diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index 5184894b0..638e13a3e 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -188,6 +188,7 @@ void Settings::loadGlobal() { showWindow = s.value("showWindow", true).toBool(); notify = s.value("notify", true).toBool(); + desktopNotify = s.value("desktopNotify", false).toBool(); groupAlwaysNotify = s.value("groupAlwaysNotify", true).toBool(); groupchatPosition = s.value("groupchatPosition", true).toBool(); separateWindow = s.value("separateWindow", false).toBool(); @@ -474,6 +475,7 @@ void Settings::saveGlobal() { s.setValue("showWindow", showWindow); s.setValue("notify", notify); + s.setValue("desktopNotify", desktopNotify); s.setValue("groupAlwaysNotify", groupAlwaysNotify); s.setValue("separateWindow", separateWindow); s.setValue("dontGroupWindows", dontGroupWindows); @@ -1632,6 +1634,22 @@ void Settings::setShowWindow(bool newValue) } } +bool Settings::getDesktopNotify() const +{ + QMutexLocker locker{&bigLock}; + return desktopNotify; +} + +void Settings::setDesktopNotify(bool enabled) +{ + QMutexLocker locker{&bigLock}; + + if (enabled != desktopNotify) { + desktopNotify = enabled; + emit desktopNotifyChanged(desktopNotify); + } +} + QByteArray Settings::getSplitterState() const { QMutexLocker locker{&bigLock}; diff --git a/src/persistence/settings.h b/src/persistence/settings.h index 33241210a..c0432b3a4 100644 --- a/src/persistence/settings.h +++ b/src/persistence/settings.h @@ -171,6 +171,7 @@ signals: void lightTrayIconChanged(bool enabled); void minimizeToTrayChanged(bool enabled); void notifyChanged(bool enabled); + void desktopNotifyChanged(bool enabled); void showWindowChanged(bool enabled); void makeToxPortableChanged(bool enabled); void busySoundChanged(bool enabled); @@ -324,6 +325,9 @@ public: bool getShowWindow() const; void setShowWindow(bool newValue); + bool getDesktopNotify() const; + void setDesktopNotify(bool enabled); + bool getNotifySound() const; void setNotifySound(bool newValue); @@ -603,6 +607,7 @@ private: bool useEmoticons; bool checkUpdates; bool notify; + bool desktopNotify; bool showWindow; bool notifySound; bool busySound; diff --git a/src/platform/desktop_notifications/desktopnotify.cpp b/src/platform/desktop_notifications/desktopnotify.cpp index 97015c792..4f48c4056 100644 --- a/src/platform/desktop_notifications/desktopnotify.cpp +++ b/src/platform/desktop_notifications/desktopnotify.cpp @@ -1,5 +1,7 @@ #include "desktopnotify.h" +#include + #include #include @@ -31,6 +33,11 @@ DesktopNotify::NotificationPtr DesktopNotify::createNotification(const QString& 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); @@ -43,6 +50,11 @@ void DesktopNotify::notifyGroupMessage() 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); @@ -56,6 +68,11 @@ void DesktopNotify::notifyFriendRequest() 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); @@ -69,6 +86,11 @@ void DesktopNotify::notifyGroupInvite() 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); diff --git a/src/widget/form/settings/userinterfaceform.cpp b/src/widget/form/settings/userinterfaceform.cpp index 90b576f18..a4d08ff7c 100644 --- a/src/widget/form/settings/userinterfaceform.cpp +++ b/src/widget/form/settings/userinterfaceform.cpp @@ -81,6 +81,12 @@ UserInterfaceForm::UserInterfaceForm(SettingsWidget* myParent) bodyUI->notifySound->setEnabled(s.getNotify()); bodyUI->busySound->setChecked(s.getBusySound()); bodyUI->busySound->setEnabled(s.getNotifySound() && s.getNotify()); +#if DESKTOP_NOTIFICATIONS + bodyUI->desktopNotify->setChecked(s.getDesktopNotify()); + bodyUI->desktopNotify->setEnabled(s.getNotify()); +#else + bodyUI->desktopNotify->hide(); +#endif bodyUI->showWindow->setChecked(s.getShowWindow()); @@ -278,6 +284,12 @@ void UserInterfaceForm::on_notifySound_stateChanged() bodyUI->busySound->setEnabled(notify); } +void UserInterfaceForm::on_desktopNotify_stateChanged() +{ + const bool notify = bodyUI->desktopNotify->isChecked(); + Settings::getInstance().setDesktopNotify(notify); +} + void UserInterfaceForm::on_busySound_stateChanged() { Settings::getInstance().setBusySound(bodyUI->busySound->isChecked()); diff --git a/src/widget/form/settings/userinterfaceform.h b/src/widget/form/settings/userinterfaceform.h index 63d1c5676..e51894f6a 100644 --- a/src/widget/form/settings/userinterfaceform.h +++ b/src/widget/form/settings/userinterfaceform.h @@ -49,6 +49,7 @@ private slots: void on_textStyleComboBox_currentTextChanged(); void on_useEmoticons_stateChanged(); void on_notify_stateChanged(); + void on_desktopNotify_stateChanged(); void on_notifySound_stateChanged(); void on_busySound_stateChanged(); void on_showWindow_stateChanged(); diff --git a/src/widget/form/settings/userinterfacesettings.ui b/src/widget/form/settings/userinterfacesettings.ui index 48d98d94e..cf0ac58b5 100644 --- a/src/widget/form/settings/userinterfacesettings.ui +++ b/src/widget/form/settings/userinterfacesettings.ui @@ -214,6 +214,13 @@ + + + + Notify via desktop notifications + + +