From 6a581ace4f14c30f1c66daf28064d7aefde546fc Mon Sep 17 00:00:00 2001 From: "Javier S. Pedro" Date: Sun, 14 Sep 2014 20:56:29 +0200 Subject: simplify notification monitoring for now --- src/controller.cpp | 3 +++ src/controller.h | 3 ++- src/notificationmonitor.cpp | 27 +++++++-------------------- src/notificationmonitor.h | 13 ------------- 4 files changed, 12 insertions(+), 34 deletions(-) diff --git a/src/controller.cpp b/src/controller.cpp index a5ff22d..f4a2b09 100644 --- a/src/controller.cpp +++ b/src/controller.cpp @@ -16,6 +16,7 @@ Controller::Controller(const QString &settingsPrefix, QQuickView *view, QObject _settings(new MDConfGroup(this)), _metawatch(0), _reconnect(new ReconnectTimer(this)), + _monitor(NotificationMonitor::instance()), _widgets(new WidgetInfoModel(settingsPrefix, this)), _curMode(MetaWatch::WatchModeIdle), _curPage(0), _batteryCharge(0), _batteryCharging(false) @@ -92,6 +93,8 @@ void Controller::connectToAddress(const QString &address) connect(_metawatch, &MetaWatch::batteryStatus, this, &Controller::handleMetaWatchBatteryStatus); connect(_reconnect, &ReconnectTimer::tryReconnect, _metawatch, &MetaWatch::connectDevice); + qDebug() << "Scheduling initial connection attempt to" << _address; + _reconnect->scheduleNextAttempt(); } diff --git a/src/controller.h b/src/controller.h index 604da2e..f4d4513 100644 --- a/src/controller.h +++ b/src/controller.h @@ -7,6 +7,7 @@ #include "metawatch.h" #include "reconnecttimer.h" +#include "notificationmonitor.h" #include "widgetinfomodel.h" class Controller : public QObject @@ -51,7 +52,7 @@ private: MDConfGroup *_settings; MetaWatch *_metawatch; ReconnectTimer *_reconnect; - + NotificationMonitor *_monitor; WidgetInfoModel *_widgets; QString _address; diff --git a/src/notificationmonitor.cpp b/src/notificationmonitor.cpp index 50f7b91..50b2e3e 100644 --- a/src/notificationmonitor.cpp +++ b/src/notificationmonitor.cpp @@ -1,33 +1,25 @@ #include #include #include - #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'"); + QDBusConnectionInterface *dbus = bus.interface(); + dbus->call("AddMatch", + "interface='org.freedesktop.Notifications',member='Notify',type='method_call',eavesdrop='true'"); } NotificationMonitor::~NotificationMonitor() { + QDBusConnection bus = QDBusConnection::sessionBus(); + QDBusConnectionInterface *dbus = bus.interface(); + dbus->call("RemoveMatch", + "interface='org.freedesktop.Notifications',member='Notify',type='method_call',eavesdrop='true'"); } NotificationMonitor *NotificationMonitor::instance() @@ -37,8 +29,3 @@ NotificationMonitor *NotificationMonitor::instance() } return global_monitor; } - -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 eac06ff..e8b6501 100644 --- a/src/notificationmonitor.h +++ b/src/notificationmonitor.h @@ -2,8 +2,6 @@ #define NOTIFICATIONMONITOR_H #include -#include -#include #include "notification.h" @@ -16,19 +14,8 @@ public: static NotificationMonitor *instance(); -signals: - void newNotification(Notification *notification); - private: explicit NotificationMonitor(QObject *parent = 0); - -private slots: - void handleServiceOwnerChanged(const QString &serviceName, const QString &oldOwner, const QString &newOwner); - -private: - QDBusServiceWatcher *_watcher; - QHash _pendingNotifications; - QHash _notifications; }; #endif // NOTIFICATIONMONITOR_H -- cgit v1.2.3