-
Notifications
You must be signed in to change notification settings - Fork 6
/
notificationmonitor_p.h
107 lines (81 loc) · 2.99 KB
/
notificationmonitor_p.h
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
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
#ifndef WATCHFISH_NOTIFICATIONMONITOR_P_H
#define WATCHFISH_NOTIFICATIONMONITOR_P_H
#include <QtCore/QObject>
#include <dbus/dbus.h>
#include "notificationmonitor.h"
#define CATEGORY_DEFINITION_FILE_DIRECTORY "/usr/share/lipstick/notificationcategories"
#define CATEGORY_REFRESH_CHECK_TIME 120
#if defined(UUITK_EDITION)
#define DESKTOP_FILE_DIRECTORY "/home/phablet/.local/share/applications"
#else // defined(MER_EDITION_SAILFISH) // and others
#define DESKTOP_FILE_DIRECTORY "/usr/share/applications"
#endif
#define DESKTOP_REFRESH_CHECK_TIME 120
namespace watchfish
{
struct NotificationCategoryCacheEntry
{
QHash<QString, QString> data;
QDateTime lastReadTime;
QDateTime lastCheckTime;
};
struct AppNameCacheEntry
{
QString name;
QDateTime lastReadTime;
QDateTime lastCheckTime;
};
struct ProtoNotification
{
QString appId;
QString appName;
QString appIcon;
QString summary;
QString body;
QHash<QString, QString> hints;
int expireTimeout;
QStringList actions;
};
class NotificationMonitorPrivate : public QObject
{
Q_OBJECT
public:
explicit NotificationMonitorPrivate(NotificationMonitor *q);
~NotificationMonitorPrivate();
private:
/** Converts a ProtoNotification into a Notification object and raises it. */
void processIncomingNotification(quint32 id, const ProtoNotification &proto);
/** Raises appropiate notification signal. */
void processCloseNotification(quint32 id, quint32 reason);
/** Sends a D-Bus message for a method call with a single string argument. */
void sendMessageWithString(const char *service, const char *path, const char *iface, const char *method, const char *arg);
/** Adds a D-Bus filter match rule. */
void addMatchRule(const char *rule);
void removeMatchRule(const char *rule);
/** Converts a fdo Notification D-Bus message into a ProtoNotification object. */
ProtoNotification parseNotifyCall(DBusMessage *msg) const;
QHash<QString,QString> getCategoryInfo(const QString &s) const;
QString getAppName(const QString &id) const;
QString guessAppId(const QString &id) const;
static dbus_bool_t busWatchAdd(DBusWatch *watch, void *data);
static void busWatchRemove(DBusWatch *watch, void *data);
static void busWatchToggle(DBusWatch *watch, void *data);
static DBusHandlerResult busMessageFilter(DBusConnection *conn, DBusMessage *msg, void *user_data);
private slots:
void handleBusSocketActivated();
private:
NotificationMonitor * const q_ptr;
Q_DECLARE_PUBLIC(NotificationMonitor)
/** The current set of monitored notifications, indexed by id. */
QMap<quint32, Notification*> _notifs;
/** Low level dbus connection used for sniffing. */
DBusConnection *_conn;
/** Serials of DBUS method calls of which we are expecting a reply. */
QHash<quint32, ProtoNotification> _pendingConfirmation;
/** Cache of notification category info. */
mutable QHash<QString, NotificationCategoryCacheEntry> _categoryCache;
/** Cache of application names. */
mutable QHash<QString, AppNameCacheEntry> _appNameCache;
};
}
#endif // WATCHFISH_NOTIFICATIONMONITOR_P_H