调整第二次扫描崩溃

This commit is contained in:
yangjiaxuan 2023-05-24 14:40:06 +08:00
parent 722680abb2
commit d686ef3122
9 changed files with 208 additions and 76 deletions

View File

@ -9,3 +9,4 @@ show_setting_ui
show_progress_ui
show_messagebox_ui
show_twain_srclist_ui
close_ui

View File

@ -3,6 +3,8 @@
#include <qwinwidget.hpp>
#include "lang/app_language.h"
extern Manager* g_manager;
Manager::Manager()
: QObject(nullptr)
, m_progressUiCallback(std::function<void(ui_result)>())
@ -23,6 +25,13 @@ Manager::Manager()
connect(this, SIGNAL(createMessageBoxUi(bool)), this, SLOT(on_createMessageBoxUi(bool)));
connect(this, SIGNAL(createTwainSrcUi(bool)), this, SLOT(on_createTwainSrcUi(bool)));
connect(this, SIGNAL(deleteDeviceSelectUi()), this, SLOT(on_deleteDeviceSelectUi()));
connect(this, SIGNAL(deleteSettingUi()), this, SLOT(on_deleteSettingUi()));
connect(this, SIGNAL(deleteProgressUi()), this, SLOT(on_deleteProgressUi()));
connect(this, SIGNAL(deleteMessageBoxUi()), this, SLOT(on_deleteMessageBoxUi()));
connect(this, SIGNAL(deleteTwainSrcUi()), this, SLOT(on_deleteTwainSrcUi()));
connect(this, SIGNAL(deleteManager()), this, SLOT(on_deleteManager()));
emit init();
}
@ -35,51 +44,6 @@ Manager::~Manager()
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<DEVQUEUI>& devs)
{
m_DeviceSelectDevs = devs;
@ -184,6 +148,47 @@ int Manager::showTwainSrcUi(bool qt, DSMENTRYPROC dsmProc, const TW_IDENTITY *ap
return 0;
}
void Manager::closeDeviceSelectUi()
{
emit deleteDeviceSelectUi();
}
void Manager::closeSettingUi()
{
emit deleteSettingUi();
}
void Manager::closeProgressUi()
{
emit deleteProgressUi();
}
void Manager::closeMessageBoxUi()
{
emit deleteMessageBoxUi();
}
void Manager::closeTwainSrcUi()
{
emit deleteTwainSrcUi();
}
void Manager::closeManager()
{
emit deleteManager();
}
void Manager::clear_functions(void)
{
m_settingUiCallback = std::function<void(ui_result)>();
m_progressUiCallback = std::function<void(ui_result)>();
m_notify = nullptr;
if (this->m_progressUi)
m_progressUi->clear_callback();
if (m_settingUi)
m_settingUi->clear_callback();
}
void Manager::on_init()
{
m_langCode = lang_get_cur_code_page();
@ -204,7 +209,7 @@ void Manager::on_init()
void Manager::on_createDeviceSelect(bool qt)
{
if (m_deviceSelectUi != nullptr)
if (m_deviceSelectUi == nullptr)
m_deviceSelectUi = new Dialog_device_select(m_DeviceSelectDevs);
m_deviceSelectUi->exec();
m_DeviceSelectResult = m_deviceSelectUi->getDevId();
@ -229,8 +234,15 @@ void Manager::on_createSettingUi(bool qt)
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);
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(m_device, &m_api, m_with_scan, m_devName.c_str(), close_prog, qParent);
m_settingUi->setModal(true);
m_settingUi->show();
}
@ -250,8 +262,15 @@ void Manager::on_createProgressUi(bool qt)
qParent = m_progressUiparent;
#endif
if (m_progressUi != nullptr)
m_progressUi = new Dialog_progress_ui(m_progressUiCallback, m_notify, qParent);
auto close_prog = [&](ui_result r) ->void
{
m_progressUi = nullptr;
if(m_progressUiCallback)
m_progressUiCallback(r);
m_progressUiCallback = std::function<void(ui_result)>();
};
if (m_progressUi == nullptr)
m_progressUi = new Dialog_progress_ui(close_prog, m_notify, qParent);
m_progressUi->setModal(true);
m_progressUi->show();
@ -275,7 +294,7 @@ void Manager::on_createMessageBoxUi(bool qt)
qParent = m_messageBoxUiParent;
#endif
if (m_msgBoxUi != nullptr)
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);
@ -296,7 +315,7 @@ void Manager::on_createTwainSrcUi(bool qt)
qParent = m_TwainSrcUiparent;
#endif
if (m_twainSrcUi != nullptr)
if (m_twainSrcUi == nullptr)
m_twainSrcUi = new Dialog_Twain_Source_Select (m_dsmProc, &m_appId, qParent);
if (m_twainSrcUi->exec())
{
@ -308,3 +327,60 @@ void Manager::on_createTwainSrcUi(bool qt)
::PostThreadMessage(m_twainSrcUiThreadId, WM_QUIT, 0, 0);
}
}
void Manager::on_deleteDeviceSelectUi()
{
if (m_deviceSelectUi != nullptr)
{
delete m_deviceSelectUi;
m_deviceSelectUi = nullptr;
}
}
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;
}
}
void Manager::on_deleteTwainSrcUi()
{
if (m_twainSrcUi != nullptr)
{
delete m_twainSrcUi;
m_twainSrcUi = nullptr;
}
}
void Manager::on_deleteManager()
{
if (NULL != g_manager)
{
delete g_manager;
g_manager = nullptr;
}
QApplication::exit();
}

View File

@ -15,18 +15,21 @@ public:
Manager();
~Manager();
void closeDeviceSelectUi();
void closeSettingUi();
void closeProgressUi();
void closeMessageBoxUi();
void closeTwainSrcUi();
int showDeviceSelect(bool qt, const std::vector<DEVQUEUI>& devs);
int showSettingUi(bool qt, SANE_Handle device, HWND settingUiParent, LPSANEAPI api, const char *devName, bool with_scan, std::function<void(ui_result)> callback);
int showProgressUi(bool qt, HWND parent, std::function<void (ui_result)> callback, std::function<void (int, void *, int)> *notify);
int showMessageBoxUi(bool qt, HWND parent, int event, void *msg, int flag);
int showTwainSrcUi(bool qt, DSMENTRYPROC dsmProc, const TW_IDENTITY *appId, HGWindow parent, TW_IDENTITY *ds);
void closeDeviceSelectUi();
void closeSettingUi();
void closeProgressUi();
void closeMessageBoxUi();
void closeTwainSrcUi();
void closeManager();
void clear_functions(void);
signals:
void init();
void createDeviceSelect(bool qt);
@ -35,6 +38,13 @@ signals:
void createMessageBoxUi(bool qt);
void createTwainSrcUi(bool qt);
void deleteDeviceSelectUi();
void deleteSettingUi();
void deleteProgressUi();
void deleteMessageBoxUi();
void deleteTwainSrcUi();
void deleteManager();
private slots:
void on_init();
void on_createDeviceSelect(bool qt);
@ -43,6 +53,13 @@ private slots:
void on_createMessageBoxUi(bool qt);
void on_createTwainSrcUi(bool qt);
void on_deleteDeviceSelectUi();
void on_deleteSettingUi();
void on_deleteProgressUi();
void on_deleteMessageBoxUi();
void on_deleteTwainSrcUi();
void on_deleteManager();
private:
QTranslator m_translator;
QTranslator m_translator_qt;

View File

@ -30,7 +30,7 @@ Dialog_progress_ui::Dialog_progress_ui(std::function<void (ui_result)> callback,
m_timer = new QTimer(this);
connect(this, SIGNAL(scan_status(QString,bool)), this, SLOT(on_scan_status(QString,bool)), Qt::QueuedConnection);
connect(this, SIGNAL(scan_finish(int)), this, SLOT(on_scan_finish(int)), Qt::QueuedConnection);
connect(this, SIGNAL(scan_finish(int, QString)), this, SLOT(on_scan_finish(int, QString)), Qt::QueuedConnection);
}
Dialog_progress_ui::~Dialog_progress_ui()
@ -46,20 +46,24 @@ void Dialog_progress_ui::closeEvent(QCloseEvent *e)
{
if (e->spontaneous())
{
if(!quit_)
m_callback(UI_RESULT_CLOSE_CANCEL);
}
e->ignore();
}
}
void Dialog_progress_ui::on_pbtn_cancelScan_clicked()
{
if (!quit_)
m_callback(UI_RESULT_CLOSE_CANCEL);
}
void notify_close(std::function<void (ui_result)> callback)
{
std::this_thread::sleep_for(std::chrono::milliseconds(500));
if (callback)
callback(UI_RESULT_CLOSE_NORMAL);
}
@ -67,8 +71,11 @@ void Dialog_progress_ui::on_pbtn_close_clicked()
{
disconnect(m_timer, SIGNAL(timeout()), this, SLOT(on_pbtn_close_clicked()));
//CloseHandle(CreateThread(NULL, 0, notify_close, (void*)m_callback, 0, 0));
if (!quit_)
{
std::thread th_close(notify_close, m_callback);
th_close.detach();
}
// m_callback(UI_RESULT_CLOSE_NORMAL);
close();
}
@ -81,8 +88,9 @@ void Dialog_progress_ui::on_scan_status(QString finishInfo, bool isScanning)
ui->pbtn_close->setVisible(!isScanning);
}
void Dialog_progress_ui::on_scan_finish(int flag)
void Dialog_progress_ui::on_scan_finish(int flag, QString finishInfo)
{
on_scan_status(finishInfo, false);
if (SCANNER_ERR_OK == flag || SCANNER_ERR_USER_CANCELED == flag)
{
m_timer->start(2000);
@ -109,9 +117,9 @@ void Dialog_progress_ui::FuncNotify(int event, void *msg, int flag)
case SANE_EVENT_SCAN_FINISHED:
{
emit p->scan_finish(flag);
QString finishInfo((char*)msg);
emit p->scan_status(finishInfo, false);
emit p->scan_finish(flag, finishInfo);
// emit p->scan_status(finishInfo, false);
}
break;
}

View File

@ -13,6 +13,7 @@ class Dialog_progress_ui : public QDialog
{
Q_OBJECT
bool quit_ = false;
public:
explicit Dialog_progress_ui(std::function<void (ui_result)> callback, std::function<void (int, void *, int)> *notify, QWidget *parent = nullptr);
~Dialog_progress_ui();
@ -22,7 +23,7 @@ private:
signals:
void scan_status(QString finishInfo, bool isScanning);
void scan_finish(int flag);
void scan_finish(int flag, QString finishInfo);
protected:
void closeEvent(QCloseEvent *e) override;
@ -32,10 +33,15 @@ private slots:
void on_pbtn_close_clicked();
void on_scan_status(QString finishInfo, bool isScanning);
void on_scan_finish(int flag);
void on_scan_finish(int flag, QString finishInfo);
public:
static void FuncNotify(int event, void *msg, int flag);
void clear_callback(void)
{
quit_ = true;
m_callback = std::function<void(ui_result)>();
}
private:
Ui::Dialog_progress_ui *ui;

View File

@ -45,9 +45,11 @@ BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpvReserved*/)
}
else if (dwReason == DLL_PROCESS_DETACH)
{
#if 0
if (NULL != g_manager)
{
g_manager->deleteLater();
g_manager = nullptr;
}
if (NULL != g_hThread)
@ -58,7 +60,7 @@ BOOL WINAPI DllMain(HINSTANCE hInstance, DWORD dwReason, LPVOID /*lpvReserved*/)
HGBase_DestroyEvent(g_event);
g_event = NULL;
}
#endif
g_hInst = NULL;
}

View File

@ -121,6 +121,7 @@ hg_settingdialog::~hg_settingdialog()
cur_cfg_->release();
hg_setting_ui_ = NULL;
if(!quit_)
m_callback(UI_RESULT_CLOSE_SETTING);
}
@ -1550,6 +1551,7 @@ void hg_settingdialog::slot_buttonScanClicked()
{
save_scheme();
m_closeButton = closeButtonScan;
if (!quit_)
m_callback(UI_RESULT_START_SCAN);
}

View File

@ -15,6 +15,7 @@ class hg_settingdialog : public QDialog
int changed_count_;
bool save_;
bool clicked_gamma_;
bool quit_ = false;
dev_que dev_que_;
gb::scanner_cfg *cur_cfg_;
gb::sane_config_schm *cur_scheme_;
@ -61,6 +62,11 @@ public:
int get_changed_items(void);
int getCloseButtonCliked();
gb::sane_config_schm *getCurScheme();
void clear_callback(void)
{
quit_ = true;
m_callback = std::function<void(ui_result)>();
}
public:
enum closeButtonClicked

View File

@ -181,18 +181,32 @@ int close_ui(int which)
return 0;
}
if (UI_INDICATOR == which)
if (UI_INDICATOR & which)
{
g_manager->closeProgressUi();
}
else if (UI_SETTING == which)
if (UI_SETTING & which)
{
g_manager->closeSettingUi();
}
else if (UI_MSG_BOX == which)
if (UI_MSG_BOX & which)
{
g_manager->closeMessageBoxUi();
}
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;
}