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 <QMessageBox>
|
||||
#include <QVBoxLayout>
|
||||
#include <QDialogButtonBox>
|
||||
|
||||
#include <QPushButton>
|
||||
#include <QLabel>
|
||||
#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);
|
||||
progress = new QProgressBar(this);
|
||||
|
||||
QDialogButtonBox *buttonBox = new QDialogButtonBox(this);
|
||||
buttonBox = new QDialogButtonBox(this);
|
||||
buttonBox->setFixedWidth(350);
|
||||
|
||||
ok = new QPushButton("Close", 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);
|
||||
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);
|
||||
|
||||
connect(gotoDownload, SIGNAL(clicked()), this, SLOT(gotoDownloadPage()));
|
||||
connect(manualDownload, SIGNAL(clicked()), this, SLOT(downloadUpdate()));
|
||||
connect(stopDownload, SIGNAL(clicked()), this, SLOT(cancelDownload()));
|
||||
connect(ok, SIGNAL(clicked()), this, SLOT(closeDialog()));
|
||||
|
||||
QVBoxLayout *parentLayout = new QVBoxLayout(this);
|
||||
|
@ -56,22 +60,17 @@ DlgUpdate::DlgUpdate(QWidget *parent) : QDialog(parent) {
|
|||
//Initialize the checker and downloader class
|
||||
uDownloader = new UpdateDownloader(this);
|
||||
connect(uDownloader, SIGNAL(downloadSuccessful(QUrl)), this, SLOT(downloadSuccessful(QUrl)));
|
||||
connect(uDownloader, SIGNAL(progressMade(qint64, qint64)),
|
||||
this, SLOT(downloadProgressMade(qint64, qint64)));
|
||||
connect(uDownloader, SIGNAL(error(QString)),
|
||||
this, SLOT(downloadError(QString)));
|
||||
connect(uDownloader, SIGNAL(progressMade(qint64, qint64)), this, SLOT(downloadProgressMade(qint64, qint64)));
|
||||
connect(uDownloader, SIGNAL(error(QString)), this, SLOT(downloadError(QString)));
|
||||
|
||||
ReleaseChannel * channel = settingsCache->getUpdateReleaseChannel();
|
||||
connect(channel, SIGNAL(finishedCheck(bool, bool, Release * )),
|
||||
this, SLOT(finishedUpdateCheck(bool, bool, Release * )));
|
||||
connect(channel, SIGNAL(error(QString)),
|
||||
this, SLOT(updateCheckError(QString)));
|
||||
connect(channel, SIGNAL(finishedCheck(bool, bool, Release *)), this, SLOT(finishedUpdateCheck(bool, bool, Release *)));
|
||||
connect(channel, SIGNAL(error(QString)), this, SLOT(updateCheckError(QString)));
|
||||
|
||||
//Check for updates
|
||||
beginUpdateCheck();
|
||||
}
|
||||
|
||||
|
||||
void DlgUpdate::closeDialog() {
|
||||
accept();
|
||||
}
|
||||
|
@ -83,11 +82,17 @@ void DlgUpdate::gotoDownloadPage() {
|
|||
|
||||
void DlgUpdate::downloadUpdate() {
|
||||
setLabel(tr("Downloading update..."));
|
||||
enableOkButton(false);
|
||||
enableUpdateButton(false);
|
||||
addStopDownloadAndRemoveOthers(true); // Will remove all other buttons
|
||||
uDownloader->beginDownload(updateUrl);
|
||||
}
|
||||
|
||||
void DlgUpdate::cancelDownload() {
|
||||
emit uDownloader->stopDownload();
|
||||
setLabel("Download Canceled");
|
||||
addStopDownloadAndRemoveOthers(false);
|
||||
downloadProgressMade(0, 1);
|
||||
}
|
||||
|
||||
void DlgUpdate::beginUpdateCheck() {
|
||||
progress->setMinimum(0);
|
||||
progress->setMaximum(0);
|
||||
|
@ -142,6 +147,19 @@ void DlgUpdate::enableUpdateButton(bool 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) {
|
||||
ok->setEnabled(enable);
|
||||
}
|
||||
|
|
|
@ -3,6 +3,7 @@
|
|||
|
||||
#include <QtNetwork>
|
||||
#include <QProgressDialog>
|
||||
#include <QDialogButtonBox>
|
||||
|
||||
#include "update_downloader.h"
|
||||
class Release;
|
||||
|
@ -16,6 +17,7 @@ private slots:
|
|||
void finishedUpdateCheck(bool needToUpdate, bool isCompatible, Release *release);
|
||||
void gotoDownloadPage();
|
||||
void downloadUpdate();
|
||||
void cancelDownload();
|
||||
void updateCheckError(QString errorString);
|
||||
void downloadSuccessful(QUrl filepath);
|
||||
void downloadProgressMade(qint64 bytesRead, qint64 totalBytes);
|
||||
|
@ -25,13 +27,15 @@ private:
|
|||
QUrl updateUrl;
|
||||
void enableUpdateButton(bool enable);
|
||||
void enableOkButton(bool enable);
|
||||
void addStopDownloadAndRemoveOthers(bool enable);
|
||||
void beginUpdateCheck();
|
||||
void setLabel(QString text);
|
||||
QLabel *statusLabel, *descriptionLabel;
|
||||
QProgressBar *progress;
|
||||
QPushButton *manualDownload, *gotoDownload, *ok;
|
||||
QPushButton *manualDownload, *gotoDownload, *ok, *stopDownload;
|
||||
QPushButton *cancel;
|
||||
UpdateDownloader *uDownloader;
|
||||
QDialogButtonBox *buttonBox;
|
||||
};
|
||||
|
||||
#endif
|
||||
|
|
|
@ -1,4 +1,5 @@
|
|||
#include <QUrl>
|
||||
#include <QDebug>
|
||||
|
||||
#include "update_downloader.h"
|
||||
|
||||
|
@ -14,10 +15,13 @@ void UpdateDownloader::beginDownload(QUrl downloadUrl) {
|
|||
response = netMan->get(QNetworkRequest(downloadUrl));
|
||||
connect(response, SIGNAL(finished()), this, SLOT(fileFinished()));
|
||||
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) {
|
||||
if (response == nullptr)
|
||||
return;
|
||||
|
||||
emit error(response->errorString().toUtf8());
|
||||
}
|
||||
|
||||
|
|
|
@ -19,6 +19,7 @@ signals:
|
|||
void downloadSuccessful(QUrl filepath);
|
||||
void progressMade(qint64 bytesRead, qint64 totalBytes);
|
||||
void error(QString errorString);
|
||||
void stopDownload();
|
||||
private:
|
||||
QUrl originalUrl;
|
||||
QNetworkAccessManager *netMan;
|
||||
|
|
Loading…
Reference in a new issue