378 lines
9.0 KiB
C++
378 lines
9.0 KiB
C++
#include "Manager.h"
|
|
#include <QApplication>
|
|
#ifdef HG_CMP_MSC
|
|
#include <qwinwidget.hpp>
|
|
#endif
|
|
#include "lang/app_language.h"
|
|
|
|
extern Manager* g_manager;
|
|
|
|
Manager::Manager()
|
|
: QObject(nullptr)
|
|
, m_progressUiCallback(std::function<void(ui_result)>())
|
|
, m_notify(nullptr)
|
|
, m_settingUiCallback(std::function<void(ui_result)>())
|
|
, m_settingUi(nullptr)
|
|
, m_progressUi(nullptr)
|
|
, m_msgBoxUi(nullptr)
|
|
{
|
|
HGBase_CreateEvent(HGFALSE, HGFALSE, &m_event);
|
|
|
|
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(deleteSettingUi()), this, SLOT(on_deleteSettingUi()));
|
|
connect(this, SIGNAL(deleteProgressUi()), this, SLOT(on_deleteProgressUi()));
|
|
connect(this, SIGNAL(deleteMessageBoxUi()), this, SLOT(on_deleteMessageBoxUi()));
|
|
|
|
emit init();
|
|
}
|
|
|
|
Manager::~Manager()
|
|
{
|
|
QCoreApplication::removeTranslator(&m_translator);
|
|
if (20127 != m_langCode)
|
|
QCoreApplication::removeTranslator(&m_translator_qt);
|
|
|
|
HGBase_DestroyEvent(m_event);
|
|
}
|
|
|
|
int Manager::showDeviceSelect(bool qt, const std::vector<DEVQUEUI>& devs)
|
|
{
|
|
m_DeviceSelectDevs = devs;
|
|
#ifdef HG_CMP_MSC
|
|
m_DeviceSelectThreadId = GetCurrentThreadId();
|
|
#endif
|
|
emit createDeviceSelect(qt);
|
|
|
|
#ifdef HG_CMP_MSC
|
|
if (!qt)
|
|
{
|
|
MSG msg;
|
|
while (GetMessage(&msg, NULL, 0, 0))
|
|
{
|
|
TranslateMessage(&msg);
|
|
DispatchMessage(&msg);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
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)
|
|
{
|
|
m_device = device;
|
|
scanner_cfg_ = cfg;
|
|
m_settingUiParent = (HGWindow)parent;
|
|
memcpy(&m_api, api, sizeof(m_api));
|
|
m_devName = devName;
|
|
m_with_scan = with_scan;
|
|
m_settingUiCallback = callback;
|
|
#ifdef HG_CMP_MSC
|
|
m_SettingUiThreadId = 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;
|
|
#ifdef HG_CMP_MSC
|
|
m_ProgressUiThreadId = GetCurrentThreadId();
|
|
#endif
|
|
emit createProgressUi(qt);
|
|
|
|
#ifdef HG_CMP_MSC
|
|
if (!qt)
|
|
{
|
|
MSG msg;
|
|
while (GetMessage(&msg, NULL, 0, 0))
|
|
{
|
|
TranslateMessage(&msg);
|
|
DispatchMessage(&msg);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
return 0;
|
|
}
|
|
|
|
int Manager::showMessageBoxUi(bool qt, HWND parent, int event, void *msg, int flag)
|
|
{
|
|
m_messageBoxUiParent = nullptr;
|
|
m_notifyEvent = event;
|
|
m_message = (char*)msg;
|
|
m_flag = flag;
|
|
#ifdef HG_CMP_MSC
|
|
m_MessageBoxUiThreadId = GetCurrentThreadId();
|
|
#endif
|
|
emit createMessageBoxUi(qt);
|
|
|
|
#ifdef HG_CMP_MSC
|
|
if (!qt)
|
|
{
|
|
MSG msg;
|
|
while (GetMessage(&msg, NULL, 0, 0))
|
|
{
|
|
TranslateMessage(&msg);
|
|
DispatchMessage(&msg);
|
|
}
|
|
}
|
|
#endif
|
|
|
|
return 0;
|
|
}
|
|
|
|
int Manager::showTwainSrcUi(bool qt, 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)
|
|
{
|
|
m_vds.push_back(vds[i]);
|
|
}
|
|
m_defDsName = defDevName;
|
|
memset(&m_ds, 0, sizeof(TW_IDENTITY));
|
|
|
|
emit createTwainSrcUi(qt);
|
|
#ifdef HG_CMP_MSC
|
|
if (!qt)
|
|
{
|
|
MSG msg;
|
|
while (GetMessage(&msg, NULL, 0, 0))
|
|
{
|
|
TranslateMessage(&msg);
|
|
DispatchMessage(&msg);
|
|
}
|
|
}
|
|
#endif
|
|
memcpy(ds, &m_ds, sizeof(TW_IDENTITY));
|
|
return 0;
|
|
}
|
|
|
|
void Manager::closeSettingUi()
|
|
{
|
|
emit deleteSettingUi();
|
|
}
|
|
|
|
void Manager::closeProgressUi()
|
|
{
|
|
emit deleteProgressUi();
|
|
}
|
|
|
|
void Manager::closeMessageBoxUi()
|
|
{
|
|
emit deleteMessageBoxUi();
|
|
}
|
|
|
|
void Manager::clear_functions(void)
|
|
{
|
|
m_settingUiCallback = std::function<void(ui_result)>();
|
|
m_progressUiCallback = std::function<void(ui_result)>();
|
|
m_notify = nullptr;
|
|
if (m_progressUi)
|
|
m_progressUi->clear_callback();
|
|
if (m_settingUi)
|
|
m_settingUi->clear_callback();
|
|
}
|
|
|
|
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);
|
|
}
|
|
|
|
void Manager::on_createDeviceSelect(bool qt)
|
|
{
|
|
Dialog_device_select *dlg = new Dialog_device_select(m_DeviceSelectDevs);
|
|
dlg->exec();
|
|
m_DeviceSelectResult = dlg->getDevId();
|
|
#ifdef HG_CMP_MSC
|
|
if (!qt)
|
|
{
|
|
::PostThreadMessage(m_DeviceSelectThreadId, WM_QUIT, 0, 0);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void Manager::on_createSettingUi(bool qt)
|
|
{
|
|
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
|
|
|
|
auto close_prog = [this](ui_result r) ->void
|
|
{
|
|
if(r != UI_RESULT_START_SCAN)
|
|
m_settingUi = nullptr;
|
|
m_settingUiCallback(r);
|
|
};
|
|
|
|
if (m_settingUi == nullptr)
|
|
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();
|
|
}
|
|
|
|
void Manager::on_createProgressUi(bool qt)
|
|
{
|
|
QWidget *qParent = nullptr;
|
|
#ifdef HG_CMP_MSC
|
|
if (nullptr != m_progressUiparent)
|
|
{
|
|
QWinWidget *win = new QWinWidget(m_progressUiparent);
|
|
win->showCentered();
|
|
qParent = win;
|
|
}
|
|
|
|
#else
|
|
qParent = m_progressUiparent;
|
|
#endif
|
|
|
|
auto close_prog = [&](ui_result r) ->void
|
|
{
|
|
//m_progressUi = nullptr;
|
|
if(m_progressUiCallback)
|
|
m_progressUiCallback(r);
|
|
|
|
if(r == UI_RESULT_CLOSE_NORMAL)
|
|
m_progressUiCallback = std::function<void(ui_result)>();
|
|
};
|
|
if (m_progressUi == nullptr)
|
|
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)
|
|
{
|
|
::PostThreadMessage(m_ProgressUiThreadId, WM_QUIT, 0, 0);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void Manager::on_createMessageBoxUi(bool qt)
|
|
{
|
|
if (m_msgBoxUi != nullptr)
|
|
{
|
|
delete m_msgBoxUi;
|
|
m_msgBoxUi = nullptr;
|
|
}
|
|
|
|
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
|
|
|
|
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;
|
|
#ifdef HG_CMP_MSC
|
|
if (!qt)
|
|
{
|
|
::PostThreadMessage(m_MessageBoxUiThreadId, WM_QUIT, 0, 0);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void Manager::on_createTwainSrcUi(bool qt)
|
|
{
|
|
QWidget *qParent = nullptr;
|
|
#ifdef HG_CMP_MSC
|
|
QWinWidget win(m_TwainSrcUiparent);
|
|
if (nullptr != m_TwainSrcUiparent)
|
|
{
|
|
win.showCentered();
|
|
qParent = &win;
|
|
}
|
|
#else
|
|
qParent = m_TwainSrcUiparent;
|
|
#endif
|
|
|
|
Dialog_Twain_Source_Select *dlg = new Dialog_Twain_Source_Select (m_vds, m_defDsName, qParent);
|
|
if (dlg->exec())
|
|
{
|
|
dlg->GetIdentify(&m_ds);
|
|
}
|
|
#ifdef HG_CMP_MSC
|
|
if (!qt)
|
|
{
|
|
::PostThreadMessage(m_twainSrcUiThreadId, WM_QUIT, 0, 0);
|
|
}
|
|
#endif
|
|
}
|
|
|
|
void Manager::on_deleteSettingUi()
|
|
{
|
|
if (m_settingUi != nullptr)
|
|
{
|
|
m_settingUi->clear_callback();
|
|
delete m_settingUi;
|
|
m_settingUi = nullptr;
|
|
}
|
|
}
|
|
|
|
void Manager::on_deleteProgressUi()
|
|
{
|
|
if (m_progressUi != nullptr)
|
|
{
|
|
m_progressUi->clear_callback();
|
|
delete m_progressUi;
|
|
m_progressUi = nullptr;
|
|
}
|
|
}
|
|
|
|
void Manager::on_deleteMessageBoxUi()
|
|
{
|
|
if (m_msgBoxUi != nullptr)
|
|
{
|
|
delete m_msgBoxUi;
|
|
m_msgBoxUi = nullptr;
|
|
}
|
|
}
|