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

Commit

Permalink
feat(notify): integrate desktop notifications into settings
Browse files Browse the repository at this point in the history
  • Loading branch information
sudden6 committed Mar 24, 2019
1 parent 7189b46 commit 4cb0095
Show file tree
Hide file tree
Showing 6 changed files with 65 additions and 0 deletions.
18 changes: 18 additions & 0 deletions src/persistence/settings.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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();
Expand Down Expand Up @@ -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);
Expand Down Expand Up @@ -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};
Expand Down
5 changes: 5 additions & 0 deletions src/persistence/settings.h
Original file line number Diff line number Diff line change
Expand Up @@ -171,6 +171,7 @@ public slots:
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);
Expand Down Expand Up @@ -324,6 +325,9 @@ public slots:
bool getShowWindow() const;
void setShowWindow(bool newValue);

bool getDesktopNotify() const;
void setDesktopNotify(bool enabled);

bool getNotifySound() const;
void setNotifySound(bool newValue);

Expand Down Expand Up @@ -603,6 +607,7 @@ public slots:
bool useEmoticons;
bool checkUpdates;
bool notify;
bool desktopNotify;
bool showWindow;
bool notifySound;
bool busySound;
Expand Down
22 changes: 22 additions & 0 deletions src/platform/desktop_notifications/desktopnotify.cpp
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
#include "desktopnotify.h"

#include <src/persistence/settings.h>

#include <libsnore/snore.h>

#include <QDebug>
Expand Down Expand Up @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand All @@ -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);
Expand Down
12 changes: 12 additions & 0 deletions src/widget/form/settings/userinterfaceform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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());

Expand Down Expand Up @@ -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());
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 @@ -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();
Expand Down
7 changes: 7 additions & 0 deletions src/widget/form/settings/userinterfacesettings.ui
Original file line number Diff line number Diff line change
Expand Up @@ -214,6 +214,13 @@
</item>
</layout>
</item>
<item>
<widget class="QCheckBox" name="desktopNotify">
<property name="text">
<string>Notify via desktop notifications</string>
</property>
</widget>
</item>
</layout>
</item>
<item>
Expand Down

0 comments on commit 4cb0095

Please sign in to comment.