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 --- salmeta.pro | 2 -- src/notificationadaptor.cpp | 27 --------------- src/notificationadaptor.h | 65 ----------------------------------- src/notificationmonitor.cpp | 39 +++++++-------------- src/notificationmonitor.h | 9 ++--- src/org.freedesktop.Notifications.xml | 46 ------------------------- 6 files changed, 17 insertions(+), 171 deletions(-) delete mode 100644 src/notificationadaptor.cpp delete mode 100644 src/notificationadaptor.h delete mode 100644 src/org.freedesktop.Notifications.xml diff --git a/salmeta.pro b/salmeta.pro index 4a75956..8bf7ec8 100644 --- a/salmeta.pro +++ b/salmeta.pro @@ -19,7 +19,6 @@ SOURCES += src/salmeta.cpp \ src/widgetinfo.cpp \ src/widgetinfomodel.cpp \ src/availablewidgetsmodel.cpp \ - src/notificationadaptor.cpp \ src/notification.cpp HEADERS += \ @@ -32,7 +31,6 @@ HEADERS += \ src/widgetinfo.h \ src/widgetinfomodel.h \ src/availablewidgetsmodel.h \ - src/notificationadaptor.h \ src/notification.h OTHER_FILES += qml/salmeta.qml \ diff --git a/src/notificationadaptor.cpp b/src/notificationadaptor.cpp deleted file mode 100644 index 4279831..0000000 --- a/src/notificationadaptor.cpp +++ /dev/null @@ -1,27 +0,0 @@ -/* - * This file was generated by qdbusxml2cpp version 0.7 - * Command line was: qdbusxml2cpp -c NotificationAdaptor -a notificationadaptor.cpp org.freedesktop.Notifications.xml - * - * qdbusxml2cpp is Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). - * - * This is an auto-generated file. - * This file may have been hand-edited. Look for HAND-EDIT comments - * before re-generating it. - */ - -#include "notificationadaptor.h" - -/* - * Implementation of adaptor class NotificationAdaptor - */ - -NotificationAdaptor::NotificationAdaptor(QObject *parent) - : QDBusAbstractAdaptor(parent) -{ -} - -uint NotificationAdaptor::Notify(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) -{ - // handle method call org.freedesktop.Notifications.Notify - static_cast(parent())->handleNotification(app_name, replaces_id, app_icon, summary, body, actions, hints, expire_timeout); -} diff --git a/src/notificationadaptor.h b/src/notificationadaptor.h deleted file mode 100644 index 0fba973..0000000 --- a/src/notificationadaptor.h +++ /dev/null @@ -1,65 +0,0 @@ -/* - * This file was generated by qdbusxml2cpp version 0.7 - * Command line was: qdbusxml2cpp -c NotificationAdaptor -a notificationadaptor.cpp org.freedesktop.Notifications.xml - * - * qdbusxml2cpp is Copyright (C) 2013 Digia Plc and/or its subsidiary(-ies). - * - * This is an auto-generated file. - * This file may have been hand-edited. Look for HAND-EDIT comments - * before re-generating it. - */ - -#ifndef NOTIFICATIONADAPTOR -#define NOTIFICATIONADAPTOR - -#include -#include -#include -#include -#include -#include -#include -#include -#include - -#include "notificationmonitor.h" - -/* - * Adaptor class for interface org.freedesktop.Notifications - */ -class NotificationAdaptor: public QDBusAbstractAdaptor -{ - Q_OBJECT - Q_CLASSINFO("D-Bus Interface", "org.freedesktop.Notifications") - Q_CLASSINFO("D-Bus Introspection", "" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" -" \n" - - - - "") -public: - explicit NotificationAdaptor(QObject *parent); - -public: // PROPERTIES -public Q_SLOTS: // METHODS - uint Notify(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 NotificationClosed(uint id, uint reason); -}; - -#endif 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; } diff --git a/src/notificationmonitor.h b/src/notificationmonitor.h index de9a0e7..eac06ff 100644 --- a/src/notificationmonitor.h +++ b/src/notificationmonitor.h @@ -3,6 +3,7 @@ #include #include +#include #include "notification.h" @@ -22,12 +23,12 @@ private: explicit NotificationMonitor(QObject *parent = 0); private slots: - void 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 handleClosedNotification(uint id); - friend class NotificationAdaptor; + void handleServiceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner); private: - QHash _pendingNotifications; + QHash _notifications; }; #endif // NOTIFICATIONMONITOR_H diff --git a/src/org.freedesktop.Notifications.xml b/src/org.freedesktop.Notifications.xml deleted file mode 100644 index 89947c9..0000000 --- a/src/org.freedesktop.Notifications.xml +++ /dev/null @@ -1,46 +0,0 @@ - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - - -- cgit v1.2.3