#include "dialog_updateprogress.h" #include "ui_dialog_updateprogress.h" #include "base/HGInfo.h" #include #include #include #include Dialog_updateProgress::Dialog_updateProgress(VersionDll *dll, const QString &url, const QString &savePath, QWidget *parent) : QDialog(parent) , m_versionDll(dll) , m_url(url) , m_savePath(savePath) , ui(new Ui::Dialog_updateProgress) { ui->setupUi(this); ui->progressBar->setValue(0); connect(this, SIGNAL(updateProgress(int)), this, SLOT(on_updateProgress(int)), Qt::QueuedConnection); connect(this, SIGNAL(finish()), this, SLOT(on_finish()), 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; } HGInt HGAPI Dialog_updateProgress::HttpDownloadThreadFunc(HGULonglong totalSize, HGULonglong nowSize, HGPointer 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 HGAPI Dialog_updateProgress::ThreadFunc(HGThread thread, HGPointer param) { (void)thread; Dialog_updateProgress *p = (Dialog_updateProgress *)param; HGResult ret = p->m_versionDll->HttpDownload(p->m_url.toStdString().c_str(), p->m_savePath.toStdString().c_str(), HttpDownloadThreadFunc, p); if (HGBASE_ERR_OK != ret) { QFile::remove(p->m_savePath.toStdString().c_str()); HGBase_WriteInfo(HGBASE_INFOTYPE_ERROR, "UpgradeHttpDownload:%u", ret); } emit p->finish(); } void Dialog_updateProgress::on_updateProgress(int value) { ui->progressBar->setValue(value); } void Dialog_updateProgress::on_finish() { accept(); } void Dialog_updateProgress::on_pushButton_clicked() { close(); } void Dialog_updateProgress::closeEvent(QCloseEvent* e) { m_stopThread = true; }