mirror of
https://github.com/shadps4-emu/shadPS4.git
synced 2024-11-23 11:20:07 +00:00
progressBar DownloadUpdate (#1141)
This commit is contained in:
parent
a4168150ed
commit
40d00e3066
@ -23,6 +23,7 @@
|
|||||||
#include <common/path_util.h>
|
#include <common/path_util.h>
|
||||||
#include <common/scm_rev.h>
|
#include <common/scm_rev.h>
|
||||||
#include <common/version.h>
|
#include <common/version.h>
|
||||||
|
#include <qprogressbar.h>
|
||||||
#include "check_update.h"
|
#include "check_update.h"
|
||||||
|
|
||||||
using namespace Common::FS;
|
using namespace Common::FS;
|
||||||
@ -313,15 +314,32 @@ void CheckUpdate::requestChangelog(const QString& currentRev, const QString& lat
|
|||||||
}
|
}
|
||||||
|
|
||||||
void CheckUpdate::DownloadUpdate(const QString& url) {
|
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);
|
QNetworkRequest request(url);
|
||||||
QNetworkReply* reply = networkManager->get(request);
|
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) {
|
if (reply->error() != QNetworkReply::NoError) {
|
||||||
QMessageBox::warning(this, tr("Error"),
|
QMessageBox::warning(this, tr("Error"),
|
||||||
tr("Network error occurred while trying to access the URL") +
|
tr("Network error occurred while trying to access the URL") +
|
||||||
":\n" + url + "\n" + reply->errorString());
|
":\n" + url + "\n" + reply->errorString());
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
progressBar->deleteLater();
|
||||||
return;
|
return;
|
||||||
}
|
}
|
||||||
|
|
||||||
@ -348,6 +366,7 @@ void CheckUpdate::DownloadUpdate(const QString& url) {
|
|||||||
}
|
}
|
||||||
|
|
||||||
reply->deleteLater();
|
reply->deleteLater();
|
||||||
|
progressBar->deleteLater();
|
||||||
});
|
});
|
||||||
}
|
}
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user