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(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)

View File

@ -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);

View File

@ -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);
}

View File

@ -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;

View File

@ -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) {

View File

@ -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)

View File

@ -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();