diff --git a/mainwindow.cpp b/mainwindow.cpp index ecf8e55..5cca1e3 100644 --- a/mainwindow.cpp +++ b/mainwindow.cpp @@ -2,10 +2,14 @@ #include "./ui_mainwindow.h" #include +#include #include "data/settingshandler.h" #include "genericcore.h" +static QString updateTextClean = "Do you want to update the application now?"; +static QString updateTextDirty = "Do you want to save the tasks & update the application now?"; + MainWindow::MainWindow(QWidget* parent) : QMainWindow(parent) , ui(new Ui::MainWindow) { @@ -32,6 +36,8 @@ MainWindow::MainWindow(QWidget* parent) connect(m_core, &GenericCore::displayStatusMessage, this, &MainWindow::displayStatusMessage); connect(this, &MainWindow::displayStatusMessage, this, &MainWindow::showStatusMessage); + connect(this, &MainWindow::checkForUpdates, this, + &MainWindow::on_actionCheck_for_update_triggered, Qt::QueuedConnection); } MainWindow::~MainWindow() { @@ -49,6 +55,20 @@ void MainWindow::showStatusMessage(const QString text) { ui->statusbar->showMessage(text); } +void MainWindow::on_actionCheck_for_update_triggered() { + showStatusMessage("Checking for update..."); + const bool updateAvailable = m_core->isApplicationUpdateAvailable(); + if (updateAvailable) { + const QString text = isWindowModified() ? updateTextDirty : updateTextClean; + const QMessageBox::StandardButton clickedButton = QMessageBox::question( + this, tr("Update available."), text, QMessageBox::Yes | QMessageBox::No, QMessageBox::Yes); + if (clickedButton == QMessageBox::Yes) { + m_core->triggerApplicationUpdate(); + close(); + } + } +} + void MainWindow::closeEvent(QCloseEvent* event) { if (isWindowModified()) { QMessageBox msgBox; diff --git a/mainwindow.h b/mainwindow.h index f47ea80..7ebac8f 100644 --- a/mainwindow.h +++ b/mainwindow.h @@ -21,14 +21,17 @@ class MainWindow : public QMainWindow { signals: void displayStatusMessage(QString message); + void checkForUpdates(); protected: void closeEvent(QCloseEvent* event) override; private slots: - void on_pushButton_clicked(); - void showStatusMessage(const QString text); + + void on_pushButton_clicked(); + void on_actionCheck_for_update_triggered(); + private: Ui::MainWindow* ui; diff --git a/mainwindow.ui b/mainwindow.ui index 4b2a83e..923021d 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -40,8 +40,38 @@ 25 + + + &File + + + + + &Edit + + + + + &View + + + + + &Help + + + + + + + + + + Check for &update + +