From 7e8ec0b0bf4438ba1239b3f37bac382725208d8a Mon Sep 17 00:00:00 2001 From: luoliangyi <87842688@@qq.com> Date: Tue, 4 Jul 2023 13:37:46 +0800 Subject: [PATCH] =?UTF-8?q?=E8=A7=A3=E5=86=B3twainui=E5=9C=A8linux?= =?UTF-8?q?=E4=B8=8A=E7=9A=84=E7=BC=96=E8=AF=91=E9=97=AE=E9=A2=98?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- build2/qt/HGSolutionLinux.pro | 4 ++ build2/qt/HGTwainUI/HGTwainUI.pro | 71 ++++++++++++++++++++ modules/twainui/Manager.cpp | 45 +++++++++---- modules/twainui/Manager.h | 16 ++++- modules/twainui/app_cfg.cpp | 3 +- modules/twainui/dialog_twain_source_select.h | 1 + modules/twainui/dllmain.cpp | 44 ++---------- modules/twainui/hg_settingdialog.cpp | 12 ++-- modules/twainui/twainui.cpp | 28 ++++---- 9 files changed, 149 insertions(+), 75 deletions(-) diff --git a/build2/qt/HGSolutionLinux.pro b/build2/qt/HGSolutionLinux.pro index 36575f57..7ce1ffef 100644 --- a/build2/qt/HGSolutionLinux.pro +++ b/build2/qt/HGSolutionLinux.pro @@ -6,6 +6,7 @@ SUBDIRS += \ HGImgProc \ HGSaneUI \ HGSaneUser \ + HGTwainUI \ HGVersion \ HGScannerLib \ HGUpload \ @@ -31,6 +32,9 @@ HGSaneUser.depends = \ HGBase \ HGSaneUI +HGTwainUI.depends = \ + HGBase + HGVersion.depends = \ HGBase diff --git a/build2/qt/HGTwainUI/HGTwainUI.pro b/build2/qt/HGTwainUI/HGTwainUI.pro index aa7a667c..3d447b7b 100644 --- a/build2/qt/HGTwainUI/HGTwainUI.pro +++ b/build2/qt/HGTwainUI/HGTwainUI.pro @@ -120,6 +120,64 @@ win32 { unix { + SOURCES += ../../../modules/twainui/twainui.cpp + SOURCES += ../../../modules/twainui/hg_settingdialog.cpp + HEADERS += ../../../modules/twainui/hg_settingdialog.h + + SOURCES += \ + ../../../modules/twainui/app_cfg.cpp \ + ../../../modules/twainui/HGUIGlobal.cpp \ + ../../../modules/twainui/Manager.cpp \ + ../../../modules/twainui/cfg/cJSON.c \ + ../../../modules/twainui/cfg/gb_json.cpp \ + ../../../modules/twainui/cutdialog.cpp \ + ../../../modules/twainui/cutpapertool.cpp \ + ../../../modules/twainui/device_menu.cpp \ + ../../../modules/twainui/dialog_input.cpp \ + ../../../modules/twainui/dllmain.cpp \ + ../../../modules/twainui/gaosixy.cpp \ + ../../../modules/twainui/setpicclrtool.cpp \ + ../../../utility/HGString.cpp \ + ../../../modules/twainui/widget.cpp \ + ../../../modules/twainui/dialog_progress_ui.cpp \ + ../../../modules/twainui/dialog_device_select.cpp \ + ../../../modules/twainui/dialog_twain_source_select.cpp + HEADERS += \ + ../../../modules/twainui/app_cfg.h \ + ../../../modules/twainui/HGUIGlobal.h \ + ../../../modules/twainui/Manager.h \ + ../../../modules/twainui/cfg/cJSON.h \ + ../../../modules/twainui/cfg/gb_json.h \ + ../../../modules/twainui/cutdialog.h \ + ../../../modules/twainui/cutpapertool.h \ + ../../../modules/twainui/device_menu.h \ + ../../../modules/twainui/dialog_input.h \ + ../../../modules/twainui/gaosixy.h \ + ../../../modules/twainui/setpicclrtool.h \ + ../../../utility/HGString.h \ + ../../../modules/twainui/widget.h \ + ../../../modules/twainui/dialog_progress_ui.h \ + ../../../modules/twainui/dialog_device_select.h \ + ../../../modules/twainui/dialog_twain_source_select.h + + FORMS += \ + ../../../modules/twainui/cutdialog.ui \ + ../../../modules/twainui/cutpapertool.ui \ + ../../../modules/twainui/dialog_input.ui \ + ../../../modules/twainui/setpicclrtool.ui \ + ../../../modules/twainui/widget.ui \ + ../../../modules/twainui/dialog_progress_ui.ui \ + ../../../modules/twainui/dialog_device_select.ui \ + ../../../modules/twainui/dialog_twain_source_select.ui + + RESOURCES += \ + ../../../modules/twainui/TwainUI_resource.qrc + + TRANSLATIONS += \ + ../../../modules/twainui/TwainUI_zh_CN.ts \ + ../../../modules/twainui/TwainUI_zh_EN.ts \ + ../../../modules/twainui/qt_zh_CN.ts + DISTRIBUTION = $$system(cat /etc/issue | cut -d\' \' -f1) contains(DISTRIBUTION, UnionTech) { MY_OS = uos @@ -205,3 +263,16 @@ win32 { && xcopy /y $$SRCPDB_FILE $$DESTDLL_PATH } } + +unix { + + CONFIG(release, debug|release) { + DESTDLL_PATH = $$PWD/../../../../release/$${MY_OS}/$${MY_ARCH2}/ + message(DESTDLL_PATH: $$DESTDLL_PATH) + + SRCDLL_FILE = $${DESTDIR}/lib$${TARGET}.so + message(SRCDLL_FILE: $$SRCDLL_FILE) + + QMAKE_POST_LINK += cp $$SRCDLL_FILE $$DESTDLL_PATH + } +} diff --git a/modules/twainui/Manager.cpp b/modules/twainui/Manager.cpp index 0691991b..2991fdc2 100644 --- a/modules/twainui/Manager.cpp +++ b/modules/twainui/Manager.cpp @@ -1,6 +1,8 @@ #include "Manager.h" #include +#ifdef HG_CMP_MSC #include +#endif #include "lang/app_language.h" extern Manager* g_manager; @@ -44,9 +46,12 @@ Manager::~Manager() int Manager::showDeviceSelect(bool qt, const std::vector& devs) { m_DeviceSelectDevs = devs; +#ifdef HG_CMP_MSC m_DeviceSelectThreadId = GetCurrentThreadId(); +#endif emit createDeviceSelect(qt); +#ifdef HG_CMP_MSC if (!qt) { MSG msg; @@ -56,6 +61,7 @@ int Manager::showDeviceSelect(bool qt, const std::vector& devs) DispatchMessage(&msg); } } +#endif return m_DeviceSelectResult; } @@ -63,14 +69,14 @@ int Manager::showDeviceSelect(bool qt, const std::vector& devs) 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; + 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; @@ -78,15 +84,17 @@ int Manager::showSettingUi(bool qt, SANE_Handle device, HWND parent, LPSANEAPI a int Manager::showProgressUi(bool qt, HWND parent, std::function callback, std::function *notify) { - m_progressUiparent = parent; + m_progressUiparent = (HGWindow)parent; if (nullptr != m_settingUi) - m_progressUiparent = (HWND)m_settingUi->winId(); + 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; @@ -96,6 +104,7 @@ int Manager::showProgressUi(bool qt, HWND parent, std::functionexec(); m_DeviceSelectResult = dlg->getDevId(); - +#ifdef HG_CMP_MSC if (!qt) { ::PostThreadMessage(m_DeviceSelectThreadId, WM_QUIT, 0, 0); } +#endif } void Manager::on_createSettingUi(bool qt) @@ -269,11 +283,12 @@ 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) { ::PostThreadMessage(m_ProgressUiThreadId, WM_QUIT, 0, 0); } +#endif } void Manager::on_createMessageBoxUi(bool qt) @@ -303,11 +318,12 @@ void Manager::on_createMessageBoxUi(bool qt) 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) @@ -329,11 +345,12 @@ void Manager::on_createTwainSrcUi(bool qt) { dlg->GetIdentify(&m_ds); } - +#ifdef HG_CMP_MSC if (!qt) { ::PostThreadMessage(m_twainSrcUiThreadId, WM_QUIT, 0, 0); } +#endif } void Manager::on_deleteSettingUi() diff --git a/modules/twainui/Manager.h b/modules/twainui/Manager.h index 52a89cf4..dde1b4cf 100644 --- a/modules/twainui/Manager.h +++ b/modules/twainui/Manager.h @@ -64,32 +64,42 @@ public: HGEvent m_event; std::vector 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; - HWND m_settingUiParent; + HGWindow m_settingUiParent; SANEAPI m_api; std::string m_devName; bool m_with_scan; std::function m_settingUiCallback; Dialog_progress_ui *m_progressUi; - HWND m_progressUiparent; + HGWindow m_progressUiparent; +#ifdef HG_CMP_MSC unsigned long m_ProgressUiThreadId; +#endif std::function m_progressUiCallback; std::function *m_notify; QMessageBox *m_msgBoxUi; +#ifdef HG_CMP_MSC unsigned long m_MessageBoxUiThreadId; - HWND m_messageBoxUiParent; +#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 m_vds; std::string m_defDsName; HGWindow m_TwainSrcUiparent; diff --git a/modules/twainui/app_cfg.cpp b/modules/twainui/app_cfg.cpp index 6e97a280..2da298ac 100644 --- a/modules/twainui/app_cfg.cpp +++ b/modules/twainui/app_cfg.cpp @@ -4,8 +4,9 @@ #include "base/HGIni.h" #include "HGUIGlobal.h" #include "HGString.h" - +#ifdef HG_CMP_MSC #include +#endif bool removeSection(const HGChar* appName) { diff --git a/modules/twainui/dialog_twain_source_select.h b/modules/twainui/dialog_twain_source_select.h index c1e24bc7..b839bce0 100644 --- a/modules/twainui/dialog_twain_source_select.h +++ b/modules/twainui/dialog_twain_source_select.h @@ -3,6 +3,7 @@ #include "base/HGDef.h" #include "base/HGInc.h" +#include "sane/sane_ex.h" #include "twain/twain.h" #include #include diff --git a/modules/twainui/dllmain.cpp b/modules/twainui/dllmain.cpp index c30d5677..71b8f14e 100644 --- a/modules/twainui/dllmain.cpp +++ b/modules/twainui/dllmain.cpp @@ -8,60 +8,24 @@ #include "lang/app_language.h" #include "Manager.h" +HGEvent g_event = NULL; +HGThread g_hThread = NULL; +Manager* g_manager = NULL; + #if defined (HG_CMP_MSC) #include "qmfcapp.hpp" #include "qwinwidget.hpp" HINSTANCE g_hInst = NULL; -HGEvent g_event = NULL; -Manager* g_manager = NULL; -HGThread g_hThread = NULL; BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpvReserved*/) { if (dwReason == DLL_PROCESS_ATTACH) { g_hInst = hInstance; -#if 0 - HGChar moduleName[512]; - HGBase_GetModuleName(DllMain, moduleName, 512); - HGChar modulePath[512]; - HGBase_GetFilePath(moduleName, modulePath, 512); - - char *env = getenv("QT_QPA_PLATFORM_PLUGIN_PATH"); - if (NULL == env) - { - char newEnv[256]; - sprintf(newEnv, "QT_QPA_PLATFORM_PLUGIN_PATH=%s", modulePath); - putenv(newEnv); - } - else if (NULL == strstr(env, modulePath)) - { - char *newEnv = new char [strlen(env) + 256]; - sprintf(newEnv, "QT_QPA_PLATFORM_PLUGIN_PATH=%s;%s", env, modulePath); - putenv(newEnv); - delete []newEnv; - } -#endif } else if (dwReason == DLL_PROCESS_DETACH) { -#if 0 - if (NULL != g_manager) - { - g_manager->deleteLater(); - g_manager = nullptr; - } - - if (NULL != g_hThread) - { - QApplication::exit(); - HGBase_CloseThread(g_hThread); - g_hThread = NULL; - HGBase_DestroyEvent(g_event); - g_event = NULL; - } -#endif g_hInst = NULL; } diff --git a/modules/twainui/hg_settingdialog.cpp b/modules/twainui/hg_settingdialog.cpp index 6f364c5c..ddbda474 100644 --- a/modules/twainui/hg_settingdialog.cpp +++ b/modules/twainui/hg_settingdialog.cpp @@ -2,7 +2,9 @@ #include "hg_settingdialog.h" #include #include +#ifdef HG_CMP_MSC #include +#endif #include "cutpapertool.h" #include "setpicclrtool.h" #include "base/HGDef.h" @@ -159,19 +161,19 @@ void hg_settingdialog::initUi() setWindowTitle(QString::fromStdString(dev_que_.opened_scanner_name())); #endif + Qt::WindowFlags type = Qt::Dialog | Qt::WindowCloseButtonHint; +#ifdef HG_CMP_MSC OSVERSIONINFOW info; info.dwOSVersionInfoSize = sizeof(OSVERSIONINFOW); if (GetVersionExW(&info)) { if (info.dwMajorVersion == 6 && info.dwMinorVersion == 1) { - setWindowFlags(Qt::SubWindow | Qt::Popup | Qt::WindowStaysOnTopHint); - } - else - { - setWindowFlags(Qt::Dialog | Qt::WindowCloseButtonHint); + type = Qt::SubWindow | Qt::Popup | Qt::WindowStaysOnTopHint; } } +#endif + setWindowFlags(type); resize(740, height()); } diff --git a/modules/twainui/twainui.cpp b/modules/twainui/twainui.cpp index 0e1eefe0..33563168 100644 --- a/modules/twainui/twainui.cpp +++ b/modules/twainui/twainui.cpp @@ -13,11 +13,13 @@ #ifdef HG_CMP_MSC #include "qwinwidget.hpp" extern HINSTANCE g_hInst; -extern HGEvent g_event; -extern Manager *g_manager; -extern HGThread g_hThread; #endif +extern HGEvent g_event; +extern HGThread g_hThread; +extern Manager *g_manager; + +#ifdef HG_CMP_MSC static void HGAPI ThreadFunc(HGThread thread, HGPointer param) { bool ownApplication = false; @@ -32,15 +34,18 @@ static void HGAPI ThreadFunc(HGThread thread, HGPointer param) delete qApp; } } +#endif int choose_scanner(const std::vector &devs) { +#ifdef HG_CMP_MSC if (!qApp) { HGBase_CreateEvent(HGTRUE, HGFALSE, &g_event); HGBase_OpenThread(ThreadFunc, NULL, &g_hThread); HGBase_WaitEvent(g_event); } +#endif if (NULL == g_manager) { @@ -112,12 +117,14 @@ 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 callback) { +#ifdef HG_CMP_MSC if (!qApp) { HGBase_CreateEvent(HGTRUE, HGFALSE, &g_event); HGBase_OpenThread(ThreadFunc, NULL, &g_hThread); HGBase_WaitEvent(g_event); } +#endif if (NULL == g_manager) { @@ -129,12 +136,14 @@ int show_setting_ui(SANE_Handle device, HWND parent, LPSANEAPI api, const char * int show_progress_ui(HWND parent, std::function callback, std::function *notify) { +#ifdef HG_CMP_MSC if (!qApp) { HGBase_CreateEvent(HGTRUE, HGFALSE, &g_event); HGBase_OpenThread(ThreadFunc, NULL, &g_hThread); HGBase_WaitEvent(g_event); } +#endif if (NULL == g_manager) { @@ -146,12 +155,14 @@ int show_progress_ui(HWND parent, std::function callback, std: int show_messagebox_ui(HWND parent, int event, void *msg, int flag) { +#ifdef HG_CMP_MSC if (!qApp) { HGBase_CreateEvent(HGTRUE, HGFALSE, &g_event); HGBase_OpenThread(ThreadFunc, NULL, &g_hThread); HGBase_WaitEvent(g_event); } +#endif if (NULL == g_manager) { @@ -163,12 +174,14 @@ int show_messagebox_ui(HWND parent, int event, void *msg, int flag) int show_twain_srclist_ui(const TW_IDENTITY *vds, HGUInt count, const HGChar *defDsName, HGWindow parent, TW_IDENTITY *ds) { +#ifdef HG_CMP_MSC if (!qApp) { HGBase_CreateEvent(HGTRUE, HGFALSE, &g_event); HGBase_OpenThread(ThreadFunc, NULL, &g_hThread); HGBase_WaitEvent(g_event); } +#endif if (NULL == g_manager) { @@ -201,15 +214,6 @@ int close_ui(int which) if (which == UI_UNLOAD_MODULE) { g_manager->clear_functions(); - //g_manager->closeManager(); - - //if (NULL != g_hThread) - //{ - // HGBase_CloseThread(g_hThread); - // g_hThread = NULL; - // HGBase_DestroyEvent(g_event); - // g_event = NULL; - //} } return 0;