From 40d00e3066e559766970dc23d5f06c0f79c82198 Mon Sep 17 00:00:00 2001 From: DanielSvoboda Date: Sun, 29 Sep 2024 02:24:21 -0300 Subject: [PATCH] progressBar DownloadUpdate (#1141) --- src/qt_gui/check_update.cpp | 21 ++++++++++++++++++++- 1 file changed, 20 insertions(+), 1 deletion(-) diff --git a/src/qt_gui/check_update.cpp b/src/qt_gui/check_update.cpp index f5e284a2..b92974ba 100644 --- a/src/qt_gui/check_update.cpp +++ b/src/qt_gui/check_update.cpp @@ -23,6 +23,7 @@ #include #include #include +#include #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((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(); }); }