mirror of https://github.com/qTox/qTox.git
Browse Source
This commit adds very basic support for desktop notifications on friend request, group invites, friend messages and group messages.reviewable/pr5351/r4
7 changed files with 168 additions and 1 deletions
@ -0,0 +1,81 @@ |
|||||||
|
#include "desktopnotify.h" |
||||||
|
|
||||||
|
#include <libsnore/snore.h> |
||||||
|
|
||||||
|
#include <QDebug> |
||||||
|
|
||||||
|
DesktopNotify::DesktopNotify() |
||||||
|
: notifyCore{Snore::SnoreCore::instance()} |
||||||
|
, snoreIcon{":/img/icons/qtox.svg"} |
||||||
|
{ |
||||||
|
|
||||||
|
notifyCore.loadPlugins(Snore::SnorePlugin::Backend); |
||||||
|
qDebug() << "primary notification backend:" << notifyCore.primaryNotificationBackend(); |
||||||
|
|
||||||
|
snoreApp = Snore::Application("qTox", snoreIcon); |
||||||
|
|
||||||
|
notifyCore.registerApplication(snoreApp); |
||||||
|
} |
||||||
|
|
||||||
|
DesktopNotify::NotificationPtr DesktopNotify::createNotification(const QString& title, |
||||||
|
const QString& text, |
||||||
|
Snore::Notification* old) |
||||||
|
{ |
||||||
|
if (old == nullptr) { |
||||||
|
return NotificationPtr( |
||||||
|
new Snore::Notification(snoreApp, Snore::Alert(), title, text, snoreIcon)); |
||||||
|
} else { |
||||||
|
return NotificationPtr(new Snore::Notification(*old, title, text, snoreIcon)); |
||||||
|
} |
||||||
|
} |
||||||
|
|
||||||
|
void DesktopNotify::notifyGroupMessage() |
||||||
|
{ |
||||||
|
const QString text{}; |
||||||
|
const QString title = tr("New group message received"); |
||||||
|
NotificationPtr newNote = createNotification(title, text); |
||||||
|
if (!newNote) { |
||||||
|
qDebug() << "Failed to allocate group message notification"; |
||||||
|
return; |
||||||
|
} |
||||||
|
groupInvite = std::move(newNote); |
||||||
|
} |
||||||
|
|
||||||
|
void DesktopNotify::notifyFriendRequest() |
||||||
|
{ |
||||||
|
const QString title = tr("New friend request received"); |
||||||
|
const QString text{}; |
||||||
|
NotificationPtr newNote = createNotification(title, text); |
||||||
|
if (!newNote) { |
||||||
|
qDebug() << "Failed to allocate friend message notification"; |
||||||
|
return; |
||||||
|
} |
||||||
|
friendMessage = std::move(newNote); |
||||||
|
notifyCore.broadcastNotification(*friendMessage); |
||||||
|
} |
||||||
|
|
||||||
|
void DesktopNotify::notifyGroupInvite() |
||||||
|
{ |
||||||
|
const QString title = tr("New group invite received"); |
||||||
|
const QString text{}; |
||||||
|
NotificationPtr newNote = createNotification(title, text); |
||||||
|
if (!newNote) { |
||||||
|
qDebug() << "Failed to allocate friend message notification"; |
||||||
|
return; |
||||||
|
} |
||||||
|
friendMessage = std::move(newNote); |
||||||
|
notifyCore.broadcastNotification(*friendMessage); |
||||||
|
} |
||||||
|
|
||||||
|
void DesktopNotify::notifyFriendMessage() |
||||||
|
{ |
||||||
|
const QString title = tr("New message received"); |
||||||
|
const QString text{}; |
||||||
|
NotificationPtr newNote = createNotification(title, text); |
||||||
|
if (!newNote) { |
||||||
|
qDebug() << "Failed to allocate friend message notification"; |
||||||
|
return; |
||||||
|
} |
||||||
|
friendMessage = std::move(newNote); |
||||||
|
notifyCore.broadcastNotification(*friendMessage); |
||||||
|
} |
@ -0,0 +1,37 @@ |
|||||||
|
#ifndef DESKTOPNOTIFY_H |
||||||
|
#define DESKTOPNOTIFY_H |
||||||
|
|
||||||
|
#include <libsnore/snore.h> |
||||||
|
|
||||||
|
#include <QObject> |
||||||
|
#include <memory> |
||||||
|
|
||||||
|
class DesktopNotify : public QObject |
||||||
|
{ |
||||||
|
Q_OBJECT |
||||||
|
public: |
||||||
|
DesktopNotify(); |
||||||
|
|
||||||
|
public slots: |
||||||
|
void notifyFriendMessage(); |
||||||
|
void notifyGroupMessage(); |
||||||
|
void notifyFriendRequest(); |
||||||
|
void notifyGroupInvite(); |
||||||
|
|
||||||
|
private: |
||||||
|
using NotificationPtr = std::unique_ptr<Snore::Notification>; |
||||||
|
|
||||||
|
NotificationPtr createNotification(const QString& title, const QString& text, |
||||||
|
Snore::Notification* old = nullptr); |
||||||
|
|
||||||
|
private: |
||||||
|
Snore::SnoreCore& notifyCore; |
||||||
|
NotificationPtr groupInvite = {nullptr}; |
||||||
|
NotificationPtr groupMessage = {nullptr}; |
||||||
|
NotificationPtr friendRequest = {nullptr}; |
||||||
|
NotificationPtr friendMessage = {nullptr}; |
||||||
|
Snore::Application snoreApp; |
||||||
|
Snore::Icon snoreIcon; |
||||||
|
}; |
||||||
|
|
||||||
|
#endif // DESKTOPNOTIFY_H
|
Loading…
Reference in new issue