整理twainui代码,解决内存泄露问题
This commit is contained in:
parent
069407b74c
commit
5851064373
|
@ -8,7 +8,6 @@ SUBDIRS += \
|
|||
HGSaneUser \
|
||||
HGVersion \
|
||||
HGScannerLib \
|
||||
HGUpload \
|
||||
HGWebService \
|
||||
HGUpgrade \
|
||||
HGFWUpgrade \
|
||||
|
@ -36,9 +35,6 @@ HGScannerLib.depends = \
|
|||
HGImgFmt \
|
||||
HGImgProc
|
||||
|
||||
HGUpload.depends = \
|
||||
HGBase
|
||||
|
||||
HGWebService.depends = \
|
||||
HGBase \
|
||||
HGImgFmt \
|
||||
|
|
|
@ -8,7 +8,6 @@ SUBDIRS += \
|
|||
HGTwainUser \
|
||||
HGVersion \
|
||||
HGScannerLib \
|
||||
HGUpload \
|
||||
HGWebService \
|
||||
HGUpgrade \
|
||||
HGFWUpgrade \
|
||||
|
@ -36,9 +35,6 @@ HGScannerLib.depends = \
|
|||
HGImgFmt \
|
||||
HGImgProc
|
||||
|
||||
HGUpload.depends = \
|
||||
HGBase
|
||||
|
||||
HGWebService.depends = \
|
||||
HGBase \
|
||||
HGImgFmt \
|
||||
|
|
|
@ -18,24 +18,21 @@ Manager::Manager()
|
|||
, m_settingUiCallback(std::function<void(ui_result)>())
|
||||
, m_settingUi(nullptr)
|
||||
, m_progressUi(nullptr)
|
||||
, m_msgBoxUi(nullptr)
|
||||
{
|
||||
HGBase_CreateEvent(HGFALSE, HGFALSE, &m_event);
|
||||
|
||||
qRegisterMetaType<HGImage>("HGImage");
|
||||
|
||||
connect(this, SIGNAL(init()), this, SLOT(on_init()));
|
||||
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)));
|
||||
connect(this, SIGNAL(createSaneSrcUi(bool)), this, SLOT(on_createSaneSrcUi(bool)));
|
||||
connect(this, SIGNAL(createAbnormalImgUi(bool, HGImage)), this, SLOT(on_createAbnormalImgUi(bool, HGImage)), Qt::BlockingQueuedConnection);
|
||||
connect(this, SIGNAL(createDeviceSelect(unsigned int)), this, SLOT(on_createDeviceSelect(unsigned int)));
|
||||
connect(this, SIGNAL(createSettingUi(unsigned int)), this, SLOT(on_createSettingUi(unsigned int)));
|
||||
connect(this, SIGNAL(createProgressUi(unsigned int)), this, SLOT(on_createProgressUi(unsigned int)));
|
||||
connect(this, SIGNAL(createMessageBoxUi(unsigned int)), this, SLOT(on_createMessageBoxUi(unsigned int)));
|
||||
connect(this, SIGNAL(createTwainSrcUi(unsigned int)), this, SLOT(on_createTwainSrcUi(unsigned int)));
|
||||
connect(this, SIGNAL(createSaneSrcUi(unsigned int)), this, SLOT(on_createSaneSrcUi(unsigned int)));
|
||||
connect(this, SIGNAL(createAbnormalImgUi(unsigned int, HGImage)), this, SLOT(on_createAbnormalImgUi(unsigned int, HGImage)));
|
||||
|
||||
connect(this, SIGNAL(deleteSettingUi()), this, SLOT(on_deleteSettingUi()));
|
||||
connect(this, SIGNAL(deleteProgressUi()), this, SLOT(on_deleteProgressUi()));
|
||||
connect(this, SIGNAL(deleteMessageBoxUi()), this, SLOT(on_deleteMessageBoxUi()));
|
||||
connect(this, SIGNAL(deleteSettingUi(unsigned int)), this, SLOT(on_deleteSettingUi(unsigned int)));
|
||||
connect(this, SIGNAL(deleteProgressUi(unsigned int)), this, SLOT(on_deleteProgressUi(unsigned int)));
|
||||
connect(this, SIGNAL(deleteMessageBoxUi(unsigned int)), this, SLOT(on_deleteMessageBoxUi(unsigned int)));
|
||||
|
||||
emit init();
|
||||
}
|
||||
|
@ -45,20 +42,22 @@ Manager::~Manager()
|
|||
QCoreApplication::removeTranslator(&m_translator);
|
||||
if (936 == m_langCode)
|
||||
QCoreApplication::removeTranslator(&m_translator_qt);
|
||||
|
||||
HGBase_DestroyEvent(m_event);
|
||||
}
|
||||
|
||||
int Manager::showDeviceSelect(bool qt, const std::vector<DEVQUEUI>& devs)
|
||||
int Manager::showDeviceSelect(const std::vector<DEVQUEUI>& devs)
|
||||
{
|
||||
// param
|
||||
m_DeviceSelectDevs = devs;
|
||||
#ifdef HG_CMP_MSC
|
||||
m_DeviceSelectThreadId = GetCurrentThreadId();
|
||||
#endif
|
||||
emit createDeviceSelect(qt);
|
||||
|
||||
unsigned int ThreadId = 0;
|
||||
#ifdef HG_CMP_MSC
|
||||
if (!qt)
|
||||
if (qApp->thread() != QThread::currentThread())
|
||||
ThreadId = GetCurrentThreadId();
|
||||
#endif
|
||||
|
||||
emit createDeviceSelect(ThreadId);
|
||||
#ifdef HG_CMP_MSC
|
||||
if (0 != ThreadId)
|
||||
{
|
||||
MSG msg;
|
||||
while (GetMessage(&msg, NULL, 0, 0))
|
||||
|
@ -69,11 +68,13 @@ int Manager::showDeviceSelect(bool qt, const std::vector<DEVQUEUI>& devs)
|
|||
}
|
||||
#endif
|
||||
|
||||
// ret
|
||||
return m_DeviceSelectResult;
|
||||
}
|
||||
|
||||
int Manager::showSettingUi(bool qt, SANE_Handle device, HWND parent, LPSANEAPI api, const char * devName, gb::scanner_cfg* cfg, bool with_scan, std::function<void (ui_result)> callback)
|
||||
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)
|
||||
{
|
||||
// param
|
||||
m_device = device;
|
||||
scanner_cfg_ = cfg;
|
||||
m_settingUiParent = (HGWindow)parent;
|
||||
|
@ -81,28 +82,17 @@ int Manager::showSettingUi(bool qt, SANE_Handle device, HWND parent, LPSANEAPI a
|
|||
m_devName = devName;
|
||||
m_with_scan = with_scan;
|
||||
m_settingUiCallback = callback;
|
||||
|
||||
unsigned int ThreadId = 0;
|
||||
#ifdef HG_CMP_MSC
|
||||
m_SettingUiThreadId = GetCurrentThreadId();
|
||||
if (qApp->thread() != QThread::currentThread())
|
||||
ThreadId = GetCurrentThreadId();
|
||||
#endif
|
||||
emit createSettingUi(qt);
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Manager::showProgressUi(bool qt, HWND parent, std::function<void (ui_result)> callback, std::function<void (int, void *, int)> *notify)
|
||||
{
|
||||
m_progressUiparent = (HGWindow)parent;
|
||||
if (nullptr != m_settingUi)
|
||||
m_progressUiparent = (HGWindow)m_settingUi->winId();
|
||||
m_progressUiCallback = callback;
|
||||
m_notify = notify;
|
||||
emit createSettingUi(ThreadId);
|
||||
/*
|
||||
#ifdef HG_CMP_MSC
|
||||
m_ProgressUiThreadId = GetCurrentThreadId();
|
||||
#endif
|
||||
emit createProgressUi(qt);
|
||||
|
||||
#ifdef HG_CMP_MSC
|
||||
if (!qt)
|
||||
if (0 != ThreadId)
|
||||
{
|
||||
MSG msg;
|
||||
while (GetMessage(&msg, NULL, 0, 0))
|
||||
|
@ -112,23 +102,59 @@ int Manager::showProgressUi(bool qt, HWND parent, std::function<void (ui_result)
|
|||
}
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Manager::showMessageBoxUi(bool qt, HWND parent, int event, void *msg, int flag)
|
||||
int Manager::showProgressUi(HWND parent, std::function<void (ui_result)> callback, std::function<void (int, void *, int)> *notify)
|
||||
{
|
||||
m_messageBoxUiParent = nullptr;
|
||||
// param
|
||||
m_progressUiparent = (HGWindow)parent;
|
||||
m_progressUiCallback = callback;
|
||||
m_notify = notify;
|
||||
|
||||
unsigned int ThreadId = 0;
|
||||
#ifdef HG_CMP_MSC
|
||||
if (qApp->thread() != QThread::currentThread())
|
||||
ThreadId = GetCurrentThreadId();
|
||||
#endif
|
||||
|
||||
emit createProgressUi(ThreadId);
|
||||
/*
|
||||
#ifdef HG_CMP_MSC
|
||||
if (0 != ThreadId)
|
||||
{
|
||||
MSG msg;
|
||||
while (GetMessage(&msg, NULL, 0, 0))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Manager::showMessageBoxUi(HWND parent, int event, void *msg, int flag)
|
||||
{
|
||||
// param
|
||||
m_messageBoxUiParent = (HGWindow)parent;
|
||||
m_notifyEvent = event;
|
||||
m_message = (char*)msg;
|
||||
m_flag = flag;
|
||||
#ifdef HG_CMP_MSC
|
||||
m_MessageBoxUiThreadId = GetCurrentThreadId();
|
||||
#endif
|
||||
emit createMessageBoxUi(qt);
|
||||
|
||||
unsigned int ThreadId = 0;
|
||||
#ifdef HG_CMP_MSC
|
||||
if (!qt)
|
||||
if (qApp->thread() != QThread::currentThread())
|
||||
ThreadId = GetCurrentThreadId();
|
||||
#endif
|
||||
|
||||
emit createMessageBoxUi(ThreadId);
|
||||
#ifdef HG_CMP_MSC
|
||||
if (0 != ThreadId)
|
||||
{
|
||||
MSG msg;
|
||||
while (GetMessage(&msg, NULL, 0, 0))
|
||||
|
@ -142,13 +168,9 @@ int Manager::showMessageBoxUi(bool qt, HWND parent, int event, void *msg, int fl
|
|||
return 0;
|
||||
}
|
||||
|
||||
int Manager::showTwainSrcUi(bool qt, const TW_IDENTITY *vds, HGUInt count, const char* defDevName, HGWindow parent, TW_IDENTITY *ds)
|
||||
int Manager::showTwainSrcUi(const TW_IDENTITY *vds, HGUInt count, const char* defDevName, HGWindow parent, TW_IDENTITY *ds)
|
||||
{
|
||||
#ifdef HG_CMP_MSC
|
||||
m_twainSrcUiThreadId = GetCurrentThreadId();
|
||||
#endif
|
||||
m_TwainSrcUiparent = parent;
|
||||
|
||||
m_vds.clear();
|
||||
for (int i = 0; i < count; ++i)
|
||||
{
|
||||
|
@ -157,9 +179,15 @@ int Manager::showTwainSrcUi(bool qt, const TW_IDENTITY *vds, HGUInt count, const
|
|||
m_defDsName = defDevName;
|
||||
memset(&m_ds, 0, sizeof(TW_IDENTITY));
|
||||
|
||||
emit createTwainSrcUi(qt);
|
||||
unsigned int ThreadId = 0;
|
||||
#ifdef HG_CMP_MSC
|
||||
if (!qt)
|
||||
if (qApp->thread() != QThread::currentThread())
|
||||
ThreadId = GetCurrentThreadId();
|
||||
#endif
|
||||
|
||||
emit createTwainSrcUi(ThreadId);
|
||||
#ifdef HG_CMP_MSC
|
||||
if (0 != ThreadId)
|
||||
{
|
||||
MSG msg;
|
||||
while (GetMessage(&msg, NULL, 0, 0))
|
||||
|
@ -169,18 +197,17 @@ int Manager::showTwainSrcUi(bool qt, const TW_IDENTITY *vds, HGUInt count, const
|
|||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// ret
|
||||
memcpy(ds, &m_ds, sizeof(TW_IDENTITY));
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Manager::showSaneSrcUi(bool qt, const char **manuNames, const char **sanePaths, HGWindow parent, HGDll *dll,
|
||||
int Manager::showSaneSrcUi(const char **manuNames, const char **sanePaths, HGWindow parent, HGDll *dll,
|
||||
SANEAPI* saneApi, char *manuName, unsigned int maxLen)
|
||||
{
|
||||
#ifdef HG_CMP_MSC
|
||||
m_saneSrcUiThreadId = GetCurrentThreadId();
|
||||
#endif
|
||||
// param
|
||||
m_SaneSrcUiparent = parent;
|
||||
|
||||
m_saneSource.clear();
|
||||
const char **p1 = manuNames;
|
||||
const char **p2 = sanePaths;
|
||||
|
@ -198,9 +225,15 @@ int Manager::showSaneSrcUi(bool qt, const char **manuNames, const char **sanePat
|
|||
memset(&m_saneApi, 0, sizeof(SANEAPI));
|
||||
m_saneManuName.clear();
|
||||
|
||||
emit createSaneSrcUi(qt);
|
||||
unsigned int ThreadId = 0;
|
||||
#ifdef HG_CMP_MSC
|
||||
if (!qt)
|
||||
if (qApp->thread() != QThread::currentThread())
|
||||
ThreadId = GetCurrentThreadId();
|
||||
#endif
|
||||
|
||||
emit createSaneSrcUi(ThreadId);
|
||||
#ifdef HG_CMP_MSC
|
||||
if (0 != ThreadId)
|
||||
{
|
||||
MSG msg;
|
||||
while (GetMessage(&msg, NULL, 0, 0))
|
||||
|
@ -210,14 +243,17 @@ int Manager::showSaneSrcUi(bool qt, const char **manuNames, const char **sanePat
|
|||
}
|
||||
}
|
||||
#endif
|
||||
|
||||
// ret
|
||||
*dll = m_saneDll;
|
||||
memcpy(saneApi, &m_saneApi, sizeof(SANEAPI));
|
||||
strcpy(manuName, m_saneManuName.c_str());
|
||||
return 0;
|
||||
}
|
||||
|
||||
int Manager::showAbnormalImgUi(bool qt, SANE_Image *img)
|
||||
int Manager::showAbnormalImgUi(SANE_Image *img)
|
||||
{
|
||||
// param
|
||||
HGUInt imgType = 0;
|
||||
if (img->header.format == SANE_FRAME_GRAY)
|
||||
{
|
||||
|
@ -237,15 +273,15 @@ int Manager::showAbnormalImgUi(bool qt, SANE_Image *img)
|
|||
HGImage image = NULL;
|
||||
HGBase_CreateImageWithData(img->data, &imgInfo, &image);
|
||||
|
||||
unsigned int ThreadId = 0;
|
||||
#ifdef HG_CMP_MSC
|
||||
m_abnormalImgThreadId = GetCurrentThreadId();
|
||||
if (qApp->thread() != QThread::currentThread())
|
||||
ThreadId = GetCurrentThreadId();
|
||||
#endif
|
||||
|
||||
emit createAbnormalImgUi(qt, image);
|
||||
HGBase_DestroyImage(image);
|
||||
|
||||
emit createAbnormalImgUi(ThreadId, image);
|
||||
#ifdef HG_CMP_MSC
|
||||
if (!qt)
|
||||
if (0 != ThreadId)
|
||||
{
|
||||
MSG msg;
|
||||
while (GetMessage(&msg, NULL, 0, 0))
|
||||
|
@ -256,22 +292,81 @@ int Manager::showAbnormalImgUi(bool qt, SANE_Image *img)
|
|||
}
|
||||
#endif
|
||||
|
||||
// ret
|
||||
HGBase_DestroyImage(image);
|
||||
return m_abnormalImgResult;
|
||||
}
|
||||
|
||||
void Manager::closeSettingUi()
|
||||
{
|
||||
emit deleteSettingUi();
|
||||
unsigned int ThreadId = 0;
|
||||
#ifdef HG_CMP_MSC
|
||||
if (qApp->thread() != QThread::currentThread())
|
||||
ThreadId = GetCurrentThreadId();
|
||||
#endif
|
||||
|
||||
emit deleteSettingUi(ThreadId);
|
||||
/*
|
||||
#ifdef HG_CMP_MSC
|
||||
if (0 != ThreadId)
|
||||
{
|
||||
MSG msg;
|
||||
while (GetMessage(&msg, NULL, 0, 0))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
}
|
||||
|
||||
void Manager::closeProgressUi()
|
||||
{
|
||||
emit deleteProgressUi();
|
||||
unsigned int ThreadId = 0;
|
||||
#ifdef HG_CMP_MSC
|
||||
if (qApp->thread() != QThread::currentThread())
|
||||
ThreadId = GetCurrentThreadId();
|
||||
#endif
|
||||
|
||||
emit deleteProgressUi(ThreadId);
|
||||
/*
|
||||
#ifdef HG_CMP_MSC
|
||||
if (0 != ThreadId)
|
||||
{
|
||||
MSG msg;
|
||||
while (GetMessage(&msg, NULL, 0, 0))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
}
|
||||
|
||||
void Manager::closeMessageBoxUi()
|
||||
{
|
||||
emit deleteMessageBoxUi();
|
||||
unsigned int ThreadId = 0;
|
||||
#ifdef HG_CMP_MSC
|
||||
if (qApp->thread() != QThread::currentThread())
|
||||
ThreadId = GetCurrentThreadId();
|
||||
#endif
|
||||
|
||||
emit deleteMessageBoxUi(ThreadId);
|
||||
/*
|
||||
#ifdef HG_CMP_MSC
|
||||
if (0 != ThreadId)
|
||||
{
|
||||
MSG msg;
|
||||
while (GetMessage(&msg, NULL, 0, 0))
|
||||
{
|
||||
TranslateMessage(&msg);
|
||||
DispatchMessage(&msg);
|
||||
}
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
}
|
||||
|
||||
void Manager::clear_functions(void)
|
||||
|
@ -303,20 +398,21 @@ void Manager::on_init()
|
|||
QCoreApplication::installTranslator(&m_translator_qt);
|
||||
}
|
||||
|
||||
void Manager::on_createDeviceSelect(bool qt)
|
||||
void Manager::on_createDeviceSelect(unsigned int ThreadId)
|
||||
{
|
||||
Dialog_device_select *dlg = new Dialog_device_select(m_DeviceSelectDevs);
|
||||
dlg->exec();
|
||||
m_DeviceSelectResult = dlg->getDevId();
|
||||
Dialog_device_select dlg(m_DeviceSelectDevs);
|
||||
dlg.exec();
|
||||
m_DeviceSelectResult = dlg.getDevId();
|
||||
|
||||
#ifdef HG_CMP_MSC
|
||||
if (!qt)
|
||||
if (0 != ThreadId)
|
||||
{
|
||||
::PostThreadMessage(m_DeviceSelectThreadId, WM_QUIT, 0, 0);
|
||||
::PostThreadMessage(ThreadId, WM_QUIT, 0, 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Manager::on_createSettingUi(bool qt)
|
||||
void Manager::on_createSettingUi(unsigned int ThreadId)
|
||||
{
|
||||
QWidget *qParent = nullptr;
|
||||
#ifdef HG_CMP_MSC
|
||||
|
@ -342,10 +438,22 @@ void Manager::on_createSettingUi(bool qt)
|
|||
m_settingUi = new hg_settingdialog(this, m_device, &m_api, m_with_scan, m_devName.c_str(), scanner_cfg_, close_prog, qParent);
|
||||
m_settingUi->setModal(true);
|
||||
m_settingUi->show();
|
||||
|
||||
/*
|
||||
#ifdef HG_CMP_MSC
|
||||
if (0 != ThreadId)
|
||||
{
|
||||
::PostThreadMessage(ThreadId, WM_QUIT, 0, 0);
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
}
|
||||
|
||||
void Manager::on_createProgressUi(bool qt)
|
||||
void Manager::on_createProgressUi(unsigned int ThreadId)
|
||||
{
|
||||
if (nullptr != m_settingUi)
|
||||
m_progressUiparent = (HGWindow)m_settingUi->winId();
|
||||
|
||||
QWidget *qParent = nullptr;
|
||||
#ifdef HG_CMP_MSC
|
||||
if (nullptr != m_progressUiparent)
|
||||
|
@ -361,7 +469,6 @@ void Manager::on_createProgressUi(bool qt)
|
|||
|
||||
auto close_prog = [&](ui_result r) ->void
|
||||
{
|
||||
//m_progressUi = nullptr;
|
||||
if(m_progressUiCallback)
|
||||
m_progressUiCallback(r);
|
||||
|
||||
|
@ -373,50 +480,44 @@ void Manager::on_createProgressUi(bool qt)
|
|||
m_progressUi = new Dialog_progress_ui(this, close_prog, m_notify, qParent);
|
||||
m_progressUi->setModal(true);
|
||||
m_progressUi->show();
|
||||
|
||||
/*
|
||||
#ifdef HG_CMP_MSC
|
||||
if (!qt)
|
||||
if (0 != ThreadId)
|
||||
{
|
||||
::PostThreadMessage(m_ProgressUiThreadId, WM_QUIT, 0, 0);
|
||||
::PostThreadMessage(ThreadId, WM_QUIT, 0, 0);
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
}
|
||||
|
||||
void Manager::on_createMessageBoxUi(bool qt)
|
||||
void Manager::on_createMessageBoxUi(unsigned int ThreadId)
|
||||
{
|
||||
if (m_msgBoxUi != nullptr)
|
||||
{
|
||||
delete m_msgBoxUi;
|
||||
m_msgBoxUi = nullptr;
|
||||
}
|
||||
|
||||
QWidget *qParent = nullptr;
|
||||
#ifdef HG_CMP_MSC
|
||||
QWinWidget win(m_messageBoxUiParent);
|
||||
if (nullptr != m_messageBoxUiParent)
|
||||
{
|
||||
QWinWidget *win = new QWinWidget(m_messageBoxUiParent);
|
||||
win->showCentered();
|
||||
qParent = win;
|
||||
win.showCentered();
|
||||
qParent = &win;
|
||||
}
|
||||
#else
|
||||
qParent = m_messageBoxUiParent;
|
||||
#endif
|
||||
|
||||
assert(m_msgBoxUi == nullptr);
|
||||
m_msgBoxUi = new QMessageBox(QMessageBox::Critical, tr("Prompt"), QString::fromStdString(m_message), QMessageBox::Ok, qParent);
|
||||
m_msgBoxUi->setWindowFlags(Qt::SubWindow | Qt::Popup | Qt::WindowStaysOnTopHint);
|
||||
//m_msgBoxUi->setModal(true);
|
||||
m_msgBoxUi->exec();
|
||||
delete m_msgBoxUi;
|
||||
m_msgBoxUi = nullptr;
|
||||
QMessageBox dlg(QMessageBox::Critical, tr("Prompt"), QString::fromStdString(m_message), QMessageBox::Ok, qParent);
|
||||
dlg.setWindowFlags(Qt::SubWindow | Qt::Popup | Qt::WindowStaysOnTopHint);
|
||||
dlg.exec();
|
||||
|
||||
#ifdef HG_CMP_MSC
|
||||
if (!qt)
|
||||
if (0 != ThreadId)
|
||||
{
|
||||
::PostThreadMessage(m_MessageBoxUiThreadId, WM_QUIT, 0, 0);
|
||||
::PostThreadMessage(ThreadId, WM_QUIT, 0, 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Manager::on_createTwainSrcUi(bool qt)
|
||||
void Manager::on_createTwainSrcUi(unsigned int ThreadId)
|
||||
{
|
||||
QWidget *qParent = nullptr;
|
||||
#ifdef HG_CMP_MSC
|
||||
|
@ -430,20 +531,21 @@ void Manager::on_createTwainSrcUi(bool qt)
|
|||
qParent = m_TwainSrcUiparent;
|
||||
#endif
|
||||
|
||||
Dialog_Twain_Source_Select *dlg = new Dialog_Twain_Source_Select (m_vds, m_defDsName, qParent);
|
||||
if (dlg->exec())
|
||||
Dialog_Twain_Source_Select dlg(m_vds, m_defDsName, qParent);
|
||||
if (dlg.exec())
|
||||
{
|
||||
dlg->GetIdentify(&m_ds);
|
||||
dlg.GetIdentify(&m_ds);
|
||||
}
|
||||
|
||||
#ifdef HG_CMP_MSC
|
||||
if (!qt)
|
||||
if (0 != ThreadId)
|
||||
{
|
||||
::PostThreadMessage(m_twainSrcUiThreadId, WM_QUIT, 0, 0);
|
||||
::PostThreadMessage(ThreadId, WM_QUIT, 0, 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Manager::on_createSaneSrcUi(bool qt)
|
||||
void Manager::on_createSaneSrcUi(unsigned int ThreadId)
|
||||
{
|
||||
QWidget *qParent = nullptr;
|
||||
#ifdef HG_CMP_MSC
|
||||
|
@ -457,41 +559,37 @@ void Manager::on_createSaneSrcUi(bool qt)
|
|||
qParent = m_SaneSrcUiparent;
|
||||
#endif
|
||||
|
||||
Dialog_Source_Select *dlg = new Dialog_Source_Select (m_saneSource, qParent);
|
||||
if (dlg->exec())
|
||||
Dialog_Source_Select dlg(m_saneSource, qParent);
|
||||
if (dlg.exec())
|
||||
{
|
||||
m_saneManuName = dlg->GetManuName();
|
||||
m_saneDll = dlg->GetDll();
|
||||
dlg->GetSaneAPI(&m_saneApi);
|
||||
m_saneManuName = dlg.GetManuName();
|
||||
m_saneDll = dlg.GetDll();
|
||||
dlg.GetSaneAPI(&m_saneApi);
|
||||
}
|
||||
|
||||
#ifdef HG_CMP_MSC
|
||||
if (!qt)
|
||||
if (0 != ThreadId)
|
||||
{
|
||||
::PostThreadMessage(m_saneSrcUiThreadId, WM_QUIT, 0, 0);
|
||||
::PostThreadMessage(ThreadId, WM_QUIT, 0, 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Manager::on_createAbnormalImgUi(bool qt, HGImage image)
|
||||
void Manager::on_createAbnormalImgUi(unsigned int ThreadId, HGImage image)
|
||||
{
|
||||
Dialog_abnormal_img_select* dlg = nullptr;
|
||||
Dialog_abnormal_img_select dlg(image, m_progressUi);
|
||||
dlg.exec();
|
||||
m_abnormalImgResult = dlg.getUserSelect();
|
||||
|
||||
if (m_progressUi != nullptr)
|
||||
dlg = new Dialog_abnormal_img_select(image, m_progressUi);
|
||||
else
|
||||
dlg = new Dialog_abnormal_img_select(image);
|
||||
|
||||
dlg->exec();
|
||||
m_abnormalImgResult = dlg->getUserSelect();
|
||||
#ifdef HG_CMP_MSC
|
||||
if (!qt)
|
||||
if (0 != ThreadId)
|
||||
{
|
||||
::PostThreadMessage(m_abnormalImgThreadId, WM_QUIT, 0, 0);
|
||||
::PostThreadMessage(ThreadId, WM_QUIT, 0, 0);
|
||||
}
|
||||
#endif
|
||||
}
|
||||
|
||||
void Manager::on_deleteSettingUi()
|
||||
void Manager::on_deleteSettingUi(unsigned int ThreadId)
|
||||
{
|
||||
if (m_settingUi != nullptr)
|
||||
{
|
||||
|
@ -499,9 +597,18 @@ void Manager::on_deleteSettingUi()
|
|||
delete m_settingUi;
|
||||
m_settingUi = nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
#ifdef HG_CMP_MSC
|
||||
if (0 != ThreadId)
|
||||
{
|
||||
::PostThreadMessage(ThreadId, WM_QUIT, 0, 0);
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
}
|
||||
|
||||
void Manager::on_deleteProgressUi()
|
||||
void Manager::on_deleteProgressUi(unsigned int ThreadId)
|
||||
{
|
||||
if (m_progressUi != nullptr)
|
||||
{
|
||||
|
@ -509,13 +616,25 @@ void Manager::on_deleteProgressUi()
|
|||
delete m_progressUi;
|
||||
m_progressUi = nullptr;
|
||||
}
|
||||
|
||||
/*
|
||||
#ifdef HG_CMP_MSC
|
||||
if (0 != ThreadId)
|
||||
{
|
||||
::PostThreadMessage(ThreadId, WM_QUIT, 0, 0);
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
}
|
||||
|
||||
void Manager::on_deleteMessageBoxUi()
|
||||
void Manager::on_deleteMessageBoxUi(unsigned int ThreadId)
|
||||
{
|
||||
if (m_msgBoxUi != nullptr)
|
||||
/*
|
||||
#ifdef HG_CMP_MSC
|
||||
if (0 != ThreadId)
|
||||
{
|
||||
delete m_msgBoxUi;
|
||||
m_msgBoxUi = nullptr;
|
||||
::PostThreadMessage(ThreadId, WM_QUIT, 0, 0);
|
||||
}
|
||||
#endif
|
||||
*/
|
||||
}
|
||||
|
|
|
@ -17,14 +17,14 @@ public:
|
|||
Manager();
|
||||
~Manager();
|
||||
|
||||
int showDeviceSelect(bool qt, const std::vector<DEVQUEUI>& devs);
|
||||
int showSettingUi(bool qt, SANE_Handle device, HWND settingUiParent, LPSANEAPI api, const char * devName, gb::scanner_cfg* cfg, 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 showMessageBoxUi(bool qt, HWND parent, int event, void *msg, int flag);
|
||||
int showTwainSrcUi(bool qt, const TW_IDENTITY *vds, HGUInt count, const char* defDevName, HGWindow parent, TW_IDENTITY *ds);
|
||||
int showSaneSrcUi(bool qt, const char **manuNames, const char **sanePaths, HGWindow parent, HGDll *dll,
|
||||
int showDeviceSelect(const std::vector<DEVQUEUI>& devs);
|
||||
int showSettingUi(SANE_Handle device, HWND settingUiParent, LPSANEAPI api, const char * devName, gb::scanner_cfg* cfg, bool with_scan, std::function<void(ui_result)> callback);
|
||||
int showProgressUi(HWND parent, std::function<void (ui_result)> callback, std::function<void (int, void *, int)> *notify);
|
||||
int showMessageBoxUi(HWND parent, int event, void *msg, int flag);
|
||||
int showTwainSrcUi(const TW_IDENTITY *vds, HGUInt count, const char* defDevName, HGWindow parent, TW_IDENTITY *ds);
|
||||
int showSaneSrcUi(const char **manuNames, const char **sanePaths, HGWindow parent, HGDll *dll,
|
||||
SANEAPI* saneApi, char *manuName, unsigned int maxLen);
|
||||
int showAbnormalImgUi(bool qt, SANE_Image *img);
|
||||
int showAbnormalImgUi(SANE_Image *img);
|
||||
|
||||
void closeSettingUi();
|
||||
void closeProgressUi();
|
||||
|
@ -34,50 +34,41 @@ public:
|
|||
|
||||
signals:
|
||||
void init();
|
||||
void createDeviceSelect(bool qt);
|
||||
void createSettingUi(bool qt);
|
||||
void createProgressUi(bool qt);
|
||||
void createMessageBoxUi(bool qt);
|
||||
void createTwainSrcUi(bool qt);
|
||||
void createSaneSrcUi(bool qt);
|
||||
void createAbnormalImgUi(bool qt, HGImage image);
|
||||
void createDeviceSelect(unsigned int ThreadId);
|
||||
void createSettingUi(unsigned int ThreadId);
|
||||
void createProgressUi(unsigned int ThreadId);
|
||||
void createMessageBoxUi(unsigned int ThreadId);
|
||||
void createTwainSrcUi(unsigned int ThreadId);
|
||||
void createSaneSrcUi(unsigned int ThreadId);
|
||||
void createAbnormalImgUi(unsigned int ThreadId, HGImage image);
|
||||
|
||||
void deleteSettingUi();
|
||||
void deleteProgressUi();
|
||||
void deleteMessageBoxUi();
|
||||
void deleteManager();
|
||||
void deleteSettingUi(unsigned int ThreadId);
|
||||
void deleteProgressUi(unsigned int ThreadId);
|
||||
void deleteMessageBoxUi(unsigned int ThreadId);
|
||||
|
||||
private slots:
|
||||
void on_init();
|
||||
void on_createDeviceSelect(bool qt);
|
||||
void on_createSettingUi(bool qt);
|
||||
void on_createProgressUi(bool qt);
|
||||
void on_createMessageBoxUi(bool qt);
|
||||
void on_createTwainSrcUi(bool qt);
|
||||
void on_createSaneSrcUi(bool qt);
|
||||
void on_createAbnormalImgUi(bool qt, HGImage image);
|
||||
void on_createDeviceSelect(unsigned int ThreadId);
|
||||
void on_createSettingUi(unsigned int ThreadId);
|
||||
void on_createProgressUi(unsigned int ThreadId);
|
||||
void on_createMessageBoxUi(unsigned int ThreadId);
|
||||
void on_createTwainSrcUi(unsigned int ThreadId);
|
||||
void on_createSaneSrcUi(unsigned int ThreadId);
|
||||
void on_createAbnormalImgUi(unsigned int ThreadId, HGImage image);
|
||||
|
||||
void on_deleteSettingUi();
|
||||
void on_deleteProgressUi();
|
||||
void on_deleteMessageBoxUi();
|
||||
void on_deleteSettingUi(unsigned int ThreadId);
|
||||
void on_deleteProgressUi(unsigned int ThreadId);
|
||||
void on_deleteMessageBoxUi(unsigned int ThreadId);
|
||||
|
||||
public:
|
||||
QTranslator m_translator;
|
||||
QTranslator m_translator_qt;
|
||||
int m_langCode;
|
||||
|
||||
HGEvent m_event;
|
||||
|
||||
std::vector<DEVQUEUI> m_DeviceSelectDevs;
|
||||
#ifdef HG_CMP_MSC
|
||||
unsigned long m_DeviceSelectThreadId;
|
||||
#endif
|
||||
int m_DeviceSelectResult;
|
||||
|
||||
hg_settingdialog *m_settingUi;
|
||||
#ifdef HG_CMP_MSC
|
||||
unsigned long m_SettingUiThreadId;
|
||||
#endif
|
||||
SANE_Handle m_device;
|
||||
HGWindow m_settingUiParent;
|
||||
SANEAPI m_api;
|
||||
|
@ -88,40 +79,24 @@ public:
|
|||
|
||||
Dialog_progress_ui *m_progressUi;
|
||||
HGWindow m_progressUiparent;
|
||||
#ifdef HG_CMP_MSC
|
||||
unsigned long m_ProgressUiThreadId;
|
||||
#endif
|
||||
std::function<void (ui_result)> m_progressUiCallback;
|
||||
std::function<void (int, void *, int)> *m_notify;
|
||||
|
||||
QMessageBox *m_msgBoxUi;
|
||||
#ifdef HG_CMP_MSC
|
||||
unsigned long m_MessageBoxUiThreadId;
|
||||
#endif
|
||||
HGWindow m_messageBoxUiParent;
|
||||
int m_notifyEvent;
|
||||
std::string m_message;
|
||||
int m_flag;
|
||||
|
||||
#ifdef HG_CMP_MSC
|
||||
unsigned long m_twainSrcUiThreadId;
|
||||
#endif
|
||||
std::vector<TW_IDENTITY> m_vds;
|
||||
std::string m_defDsName;
|
||||
HGWindow m_TwainSrcUiparent;
|
||||
TW_IDENTITY m_ds;
|
||||
|
||||
#ifdef HG_CMP_MSC
|
||||
unsigned long m_saneSrcUiThreadId;
|
||||
#endif
|
||||
std::vector<std::pair<std::string, std::string> > m_saneSource;
|
||||
HGWindow m_SaneSrcUiparent;
|
||||
HGDll m_saneDll;
|
||||
SANEAPI m_saneApi;
|
||||
std::string m_saneManuName;
|
||||
|
||||
#ifdef HG_CMP_MSC
|
||||
unsigned long m_abnormalImgThreadId;
|
||||
#endif
|
||||
int m_abnormalImgResult;
|
||||
};
|
||||
|
|
|
@ -40,7 +40,7 @@ static void HGAPI ThreadFunc(HGThread thread, HGPointer param)
|
|||
}
|
||||
}
|
||||
|
||||
int choose_scanner(const std::vector<DEVQUEUI> &devs)
|
||||
static void Init()
|
||||
{
|
||||
if (!qApp)
|
||||
{
|
||||
|
@ -48,28 +48,28 @@ int choose_scanner(const std::vector<DEVQUEUI> &devs)
|
|||
HGBase_OpenThread(ThreadFunc, NULL, &g_hThread);
|
||||
HGBase_WaitEvent(g_event);
|
||||
}
|
||||
|
||||
if (NULL == g_manager)
|
||||
else
|
||||
{
|
||||
g_manager = new Manager;
|
||||
if (NULL == g_manager)
|
||||
{
|
||||
g_manager = new Manager;
|
||||
//g_manager->moveToThread(qApp->thread());
|
||||
}
|
||||
}
|
||||
|
||||
return g_manager->showDeviceSelect(nullptr == g_hThread, devs);
|
||||
assert(nullptr != g_manager);
|
||||
}
|
||||
|
||||
int choose_scanner(const std::vector<DEVQUEUI> &devs)
|
||||
{
|
||||
Init();
|
||||
|
||||
return g_manager->showDeviceSelect(devs);
|
||||
}
|
||||
|
||||
char *apply_current_config(const char *dev_name, SANE_Handle device, LPSANEAPI api) // this function only called after scanner open
|
||||
{
|
||||
if (!qApp)
|
||||
{
|
||||
HGBase_CreateEvent(HGTRUE, HGFALSE, &g_event);
|
||||
HGBase_OpenThread(ThreadFunc, NULL, &g_hThread);
|
||||
HGBase_WaitEvent(g_event);
|
||||
}
|
||||
|
||||
if (NULL == g_manager)
|
||||
{
|
||||
g_manager = new Manager;
|
||||
}
|
||||
Init();
|
||||
|
||||
dev_que devQue;
|
||||
gb::scanner_cfg *cur_cfg_ = nullptr;
|
||||
|
@ -195,88 +195,38 @@ void twain_ui_free(void *buf)
|
|||
|
||||
int show_setting_ui(SANE_Handle device, HWND parent, LPSANEAPI api, const char *devName, bool with_scan, std::function<void(ui_result)> callback)
|
||||
{
|
||||
if (!qApp)
|
||||
{
|
||||
HGBase_CreateEvent(HGTRUE, HGFALSE, &g_event);
|
||||
HGBase_OpenThread(ThreadFunc, NULL, &g_hThread);
|
||||
HGBase_WaitEvent(g_event);
|
||||
}
|
||||
Init();
|
||||
|
||||
if (NULL == g_manager)
|
||||
{
|
||||
g_manager = new Manager;
|
||||
}
|
||||
|
||||
return g_manager->showSettingUi(nullptr == g_hThread, device, parent, api, devName, scanner_cfg_, with_scan, callback);
|
||||
return g_manager->showSettingUi(device, parent, api, devName, scanner_cfg_, with_scan, callback);
|
||||
}
|
||||
|
||||
int show_progress_ui(HWND parent, std::function<void (ui_result)> callback, std::function<void (int, void *, int)> *notify)
|
||||
{
|
||||
if (!qApp)
|
||||
{
|
||||
HGBase_CreateEvent(HGTRUE, HGFALSE, &g_event);
|
||||
HGBase_OpenThread(ThreadFunc, NULL, &g_hThread);
|
||||
HGBase_WaitEvent(g_event);
|
||||
}
|
||||
Init();
|
||||
|
||||
if (NULL == g_manager)
|
||||
{
|
||||
g_manager = new Manager;
|
||||
}
|
||||
|
||||
return g_manager->showProgressUi(nullptr == g_hThread, parent, callback, notify);
|
||||
return g_manager->showProgressUi(parent, callback, notify);
|
||||
}
|
||||
|
||||
int show_messagebox_ui(HWND parent, int event, void *msg, int flag)
|
||||
{
|
||||
if (!qApp)
|
||||
{
|
||||
HGBase_CreateEvent(HGTRUE, HGFALSE, &g_event);
|
||||
HGBase_OpenThread(ThreadFunc, NULL, &g_hThread);
|
||||
HGBase_WaitEvent(g_event);
|
||||
}
|
||||
Init();
|
||||
|
||||
if (NULL == g_manager)
|
||||
{
|
||||
g_manager = new Manager;
|
||||
}
|
||||
|
||||
return g_manager->showMessageBoxUi(nullptr == g_hThread, parent, event, msg, flag);
|
||||
return g_manager->showMessageBoxUi(parent, event, msg, flag);
|
||||
}
|
||||
|
||||
int show_twain_srclist_ui(const TW_IDENTITY *vds, HGUInt count, const HGChar *defDsName, HGWindow parent, TW_IDENTITY *ds)
|
||||
{
|
||||
if (!qApp)
|
||||
{
|
||||
HGBase_CreateEvent(HGTRUE, HGFALSE, &g_event);
|
||||
HGBase_OpenThread(ThreadFunc, NULL, &g_hThread);
|
||||
HGBase_WaitEvent(g_event);
|
||||
}
|
||||
Init();
|
||||
|
||||
if (NULL == g_manager)
|
||||
{
|
||||
g_manager = new Manager;
|
||||
}
|
||||
|
||||
return g_manager->showTwainSrcUi(nullptr == g_hThread, vds, count, defDsName, parent, ds);
|
||||
return g_manager->showTwainSrcUi(vds, count, defDsName, parent, ds);
|
||||
}
|
||||
|
||||
int show_srclist_ui(const char **manuNames, const char **sanePaths, HGWindow parent, HGDll *dll,
|
||||
SANEAPI* saneApi, char *manuName, unsigned int maxLen)
|
||||
{
|
||||
if (!qApp)
|
||||
{
|
||||
HGBase_CreateEvent(HGTRUE, HGFALSE, &g_event);
|
||||
HGBase_OpenThread(ThreadFunc, NULL, &g_hThread);
|
||||
HGBase_WaitEvent(g_event);
|
||||
}
|
||||
Init();
|
||||
|
||||
if (NULL == g_manager)
|
||||
{
|
||||
g_manager = new Manager;
|
||||
}
|
||||
|
||||
return g_manager->showSaneSrcUi(nullptr == g_hThread, manuNames, sanePaths, parent, dll, saneApi, manuName, maxLen);
|
||||
return g_manager->showSaneSrcUi(manuNames, sanePaths, parent, dll, saneApi, manuName, maxLen);
|
||||
}
|
||||
|
||||
int close_ui(int which)
|
||||
|
@ -305,17 +255,14 @@ int close_ui(int which)
|
|||
|
||||
if (nullptr == g_hThread)
|
||||
{
|
||||
if (NULL != g_manager)
|
||||
{
|
||||
delete g_manager;
|
||||
g_manager = nullptr;
|
||||
}
|
||||
//g_manager->moveToThread(QThread::currentThread());
|
||||
delete g_manager;
|
||||
g_manager = nullptr;
|
||||
}
|
||||
else
|
||||
{
|
||||
#if 0
|
||||
QApplication::exit();
|
||||
|
||||
HGBase_CloseThread(g_hThread);
|
||||
g_hThread = NULL;
|
||||
HGBase_DestroyEvent(g_event);
|
||||
|
@ -334,17 +281,7 @@ void pump_ui_message(void* reserved)
|
|||
|
||||
int abnormal_image(SANE_Image *img, HGWindow parent)
|
||||
{
|
||||
if (!qApp)
|
||||
{
|
||||
HGBase_CreateEvent(HGTRUE, HGFALSE, &g_event);
|
||||
HGBase_OpenThread(ThreadFunc, NULL, &g_hThread);
|
||||
HGBase_WaitEvent(g_event);
|
||||
}
|
||||
Init();
|
||||
|
||||
if (NULL == g_manager)
|
||||
{
|
||||
g_manager = new Manager;
|
||||
}
|
||||
|
||||
return g_manager->showAbnormalImgUi(nullptr == g_hThread, img);
|
||||
return g_manager->showAbnormalImgUi(img);
|
||||
}
|
||||
|
|
Loading…
Reference in New Issue