From 7fdd6f12797cd8f837b136bd24a2e125a5afc3e0 Mon Sep 17 00:00:00 2001 From: yangjiaxuan <171295266@qq.com> Date: Thu, 7 Jul 2022 16:16:41 +0800 Subject: [PATCH] =?UTF-8?q?=E5=AE=9E=E7=8E=B0=E5=8F=AF=E4=BB=A5=E4=B8=8B?= =?UTF-8?q?=E8=BD=BD=E6=9C=8D=E5=8A=A1=E5=99=A8=E4=B8=8A=E7=9A=84app?= =?UTF-8?q?=E7=89=88=E6=9C=AC?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- app/scanner/dialog_updateprogress.cpp | 79 +++++++++++++++++++++ app/scanner/dialog_updateprogress.h | 42 +++++++++++ app/scanner/dialog_updateprogress.ui | 65 +++++++++++++++++ app/scanner/mainwindow.cpp | 46 ++++++++++++ app/scanner/mainwindow.h | 6 ++ app/scanner/mainwindow.ui | 8 ++- build-qt/HGSolution/HGScanner/HGScanner.pro | 9 ++- 7 files changed, 251 insertions(+), 4 deletions(-) create mode 100644 app/scanner/dialog_updateprogress.cpp create mode 100644 app/scanner/dialog_updateprogress.h create mode 100644 app/scanner/dialog_updateprogress.ui diff --git a/app/scanner/dialog_updateprogress.cpp b/app/scanner/dialog_updateprogress.cpp new file mode 100644 index 00000000..401efcb2 --- /dev/null +++ b/app/scanner/dialog_updateprogress.cpp @@ -0,0 +1,79 @@ +#include "dialog_updateprogress.h" +#include "ui_dialog_updateprogress.h" +#include "base/HGUtility.h" + +Dialog_updateProgress::Dialog_updateProgress(class HGVersion &version, const QString &url, QWidget *parent) : + QDialog(parent) + , m_version(version) + , m_url(url) + , ui(new Ui::Dialog_updateProgress) +{ + ui->setupUi(this); + ui->progressBar->setValue(0); + + connect(this, SIGNAL(updateProgress(int)), this, SLOT(on_updateProgress(int)), Qt::QueuedConnection); + + m_stopThread = false; + HGBase_OpenThread(ThreadFunc, this, &m_thread); +} + +Dialog_updateProgress::~Dialog_updateProgress() +{ + if (nullptr != m_thread) + { + HGBase_CloseThread(m_thread); + m_thread = nullptr; + } + + delete ui; +} + +int Dialog_updateProgress::HttpDownloadThreadFunc(long long totalSize, long long nowSize, void *param) +{ + Dialog_updateProgress *p = (Dialog_updateProgress *)param; + if (p->m_stopThread) + { + return 1; + } + + if (totalSize != 0) + { + emit p->updateProgress(((double)nowSize / totalSize) * 100); + } + + return 0; +} + +void Dialog_updateProgress::ThreadFunc(HGThread thread, HGPointer param) +{ + (void)thread; + Dialog_updateProgress *p = (Dialog_updateProgress *)param; + + HGChar cfgPath[512]; + HGBase_GetConfigPath(cfgPath, 512); + HGBase_CreateDir(cfgPath); + strcat(cfgPath, "123.exe"); + + p->m_version.HttpDownload(p->m_url.toStdString(), cfgPath, HttpDownloadThreadFunc, p); +} + +void Dialog_updateProgress::on_updateProgress(int value) +{ + ui->progressBar->setValue(value); +} + +void Dialog_updateProgress::on_pushButton_clicked() +{ + m_stopThread = true; + HGBase_CloseThread(m_thread); + m_thread = nullptr; + close(); +} + +void Dialog_updateProgress::closeEvent(QCloseEvent* e) +{ + (void)e; + m_stopThread = true; + HGBase_CloseThread(m_thread); + m_thread = nullptr; +} \ No newline at end of file diff --git a/app/scanner/dialog_updateprogress.h b/app/scanner/dialog_updateprogress.h new file mode 100644 index 00000000..a21f7d07 --- /dev/null +++ b/app/scanner/dialog_updateprogress.h @@ -0,0 +1,42 @@ +#ifndef DIALOG_UPDATEPROGRESS_H +#define DIALOG_UPDATEPROGRESS_H + +#include +#include "base/HGThread.h" +#include "HGVersion.h" +#include "mainwindow.h" + +namespace Ui { +class Dialog_updateProgress; +} + +class Dialog_updateProgress : public QDialog +{ + Q_OBJECT + +public: + explicit Dialog_updateProgress(class HGVersion &version, const QString &url, QWidget *parent = nullptr); + ~Dialog_updateProgress(); +private: + static int HttpDownloadThreadFunc(long long totalSize, long long nowSize, void *param); + static void ThreadFunc(HGThread thread, HGPointer param); + +signals: + void updateProgress(int value); +private slots: + void on_updateProgress(int value); + + void on_pushButton_clicked(); +protected: + virtual void closeEvent(QCloseEvent* e); + +private: + Ui::Dialog_updateProgress *ui; + + class HGVersion &m_version; + QString m_url; + bool m_stopThread; + HGThread m_thread; +}; + +#endif // DIALOG_UPDATEPROGRESS_H diff --git a/app/scanner/dialog_updateprogress.ui b/app/scanner/dialog_updateprogress.ui new file mode 100644 index 00000000..28a1918f --- /dev/null +++ b/app/scanner/dialog_updateprogress.ui @@ -0,0 +1,65 @@ + + + Dialog_updateProgress + + + + 0 + 0 + 500 + 101 + + + + Dialog + + + + + + 24 + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + stop + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + + + + diff --git a/app/scanner/mainwindow.cpp b/app/scanner/mainwindow.cpp index 8da95916..fb7c9cc7 100644 --- a/app/scanner/mainwindow.cpp +++ b/app/scanner/mainwindow.cpp @@ -28,6 +28,7 @@ #include "dialog_clrcache.h" #include "dialog_moveto.h" #include "dialog_imageeditor.h" +#include "dialog_updateprogress.h" #include "hg_settingdialog.h" #include "base/HGInfo.h" #include "imgfmt/HGPdf.h" @@ -86,6 +87,8 @@ MainWindow::MainWindow(class HGVersion& version, QWidget *parent) resize(950, 720); } + ui->actionact_update->setVisible(false); + m_config.load(); ui->toolBar->addAction(ui->act_scannerSettings); @@ -1079,6 +1082,22 @@ void MainWindow::on_statusInfoDblClick() m_dialogLog->show(); } +void MainWindow::on_update(QListWidgetItem *item) +{ + m_listwidget->close(); + if(0 == m_version.CompareVersion(m_version.GetCurrVersion(), item->text().toStdString())) + { + QMessageBox::information(this, "tip", "Already in current version"); + return; + }else + { + QString url = item->data(Qt::UserRole).toString(); + + Dialog_updateProgress dlg(m_version, url); + dlg.exec(); + } +} + void MainWindow::on_act_thumbnailBar_triggered(bool checked) { ui->dockWidget->setVisible(checked); @@ -3088,3 +3107,30 @@ void MainWindow::on_act_sortPages_triggered() m_thumb->bookSort(); } + +void MainWindow::on_actionact_update_triggered() +{ + m_listwidget = new QListWidget; + m_listwidget->setWindowTitle("chose the version"); + + std::list versionList; + if(m_version.GetVersionInfoList(versionList)) + { + std::list::iterator iter; + + for(iter = versionList.begin(); iter != versionList.end(); ++iter) + { + QListWidgetItem *listwidgetItem = new QListWidgetItem; + listwidgetItem->setText(QString(iter->version.c_str())); + listwidgetItem->setData(Qt::UserRole, iter->url.c_str()); + listwidgetItem->setToolTip(iter->desc.c_str() + tr(" buginfo: ") + iter->bugInfo.c_str()); + m_listwidget->addItem(listwidgetItem); + connect(m_listwidget, SIGNAL(itemDoubleClicked(QListWidgetItem*)), this, SLOT(on_update(QListWidgetItem*)), Qt::QueuedConnection); + } + m_listwidget->show(); + } + else + { + QMessageBox::critical(this, tr("error"), tr("get versionlist failed")); + } +} diff --git a/app/scanner/mainwindow.h b/app/scanner/mainwindow.h index f6441787..f47926c4 100644 --- a/app/scanner/mainwindow.h +++ b/app/scanner/mainwindow.h @@ -3,12 +3,14 @@ #include #include +#include #include "HGImgView.h" #include "HGImgThumb.h" #include "sane/sane_ex.h" #include "config.h" #include "dialog_aquireinto.h" #include "imgfmt/HGImgFmt.h" +#include "HGVersion.h" #include "device_menu.h" #include "sane_device.h" @@ -120,6 +122,7 @@ private slots: void on_continueScan(); void on_stopScan(); void on_statusInfoDblClick(); + void on_update(QListWidgetItem *item); void on_act_thumbnailBar_triggered(bool checked); @@ -199,6 +202,8 @@ private slots: void on_act_sortPages_triggered(); + void on_actionact_update_triggered(); + public slots: void my_url_handler(const QUrl& url); @@ -231,6 +236,7 @@ private: HGImgThumb *m_thumb; QMenu *m_thumbMenu; QAction *m_moveToAction; + QListWidget* m_listwidget; config m_config; sane_dev cur_dev_; diff --git a/app/scanner/mainwindow.ui b/app/scanner/mainwindow.ui index b57cf4fc..07292097 100644 --- a/app/scanner/mainwindow.ui +++ b/app/scanner/mainwindow.ui @@ -35,7 +35,7 @@ 0 0 800 - 36 + 22 @@ -154,6 +154,7 @@ + @@ -577,6 +578,11 @@ act_autoSave + + + act_update + + diff --git a/build-qt/HGSolution/HGScanner/HGScanner.pro b/build-qt/HGSolution/HGScanner/HGScanner.pro index 5e41c82d..657f4143 100644 --- a/build-qt/HGSolution/HGScanner/HGScanner.pro +++ b/build-qt/HGSolution/HGScanner/HGScanner.pro @@ -186,7 +186,8 @@ SOURCES += \ ../../../app/scanner/HGImgView.cpp \ ../../../app/scanner/HGUIGlobal.cpp \ ../../../utility/HGString.cpp \ - ../../../app/scanner/dialog_input.cpp + ../../../app/scanner/dialog_input.cpp\ + ../../../app/scanner/dialog_updateprogress.cpp HEADERS += \ ../../../app/scanner/HGVersion.h \ @@ -231,7 +232,8 @@ HEADERS += \ ../../../app/scanner/HGUIGlobal.h \ ../../../utility/HGString.h \ ../../../app/scanner/dialog_input.h \ - ../../../app/scanner/custom_file_dialog.h + ../../../app/scanner/custom_file_dialog.h\ + ../../../app/scanner/dialog_updateprogress.h FORMS += \ ../../../app/scanner/cutdialog.ui \ @@ -261,7 +263,8 @@ FORMS += \ ../../../app/scanner/widget_imgproc_base.ui \ ../../../app/scanner/widget_statusbar.ui \ ../../../app/scanner/dialog_log.ui \ - ../../../app/scanner/dialog_input.ui + ../../../app/scanner/dialog_input.ui \ + ../../../app/scanner/dialog_updateprogress.ui TRANSLATIONS += \ ../../../app/scanner/Scanner_zh_CN.ts \