code_app/app/scanner/dialog_updateprogress.cpp

79 lines
1.8 KiB
C++

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