From e5951a960ea65acd0a4487c8565b69e9618cf3f5 Mon Sep 17 00:00:00 2001 From: luoliangyi <87842688@@qq.com> Date: Mon, 29 May 2023 17:04:55 +0800 Subject: [PATCH] =?UTF-8?q?saneui=E4=B8=AD=E5=8E=BB=E6=8E=89sane=5Fio=5Fco?= =?UTF-8?q?ntrol=E7=9B=B8=E5=85=B3=E8=B0=83=E7=94=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- modules/sane_user/HGSaneImpl.cpp | 7 +-- modules/saneui/device_menu.h | 77 ++++++++++++++++++++++--- modules/saneui/dialog_source_select.cpp | 5 -- modules/saneui/hg_settingdialog.cpp | 33 ++++------- modules/saneui/hg_settingdialog.h | 2 +- 5 files changed, 82 insertions(+), 42 deletions(-) diff --git a/modules/sane_user/HGSaneImpl.cpp b/modules/sane_user/HGSaneImpl.cpp index 3f3f1c5f..ecd8b706 100644 --- a/modules/sane_user/HGSaneImpl.cpp +++ b/modules/sane_user/HGSaneImpl.cpp @@ -250,7 +250,7 @@ HGResult HGSaneSourceImpl::Init(const HGChar* saneManu, HGDll dll, const SANEAPI || NULL == saneAPI->sane_cancel_api || NULL == saneAPI->sane_get_devices_api || NULL == saneAPI->sane_get_option_descriptor_api || NULL == saneAPI->sane_control_option_api || NULL == saneAPI->sane_get_parameters_api || NULL == saneAPI->sane_set_io_mode_api - || NULL == saneAPI->sane_strstatus_api || NULL == saneAPI->sane_io_control_api + || NULL == saneAPI->sane_strstatus_api || NULL == saneAPI->sane_init_api || NULL == saneAPI->sane_exit_api) { return HGBASE_ERR_INVALIDARG; @@ -524,11 +524,6 @@ HGResult HGSaneSourceImpl::FindFunctions(HGDll dll, const HGChar* saneManu, SANE if (HGBASE_ERR_OK != ret) break; - sprintf(funcName, "sane_%s_io_control", saneManu); - ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_io_control_api); - if (HGBASE_ERR_OK != ret) - break; - } while (0); return ret; diff --git a/modules/saneui/device_menu.h b/modules/saneui/device_menu.h index bab55cae..f06adf83 100644 --- a/modules/saneui/device_menu.h +++ b/modules/saneui/device_menu.h @@ -195,12 +195,76 @@ public: gb::scanner_cfg::update(conf, &func); } + static SANE_Status restore_settings(const SANEAPI* saneApi, SANE_Handle h) + { + SANE_Int dev_options = 0; + saneApi->sane_control_option_api(h, 0, SANE_ACTION_GET_VALUE, &dev_options, nullptr); + for(int i = 1; i < dev_options; ++i) + { + const SANE_Option_Descriptor* opt = saneApi->sane_get_option_descriptor_api(h, i); + if(!opt) + continue; + + saneApi->sane_control_option_api(h, i, SANE_ACTION_SET_AUTO, NULL, NULL); + } + + return SANE_STATUS_GOOD; + } + static SANE_Status get_default_value(const SANEAPI* saneApi, SANE_Handle h, int i, void* def) + { + const SANE_Option_Descriptor* opt = saneApi->sane_get_option_descriptor_api(h, i); + if(!opt) + { + return SANE_STATUS_INVAL; + } + + if(opt->type == SANE_TYPE_BOOL) + { + SANE_Bool v = SANE_TRUE; + saneApi->sane_control_option_api(h, i, SANE_ACTION_GET_VALUE, &v, NULL); + saneApi->sane_control_option_api(h, i, SANE_ACTION_SET_AUTO, NULL, NULL); + saneApi->sane_control_option_api(h, i, SANE_ACTION_GET_VALUE, def, NULL); + saneApi->sane_control_option_api(h, i, SANE_ACTION_SET_VALUE, &v, NULL); + } + else if (opt->type == SANE_TYPE_INT) + { + SANE_Int v = 0; + saneApi->sane_control_option_api(h, i, SANE_ACTION_GET_VALUE, &v, NULL); + saneApi->sane_control_option_api(h, i, SANE_ACTION_SET_AUTO, NULL, NULL); + saneApi->sane_control_option_api(h, i, SANE_ACTION_GET_VALUE, def, NULL); + saneApi->sane_control_option_api(h, i, SANE_ACTION_SET_VALUE, &v, NULL); + } + else if(opt->type == SANE_TYPE_FIXED) + { + SANE_Fixed v = 0; + saneApi->sane_control_option_api(h, i, SANE_ACTION_GET_VALUE, &v, NULL); + saneApi->sane_control_option_api(h, i, SANE_ACTION_SET_AUTO, NULL, NULL); + saneApi->sane_control_option_api(h, i, SANE_ACTION_GET_VALUE, def, NULL); + saneApi->sane_control_option_api(h, i, SANE_ACTION_SET_VALUE, &v, NULL); + } + else + { + char *buf = new char[opt->size + 4]; + memset(buf, 0, opt->size + 4); + saneApi->sane_control_option_api(h, i, SANE_ACTION_GET_VALUE, buf, NULL); + saneApi->sane_control_option_api(h, i, SANE_ACTION_SET_AUTO, NULL, NULL); + saneApi->sane_control_option_api(h, i, SANE_ACTION_GET_VALUE, def, NULL); + saneApi->sane_control_option_api(h, i, SANE_ACTION_SET_VALUE, buf, NULL); + delete[] buf; + } + + return SANE_STATUS_GOOD; + } + static SANE_Status set_custom_gamma(const SANEAPI* saneApi, SANE_Handle h, SANE_Gamma *gamma) + { + return saneApi->sane_control_option_api(h, 0x885A, SANE_ACTION_SET_VALUE, gamma, NULL); + } static void apply_scheme(const SANEAPI* saneApi, SANE_Handle h, gb::sane_config_schm* schm) { SANE_Int count = 0, none = 0; std::string name(""), val(""); - none = saneApi->sane_io_control_api(h, IO_CTRL_CODE_RESTORE_SETTINGS, NULL, NULL); + none = restore_settings(saneApi, h); if(schm && schm->id_from_name(SANE_STD_OPT_NAME_COLOR_MODE) == -1) { SANE_Int dev_options = 0; @@ -215,24 +279,24 @@ public: if(opt->type == SANE_TYPE_BOOL) { SANE_Bool v = SANE_TRUE; - saneApi->sane_io_control_api(h, IO_CTRL_CODE_GET_DEFAULT_VALUE, &v, &n); + get_default_value(saneApi, h, n, &v); schm->set_default_value(i, opt->name, (char*)&v, sizeof(v)); } else if (opt->type == SANE_TYPE_INT) { SANE_Int v = 0; - saneApi->sane_io_control_api(h, IO_CTRL_CODE_GET_DEFAULT_VALUE, &v, &n); + get_default_value(saneApi, h, n, &v); schm->set_default_value(i, opt->name, (char*)&v, sizeof(v)); } else if(opt->type == SANE_TYPE_FIXED) { SANE_Fixed v = 0; - saneApi->sane_io_control_api(h, IO_CTRL_CODE_GET_DEFAULT_VALUE, &v, &n); + get_default_value(saneApi, h, n, &v); schm->set_default_value(i, opt->name, (char*)&v, sizeof(v)); } else { char *buf = new char[opt->size + 4]; memset(buf, 0, opt->size + 4); - saneApi->sane_io_control_api(h, IO_CTRL_CODE_GET_DEFAULT_VALUE, buf, &n); + get_default_value(saneApi, h, n, buf); std::string langCN(to_default_language(buf, nullptr)); schm->set_default_value(i, opt->name, &langCN[0], langCN.length()); delete[] buf; @@ -250,8 +314,7 @@ public: { if(name == SANE_STD_OPT_NAME_IS_CUSTOM_GAMMA && val.length() == sizeof(SANE_Gamma)) { - unsigned int l = val.length(); - saneApi->sane_io_control_api(h, IO_CTRL_CODE_SET_CUSTOM_GAMMA, &val[0], &l); + set_custom_gamma(saneApi, h, (SANE_Gamma*)&val[0]); } } } diff --git a/modules/saneui/dialog_source_select.cpp b/modules/saneui/dialog_source_select.cpp index cfed9edd..aa2c4198 100644 --- a/modules/saneui/dialog_source_select.cpp +++ b/modules/saneui/dialog_source_select.cpp @@ -164,11 +164,6 @@ HGResult Dialog_Source_Select::FindFunctions(HGDll dll, const HGChar* saneManu, if (HGBASE_ERR_OK != ret) break; - sprintf(funcName, "sane_%s_io_control", saneManu); - ret = HGBase_GetDllProcAddress(dll, funcName, (HGPointer*)&saneAPI->sane_io_control_api); - if (HGBASE_ERR_OK != ret) - break; - } while (0); return ret; diff --git a/modules/saneui/hg_settingdialog.cpp b/modules/saneui/hg_settingdialog.cpp index c4e21981..da986bab 100644 --- a/modules/saneui/hg_settingdialog.cpp +++ b/modules/saneui/hg_settingdialog.cpp @@ -75,7 +75,7 @@ hg_settingdialog::hg_settingdialog(const SANEAPI* saneApi, SANE_Handle handle, c initUi(); on_current_scheme_changed(); - getAppVersion(); + //getAppVersion(); } hg_settingdialog::~hg_settingdialog() @@ -127,7 +127,7 @@ void hg_settingdialog::updateOpt() if(first) { unsigned int n = i; - m_saneAPI.sane_io_control_api(m_devHandle, IO_CTRL_CODE_GET_DEFAULT_VALUE, &init, &n); + dev_que::get_default_value(&m_saneAPI, m_devHandle, n, &init); cur_scheme_->set_default_value(i, opt->name, (char*)&init, sizeof(init)); } } @@ -141,7 +141,7 @@ void hg_settingdialog::updateOpt() if(first) { unsigned int n = i; - m_saneAPI.sane_io_control_api(m_devHandle, IO_CTRL_CODE_GET_DEFAULT_VALUE, &init, &n); + dev_que::get_default_value(&m_saneAPI, m_devHandle, n, &init); cur_scheme_->set_default_value(i, opt->name, (char*)&init, sizeof(init)); } } @@ -155,7 +155,7 @@ void hg_settingdialog::updateOpt() if(first) { unsigned int n = i; - m_saneAPI.sane_io_control_api(m_devHandle, IO_CTRL_CODE_GET_DEFAULT_VALUE, &init, &n); + dev_que::get_default_value(&m_saneAPI, m_devHandle, n, &init); cur_scheme_->set_default_value(i, opt->name, (char*)&init, sizeof(init)); } } @@ -169,7 +169,7 @@ void hg_settingdialog::updateOpt() if(first) { unsigned int n = i; - int err = m_saneAPI.sane_io_control_api(m_devHandle, IO_CTRL_CODE_GET_DEFAULT_VALUE, init, &n); + int err = dev_que::get_default_value(&m_saneAPI, m_devHandle, n, init); (void)err; std::string langCN(to_default_language(init, nullptr)); cur_scheme_->set_default_value(i, opt->name, &langCN[0], langCN.length()); @@ -1187,8 +1187,7 @@ void hg_settingdialog::slot_gammaButtonClicked() } } - unsigned int len = sizeof(SANE_Gamma); - m_saneAPI.sane_io_control_api(m_devHandle, IO_CTRL_CODE_SET_CUSTOM_GAMMA, &m_gammaData, &len); + dev_que::set_custom_gamma(&m_saneAPI, m_devHandle, &m_gammaData); cur_scheme_->config_changed(SANE_STD_OPT_NAME_IS_CUSTOM_GAMMA, (char*)&m_gammaData, sizeof(m_gammaData), true); } } @@ -1760,23 +1759,11 @@ void hg_settingdialog::cancel_setting(void) dev_que::apply_scheme(&m_saneAPI, m_devHandle, cur_scheme_); } -void hg_settingdialog::getAppVersion() +std::string hg_settingdialog::getAppVersion() { - SANE_About *about = nullptr; - unsigned int len = 0; - std::string versionNum; - if (m_saneAPI.sane_io_control_api(m_devHandle, IO_CTRL_CODE_ABOUT_INFO, about, &len) == SANE_STATUS_NO_MEM) - { - about = (SANE_About*)malloc(len + 128); - if (about) - { - memset(about, 0, len + 128); - if (m_saneAPI.sane_io_control_api(m_devHandle, IO_CTRL_CODE_ABOUT_INFO, about, &len) == SANE_STATUS_GOOD) - { - versionNum = about->version; - } - } - } + char v[256] = {0}; + m_saneAPI.sane_control_option_api(m_devHandle, (SANE_Int)0x884A, SANE_ACTION_GET_VALUE, v, NULL); + return v; } void hg_settingdialog::apply_current_scheme(void) { diff --git a/modules/saneui/hg_settingdialog.h b/modules/saneui/hg_settingdialog.h index 756090d4..7aa4e33c 100644 --- a/modules/saneui/hg_settingdialog.h +++ b/modules/saneui/hg_settingdialog.h @@ -79,7 +79,7 @@ private: std::string getCurUiShemeName(std::string name); void save_scheme(void); void cancel_setting(void); - void getAppVersion(); + std::string getAppVersion(); void apply_current_scheme(void); private: