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
|
#include <QtCore/QDebug>
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusConnectionInterface>
#include "notificationmonitor.h"
#include "notificationadaptor.h"
static NotificationMonitor *global_monitor = 0;
namespace
{
void handleEavesdropCallFinished(QDBusPendingCallWatcher *watcher)
{
QDBusPendingReply reply = *watcher;
if (reply.isError()) {
QDBusError error = reply.error();
qWarning() << "Failure to eavesdrop for notifications:" << error.message();
} else {
qDebug() << "Now eavesdropping notifications";
}
}
}
NotificationMonitor::NotificationMonitor(QObject *parent) :
QObject(parent)
{
}
NotificationMonitor::~NotificationMonitor()
{
}
NotificationMonitor *NotificationMonitor::instance()
{
if (!global_monitor) {
QDBusConnection bus = QDBusConnection::sessionBus();
// First register the global monitor object that will listen for notifications...
global_monitor = new NotificationMonitor;
new NotificationAdaptor(global_monitor);
bus.registerObject("/org/freedesktop/Notifications", global_monitor);
// Now register for eavesdropping
QDBusConnectionInterface *dbus = bus.interface();
QDBusPendingCall call = dbus->asyncCall("AddMatch",
"interface='org.freedesktop.Notifications',member='Notify',type='method_call',eavesdrop='true'");
QDBusPendingCallWatcher *watcher = new QDBusPendingCallWatcher(call);
connect(watcher, &QDBusPendingCallWatcher::finished, &handleEavesdropCallFinished);
}
return global_monitor;
}
void NotificationMonitor::handleNotification(const QString &app_name, uint replaces_id, const QString &app_icon, const QString &summary, const QString &body, const QStringList &actions, const QVariantHash &hints, int expire_timeout)
{
}
|