1
0
mirror of https://github.com/qTox/qTox.git synced 2024-03-22 14:00:36 +08:00

fix(ui): Improved notifications

This commit is contained in:
Monsterovich 2019-05-22 19:48:23 +02:00
parent 22362d2940
commit 1bbe210c25
7 changed files with 38 additions and 38 deletions

View File

@ -14,7 +14,7 @@ option(USE_CCACHE "Use ccache when available" ON)
option(SPELL_CHECK "Enable spell cheching support" ON) option(SPELL_CHECK "Enable spell cheching support" ON)
option(SVGZ_ICON "Compress the SVG icon of qTox" ON) option(SVGZ_ICON "Compress the SVG icon of qTox" ON)
option(ASAN "Compile with AddressSanitizer" OFF) 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 # process generated files if cmake >= 3.10
if(POLICY CMP0071) if(POLICY CMP0071)

View File

@ -44,6 +44,7 @@ public:
virtual ~FileTransferWidget(); virtual ~FileTransferWidget();
void autoAcceptTransfer(const QString& path); void autoAcceptTransfer(const QString& path);
bool isActive() const; bool isActive() const;
static QString getHumanReadableSize(qint64 size);
protected slots: protected slots:
void onFileTransferInfo(ToxFile file); void onFileTransferInfo(ToxFile file);
@ -56,7 +57,6 @@ protected slots:
void fileTransferBrokenUnbroken(ToxFile file, bool broken); void fileTransferBrokenUnbroken(ToxFile file, bool broken);
protected: protected:
QString getHumanReadableSize(qint64 size);
void updateWidgetColor(ToxFile const& file); void updateWidgetColor(ToxFile const& file);
void updateWidgetText(ToxFile const& file); void updateWidgetText(ToxFile const& file);
void updateFileProgress(ToxFile const& file); void updateFileProgress(ToxFile const& file);

View File

@ -19,37 +19,26 @@ DesktopNotify::DesktopNotify()
notifyCore.registerApplication(snoreApp); 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(); const Settings& s = Settings::getInstance();
if(!(s.getNotify() && s.getDesktopNotify())) { if(!(s.getNotify() && s.getDesktopNotify())) {
return; return;
} }
Snore::Notification notify{snoreApp, Snore::Alert(), title, {}, snoreIcon}; Snore::Notification notify{snoreApp, Snore::Alert(), title, text, icon};
notifyCore.broadcastNotification(notify); 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, message, snoreIcon);
createNotification(title);
} }
void DesktopNotify::notifyFriendRequest() void DesktopNotify::notifyMessagePixmap(const QString title, const QString message, QPixmap avatar)
{ {
const QString title = tr("New friend request received"); Snore::Icon new_icon(avatar);
createNotification(title); 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);
}

View File

@ -13,13 +13,11 @@ public:
DesktopNotify(); DesktopNotify();
public slots: public slots:
void notifyFriendMessage(); void notifyMessage(const QString title, const QString message);
void notifyGroupMessage(); void notifyMessagePixmap(const QString title, const QString message, QPixmap avatar);
void notifyFriendRequest();
void notifyGroupInvite();
private: private:
void createNotification(const QString& title); void createNotification(const QString& title, const QString &text, Snore::Icon &icon);
private: private:
Snore::SnoreCore& notifyCore; Snore::SnoreCore& notifyCore;

View File

@ -338,7 +338,10 @@ void ChatForm::onFileRecvRequest(ToxFile file)
return; return;
} }
Widget::getInstance()->newFriendMessageAlert(f->getPublicKey()); Widget::getInstance()->newFriendMessageAlert(f->getPublicKey(),
file.fileName +
" (" + FileTransferWidget::getHumanReadableSize(file.filesize) + ")",
true, true);
QString name; QString name;
ToxPk friendId = f->getPublicKey(); ToxPk friendId = f->getPublicKey();
if (friendId != previousId) { if (friendId != previousId) {

View File

@ -964,7 +964,7 @@ void Widget::cleanupNotificationSound()
void Widget::incomingNotification(uint32_t friendnumber) void Widget::incomingNotification(uint32_t friendnumber)
{ {
const auto& friendId = FriendList::id2Key(friendnumber); const auto& friendId = FriendList::id2Key(friendnumber);
newFriendMessageAlert(friendId, false); newFriendMessageAlert(friendId, {}, false);
// loop until call answered or rejected // loop until call answered or rejected
playNotificationSound(IAudioSink::Sound::IncomingCall, true); 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); profile->getHistory()->addNewMessage(publicKey, text, publicKey, timestamp, true, name);
} }
newFriendMessageAlert(friendId); newFriendMessageAlert(friendId, message);
} }
void Widget::addFriendDialog(const Friend* frnd, ContentDialog* dialog) void Widget::addFriendDialog(const Friend* frnd, ContentDialog* dialog)
@ -1344,7 +1344,7 @@ void Widget::addGroupDialog(Group* group, ContentDialog* dialog)
emit widget->chatroomWidgetClicked(widget); 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; bool hasActive;
QWidget* currentWindow; QWidget* currentWindow;
@ -1381,7 +1381,11 @@ bool Widget::newFriendMessageAlert(const ToxPk& friendId, bool sound)
widget->updateStatusLight(); widget->updateStatusLight();
ui->friendList->trackWidget(widget); ui->friendList->trackWidget(widget);
#if DESKTOP_NOTIFICATIONS #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 #endif
if (contentDialog == nullptr) { if (contentDialog == nullptr) {
@ -1398,7 +1402,7 @@ bool Widget::newFriendMessageAlert(const ToxPk& friendId, bool sound)
return false; 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; bool hasActive;
QWidget* currentWindow; QWidget* currentWindow;
@ -1421,7 +1425,13 @@ bool Widget::newGroupMessageAlert(const GroupId& groupId, bool notify)
g->setEventFlag(true); g->setEventFlag(true);
widget->updateStatusLight(); widget->updateStatusLight();
#if DESKTOP_NOTIFICATIONS #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 #endif
if (contentDialog == nullptr) { if (contentDialog == nullptr) {
@ -1497,7 +1507,7 @@ void Widget::onFriendRequestReceived(const ToxPk& friendPk, const QString& messa
friendRequestsUpdate(); friendRequestsUpdate();
newMessageAlert(window(), isActiveWindow(), true, true); newMessageAlert(window(), isActiveWindow(), true, true);
#if DESKTOP_NOTIFICATIONS #if DESKTOP_NOTIFICATIONS
notifier.notifyFriendRequest(); notifier.notifyMessage(friendPk.toString() + tr(" sent you a friend request."), message);
#endif #endif
} }
} }
@ -1736,7 +1746,7 @@ void Widget::onGroupInviteReceived(const GroupInvite& inviteInfo)
groupInvitesUpdate(); groupInvitesUpdate();
newMessageAlert(window(), isActiveWindow(), true, true); newMessageAlert(window(), isActiveWindow(), true, true);
#if DESKTOP_NOTIFICATIONS #if DESKTOP_NOTIFICATIONS
notifier.notifyGroupInvite(); notifier.notifyMessagePixmap(f->getDisplayedName() + tr(" invites you to join a group."), {}, Nexus::getProfile()->loadAvatar(f->getPublicKey()));
#endif #endif
} }
} else { } else {
@ -1781,7 +1791,7 @@ void Widget::onGroupMessageReceived(int groupnumber, int peernumber, const QStri
form->addMessage(author, message, date, isAction, true); 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) void Widget::onGroupPeerlistChanged(uint32_t groupnumber)

View File

@ -123,8 +123,8 @@ public:
void showUpdateDownloadProgress(); void showUpdateDownloadProgress();
void addFriendDialog(const Friend* frnd, ContentDialog* dialog); void addFriendDialog(const Friend* frnd, ContentDialog* dialog);
void addGroupDialog(Group* group, ContentDialog* dialog); void addGroupDialog(Group* group, ContentDialog* dialog);
bool newFriendMessageAlert(const ToxPk& friendId, bool sound = true); bool newFriendMessageAlert(const ToxPk& friendId, const QString text, bool sound = true, bool file = false);
bool newGroupMessageAlert(const GroupId& groupId, bool notify); bool newGroupMessageAlert(const GroupId& groupId, const ToxPk authorPk, const QString message, bool notify);
bool getIsWindowMinimized(); bool getIsWindowMinimized();
void updateIcons(); void updateIcons();