progressBar DownloadUpdate (#1141)

This commit is contained in:
DanielSvoboda 2024-09-29 02:24:21 -03:00 committed by GitHub
parent a4168150ed
commit 40d00e3066
No known key found for this signature in database
GPG Key ID: B5690EEEBB952194

View File

@ -23,6 +23,7 @@
#include <common/path_util.h>
#include <common/scm_rev.h>
#include <common/version.h>
#include <qprogressbar.h>
#include "check_update.h"
using namespace Common::FS;
@ -313,15 +314,32 @@ void CheckUpdate::requestChangelog(const QString& currentRev, const QString& lat
}
void CheckUpdate::DownloadUpdate(const QString& url) {
QProgressBar* progressBar = new QProgressBar(this);
progressBar->setRange(0, 100);
progressBar->setTextVisible(true);
progressBar->setValue(0);
layout()->addWidget(progressBar);
QNetworkRequest request(url);
QNetworkReply* reply = networkManager->get(request);
connect(reply, &QNetworkReply::finished, this, [this, reply, url]() {
connect(reply, &QNetworkReply::downloadProgress, this,
[progressBar](qint64 bytesReceived, qint64 bytesTotal) {
if (bytesTotal > 0) {
int percentage = static_cast<int>((bytesReceived * 100) / bytesTotal);
progressBar->setValue(percentage);
}
});
connect(reply, &QNetworkReply::finished, this, [this, reply, progressBar, url]() {
progressBar->setValue(100);
if (reply->error() != QNetworkReply::NoError) {
QMessageBox::warning(this, tr("Error"),
tr("Network error occurred while trying to access the URL") +
":\n" + url + "\n" + reply->errorString());
reply->deleteLater();
progressBar->deleteLater();
return;
}
@ -348,6 +366,7 @@ void CheckUpdate::DownloadUpdate(const QString& url) {
}
reply->deleteLater();
progressBar->deleteLater();
});
}