Debian Codegraph @

src/notifications/Manager.h

raw symbols SCIP
1 // SPDX-FileCopyrightText: Nheko Contributors
2 //
3 // SPDX-License-Identifier: GPL-3.0-or-later
4
5 #pragma once
6
7 #include <QImage>
8 #include <QMap>
9 #include <QObject>
10 #include <QString>
11
12 #include <mtx/responses/notifications.hpp>
13
14 #if defined(NHEKO_DBUS_SYS)
15 #include <QtDBus/QDBusArgument>
16 #include <QtDBus/QDBusInterface>
17 #endif
18
19 struct roomEventId
20 {
21 QString roomId;
22 QString eventId;
23 };
24
25 inline bool
26 operator==(const roomEventId &a, const roomEventId &b)
27 {
28 return a.roomId == b.roomId && a.eventId == b.eventId;
29 }
30
31 class NotificationsManager final : public QObject
32 {
33 Q_OBJECT
34 public:
35 NotificationsManager(QObject *parent = nullptr);
36
37 void postNotification(const mtx::responses::Notification &notification, const QImage &icon);
38
39 void removeNotification(const QString &roomId, const QString &eventId);
40
41 signals:
42 void notificationClicked(const QString roomId, const QString eventId);
43 void sendNotificationReply(const QString roomId, const QString eventId, const QString body);
44 void systemPostNotificationCb(const QString &room_id,
45 const QString &event_id,
46 const QString &roomName,
47 const QString &text,
48 const QImage &icon);
49
50 public slots:
51 void removeNotifications(const QString &roomId, const std::vector<QString> &eventId);
52
53 #if defined(NHEKO_DBUS_SYS)
54 public:
55 void closeNotifications(QString roomId);
56 #if defined(Q_OS_UNIX) && !defined(Q_OS_MACOS)
57 void closeAllNotifications();
58 #endif
59
60 private:
61 QDBusInterface dbus;
62
63 void systemPostNotification(const QString &room_id,
64 const QString &event_id,
65 const QString &roomName,
66 const QString &text,
67 const QImage &icon);
68 void closeNotification(uint id);
69 const bool hasMarkup_;
70 const bool hasImages_;
71 #endif
72
73 #if defined(Q_OS_MACOS)
74 private:
75 // Objective-C(++) doesn't like to do lots of regular C++, so the actual notification
76 // posting is split out
77 void objCxxPostNotification(const QString room_name,
78 const QString room_id,
79 const QString event_id,
80 const QString subtitle,
81 const QString informativeText,
82 const QString bodyImagePath,
83 const bool playSound);
84
85 QString respondStr;
86 QString sendStr;
87 QString placeholder;
88
89 public:
90 static void attachToMacNotifCenter();
91 #endif
92
93 #if defined(Q_OS_WINDOWS)
94 private:
95 void systemPostNotification(const QString &roomid,
96 const QString &eventid,
97 const QString &line1,
98 const QString &line2,
99 const QString &iconPath,
100 const QString &bodyImagePath);
101 #endif
102
103 // these slots are platform specific (D-Bus only)
104 // but Qt slot declarations can not be inside an ifdef!
105 private slots:
106 void actionInvoked(uint id, QString action);
107 void activationToken(uint id, QString action);
108 void notificationClosed(uint id, uint reason);
109 void notificationReplied(uint id, QString reply);
110
111 private:
112 QString getMessageTemplate(const mtx::responses::Notification &notification);
113 bool allowShowingImages(const mtx::responses::Notification &notification);
114
115 // notification ID to (room ID, event ID)
116 // Only populated on Linux atm
117 QMap<uint, roomEventId> notificationIds;
118 };