2023-05-10 12:30:07 +00:00
|
|
|
#include "Manager.h"
|
|
|
|
#include <QApplication>
|
2023-07-04 05:37:46 +00:00
|
|
|
#ifdef HG_CMP_MSC
|
2023-05-10 12:30:07 +00:00
|
|
|
#include <qwinwidget.hpp>
|
2023-07-04 05:37:46 +00:00
|
|
|
#endif
|
2023-05-10 12:30:07 +00:00
|
|
|
#include "lang/app_language.h"
|
2023-09-18 10:06:29 +00:00
|
|
|
#include <locale.h>
|
2023-10-08 07:19:23 +00:00
|
|
|
#include <QMetaType>
|
2023-11-20 06:41:35 +00:00
|
|
|
#include "base/HGInfo.h"
|
2023-10-08 07:19:23 +00:00
|
|
|
|
|
|
|
Q_DECLARE_METATYPE(HGImage)
|
2023-05-10 12:30:07 +00:00
|
|
|
|
2023-05-24 06:40:06 +00:00
|
|
|
extern Manager* g_manager;
|
|
|
|
|
2023-05-10 12:30:07 +00:00
|
|
|
Manager::Manager()
|
|
|
|
: QObject(nullptr)
|
2023-05-23 09:40:43 +00:00
|
|
|
, m_progressUiCallback(std::function<void(ui_result)>())
|
2023-11-29 06:39:11 +00:00
|
|
|
, m_progNotify(nullptr)
|
|
|
|
, m_settingNotify(nullptr)
|
2023-05-23 09:40:43 +00:00
|
|
|
, m_settingUiCallback(std::function<void(ui_result)>())
|
|
|
|
, m_settingUi(nullptr)
|
|
|
|
, m_progressUi(nullptr)
|
2023-05-10 12:30:07 +00:00
|
|
|
{
|
2023-10-08 07:19:23 +00:00
|
|
|
qRegisterMetaType<HGImage>("HGImage");
|
|
|
|
|
2023-05-10 12:30:07 +00:00
|
|
|
connect(this, SIGNAL(init()), this, SLOT(on_init()));
|
2023-11-21 01:26:31 +00:00
|
|
|
connect(this, SIGNAL(createDeviceSelect(void *)), this, SLOT(on_createDeviceSelect(void *)));
|
|
|
|
connect(this, SIGNAL(createSettingUi(void *)), this, SLOT(on_createSettingUi(void *)));
|
2023-11-20 10:09:21 +00:00
|
|
|
connect(this, SIGNAL(createProgressUi(void *)), this, SLOT(on_createProgressUi(void *)));
|
2023-11-21 01:26:31 +00:00
|
|
|
connect(this, SIGNAL(createMessageBoxUi(void *)), this, SLOT(on_createMessageBoxUi(void *)));
|
|
|
|
connect(this, SIGNAL(createTwainSrcUi(void *)), this, SLOT(on_createTwainSrcUi(void *)));
|
|
|
|
connect(this, SIGNAL(createSaneSrcUi(void *)), this, SLOT(on_createSaneSrcUi(void *)));
|
|
|
|
connect(this, SIGNAL(createAbnormalImgUi(void *, HGImage)), this, SLOT(on_createAbnormalImgUi(void *, HGImage)));
|
2023-10-26 11:09:44 +00:00
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
connect(this, SIGNAL(deleteSettingUi(void *)), this, SLOT(on_deleteSettingUi(void *)));
|
|
|
|
connect(this, SIGNAL(deleteProgressUi(void *)), this, SLOT(on_deleteProgressUi(void *)));
|
|
|
|
connect(this, SIGNAL(deleteMessageBoxUi(void *)), this, SLOT(on_deleteMessageBoxUi(void *)));
|
2023-05-24 06:40:06 +00:00
|
|
|
|
2023-05-10 12:30:07 +00:00
|
|
|
emit init();
|
|
|
|
}
|
|
|
|
|
|
|
|
Manager::~Manager()
|
|
|
|
{
|
|
|
|
QCoreApplication::removeTranslator(&m_translator);
|
2023-09-18 10:06:29 +00:00
|
|
|
if (936 == m_langCode)
|
2023-05-10 12:30:07 +00:00
|
|
|
QCoreApplication::removeTranslator(&m_translator_qt);
|
|
|
|
}
|
|
|
|
|
2023-10-26 11:09:44 +00:00
|
|
|
int Manager::showDeviceSelect(const std::vector<DEVQUEUI>& devs)
|
2023-05-10 12:30:07 +00:00
|
|
|
{
|
2023-10-26 11:09:44 +00:00
|
|
|
// param
|
2023-05-10 12:30:07 +00:00
|
|
|
m_DeviceSelectDevs = devs;
|
2023-10-26 11:09:44 +00:00
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
void *hStopEvent = nullptr;
|
2023-07-04 05:37:46 +00:00
|
|
|
#ifdef HG_CMP_MSC
|
2023-10-26 11:09:44 +00:00
|
|
|
if (qApp->thread() != QThread::currentThread())
|
2023-11-21 01:26:31 +00:00
|
|
|
{
|
|
|
|
hStopEvent = ::CreateEvent(0, FALSE, FALSE, 0);
|
|
|
|
}
|
2023-07-04 05:37:46 +00:00
|
|
|
#endif
|
2023-05-10 12:30:07 +00:00
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
emit createDeviceSelect(hStopEvent);
|
|
|
|
|
2023-07-04 05:37:46 +00:00
|
|
|
#ifdef HG_CMP_MSC
|
2023-11-21 01:26:31 +00:00
|
|
|
if (nullptr != hStopEvent)
|
2023-05-10 12:30:07 +00:00
|
|
|
{
|
2023-11-21 01:26:31 +00:00
|
|
|
msgLoop(hStopEvent);
|
|
|
|
CloseHandle(hStopEvent);
|
2023-05-10 12:30:07 +00:00
|
|
|
}
|
2023-07-04 05:37:46 +00:00
|
|
|
#endif
|
2023-05-10 12:30:07 +00:00
|
|
|
|
2023-10-26 11:09:44 +00:00
|
|
|
// ret
|
2023-05-10 12:30:07 +00:00
|
|
|
return m_DeviceSelectResult;
|
|
|
|
}
|
|
|
|
|
2023-11-29 06:39:11 +00:00
|
|
|
int Manager::showSettingUi(SANE_Handle device, HWND parent, LPSANEAPI api, const char * devName, gb::scanner_cfg* cfg, bool with_scan, std::function<void (ui_result)> callback, std::function<void(int, void*, int)>* notify)
|
2023-05-10 12:30:07 +00:00
|
|
|
{
|
2023-10-26 11:09:44 +00:00
|
|
|
// param
|
2023-05-10 12:30:07 +00:00
|
|
|
m_device = device;
|
2023-07-05 13:54:19 +00:00
|
|
|
scanner_cfg_ = cfg;
|
2023-07-04 05:37:46 +00:00
|
|
|
m_settingUiParent = (HGWindow)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;
|
2023-11-29 06:39:11 +00:00
|
|
|
m_settingNotify = notify;
|
2023-10-26 11:09:44 +00:00
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
void *hStopEvent = nullptr;
|
2023-10-26 11:09:44 +00:00
|
|
|
#ifdef HG_CMP_MSC
|
|
|
|
if (qApp->thread() != QThread::currentThread())
|
|
|
|
{
|
2023-11-21 01:26:31 +00:00
|
|
|
hStopEvent = ::CreateEvent(0, FALSE, FALSE, 0);
|
2023-10-26 11:09:44 +00:00
|
|
|
}
|
2023-07-04 05:37:46 +00:00
|
|
|
#endif
|
2023-05-10 12:30:07 +00:00
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
emit createSettingUi(hStopEvent);
|
2023-11-20 06:41:35 +00:00
|
|
|
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "[Manager::showSettingUi] emit createSettingUi(ThreadId)");
|
2023-11-29 06:39:11 +00:00
|
|
|
|
|
|
|
#ifdef HG_CMP_MSC
|
|
|
|
if (nullptr != hStopEvent)
|
|
|
|
{
|
|
|
|
msgLoop(hStopEvent);
|
|
|
|
CloseHandle(hStopEvent);
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-05-10 12:30:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-10-26 11:09:44 +00:00
|
|
|
int Manager::showProgressUi(HWND parent, std::function<void (ui_result)> callback, std::function<void (int, void *, int)> *notify)
|
2023-05-10 12:30:07 +00:00
|
|
|
{
|
2023-10-26 11:09:44 +00:00
|
|
|
// param
|
2023-07-04 05:37:46 +00:00
|
|
|
m_progressUiparent = (HGWindow)parent;
|
2023-05-10 12:30:07 +00:00
|
|
|
m_progressUiCallback = callback;
|
2023-11-29 06:39:11 +00:00
|
|
|
m_progNotify = notify;
|
2023-10-26 11:09:44 +00:00
|
|
|
|
2023-11-20 10:09:21 +00:00
|
|
|
void *hStopEvent = nullptr;
|
2023-07-04 05:37:46 +00:00
|
|
|
#ifdef HG_CMP_MSC
|
2023-10-26 11:09:44 +00:00
|
|
|
if (qApp->thread() != QThread::currentThread())
|
2023-11-20 06:41:35 +00:00
|
|
|
{
|
2023-11-20 10:09:21 +00:00
|
|
|
hStopEvent = ::CreateEvent(0, FALSE, FALSE, 0);
|
2023-11-20 06:41:35 +00:00
|
|
|
}
|
2023-07-04 05:37:46 +00:00
|
|
|
#endif
|
2023-05-27 06:09:54 +00:00
|
|
|
|
2023-11-20 10:09:21 +00:00
|
|
|
emit createProgressUi(hStopEvent);
|
2023-11-20 06:41:35 +00:00
|
|
|
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "[Manager::showProgressUi] emit createProgressUi(ThreadId)");
|
2023-11-16 07:32:35 +00:00
|
|
|
|
2023-07-04 05:37:46 +00:00
|
|
|
#ifdef HG_CMP_MSC
|
2023-11-20 10:09:21 +00:00
|
|
|
if (nullptr != hStopEvent)
|
2023-05-19 10:41:49 +00:00
|
|
|
{
|
2023-11-21 01:26:31 +00:00
|
|
|
msgLoop(hStopEvent);
|
2023-11-20 10:09:21 +00:00
|
|
|
CloseHandle(hStopEvent);
|
2023-05-19 10:41:49 +00:00
|
|
|
}
|
2023-07-04 05:37:46 +00:00
|
|
|
#endif
|
2023-05-16 02:57:46 +00:00
|
|
|
|
2023-11-20 06:41:35 +00:00
|
|
|
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "[Manager::showProgressUi] Exit Message Loop");
|
2023-05-10 12:30:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-10-26 11:09:44 +00:00
|
|
|
int Manager::showMessageBoxUi(HWND parent, int event, void *msg, int flag)
|
2023-05-10 12:30:07 +00:00
|
|
|
{
|
2023-10-26 11:09:44 +00:00
|
|
|
// param
|
|
|
|
m_messageBoxUiParent = (HGWindow)parent;
|
2023-05-10 12:30:07 +00:00
|
|
|
m_notifyEvent = event;
|
|
|
|
m_message = (char*)msg;
|
|
|
|
m_flag = flag;
|
2023-10-26 11:09:44 +00:00
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
void *hStopEvent = nullptr;
|
2023-07-04 05:37:46 +00:00
|
|
|
#ifdef HG_CMP_MSC
|
2023-10-26 11:09:44 +00:00
|
|
|
if (qApp->thread() != QThread::currentThread())
|
2023-11-21 01:26:31 +00:00
|
|
|
{
|
|
|
|
hStopEvent = ::CreateEvent(0, FALSE, FALSE, 0);
|
|
|
|
}
|
2023-07-04 05:37:46 +00:00
|
|
|
#endif
|
2023-05-10 12:30:07 +00:00
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
emit createMessageBoxUi(hStopEvent);
|
|
|
|
|
2023-07-04 05:37:46 +00:00
|
|
|
#ifdef HG_CMP_MSC
|
2023-11-21 01:26:31 +00:00
|
|
|
if (nullptr != hStopEvent)
|
2023-05-25 10:41:40 +00:00
|
|
|
{
|
2023-11-21 01:26:31 +00:00
|
|
|
msgLoop(hStopEvent);
|
|
|
|
CloseHandle(hStopEvent);
|
2023-05-25 10:41:40 +00:00
|
|
|
}
|
2023-07-04 05:37:46 +00:00
|
|
|
#endif
|
2023-05-25 10:41:40 +00:00
|
|
|
|
2023-05-10 12:30:07 +00:00
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-10-26 11:09:44 +00:00
|
|
|
int Manager::showTwainSrcUi(const TW_IDENTITY *vds, HGUInt count, const char* defDevName, HGWindow parent, TW_IDENTITY *ds)
|
2023-05-12 06:39:19 +00:00
|
|
|
{
|
|
|
|
m_TwainSrcUiparent = parent;
|
2023-05-30 11:11:24 +00:00
|
|
|
m_vds.clear();
|
|
|
|
for (int i = 0; i < count; ++i)
|
|
|
|
{
|
|
|
|
m_vds.push_back(vds[i]);
|
|
|
|
}
|
|
|
|
m_defDsName = defDevName;
|
2023-05-12 06:39:19 +00:00
|
|
|
memset(&m_ds, 0, sizeof(TW_IDENTITY));
|
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
void *hStopEvent = nullptr;
|
2023-10-26 11:09:44 +00:00
|
|
|
#ifdef HG_CMP_MSC
|
|
|
|
if (qApp->thread() != QThread::currentThread())
|
2023-11-21 01:26:31 +00:00
|
|
|
{
|
|
|
|
hStopEvent = ::CreateEvent(0, FALSE, FALSE, 0);
|
|
|
|
}
|
2023-10-26 11:09:44 +00:00
|
|
|
#endif
|
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
emit createTwainSrcUi(hStopEvent);
|
|
|
|
|
2023-07-04 05:37:46 +00:00
|
|
|
#ifdef HG_CMP_MSC
|
2023-11-21 01:26:31 +00:00
|
|
|
if (nullptr != hStopEvent)
|
2023-05-12 06:39:19 +00:00
|
|
|
{
|
2023-11-21 01:26:31 +00:00
|
|
|
msgLoop(hStopEvent);
|
|
|
|
CloseHandle(hStopEvent);
|
2023-05-12 06:39:19 +00:00
|
|
|
}
|
2023-07-04 05:37:46 +00:00
|
|
|
#endif
|
2023-10-26 11:09:44 +00:00
|
|
|
|
|
|
|
// ret
|
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-10-26 11:09:44 +00:00
|
|
|
int Manager::showSaneSrcUi(const char **manuNames, const char **sanePaths, HGWindow parent, HGDll *dll,
|
2023-08-12 07:30:33 +00:00
|
|
|
SANEAPI* saneApi, char *manuName, unsigned int maxLen)
|
|
|
|
{
|
2023-10-26 11:09:44 +00:00
|
|
|
// param
|
2023-08-12 07:30:33 +00:00
|
|
|
m_SaneSrcUiparent = parent;
|
|
|
|
m_saneSource.clear();
|
|
|
|
const char **p1 = manuNames;
|
|
|
|
const char **p2 = sanePaths;
|
|
|
|
while (*p1 != NULL && *p2 != NULL)
|
|
|
|
{
|
|
|
|
std::pair<std::string, std::string> pr;
|
|
|
|
pr.first = *p1;
|
|
|
|
pr.second = *p2;
|
|
|
|
m_saneSource.push_back(pr);
|
|
|
|
++p1;
|
|
|
|
++p2;
|
|
|
|
}
|
|
|
|
|
|
|
|
m_saneDll = NULL;
|
|
|
|
memset(&m_saneApi, 0, sizeof(SANEAPI));
|
|
|
|
m_saneManuName.clear();
|
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
void *hStopEvent = nullptr;
|
2023-10-26 11:09:44 +00:00
|
|
|
#ifdef HG_CMP_MSC
|
|
|
|
if (qApp->thread() != QThread::currentThread())
|
2023-11-21 01:26:31 +00:00
|
|
|
{
|
|
|
|
hStopEvent = ::CreateEvent(0, FALSE, FALSE, 0);
|
|
|
|
}
|
2023-10-26 11:09:44 +00:00
|
|
|
#endif
|
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
emit createSaneSrcUi(hStopEvent);
|
|
|
|
|
2023-08-12 07:30:33 +00:00
|
|
|
#ifdef HG_CMP_MSC
|
2023-11-21 01:26:31 +00:00
|
|
|
if (nullptr != hStopEvent)
|
2023-08-12 07:30:33 +00:00
|
|
|
{
|
2023-11-21 01:26:31 +00:00
|
|
|
msgLoop(hStopEvent);
|
|
|
|
CloseHandle(hStopEvent);
|
2023-08-12 07:30:33 +00:00
|
|
|
}
|
|
|
|
#endif
|
2023-10-26 11:09:44 +00:00
|
|
|
|
|
|
|
// ret
|
2023-08-12 07:30:33 +00:00
|
|
|
*dll = m_saneDll;
|
|
|
|
memcpy(saneApi, &m_saneApi, sizeof(SANEAPI));
|
|
|
|
strcpy(manuName, m_saneManuName.c_str());
|
|
|
|
return 0;
|
|
|
|
}
|
|
|
|
|
2023-10-26 11:09:44 +00:00
|
|
|
int Manager::showAbnormalImgUi(SANE_Image *img)
|
2023-10-08 07:19:23 +00:00
|
|
|
{
|
2023-10-26 11:09:44 +00:00
|
|
|
// param
|
2023-10-08 07:19:23 +00:00
|
|
|
HGUInt imgType = 0;
|
|
|
|
if (img->header.format == SANE_FRAME_GRAY)
|
|
|
|
{
|
|
|
|
if (1 == img->header.depth)
|
|
|
|
imgType = HGBASE_IMGTYPE_BINARY;
|
|
|
|
else if (8 == img->header.depth)
|
|
|
|
imgType = HGBASE_IMGTYPE_GRAY;
|
|
|
|
}
|
|
|
|
else if (img->header.format == SANE_FRAME_RGB)
|
|
|
|
{
|
|
|
|
imgType = HGBASE_IMGTYPE_RGB;
|
|
|
|
}
|
|
|
|
|
|
|
|
HGImageInfo imgInfo = { (HGUInt)img->header.pixels_per_line, (HGUInt)img->header.lines,
|
|
|
|
imgType, (HGUInt)img->header.bytes_per_line, HGBASE_IMGORIGIN_TOP };
|
|
|
|
|
|
|
|
HGImage image = NULL;
|
|
|
|
HGBase_CreateImageWithData(img->data, &imgInfo, &image);
|
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
void *hStopEvent = nullptr;
|
2023-10-08 07:19:23 +00:00
|
|
|
#ifdef HG_CMP_MSC
|
2023-10-26 11:09:44 +00:00
|
|
|
if (qApp->thread() != QThread::currentThread())
|
2023-11-21 01:26:31 +00:00
|
|
|
{
|
|
|
|
hStopEvent = ::CreateEvent(0, FALSE, FALSE, 0);
|
|
|
|
}
|
2023-10-08 07:19:23 +00:00
|
|
|
#endif
|
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
emit createAbnormalImgUi(hStopEvent, image);
|
|
|
|
|
2023-10-08 07:19:23 +00:00
|
|
|
#ifdef HG_CMP_MSC
|
2023-11-21 01:26:31 +00:00
|
|
|
if (nullptr != hStopEvent)
|
2023-10-08 07:19:23 +00:00
|
|
|
{
|
2023-11-21 01:26:31 +00:00
|
|
|
msgLoop(hStopEvent);
|
|
|
|
CloseHandle(hStopEvent);
|
2023-10-08 07:19:23 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
|
2023-10-26 11:09:44 +00:00
|
|
|
// ret
|
|
|
|
HGBase_DestroyImage(image);
|
2023-10-08 07:19:23 +00:00
|
|
|
return m_abnormalImgResult;
|
|
|
|
}
|
|
|
|
|
2023-05-24 06:40:06 +00:00
|
|
|
void Manager::closeSettingUi()
|
|
|
|
{
|
2023-11-21 01:26:31 +00:00
|
|
|
void *hStopEvent = nullptr;
|
2023-10-26 11:09:44 +00:00
|
|
|
#ifdef HG_CMP_MSC
|
|
|
|
if (qApp->thread() != QThread::currentThread())
|
2023-11-21 01:26:31 +00:00
|
|
|
{
|
|
|
|
hStopEvent = ::CreateEvent(0, FALSE, FALSE, 0);
|
|
|
|
}
|
2023-10-26 11:09:44 +00:00
|
|
|
#endif
|
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
emit deleteSettingUi(hStopEvent);
|
2023-05-24 06:40:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Manager::closeProgressUi()
|
|
|
|
{
|
2023-11-21 01:26:31 +00:00
|
|
|
void *hStopEvent = nullptr;
|
2023-10-26 11:09:44 +00:00
|
|
|
#ifdef HG_CMP_MSC
|
|
|
|
if (qApp->thread() != QThread::currentThread())
|
2023-11-21 01:26:31 +00:00
|
|
|
{
|
|
|
|
hStopEvent = ::CreateEvent(0, FALSE, FALSE, 0);
|
|
|
|
}
|
2023-10-26 11:09:44 +00:00
|
|
|
#endif
|
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
emit deleteProgressUi(hStopEvent);
|
2023-05-24 06:40:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Manager::closeMessageBoxUi()
|
|
|
|
{
|
2023-11-21 01:26:31 +00:00
|
|
|
void *hStopEvent = nullptr;
|
2023-10-26 11:09:44 +00:00
|
|
|
#ifdef HG_CMP_MSC
|
|
|
|
if (qApp->thread() != QThread::currentThread())
|
2023-11-21 01:26:31 +00:00
|
|
|
{
|
|
|
|
hStopEvent = ::CreateEvent(0, FALSE, FALSE, 0);
|
|
|
|
}
|
2023-10-26 11:09:44 +00:00
|
|
|
#endif
|
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
emit deleteMessageBoxUi(hStopEvent);
|
2023-05-24 06:40:06 +00:00
|
|
|
}
|
|
|
|
|
|
|
|
void Manager::clear_functions(void)
|
|
|
|
{
|
|
|
|
m_settingUiCallback = std::function<void(ui_result)>();
|
|
|
|
m_progressUiCallback = std::function<void(ui_result)>();
|
2023-11-29 06:39:11 +00:00
|
|
|
m_progNotify = nullptr;
|
|
|
|
m_settingNotify = nullptr;
|
2023-05-24 10:00:21 +00:00
|
|
|
if (m_progressUi)
|
2023-05-24 06:40:06 +00:00
|
|
|
m_progressUi->clear_callback();
|
|
|
|
if (m_settingUi)
|
|
|
|
m_settingUi->clear_callback();
|
|
|
|
}
|
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
void Manager::msgLoop(void *hEvent)
|
|
|
|
{
|
|
|
|
#ifdef HG_CMP_MSC
|
|
|
|
assert(nullptr != hEvent);
|
|
|
|
|
|
|
|
while (1)
|
|
|
|
{
|
|
|
|
MSG msg;
|
|
|
|
while (PeekMessage(&msg, NULL, 0, 0, PM_REMOVE))
|
|
|
|
{
|
|
|
|
TranslateMessage(&msg);
|
|
|
|
DispatchMessage(&msg);
|
|
|
|
}
|
|
|
|
|
|
|
|
HANDLE arEvents[1] = { hEvent };
|
|
|
|
DWORD result = MsgWaitForMultipleObjectsEx(1, arEvents, INFINITE, QS_ALLINPUT, MWMO_ALERTABLE);
|
|
|
|
if (result == WAIT_OBJECT_0 + 1) // msg received
|
|
|
|
{
|
|
|
|
continue;
|
|
|
|
}
|
|
|
|
else if (result == WAIT_OBJECT_0)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
else if (result == WAIT_IO_COMPLETION)
|
|
|
|
{
|
|
|
|
break;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-05-10 12:30:07 +00:00
|
|
|
void Manager::on_init()
|
|
|
|
{
|
|
|
|
m_langCode = lang_get_cur_code_page();
|
2023-09-18 10:06:29 +00:00
|
|
|
if (936 != m_langCode)
|
2023-05-10 12:30:07 +00:00
|
|
|
{
|
|
|
|
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);
|
2023-09-18 10:06:29 +00:00
|
|
|
if (936 == m_langCode)
|
2023-05-10 12:30:07 +00:00
|
|
|
QCoreApplication::installTranslator(&m_translator_qt);
|
|
|
|
}
|
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
void Manager::on_createDeviceSelect(void *hEvent)
|
2023-05-10 12:30:07 +00:00
|
|
|
{
|
2023-10-26 11:09:44 +00:00
|
|
|
Dialog_device_select dlg(m_DeviceSelectDevs);
|
|
|
|
dlg.exec();
|
|
|
|
m_DeviceSelectResult = dlg.getDevId();
|
|
|
|
|
2023-07-04 05:37:46 +00:00
|
|
|
#ifdef HG_CMP_MSC
|
2023-11-21 01:26:31 +00:00
|
|
|
if (nullptr != hEvent)
|
2023-05-19 10:41:49 +00:00
|
|
|
{
|
2023-11-21 01:26:31 +00:00
|
|
|
SetEvent((HANDLE)hEvent);
|
2023-05-19 10:41:49 +00:00
|
|
|
}
|
2023-07-04 05:37:46 +00:00
|
|
|
#endif
|
2023-05-10 12:30:07 +00:00
|
|
|
}
|
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
void Manager::on_createSettingUi(void *hEvent)
|
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
|
|
|
|
|
2023-05-24 06:40:06 +00:00
|
|
|
auto close_prog = [this](ui_result r) ->void
|
|
|
|
{
|
|
|
|
if(r != UI_RESULT_START_SCAN)
|
|
|
|
m_settingUi = nullptr;
|
|
|
|
m_settingUiCallback(r);
|
|
|
|
};
|
|
|
|
|
2023-10-20 08:05:50 +00:00
|
|
|
if (m_settingUi != nullptr)
|
|
|
|
delete m_settingUi;
|
2023-11-29 06:39:11 +00:00
|
|
|
m_settingUi = new hg_settingdialog(this, m_device, &m_api, m_with_scan, m_devName.c_str(), scanner_cfg_, close_prog, m_settingNotify, qParent);
|
2023-05-23 09:40:43 +00:00
|
|
|
m_settingUi->setModal(true);
|
2023-12-11 09:25:59 +00:00
|
|
|
|
|
|
|
if (nullptr == m_settingUiParent)
|
|
|
|
{
|
|
|
|
m_settingUi->setWindowFlags(Qt::WindowStaysOnTopHint);
|
|
|
|
}
|
|
|
|
|
2023-05-23 09:40:43 +00:00
|
|
|
m_settingUi->show();
|
2023-11-20 06:41:35 +00:00
|
|
|
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "[Manager::on_createSettingUi] m_settingUi->show()");
|
2023-11-29 06:39:11 +00:00
|
|
|
|
|
|
|
#ifdef HG_CMP_MSC
|
|
|
|
if (nullptr != hEvent)
|
|
|
|
{
|
|
|
|
SetEvent((HANDLE)hEvent);
|
|
|
|
}
|
|
|
|
#endif
|
2023-05-10 12:30:07 +00:00
|
|
|
}
|
|
|
|
|
2023-11-20 10:09:21 +00:00
|
|
|
void Manager::on_createProgressUi(void *hEvent)
|
2023-05-10 12:30:07 +00:00
|
|
|
{
|
2023-10-26 11:09:44 +00:00
|
|
|
if (nullptr != m_settingUi)
|
|
|
|
m_progressUiparent = (HGWindow)m_settingUi->winId();
|
|
|
|
|
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
|
|
|
|
|
2023-05-24 06:40:06 +00:00
|
|
|
auto close_prog = [&](ui_result r) ->void
|
|
|
|
{
|
|
|
|
if(m_progressUiCallback)
|
|
|
|
m_progressUiCallback(r);
|
2023-05-24 10:00:21 +00:00
|
|
|
|
|
|
|
if(r == UI_RESULT_CLOSE_NORMAL)
|
|
|
|
m_progressUiCallback = std::function<void(ui_result)>();
|
2023-05-24 06:40:06 +00:00
|
|
|
};
|
2023-10-20 08:05:50 +00:00
|
|
|
if (m_progressUi != nullptr)
|
|
|
|
delete m_progressUi;
|
2023-11-29 06:39:11 +00:00
|
|
|
m_progressUi = new Dialog_progress_ui(this, close_prog, m_progNotify, qParent);
|
2023-05-23 09:40:43 +00:00
|
|
|
m_progressUi->setModal(true);
|
|
|
|
m_progressUi->show();
|
2023-11-20 06:41:35 +00:00
|
|
|
HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "[Manager::on_createProgressUi] m_progressUi->show()");
|
2023-11-21 01:26:31 +00:00
|
|
|
|
2023-07-04 05:37:46 +00:00
|
|
|
#ifdef HG_CMP_MSC
|
2023-11-20 10:09:21 +00:00
|
|
|
if (nullptr != hEvent)
|
2023-05-19 10:41:49 +00:00
|
|
|
{
|
2023-11-20 10:09:21 +00:00
|
|
|
SetEvent((HANDLE)hEvent);
|
2023-05-19 10:41:49 +00:00
|
|
|
}
|
2023-07-04 05:37:46 +00:00
|
|
|
#endif
|
2023-05-10 12:30:07 +00:00
|
|
|
}
|
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
void Manager::on_createMessageBoxUi(void *hEvent)
|
2023-05-10 12:30:07 +00:00
|
|
|
{
|
|
|
|
QWidget *qParent = nullptr;
|
|
|
|
#ifdef HG_CMP_MSC
|
2023-10-26 11:09:44 +00:00
|
|
|
QWinWidget win(m_messageBoxUiParent);
|
2023-05-10 12:30:07 +00:00
|
|
|
if (nullptr != m_messageBoxUiParent)
|
|
|
|
{
|
2023-10-26 11:09:44 +00:00
|
|
|
win.showCentered();
|
|
|
|
qParent = &win;
|
2023-05-10 12:30:07 +00:00
|
|
|
}
|
|
|
|
#else
|
|
|
|
qParent = m_messageBoxUiParent;
|
|
|
|
#endif
|
|
|
|
|
2023-10-26 11:09:44 +00:00
|
|
|
QMessageBox dlg(QMessageBox::Critical, tr("Prompt"), QString::fromStdString(m_message), QMessageBox::Ok, qParent);
|
|
|
|
dlg.setWindowFlags(Qt::SubWindow | Qt::Popup | Qt::WindowStaysOnTopHint);
|
|
|
|
dlg.exec();
|
|
|
|
|
2023-07-04 05:37:46 +00:00
|
|
|
#ifdef HG_CMP_MSC
|
2023-11-21 01:26:31 +00:00
|
|
|
if (nullptr != hEvent)
|
2023-05-25 10:41:40 +00:00
|
|
|
{
|
2023-11-21 01:26:31 +00:00
|
|
|
SetEvent((HANDLE)hEvent);
|
2023-05-25 10:41:40 +00:00
|
|
|
}
|
2023-07-04 05:37:46 +00:00
|
|
|
#endif
|
2023-05-10 12:30:07 +00:00
|
|
|
}
|
2023-05-12 06:39:19 +00:00
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
void Manager::on_createTwainSrcUi(void *hEvent)
|
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
|
|
|
|
|
2023-10-26 11:09:44 +00:00
|
|
|
Dialog_Twain_Source_Select dlg(m_vds, m_defDsName, qParent);
|
|
|
|
if (dlg.exec())
|
2023-05-12 06:39:19 +00:00
|
|
|
{
|
2023-10-26 11:09:44 +00:00
|
|
|
dlg.GetIdentify(&m_ds);
|
2023-05-12 06:39:19 +00:00
|
|
|
}
|
2023-10-26 11:09:44 +00:00
|
|
|
|
2023-07-04 05:37:46 +00:00
|
|
|
#ifdef HG_CMP_MSC
|
2023-11-21 01:26:31 +00:00
|
|
|
if (nullptr != hEvent)
|
2023-05-19 10:41:49 +00:00
|
|
|
{
|
2023-11-21 01:26:31 +00:00
|
|
|
SetEvent((HANDLE)hEvent);
|
2023-05-19 10:41:49 +00:00
|
|
|
}
|
2023-07-04 05:37:46 +00:00
|
|
|
#endif
|
2023-05-12 06:39:19 +00:00
|
|
|
}
|
2023-05-24 06:40:06 +00:00
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
void Manager::on_createSaneSrcUi(void *hEvent)
|
2023-08-12 07:30:33 +00:00
|
|
|
{
|
|
|
|
QWidget *qParent = nullptr;
|
|
|
|
#ifdef HG_CMP_MSC
|
|
|
|
QWinWidget win(m_SaneSrcUiparent);
|
|
|
|
if (nullptr != m_SaneSrcUiparent)
|
|
|
|
{
|
|
|
|
win.showCentered();
|
|
|
|
qParent = &win;
|
|
|
|
}
|
|
|
|
#else
|
|
|
|
qParent = m_SaneSrcUiparent;
|
|
|
|
#endif
|
|
|
|
|
2023-10-26 11:09:44 +00:00
|
|
|
Dialog_Source_Select dlg(m_saneSource, qParent);
|
|
|
|
if (dlg.exec())
|
2023-08-12 07:30:33 +00:00
|
|
|
{
|
2023-10-26 11:09:44 +00:00
|
|
|
m_saneManuName = dlg.GetManuName();
|
|
|
|
m_saneDll = dlg.GetDll();
|
|
|
|
dlg.GetSaneAPI(&m_saneApi);
|
2023-08-12 07:30:33 +00:00
|
|
|
}
|
2023-10-26 11:09:44 +00:00
|
|
|
|
2023-08-12 07:30:33 +00:00
|
|
|
#ifdef HG_CMP_MSC
|
2023-11-21 01:26:31 +00:00
|
|
|
if (nullptr != hEvent)
|
2023-08-12 07:30:33 +00:00
|
|
|
{
|
2023-11-21 01:26:31 +00:00
|
|
|
SetEvent((HANDLE)hEvent);
|
2023-08-12 07:30:33 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
void Manager::on_createAbnormalImgUi(void *hEvent, HGImage image)
|
2023-10-08 07:19:23 +00:00
|
|
|
{
|
2023-10-26 11:09:44 +00:00
|
|
|
Dialog_abnormal_img_select dlg(image, m_progressUi);
|
|
|
|
dlg.exec();
|
|
|
|
m_abnormalImgResult = dlg.getUserSelect();
|
2023-10-08 07:19:23 +00:00
|
|
|
|
|
|
|
#ifdef HG_CMP_MSC
|
2023-11-21 01:26:31 +00:00
|
|
|
if (nullptr != hEvent)
|
2023-10-08 07:19:23 +00:00
|
|
|
{
|
2023-11-21 01:26:31 +00:00
|
|
|
SetEvent((HANDLE)hEvent);
|
2023-10-08 07:19:23 +00:00
|
|
|
}
|
|
|
|
#endif
|
|
|
|
}
|
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
void Manager::on_deleteSettingUi(void *hEvent)
|
2023-05-24 06:40:06 +00:00
|
|
|
{
|
|
|
|
if (m_settingUi != nullptr)
|
|
|
|
{
|
|
|
|
m_settingUi->clear_callback();
|
|
|
|
delete m_settingUi;
|
|
|
|
m_settingUi = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
void Manager::on_deleteProgressUi(void *hEvent)
|
2023-05-24 06:40:06 +00:00
|
|
|
{
|
|
|
|
if (m_progressUi != nullptr)
|
|
|
|
{
|
|
|
|
m_progressUi->clear_callback();
|
|
|
|
delete m_progressUi;
|
|
|
|
m_progressUi = nullptr;
|
|
|
|
}
|
|
|
|
}
|
|
|
|
|
2023-11-21 01:26:31 +00:00
|
|
|
void Manager::on_deleteMessageBoxUi(void *hEvent)
|
2023-05-24 06:40:06 +00:00
|
|
|
{
|
2023-11-20 06:41:35 +00:00
|
|
|
|
2023-05-24 06:40:06 +00:00
|
|
|
}
|