summaryrefslogtreecommitdiff
path: root/src/notificationmonitor.cpp
blob: 50f7b9100fcfb668b0e521cc0392167dbb3bdf55 (plain)
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
#include <QtCore/QDebug>
#include <QtDBus/QDBusConnection>
#include <QtDBus/QDBusConnectionInterface>

#include "notificationmonitor.h"

static NotificationMonitor *global_monitor = 0;

namespace
{

}

NotificationMonitor::NotificationMonitor(QObject *parent) :
	QObject(parent)
{
	QDBusConnection bus = QDBusConnection::sessionBus();

	_watcher = new QDBusServiceWatcher("org.freedesktop.Notifications", bus,
	                                   QDBusServiceWatcher::WatchForOwnerChange,
	                                   this);
	connect(_watcher, &QDBusServiceWatcher::serviceOwnerChanged,
	        this, &NotificationMonitor::handleServiceOwnerChanged);

	bus.interface()->call("AddMatch",
	                      "interface='org.freedesktop.Notifications',member='Notify',type='method_call',eavesdrop='true'");
}

NotificationMonitor::~NotificationMonitor()
{
}

NotificationMonitor *NotificationMonitor::instance()
{
	if (!global_monitor) {
		global_monitor = new NotificationMonitor;
	}
	return global_monitor;
}

void NotificationMonitor::handleServiceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner)
{
	qDebug() << "Service owner changed" << serviceName << oldOwner << newOwner;
}