diff options
author | Jan Dalheimer <jan@dalheimer.de> | 2014-01-03 19:19:27 +0100 |
---|---|---|
committer | Jan Dalheimer <jan@dalheimer.de> | 2014-01-03 19:19:27 +0100 |
commit | b3dd1eba2146849cddd7e85b16aa3b8af9d2de23 (patch) | |
tree | 2f7f5dc275257bf4cdecd70063982dfa7d2e15f2 /gui/MainWindow.cpp | |
parent | c35012f1a570e752051c8fcbafe628fc64aa793f (diff) | |
download | MultiMC-b3dd1eba2146849cddd7e85b16aa3b8af9d2de23.tar MultiMC-b3dd1eba2146849cddd7e85b16aa3b8af9d2de23.tar.gz MultiMC-b3dd1eba2146849cddd7e85b16aa3b8af9d2de23.tar.lz MultiMC-b3dd1eba2146849cddd7e85b16aa3b8af9d2de23.tar.xz MultiMC-b3dd1eba2146849cddd7e85b16aa3b8af9d2de23.zip |
Notifications system. Mainly to be used in case the updater breaks.
Diffstat (limited to 'gui/MainWindow.cpp')
-rw-r--r-- | gui/MainWindow.cpp | 56 |
1 files changed, 56 insertions, 0 deletions
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 <logic/updater/UpdateChecker.h> +#include <logic/updater/NotificationChecker.h> #include <logic/tasks/ThreadTask.h> 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<int> stringToIntList(const QString &string) +{ + QStringList split = string.split(',', QString::SkipEmptyParts); + QList<int> out; + for (int i = 0; i < split.size(); ++i) + { + out.append(split.at(i).toInt()); + } + return out; +} +QString intListToString(const QList<int> &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<NotificationChecker::NotificationEntry> entries = + MMC->notificationChecker()->notificationEntries(); + QList<int> 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."; |