cancel downloads from updater (#2534)
* cancel downloads from updater - fix #2534 * fix double popup
This commit is contained in:
parent
6f30304271
commit
06c3edf4c6
4 changed files with 45 additions and 18 deletions
|
@ -3,7 +3,7 @@
|
||||||
#include <QDesktopServices>
|
#include <QDesktopServices>
|
||||||
#include <QMessageBox>
|
#include <QMessageBox>
|
||||||
#include <QVBoxLayout>
|
#include <QVBoxLayout>
|
||||||
#include <QDialogButtonBox>
|
|
||||||
#include <QPushButton>
|
#include <QPushButton>
|
||||||
#include <QLabel>
|
#include <QLabel>
|
||||||
#include <QProgressBar>
|
#include <QProgressBar>
|
||||||
|
@ -24,17 +24,21 @@ DlgUpdate::DlgUpdate(QWidget *parent) : QDialog(parent) {
|
||||||
descriptionLabel = new QLabel(tr("Current release channel:") + " " + tr(settingsCache->getUpdateReleaseChannel()->getName().toUtf8()), this);
|
descriptionLabel = new QLabel(tr("Current release channel:") + " " + tr(settingsCache->getUpdateReleaseChannel()->getName().toUtf8()), this);
|
||||||
progress = new QProgressBar(this);
|
progress = new QProgressBar(this);
|
||||||
|
|
||||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
|
buttonBox = new QDialogButtonBox(this);
|
||||||
|
buttonBox->setFixedWidth(350);
|
||||||
|
|
||||||
ok = new QPushButton("Close", this);
|
ok = new QPushButton("Close", this);
|
||||||
manualDownload = new QPushButton(tr("Reinstall"), this);
|
manualDownload = new QPushButton(tr("Reinstall"), this);
|
||||||
enableUpdateButton(false); //Unless we know there's an update available, you can't install
|
stopDownload = new QPushButton(tr("Cancel Download"), this);
|
||||||
gotoDownload = new QPushButton(tr("Open Download Page"), this);
|
gotoDownload = new QPushButton(tr("Open Download Page"), this);
|
||||||
buttonBox->addButton(manualDownload, QDialogButtonBox::ActionRole);
|
|
||||||
buttonBox->addButton(gotoDownload, QDialogButtonBox::ActionRole);
|
addStopDownloadAndRemoveOthers(false); // Add all buttons to box
|
||||||
|
enableUpdateButton(false); //Unless we know there's an update available, you can't install
|
||||||
buttonBox->addButton(ok, QDialogButtonBox::AcceptRole);
|
buttonBox->addButton(ok, QDialogButtonBox::AcceptRole);
|
||||||
|
|
||||||
connect(gotoDownload, SIGNAL(clicked()), this, SLOT(gotoDownloadPage()));
|
connect(gotoDownload, SIGNAL(clicked()), this, SLOT(gotoDownloadPage()));
|
||||||
connect(manualDownload, SIGNAL(clicked()), this, SLOT(downloadUpdate()));
|
connect(manualDownload, SIGNAL(clicked()), this, SLOT(downloadUpdate()));
|
||||||
|
connect(stopDownload, SIGNAL(clicked()), this, SLOT(cancelDownload()));
|
||||||
connect(ok, SIGNAL(clicked()), this, SLOT(closeDialog()));
|
connect(ok, SIGNAL(clicked()), this, SLOT(closeDialog()));
|
||||||
|
|
||||||
QVBoxLayout *parentLayout = new QVBoxLayout(this);
|
QVBoxLayout *parentLayout = new QVBoxLayout(this);
|
||||||
|
@ -56,22 +60,17 @@ DlgUpdate::DlgUpdate(QWidget *parent) : QDialog(parent) {
|
||||||
//Initialize the checker and downloader class
|
//Initialize the checker and downloader class
|
||||||
uDownloader = new UpdateDownloader(this);
|
uDownloader = new UpdateDownloader(this);
|
||||||
connect(uDownloader, SIGNAL(downloadSuccessful(QUrl)), this, SLOT(downloadSuccessful(QUrl)));
|
connect(uDownloader, SIGNAL(downloadSuccessful(QUrl)), this, SLOT(downloadSuccessful(QUrl)));
|
||||||
connect(uDownloader, SIGNAL(progressMade(qint64, qint64)),
|
connect(uDownloader, SIGNAL(progressMade(qint64, qint64)), this, SLOT(downloadProgressMade(qint64, qint64)));
|
||||||
this, SLOT(downloadProgressMade(qint64, qint64)));
|
connect(uDownloader, SIGNAL(error(QString)), this, SLOT(downloadError(QString)));
|
||||||
connect(uDownloader, SIGNAL(error(QString)),
|
|
||||||
this, SLOT(downloadError(QString)));
|
|
||||||
|
|
||||||
ReleaseChannel * channel = settingsCache->getUpdateReleaseChannel();
|
ReleaseChannel * channel = settingsCache->getUpdateReleaseChannel();
|
||||||
connect(channel, SIGNAL(finishedCheck(bool, bool, Release * )),
|
connect(channel, SIGNAL(finishedCheck(bool, bool, Release *)), this, SLOT(finishedUpdateCheck(bool, bool, Release *)));
|
||||||
this, SLOT(finishedUpdateCheck(bool, bool, Release * )));
|
connect(channel, SIGNAL(error(QString)), this, SLOT(updateCheckError(QString)));
|
||||||
connect(channel, SIGNAL(error(QString)),
|
|
||||||
this, SLOT(updateCheckError(QString)));
|
|
||||||
|
|
||||||
//Check for updates
|
//Check for updates
|
||||||
beginUpdateCheck();
|
beginUpdateCheck();
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
||||||
void DlgUpdate::closeDialog() {
|
void DlgUpdate::closeDialog() {
|
||||||
accept();
|
accept();
|
||||||
}
|
}
|
||||||
|
@ -83,11 +82,17 @@ void DlgUpdate::gotoDownloadPage() {
|
||||||
|
|
||||||
void DlgUpdate::downloadUpdate() {
|
void DlgUpdate::downloadUpdate() {
|
||||||
setLabel(tr("Downloading update..."));
|
setLabel(tr("Downloading update..."));
|
||||||
enableOkButton(false);
|
addStopDownloadAndRemoveOthers(true); // Will remove all other buttons
|
||||||
enableUpdateButton(false);
|
|
||||||
uDownloader->beginDownload(updateUrl);
|
uDownloader->beginDownload(updateUrl);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DlgUpdate::cancelDownload() {
|
||||||
|
emit uDownloader->stopDownload();
|
||||||
|
setLabel("Download Canceled");
|
||||||
|
addStopDownloadAndRemoveOthers(false);
|
||||||
|
downloadProgressMade(0, 1);
|
||||||
|
}
|
||||||
|
|
||||||
void DlgUpdate::beginUpdateCheck() {
|
void DlgUpdate::beginUpdateCheck() {
|
||||||
progress->setMinimum(0);
|
progress->setMinimum(0);
|
||||||
progress->setMaximum(0);
|
progress->setMaximum(0);
|
||||||
|
@ -142,6 +147,19 @@ void DlgUpdate::enableUpdateButton(bool enable) {
|
||||||
manualDownload->setEnabled(enable);
|
manualDownload->setEnabled(enable);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
void DlgUpdate::addStopDownloadAndRemoveOthers(bool enable) {
|
||||||
|
if (enable) {
|
||||||
|
buttonBox->addButton(stopDownload, QDialogButtonBox::ActionRole);
|
||||||
|
buttonBox->removeButton(manualDownload);
|
||||||
|
buttonBox->removeButton(gotoDownload);
|
||||||
|
}
|
||||||
|
else {
|
||||||
|
buttonBox->removeButton(stopDownload);
|
||||||
|
buttonBox->addButton(manualDownload, QDialogButtonBox::ActionRole);
|
||||||
|
buttonBox->addButton(gotoDownload, QDialogButtonBox::ActionRole);
|
||||||
|
}
|
||||||
|
}
|
||||||
|
|
||||||
void DlgUpdate::enableOkButton(bool enable) {
|
void DlgUpdate::enableOkButton(bool enable) {
|
||||||
ok->setEnabled(enable);
|
ok->setEnabled(enable);
|
||||||
}
|
}
|
||||||
|
|
|
@ -3,6 +3,7 @@
|
||||||
|
|
||||||
#include <QtNetwork>
|
#include <QtNetwork>
|
||||||
#include <QProgressDialog>
|
#include <QProgressDialog>
|
||||||
|
#include <QDialogButtonBox>
|
||||||
|
|
||||||
#include "update_downloader.h"
|
#include "update_downloader.h"
|
||||||
class Release;
|
class Release;
|
||||||
|
@ -16,6 +17,7 @@ private slots:
|
||||||
void finishedUpdateCheck(bool needToUpdate, bool isCompatible, Release *release);
|
void finishedUpdateCheck(bool needToUpdate, bool isCompatible, Release *release);
|
||||||
void gotoDownloadPage();
|
void gotoDownloadPage();
|
||||||
void downloadUpdate();
|
void downloadUpdate();
|
||||||
|
void cancelDownload();
|
||||||
void updateCheckError(QString errorString);
|
void updateCheckError(QString errorString);
|
||||||
void downloadSuccessful(QUrl filepath);
|
void downloadSuccessful(QUrl filepath);
|
||||||
void downloadProgressMade(qint64 bytesRead, qint64 totalBytes);
|
void downloadProgressMade(qint64 bytesRead, qint64 totalBytes);
|
||||||
|
@ -25,13 +27,15 @@ private:
|
||||||
QUrl updateUrl;
|
QUrl updateUrl;
|
||||||
void enableUpdateButton(bool enable);
|
void enableUpdateButton(bool enable);
|
||||||
void enableOkButton(bool enable);
|
void enableOkButton(bool enable);
|
||||||
|
void addStopDownloadAndRemoveOthers(bool enable);
|
||||||
void beginUpdateCheck();
|
void beginUpdateCheck();
|
||||||
void setLabel(QString text);
|
void setLabel(QString text);
|
||||||
QLabel *statusLabel, *descriptionLabel;
|
QLabel *statusLabel, *descriptionLabel;
|
||||||
QProgressBar *progress;
|
QProgressBar *progress;
|
||||||
QPushButton *manualDownload, *gotoDownload, *ok;
|
QPushButton *manualDownload, *gotoDownload, *ok, *stopDownload;
|
||||||
QPushButton *cancel;
|
QPushButton *cancel;
|
||||||
UpdateDownloader *uDownloader;
|
UpdateDownloader *uDownloader;
|
||||||
|
QDialogButtonBox *buttonBox;
|
||||||
};
|
};
|
||||||
|
|
||||||
#endif
|
#endif
|
||||||
|
|
|
@ -1,4 +1,5 @@
|
||||||
#include <QUrl>
|
#include <QUrl>
|
||||||
|
#include <QDebug>
|
||||||
|
|
||||||
#include "update_downloader.h"
|
#include "update_downloader.h"
|
||||||
|
|
||||||
|
@ -14,10 +15,13 @@ void UpdateDownloader::beginDownload(QUrl downloadUrl) {
|
||||||
response = netMan->get(QNetworkRequest(downloadUrl));
|
response = netMan->get(QNetworkRequest(downloadUrl));
|
||||||
connect(response, SIGNAL(finished()), this, SLOT(fileFinished()));
|
connect(response, SIGNAL(finished()), this, SLOT(fileFinished()));
|
||||||
connect(response, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64)));
|
connect(response, SIGNAL(downloadProgress(qint64, qint64)), this, SLOT(downloadProgress(qint64, qint64)));
|
||||||
connect(response, SIGNAL(error(QNetworkReply::NetworkError)), this, SLOT(downloadError(QNetworkReply::NetworkError)));
|
connect(this, SIGNAL(stopDownload()), response, SLOT(abort()));
|
||||||
}
|
}
|
||||||
|
|
||||||
void UpdateDownloader::downloadError(QNetworkReply::NetworkError) {
|
void UpdateDownloader::downloadError(QNetworkReply::NetworkError) {
|
||||||
|
if (response == nullptr)
|
||||||
|
return;
|
||||||
|
|
||||||
emit error(response->errorString().toUtf8());
|
emit error(response->errorString().toUtf8());
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -19,6 +19,7 @@ signals:
|
||||||
void downloadSuccessful(QUrl filepath);
|
void downloadSuccessful(QUrl filepath);
|
||||||
void progressMade(qint64 bytesRead, qint64 totalBytes);
|
void progressMade(qint64 bytesRead, qint64 totalBytes);
|
||||||
void error(QString errorString);
|
void error(QString errorString);
|
||||||
|
void stopDownload();
|
||||||
private:
|
private:
|
||||||
QUrl originalUrl;
|
QUrl originalUrl;
|
||||||
QNetworkAccessManager *netMan;
|
QNetworkAccessManager *netMan;
|
||||||
|
|
Loading…
Reference in a new issue