From 83fed6b7cd42d64aec7af48ea95d1bab235cc9d7 Mon Sep 17 00:00:00 2001 From: Martin Rotter Date: Fri, 9 May 2025 11:04:51 +0200 Subject: [PATCH] allow finetuning of showing of dialogs depending on notification/event type --- src/librssguard/core/feeddownloader.cpp | 2 +- .../gui/notifications/singlenotificationeditor.cpp | 3 +++ .../gui/notifications/singlenotificationeditor.ui | 10 +++++++++- src/librssguard/miscellaneous/application.cpp | 7 ++++++- src/librssguard/miscellaneous/notification.cpp | 8 +++++++- src/librssguard/miscellaneous/notification.h | 5 ++++- src/librssguard/miscellaneous/notificationfactory.cpp | 8 +++++--- 7 files changed, 35 insertions(+), 8 deletions(-) diff --git a/src/librssguard/core/feeddownloader.cpp b/src/librssguard/core/feeddownloader.cpp index 96b604b3b..8ef68532d 100644 --- a/src/librssguard/core/feeddownloader.cpp +++ b/src/librssguard/core/feeddownloader.cpp @@ -488,7 +488,7 @@ void FeedDownloader::finalizeUpdate() { if (!m_results.erroredFeeds().isEmpty()) { qApp->showGuiMessage(Notification::Event::ArticlesFetchingError, - {QObject::tr("Some feed have error"), + {QObject::tr("Some feeds have error"), QObject::tr("Some feeds threw an error when fetching articles."), QSystemTrayIcon::MessageIcon::Critical}); } diff --git a/src/librssguard/gui/notifications/singlenotificationeditor.cpp b/src/librssguard/gui/notifications/singlenotificationeditor.cpp index 0be560957..c53ad280b 100644 --- a/src/librssguard/gui/notifications/singlenotificationeditor.cpp +++ b/src/librssguard/gui/notifications/singlenotificationeditor.cpp @@ -26,6 +26,7 @@ SingleNotificationEditor::SingleNotificationEditor(const Notification& notificat connect(m_ui.m_btnBrowseSound, &QPushButton::clicked, this, &SingleNotificationEditor::selectSoundFile); connect(m_ui.m_txtSound, &QLineEdit::textChanged, this, &SingleNotificationEditor::notificationChanged); connect(m_ui.m_cbBalloon, &QCheckBox::toggled, this, &SingleNotificationEditor::notificationChanged); + connect(m_ui.m_cbDialogs, &QCheckBox::toggled, this, &SingleNotificationEditor::notificationChanged); connect(m_ui.m_cbPlaySound, &QCheckBox::toggled, this, &SingleNotificationEditor::notificationChanged); connect(m_ui.m_slidVolume, &QSlider::valueChanged, this, &SingleNotificationEditor::notificationChanged); @@ -38,6 +39,7 @@ SingleNotificationEditor::SingleNotificationEditor(const Notification& notificat Notification SingleNotificationEditor::notification() const { return Notification(m_notificationEvent, m_ui.m_cbBalloon->isChecked(), + m_ui.m_cbDialogs->isChecked(), m_ui.m_cbPlaySound->isChecked(), m_ui.m_txtSound->text(), m_ui.m_slidVolume->value()); @@ -64,6 +66,7 @@ void SingleNotificationEditor::loadNotification(const Notification& notification m_ui.m_txtSound->setText(notification.soundPath()); m_ui.m_slidVolume->setValue(notification.volume()); m_ui.m_cbBalloon->setChecked(notification.balloonEnabled()); + m_ui.m_cbDialogs->setChecked(notification.dialogEnabled()); m_ui.m_cbPlaySound->setChecked(notification.soundEnabled()); m_notificationEvent = notification.event(); diff --git a/src/librssguard/gui/notifications/singlenotificationeditor.ui b/src/librssguard/gui/notifications/singlenotificationeditor.ui index fd0bcee33..a9343191d 100644 --- a/src/librssguard/gui/notifications/singlenotificationeditor.ui +++ b/src/librssguard/gui/notifications/singlenotificationeditor.ui @@ -7,7 +7,7 @@ 0 0 423 - 128 + 152 @@ -24,6 +24,13 @@ + + + + Show dialogs + + + @@ -121,6 +128,7 @@ m_cbBalloon + m_cbDialogs m_cbPlaySound m_txtSound m_btnBrowseSound diff --git a/src/librssguard/miscellaneous/application.cpp b/src/librssguard/miscellaneous/application.cpp index f63d74a57..5391bf06f 100644 --- a/src/librssguard/miscellaneous/application.cpp +++ b/src/librssguard/miscellaneous/application.cpp @@ -272,6 +272,7 @@ Application::Application(const QString& id, int& argc, char** argv, const QStrin m_notifications->save({Notification(Notification::Event::GeneralEvent, true), Notification(Notification::Event::NewUnreadArticlesFetched, true, + false, true, QSL("%1/notify.wav").arg(SOUNDS_BUILTIN_DIRECTORY)), Notification(Notification::Event::NewAppVersionAvailable, true), @@ -773,9 +774,13 @@ void Application::showGuiMessageCore(Notification::Event event, GuiMessageDestination dest, const GuiAction& action, QWidget* parent) { + bool show_dialog = true; + if (m_notifications->areNotificationsEnabled()) { auto notification = m_notifications->notificationForEvent(event); + show_dialog = notification.dialogEnabled(); + if (notification.soundEnabled()) { notification.playSound(this); } @@ -807,7 +812,7 @@ void Application::showGuiMessageCore(Notification::Event event, } } - if (dest.m_messageBox || msg.m_type == QSystemTrayIcon::MessageIcon::Critical) { + if (show_dialog && (dest.m_messageBox || msg.m_type == QSystemTrayIcon::MessageIcon::Critical)) { // Tray icon or OSD is not available, display simple text box. MsgBox::show(parent == nullptr ? mainFormWidget() : parent, QMessageBox::Icon(msg.m_type), diff --git a/src/librssguard/miscellaneous/notification.cpp b/src/librssguard/miscellaneous/notification.cpp index bb70f9fe1..b165a0514 100644 --- a/src/librssguard/miscellaneous/notification.cpp +++ b/src/librssguard/miscellaneous/notification.cpp @@ -17,10 +17,12 @@ Notification::Notification(Notification::Event event, bool balloon, + bool dialog, bool play_sound, const QString& sound_path, int volume) - : m_event(event), m_balloonEnabled(balloon), m_soundEnabled(play_sound), m_soundPath(sound_path), m_volume(volume) {} + : m_event(event), m_balloonEnabled(balloon), m_dialogEnabled(dialog), m_soundEnabled(play_sound), + m_soundPath(sound_path), m_volume(volume) {} Notification::Event Notification::event() const { return m_event; @@ -161,6 +163,10 @@ QString Notification::nameForEvent(Notification::Event event) { } } +bool Notification::dialogEnabled() const { + return m_dialogEnabled; +} + void Notification::setSoundEnabled(bool play_sound) { m_soundEnabled = play_sound; } diff --git a/src/librssguard/miscellaneous/notification.h b/src/librssguard/miscellaneous/notification.h index 75d165e53..ee909074d 100644 --- a/src/librssguard/miscellaneous/notification.h +++ b/src/librssguard/miscellaneous/notification.h @@ -47,12 +47,14 @@ class Notification { }; explicit Notification(Event event = Event::NoEvent, - bool balloon = {}, + bool balloon = false, + bool dialog = true, bool play_sound = true, const QString& sound_path = {}, int volume = DEFAULT_NOTIFICATION_VOLUME); bool balloonEnabled() const; + bool dialogEnabled() const; Event event() const; void setEvent(Event event); @@ -78,6 +80,7 @@ class Notification { private: Event m_event; bool m_balloonEnabled; + bool m_dialogEnabled; bool m_soundEnabled; QString m_soundPath; qreal m_volume; diff --git a/src/librssguard/miscellaneous/notificationfactory.cpp b/src/librssguard/miscellaneous/notificationfactory.cpp index 91a03d2dc..8dc5fa95f 100644 --- a/src/librssguard/miscellaneous/notificationfactory.cpp +++ b/src/librssguard/miscellaneous/notificationfactory.cpp @@ -50,12 +50,13 @@ void NotificationFactory::load(Settings* settings) { for (const auto& key : notif_keys) { auto event = Notification::Event(key.toInt()); auto data = settings->value(GROUP(Notifications), key).toStringList(); - auto enabled = data.at(0).toInt() != 0; + auto balloon = data.at(0).toInt() != 0; auto sound_path = data.at(1); auto volume = data.size() > 2 ? data.at(2).toInt() : DEFAULT_NOTIFICATION_VOLUME; auto play_sound = data.size() > 3 ? data.at(3).toInt() != 0 : true; + auto dialog = data.size() > 4 ? data.at(4).toInt() != 0 : false; - m_notifications.append(Notification(event, enabled, play_sound, sound_path, volume)); + m_notifications.append(Notification(event, balloon, dialog, play_sound, sound_path, volume)); } } @@ -69,6 +70,7 @@ void NotificationFactory::save(const QList& new_notifications, Set QStringList{n.balloonEnabled() ? QSL("1") : QSL("0"), n.soundPath(), QString::number(n.volume()), - n.soundEnabled() ? QSL("1") : QSL("0")}); + n.soundEnabled() ? QSL("1") : QSL("0"), + n.dialogEnabled() ? QSL("1") : QSL("0")}); } }