device_option添加是否创建分组属性的开关

This commit is contained in:
gb 2024-01-02 15:21:54 +08:00
parent 57eb55bcf3
commit 51ba9c21df
3 changed files with 28 additions and 21 deletions

View File

@ -222,9 +222,9 @@ void hg_scanner::init(void)
ret = scanner_->option_get_all(opts);
set_opt_json_text(&opts[0]);
if(user_)
dev_opts_ = new device_option(privilege, logmsg);
dev_opts_ = new device_option(false, privilege, logmsg);
else
dev_opts_ = new device_option(privilege_empty, logmsg);
dev_opts_ = new device_option(false, privilege_empty, logmsg);
dev_opts_->add(this);
status_ = SCANNER_ERR_OK;

View File

@ -364,8 +364,10 @@ bool device_option::range_value::set_value(gb_json* jsn, const char* type, devic
}
device_option::device_option(std::function<bool(int)> user_priv, std::function<void(const char*)> log) : origin_(nullptr), now_(nullptr)
, user_(user_priv), log_(log)
device_option::device_option(bool no_group, std::function<bool(int)> user_priv
, std::function<void(const char*)> log)
: no_grp_(no_group), origin_(nullptr), now_(nullptr)
, user_(user_priv), log_(log)
{}
device_option::~device_option()
{
@ -1237,8 +1239,15 @@ bool device_option::arrange_raw_json(sane_opt_provider* sop)
child->get_value("type", str);
if (str != JSON_SANE_TYPE_GROUP) // omit group
{
child->get_value("group", str);
insert_option(child, sop, str.empty() ? nullptr : str.c_str());
if(no_grp_)
{
insert_option(child, sop);
}
else
{
child->get_value("group", str);
insert_option(child, sop, str.empty() ? nullptr : str.c_str());
}
}
child->release();
child = jsn->next_child();
@ -1697,7 +1706,7 @@ void device_option::clear(void)
}
bool device_option::add(sane_opt_provider* sop)
{
bool ret = false;
bool ret = false;
clear_for_reconstruct();
if (arrange_raw_json(sop))
@ -1912,7 +1921,7 @@ int device_option::restore(sane_opt_provider* holder)
while (child)
{
if ((!holder || src_.count(child->key()) && src_[child->key()] == holder)
&& is_auto_restore_default(child->key().c_str()))
&& is_auto_restore_default(child))
{
std::string val(device_option::option_value(child, true));
update_data(child->key().c_str(), &val[0], false);
@ -1942,20 +1951,17 @@ int device_option::count(void)
else
return 0;
}
bool device_option::is_auto_restore_default(const char* name)
bool device_option::is_auto_restore_default(gb_json* jsn)
{
gb_json* jsn = now_ ? now_ : origin_,
* child = nullptr;
bool support = true;
bool support = true;
std::string type("");
jsn->get_value(name, child);
if (child)
{
if (!child->get_value("auto", support))
support = true;
jsn->get_value("type", type);
if(type == JSON_SANE_TYPE_BUTTON || type == JSON_SANE_TYPE_GROUP)
return false;
child->release();
}
if (!jsn->get_value("auto", support))
support = true;
return support;
}

View File

@ -24,6 +24,7 @@ class device_option : public refer
{
gb_json* origin_;
gb_json* now_;
bool no_grp_ = false;
std::map<std::string, sane_opt_provider*> src_;
std::vector<std::string> master_opts_; // options that value changed will affect others
std::map<std::string, simple_logic*> slaver_;
@ -345,7 +346,7 @@ protected:
public:
device_option(std::function<bool(int)> user_priv = std::function<bool(int)>()
device_option(bool no_group = false, std::function<bool(int)> user_priv = std::function<bool(int)>()
, std::function<void(const char*)> log = std::function<void(const char*)>());
~device_option();
@ -361,7 +362,7 @@ public:
int restore(sane_opt_provider* holder); //
int count(void); // return option count
bool is_auto_restore_default(const char* name);
bool is_auto_restore_default(gb_json* jsn);
std::string get_name_by_sane_id(int sane_ind);
std::string get_option_value_type(const char* name, size_t* size = nullptr);
std::string get_option_value_type(int sane_ind, size_t* size = nullptr);