From 2640e432bdd65f7668f00a03f93401a0d3fe3048 Mon Sep 17 00:00:00 2001 From: yangjiaxuan <171295266@qq.com> Date: Tue, 30 May 2023 19:11:24 +0800 Subject: [PATCH] =?UTF-8?q?=E6=B7=BB=E5=8A=A0=E9=BB=98=E8=AE=A4=E6=89=93?= =?UTF-8?q?=E5=BC=80=E8=AE=BE=E5=A4=87=E5=8A=9F=E8=83=BD?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scanner2/device_user.cpp | 15 +++ app/scanner2/device_user.h | 1 + app/scanner2/mainwindow.cpp | 38 +++--- build2/qt/HGTwainUser/HGTwainUser.pro | 9 +- modules/twain_user/HGTwainErr.h | 5 +- modules/twain_user/HGTwainImpl.cpp | 126 +++++++++++------- modules/twain_user/HGTwainImpl.hpp | 2 + modules/twain_user/app_cfg.cpp | 27 ++++ modules/twain_user/app_cfg.h | 9 ++ modules/twainui/Manager.cpp | 13 +- modules/twainui/Manager.h | 5 +- .../twainui/dialog_twain_source_select.cpp | 88 ++---------- modules/twainui/dialog_twain_source_select.h | 9 +- modules/twainui/twainui.cpp | 4 +- 14 files changed, 189 insertions(+), 162 deletions(-) create mode 100644 modules/twain_user/app_cfg.cpp create mode 100644 modules/twain_user/app_cfg.h diff --git a/app/scanner2/device_user.cpp b/app/scanner2/device_user.cpp index 38ac1f8b..7a98d6eb 100644 --- a/app/scanner2/device_user.cpp +++ b/app/scanner2/device_user.cpp @@ -29,6 +29,21 @@ class DeviceUser* DeviceUserMgr::OpenDeviceUser() return new DeviceUser(m_wnd, ds, m_password); } +DeviceUser *DeviceUserMgr::OpenDefaultDeviceUser() +{ + HGUInt count = 0; + HGTwain_GetDSCount(m_twainDSM, &count); + for (int i = 0; i < count; ++i) + { + HGTwainDS ds = nullptr; + HGTwain_OpenDS(m_twainDSM, i, &ds); + if (ds != nullptr) + return new DeviceUser(m_wnd, ds, m_password); + } + + return nullptr; +} + DeviceUser::DeviceUser(QWidget *wnd, HGTwainDS ds, QString password) { m_wnd = wnd; diff --git a/app/scanner2/device_user.h b/app/scanner2/device_user.h index 2de3b7e4..5db00c55 100644 --- a/app/scanner2/device_user.h +++ b/app/scanner2/device_user.h @@ -17,6 +17,7 @@ public: // 弹出设备选择对话框,选择twain源 class DeviceUser* OpenDeviceUser(); + class DeviceUser* OpenDefaultDeviceUser(); private: QWidget *m_wnd; diff --git a/app/scanner2/mainwindow.cpp b/app/scanner2/mainwindow.cpp index 6d2edead..361c7368 100644 --- a/app/scanner2/mainwindow.cpp +++ b/app/scanner2/mainwindow.cpp @@ -349,9 +349,6 @@ MainWindow::MainWindow(const QString& appLang, QWidget *parent) else m_password = passwordDecrypt(password); - m_devUserMgr = new DeviceUserMgr(m_password, this); - m_devUser = nullptr; - m_dlgFullScreen = nullptr; ui->act_autoSave->setChecked(getCfgValue("save", "autoSave", false)); @@ -381,6 +378,15 @@ MainWindow::MainWindow(const QString& appLang, QWidget *parent) connect(m_widget_sideBar, SIGNAL(applyToImage(HGImage,int,int,double,bool)), this, SLOT(on_dialog_sideBar_applyToImage(HGImage,int,int,double,bool))); connect(m_widget_sideBar, SIGNAL(finish(bool)), this, SLOT(on_dialog_sideBar_finish(bool))); + m_devUserMgr = new DeviceUserMgr(m_password, this); + m_devUser = m_devUserMgr->OpenDefaultDeviceUser(); + if (m_devUser != nullptr) + { + m_wndStatusBar->setDeviceStatusInfo(tr("Device %1 is open").arg(m_devUser->GetName()), false); + connect(m_devUser, SIGNAL(newImage(void*)), this, SLOT(on_newImage(void*)), Qt::DirectConnection); + connect(m_devUser, &DeviceUser::scanEvent, this, &MainWindow::on_scanEvent, Qt::QueuedConnection); + } + updateSideBar(); updateActionStatus(); } @@ -3791,27 +3797,23 @@ void MainWindow::on_act_selectDevice_triggered() m_versionDll->PostUserLogoutInfo(HGVERSION_APPNAME_SCANNER, m_oemName); } + if (nullptr != m_devUser) + { + disconnect(m_devUser, SIGNAL(newImage(void*)), this, SLOT(on_newImage(void*))); + disconnect(m_devUser, &DeviceUser::scanEvent, this, &MainWindow::on_scanEvent); + m_devUser->Logout(); + delete m_devUser; + m_devUser = nullptr; + } + DeviceUser *devUser = m_devUserMgr->OpenDeviceUser(); if (devUser != nullptr) { - if (nullptr != m_devUser) - { - disconnect(m_devUser, SIGNAL(newImage(void*)), this, SLOT(on_newImage(void*))); - disconnect(m_devUser, &DeviceUser::scanEvent, this, &MainWindow::on_scanEvent); - m_devUser->Logout(); - delete m_devUser; - m_devUser = nullptr; - m_wndStatusBar->setDeviceStatusInfo(tr("Please go to 'Menu Bar ->Scan' to select a device"), false); - } - m_devUser = devUser; m_wndStatusBar->setDeviceStatusInfo(tr("Device %1 is open").arg(m_devUser->GetName()), false); connect(m_devUser, SIGNAL(newImage(void*)), this, SLOT(on_newImage(void*)), Qt::DirectConnection); connect(m_devUser, &DeviceUser::scanEvent, this, &MainWindow::on_scanEvent, Qt::QueuedConnection); - updateActionStatus(); - } - else - { - QMessageBox::information(this, tr("Prompt"), tr("Open device failed")); } + + updateActionStatus(); } diff --git a/build2/qt/HGTwainUser/HGTwainUser.pro b/build2/qt/HGTwainUser/HGTwainUser.pro index 732effc2..b178839a 100644 --- a/build2/qt/HGTwainUser/HGTwainUser.pro +++ b/build2/qt/HGTwainUser/HGTwainUser.pro @@ -31,12 +31,16 @@ win32 { SOURCES += \ ../../../modules/twain_user/HGTwain.cpp \ ../../../modules/twain_user/HGTwainImpl.cpp \ - ../../../modules/twain_user/dllmain.cpp + ../../../modules/twain_user/dllmain.cpp \ + ../../../modules/twain_user/app_cfg.cpp \ + ../../../utility/HGString.cpp HEADERS += \ ../../../modules/twain_user/HGTwain.h \ ../../../modules/twain_user/HGTwainErr.h \ - ../../../modules/twain_user/HGTwainImpl.hpp + ../../../modules/twain_user/HGTwainImpl.hpp \ + ../../../modules/twain_user/app_cfg.h \ + ../../../utility/HGString.h MY_OS = windows TARGET = $${OEM_PREFIX}TwainUser @@ -103,6 +107,7 @@ unix { } INCLUDEPATH += $$PWD/../../../modules +INCLUDEPATH += $$PWD/../../../utility INCLUDEPATH += $$PWD/../../../../sdk/include DESTDIR = $$PWD/../../build/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE} diff --git a/modules/twain_user/HGTwainErr.h b/modules/twain_user/HGTwainErr.h index 9946c025..86a91449 100644 --- a/modules/twain_user/HGTwainErr.h +++ b/modules/twain_user/HGTwainErr.h @@ -4,4 +4,7 @@ /* 一般错误 */ #define HGTWAIN_ERR_FAIL 0x00001001L -#endif /* __HGTWAINERR_H__ */ \ No newline at end of file +/* UI取消操作 */ +#define HGTWAIN_ERR_CANCELUI 0x00001002L + +#endif /* __HGTWAINERR_H__ */ diff --git a/modules/twain_user/HGTwainImpl.cpp b/modules/twain_user/HGTwainImpl.cpp index c8291e3f..7782cb9f 100644 --- a/modules/twain_user/HGTwainImpl.cpp +++ b/modules/twain_user/HGTwainImpl.cpp @@ -1,6 +1,7 @@ #include "HGTwainImpl.hpp" #include "../base/HGInc.h" #include "../base/HGInfo.h" +#include "app_cfg.h" std::map HGTwainDSMImpl::m_mapWnd; @@ -24,6 +25,7 @@ HGTwainDSMImpl::HGTwainDSMImpl() m_hWnd = NULL; m_oldWndProc = NULL; + m_vds.clear(); } HGTwainDSMImpl::~HGTwainDSMImpl() @@ -72,6 +74,19 @@ HGResult HGTwainDSMImpl::Create(HWND hwnd) m_hWnd = hwnd; m_mapWnd[m_hWnd] = this; m_oldWndProc = (WNDPROC)SetWindowLongPtrW(m_hWnd, GWLP_WNDPROC, (LONG_PTR)NewWndProc); + + TW_IDENTITY ds; + if (TWRC_SUCCESS == m_pDSMProc(&m_AppId, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETFIRST, &ds)) + { + if (!filterTwainSource(ds.ProductName)) + m_vds.push_back(ds); + while (TWRC_SUCCESS == m_pDSMProc(&m_AppId, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETNEXT, &ds)) + { + if (!filterTwainSource(ds.ProductName)) + m_vds.push_back(ds); + } + } + return HGBASE_ERR_OK; } @@ -84,6 +99,8 @@ HGResult HGTwainDSMImpl::Destroy() return HGBASE_ERR_FAIL; } + m_vds.clear(); + m_pDSMProc(&m_AppId, NULL, DG_CONTROL, DAT_PARENT, MSG_CLOSEDSM, (TW_MEMREF)&m_hWnd); SetWindowLongPtrW(m_hWnd, GWLP_WNDPROC, (LONG_PTR)m_oldWndProc); m_oldWndProc = NULL; @@ -111,18 +128,7 @@ HGResult HGTwainDSMImpl::GetDSCount(HGUInt* count) return HGBASE_ERR_INVALIDARG; } - HGUInt num = 0; - TW_IDENTITY ds; - if (TWRC_SUCCESS == m_pDSMProc(&m_AppId, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETFIRST, &ds)) - { - ++num; - while (TWRC_SUCCESS == m_pDSMProc(&m_AppId, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETNEXT, &ds)) - { - ++num; - } - } - - *count = num; + *count = m_vds.size(); return HGBASE_ERR_OK; } @@ -133,23 +139,12 @@ HGResult HGTwainDSMImpl::GetDSName(HGUInt index, HGChar* name, HGUInt maxLen) return HGBASE_ERR_INVALIDARG; } - std::vector vds; - TW_IDENTITY ds; - if (TWRC_SUCCESS == m_pDSMProc(&m_AppId, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETFIRST, &ds)) - { - vds.push_back(ds); - while (TWRC_SUCCESS == m_pDSMProc(&m_AppId, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETNEXT, &ds)) - { - vds.push_back(ds); - } - } - - if (index >= (HGUInt)vds.size()) + if (index >= (HGUInt)m_vds.size()) return HGBASE_ERR_INVALIDARG; - if (maxLen < strlen(vds[index].ProductName) + 1) + if (maxLen < strlen(m_vds[index].ProductName) + 1) return HGBASE_ERR_FAIL; - strcpy(name, vds[index].ProductName); + strcpy(name, m_vds[index].ProductName); return HGBASE_ERR_OK; } @@ -160,28 +155,18 @@ HGResult HGTwainDSMImpl::OpenDS(HGUInt index, class HGTwainDSImpl** dsImpl) return HGBASE_ERR_INVALIDARG; } - std::vector vds; - TW_IDENTITY ds; - if (TWRC_SUCCESS == m_pDSMProc(&m_AppId, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETFIRST, &ds)) - { - vds.push_back(ds); - while (TWRC_SUCCESS == m_pDSMProc(&m_AppId, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETNEXT, &ds)) - { - vds.push_back(ds); - } - } - - if (index >= (HGUInt)vds.size()) + if (index >= (HGUInt)m_vds.size()) return HGBASE_ERR_INVALIDARG; class HGTwainDSImpl* newDSImpl = new HGTwainDSImpl(this); - HGResult ret = newDSImpl->Open(&vds[index]); + HGResult ret = newDSImpl->Open(&m_vds[index]); if (HGBASE_ERR_OK != ret) { delete newDSImpl; return ret; } + saveCfgValue("twain", "source", m_vds[index].ProductName); m_listDSImpl.push_back(newDSImpl); *dsImpl = newDSImpl; return HGBASE_ERR_OK; @@ -192,22 +177,39 @@ HGResult HGTwainDSMImpl::OpenDefaultDS(class HGTwainDSImpl** dsImpl) if (NULL == dsImpl) { return HGBASE_ERR_INVALIDARG; - } + } - TW_IDENTITY defDS; - if (TWRC_SUCCESS != m_pDSMProc(&m_AppId, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETDEFAULT, &defDS)) - { - return HGTWAIN_ERR_FAIL; - } + if (m_vds.empty()) + { + return HGBASE_ERR_FAIL; + } + + std::string sourceName = getCfgValue("twain", "source", std::string("")); + + int index = -1; + for (int i = 0; i < m_vds.size(); ++i) + { + if (strcmp(m_vds[i].ProductName, sourceName.c_str()) == 0) + { + index = i; + break; + } + } + + if (-1 == index) + { + index = 0; + } class HGTwainDSImpl* newDSImpl = new HGTwainDSImpl(this); - HGResult ret = newDSImpl->Open(&defDS); + HGResult ret = newDSImpl->Open(&m_vds[0]); if (HGBASE_ERR_OK != ret) { delete newDSImpl; return ret; } + saveCfgValue("twain", "source", m_vds[index].ProductName); m_listDSImpl.push_back(newDSImpl); *dsImpl = newDSImpl; return HGBASE_ERR_OK; @@ -234,6 +236,7 @@ HGResult HGTwainDSMImpl::OpenSelectedDS(class HGTwainDSImpl** dsImpl) return ret; } + saveCfgValue("twain", "source", selectDS.ProductName); m_listDSImpl.push_back(newDSImpl); *dsImpl = newDSImpl; return HGBASE_ERR_OK; @@ -246,16 +249,18 @@ HGResult HGTwainDSMImpl::OpenSelectedDSEx(class HGTwainDSImpl** dsImpl) return HGBASE_ERR_INVALIDARG; } + std::string sourceName = getCfgValue("twain", "source", std::string("")); + TW_IDENTITY selectDS; memset(&selectDS, 0, sizeof(TW_IDENTITY)); - if (-2 == show_twain_srclist_ui(m_pDSMProc, &m_AppId, m_hWnd, &selectDS)) + if (-2 == show_twain_srclist_ui(m_pDSMProc, &m_vds[0], m_vds.size(), sourceName.c_str(), m_hWnd, &selectDS)) { return HGBASE_ERR_NOTSUPPORT; } if (0 == selectDS.Id) { - return HGBASE_ERR_FAIL; + return HGTWAIN_ERR_CANCELUI; } class HGTwainDSImpl* newDSImpl = new HGTwainDSImpl(this); @@ -266,6 +271,7 @@ HGResult HGTwainDSMImpl::OpenSelectedDSEx(class HGTwainDSImpl** dsImpl) return ret; } + saveCfgValue("twain", "source", selectDS.ProductName); m_listDSImpl.push_back(newDSImpl); *dsImpl = newDSImpl; return HGBASE_ERR_OK; @@ -319,6 +325,30 @@ LRESULT CALLBACK HGTwainDSMImpl::NewWndProc(HWND hWnd, UINT msg, WPARAM wParam, return CallWindowProcW(p->m_oldWndProc, hWnd, msg, wParam, lParam); } +bool HGTwainDSMImpl::filterTwainSource(const char* sourceName) +{ +#if !defined(OEM_HANWANG) && !defined(OEM_LISICHENG) && !defined(OEM_CANGTIAN) && !defined(OEM_ZHONGJING) && !defined(OEM_ZIGUANG) && !defined(OEM_NEUTRAL) + std::string oemIden = "HUAGOSCAN"; +#elif defined(OEM_HANWANG) + std::string oemIden = "Hanvon"; +#elif defined(OEM_LISICHENG) + std::string oemIden = "LANXUMSCAN"; +#elif defined(OEM_CANGTIAN) + std::string oemIden = "CUMTENN"; +#elif defined(OEM_ZHONGJING) + std::string oemIden = "Microtek"; +#elif defined(OEM_ZIGUANG) + std::string oemIden = "Uniscan"; +#endif + + if (NULL == strstr(sourceName, oemIden.c_str())) + { + return true; + } + + return false; +} + HGTwainDSImpl::HGTwainDSImpl(HGTwainDSMImpl* dsmImpl) { diff --git a/modules/twain_user/HGTwainImpl.hpp b/modules/twain_user/HGTwainImpl.hpp index 15467659..1e56433b 100644 --- a/modules/twain_user/HGTwainImpl.hpp +++ b/modules/twain_user/HGTwainImpl.hpp @@ -29,6 +29,7 @@ public: private: void RemoveDS(class HGTwainDSImpl* dsImpl); static LRESULT CALLBACK NewWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam); + bool filterTwainSource(const char* sourceName); private: HGDll m_hDll; @@ -37,6 +38,7 @@ private: HWND m_hWnd; static std::map m_mapWnd; WNDPROC m_oldWndProc; + std::vector m_vds; std::vector m_listDSImpl; }; diff --git a/modules/twain_user/app_cfg.cpp b/modules/twain_user/app_cfg.cpp new file mode 100644 index 00000000..955e57eb --- /dev/null +++ b/modules/twain_user/app_cfg.cpp @@ -0,0 +1,27 @@ +#include "app_cfg.h" +#include "base/HGDef.h" +#include "base/HGInc.h" +#include "base/HGUtility.h" +#include "base/HGIni.h" +#include "HGString.h" + +std::string getCfgValue(const char *appName, const char *key, const std::string &def) +{ + HGChar cfgPath[512]; + HGBase_GetConfigPath(cfgPath, 512); + strcat(cfgPath, "config.ini"); + + HGChar value[512] = {0}; + HGBase_GetProfileString(cfgPath, appName, key, def.c_str(), value, 512); + return StdStringToUtf8(value).c_str(); +} + +void saveCfgValue(const char *appName, const char *key, const std::string &value) +{ + HGChar cfgPath[512]; + HGBase_GetConfigPath(cfgPath, 512); + HGBase_CreateDir(cfgPath); + strcat(cfgPath, "config.ini"); + + HGBase_SetProfileString(cfgPath, appName, key, value.c_str()); +} diff --git a/modules/twain_user/app_cfg.h b/modules/twain_user/app_cfg.h new file mode 100644 index 00000000..2736dc0a --- /dev/null +++ b/modules/twain_user/app_cfg.h @@ -0,0 +1,9 @@ +#ifndef __APP_CFG_H__ +#define __APP_CFG_H__ + +#include + +std::string getCfgValue(const char *appName, const char *key, const std::string &def); +void saveCfgValue(const char *appName, const char *key, const std::string &value); + +#endif /* __APP_CFG_H__ */ diff --git a/modules/twainui/Manager.cpp b/modules/twainui/Manager.cpp index 6765e212..f81eb560 100644 --- a/modules/twainui/Manager.cpp +++ b/modules/twainui/Manager.cpp @@ -125,14 +125,19 @@ int Manager::showMessageBoxUi(bool qt, HWND parent, int event, void *msg, int fl return 0; } -int Manager::showTwainSrcUi(bool qt, DSMENTRYPROC dsmProc, const TW_IDENTITY *appId, HGWindow parent, TW_IDENTITY *ds) +int Manager::showTwainSrcUi(bool qt, DSMENTRYPROC dsmProc, const TW_IDENTITY *vds, HGUInt count, const char* defDevName, HGWindow parent, TW_IDENTITY *ds) { m_twainSrcUiThreadId = GetCurrentThreadId(); m_TwainSrcUiparent = parent; m_dsmProc = dsmProc; - memcpy(&m_appId, appId, sizeof(TW_IDENTITY)); - memset(ds, 0, sizeof(TW_IDENTITY)); + + m_vds.clear(); + for (int i = 0; i < count; ++i) + { + m_vds.push_back(vds[i]); + } + m_defDsName = defDevName; memset(&m_ds, 0, sizeof(TW_IDENTITY)); emit createTwainSrcUi(qt); @@ -314,7 +319,7 @@ void Manager::on_createTwainSrcUi(bool qt) qParent = m_TwainSrcUiparent; #endif - Dialog_Twain_Source_Select *dlg = new Dialog_Twain_Source_Select (m_dsmProc, &m_appId, qParent); + Dialog_Twain_Source_Select *dlg = new Dialog_Twain_Source_Select (m_vds, m_defDsName, qParent); if (dlg->exec()) { dlg->GetIdentify(&m_ds); diff --git a/modules/twainui/Manager.h b/modules/twainui/Manager.h index 9d424415..d8055d38 100644 --- a/modules/twainui/Manager.h +++ b/modules/twainui/Manager.h @@ -19,7 +19,7 @@ public: int showSettingUi(bool qt, SANE_Handle device, HWND settingUiParent, LPSANEAPI api, const char *devName, bool with_scan, std::function callback); int showProgressUi(bool qt, HWND parent, std::function callback, std::function *notify); int showMessageBoxUi(bool qt, HWND parent, int event, void *msg, int flag); - int showTwainSrcUi(bool qt, DSMENTRYPROC dsmProc, const TW_IDENTITY *appId, HGWindow parent, TW_IDENTITY *ds); + int showTwainSrcUi(bool qt, DSMENTRYPROC dsmProc, const TW_IDENTITY *vds, HGUInt count, const char* defDevName, HGWindow parent, TW_IDENTITY *ds); void closeDeviceSelectUi(); void closeSettingUi(); @@ -91,7 +91,8 @@ private: unsigned long m_twainSrcUiThreadId; DSMENTRYPROC m_dsmProc; - TW_IDENTITY m_appId; + std::vector m_vds; + std::string m_defDsName; HGWindow m_TwainSrcUiparent; TW_IDENTITY m_ds; }; diff --git a/modules/twainui/dialog_twain_source_select.cpp b/modules/twainui/dialog_twain_source_select.cpp index 3c9943b6..9e285a6e 100644 --- a/modules/twainui/dialog_twain_source_select.cpp +++ b/modules/twainui/dialog_twain_source_select.cpp @@ -1,53 +1,33 @@ #include "dialog_twain_source_select.h" #include "ui_dialog_twain_source_select.h" -Dialog_Twain_Source_Select::Dialog_Twain_Source_Select(DSMENTRYPROC dsmProc, const TW_IDENTITY *appId, QWidget *parent) : +Dialog_Twain_Source_Select::Dialog_Twain_Source_Select(const std::vector &vds, + const std::string &defDSName, QWidget *parent) : QDialog(parent), ui(new Ui::Dialog_Twain_Source_Select) { ui->setupUi(this); - m_vSource.clear(); - m_dsmProc = dsmProc; - memcpy(&m_appId, appId, sizeof(TW_IDENTITY)); + m_vSource = vds; memset(&m_ds, 0, sizeof(TW_IDENTITY)); setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); - TW_IDENTITY ds; - if (TWRC_SUCCESS == m_dsmProc(&m_appId, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETFIRST, &ds)) + for (int i = 0; i < m_vSource.size(); ++i) { - m_vSource.push_back(ds); char name[256]; - sprintf(name, "%s %u.%u", ds.ProductName, ds.Version.MajorNum, ds.Version.MinorNum); + sprintf(name, "%s %u.%u", m_vSource[i].ProductName, m_vSource[i].Version.MajorNum, m_vSource[i].Version.MinorNum); ui->listWidget->addItem(name); - while (TWRC_SUCCESS == m_dsmProc(&m_appId, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETNEXT, &ds)) + + if (0 == strcmp(m_vSource[i].ProductName, defDSName.c_str())) { - m_vSource.push_back(ds); - char name[256]; - sprintf(name, "%s %u.%u", ds.ProductName, ds.Version.MajorNum, ds.Version.MinorNum); - ui->listWidget->addItem(name); + ui->listWidget->setCurrentItem(ui->listWidget->item(i)); } } - QString source = getCfgValue("twain", "source", QString("")); - if (!source.isEmpty()) - { - int count = ui->listWidget->count(); - for (int i = 0; i < count; ++i) - { - filterTwainSource(i); - - if (ui->listWidget->item(i)->text() == source) - { - ui->listWidget->setCurrentItem(ui->listWidget->item(i)); - } - } - } - else - { + QListWidgetItem *item = ui->listWidget->currentItem(); + if (item == nullptr) ui->listWidget->setCurrentRow(0); - } } Dialog_Twain_Source_Select::~Dialog_Twain_Source_Select() @@ -68,56 +48,8 @@ void Dialog_Twain_Source_Select::keyPressEvent(QKeyEvent *e) } } -void Dialog_Twain_Source_Select::filterTwainSource(int index) -{ -#if !defined(OEM_HANWANG) && !defined(OEM_LISICHENG) && !defined(OEM_CANGTIAN) && !defined(OEM_ZHONGJING) && !defined(OEM_ZIGUANG) && !defined(OEM_NEUTRAL) - if (!ui->listWidget->item(index)->text().contains("HUAGOSCAN")) - { - ui->listWidget->item(index)->setHidden(true); - } -#elif defined(OEM_HANWANG) - { - if (!ui->listWidget->item(index)->text().contains("Hanvon")) - { - ui->listWidget->item(index)->setHidden(true); - } - } -#elif defined(OEM_LISICHENG) - { - if (!ui->listWidget->item(index)->text().contains("LANXUMSCAN")) - { - ui->listWidget->item(index)->setHidden(true); - } - } -#elif defined(OEM_CANGTIAN) - { - if (!ui->listWidget->item(index)->text().contains("CUMTENN")) - { - ui->listWidget->item(index)->setHidden(true); - } - } -#elif defined(OEM_ZHONGJING) - { - if (!ui->listWidget->item(index)->text().contains("Microtek")) - { - ui->listWidget->item(index)->setHidden(true); - } - } -#elif defined(OEM_ZIGUANG) - { - if (!ui->listWidget->item(index)->text().contains("Uniscan")) - { - ui->listWidget->item(index)->setHidden(true); - } - } -#endif -} - void Dialog_Twain_Source_Select::on_pushButton_OK_clicked() { - QString source = ui->listWidget->currentItem()->text(); - saveCfgValue("twain", "source", source); - int index = ui->listWidget->currentRow(); if (index < 0) { diff --git a/modules/twainui/dialog_twain_source_select.h b/modules/twainui/dialog_twain_source_select.h index bfcae556..c1e24bc7 100644 --- a/modules/twainui/dialog_twain_source_select.h +++ b/modules/twainui/dialog_twain_source_select.h @@ -4,7 +4,6 @@ #include "base/HGDef.h" #include "base/HGInc.h" #include "twain/twain.h" -#include "app_cfg.h" #include #include #include @@ -18,7 +17,8 @@ class Dialog_Twain_Source_Select : public QDialog Q_OBJECT public: - explicit Dialog_Twain_Source_Select(DSMENTRYPROC dsmProc, const TW_IDENTITY *appId, QWidget *parent = nullptr); + explicit Dialog_Twain_Source_Select(const std::vector &vds, + const std::string &defDSName, QWidget *parent = nullptr); ~Dialog_Twain_Source_Select(); void GetIdentify(TW_IDENTITY *ds); @@ -26,9 +26,6 @@ public: protected: void keyPressEvent(QKeyEvent *e) override; -private: - void filterTwainSource(int index); - private slots: void on_pushButton_OK_clicked(); @@ -39,8 +36,6 @@ private slots: private: Ui::Dialog_Twain_Source_Select *ui; std::vector m_vSource; - DSMENTRYPROC m_dsmProc; - TW_IDENTITY m_appId; TW_IDENTITY m_ds; }; diff --git a/modules/twainui/twainui.cpp b/modules/twainui/twainui.cpp index ae36dff7..0ab561d5 100644 --- a/modules/twainui/twainui.cpp +++ b/modules/twainui/twainui.cpp @@ -159,7 +159,7 @@ int show_messagebox_ui(HWND parent, int event, void *msg, int flag) return g_manager->showMessageBoxUi(nullptr == g_hThread, parent, event, msg, flag); } -int show_twain_srclist_ui(DSMENTRYPROC dsmProc, const TW_IDENTITY *appId, HGWindow parent, TW_IDENTITY *ds) +int show_twain_srclist_ui(DSMENTRYPROC dsmProc, const TW_IDENTITY *vds, HGUInt count, const HGChar *defDsName, HGWindow parent, TW_IDENTITY *ds) { if (!qApp) { @@ -173,7 +173,7 @@ int show_twain_srclist_ui(DSMENTRYPROC dsmProc, const TW_IDENTITY *appId, HGWind g_manager = new Manager; } - return g_manager->showTwainSrcUi(nullptr == g_hThread, dsmProc, appId, parent, ds); + return g_manager->showTwainSrcUi(nullptr == g_hThread, dsmProc, vds, count, defDsName, parent, ds); } int close_ui(int which)