From e297b2cc9fb68bf25da2a48f6209ec4824dc5d08 Mon Sep 17 00:00:00 2001 From: luoliangyi <87842688@qq.com> Date: Mon, 20 Nov 2023 14:41:35 +0800 Subject: [PATCH] =?UTF-8?q?twainui=E5=A2=9E=E5=8A=A0=E8=B0=83=E8=AF=95?= =?UTF-8?q?=E6=97=A5=E5=BF=97?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scanner2/mainwindow.h | 53 +++++++++---------- modules/base/HGConsole.cpp | 8 +-- modules/base/HGLog.cpp | 5 +- modules/twainui/Manager.cpp | 102 +++++------------------------------- 4 files changed, 46 insertions(+), 122 deletions(-) diff --git a/app/scanner2/mainwindow.h b/app/scanner2/mainwindow.h index 686dff2a..aab30430 100644 --- a/app/scanner2/mainwindow.h +++ b/app/scanner2/mainwindow.h @@ -52,6 +52,26 @@ enum askIfClear notClearAndScan }; +typedef struct _save_opt +{ + QString path; + int index; + int jpegQuality; + int tiffCompressionBW; + int tiffCompression; + int tiffQuality; + bool isOcr; +}SAVEOPT; + +enum ScanType +{ + ScanType_None, + ScanType_ScanToCache, + ScanType_SingleScanToCache, + ScanType_ScanInto, + ScanType_InsertScanInto +}; + class MainWindow : public QMainWindow { Q_OBJECT @@ -63,6 +83,8 @@ public: void exitFullScreen(); static HGResult saveImage(HGImage image, const HGImgFmtSaveInfo* info, bool ocr, const HGChar *fileName); static QString getLogInfo(HGResult ret); + +private: static void HGAPI ocrThreadFunc(HGThread thread, HGPointer param); static void HGAPI ocrMsgPumpFunc(HGMsgPump msgPump, const HGMsg* msg, HGPointer param); @@ -280,41 +302,14 @@ private: bool auto_save_changes_; bool save_from_changed_; - typedef struct _save_opt - { - QString path; - int index; - int jpegQuality; - int tiffCompressionBW; - int tiffCompression; - int tiffQuality; - bool isOcr; - }SAVEOPT; - SAVEOPT auto_save_info_; - - union VIDPID - { - struct - { - unsigned short VID; - unsigned short PID; - }; - unsigned int Value; - }; + SAVEOPT auto_save_info_; QString m_currFilePath; int m_currIndex; int m_multiPageCount; int m_multiIndex; bool m_modify; // m_view上面的图像是否改变 - enum ScanType - { - ScanType_None, - ScanType_ScanToCache, - ScanType_SingleScanToCache, - ScanType_ScanInto, - ScanType_InsertScanInto - }; + ScanType m_scanType; // 1-扫描到缓存目录,2-单张扫描到缓存目录,3-扫描到指定目录,4-插入扫描到指定目录 int m_scanInsertPos; // 扫描插入位置,-1表示插入到最后 int m_scanCurIndex; diff --git a/modules/base/HGConsole.cpp b/modules/base/HGConsole.cpp index 48e5eadd..0c963dc0 100644 --- a/modules/base/HGConsole.cpp +++ b/modules/base/HGConsole.cpp @@ -69,10 +69,12 @@ HGResult HGAPI HGBase_WriteConsole(HGConsole console, const HGChar* info) #if defined(HG_CMP_MSC) DWORD dwNumberOfCharsWritten; WriteConsoleA(consoleImpl->m_hConsole, info, (DWORD)strlen(info), &dwNumberOfCharsWritten, NULL); - WriteConsoleA(consoleImpl->m_hConsole, "\r\n", (DWORD)strlen("\r\n"), &dwNumberOfCharsWritten, NULL); + if (info[strlen(info) - 1] != '\n') + WriteConsoleA(consoleImpl->m_hConsole, "\r\n", (DWORD)strlen("\r\n"), &dwNumberOfCharsWritten, NULL); #else printf(info); - printf("\n"); + if (info[strlen(info) - 1] != '\n') + printf("\n"); #endif return HGBASE_ERR_OK; -} \ No newline at end of file +} diff --git a/modules/base/HGLog.cpp b/modules/base/HGLog.cpp index 8825f986..c935ac2d 100644 --- a/modules/base/HGLog.cpp +++ b/modules/base/HGLog.cpp @@ -83,7 +83,8 @@ HGResult HGAPI HGBase_WriteLog(HGLog log, const HGChar* info) fseeko64(logImpl->m_file, 0, SEEK_END); #endif fwrite(info, 1, strlen(info), logImpl->m_file); - fwrite("\n", 1, strlen("\n"), logImpl->m_file); + if (info[strlen(info) - 1] != '\n') + fwrite("\n", 1, strlen("\n"), logImpl->m_file); fflush(logImpl->m_file); return HGBASE_ERR_OK; -} \ No newline at end of file +} diff --git a/modules/twainui/Manager.cpp b/modules/twainui/Manager.cpp index 182fa143..c3da90fb 100644 --- a/modules/twainui/Manager.cpp +++ b/modules/twainui/Manager.cpp @@ -6,6 +6,7 @@ #include "lang/app_language.h" #include #include +#include "base/HGInfo.h" Q_DECLARE_METATYPE(HGImage) @@ -86,24 +87,14 @@ int Manager::showSettingUi(SANE_Handle device, HWND parent, LPSANEAPI api, const unsigned int ThreadId = 0; #ifdef HG_CMP_MSC if (qApp->thread() != QThread::currentThread()) + { ThreadId = GetCurrentThreadId(); + HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "[Manager::showSettingUi] qApp->thread() != QThread::currentThread(), ThreadId=%u", ThreadId); + } #endif emit createSettingUi(ThreadId); -/* -#ifdef HG_CMP_MSC - if (0 != ThreadId) - { - MSG msg; - while (GetMessage(&msg, NULL, 0, 0)) - { - TranslateMessage(&msg); - DispatchMessage(&msg); - } - } -#endif -*/ - + HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "[Manager::showSettingUi] emit createSettingUi(ThreadId)"); return 0; } @@ -117,10 +108,14 @@ int Manager::showProgressUi(HWND parent, std::function callbac unsigned int ThreadId = 0; #ifdef HG_CMP_MSC if (qApp->thread() != QThread::currentThread()) + { ThreadId = GetCurrentThreadId(); + HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "[Manager::showProgressUi] qApp->thread() != QThread::currentThread(), ThreadId=%u", ThreadId); + } #endif emit createProgressUi(ThreadId); + HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "[Manager::showProgressUi] emit createProgressUi(ThreadId)"); #ifdef HG_CMP_MSC if (0 != ThreadId) @@ -134,6 +129,7 @@ int Manager::showProgressUi(HWND parent, std::function callbac } #endif + HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "[Manager::showProgressUi] Exit Message Loop"); return 0; } @@ -305,19 +301,6 @@ void Manager::closeSettingUi() #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() @@ -329,19 +312,6 @@ void Manager::closeProgressUi() #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() @@ -353,19 +323,6 @@ void Manager::closeMessageBoxUi() #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) @@ -438,14 +395,7 @@ void Manager::on_createSettingUi(unsigned int ThreadId) m_settingUi->setModal(true); m_settingUi->show(); -/* -#ifdef HG_CMP_MSC - if (0 != ThreadId) - { - ::PostThreadMessage(ThreadId, WM_QUIT, 0, 0); - } -#endif -*/ + HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "[Manager::on_createSettingUi] m_settingUi->show()"); } void Manager::on_createProgressUi(unsigned int ThreadId) @@ -480,11 +430,12 @@ void Manager::on_createProgressUi(unsigned int ThreadId) m_progressUi->setModal(true); m_progressUi->show(); - + HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "[Manager::on_createProgressUi] m_progressUi->show()"); #ifdef HG_CMP_MSC if (0 != ThreadId) { ::PostThreadMessage(ThreadId, WM_QUIT, 0, 0); + HGBase_WriteInfo(HGBASE_INFOTYPE_DESC, "[Manager::on_createProgressUi] PostThreadMessage(ThreadId, WM_QUIT, 0, 0)"); } #endif } @@ -595,15 +546,6 @@ void Manager::on_deleteSettingUi(unsigned int ThreadId) delete m_settingUi; m_settingUi = nullptr; } - -/* -#ifdef HG_CMP_MSC - if (0 != ThreadId) - { - ::PostThreadMessage(ThreadId, WM_QUIT, 0, 0); - } -#endif -*/ } void Manager::on_deleteProgressUi(unsigned int ThreadId) @@ -614,25 +556,9 @@ void Manager::on_deleteProgressUi(unsigned int ThreadId) delete m_progressUi; m_progressUi = nullptr; } - -/* -#ifdef HG_CMP_MSC - if (0 != ThreadId) - { - ::PostThreadMessage(ThreadId, WM_QUIT, 0, 0); - } -#endif -*/ } void Manager::on_deleteMessageBoxUi(unsigned int ThreadId) { -/* -#ifdef HG_CMP_MSC - if (0 != ThreadId) - { - ::PostThreadMessage(ThreadId, WM_QUIT, 0, 0); - } -#endif -*/ + }