From d045466017cffcc8873ad7a2cdba481d91d1d6b0 Mon Sep 17 00:00:00 2001 From: 0xFEEDC0DE64 <0xFEEDC0DE64@gmail.com> Date: Thu, 7 Dec 2017 00:51:45 +0100 Subject: [PATCH] Implemented UpdateDialog --- dialogs/updatedialog.cpp | 35 ++++++++++- dialogs/updatedialog.h | 4 ++ dialogs/updatedialog.ui | 131 ++++++++++++++++++++++----------------- mainwindow.ui | 4 +- 4 files changed, 115 insertions(+), 59 deletions(-) diff --git a/dialogs/updatedialog.cpp b/dialogs/updatedialog.cpp index 0e252e7..0236d0f 100644 --- a/dialogs/updatedialog.cpp +++ b/dialogs/updatedialog.cpp @@ -11,6 +11,10 @@ #include #include #include +#include +#include + +#include "zeiterfassungsettings.h" UpdateDialog::UpdateDialog(ZeiterfassungSettings &settings, QNetworkAccessManager *manager, QWidget *parent) : QDialog(parent), @@ -19,6 +23,15 @@ UpdateDialog::UpdateDialog(ZeiterfassungSettings &settings, QNetworkAccessManage { ui->setupUi(this); + setAttribute(Qt::WA_DeleteOnClose); + + connect(ui->buttonBox, &QDialogButtonBox::accepted, this, &UpdateDialog::submit); + connect(ui->buttonBox, &QDialogButtonBox::rejected, this, [=](){ + if(ui->checkBoxDontShow->isChecked()) + m_settings.setLastUpdateCheck(QDate::currentDate()); + reject(); + }); + m_reply = manager->get(QNetworkRequest(QUrl(QStringLiteral("https://api.github.com/repos/0xFEEDC0DE64/QtZeiterfassung/releases")))); connect(m_reply, &QNetworkReply::finished, this, &UpdateDialog::finished); } @@ -60,6 +73,26 @@ void UpdateDialog::finished() auto releaseObj = releaseVal.toObject(); auto version = QVersionNumber::fromString(releaseObj.value("tag_name").toString()); - qDebug() << version << (appVersion < version); + if(appVersion < version) + { + m_url = QUrl(releaseObj.value("html_url").toString()); + ui->labelDescription->setText(releaseObj.value("body").toString()); + + show(); + return; + } } + + deleteLater(); +} + +void UpdateDialog::submit() +{ + if(ui->checkBoxDontShow->isChecked()) + m_settings.setLastUpdateCheck(QDate::currentDate()); + + if(!QDesktopServices::openUrl(m_url)) + QMessageBox::warning(this, tr("Could not open default webbrowser!"), tr("Could not open default webbrowser!")); + + accept(); } diff --git a/dialogs/updatedialog.h b/dialogs/updatedialog.h index d162208..7f7b836 100644 --- a/dialogs/updatedialog.h +++ b/dialogs/updatedialog.h @@ -2,6 +2,7 @@ #define UPDATEDIALOG_H #include +#include class QNetworkAccessManager; class QNetworkReply; @@ -19,11 +20,14 @@ public: private Q_SLOTS: void finished(); + void submit(); private: Ui::UpdateDialog *ui; ZeiterfassungSettings &m_settings; QNetworkReply *m_reply; + + QUrl m_url; }; #endif // UPDATEDIALOG_H diff --git a/dialogs/updatedialog.ui b/dialogs/updatedialog.ui index f25d591..a130bde 100644 --- a/dialogs/updatedialog.ui +++ b/dialogs/updatedialog.ui @@ -1,71 +1,90 @@ + - - - UpdateDialog 0 0 - 400 - 300 + 447 + 280 Dialog - - - - 30 - 240 - 341 - 32 - - - - Qt::Horizontal - - - QDialogButtonBox::Cancel|QDialogButtonBox::Ok - - + + + + + + 20 + + + + New update available! + + + + + + + There is a new release available to download! + + + + + + + QFrame::WinPanel + + + QFrame::Sunken + + + TextLabel + + + Qt::AlignLeading|Qt::AlignLeft|Qt::AlignTop + + + + + + + + + Qt::Horizontal + + + + 40 + 20 + + + + + + + + Dont show today anymore + + + + + + + + + Qt::Horizontal + + + QDialogButtonBox::Cancel|QDialogButtonBox::Ok + + + + - - - - buttonBox - accepted() - UpdateDialog - accept() - - - 248 - 254 - - - 157 - 274 - - - - - buttonBox - rejected() - UpdateDialog - reject() - - - 316 - 260 - - - 286 - 274 - - - - + diff --git a/mainwindow.ui b/mainwindow.ui index 9c5f41d..a0f6776 100644 --- a/mainwindow.ui +++ b/mainwindow.ui @@ -196,7 +196,7 @@ 0 0 1220 - 438 + 454 @@ -258,7 +258,7 @@ 0 0 1242 - 26 + 22