diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index 638e13a3e..96b071762 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -188,7 +188,7 @@ void Settings::loadGlobal() { showWindow = s.value("showWindow", true).toBool(); notify = s.value("notify", true).toBool(); - desktopNotify = s.value("desktopNotify", false).toBool(); + desktopNotify = s.value("desktopNotify", true).toBool(); groupAlwaysNotify = s.value("groupAlwaysNotify", true).toBool(); groupchatPosition = s.value("groupchatPosition", true).toBool(); separateWindow = s.value("separateWindow", false).toBool(); diff --git a/src/platform/desktop_notifications/desktopnotify.cpp b/src/platform/desktop_notifications/desktopnotify.cpp index 4f48c4056..3784f61b0 100644 --- a/src/platform/desktop_notifications/desktopnotify.cpp +++ b/src/platform/desktop_notifications/desktopnotify.cpp @@ -19,85 +19,37 @@ DesktopNotify::DesktopNotify() notifyCore.registerApplication(snoreApp); } -DesktopNotify::NotificationPtr DesktopNotify::createNotification(const QString& title, - const QString& text, - Snore::Notification* old) +void DesktopNotify::createNotification(const QString& title) { - if (old == nullptr) { - return NotificationPtr( - new Snore::Notification(snoreApp, Snore::Alert(), title, text, snoreIcon)); - } else { - return NotificationPtr(new Snore::Notification(*old, title, text, snoreIcon)); + const Settings& s = Settings::getInstance(); + if(!(s.getNotify() && s.getDesktopNotify())) { + return; } + + Snore::Notification notify{snoreApp, Snore::Alert(), title, {}, snoreIcon}; + notifyCore.broadcastNotification(notify); } void DesktopNotify::notifyGroupMessage() { - const Settings& s = Settings::getInstance(); - if(!(s.getNotify() && s.getDesktopNotify())) { - return; - } - - const QString text{}; const QString title = tr("New group message received"); - NotificationPtr newNote = createNotification(title, text); - if (!newNote) { - qDebug() << "Failed to allocate group message notification"; - return; - } - groupInvite = std::move(newNote); + createNotification(title); } void DesktopNotify::notifyFriendRequest() { - const Settings& s = Settings::getInstance(); - if(!(s.getNotify() && s.getDesktopNotify())) { - return; - } - const QString title = tr("New friend request received"); - const QString text{}; - NotificationPtr newNote = createNotification(title, text); - if (!newNote) { - qDebug() << "Failed to allocate friend message notification"; - return; - } - friendMessage = std::move(newNote); - notifyCore.broadcastNotification(*friendMessage); + createNotification(title); } void DesktopNotify::notifyGroupInvite() { - const Settings& s = Settings::getInstance(); - if(!(s.getNotify() && s.getDesktopNotify())) { - return; - } - const QString title = tr("New group invite received"); - const QString text{}; - NotificationPtr newNote = createNotification(title, text); - if (!newNote) { - qDebug() << "Failed to allocate friend message notification"; - return; - } - friendMessage = std::move(newNote); - notifyCore.broadcastNotification(*friendMessage); + createNotification(title); } void DesktopNotify::notifyFriendMessage() { - const Settings& s = Settings::getInstance(); - if(!(s.getNotify() && s.getDesktopNotify())) { - return; - } - const QString title = tr("New message received"); - const QString text{}; - NotificationPtr newNote = createNotification(title, text); - if (!newNote) { - qDebug() << "Failed to allocate friend message notification"; - return; - } - friendMessage = std::move(newNote); - notifyCore.broadcastNotification(*friendMessage); + createNotification(title); } diff --git a/src/platform/desktop_notifications/desktopnotify.h b/src/platform/desktop_notifications/desktopnotify.h index 81c0f08c9..4f2db7c45 100644 --- a/src/platform/desktop_notifications/desktopnotify.h +++ b/src/platform/desktop_notifications/desktopnotify.h @@ -19,17 +19,10 @@ public slots: void notifyGroupInvite(); private: - using NotificationPtr = std::unique_ptr; - - NotificationPtr createNotification(const QString& title, const QString& text, - Snore::Notification* old = nullptr); + void createNotification(const QString& title); private: Snore::SnoreCore& notifyCore; - NotificationPtr groupInvite = {nullptr}; - NotificationPtr groupMessage = {nullptr}; - NotificationPtr friendRequest = {nullptr}; - NotificationPtr friendMessage = {nullptr}; Snore::Application snoreApp; Snore::Icon snoreIcon; }; diff --git a/src/widget/form/settings/userinterfaceform.cpp b/src/widget/form/settings/userinterfaceform.cpp index a4d08ff7c..ee9d0860e 100644 --- a/src/widget/form/settings/userinterfaceform.cpp +++ b/src/widget/form/settings/userinterfaceform.cpp @@ -275,6 +275,7 @@ void UserInterfaceForm::on_notify_stateChanged() bodyUI->groupOnlyNotfiyWhenMentioned->setEnabled(notify); bodyUI->notifySound->setEnabled(notify); bodyUI->busySound->setEnabled(notify && bodyUI->notifySound->isChecked()); + bodyUI->desktopNotify->setEnabled(notify); } void UserInterfaceForm::on_notifySound_stateChanged() diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 308ea6639..89c7ee923 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -1446,7 +1446,13 @@ bool Widget::newMessageAlert(QWidget* currentWindow, bool isActive, bool sound, if (settings.getNotify()) { if (inactiveWindow) { +#if DESKTOP_NOTIFICATIONS + if (!settings.getDesktopNotify()) { + QApplication::alert(currentWindow); + } +#else QApplication::alert(currentWindow); +#endif eventFlag = true; } bool isBusy = Nexus::getCore()->getStatus() == Status::Busy;