From 4bc56bff80046b74926289be8825726296f39791 Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sun, 14 Sep 2014 19:47:14 +0200 Subject: Prepare new plan for notification eavesdropping --- src/notificationmonitor.cpp | 39 ++++++++++++--------------------------- 1 file changed, 12 insertions(+), 27 deletions(-) (limited to 'src/notificationmonitor.cpp') diff --git a/src/notificationmonitor.cpp b/src/notificationmonitor.cpp index cdf4d50..50f7b91 100644 --- a/src/notificationmonitor.cpp +++ b/src/notificationmonitor.cpp @@ -3,29 +3,27 @@ #include #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) { + 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() @@ -35,25 +33,12 @@ 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) +void NotificationMonitor::handleServiceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner) { - + qDebug() << "Service owner changed" << serviceName << oldOwner << newOwner; } -- cgit v1.2.3