#include #include #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) { } 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) { }