mirror of
https://github.com/Cockatrice/Cockatrice.git
synced 2026-06-11 00:24:47 -07:00
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);
|
||||
}
|
||||
|
|
|
|||
Loading…
Add table
Add a link
Reference in a new issue