1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
|
#pragma once
#include <QImage>
#include <QObject>
#include <QString>
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
#include <QtDBus/QDBusArgument>
#include <QtDBus/QDBusInterface>
#endif
struct roomEventId
{
QString roomId;
QString eventId;
};
inline bool
operator==(const roomEventId &a, const roomEventId &b)
{
return a.roomId == b.roomId && a.eventId == b.eventId;
}
class NotificationsManager : public QObject
{
Q_OBJECT
public:
NotificationsManager(QObject *parent = nullptr);
void postNotification(const QString &roomId,
const QString &eventId,
const QString &roomName,
const QString &senderName,
const QString &text,
const QImage &icon);
signals:
void notificationClicked(const QString roomId, const QString eventId);
void sendNotificationReply(const QString roomId, const QString eventId, const QString body);
public slots:
void removeNotification(const QString &roomId, const QString &eventId);
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
public:
void closeNotifications(QString roomId);
private:
QDBusInterface dbus;
uint showNotification(const QString summary, const QString text, const QImage image);
void closeNotification(uint id);
// notification ID to (room ID, event ID)
QMap<uint, roomEventId> notificationIds;
#endif
// these slots are platform specific (D-Bus only)
// but Qt slot declarations can not be inside an ifdef!
private slots:
void actionInvoked(uint id, QString action);
void notificationClosed(uint id, uint reason);
void notificationReplied(uint id, QString reply);
};
#if defined(Q_OS_LINUX) || defined(Q_OS_FREEBSD)
QDBusArgument &
operator<<(QDBusArgument &arg, const QImage &image);
const QDBusArgument &
operator>>(const QDBusArgument &arg, QImage &);
#endif
|