From fcd88d65b2875c06312374186fd9a08a9637dac7 Mon Sep 17 00:00:00 2001 From: Anthony Bilinski Date: Tue, 3 Apr 2018 15:08:38 -0700 Subject: [PATCH] feat(ui): add setting for disabling new message notification popup Fix #4979 --- src/persistence/settings.cpp | 17 ++++++++++++++ src/persistence/settings.h | 5 ++++ .../form/settings/userinterfaceform.cpp | 6 +++++ src/widget/form/settings/userinterfaceform.h | 1 + .../form/settings/userinterfacesettings.ui | 11 +++++++++ src/widget/widget.cpp | 23 ++++++++++--------- 6 files changed, 52 insertions(+), 11 deletions(-) diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index 7ba3d276f..201203126 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -208,6 +208,7 @@ void Settings::loadGlobal() { showWindow = s.value("showWindow", true).toBool(); showInFront = s.value("showInFront", true).toBool(); + notify = s.value("notify", true).toBool(); groupAlwaysNotify = s.value("groupAlwaysNotify", true).toBool(); groupchatPosition = s.value("groupchatPosition", true).toBool(); separateWindow = s.value("separateWindow", false).toBool(); @@ -526,6 +527,7 @@ void Settings::saveGlobal() { s.setValue("showWindow", showWindow); s.setValue("showInFront", showInFront); + s.setValue("notify", notify); s.setValue("groupAlwaysNotify", groupAlwaysNotify); s.setValue("separateWindow", separateWindow); s.setValue("dontGroupWindows", dontGroupWindows); @@ -1668,6 +1670,21 @@ void Settings::setCheckUpdates(bool newValue) } } +bool Settings::getNotify() const +{ + QMutexLocker locker{&bigLock}; + return notify; +} + +void Settings::setNotify(bool newValue) +{ + QMutexLocker locker{&bigLock}; + if (newValue != notify) { + notify = newValue; + emit notifyChanged(notify); + } +} + bool Settings::getShowWindow() const { QMutexLocker locker{&bigLock}; diff --git a/src/persistence/settings.h b/src/persistence/settings.h index 542ca0f0a..14cdc6143 100644 --- a/src/persistence/settings.h +++ b/src/persistence/settings.h @@ -166,6 +166,7 @@ signals: void closeToTrayChanged(bool enabled); void lightTrayIconChanged(bool enabled); void minimizeToTrayChanged(bool enabled); + void notifyChanged(bool enabled); void showWindowChanged(bool enabled); void makeToxPortableChanged(bool enabled); void busySoundChanged(bool enabled); @@ -315,6 +316,9 @@ public: bool getCheckUpdates() const; void setCheckUpdates(bool newValue); + bool getNotify() const; + void setNotify(bool newValue); + bool getShowWindow() const; void setShowWindow(bool newValue); @@ -580,6 +584,7 @@ private: bool lightTrayIcon; bool useEmoticons; bool checkUpdates; + bool notify; bool showWindow; bool showInFront; bool notifySound; diff --git a/src/widget/form/settings/userinterfaceform.cpp b/src/widget/form/settings/userinterfaceform.cpp index 6bf18466a..d2f8628d0 100644 --- a/src/widget/form/settings/userinterfaceform.cpp +++ b/src/widget/form/settings/userinterfaceform.cpp @@ -75,6 +75,7 @@ UserInterfaceForm::UserInterfaceForm(SettingsWidget* myParent) int index = static_cast(s.getStylePreference()); bodyUI->textStyleComboBox->setCurrentIndex(index); + bodyUI->notify->setChecked(s.getNotify()); bool showWindow = s.getShowWindow(); bodyUI->showWindow->setChecked(showWindow); @@ -260,6 +261,11 @@ void UserInterfaceForm::reloadSmileys() bodyUI->emoticonSize->setMaximum(actualSize.width()); } +void UserInterfaceForm::on_notify_stateChanged() +{ + Settings::getInstance().setNotify(bodyUI->notify->isChecked()); +} + void UserInterfaceForm::on_showWindow_stateChanged() { bool isChecked = bodyUI->showWindow->isChecked(); diff --git a/src/widget/form/settings/userinterfaceform.h b/src/widget/form/settings/userinterfaceform.h index 7c58229b2..ad55be455 100644 --- a/src/widget/form/settings/userinterfaceform.h +++ b/src/widget/form/settings/userinterfaceform.h @@ -48,6 +48,7 @@ private slots: void on_dateFormats_editTextChanged(const QString& format); void on_textStyleComboBox_currentTextChanged(); void on_useEmoticons_stateChanged(); + void on_notify_stateChanged(); void on_showWindow_stateChanged(); void on_showInFront_stateChanged(); void on_groupAlwaysNotify_stateChanged(); diff --git a/src/widget/form/settings/userinterfacesettings.ui b/src/widget/form/settings/userinterfacesettings.ui index ff45d291e..6fe062e2c 100644 --- a/src/widget/form/settings/userinterfacesettings.ui +++ b/src/widget/form/settings/userinterfacesettings.ui @@ -161,6 +161,16 @@ 6 + + + + Show a notification when you receive a new message and the window is not selected. + + + Notify + + + @@ -572,6 +582,7 @@ txtChatFont txtChatFontSize textStyleComboBox + notify showWindow showInFront groupAlwaysNotify diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 10951090e..3df9b81c1 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -1421,11 +1421,6 @@ bool Widget::newMessageAlert(QWidget* currentWindow, bool isActive, bool sound, } if (notify) { - if (inactiveWindow) { - QApplication::alert(currentWindow); - eventFlag = true; - } - if (Settings::getInstance().getShowWindow()) { currentWindow->show(); if (inactiveWindow && Settings::getInstance().getShowInFront()) { @@ -1433,13 +1428,19 @@ bool Widget::newMessageAlert(QWidget* currentWindow, bool isActive, bool sound, } } - bool isBusy = Nexus::getCore()->getStatus() == Status::Busy; - bool busySound = Settings::getInstance().getBusySound(); - bool notifySound = Settings::getInstance().getNotifySound(); + if (Settings::getInstance().getNotify()) { + if (inactiveWindow) { + QApplication::alert(currentWindow); + eventFlag = true; + } + bool isBusy = Nexus::getCore()->getStatus() == Status::Busy; + bool busySound = Settings::getInstance().getBusySound(); + bool notifySound = Settings::getInstance().getNotifySound(); - if (notifySound && sound && (!isBusy || busySound)) { - QString soundPath = Audio::getSound(Audio::Sound::NewMessage); - Audio::getInstance().playMono16Sound(soundPath); + if (notifySound && sound && (!isBusy || busySound)) { + QString soundPath = Audio::getSound(Audio::Sound::NewMessage); + Audio::getInstance().playMono16Sound(soundPath); + } } }