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); ret = scanner_->option_get_all(opts);
set_opt_json_text(&opts[0]); set_opt_json_text(&opts[0]);
if(user_) if(user_)
dev_opts_ = new device_option(privilege, logmsg); dev_opts_ = new device_option(false, privilege, logmsg);
else else
dev_opts_ = new device_option(privilege_empty, logmsg); dev_opts_ = new device_option(false, privilege_empty, logmsg);
dev_opts_->add(this); dev_opts_->add(this);
status_ = SCANNER_ERR_OK; status_ = SCANNER_ERR_OK;

View File

@ -364,7 +364,9 @@ 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) 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) , user_(user_priv), log_(log)
{} {}
device_option::~device_option() device_option::~device_option()
@ -1236,10 +1238,17 @@ bool device_option::arrange_raw_json(sane_opt_provider* sop)
{ {
child->get_value("type", str); child->get_value("type", str);
if (str != JSON_SANE_TYPE_GROUP) // omit group if (str != JSON_SANE_TYPE_GROUP) // omit group
{
if(no_grp_)
{
insert_option(child, sop);
}
else
{ {
child->get_value("group", str); child->get_value("group", str);
insert_option(child, sop, str.empty() ? nullptr : str.c_str()); insert_option(child, sop, str.empty() ? nullptr : str.c_str());
} }
}
child->release(); child->release();
child = jsn->next_child(); child = jsn->next_child();
} }
@ -1912,7 +1921,7 @@ int device_option::restore(sane_opt_provider* holder)
while (child) while (child)
{ {
if ((!holder || src_.count(child->key()) && src_[child->key()] == holder) 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)); std::string val(device_option::option_value(child, true));
update_data(child->key().c_str(), &val[0], false); update_data(child->key().c_str(), &val[0], false);
@ -1942,21 +1951,18 @@ int device_option::count(void)
else else
return 0; 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); jsn->get_value("type", type);
if (child) if(type == JSON_SANE_TYPE_BUTTON || type == JSON_SANE_TYPE_GROUP)
{ return false;
if (!child->get_value("auto", support))
if (!jsn->get_value("auto", support))
support = true; support = true;
child->release();
}
return support; return support;
} }
std::string device_option::get_name_by_sane_id(int sane_ind) std::string device_option::get_name_by_sane_id(int sane_ind)

View File

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