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 ++++++++++++++++++++++++++++++++++++++++++++++++++++++ gui/MainWindow.h | 2 ++ 2 files changed, 58 insertions(+) (limited to 'gui') 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."; diff --git a/gui/MainWindow.h b/gui/MainWindow.h index f2315ee6..7089b98b 100644 --- a/gui/MainWindow.h +++ b/gui/MainWindow.h @@ -157,6 +157,8 @@ slots: void updateAvailable(QString repo, QString versionName, int versionId); + void notificationsChanged(); + void activeAccountChanged(); void changeActiveAccount(); -- 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') 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') 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 From e558584af0e6a168d76868e89d132aeebd0aa36a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Petr=20Mr=C3=A1zek?= Date: Fri, 3 Jan 2014 23:26:21 +0100 Subject: Fix library column stretching --- gui/widgets/ModListView.cpp | 20 +++++++++++++++----- 1 file changed, 15 insertions(+), 5 deletions(-) (limited to 'gui') diff --git a/gui/widgets/ModListView.cpp b/gui/widgets/ModListView.cpp index 9d5950c3..358e6331 100644 --- a/gui/widgets/ModListView.cpp +++ b/gui/widgets/ModListView.cpp @@ -44,9 +44,19 @@ void ModListView::setModel ( QAbstractItemModel* model ) QTreeView::setModel ( model ); auto head = header(); head->setStretchLastSection(false); - head->setSectionResizeMode(0, QHeaderView::ResizeToContents); - head->setSectionResizeMode(1, QHeaderView::Stretch); - for(int i = 2; i < head->count(); i++) - head->setSectionResizeMode(i, QHeaderView::ResizeToContents); - dropIndicatorPosition(); + // HACK: this is true for the checkbox column of mod lists + auto string = model->headerData(0,head->orientation()).toString(); + if(!string.size()) + { + head->setSectionResizeMode(0, QHeaderView::ResizeToContents); + head->setSectionResizeMode(1, QHeaderView::Stretch); + for(int i = 2; i < head->count(); i++) + head->setSectionResizeMode(i, QHeaderView::ResizeToContents); + } + else + { + head->setSectionResizeMode(0, QHeaderView::Stretch); + for(int i = 1; i < head->count(); i++) + head->setSectionResizeMode(i, QHeaderView::ResizeToContents); + } } -- cgit v1.2.3