Quit app before updating

Show a message box prompting the user to quit the application before
applying the update
This commit is contained in:
Alex Spataru 2015-01-02 15:32:12 -07:00
parent 34e331b2ac
commit 7b0444263e
4 changed files with 40 additions and 5 deletions

View File

@ -24,6 +24,11 @@ DownloadDialog::DownloadDialog (QWidget *parent)
// Connect SIGNALS/SLOTS
connect (ui->stopButton, SIGNAL (clicked()), this, SLOT (cancelDownload()));
connect (ui->openButton, SIGNAL (clicked()), this, SLOT (installUpdate()));
// Configure open button
ui->openButton->setEnabled(false);
ui->openButton->setVisible(false);
// Initialize the network access manager
m_manager = new QNetworkAccessManager (this);
@ -61,6 +66,28 @@ void DownloadDialog::beginDownload (const QUrl& url) {
showNormal();
}
void DownloadDialog::installUpdate(void) {
QMessageBox msg;
msg.setIcon(QMessageBox::Question);
msg.setText("<b>" +
tr("To apply the update(s), you must first quit %1")
.arg(qApp->applicationName()) +
"</b>");
msg.setInformativeText(tr("Do you want to quit %1 now?").arg(qApp->applicationName()));
msg.setStandardButtons(QMessageBox::Yes | QMessageBox::No);
if (msg.exec() == QMessageBox::Yes) {
openDownload();
qApp->closeAllWindows();
}
else {
ui->openButton->setEnabled(true);
ui->openButton->setVisible(true);
ui->timeLabel->setText (tr ("Click the \"Open\" button to apply the update"));
}
}
void DownloadDialog::openDownload(void) {
if (!m_path.isEmpty()) {
QString url = m_path;
@ -110,7 +137,7 @@ void DownloadDialog::downloadFinished(void) {
}
file.close();
openDownload();
installUpdate();
}
}

View File

@ -41,6 +41,7 @@ public:
private slots:
void openDownload(void);
void installUpdate(void);
void cancelDownload(void);
void downloadFinished(void);
void updateProgress (qint64 received, qint64 total);

View File

@ -185,6 +185,13 @@
</property>
</spacer>
</item>
<item>
<widget class="QPushButton" name="openButton">
<property name="text">
<string>Open</string>
</property>
</widget>
</item>
<item>
<widget class="QPushButton" name="stopButton">
<property name="text">