HGSaneUI中实现twain源选择对话框

This commit is contained in:
luoliangyi 2023-04-04 13:18:13 +08:00
parent 21f91712ac
commit 35ca04e7ab
21 changed files with 346 additions and 50 deletions

View File

@ -18,7 +18,7 @@ DeviceUserMgr::~DeviceUserMgr()
class DeviceUser* DeviceUserMgr::OpenDeviceUser()
{
HGTwainDS ds = nullptr;
HGTwain_OpenSelectedDS(m_twainDSM, &ds);
HGTwain_OpenSelectedDSEx(m_twainDSM, &ds);
if (nullptr == ds)
return nullptr;
return new DeviceUser(m_wnd, ds);

View File

@ -6,3 +6,4 @@ show_srclist_ui
show_devlist_ui
show_setting_ui
show_scan_ui
show_twain_srclist_ui

View File

@ -66,9 +66,14 @@ win32 {
SOURCES += ../../../modules/saneui/qmfcapp.cpp
SOURCES += ../../../modules/saneui/qwinhost.cpp
SOURCES += ../../../modules/saneui/qwinwidget.cpp
SOURCES += ../../../modules/saneui/dialog_twain_source_select.cpp
HEADERS += ../../../modules/saneui/qmfcapp.hpp
HEADERS += ../../../modules/saneui/qwinhost.hpp
HEADERS += ../../../modules/saneui/qwinwidget.hpp
HEADERS += ../../../modules/saneui/dialog_twain_source_select.h
FORMS += ../../../modules/saneui/dialog_twain_source_select.ui
MY_OS = windows
TARGET = $${OEM_PREFIX}SaneUI

View File

@ -32,7 +32,8 @@ HGSaneUser.depends = \
HGSaneUI
HGTwainUser.depends = \
HGBase
HGBase \
HGSaneUI
HGVersion.depends = \
HGBase

View File

@ -9,6 +9,7 @@ HGTwain_GetDSNameWithIndex
HGTwain_OpenDS
HGTwain_OpenDefaultDS
HGTwain_OpenSelectedDS
HGTwain_OpenSelectedDSEx
HGTwain_CloseDS
HGTwain_GetDSName
HGTwain_EnableDSUIOnly

View File

@ -94,7 +94,7 @@ win32 {
DEF_FILE = HGTwainUser.def
LIBS += -lgdi32 -lgdiplus -ldbghelp -luser32
LIBS += -L$$PWD/../../build/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE} -l$${OEM_PREFIX}Base
LIBS += -L$$PWD/../../build/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE} -l$${OEM_PREFIX}Base -l$${OEM_PREFIX}SaneUI
}
unix {
@ -131,11 +131,11 @@ unix {
QMAKE_LFLAGS += -z defs -B direct
LIBS += -lpthread -ldl
LIBS += -L$$PWD/../../build/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE} -l$${OEM_PREFIX2}Base
LIBS += -L$$PWD/../../build/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE} -l$${OEM_PREFIX2}Base -l$${OEM_PREFIX2}SaneUI
}
INCLUDEPATH += $$PWD/../../../modules
INCLUDEPATH += $$PWD/../../../third_party/twain
INCLUDEPATH += $$PWD/../../../../sdk/include
DESTDIR = $$PWD/../../build/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE}
UI_DIR = $$PWD/../../temp/$${MY_OS}/$${OEM_NAME}/$${MY_ARCH}/$${MY_CONFIGURE}/$${TARGET}

View File

@ -2,6 +2,7 @@
#include "dialog_source_select.h"
#include "dialog_device_select.h"
#include "dialog_device_scan.h"
#include "dialog_twain_source_select.h"
#include "hg_settingdialog.h"
#include "lang/app_language.h"
#include <QMessageBox>
@ -161,3 +162,40 @@ int show_scan_ui(const SANEAPI* saneApi, SANE_Handle handle, const char *devName
QCoreApplication::removeTranslator(&translator);
return 0;
}
#if defined(HG_CMP_MSC)
int show_twain_srclist_ui(DSMENTRYPROC dsmProc, const TW_IDENTITY *appId, HGWindow parent, TW_IDENTITY *ds)
{
if (nullptr == dsmProc || nullptr == appId || nullptr == ds)
return -1;
QWidget *qParent = nullptr;
#ifdef HG_CMP_MSC
if (!g_ownApplication)
g_ownApplication = QMfcApp::pluginInstance(g_hInst);
QWinWidget win(parent);
win.showCentered();
qParent = &win;
#else
qParent = parent;
#endif
QTranslator translator;
int cp = lang_get_cur_code_page();
if (20127 == cp)
translator.load(":translation/SaneUI_zh_EN.qm");
else
translator.load(":translation/SaneUI_zh_CN.qm");
QCoreApplication::installTranslator(&translator);
memset(ds, 0, sizeof(TW_IDENTITY));
Dialog_Twain_Source_Select dlg(dsmProc, appId, qParent);
if (dlg.exec())
{
dlg.GetIdentify(ds);
}
QCoreApplication::removeTranslator(&translator);
return 0;
}
#endif

View File

@ -4,6 +4,9 @@
#include "../base/HGDef.h"
#include "../base/HGDll.h"
#include "sane/sane_ex.h"
#if defined(HG_CMP_MSC)
#include "twain/twain.h"
#endif
typedef void (*show_scan_ui_image_callback)(const SANE_Parameters *imageFormat, const SANE_Byte *imageData, void * callbackParam);
@ -14,4 +17,8 @@ HGEXPORT int show_setting_ui(const SANEAPI* saneApi, SANE_Handle handle, const c
HGEXPORT int show_scan_ui(const SANEAPI* saneApi, SANE_Handle handle, const char *devName, HGWindow parent,
show_scan_ui_image_callback callback, void *callbackParam);
#if defined(HG_CMP_MSC)
HGEXPORT int show_twain_srclist_ui(DSMENTRYPROC dsmProc, const TW_IDENTITY *appId, HGWindow parent, TW_IDENTITY *ds);
#endif
#endif

Binary file not shown.

View File

@ -1451,6 +1451,24 @@ Please make sure the two passwords are the same.</source>
<translation></translation>
</message>
</context>
<context>
<name>Dialog_Twain_Source_Select</name>
<message>
<location filename="dialog_twain_source_select.ui" line="14"/>
<source>Select source</source>
<translation></translation>
</message>
<message>
<location filename="dialog_twain_source_select.ui" line="42"/>
<source>OK</source>
<translation></translation>
</message>
<message>
<location filename="dialog_twain_source_select.ui" line="49"/>
<source>Cancel</source>
<translation></translation>
</message>
</context>
<context>
<name>Dialog_WriteSettings</name>
<message>

Binary file not shown.

View File

@ -1328,6 +1328,24 @@ Please make sure the two passwords are the same.</source>
<translation>Find function failed</translation>
</message>
</context>
<context>
<name>Dialog_Twain_Source_Select</name>
<message>
<location filename="dialog_twain_source_select.ui" line="14"/>
<source>Select source</source>
<translation>Select source</translation>
</message>
<message>
<location filename="dialog_twain_source_select.ui" line="42"/>
<source>OK</source>
<translation>OK</translation>
</message>
<message>
<location filename="dialog_twain_source_select.ui" line="49"/>
<source>Cancel</source>
<translation>Cancel</translation>
</message>
</context>
<context>
<name>Dialog_WriteSettings</name>
<message>

View File

@ -3,7 +3,6 @@
#include "base/HGDef.h"
#include "base/HGThread.h"
#include "sane/sane_ex.h"
#include "HGSaneUI.h"
#include <QDialog>

View File

@ -1,8 +1,7 @@
#ifndef DIALOG_DEVICE_SELECT_H
#define DIALOG_DEVICE_SELECT_H
#include "base/HGDef.h"
#include "sane/sane_ex.h"
#include "HGSaneUI.h"
#include <QDialog>
#include <string>
#include <vector>

View File

@ -0,0 +1,60 @@
#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) :
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));
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))
{
m_vSource.push_back(ds);
ui->listWidget->addItem(ds.ProductName);
while (TWRC_SUCCESS == m_dsmProc(&m_appId, NULL, DG_CONTROL, DAT_IDENTITY, MSG_GETNEXT, &ds))
{
m_vSource.push_back(ds);
ui->listWidget->addItem(ds.ProductName);
}
}
if (!m_vSource.empty())
{
ui->listWidget->setCurrentRow(0);
}
}
Dialog_Twain_Source_Select::~Dialog_Twain_Source_Select()
{
delete ui;
}
void Dialog_Twain_Source_Select::GetIdentify(TW_IDENTITY *ds)
{
memcpy(ds, &m_ds, sizeof(TW_IDENTITY));
}
void Dialog_Twain_Source_Select::on_pushButton_OK_clicked()
{
int index = ui->listWidget->currentRow();
if (index < 0)
{
return;
}
memcpy(&m_ds, &m_vSource[index], sizeof(TW_IDENTITY));
accept();
}
void Dialog_Twain_Source_Select::on_pushButton_Cancel_clicked()
{
reject();
}

View File

@ -0,0 +1,34 @@
#ifndef DIALOG_TWAIN_SOURCE_SELECT_H
#define DIALOG_TWAIN_SOURCE_SELECT_H
#include "HGSaneUI.h"
#include <QDialog>
namespace Ui {
class Dialog_Twain_Source_Select;
}
class Dialog_Twain_Source_Select : public QDialog
{
Q_OBJECT
public:
explicit Dialog_Twain_Source_Select(DSMENTRYPROC dsmProc, const TW_IDENTITY *appId, QWidget *parent = nullptr);
~Dialog_Twain_Source_Select();
void GetIdentify(TW_IDENTITY *ds);
private slots:
void on_pushButton_OK_clicked();
void on_pushButton_Cancel_clicked();
private:
Ui::Dialog_Twain_Source_Select *ui;
std::vector<TW_IDENTITY> m_vSource;
DSMENTRYPROC m_dsmProc;
TW_IDENTITY m_appId;
TW_IDENTITY m_ds;
};
#endif // DIALOG_TWAIN_SOURCE_SELECT_H

View File

@ -0,0 +1,59 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog_Twain_Source_Select</class>
<widget class="QDialog" name="Dialog_Twain_Source_Select">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>343</width>
<height>203</height>
</rect>
</property>
<property name="windowTitle">
<string>Select source</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<widget class="QListWidget" name="listWidget"/>
</item>
</layout>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout_2">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton_OK">
<property name="text">
<string>OK</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="pushButton_Cancel">
<property name="text">
<string>Cancel</string>
</property>
</widget>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -117,6 +117,25 @@ HGResult HGAPI HGTwain_OpenSelectedDS(HGTwainDSM dsm, HGTwainDS* ds)
return HGBASE_ERR_OK;
}
HGResult HGAPI HGTwain_OpenSelectedDSEx(HGTwainDSM dsm, HGTwainDS* ds)
{
if (NULL == dsm)
{
return HGBASE_ERR_INVALIDARG;
}
HGTwainDSMImpl* twainDSMImpl = (HGTwainDSMImpl*)dsm;
class HGTwainDSImpl* dsImpl = NULL;
HGResult ret = twainDSMImpl->OpenSelectedDSEx(&dsImpl);
if (HGBASE_ERR_OK != ret)
{
return ret;
}
*ds = (HGTwainDS)dsImpl;
return HGBASE_ERR_OK;
}
HGResult HGAPI HGTwain_CloseDS(HGTwainDS ds)
{
if (NULL == ds)

View File

@ -28,6 +28,8 @@ HGEXPORT HGResult HGAPI HGTwain_OpenDefaultDS(HGTwainDSM dsm, HGTwainDS* ds);
HGEXPORT HGResult HGAPI HGTwain_OpenSelectedDS(HGTwainDSM dsm, HGTwainDS* ds);
HGEXPORT HGResult HGAPI HGTwain_OpenSelectedDSEx(HGTwainDSM dsm, HGTwainDS* ds);
HGEXPORT HGResult HGAPI HGTwain_CloseDS(HGTwainDS ds);
HGEXPORT HGResult HGAPI HGTwain_GetDSName(HGTwainDS ds, HGChar* name, HGUInt maxLen);

View File

@ -235,6 +235,38 @@ HGResult HGTwainDSMImpl::OpenSelectedDS(class HGTwainDSImpl** dsImpl)
return HGBASE_ERR_OK;
}
HGResult HGTwainDSMImpl::OpenSelectedDSEx(class HGTwainDSImpl** dsImpl)
{
if (NULL == dsImpl)
{
return HGBASE_ERR_INVALIDARG;
}
TW_IDENTITY selectDS;
memset(&selectDS, 0, sizeof(TW_IDENTITY));
if (-2 == show_twain_srclist_ui(m_pDSMProc, &m_AppId, m_hWnd, &selectDS))
{
return HGBASE_ERR_NOTSUPPORT;
}
if (0 == selectDS.Id)
{
return HGBASE_ERR_FAIL;
}
class HGTwainDSImpl* newDSImpl = new HGTwainDSImpl(this);
HGResult ret = newDSImpl->Open(&selectDS);
if (HGBASE_ERR_OK != ret)
{
delete newDSImpl;
return ret;
}
m_listDSImpl.push_back(newDSImpl);
*dsImpl = newDSImpl;
return HGBASE_ERR_OK;
}
void HGTwainDSMImpl::RemoveDS(class HGTwainDSImpl* dsImpl)
{
std::vector<class HGTwainDSImpl*>::iterator iter;
@ -326,11 +358,12 @@ HGTwainDSImpl::~HGTwainDSImpl()
}
HGResult HGTwainDSImpl::Open(const TW_IDENTITY* iden)
HGResult HGTwainDSImpl::Open(TW_IDENTITY* iden)
{
assert(!m_open);
assert(NULL != iden);
USHORT ret = m_dsmImpl->m_pDSMProc(&m_dsmImpl->m_AppId, NULL, DG_CONTROL, DAT_IDENTITY, MSG_OPENDS, &m_iden);
USHORT ret = m_dsmImpl->m_pDSMProc(&m_dsmImpl->m_AppId, NULL, DG_CONTROL, DAT_IDENTITY, MSG_OPENDS, iden);
if (TWRC_SUCCESS != ret)
{
return HGTWAIN_ERR_FAIL;

View File

@ -3,7 +3,8 @@
#include "HGTwain.h"
#include "../base/HGDll.h"
#include "twain.h"
#include "twain/twain.h"
#include "saneui/HGSaneUI.h"
#include <vector>
#include <map>
@ -21,6 +22,7 @@ public:
HGResult OpenDS(HGUInt index, class HGTwainDSImpl** dsImpl);
HGResult OpenDefaultDS(class HGTwainDSImpl** dsImpl);
HGResult OpenSelectedDS(class HGTwainDSImpl** dsImpl);
HGResult OpenSelectedDSEx(class HGTwainDSImpl** dsImpl);
private:
void RemoveDS(class HGTwainDSImpl* dsImpl);
@ -44,7 +46,7 @@ public:
~HGTwainDSImpl();
public:
HGResult Open(const TW_IDENTITY* iden);
HGResult Open(TW_IDENTITY* iden);
HGResult Close();
HGResult GetName(HGChar* name, HGUInt maxLen);
HGResult EnableUIOnly(HWND parent, HGDSCloseReqFunc eventFunc, HGPointer eventParam);