#include "Manager.h" #include #include #include "lang/app_language.h" Manager::Manager() : QObject(nullptr) , m_progressUiCallback(std::function()) , m_notify(nullptr) , m_settingUiCallback(std::function()) , m_deviceSelectUi(nullptr) , m_settingUi(nullptr) , m_progressUi(nullptr) , m_msgBoxUi(nullptr) , m_twainSrcUi(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))); emit init(); } Manager::~Manager() { QCoreApplication::removeTranslator(&m_translator); if (20127 != m_langCode) QCoreApplication::removeTranslator(&m_translator_qt); HGBase_DestroyEvent(m_event); } void Manager::closeDeviceSelectUi() { if (m_deviceSelectUi != nullptr) { delete m_deviceSelectUi; m_deviceSelectUi = nullptr; } } void Manager::closeSettingUi() { if (m_settingUi != nullptr) { delete m_settingUi; m_settingUi = nullptr; } } void Manager::closeProgressUi() { if (m_progressUi != nullptr) { delete m_progressUi; m_progressUi = nullptr; } } void Manager::closeMessageBoxUi() { if (m_msgBoxUi != nullptr) { delete m_msgBoxUi; m_msgBoxUi = nullptr; } } void Manager::closeTwainSrcUi() { if (m_twainSrcUi != nullptr) { delete m_twainSrcUi; m_twainSrcUi = nullptr; } } int Manager::showDeviceSelect(bool qt, const std::vector& devs) { m_DeviceSelectDevs = devs; m_DeviceSelectThreadId = GetCurrentThreadId(); emit createDeviceSelect(qt); if (!qt) { MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } } return m_DeviceSelectResult; } int Manager::showSettingUi(bool qt, SANE_Handle device, HWND parent, LPSANEAPI api, const char *devName, bool with_scan, std::function callback) { m_device = device; m_settingUiParent = parent; memcpy(&m_api, api, sizeof(m_api)); m_devName = devName; m_with_scan = with_scan; m_settingUiCallback = callback; m_SettingUiThreadId = GetCurrentThreadId(); emit createSettingUi(qt); return 0; } int Manager::showProgressUi(bool qt, HWND parent, std::function callback, std::function *notify) { m_progressUiparent = parent; hg_settingdialog *settingDlg = hg_settingdialog::GetSettingDialog(); if (nullptr != settingDlg) m_progressUiparent = (HWND)settingDlg->winId(); m_progressUiCallback = callback; m_notify = notify; if (!qt) { m_ProgressUiThreadId = GetCurrentThreadId(); emit createProgressUi(qt); MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } } else { on_createProgressUi(qt); } 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; m_MessageBoxUiThreadId = GetCurrentThreadId(); emit createMessageBoxUi(qt); return 0; } int Manager::showTwainSrcUi(bool qt, DSMENTRYPROC dsmProc, const TW_IDENTITY *appId, HGWindow parent, TW_IDENTITY *ds) { m_twainSrcUiThreadId = GetCurrentThreadId(); m_TwainSrcUiparent = parent; m_dsmProc = dsmProc; memcpy(&m_appId, appId, sizeof(TW_IDENTITY)); memset(ds, 0, sizeof(TW_IDENTITY)); memset(&m_ds, 0, sizeof(TW_IDENTITY)); emit createTwainSrcUi(qt); if (!qt) { MSG msg; while (GetMessage(&msg, NULL, 0, 0)) { TranslateMessage(&msg); DispatchMessage(&msg); } } memcpy(ds, &m_ds, sizeof(TW_IDENTITY)); return 0; } 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) { if (m_deviceSelectUi != nullptr) m_deviceSelectUi = new Dialog_device_select(m_DeviceSelectDevs); m_deviceSelectUi->exec(); m_DeviceSelectResult = m_deviceSelectUi->getDevId(); if (!qt) { ::PostThreadMessage(m_DeviceSelectThreadId, WM_QUIT, 0, 0); } } 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 if (m_settingUi != nullptr) m_settingUi = new hg_settingdialog(m_device, &m_api, m_with_scan, m_devName.c_str(), m_settingUiCallback, 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 if (m_progressUi != nullptr) m_progressUi = new Dialog_progress_ui(m_progressUiCallback, m_notify, qParent); m_progressUi->setModal(true); m_progressUi->show(); if (!qt) { ::PostThreadMessage(m_ProgressUiThreadId, WM_QUIT, 0, 0); } } void Manager::on_createMessageBoxUi(bool qt) { 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 if (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->show(); } 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 if (m_twainSrcUi != nullptr) m_twainSrcUi = new Dialog_Twain_Source_Select (m_dsmProc, &m_appId, qParent); if (m_twainSrcUi->exec()) { m_twainSrcUi->GetIdentify(&m_ds); } if (!qt) { ::PostThreadMessage(m_twainSrcUiThreadId, WM_QUIT, 0, 0); } }