From 51ba9c21df1494a4f8d24a4359a34748eeafc896 Mon Sep 17 00:00:00 2001 From: gb <741021719@qq.com> Date: Tue, 2 Jan 2024 15:21:54 +0800 Subject: [PATCH] =?UTF-8?q?device=5Foption=E6=B7=BB=E5=8A=A0=E6=98=AF?= =?UTF-8?q?=E5=90=A6=E5=88=9B=E5=BB=BA=E5=88=86=E7=BB=84=E5=B1=9E=E6=80=A7?= =?UTF-8?q?=E7=9A=84=E5=BC=80=E5=85=B3?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- hgdriver/hgdev/hg_scanner.cpp | 4 ++-- sdk/sane_opt_json/device_opt.cpp | 40 ++++++++++++++++++-------------- sdk/sane_opt_json/device_opt.h | 5 ++-- 3 files changed, 28 insertions(+), 21 deletions(-) diff --git a/hgdriver/hgdev/hg_scanner.cpp b/hgdriver/hgdev/hg_scanner.cpp index 4b5c825..4537fec 100644 --- a/hgdriver/hgdev/hg_scanner.cpp +++ b/hgdriver/hgdev/hg_scanner.cpp @@ -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; diff --git a/sdk/sane_opt_json/device_opt.cpp b/sdk/sane_opt_json/device_opt.cpp index 5bfeb1f..62c5e04 100644 --- a/sdk/sane_opt_json/device_opt.cpp +++ b/sdk/sane_opt_json/device_opt.cpp @@ -364,8 +364,10 @@ bool device_option::range_value::set_value(gb_json* jsn, const char* type, devic } -device_option::device_option(std::function user_priv, std::function log) : origin_(nullptr), now_(nullptr) - , user_(user_priv), log_(log) +device_option::device_option(bool no_group, std::function user_priv + , std::function 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; } diff --git a/sdk/sane_opt_json/device_opt.h b/sdk/sane_opt_json/device_opt.h index 228bc9a..9ae2270 100644 --- a/sdk/sane_opt_json/device_opt.h +++ b/sdk/sane_opt_json/device_opt.h @@ -24,6 +24,7 @@ class device_option : public refer { gb_json* origin_; gb_json* now_; + bool no_grp_ = false; std::map src_; std::vector master_opts_; // options that value changed will affect others std::map slaver_; @@ -345,7 +346,7 @@ protected: public: - device_option(std::function user_priv = std::function() + device_option(bool no_group = false, std::function user_priv = std::function() , std::function log = std::function()); ~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);