From 1bbe210c254a8ebbc6f529def5632ac47a941077 Mon Sep 17 00:00:00 2001 From: Monsterovich Date: Wed, 22 May 2019 19:48:23 +0200 Subject: [PATCH 1/8] fix(ui): Improved notifications --- CMakeLists.txt | 2 +- src/chatlog/content/filetransferwidget.h | 2 +- .../desktop_notifications/desktopnotify.cpp | 27 ++++++------------ .../desktop_notifications/desktopnotify.h | 8 ++---- src/widget/form/chatform.cpp | 5 +++- src/widget/widget.cpp | 28 +++++++++++++------ src/widget/widget.h | 4 +-- 7 files changed, 38 insertions(+), 38 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 774c89cea..7073e9b6f 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ option(USE_CCACHE "Use ccache when available" ON) option(SPELL_CHECK "Enable spell cheching support" ON) option(SVGZ_ICON "Compress the SVG icon of qTox" ON) option(ASAN "Compile with AddressSanitizer" OFF) -option(DESKTOP_NOTIFICATIONS "Use snorenotify for desktop notifications" OFF) +option(DESKTOP_NOTIFICATIONS "Use snorenotify for desktop notifications" ON) # process generated files if cmake >= 3.10 if(POLICY CMP0071) diff --git a/src/chatlog/content/filetransferwidget.h b/src/chatlog/content/filetransferwidget.h index fff5ea6ba..717548252 100644 --- a/src/chatlog/content/filetransferwidget.h +++ b/src/chatlog/content/filetransferwidget.h @@ -44,6 +44,7 @@ public: virtual ~FileTransferWidget(); void autoAcceptTransfer(const QString& path); bool isActive() const; + static QString getHumanReadableSize(qint64 size); protected slots: void onFileTransferInfo(ToxFile file); @@ -56,7 +57,6 @@ protected slots: void fileTransferBrokenUnbroken(ToxFile file, bool broken); protected: - QString getHumanReadableSize(qint64 size); void updateWidgetColor(ToxFile const& file); void updateWidgetText(ToxFile const& file); void updateFileProgress(ToxFile const& file); diff --git a/src/platform/desktop_notifications/desktopnotify.cpp b/src/platform/desktop_notifications/desktopnotify.cpp index 3784f61b0..74f945f17 100644 --- a/src/platform/desktop_notifications/desktopnotify.cpp +++ b/src/platform/desktop_notifications/desktopnotify.cpp @@ -19,37 +19,26 @@ DesktopNotify::DesktopNotify() notifyCore.registerApplication(snoreApp); } -void DesktopNotify::createNotification(const QString& title) +void DesktopNotify::createNotification(const QString& title, const QString &text, Snore::Icon &icon) { const Settings& s = Settings::getInstance(); if(!(s.getNotify() && s.getDesktopNotify())) { return; } - Snore::Notification notify{snoreApp, Snore::Alert(), title, {}, snoreIcon}; + Snore::Notification notify{snoreApp, Snore::Alert(), title, text, icon}; + notifyCore.broadcastNotification(notify); } -void DesktopNotify::notifyGroupMessage() +void DesktopNotify::notifyMessage(const QString title, const QString message) { - const QString title = tr("New group message received"); - createNotification(title); + createNotification(title, message, snoreIcon); } -void DesktopNotify::notifyFriendRequest() +void DesktopNotify::notifyMessagePixmap(const QString title, const QString message, QPixmap avatar) { - const QString title = tr("New friend request received"); - createNotification(title); + Snore::Icon new_icon(avatar); + createNotification(title, message, new_icon); } -void DesktopNotify::notifyGroupInvite() -{ - const QString title = tr("New group invite received"); - createNotification(title); -} - -void DesktopNotify::notifyFriendMessage() -{ - const QString title = tr("New message received"); - createNotification(title); -} diff --git a/src/platform/desktop_notifications/desktopnotify.h b/src/platform/desktop_notifications/desktopnotify.h index 4f2db7c45..85a4a6f72 100644 --- a/src/platform/desktop_notifications/desktopnotify.h +++ b/src/platform/desktop_notifications/desktopnotify.h @@ -13,13 +13,11 @@ public: DesktopNotify(); public slots: - void notifyFriendMessage(); - void notifyGroupMessage(); - void notifyFriendRequest(); - void notifyGroupInvite(); + void notifyMessage(const QString title, const QString message); + void notifyMessagePixmap(const QString title, const QString message, QPixmap avatar); private: - void createNotification(const QString& title); + void createNotification(const QString& title, const QString &text, Snore::Icon &icon); private: Snore::SnoreCore& notifyCore; diff --git a/src/widget/form/chatform.cpp b/src/widget/form/chatform.cpp index f2e296c3a..ef6b94ebc 100644 --- a/src/widget/form/chatform.cpp +++ b/src/widget/form/chatform.cpp @@ -338,7 +338,10 @@ void ChatForm::onFileRecvRequest(ToxFile file) return; } - Widget::getInstance()->newFriendMessageAlert(f->getPublicKey()); + Widget::getInstance()->newFriendMessageAlert(f->getPublicKey(), + file.fileName + + " (" + FileTransferWidget::getHumanReadableSize(file.filesize) + ")", + true, true); QString name; ToxPk friendId = f->getPublicKey(); if (friendId != previousId) { diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 7c1a3ef1f..52ebe4be8 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -964,7 +964,7 @@ void Widget::cleanupNotificationSound() void Widget::incomingNotification(uint32_t friendnumber) { const auto& friendId = FriendList::id2Key(friendnumber); - newFriendMessageAlert(friendId, false); + newFriendMessageAlert(friendId, {}, false); // loop until call answered or rejected playNotificationSound(IAudioSink::Sound::IncomingCall, true); @@ -1238,7 +1238,7 @@ void Widget::onFriendMessageReceived(uint32_t friendnumber, const QString& messa profile->getHistory()->addNewMessage(publicKey, text, publicKey, timestamp, true, name); } - newFriendMessageAlert(friendId); + newFriendMessageAlert(friendId, message); } void Widget::addFriendDialog(const Friend* frnd, ContentDialog* dialog) @@ -1344,7 +1344,7 @@ void Widget::addGroupDialog(Group* group, ContentDialog* dialog) emit widget->chatroomWidgetClicked(widget); } -bool Widget::newFriendMessageAlert(const ToxPk& friendId, bool sound) +bool Widget::newFriendMessageAlert(const ToxPk& friendId, const QString text, bool sound, bool file) { bool hasActive; QWidget* currentWindow; @@ -1381,7 +1381,11 @@ bool Widget::newFriendMessageAlert(const ToxPk& friendId, bool sound) widget->updateStatusLight(); ui->friendList->trackWidget(widget); #if DESKTOP_NOTIFICATIONS - notifier.notifyFriendMessage(); + QString title = f->getDisplayedName(); + if (file) { + title += " - " + tr("File sent"); + } + notifier.notifyMessagePixmap(title, text, Nexus::getProfile()->loadAvatar(f->getPublicKey())); #endif if (contentDialog == nullptr) { @@ -1398,7 +1402,7 @@ bool Widget::newFriendMessageAlert(const ToxPk& friendId, bool sound) return false; } -bool Widget::newGroupMessageAlert(const GroupId& groupId, bool notify) +bool Widget::newGroupMessageAlert(const GroupId& groupId, const ToxPk authorPk, const QString message, bool notify) { bool hasActive; QWidget* currentWindow; @@ -1421,7 +1425,13 @@ bool Widget::newGroupMessageAlert(const GroupId& groupId, bool notify) g->setEventFlag(true); widget->updateStatusLight(); #if DESKTOP_NOTIFICATIONS - notifier.notifyGroupMessage(); + 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 if (contentDialog == nullptr) { @@ -1497,7 +1507,7 @@ void Widget::onFriendRequestReceived(const ToxPk& friendPk, const QString& messa friendRequestsUpdate(); newMessageAlert(window(), isActiveWindow(), true, true); #if DESKTOP_NOTIFICATIONS - notifier.notifyFriendRequest(); + notifier.notifyMessage(friendPk.toString() + tr(" sent you a friend request."), message); #endif } } @@ -1736,7 +1746,7 @@ void Widget::onGroupInviteReceived(const GroupInvite& inviteInfo) groupInvitesUpdate(); newMessageAlert(window(), isActiveWindow(), true, true); #if DESKTOP_NOTIFICATIONS - notifier.notifyGroupInvite(); + notifier.notifyMessagePixmap(f->getDisplayedName() + tr(" invites you to join a group."), {}, Nexus::getProfile()->loadAvatar(f->getPublicKey())); #endif } } else { @@ -1781,7 +1791,7 @@ void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QStri form->addMessage(author, message, date, isAction, true); } - newGroupMessageAlert(groupId, targeted || settings.getGroupAlwaysNotify()); + newGroupMessageAlert(groupId, author, message, targeted || settings.getGroupAlwaysNotify()); } void Widget::onGroupPeerlistChanged(uint32_t groupnumber) diff --git a/src/widget/widget.h b/src/widget/widget.h index 1a6a4ef8f..7ad206cff 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -123,8 +123,8 @@ public: void showUpdateDownloadProgress(); void addFriendDialog(const Friend* frnd, ContentDialog* dialog); void addGroupDialog(Group* group, ContentDialog* dialog); - bool newFriendMessageAlert(const ToxPk& friendId, bool sound = true); - bool newGroupMessageAlert(const GroupId& groupId, bool notify); + bool newFriendMessageAlert(const ToxPk& friendId, const QString text, bool sound = true, bool file = false); + bool newGroupMessageAlert(const GroupId& groupId, const ToxPk authorPk, const QString message, bool notify); bool getIsWindowMinimized(); void updateIcons(); From 3b305dd05a8210928a2bed7026b7f4fa7d9003bf Mon Sep 17 00:00:00 2001 From: Monsterovich Date: Thu, 23 May 2019 00:44:26 +0200 Subject: [PATCH 2/8] 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 { From 4a6ebff63a78650279856fcf3e1737d54e2523a0 Mon Sep 17 00:00:00 2001 From: Monsterovich Date: Thu, 23 May 2019 00:50:04 +0200 Subject: [PATCH 3/8] fix(ui): minor fix --- src/platform/desktop_notifications/desktopnotify.cpp | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/src/platform/desktop_notifications/desktopnotify.cpp b/src/platform/desktop_notifications/desktopnotify.cpp index 7754fe705..ab2ddcfb3 100644 --- a/src/platform/desktop_notifications/desktopnotify.cpp +++ b/src/platform/desktop_notifications/desktopnotify.cpp @@ -50,7 +50,7 @@ void DesktopNotify::notifyMessageSimple(const MessageType type) 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; + case MSG_GROUP_INVITE: message = tr("Group invite received"); break; default: break; } From 84e41303ce6297df68886d4a1615a07286aed794 Mon Sep 17 00:00:00 2001 From: Monsterovich Date: Thu, 23 May 2019 01:42:20 +0200 Subject: [PATCH 4/8] fix(ui): don't forget to update UI --- src/widget/form/settings/userinterfaceform.cpp | 1 + 1 file changed, 1 insertion(+) diff --git a/src/widget/form/settings/userinterfaceform.cpp b/src/widget/form/settings/userinterfaceform.cpp index 5166ca552..442e15d16 100644 --- a/src/widget/form/settings/userinterfaceform.cpp +++ b/src/widget/form/settings/userinterfaceform.cpp @@ -78,6 +78,7 @@ UserInterfaceForm::UserInterfaceForm(SettingsWidget* myParent) bodyUI->groupOnlyNotfiyWhenMentioned->setChecked(!s.getGroupAlwaysNotify()); bodyUI->groupOnlyNotfiyWhenMentioned->setEnabled(s.getNotify()); bodyUI->notifySound->setChecked(s.getNotifySound()); + bodyUI->notifyHide->setChecked(s.getNotifyHide()); bodyUI->notifySound->setEnabled(s.getNotify()); bodyUI->busySound->setChecked(s.getBusySound()); bodyUI->busySound->setEnabled(s.getNotifySound() && s.getNotify()); From f8b54b39f311b6d05b29e517c88c7fcf5fa4f5de Mon Sep 17 00:00:00 2001 From: Monsterovich Date: Thu, 23 May 2019 15:30:31 +0200 Subject: [PATCH 5/8] fix(ui): apply requested changes --- .../desktop_notifications/desktopnotify.cpp | 10 +++++----- .../desktop_notifications/desktopnotify.h | 12 +++++------ src/widget/widget.cpp | 20 ++++++++----------- 3 files changed, 19 insertions(+), 23 deletions(-) diff --git a/src/platform/desktop_notifications/desktopnotify.cpp b/src/platform/desktop_notifications/desktopnotify.cpp index ab2ddcfb3..68bcee4ab 100644 --- a/src/platform/desktop_notifications/desktopnotify.cpp +++ b/src/platform/desktop_notifications/desktopnotify.cpp @@ -46,11 +46,11 @@ 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 received"); break; + case MessageType::FRIEND: message = tr("New message"); break; + case MessageType::FRIEND_FILE: message = tr("Incoming file transfer"); break; + case MessageType::FRIEND_REQUEST: message = tr("Friend request received"); break; + case MessageType::GROUP: message = tr("New group message"); break; + case MessageType::GROUP_INVITE: message = tr("Group invite received"); break; default: break; } diff --git a/src/platform/desktop_notifications/desktopnotify.h b/src/platform/desktop_notifications/desktopnotify.h index 94aba3fa9..ba7b753ef 100644 --- a/src/platform/desktop_notifications/desktopnotify.h +++ b/src/platform/desktop_notifications/desktopnotify.h @@ -12,12 +12,12 @@ class DesktopNotify : public QObject public: DesktopNotify(); - enum MessageType { - MSG_FRIEND = 0, - MSG_FRIEND_FILE, - MSG_FRIEND_REQUEST, - MSG_GROUP, - MSG_GROUP_INVITE + enum class MessageType { + FRIEND, + FRIEND_FILE, + FRIEND_REQUEST, + GROUP, + GROUP_INVITE }; public slots: diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index 3d71c62a8..c813d495b 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -1381,9 +1381,8 @@ bool Widget::newFriendMessageAlert(const ToxPk& friendId, const QString text, bo widget->updateStatusLight(); ui->friendList->trackWidget(widget); #if DESKTOP_NOTIFICATIONS - const Settings& s = Settings::getInstance(); - if (s.getNotifyHide()) { - notifier.notifyMessageSimple(file ? DesktopNotify::MSG_FRIEND_FILE : DesktopNotify::MSG_FRIEND); + if (settings.getNotifyHide()) { + notifier.notifyMessageSimple(file ? DesktopNotify::MessageType::FRIEND_FILE : DesktopNotify::MessageType::FRIEND); } else { QString title = f->getDisplayedName(); if (file) { @@ -1430,9 +1429,8 @@ bool Widget::newGroupMessageAlert(const GroupId& groupId, const ToxPk authorPk, g->setEventFlag(true); widget->updateStatusLight(); #if DESKTOP_NOTIFICATIONS - const Settings& s = Settings::getInstance(); - if (s.getNotifyHide()) { - notifier.notifyMessageSimple(DesktopNotify::MSG_GROUP); + if (settings.getNotifyHide()) { + notifier.notifyMessageSimple(DesktopNotify::MessageType::GROUP); } else { Friend *f = FriendList::findFriend(authorPk); QString title = g->getPeerList().value(authorPk) + " (" + g->getDisplayedName() + ")"; @@ -1517,9 +1515,8 @@ void Widget::onFriendRequestReceived(const ToxPk& friendPk, const QString& messa friendRequestsUpdate(); newMessageAlert(window(), isActiveWindow(), true, true); #if DESKTOP_NOTIFICATIONS - const Settings& s = Settings::getInstance(); - if (s.getNotifyHide()) { - notifier.notifyMessageSimple(DesktopNotify::MSG_FRIEND_REQUEST); + if (settings.getNotifyHide()) { + notifier.notifyMessageSimple(DesktopNotify::MessageType::FRIEND_REQUEST); } else { notifier.notifyMessage(friendPk.toString() + tr(" sent you a friend request."), message); } @@ -1761,9 +1758,8 @@ void Widget::onGroupInviteReceived(const GroupInvite& inviteInfo) groupInvitesUpdate(); newMessageAlert(window(), isActiveWindow(), true, true); #if DESKTOP_NOTIFICATIONS - const Settings& s = Settings::getInstance(); - if (s.getNotifyHide()) { - notifier.notifyMessageSimple(DesktopNotify::MSG_GROUP_INVITE); + if (settings.getNotifyHide()) { + notifier.notifyMessageSimple(DesktopNotify::MessageType::GROUP_INVITE); } else { notifier.notifyMessagePixmap(f->getDisplayedName() + tr(" invites you to join a group."), {}, Nexus::getProfile()->loadAvatar(f->getPublicKey())); } From 821ed5261641043121d0b716d381346ac7502a15 Mon Sep 17 00:00:00 2001 From: Monsterovich Date: Thu, 23 May 2019 19:18:24 +0200 Subject: [PATCH 6/8] fix(ui): revert CMakeLists.txt --- CMakeLists.txt | 2 +- 1 file changed, 1 insertion(+), 1 deletion(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 7073e9b6f..774c89cea 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -14,7 +14,7 @@ option(USE_CCACHE "Use ccache when available" ON) option(SPELL_CHECK "Enable spell cheching support" ON) option(SVGZ_ICON "Compress the SVG icon of qTox" ON) option(ASAN "Compile with AddressSanitizer" OFF) -option(DESKTOP_NOTIFICATIONS "Use snorenotify for desktop notifications" ON) +option(DESKTOP_NOTIFICATIONS "Use snorenotify for desktop notifications" OFF) # process generated files if cmake >= 3.10 if(POLICY CMP0071) From 161a773dbbc4546442ad67dc96400fcd583fdccf Mon Sep 17 00:00:00 2001 From: Monsterovich Date: Thu, 23 May 2019 19:42:09 +0200 Subject: [PATCH 7/8] fix(ui): minor fix --- src/platform/desktop_notifications/desktopnotify.cpp | 6 +++--- src/platform/desktop_notifications/desktopnotify.h | 6 +++--- 2 files changed, 6 insertions(+), 6 deletions(-) diff --git a/src/platform/desktop_notifications/desktopnotify.cpp b/src/platform/desktop_notifications/desktopnotify.cpp index 68bcee4ab..60f306b01 100644 --- a/src/platform/desktop_notifications/desktopnotify.cpp +++ b/src/platform/desktop_notifications/desktopnotify.cpp @@ -19,7 +19,7 @@ DesktopNotify::DesktopNotify() notifyCore.registerApplication(snoreApp); } -void DesktopNotify::createNotification(const QString& title, const QString &text, Snore::Icon &icon) +void DesktopNotify::createNotification(const QString& title, const QString& text, Snore::Icon& icon) { const Settings& s = Settings::getInstance(); if(!(s.getNotify() && s.getDesktopNotify())) { @@ -31,12 +31,12 @@ void DesktopNotify::createNotification(const QString& title, const QString &text notifyCore.broadcastNotification(notify); } -void DesktopNotify::notifyMessage(const QString title, const QString message) +void DesktopNotify::notifyMessage(const QString& title, const QString& message) { createNotification(title, message, snoreIcon); } -void DesktopNotify::notifyMessagePixmap(const QString title, const QString message, QPixmap avatar) +void DesktopNotify::notifyMessagePixmap(const QString& title, const QString& message, QPixmap avatar) { Snore::Icon new_icon(avatar); createNotification(title, message, new_icon); diff --git a/src/platform/desktop_notifications/desktopnotify.h b/src/platform/desktop_notifications/desktopnotify.h index ba7b753ef..82ab70350 100644 --- a/src/platform/desktop_notifications/desktopnotify.h +++ b/src/platform/desktop_notifications/desktopnotify.h @@ -21,12 +21,12 @@ public: }; public slots: - void notifyMessage(const QString title, const QString message); - void notifyMessagePixmap(const QString title, const QString message, QPixmap avatar); + 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); + void createNotification(const QString& title, const QString& text, Snore::Icon& icon); private: Snore::SnoreCore& notifyCore; From 1c02dc2d6ba4f6d217c2fc55fa513d252aa4dbde Mon Sep 17 00:00:00 2001 From: Monsterovich Date: Thu, 23 May 2019 19:49:42 +0200 Subject: [PATCH 8/8] fix(ui): fix 2 --- src/widget/widget.cpp | 4 ++-- src/widget/widget.h | 4 ++-- 2 files changed, 4 insertions(+), 4 deletions(-) diff --git a/src/widget/widget.cpp b/src/widget/widget.cpp index c813d495b..8ee6fe007 100644 --- a/src/widget/widget.cpp +++ b/src/widget/widget.cpp @@ -1344,7 +1344,7 @@ void Widget::addGroupDialog(Group* group, ContentDialog* dialog) emit widget->chatroomWidgetClicked(widget); } -bool Widget::newFriendMessageAlert(const ToxPk& friendId, const QString text, bool sound, bool file) +bool Widget::newFriendMessageAlert(const ToxPk& friendId, const QString& text, bool sound, bool file) { bool hasActive; QWidget* currentWindow; @@ -1406,7 +1406,7 @@ bool Widget::newFriendMessageAlert(const ToxPk& friendId, const QString text, bo return false; } -bool Widget::newGroupMessageAlert(const GroupId& groupId, const ToxPk authorPk, const QString message, bool notify) +bool Widget::newGroupMessageAlert(const GroupId& groupId, const ToxPk& authorPk, const QString& message, bool notify) { bool hasActive; QWidget* currentWindow; diff --git a/src/widget/widget.h b/src/widget/widget.h index 7ad206cff..6e5148247 100644 --- a/src/widget/widget.h +++ b/src/widget/widget.h @@ -123,8 +123,8 @@ public: void showUpdateDownloadProgress(); void addFriendDialog(const Friend* frnd, ContentDialog* dialog); void addGroupDialog(Group* group, ContentDialog* dialog); - bool newFriendMessageAlert(const ToxPk& friendId, const QString text, bool sound = true, bool file = false); - bool newGroupMessageAlert(const GroupId& groupId, const ToxPk authorPk, const QString message, bool notify); + bool newFriendMessageAlert(const ToxPk& friendId, const QString& text, bool sound = true, bool file = false); + bool newGroupMessageAlert(const GroupId& groupId, const ToxPk& authorPk, const QString& message, bool notify); bool getIsWindowMinimized(); void updateIcons();