Skip to content
This repository has been archived by the owner on Feb 12, 2023. It is now read-only.

Commit

Permalink
feat(ui): add setting for disabling new message notification popup
Browse files Browse the repository at this point in the history
Fix #4979
  • Loading branch information
anthonybilinski committed Apr 8, 2018
1 parent 9f8b0fe commit fcd88d6
Show file tree
Hide file tree
Showing 6 changed files with 52 additions and 11 deletions.
17 changes: 17 additions & 0 deletions src/persistence/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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};
Expand Down
5 changes: 5 additions & 0 deletions src/persistence/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -166,6 +166,7 @@ public slots:
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);
Expand Down Expand Up @@ -315,6 +316,9 @@ public slots:
bool getCheckUpdates() const;
void setCheckUpdates(bool newValue);

bool getNotify() const;
void setNotify(bool newValue);

bool getShowWindow() const;
void setShowWindow(bool newValue);

Expand Down Expand Up @@ -580,6 +584,7 @@ public slots:
bool lightTrayIcon;
bool useEmoticons;
bool checkUpdates;
bool notify;
bool showWindow;
bool showInFront;
bool notifySound;
Expand Down
6 changes: 6 additions & 0 deletions src/widget/form/settings/userinterfaceform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -75,6 +75,7 @@ UserInterfaceForm::UserInterfaceForm(SettingsWidget* myParent)
int index = static_cast<int>(s.getStylePreference());
bodyUI->textStyleComboBox->setCurrentIndex(index);

bodyUI->notify->setChecked(s.getNotify());
bool showWindow = s.getShowWindow();

bodyUI->showWindow->setChecked(showWindow);
Expand Down Expand Up @@ -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();
Expand Down
1 change: 1 addition & 0 deletions src/widget/form/settings/userinterfaceform.h
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down
11 changes: 11 additions & 0 deletions src/widget/form/settings/userinterfacesettings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -161,6 +161,16 @@
<property name="topMargin">
<number>6</number>
</property>
<item>
<widget class="QCheckBox" name="notify">
<property name="toolTip">
<string comment="tooltip for Notify setting">Show a notification when you receive a new message and the window is not selected.</string>
</property>
<property name="text">
<string>Notify</string>
</property>
</widget>
</item>
<item>
<widget class="QCheckBox" name="showWindow">
<property name="toolTip">
Expand Down Expand Up @@ -572,6 +582,7 @@
<tabstop>txtChatFont</tabstop>
<tabstop>txtChatFontSize</tabstop>
<tabstop>textStyleComboBox</tabstop>
<tabstop>notify</tabstop>
<tabstop>showWindow</tabstop>
<tabstop>showInFront</tabstop>
<tabstop>groupAlwaysNotify</tabstop>
Expand Down
23 changes: 12 additions & 11 deletions src/widget/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -1421,25 +1421,26 @@ 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()) {
currentWindow->activateWindow();
}
}

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);
}
}
}

Expand Down

0 comments on commit fcd88d6

Please sign in to comment.