From 3b305dd05a8210928a2bed7026b7f4fa7d9003bf Mon Sep 17 00:00:00 2001 From: Monsterovich Date: Thu, 23 May 2019 00:44:26 +0200 Subject: [PATCH] fix(ui): Added option to hide message sender and contents --- src/persistence/settings.cpp | 18 ++++++++ src/persistence/settings.h | 5 +++ .../desktop_notifications/desktopnotify.cpp | 14 +++++++ .../desktop_notifications/desktopnotify.h | 9 ++++ .../form/settings/userinterfaceform.cpp | 6 +++ src/widget/form/settings/userinterfaceform.h | 2 +- .../form/settings/userinterfacesettings.ui | 9 +++- src/widget/widget.cpp | 42 ++++++++++++++----- 8 files changed, 92 insertions(+), 13 deletions(-) diff --git a/src/persistence/settings.cpp b/src/persistence/settings.cpp index c3dba19b5..c25053147 100644 --- a/src/persistence/settings.cpp +++ b/src/persistence/settings.cpp @@ -154,6 +154,7 @@ void Settings::loadGlobal() autoAwayTime = s.value("autoAwayTime", 10).toInt(); checkUpdates = s.value("checkUpdates", true).toBool(); notifySound = s.value("notifySound", true).toBool(); // note: notifySound and busySound UI elements are now under UI settings + notifyHide = s.value("notifyHide", false).toBool(); busySound = s.value("busySound", false).toBool(); // page, but kept under General in settings file to be backwards compatible fauxOfflineMessaging = s.value("fauxOfflineMessaging", true).toBool(); autoSaveEnabled = s.value("autoSaveEnabled", false).toBool(); @@ -435,6 +436,7 @@ void Settings::saveGlobal() s.setValue("autoAwayTime", autoAwayTime); s.setValue("checkUpdates", checkUpdates); s.setValue("notifySound", notifySound); + s.setValue("notifyHide", notifyHide); s.setValue("busySound", busySound); s.setValue("fauxOfflineMessaging", fauxOfflineMessaging); s.setValue("autoSaveEnabled", autoSaveEnabled); @@ -1005,6 +1007,22 @@ void Settings::setNotifySound(bool newValue) } } +bool Settings::getNotifyHide() const +{ + QMutexLocker locker{&bigLock}; + return notifyHide; +} + +void Settings::setNotifyHide(bool newValue) +{ + QMutexLocker locker{&bigLock}; + + if (newValue != notifyHide) { + notifyHide = newValue; + emit notifyHideChanged(notifyHide); + } +} + bool Settings::getBusySound() const { QMutexLocker locker{&bigLock}; diff --git a/src/persistence/settings.h b/src/persistence/settings.h index 0d0ad0005..45d10614d 100644 --- a/src/persistence/settings.h +++ b/src/persistence/settings.h @@ -181,6 +181,7 @@ signals: void makeToxPortableChanged(bool enabled); void busySoundChanged(bool enabled); void notifySoundChanged(bool enabled); + void notifyHideChanged(bool enabled); void groupAlwaysNotifyChanged(bool enabled); void translationChanged(const QString& translation); void toxmeInfoChanged(const QString& info); @@ -337,6 +338,9 @@ public: bool getNotifySound() const; void setNotifySound(bool newValue); + bool getNotifyHide() const; + void setNotifyHide(bool newValue); + bool getBusySound() const; void setBusySound(bool newValue); @@ -620,6 +624,7 @@ private: bool desktopNotify; bool showWindow; bool notifySound; + bool notifyHide; bool busySound; bool groupAlwaysNotify; bool nameColors; diff --git a/src/platform/desktop_notifications/desktopnotify.cpp b/src/platform/desktop_notifications/desktopnotify.cpp index 74f945f17..7754fe705 100644 --- a/src/platform/desktop_notifications/desktopnotify.cpp +++ b/src/platform/desktop_notifications/desktopnotify.cpp @@ -42,3 +42,17 @@ void DesktopNotify::notifyMessagePixmap(const QString title, const QString messa createNotification(title, message, new_icon); } +void DesktopNotify::notifyMessageSimple(const MessageType type) +{ + QString message; + switch (type) { + case MSG_FRIEND: message = tr("New message"); break; + case MSG_FRIEND_FILE: message = tr("Incoming file transfer"); break; + case MSG_FRIEND_REQUEST: message = tr("Friend request received"); break; + case MSG_GROUP: message = tr("New group message"); break; + case MSG_GROUP_INVITE: message = tr("Group invite"); break; + default: break; + } + + createNotification(message, {}, snoreIcon); +} diff --git a/src/platform/desktop_notifications/desktopnotify.h b/src/platform/desktop_notifications/desktopnotify.h index 85a4a6f72..94aba3fa9 100644 --- a/src/platform/desktop_notifications/desktopnotify.h +++ b/src/platform/desktop_notifications/desktopnotify.h @@ -12,9 +12,18 @@ class DesktopNotify : public QObject public: DesktopNotify(); + enum MessageType { + MSG_FRIEND = 0, + MSG_FRIEND_FILE, + MSG_FRIEND_REQUEST, + MSG_GROUP, + MSG_GROUP_INVITE + }; + public slots: void notifyMessage(const QString title, const QString message); void notifyMessagePixmap(const QString title, const QString message, QPixmap avatar); + void notifyMessageSimple(const MessageType type); private: void createNotification(const QString& title, const QString &text, Snore::Icon &icon); diff --git a/src/widget/form/settings/userinterfaceform.cpp b/src/widget/form/settings/userinterfaceform.cpp index ee9d0860e..5166ca552 100644 --- a/src/widget/form/settings/userinterfaceform.cpp +++ b/src/widget/form/settings/userinterfaceform.cpp @@ -391,3 +391,9 @@ void UserInterfaceForm::on_useNameColors_stateChanged(int value) { Settings::getInstance().setEnableGroupChatsColor(value); } + +void UserInterfaceForm::on_notifyHide_stateChanged(int value) +{ + Settings::getInstance().setNotifyHide(value); +} + diff --git a/src/widget/form/settings/userinterfaceform.h b/src/widget/form/settings/userinterfaceform.h index e51894f6a..2ed432f31 100644 --- a/src/widget/form/settings/userinterfaceform.h +++ b/src/widget/form/settings/userinterfaceform.h @@ -51,6 +51,7 @@ private slots: void on_notify_stateChanged(); void on_desktopNotify_stateChanged(); void on_notifySound_stateChanged(); + void on_notifyHide_stateChanged(int); void on_busySound_stateChanged(); void on_showWindow_stateChanged(); void on_groupOnlyNotfiyWhenMentioned_stateChanged(); @@ -60,7 +61,6 @@ private slots: void on_cbGroupchatPosition_stateChanged(); void on_themeColorCBox_currentIndexChanged(int); void on_cbShowIdenticons_stateChanged(); - void on_txtChatFont_currentFontChanged(const QFont& f); void on_txtChatFontSize_valueChanged(int arg1); void on_useNameColors_stateChanged(int value); diff --git a/src/widget/form/settings/userinterfacesettings.ui b/src/widget/form/settings/userinterfacesettings.ui index cf0ac58b5..1f664468d 100644 --- a/src/widget/form/settings/userinterfacesettings.ui +++ b/src/widget/form/settings/userinterfacesettings.ui @@ -40,7 +40,7 @@ 0 0 650 - 892 + 950 @@ -221,6 +221,13 @@ + + + + Hide message sender and contents + + + diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 52ebe4be8..3d71c62a8 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -1381,11 +1381,16 @@ bool Widget::newFriendMessageAlert(const ToxPk& friendId, const QString text, bo widget->updateStatusLight(); ui->friendList->trackWidget(widget); #if DESKTOP_NOTIFICATIONS - QString title = f->getDisplayedName(); - if (file) { - title += " - " + tr("File sent"); + const Settings& s = Settings::getInstance(); + if (s.getNotifyHide()) { + notifier.notifyMessageSimple(file ? DesktopNotify::MSG_FRIEND_FILE : DesktopNotify::MSG_FRIEND); + } else { + QString title = f->getDisplayedName(); + if (file) { + title += " - " + tr("File sent"); + } + notifier.notifyMessagePixmap(title, text, Nexus::getProfile()->loadAvatar(f->getPublicKey())); } - notifier.notifyMessagePixmap(title, text, Nexus::getProfile()->loadAvatar(f->getPublicKey())); #endif if (contentDialog == nullptr) { @@ -1425,12 +1430,17 @@ bool Widget::newGroupMessageAlert(const GroupId& groupId, const ToxPk authorPk, g->setEventFlag(true); widget->updateStatusLight(); #if DESKTOP_NOTIFICATIONS - Friend *f = FriendList::findFriend(authorPk); - QString title = g->getPeerList().value(authorPk) + " (" + g->getDisplayedName() + ")"; - if (!f) { - notifier.notifyMessage(title, message); + const Settings& s = Settings::getInstance(); + if (s.getNotifyHide()) { + notifier.notifyMessageSimple(DesktopNotify::MSG_GROUP); } else { - notifier.notifyMessagePixmap(title, message, Nexus::getProfile()->loadAvatar(f->getPublicKey())); + Friend *f = FriendList::findFriend(authorPk); + QString title = g->getPeerList().value(authorPk) + " (" + g->getDisplayedName() + ")"; + if (!f) { + notifier.notifyMessage(title, message); + } else { + notifier.notifyMessagePixmap(title, message, Nexus::getProfile()->loadAvatar(f->getPublicKey())); + } } #endif @@ -1507,7 +1517,12 @@ void Widget::onFriendRequestReceived(const ToxPk& friendPk, const QString& messa friendRequestsUpdate(); newMessageAlert(window(), isActiveWindow(), true, true); #if DESKTOP_NOTIFICATIONS - notifier.notifyMessage(friendPk.toString() + tr(" sent you a friend request."), message); + const Settings& s = Settings::getInstance(); + if (s.getNotifyHide()) { + notifier.notifyMessageSimple(DesktopNotify::MSG_FRIEND_REQUEST); + } else { + notifier.notifyMessage(friendPk.toString() + tr(" sent you a friend request."), message); + } #endif } } @@ -1746,7 +1761,12 @@ void Widget::onGroupInviteReceived(const GroupInvite& inviteInfo) groupInvitesUpdate(); newMessageAlert(window(), isActiveWindow(), true, true); #if DESKTOP_NOTIFICATIONS - notifier.notifyMessagePixmap(f->getDisplayedName() + tr(" invites you to join a group."), {}, Nexus::getProfile()->loadAvatar(f->getPublicKey())); + const Settings& s = Settings::getInstance(); + if (s.getNotifyHide()) { + notifier.notifyMessageSimple(DesktopNotify::MSG_GROUP_INVITE); + } else { + notifier.notifyMessagePixmap(f->getDisplayedName() + tr(" invites you to join a group."), {}, Nexus::getProfile()->loadAvatar(f->getPublicKey())); + } #endif } } else {