解决twainui在linux上的编译问题

This commit is contained in:
luoliangyi 2023-07-04 13:37:46 +08:00
parent a74dd41b35
commit 7e8ec0b0bf
9 changed files with 149 additions and 75 deletions

View File

@ -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

View File

@ -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
}
}

View File

@ -1,6 +1,8 @@
#include "Manager.h"
#include <QApplication>
#ifdef HG_CMP_MSC
#include <qwinwidget.hpp>
#endif
#include "lang/app_language.h"
extern Manager* g_manager;
@ -44,9 +46,12 @@ Manager::~Manager()
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;
@ -56,6 +61,7 @@ int Manager::showDeviceSelect(bool qt, const std::vector<DEVQUEUI>& devs)
DispatchMessage(&msg);
}
}
#endif
return m_DeviceSelectResult;
}
@ -63,14 +69,14 @@ int Manager::showDeviceSelect(bool qt, const std::vector<DEVQUEUI>& devs)
int Manager::showSettingUi(bool qt, SANE_Handle device, HWND parent, LPSANEAPI api, const char *devName, bool with_scan, std::function<void (ui_result)> 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<void (ui_result)> callback, std::function<void (int, void *, int)> *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::function<void (ui_result)
DispatchMessage(&msg);
}
}
#endif
return 0;
}
@ -106,11 +115,12 @@ int Manager::showMessageBoxUi(bool qt, HWND parent, int event, void *msg, int fl
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;
@ -120,13 +130,16 @@ int Manager::showMessageBoxUi(bool qt, HWND parent, int event, void *msg, int fl
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();
@ -138,7 +151,7 @@ int Manager::showTwainSrcUi(bool qt, const TW_IDENTITY *vds, HGUInt count, const
memset(&m_ds, 0, sizeof(TW_IDENTITY));
emit createTwainSrcUi(qt);
#ifdef HG_CMP_MSC
if (!qt)
{
MSG msg;
@ -148,7 +161,7 @@ int Manager::showTwainSrcUi(bool qt, const TW_IDENTITY *vds, HGUInt count, const
DispatchMessage(&msg);
}
}
#endif
memcpy(ds, &m_ds, sizeof(TW_IDENTITY));
return 0;
}
@ -207,11 +220,12 @@ 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)
@ -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()

View File

@ -64,32 +64,42 @@ public:
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;
HWND m_settingUiParent;
HGWindow m_settingUiParent;
SANEAPI m_api;
std::string m_devName;
bool m_with_scan;
std::function<void(ui_result)> m_settingUiCallback;
Dialog_progress_ui *m_progressUi;
HWND m_progressUiparent;
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;
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<TW_IDENTITY> m_vds;
std::string m_defDsName;
HGWindow m_TwainSrcUiparent;

View File

@ -4,8 +4,9 @@
#include "base/HGIni.h"
#include "HGUIGlobal.h"
#include "HGString.h"
#ifdef HG_CMP_MSC
#include <shlobj.h>
#endif
bool removeSection(const HGChar* appName)
{

View File

@ -3,6 +3,7 @@
#include "base/HGDef.h"
#include "base/HGInc.h"
#include "sane/sane_ex.h"
#include "twain/twain.h"
#include <QDialog>
#include <QListWidgetItem>

View File

@ -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;
}

View File

@ -2,7 +2,9 @@
#include "hg_settingdialog.h"
#include <QDebug>
#include <QLatin1String>
#ifdef HG_CMP_MSC
#include <shlobj.h>
#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());
}

View File

@ -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<DEVQUEUI> &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<void(ui_result)> 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<void (ui_result)> callback, std::function<void (int, void *, int)> *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<void (ui_result)> 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;