实现可以下载服务器上的app版本

This commit is contained in:
yangjiaxuan 2022-07-07 16:16:41 +08:00
parent 56ee129530
commit 7fdd6f1279
7 changed files with 251 additions and 4 deletions

View File

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

View File

@ -0,0 +1,42 @@
#ifndef DIALOG_UPDATEPROGRESS_H
#define DIALOG_UPDATEPROGRESS_H
#include <QDialog>
#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

View File

@ -0,0 +1,65 @@
<?xml version="1.0" encoding="UTF-8"?>
<ui version="4.0">
<class>Dialog_updateProgress</class>
<widget class="QDialog" name="Dialog_updateProgress">
<property name="geometry">
<rect>
<x>0</x>
<y>0</y>
<width>500</width>
<height>101</height>
</rect>
</property>
<property name="windowTitle">
<string>Dialog</string>
</property>
<layout class="QVBoxLayout" name="verticalLayout">
<item>
<widget class="QProgressBar" name="progressBar">
<property name="value">
<number>24</number>
</property>
</widget>
</item>
<item>
<layout class="QHBoxLayout" name="horizontalLayout">
<item>
<spacer name="horizontalSpacer">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="pushButton">
<property name="text">
<string>stop</string>
</property>
</widget>
</item>
<item>
<spacer name="horizontalSpacer_2">
<property name="orientation">
<enum>Qt::Horizontal</enum>
</property>
<property name="sizeHint" stdset="0">
<size>
<width>40</width>
<height>20</height>
</size>
</property>
</spacer>
</item>
</layout>
</item>
</layout>
</widget>
<resources/>
<connections/>
</ui>

View File

@ -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<VersionInfo> versionList;
if(m_version.GetVersionInfoList(versionList))
{
std::list<VersionInfo>::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"));
}
}

View File

@ -3,12 +3,14 @@
#include <QMainWindow>
#include <QLineEdit>
#include <QListWidgetItem>
#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_;

View File

@ -35,7 +35,7 @@
<x>0</x>
<y>0</y>
<width>800</width>
<height>36</height>
<height>22</height>
</rect>
</property>
<widget class="QMenu" name="menu_file">
@ -154,6 +154,7 @@
</property>
<addaction name="act_help"/>
<addaction name="separator"/>
<addaction name="actionact_update"/>
<addaction name="act_about"/>
</widget>
<widget class="device_menu" name="menu_device">
@ -577,6 +578,11 @@
<string>act_autoSave</string>
</property>
</action>
<action name="actionact_update">
<property name="text">
<string>act_update</string>
</property>
</action>
</widget>
<customwidgets>
<customwidget>

View File

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