From b3dd1eba2146849cddd7e85b16aa3b8af9d2de23 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Fri, 3 Jan 2014 19:19:27 +0100 Subject: Notifications system. Mainly to be used in case the updater breaks. --- gui/MainWindow.cpp | 56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ 1 file changed, 56 insertions(+) (limited to 'gui/MainWindow.cpp') diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 2b911b2c..cf34a46b 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -92,6 +92,7 @@ #include "logic/assets/AssetsUtils.h" #include "logic/assets/AssetsMigrateTask.h" #include +#include #include MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWindow) @@ -279,6 +280,9 @@ MainWindow::MainWindow(QWidget *parent) : QMainWindow(parent), ui(new Ui::MainWi // if automatic update checks are allowed, start one. if (MMC->settings()->get("AutoUpdate").toBool()) on_actionCheckUpdate_triggered(); + + connect(MMC->notificationChecker().get(), &NotificationChecker::notificationCheckFinished, + this, &MainWindow::notificationsChanged); } const QString currentInstanceId = MMC->settings()->get("SelectedInstance").toString(); @@ -495,6 +499,58 @@ void MainWindow::updateAvailable(QString repo, QString versionName, int versionI } } +QList stringToIntList(const QString &string) +{ + QStringList split = string.split(',', QString::SkipEmptyParts); + QList out; + for (int i = 0; i < split.size(); ++i) + { + out.append(split.at(i).toInt()); + } + return out; +} +QString intListToString(const QList &list) +{ + QStringList slist; + for (int i = 0; i < list.size(); ++i) + { + slist.append(QString::number(list.at(i))); + } + return slist.join(','); +} +void MainWindow::notificationsChanged() +{ + QList entries = + MMC->notificationChecker()->notificationEntries(); + QList shownNotifications = + stringToIntList(MMC->settings()->get("ShownNotifications").toString()); + for (auto it = entries.begin(); it != entries.end(); ++it) + { + NotificationChecker::NotificationEntry entry = *it; + if (!shownNotifications.contains(entry.id) && entry.applies()) + { + QMessageBox::Icon icon; + switch (entry.type) + { + case NotificationChecker::NotificationEntry::Critical: + icon = QMessageBox::Critical; + break; + case NotificationChecker::NotificationEntry::Warning: + icon = QMessageBox::Warning; + break; + case NotificationChecker::NotificationEntry::Information: + icon = QMessageBox::Information; + break; + } + + QMessageBox box(icon, tr("Notification"), entry.message, QMessageBox::Ok, this); + box.exec(); + shownNotifications.append(entry.id); + } + } + MMC->settings()->set("ShownNotifications", intListToString(shownNotifications)); +} + void MainWindow::downloadUpdates(QString repo, int versionId, bool installOnExit) { QLOG_INFO() << "Downloading updates."; -- cgit v1.2.3 From df1186e0212efc99fb0125380f2da0a3ac85fe5a Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Fri, 3 Jan 2014 21:05:03 +0100 Subject: Add the option to disable a certain message --- gui/MainWindow.cpp | 8 ++++++-- 1 file changed, 6 insertions(+), 2 deletions(-) (limited to 'gui/MainWindow.cpp') diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index cf34a46b..826cbc04 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -543,9 +543,13 @@ void MainWindow::notificationsChanged() break; } - QMessageBox box(icon, tr("Notification"), entry.message, QMessageBox::Ok, this); + QMessageBox box(icon, tr("Notification"), entry.message, QMessageBox::Close, this); + QPushButton *dontShowAgainButton = box.addButton(tr("Don't show again"), QMessageBox::AcceptRole); box.exec(); - shownNotifications.append(entry.id); + if (box.clickedButton() == dontShowAgainButton) + { + shownNotifications.append(entry.id); + } } } MMC->settings()->set("ShownNotifications", intListToString(shownNotifications)); -- cgit v1.2.3 From 116a6458b5ba35c87f6a22783d509a1fe8672f24 Mon Sep 17 00:00:00 2001 From: Jan Dalheimer Date: Fri, 3 Jan 2014 21:11:33 +0100 Subject: Explicitly set the close button to be the default button --- gui/MainWindow.cpp | 1 + 1 file changed, 1 insertion(+) (limited to 'gui/MainWindow.cpp') diff --git a/gui/MainWindow.cpp b/gui/MainWindow.cpp index 826cbc04..cb9171f1 100644 --- a/gui/MainWindow.cpp +++ b/gui/MainWindow.cpp @@ -545,6 +545,7 @@ void MainWindow::notificationsChanged() QMessageBox box(icon, tr("Notification"), entry.message, QMessageBox::Close, this); QPushButton *dontShowAgainButton = box.addButton(tr("Don't show again"), QMessageBox::AcceptRole); + box.setDefaultButton(QMessageBox::Close); box.exec(); if (box.clickedButton() == dontShowAgainButton) { -- cgit v1.2.3