添加默认打开设备功能
This commit is contained in:
parent
17af787413
commit
2640e432bd
|
@ -29,6 +29,21 @@ class DeviceUser* DeviceUserMgr::OpenDeviceUser()
|
||||||
return new DeviceUser(m_wnd, ds, m_password);
|
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)
|
DeviceUser::DeviceUser(QWidget *wnd, HGTwainDS ds, QString password)
|
||||||
{
|
{
|
||||||
m_wnd = wnd;
|
m_wnd = wnd;
|
||||||
|
|
|
@ -17,6 +17,7 @@ public:
|
||||||
|
|
||||||
// 弹出设备选择对话框,选择twain源
|
// 弹出设备选择对话框,选择twain源
|
||||||
class DeviceUser* OpenDeviceUser();
|
class DeviceUser* OpenDeviceUser();
|
||||||
|
class DeviceUser* OpenDefaultDeviceUser();
|
||||||
|
|
||||||
private:
|
private:
|
||||||
QWidget *m_wnd;
|
QWidget *m_wnd;
|
||||||
|
|
|
@ -349,9 +349,6 @@ MainWindow::MainWindow(const QString& appLang, QWidget *parent)
|
||||||
else
|
else
|
||||||
m_password = passwordDecrypt(password);
|
m_password = passwordDecrypt(password);
|
||||||
|
|
||||||
m_devUserMgr = new DeviceUserMgr(m_password, this);
|
|
||||||
m_devUser = nullptr;
|
|
||||||
|
|
||||||
m_dlgFullScreen = nullptr;
|
m_dlgFullScreen = nullptr;
|
||||||
ui->act_autoSave->setChecked(getCfgValue("save", "autoSave", false));
|
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(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)));
|
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();
|
updateSideBar();
|
||||||
updateActionStatus();
|
updateActionStatus();
|
||||||
}
|
}
|
||||||
|
@ -3791,27 +3797,23 @@ void MainWindow::on_act_selectDevice_triggered()
|
||||||
m_versionDll->PostUserLogoutInfo(HGVERSION_APPNAME_SCANNER, m_oemName);
|
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();
|
DeviceUser *devUser = m_devUserMgr->OpenDeviceUser();
|
||||||
if (devUser != nullptr)
|
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_devUser = devUser;
|
||||||
m_wndStatusBar->setDeviceStatusInfo(tr("Device %1 is open").arg(m_devUser->GetName()), false);
|
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, SIGNAL(newImage(void*)), this, SLOT(on_newImage(void*)), Qt::DirectConnection);
|
||||||
connect(m_devUser, &DeviceUser::scanEvent, this, &MainWindow::on_scanEvent, Qt::QueuedConnection);
|
connect(m_devUser, &DeviceUser::scanEvent, this, &MainWindow::on_scanEvent, Qt::QueuedConnection);
|
||||||
updateActionStatus();
|
|
||||||
}
|
|
||||||
else
|
|
||||||
{
|
|
||||||
QMessageBox::information(this, tr("Prompt"), tr("Open device failed"));
|
|
||||||
}
|
}
|
||||||
|
|
||||||
|
updateActionStatus();
|
||||||
}
|
}
|
||||||
|
|
|
@ -31,12 +31,16 @@ win32 {
|
||||||
SOURCES += \
|
SOURCES += \
|
||||||
../../../modules/twain_user/HGTwain.cpp \
|
../../../modules/twain_user/HGTwain.cpp \
|
||||||
../../../modules/twain_user/HGTwainImpl.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 += \
|
HEADERS += \
|
||||||
../../../modules/twain_user/HGTwain.h \
|
../../../modules/twain_user/HGTwain.h \
|
||||||
../../../modules/twain_user/HGTwainErr.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
|
MY_OS = windows
|
||||||
TARGET = $${OEM_PREFIX}TwainUser
|
TARGET = $${OEM_PREFIX}TwainUser
|
||||||
|
@ -103,6 +107,7 @@ unix {
|
||||||
}
|
}
|
||||||
|
|
||||||
INCLUDEPATH += $$PWD/../../../modules
|
INCLUDEPATH += $$PWD/../../../modules
|
||||||
|
INCLUDEPATH += $$PWD/../../../utility
|
||||||
INCLUDEPATH += $$PWD/../../../../sdk/include
|
INCLUDEPATH += $$PWD/../../../../sdk/include
|
||||||
|
|
||||||
DESTDIR = $$PWD/../../build/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE}
|
DESTDIR = $$PWD/../../build/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE}
|
||||||
|
|
|
@ -4,4 +4,7 @@
|
||||||
/* 一般错误 */
|
/* 一般错误 */
|
||||||
#define HGTWAIN_ERR_FAIL 0x00001001L
|
#define HGTWAIN_ERR_FAIL 0x00001001L
|
||||||
|
|
||||||
#endif /* __HGTWAINERR_H__ */
|
/* UI取消操作 */
|
||||||
|
#define HGTWAIN_ERR_CANCELUI 0x00001002L
|
||||||
|
|
||||||
|
#endif /* __HGTWAINERR_H__ */
|
||||||
|
|
|
@ -1,6 +1,7 @@
|
||||||
#include "HGTwainImpl.hpp"
|
#include "HGTwainImpl.hpp"
|
||||||
#include "../base/HGInc.h"
|
#include "../base/HGInc.h"
|
||||||
#include "../base/HGInfo.h"
|
#include "../base/HGInfo.h"
|
||||||
|
#include "app_cfg.h"
|
||||||
|
|
||||||
std::map<HWND, HGTwainDSMImpl*> HGTwainDSMImpl::m_mapWnd;
|
std::map<HWND, HGTwainDSMImpl*> HGTwainDSMImpl::m_mapWnd;
|
||||||
|
|
||||||
|
@ -24,6 +25,7 @@ HGTwainDSMImpl::HGTwainDSMImpl()
|
||||||
|
|
||||||
m_hWnd = NULL;
|
m_hWnd = NULL;
|
||||||
m_oldWndProc = NULL;
|
m_oldWndProc = NULL;
|
||||||
|
m_vds.clear();
|
||||||
}
|
}
|
||||||
|
|
||||||
HGTwainDSMImpl::~HGTwainDSMImpl()
|
HGTwainDSMImpl::~HGTwainDSMImpl()
|
||||||
|
@ -72,6 +74,19 @@ HGResult HGTwainDSMImpl::Create(HWND hwnd)
|
||||||
m_hWnd = hwnd;
|
m_hWnd = hwnd;
|
||||||
m_mapWnd[m_hWnd] = this;
|
m_mapWnd[m_hWnd] = this;
|
||||||
m_oldWndProc = (WNDPROC)SetWindowLongPtrW(m_hWnd, GWLP_WNDPROC, (LONG_PTR)NewWndProc);
|
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;
|
return HGBASE_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -84,6 +99,8 @@ HGResult HGTwainDSMImpl::Destroy()
|
||||||
return HGBASE_ERR_FAIL;
|
return HGBASE_ERR_FAIL;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
m_vds.clear();
|
||||||
|
|
||||||
m_pDSMProc(&m_AppId, NULL, DG_CONTROL, DAT_PARENT, MSG_CLOSEDSM, (TW_MEMREF)&m_hWnd);
|
m_pDSMProc(&m_AppId, NULL, DG_CONTROL, DAT_PARENT, MSG_CLOSEDSM, (TW_MEMREF)&m_hWnd);
|
||||||
SetWindowLongPtrW(m_hWnd, GWLP_WNDPROC, (LONG_PTR)m_oldWndProc);
|
SetWindowLongPtrW(m_hWnd, GWLP_WNDPROC, (LONG_PTR)m_oldWndProc);
|
||||||
m_oldWndProc = NULL;
|
m_oldWndProc = NULL;
|
||||||
|
@ -111,18 +128,7 @@ HGResult HGTwainDSMImpl::GetDSCount(HGUInt* count)
|
||||||
return HGBASE_ERR_INVALIDARG;
|
return HGBASE_ERR_INVALIDARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
HGUInt num = 0;
|
*count = m_vds.size();
|
||||||
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;
|
|
||||||
return HGBASE_ERR_OK;
|
return HGBASE_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -133,23 +139,12 @@ HGResult HGTwainDSMImpl::GetDSName(HGUInt index, HGChar* name, HGUInt maxLen)
|
||||||
return HGBASE_ERR_INVALIDARG;
|
return HGBASE_ERR_INVALIDARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<TW_IDENTITY> vds;
|
if (index >= (HGUInt)m_vds.size())
|
||||||
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())
|
|
||||||
return HGBASE_ERR_INVALIDARG;
|
return HGBASE_ERR_INVALIDARG;
|
||||||
|
|
||||||
if (maxLen < strlen(vds[index].ProductName) + 1)
|
if (maxLen < strlen(m_vds[index].ProductName) + 1)
|
||||||
return HGBASE_ERR_FAIL;
|
return HGBASE_ERR_FAIL;
|
||||||
strcpy(name, vds[index].ProductName);
|
strcpy(name, m_vds[index].ProductName);
|
||||||
return HGBASE_ERR_OK;
|
return HGBASE_ERR_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -160,28 +155,18 @@ HGResult HGTwainDSMImpl::OpenDS(HGUInt index, class HGTwainDSImpl** dsImpl)
|
||||||
return HGBASE_ERR_INVALIDARG;
|
return HGBASE_ERR_INVALIDARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
std::vector<TW_IDENTITY> vds;
|
if (index >= (HGUInt)m_vds.size())
|
||||||
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())
|
|
||||||
return HGBASE_ERR_INVALIDARG;
|
return HGBASE_ERR_INVALIDARG;
|
||||||
|
|
||||||
class HGTwainDSImpl* newDSImpl = new HGTwainDSImpl(this);
|
class HGTwainDSImpl* newDSImpl = new HGTwainDSImpl(this);
|
||||||
HGResult ret = newDSImpl->Open(&vds[index]);
|
HGResult ret = newDSImpl->Open(&m_vds[index]);
|
||||||
if (HGBASE_ERR_OK != ret)
|
if (HGBASE_ERR_OK != ret)
|
||||||
{
|
{
|
||||||
delete newDSImpl;
|
delete newDSImpl;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
saveCfgValue("twain", "source", m_vds[index].ProductName);
|
||||||
m_listDSImpl.push_back(newDSImpl);
|
m_listDSImpl.push_back(newDSImpl);
|
||||||
*dsImpl = newDSImpl;
|
*dsImpl = newDSImpl;
|
||||||
return HGBASE_ERR_OK;
|
return HGBASE_ERR_OK;
|
||||||
|
@ -192,22 +177,39 @@ HGResult HGTwainDSMImpl::OpenDefaultDS(class HGTwainDSImpl** dsImpl)
|
||||||
if (NULL == dsImpl)
|
if (NULL == dsImpl)
|
||||||
{
|
{
|
||||||
return HGBASE_ERR_INVALIDARG;
|
return HGBASE_ERR_INVALIDARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
TW_IDENTITY defDS;
|
if (m_vds.empty())
|
||||||
if (TWRC_SUCCESS != m_pDSMProc(&m_AppId, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETDEFAULT, &defDS))
|
{
|
||||||
{
|
return HGBASE_ERR_FAIL;
|
||||||
return HGTWAIN_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);
|
class HGTwainDSImpl* newDSImpl = new HGTwainDSImpl(this);
|
||||||
HGResult ret = newDSImpl->Open(&defDS);
|
HGResult ret = newDSImpl->Open(&m_vds[0]);
|
||||||
if (HGBASE_ERR_OK != ret)
|
if (HGBASE_ERR_OK != ret)
|
||||||
{
|
{
|
||||||
delete newDSImpl;
|
delete newDSImpl;
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
saveCfgValue("twain", "source", m_vds[index].ProductName);
|
||||||
m_listDSImpl.push_back(newDSImpl);
|
m_listDSImpl.push_back(newDSImpl);
|
||||||
*dsImpl = newDSImpl;
|
*dsImpl = newDSImpl;
|
||||||
return HGBASE_ERR_OK;
|
return HGBASE_ERR_OK;
|
||||||
|
@ -234,6 +236,7 @@ HGResult HGTwainDSMImpl::OpenSelectedDS(class HGTwainDSImpl** dsImpl)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
saveCfgValue("twain", "source", selectDS.ProductName);
|
||||||
m_listDSImpl.push_back(newDSImpl);
|
m_listDSImpl.push_back(newDSImpl);
|
||||||
*dsImpl = newDSImpl;
|
*dsImpl = newDSImpl;
|
||||||
return HGBASE_ERR_OK;
|
return HGBASE_ERR_OK;
|
||||||
|
@ -246,16 +249,18 @@ HGResult HGTwainDSMImpl::OpenSelectedDSEx(class HGTwainDSImpl** dsImpl)
|
||||||
return HGBASE_ERR_INVALIDARG;
|
return HGBASE_ERR_INVALIDARG;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
std::string sourceName = getCfgValue("twain", "source", std::string(""));
|
||||||
|
|
||||||
TW_IDENTITY selectDS;
|
TW_IDENTITY selectDS;
|
||||||
memset(&selectDS, 0, sizeof(TW_IDENTITY));
|
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;
|
return HGBASE_ERR_NOTSUPPORT;
|
||||||
}
|
}
|
||||||
|
|
||||||
if (0 == selectDS.Id)
|
if (0 == selectDS.Id)
|
||||||
{
|
{
|
||||||
return HGBASE_ERR_FAIL;
|
return HGTWAIN_ERR_CANCELUI;
|
||||||
}
|
}
|
||||||
|
|
||||||
class HGTwainDSImpl* newDSImpl = new HGTwainDSImpl(this);
|
class HGTwainDSImpl* newDSImpl = new HGTwainDSImpl(this);
|
||||||
|
@ -266,6 +271,7 @@ HGResult HGTwainDSMImpl::OpenSelectedDSEx(class HGTwainDSImpl** dsImpl)
|
||||||
return ret;
|
return ret;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
saveCfgValue("twain", "source", selectDS.ProductName);
|
||||||
m_listDSImpl.push_back(newDSImpl);
|
m_listDSImpl.push_back(newDSImpl);
|
||||||
*dsImpl = newDSImpl;
|
*dsImpl = newDSImpl;
|
||||||
return HGBASE_ERR_OK;
|
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);
|
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)
|
HGTwainDSImpl::HGTwainDSImpl(HGTwainDSMImpl* dsmImpl)
|
||||||
{
|
{
|
||||||
|
|
|
@ -29,6 +29,7 @@ public:
|
||||||
private:
|
private:
|
||||||
void RemoveDS(class HGTwainDSImpl* dsImpl);
|
void RemoveDS(class HGTwainDSImpl* dsImpl);
|
||||||
static LRESULT CALLBACK NewWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
static LRESULT CALLBACK NewWndProc(HWND hWnd, UINT msg, WPARAM wParam, LPARAM lParam);
|
||||||
|
bool filterTwainSource(const char* sourceName);
|
||||||
|
|
||||||
private:
|
private:
|
||||||
HGDll m_hDll;
|
HGDll m_hDll;
|
||||||
|
@ -37,6 +38,7 @@ private:
|
||||||
HWND m_hWnd;
|
HWND m_hWnd;
|
||||||
static std::map<HWND, HGTwainDSMImpl*> m_mapWnd;
|
static std::map<HWND, HGTwainDSMImpl*> m_mapWnd;
|
||||||
WNDPROC m_oldWndProc;
|
WNDPROC m_oldWndProc;
|
||||||
|
std::vector<TW_IDENTITY> m_vds;
|
||||||
std::vector<class HGTwainDSImpl *> m_listDSImpl;
|
std::vector<class HGTwainDSImpl *> m_listDSImpl;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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());
|
||||||
|
}
|
|
@ -0,0 +1,9 @@
|
||||||
|
#ifndef __APP_CFG_H__
|
||||||
|
#define __APP_CFG_H__
|
||||||
|
|
||||||
|
#include <string>
|
||||||
|
|
||||||
|
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__ */
|
|
@ -125,14 +125,19 @@ int Manager::showMessageBoxUi(bool qt, HWND parent, int event, void *msg, int fl
|
||||||
return 0;
|
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_twainSrcUiThreadId = GetCurrentThreadId();
|
||||||
|
|
||||||
m_TwainSrcUiparent = parent;
|
m_TwainSrcUiparent = parent;
|
||||||
m_dsmProc = dsmProc;
|
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));
|
memset(&m_ds, 0, sizeof(TW_IDENTITY));
|
||||||
|
|
||||||
emit createTwainSrcUi(qt);
|
emit createTwainSrcUi(qt);
|
||||||
|
@ -314,7 +319,7 @@ void Manager::on_createTwainSrcUi(bool qt)
|
||||||
qParent = m_TwainSrcUiparent;
|
qParent = m_TwainSrcUiparent;
|
||||||
#endif
|
#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())
|
if (dlg->exec())
|
||||||
{
|
{
|
||||||
dlg->GetIdentify(&m_ds);
|
dlg->GetIdentify(&m_ds);
|
||||||
|
|
|
@ -19,7 +19,7 @@ public:
|
||||||
int showSettingUi(bool qt, SANE_Handle device, HWND settingUiParent, LPSANEAPI api, const char *devName, bool with_scan, std::function<void(ui_result)> callback);
|
int showSettingUi(bool qt, SANE_Handle device, HWND settingUiParent, LPSANEAPI api, const char *devName, bool with_scan, std::function<void(ui_result)> callback);
|
||||||
int showProgressUi(bool qt, HWND parent, std::function<void (ui_result)> callback, std::function<void (int, void *, int)> *notify);
|
int showProgressUi(bool qt, HWND parent, std::function<void (ui_result)> callback, std::function<void (int, void *, int)> *notify);
|
||||||
int showMessageBoxUi(bool qt, HWND parent, int event, void *msg, int flag);
|
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 closeDeviceSelectUi();
|
||||||
void closeSettingUi();
|
void closeSettingUi();
|
||||||
|
@ -91,7 +91,8 @@ private:
|
||||||
|
|
||||||
unsigned long m_twainSrcUiThreadId;
|
unsigned long m_twainSrcUiThreadId;
|
||||||
DSMENTRYPROC m_dsmProc;
|
DSMENTRYPROC m_dsmProc;
|
||||||
TW_IDENTITY m_appId;
|
std::vector<TW_IDENTITY> m_vds;
|
||||||
|
std::string m_defDsName;
|
||||||
HGWindow m_TwainSrcUiparent;
|
HGWindow m_TwainSrcUiparent;
|
||||||
TW_IDENTITY m_ds;
|
TW_IDENTITY m_ds;
|
||||||
};
|
};
|
||||||
|
|
|
@ -1,53 +1,33 @@
|
||||||
#include "dialog_twain_source_select.h"
|
#include "dialog_twain_source_select.h"
|
||||||
#include "ui_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<TW_IDENTITY> &vds,
|
||||||
|
const std::string &defDSName, QWidget *parent) :
|
||||||
QDialog(parent),
|
QDialog(parent),
|
||||||
ui(new Ui::Dialog_Twain_Source_Select)
|
ui(new Ui::Dialog_Twain_Source_Select)
|
||||||
{
|
{
|
||||||
ui->setupUi(this);
|
ui->setupUi(this);
|
||||||
|
|
||||||
m_vSource.clear();
|
m_vSource = vds;
|
||||||
m_dsmProc = dsmProc;
|
|
||||||
memcpy(&m_appId, appId, sizeof(TW_IDENTITY));
|
|
||||||
memset(&m_ds, 0, sizeof(TW_IDENTITY));
|
memset(&m_ds, 0, sizeof(TW_IDENTITY));
|
||||||
|
|
||||||
setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
|
setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint);
|
||||||
|
|
||||||
TW_IDENTITY ds;
|
for (int i = 0; i < m_vSource.size(); ++i)
|
||||||
if (TWRC_SUCCESS == m_dsmProc(&m_appId, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETFIRST, &ds))
|
|
||||||
{
|
{
|
||||||
m_vSource.push_back(ds);
|
|
||||||
char name[256];
|
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);
|
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);
|
ui->listWidget->setCurrentItem(ui->listWidget->item(i));
|
||||||
char name[256];
|
|
||||||
sprintf(name, "%s %u.%u", ds.ProductName, ds.Version.MajorNum, ds.Version.MinorNum);
|
|
||||||
ui->listWidget->addItem(name);
|
|
||||||
}
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
QString source = getCfgValue("twain", "source", QString(""));
|
QListWidgetItem *item = ui->listWidget->currentItem();
|
||||||
if (!source.isEmpty())
|
if (item == nullptr)
|
||||||
{
|
|
||||||
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
|
|
||||||
{
|
|
||||||
ui->listWidget->setCurrentRow(0);
|
ui->listWidget->setCurrentRow(0);
|
||||||
}
|
|
||||||
}
|
}
|
||||||
|
|
||||||
Dialog_Twain_Source_Select::~Dialog_Twain_Source_Select()
|
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()
|
void Dialog_Twain_Source_Select::on_pushButton_OK_clicked()
|
||||||
{
|
{
|
||||||
QString source = ui->listWidget->currentItem()->text();
|
|
||||||
saveCfgValue("twain", "source", source);
|
|
||||||
|
|
||||||
int index = ui->listWidget->currentRow();
|
int index = ui->listWidget->currentRow();
|
||||||
if (index < 0)
|
if (index < 0)
|
||||||
{
|
{
|
||||||
|
|
|
@ -4,7 +4,6 @@
|
||||||
#include "base/HGDef.h"
|
#include "base/HGDef.h"
|
||||||
#include "base/HGInc.h"
|
#include "base/HGInc.h"
|
||||||
#include "twain/twain.h"
|
#include "twain/twain.h"
|
||||||
#include "app_cfg.h"
|
|
||||||
#include <QDialog>
|
#include <QDialog>
|
||||||
#include <QListWidgetItem>
|
#include <QListWidgetItem>
|
||||||
#include <QKeyEvent>
|
#include <QKeyEvent>
|
||||||
|
@ -18,7 +17,8 @@ class Dialog_Twain_Source_Select : public QDialog
|
||||||
Q_OBJECT
|
Q_OBJECT
|
||||||
|
|
||||||
public:
|
public:
|
||||||
explicit Dialog_Twain_Source_Select(DSMENTRYPROC dsmProc, const TW_IDENTITY *appId, QWidget *parent = nullptr);
|
explicit Dialog_Twain_Source_Select(const std::vector<TW_IDENTITY> &vds,
|
||||||
|
const std::string &defDSName, QWidget *parent = nullptr);
|
||||||
~Dialog_Twain_Source_Select();
|
~Dialog_Twain_Source_Select();
|
||||||
|
|
||||||
void GetIdentify(TW_IDENTITY *ds);
|
void GetIdentify(TW_IDENTITY *ds);
|
||||||
|
@ -26,9 +26,6 @@ public:
|
||||||
protected:
|
protected:
|
||||||
void keyPressEvent(QKeyEvent *e) override;
|
void keyPressEvent(QKeyEvent *e) override;
|
||||||
|
|
||||||
private:
|
|
||||||
void filterTwainSource(int index);
|
|
||||||
|
|
||||||
private slots:
|
private slots:
|
||||||
void on_pushButton_OK_clicked();
|
void on_pushButton_OK_clicked();
|
||||||
|
|
||||||
|
@ -39,8 +36,6 @@ private slots:
|
||||||
private:
|
private:
|
||||||
Ui::Dialog_Twain_Source_Select *ui;
|
Ui::Dialog_Twain_Source_Select *ui;
|
||||||
std::vector<TW_IDENTITY> m_vSource;
|
std::vector<TW_IDENTITY> m_vSource;
|
||||||
DSMENTRYPROC m_dsmProc;
|
|
||||||
TW_IDENTITY m_appId;
|
|
||||||
TW_IDENTITY m_ds;
|
TW_IDENTITY m_ds;
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
|
@ -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);
|
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)
|
if (!qApp)
|
||||||
{
|
{
|
||||||
|
@ -173,7 +173,7 @@ int show_twain_srclist_ui(DSMENTRYPROC dsmProc, const TW_IDENTITY *appId, HGWind
|
||||||
g_manager = new Manager;
|
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)
|
int close_ui(int which)
|
||||||
|
|
Loading…
Reference in New Issue