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

Commit

Permalink
fix(ui): Improved notifications
Browse files Browse the repository at this point in the history
  • Loading branch information
Monsterovich committed May 22, 2019
1 parent 22362d2 commit 1bbe210
Show file tree
Hide file tree
Showing 7 changed files with 38 additions and 38 deletions.
2 changes: 1 addition & 1 deletion CMakeLists.txt
Original file line number Diff line number Diff line change
Expand Up @@ -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)
Expand Down
2 changes: 1 addition & 1 deletion src/chatlog/content/filetransferwidget.h
Original file line number Diff line number Diff line change
Expand Up @@ -44,6 +44,7 @@ class FileTransferWidget : public QWidget
virtual ~FileTransferWidget();
void autoAcceptTransfer(const QString& path);
bool isActive() const;
static QString getHumanReadableSize(qint64 size);

protected slots:
void onFileTransferInfo(ToxFile file);
Expand All @@ -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);
Expand Down
27 changes: 8 additions & 19 deletions src/platform/desktop_notifications/desktopnotify.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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};
notifyCore.broadcastNotification(notify);
}
Snore::Notification notify{snoreApp, Snore::Alert(), title, text, icon};

void DesktopNotify::notifyGroupMessage()
{
const QString title = tr("New group message received");
createNotification(title);
notifyCore.broadcastNotification(notify);
}

void DesktopNotify::notifyFriendRequest()
void DesktopNotify::notifyMessage(const QString title, const QString message)
{
const QString title = tr("New friend request received");
createNotification(title);
createNotification(title, message, snoreIcon);
}

void DesktopNotify::notifyGroupInvite()
void DesktopNotify::notifyMessagePixmap(const QString title, const QString message, QPixmap avatar)
{
const QString title = tr("New group invite received");
createNotification(title);
Snore::Icon new_icon(avatar);
createNotification(title, message, new_icon);
}

void DesktopNotify::notifyFriendMessage()
{
const QString title = tr("New message received");
createNotification(title);
}
8 changes: 3 additions & 5 deletions src/platform/desktop_notifications/desktopnotify.h
Original file line number Diff line number Diff line change
Expand Up @@ -13,13 +13,11 @@ class DesktopNotify : public QObject
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;
Expand Down
5 changes: 4 additions & 1 deletion src/widget/form/chatform.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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) {
Expand Down
28 changes: 19 additions & 9 deletions src/widget/widget.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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);
Expand Down Expand Up @@ -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)
Expand Down Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand All @@ -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;
Expand All @@ -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) {
Expand Down Expand Up @@ -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
}
}
Expand Down Expand Up @@ -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 {
Expand Down Expand Up @@ -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)
Expand Down
4 changes: 2 additions & 2 deletions src/widget/widget.h
Original file line number Diff line number Diff line change
Expand Up @@ -123,8 +123,8 @@ class Widget final : public QMainWindow
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();

Expand Down

0 comments on commit 1bbe210

Please sign in to comment.