2023-05-10 12:30:07 +00:00
|
|
|
#include "Manager.h"
|
|
|
|
#include <QApplication>
|
|
|
|
#include <qwinwidget.hpp>
|
|
|
|
#include "lang/app_language.h"
|
|
|
|
|
|
|
|
Manager::Manager()
|
|
|
|
: QObject(nullptr)
|
|
|
|
{
|
|
|
|
HGBase_CreateEvent(HGFALSE, HGFALSE, &m_event);
|
|
|
|
|
|
|
|
connect(this, SIGNAL(init()), this, SLOT(on_init()));
|
2023-05-19 10:41:49 +00:00
|
|
|
connect(this, SIGNAL(createDeviceSelect(bool)), this, SLOT(on_createDeviceSelect(bool)));
|
|
|
|
connect(this, SIGNAL(createSettingUi(bool)), this, SLOT(on_createSettingUi(bool)));
|
|
|
|
connect(this, SIGNAL(createProgressUi(bool)), this, SLOT(on_createProgressUi(bool)));
|
|
|
|
connect(this, SIGNAL(createMessageBoxUi(bool)), this, SLOT(on_createMessageBoxUi(bool)));
|
|
|
|
connect(this, SIGNAL(createTwainSrcUi(bool)), this, SLOT(on_createTwainSrcUi(bool)));
|
2023-05-10 12:30:07 +00:00
|
|
|
|
|
|
|
emit init();
|
|
|
|
}
|
|
|
|
|
|
|
|
Manager::~Manager()
|
|
|
|
{
|
|
|
|
QCoreApplication::removeTranslator(&m_translator);
|
|
|
|
if (20127 != m_langCode)
|
|
|
|
QCoreApplication::removeTranslator(&m_translator_qt);
|
|
|
|
|
2023-05-11 13:07:30 +00:00
|
|
|
HGBase_DestroyEvent(m_event);
|
2023-05-10 12:30:07 +00:00
|
|
|
}
|
|
|
|
|
2023-05-19 10:41:49 +00:00
|
|
|
int Manager::showDeviceSelect(bool qt, const std::vector<DEVQUEUI>& devs)
|
2023-05-10 12:30:07 +00:00
|
|
|
{
|
|
|
|
m_DeviceSelectDevs = devs;
|
|
|
|
m_DeviceSelectThreadId = GetCurrentThreadId();
|
2023-05-19 10:41:49 +00:00
|
|
|
emit createDeviceSelect(qt);
|
2023-05-10 12:30:07 +00:00
|
|
|
|
2023-05-19 10:41:49 +00:00
|
|
|
if (!qt)
|
2023-05-10 12:30:07 +00:00
|
|
|
{
|
2023-05-19 10:41:49 +00:00
|
|
|
MSG msg;
|
|
|
|
while (GetMessage(&msg, NULL, 0, 0))
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
2023-05-10 12:30:07 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
return m_DeviceSelectResult;
|
|
|
|
}
|
|
|
|
|
2023-05-19 10:41:49 +00:00
|
|
|
int Manager::showSettingUi(bool qt, SANE_Handle device, HWND parent, LPSANEAPI api, const char *devName, bool with_scan, std::function<void (ui_result)> callback)
|
2023-05-10 12:30:07 +00:00
|
|
|
{
|
|
|
|
m_device = device;
|
2023-05-12 06:39:19 +00:00
|
|
|
m_settingUiParent = parent;
|
2023-05-10 12:30:07 +00:00
|
|
|
memcpy(&m_api, api, sizeof(m_api));
|
|
|
|
m_devName = devName;
|
|
|
|
m_with_scan = with_scan;
|
|
|
|
m_settingUiCallback = callback;
|
|
|
|
|
|
|
|
m_SettingUiThreadId = GetCurrentThreadId();
|
|
|
|
|
2023-05-19 10:41:49 +00:00
|
|
|
emit createSettingUi(qt);
|
2023-05-10 12:30:07 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-05-19 10:41:49 +00:00
|
|
|
int Manager::showProgressUi(bool qt, HWND parent, std::function<void (ui_result)> callback, std::function<void (int, void *, int)> *notify)
|
2023-05-10 12:30:07 +00:00
|
|
|
{
|
2023-05-12 10:26:23 +00:00
|
|
|
m_progressUiparent = parent;
|
2023-05-19 10:41:49 +00:00
|
|
|
hg_settingdialog *settingDlg = hg_settingdialog::GetSettingDialog();
|
|
|
|
if (nullptr != settingDlg)
|
|
|
|
m_progressUiparent = (HWND)settingDlg->winId();
|
2023-05-10 12:30:07 +00:00
|
|
|
m_progressUiCallback = callback;
|
|
|
|
m_notify = notify;
|
|
|
|
|
2023-05-19 10:41:49 +00:00
|
|
|
if (!qt)
|
|
|
|
{
|
|
|
|
m_ProgressUiThreadId = GetCurrentThreadId();
|
|
|
|
emit createProgressUi(qt);
|
|
|
|
|
|
|
|
MSG msg;
|
|
|
|
while (GetMessage(&msg, NULL, 0, 0))
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
}
|
|
|
|
else
|
2023-05-16 02:57:46 +00:00
|
|
|
{
|
2023-05-19 10:41:49 +00:00
|
|
|
on_createProgressUi(qt);
|
2023-05-16 02:57:46 +00:00
|
|
|
}
|
|
|
|
|
2023-05-10 12:30:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-05-19 10:41:49 +00:00
|
|
|
int Manager::showMessageBoxUi(bool qt, HWND parent, int event, void *msg, int flag)
|
2023-05-10 12:30:07 +00:00
|
|
|
{
|
2023-05-19 10:41:49 +00:00
|
|
|
m_messageBoxUiParent = nullptr;
|
2023-05-10 12:30:07 +00:00
|
|
|
m_notifyEvent = event;
|
|
|
|
m_message = (char*)msg;
|
|
|
|
m_flag = flag;
|
|
|
|
|
|
|
|
m_MessageBoxUiThreadId = GetCurrentThreadId();
|
|
|
|
|
2023-05-19 10:41:49 +00:00
|
|
|
emit createMessageBoxUi(qt);
|
2023-05-10 12:30:07 +00:00
|
|
|
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-05-19 10:41:49 +00:00
|
|
|
int Manager::showTwainSrcUi(bool qt, DSMENTRYPROC dsmProc, const TW_IDENTITY *appId, HGWindow parent, TW_IDENTITY *ds)
|
2023-05-12 06:39:19 +00:00
|
|
|
{
|
2023-05-12 10:26:23 +00:00
|
|
|
m_twainSrcUiThreadId = GetCurrentThreadId();
|
|
|
|
|
2023-05-12 06:39:19 +00:00
|
|
|
m_TwainSrcUiparent = parent;
|
|
|
|
m_dsmProc = dsmProc;
|
|
|
|
memcpy(&m_appId, appId, sizeof(TW_IDENTITY));
|
2023-05-12 10:26:23 +00:00
|
|
|
memset(ds, 0, sizeof(TW_IDENTITY));
|
2023-05-12 06:39:19 +00:00
|
|
|
memset(&m_ds, 0, sizeof(TW_IDENTITY));
|
|
|
|
|
2023-05-19 10:41:49 +00:00
|
|
|
emit createTwainSrcUi(qt);
|
2023-05-12 10:26:23 +00:00
|
|
|
|
2023-05-19 10:41:49 +00:00
|
|
|
if (!qt)
|
2023-05-12 06:39:19 +00:00
|
|
|
{
|
2023-05-19 10:41:49 +00:00
|
|
|
MSG msg;
|
|
|
|
while (GetMessage(&msg, NULL, 0, 0))
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
2023-05-12 06:39:19 +00:00
|
|
|
}
|
2023-05-12 10:26:23 +00:00
|
|
|
|
|
|
|
memcpy(ds, &m_ds, sizeof(TW_IDENTITY));
|
2023-05-12 06:39:19 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-05-10 12:30:07 +00:00
|
|
|
void Manager::on_init()
|
|
|
|
{
|
|
|
|
m_langCode = lang_get_cur_code_page();
|
|
|
|
if (20127 == m_langCode)
|
|
|
|
{
|
|
|
|
m_translator.load(":translation/TwainUI_zh_EN.qm");
|
|
|
|
}
|
|
|
|
else
|
|
|
|
{
|
|
|
|
m_translator.load(":translation/TwainUI_zh_CN.qm");
|
|
|
|
m_translator_qt.load(":translation/qt_zh_CN.qm");
|
|
|
|
}
|
|
|
|
|
|
|
|
QCoreApplication::installTranslator(&m_translator);
|
|
|
|
if (20127 != m_langCode)
|
|
|
|
QCoreApplication::installTranslator(&m_translator_qt);
|
|
|
|
}
|
|
|
|
|
2023-05-19 10:41:49 +00:00
|
|
|
void Manager::on_createDeviceSelect(bool qt)
|
2023-05-10 12:30:07 +00:00
|
|
|
{
|
|
|
|
Dialog_device_select dlg(m_DeviceSelectDevs);
|
|
|
|
dlg.exec();
|
|
|
|
m_DeviceSelectResult = dlg.getDevId();
|
2023-05-19 10:41:49 +00:00
|
|
|
|
|
|
|
if (!qt)
|
|
|
|
{
|
|
|
|
::PostThreadMessage(m_DeviceSelectThreadId, WM_QUIT, 0, 0);
|
|
|
|
}
|
2023-05-10 12:30:07 +00:00
|
|
|
}
|
|
|
|
|
2023-05-19 10:41:49 +00:00
|
|
|
void Manager::on_createSettingUi(bool qt)
|
2023-05-10 12:30:07 +00:00
|
|
|
{
|
|
|
|
QWidget *qParent = nullptr;
|
|
|
|
#ifdef HG_CMP_MSC
|
|
|
|
if (nullptr != m_settingUiParent)
|
|
|
|
{
|
|
|
|
QWinWidget *win = new QWinWidget(m_settingUiParent);
|
|
|
|
win->showCentered();
|
|
|
|
qParent = win;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
qParent = m_settingUiParent;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
hg_settingdialog *dlg = new hg_settingdialog(m_device, &m_api, m_with_scan, m_devName.c_str(), m_settingUiCallback, qParent);
|
|
|
|
dlg->setModal(true);
|
|
|
|
dlg->show();
|
|
|
|
}
|
|
|
|
|
2023-05-19 10:41:49 +00:00
|
|
|
void Manager::on_createProgressUi(bool qt)
|
2023-05-10 12:30:07 +00:00
|
|
|
{
|
|
|
|
QWidget *qParent = nullptr;
|
|
|
|
#ifdef HG_CMP_MSC
|
|
|
|
if (nullptr != m_progressUiparent)
|
|
|
|
{
|
|
|
|
QWinWidget *win = new QWinWidget(m_progressUiparent);
|
|
|
|
win->showCentered();
|
|
|
|
qParent = win;
|
|
|
|
}
|
2023-05-19 10:41:49 +00:00
|
|
|
|
2023-05-10 12:30:07 +00:00
|
|
|
#else
|
|
|
|
qParent = m_progressUiparent;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Dialog_progress_ui *dlg = new Dialog_progress_ui(m_progressUiCallback, m_notify, qParent);
|
|
|
|
dlg->setModal(true);
|
|
|
|
dlg->show();
|
2023-05-19 10:41:49 +00:00
|
|
|
|
|
|
|
if (!qt)
|
|
|
|
{
|
|
|
|
::PostThreadMessage(m_ProgressUiThreadId, WM_QUIT, 0, 0);
|
|
|
|
}
|
2023-05-10 12:30:07 +00:00
|
|
|
}
|
|
|
|
|
2023-05-19 10:41:49 +00:00
|
|
|
void Manager::on_createMessageBoxUi(bool qt)
|
2023-05-10 12:30:07 +00:00
|
|
|
{
|
|
|
|
QWidget *qParent = nullptr;
|
|
|
|
#ifdef HG_CMP_MSC
|
|
|
|
if (nullptr != m_messageBoxUiParent)
|
|
|
|
{
|
|
|
|
QWinWidget *win = new QWinWidget(m_messageBoxUiParent);
|
|
|
|
win->showCentered();
|
|
|
|
qParent = win;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
qParent = m_messageBoxUiParent;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
QMessageBox *msg = new QMessageBox(QMessageBox::Critical, tr("Prompt"), QString::fromStdString(m_message), QMessageBox::Ok, qParent);
|
2023-05-19 10:41:49 +00:00
|
|
|
msg->setWindowFlags(Qt::SubWindow | Qt::Popup | Qt::WindowStaysOnTopHint);
|
2023-05-10 12:30:07 +00:00
|
|
|
msg->setModal(true);
|
|
|
|
msg->show();
|
|
|
|
}
|
2023-05-12 06:39:19 +00:00
|
|
|
|
2023-05-19 10:41:49 +00:00
|
|
|
void Manager::on_createTwainSrcUi(bool qt)
|
2023-05-12 06:39:19 +00:00
|
|
|
{
|
|
|
|
QWidget *qParent = nullptr;
|
|
|
|
#ifdef HG_CMP_MSC
|
2023-05-12 10:26:23 +00:00
|
|
|
QWinWidget win(m_TwainSrcUiparent);
|
2023-05-12 06:39:19 +00:00
|
|
|
if (nullptr != m_TwainSrcUiparent)
|
|
|
|
{
|
2023-05-12 10:26:23 +00:00
|
|
|
win.showCentered();
|
|
|
|
qParent = &win;
|
2023-05-12 06:39:19 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
qParent = m_TwainSrcUiparent;
|
|
|
|
#endif
|
|
|
|
|
|
|
|
Dialog_Twain_Source_Select dlg(m_dsmProc, &m_appId, qParent);
|
|
|
|
if (dlg.exec())
|
|
|
|
{
|
|
|
|
dlg.GetIdentify(&m_ds);
|
|
|
|
}
|
2023-05-19 10:41:49 +00:00
|
|
|
|
|
|
|
if (!qt)
|
|
|
|
{
|
|
|
|
::PostThreadMessage(m_twainSrcUiThreadId, WM_QUIT, 0, 0);
|
|
|
|
}
|
2023-05-12 06:39:19 +00:00
|
|
|
}
|