From c3a71fe4191a318050541fff2cc736071301ae9b Mon Sep 17 00:00:00 2001 From: yangjiaxuan <171295266@qq.com> Date: Fri, 14 Jul 2023 17:57:17 +0800 Subject: [PATCH] =?UTF-8?q?sane=E8=B0=83=E7=94=A8=EF=BC=8C=E8=AE=BE?= =?UTF-8?q?=E5=A4=87=E7=A6=BB=E7=BA=BF=E6=97=B6=E7=82=B9=E5=87=BB=E8=AE=BE?= =?UTF-8?q?=E7=BD=AE=E5=A2=9E=E5=8A=A0=E6=8F=90=E7=A4=BA?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scanner2/mainwindow.cpp | 43 ++++++++++++++++++++-------- modules/sane_user/HGSaneErr.h | 5 +++- modules/sane_user/HGSaneImpl.cpp | 11 ++++++- modules/saneui/HGSaneUI.cpp | 9 ++++++ modules/saneui/SaneUI_zh_CN.qm | Bin 5504 -> 5512 bytes modules/saneui/SaneUI_zh_CN.ts | 2 +- modules/saneui/hg_settingdialog.cpp | 10 ++++++- modules/saneui/hg_settingdialog.h | 3 ++ 8 files changed, 67 insertions(+), 16 deletions(-) diff --git a/app/scanner2/mainwindow.cpp b/app/scanner2/mainwindow.cpp index feeca746..0e3140b6 100644 --- a/app/scanner2/mainwindow.cpp +++ b/app/scanner2/mainwindow.cpp @@ -2901,20 +2901,39 @@ void MainWindow::on_act_about_triggered() void MainWindow::on_act_scannerSettings_triggered() { - if (nullptr != m_devUser) + if (nullptr == m_devUser) { - HGResult ret = m_devUser->ShowSettingDlg(); - if (HGTWAIN_ERR_DEVICEOFFLINE == ret) - { - QMessageBox::information(this, tr("Prompt"), tr("Device is offline")); - deleteDevUser(); - } - else if (ret == HGTWAIN_ERR_FAIL) - { - QMessageBox::information(this, tr("Prompt"), tr("Open failed")); - deleteDevUser(); - } + return; } + + HGResult ret = m_devUser->ShowSettingDlg(); + bool deviceIsOnline = true; + bool openSucceed = true; + +#if defined(HG_CMP_MSC) + + if (HGTWAIN_ERR_DEVICEOFFLINE == ret) + deviceIsOnline = false; + else if (HGTWAIN_ERR_FAIL == ret) + openSucceed = false; +#else + if (HGSANE_ERR_DEVICEOFFLINE == ret) + deviceIsOnline = false; + else if (HGSANE_ERR_FAIL == ret) + openSucceed = false; + + if (!deviceIsOnline) + { + QMessageBox::information(this, tr("Prompt"), tr("Device is offline")); + deleteDevUser(); + } + else if (!openSucceed) + { + QMessageBox::information(this, tr("Prompt"), tr("Open failed")); + deleteDevUser(); + } +#endif + } void MainWindow::on_act_acquire_triggered() diff --git a/modules/sane_user/HGSaneErr.h b/modules/sane_user/HGSaneErr.h index 827e169d..584a4a0f 100644 --- a/modules/sane_user/HGSaneErr.h +++ b/modules/sane_user/HGSaneErr.h @@ -4,4 +4,7 @@ /* 一般错误 */ #define HGSANE_ERR_FAIL 0x00004001L -#endif /* __HGSANEERR_H__ */ \ No newline at end of file +/* 设备离线 */ +#define HGSANE_ERR_DEVICEOFFLINE 0x00004002L + +#endif /* __HGSANEERR_H__ */ diff --git a/modules/sane_user/HGSaneImpl.cpp b/modules/sane_user/HGSaneImpl.cpp index f32a2afc..3d51e282 100644 --- a/modules/sane_user/HGSaneImpl.cpp +++ b/modules/sane_user/HGSaneImpl.cpp @@ -776,10 +776,19 @@ HGResult HGSaneDeviceImpl::ClearDeviceLog() HGResult HGSaneDeviceImpl::ShowSettingDlg(HGWindow parent) { - if (-2 == show_setting_ui(&m_sourceImpl->m_saneApi, m_devHandle, m_devName.c_str(), parent)) + int ret = show_setting_ui(&m_sourceImpl->m_saneApi, m_devHandle, m_devName.c_str(), parent); + if (-1 == ret) + { + return HGSANE_ERR_FAIL; + } + else if (-2 == ret) { return HGBASE_ERR_NOTSUPPORT; } + else if (-3 == ret) + { + return HGSANE_ERR_DEVICEOFFLINE; + } return HGBASE_ERR_OK; } diff --git a/modules/saneui/HGSaneUI.cpp b/modules/saneui/HGSaneUI.cpp index 22955725..8aaf898e 100644 --- a/modules/saneui/HGSaneUI.cpp +++ b/modules/saneui/HGSaneUI.cpp @@ -145,6 +145,15 @@ int show_setting_ui(const SANEAPI* saneApi, SANE_Handle handle, const char *devN QCoreApplication::installTranslator(&translator2); hg_settingdialog dlg(saneApi, handle, devName, qParent); + if (!dlg.IsValid()) + { + QCoreApplication::removeTranslator(&translator); + if (20127 != cp) + QCoreApplication::removeTranslator(&translator2); + + return -3; + } + dlg.exec(); QCoreApplication::removeTranslator(&translator); diff --git a/modules/saneui/SaneUI_zh_CN.qm b/modules/saneui/SaneUI_zh_CN.qm index 1f174d4bf944a62f629f8d72a2ebdee5331673cf..852dabfb688bfdee6e50ac9b35fe98b738e25515 100644 GIT binary patch delta 217 zcmZqB?$DlK!Z>xJskz`!297gd85r0WGu--pfq_A2@5EYr!KF+=bL1EpI3$?n%6l;| z2z;G*R-W?@^F{@rppeeQul1G{Y%@If0A+}xsbgSZSjqW$**TyoN|T>5nlnC_ zEX$-Xc7Q*xbSVP^b1wh)X+T=gHIsosSZ#9>Qx7j=)a3X45*!LL45|!<3bK>A1!Uly J&DsK?tN_cXKF9z7 delta 209 zcmeCsZqS}!!q_{})Lif*1IL-K3=C|G8E*Z)z`!81bz-f(;9RDlIdTjP91=`(<-Hgf z1l~?OE6@3bd7}bQP)KFs*LuqWwi%v#fHHY(%cNQu82A>mt=ZMez`(A{zO1C3fq^TK zV^u^aP;olPdd=xT>>SV(smV_n%^7b@ zmSxfx+rgh#x|D%|IhX(YG$1W#o5{c+EVns{sfU*_X!3i02^I!b2E)nx0y1F6W@CX+ FRsforJwgBg diff --git a/modules/saneui/SaneUI_zh_CN.ts b/modules/saneui/SaneUI_zh_CN.ts index d1ba7567..d664e5d4 100644 --- a/modules/saneui/SaneUI_zh_CN.ts +++ b/modules/saneui/SaneUI_zh_CN.ts @@ -2946,7 +2946,7 @@ No: add new configuration The current parameter settings are inconsistent with the configuration scheme '%1'. To use the configuration scheme '%1' parameters, please click the restore button - 当前参数设置与配置方案 %1 不一致,如需使用配置方案 %1 参数,请点击恢复按钮 + 当前参数设置与配置方案 “%1” 不一致,如需使用配置方案 “%1” 参数,请点击恢复按钮 diff --git a/modules/saneui/hg_settingdialog.cpp b/modules/saneui/hg_settingdialog.cpp index c8bab67c..883c72f7 100644 --- a/modules/saneui/hg_settingdialog.cpp +++ b/modules/saneui/hg_settingdialog.cpp @@ -25,6 +25,7 @@ hg_settingdialog::hg_settingdialog(const SANEAPI* saneApi, SANE_Handle handle, c , m_isRefreshUi(false) , changed_count_(0) , cur_cfg_(nullptr) + , m_deviceIsValid(true) { m_dpiId = -1; m_dpiValue = 200; @@ -62,7 +63,9 @@ hg_settingdialog::hg_settingdialog(const SANEAPI* saneApi, SANE_Handle handle, c dev_que::update_old_cfg(old.toStdString().c_str()); int pid = 0; - m_saneAPI.sane_control_option_api(m_devHandle, (SANE_Int)0x8853, SANE_ACTION_GET_VALUE, &pid, NULL); + SANE_Status ret = m_saneAPI.sane_control_option_api(m_devHandle, (SANE_Int)0x8853, SANE_ACTION_GET_VALUE, &pid, NULL); + if (SANE_STATUS_GOOD != ret) + m_deviceIsValid = false; char buf[10] = { 0 }; sprintf(buf, "%x", pid); @@ -166,6 +169,11 @@ void hg_settingdialog::apply_scheme(SANE_Handle dev, LPSANEAPI api, gb::sane_con } } +bool hg_settingdialog::IsValid() +{ + return m_deviceIsValid; +} + void hg_settingdialog::initUi() { update_opt_value_from_driver(); diff --git a/modules/saneui/hg_settingdialog.h b/modules/saneui/hg_settingdialog.h index 17d0b25b..0701e807 100644 --- a/modules/saneui/hg_settingdialog.h +++ b/modules/saneui/hg_settingdialog.h @@ -54,6 +54,8 @@ public: static void apply_scheme(SANE_Handle dev, LPSANEAPI api, gb::sane_config_schm* schm); + bool IsValid(); + public: void initUi(); void update_opt_value_from_driver(); @@ -157,6 +159,7 @@ private: QComboBox *comb_; bool m_isRefreshUi; + bool m_deviceIsValid; }; #endif // HG_SETTING_DIALOG_H