From 06493a8192410095892b738902f3f68878814cd4 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Thu, 25 Jun 2015 21:19:23 +0200 Subject: [PATCH] Keep track of whether the daemon is alive Listen to dbus registrations. Remove all devices if the service dies, create all devices back when restored. Same for the NotificationsModel. REVIEW: 124183 --- interfaces/dbusinterfaces.cpp | 16 ++++++++-------- interfaces/dbusinterfaces.h | 2 ++ interfaces/devicesmodel.cpp | 6 ++++++ interfaces/notificationsmodel.cpp | 6 ++++++ 4 files changed, 22 insertions(+), 8 deletions(-) diff --git a/interfaces/dbusinterfaces.cpp b/interfaces/dbusinterfaces.cpp index a89f7a08c..68b4c64ae 100644 --- a/interfaces/dbusinterfaces.cpp +++ b/interfaces/dbusinterfaces.cpp @@ -20,14 +20,14 @@ #include "dbusinterfaces.h" -QString activatedService() { +QString DaemonDbusInterface::activatedService() { static const QString service = "org.kde.kdeconnect"; QDBusConnection::sessionBus().interface()->startService(service); return service; } DaemonDbusInterface::DaemonDbusInterface(QObject* parent) - : OrgKdeKdeconnectDaemonInterface(activatedService(), "/modules/kdeconnect", QDBusConnection::sessionBus(), parent) + : OrgKdeKdeconnectDaemonInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect", QDBusConnection::sessionBus(), parent) { } @@ -38,7 +38,7 @@ DaemonDbusInterface::~DaemonDbusInterface() } DeviceDbusInterface::DeviceDbusInterface(const QString& id, QObject* parent) - : OrgKdeKdeconnectDeviceInterface(activatedService(), "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent) + : OrgKdeKdeconnectDeviceInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent) , m_id(id) { connect(this, &OrgKdeKdeconnectDeviceInterface::pairingChanged, this, &DeviceDbusInterface::pairingChangedProxy); @@ -61,7 +61,7 @@ void DeviceDbusInterface::pluginCall(const QString &plugin, const QString &metho } DeviceBatteryDbusInterface::DeviceBatteryDbusInterface(const QString& id, QObject* parent) - : OrgKdeKdeconnectDeviceBatteryInterface(activatedService(), "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent) + : OrgKdeKdeconnectDeviceBatteryInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent) { } @@ -72,7 +72,7 @@ DeviceBatteryDbusInterface::~DeviceBatteryDbusInterface() } DeviceNotificationsDbusInterface::DeviceNotificationsDbusInterface(const QString& id, QObject* parent) - : OrgKdeKdeconnectDeviceNotificationsInterface(activatedService(), "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent) + : OrgKdeKdeconnectDeviceNotificationsInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/"+id, QDBusConnection::sessionBus(), parent) { } @@ -83,7 +83,7 @@ DeviceNotificationsDbusInterface::~DeviceNotificationsDbusInterface() } NotificationDbusInterface::NotificationDbusInterface(const QString& deviceId, const QString& notificationId, QObject* parent) - : OrgKdeKdeconnectDeviceNotificationsNotificationInterface(activatedService(), "/modules/kdeconnect/devices/"+deviceId+"/notifications/"+notificationId, QDBusConnection::sessionBus(), parent) + : OrgKdeKdeconnectDeviceNotificationsNotificationInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/"+deviceId+"/notifications/"+notificationId, QDBusConnection::sessionBus(), parent) { } @@ -94,7 +94,7 @@ NotificationDbusInterface::~NotificationDbusInterface() } SftpDbusInterface::SftpDbusInterface(const QString& id, QObject* parent) - : OrgKdeKdeconnectDeviceSftpInterface(activatedService(), "/modules/kdeconnect/devices/" + id + "/sftp", QDBusConnection::sessionBus(), parent) + : OrgKdeKdeconnectDeviceSftpInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + id + "/sftp", QDBusConnection::sessionBus(), parent) { } @@ -105,7 +105,7 @@ SftpDbusInterface::~SftpDbusInterface() } MprisDbusInterface::MprisDbusInterface(const QString& id, QObject* parent) - : OrgKdeKdeconnectDeviceMprisremoteInterface(activatedService(), "/modules/kdeconnect/devices/" + id + "/mprisremote", QDBusConnection::sessionBus(), parent) + : OrgKdeKdeconnectDeviceMprisremoteInterface(DaemonDbusInterface::activatedService(), "/modules/kdeconnect/devices/" + id + "/mprisremote", QDBusConnection::sessionBus(), parent) { connect(this, &OrgKdeKdeconnectDeviceMprisremoteInterface::propertiesChanged, this, &MprisDbusInterface::propertiesChangedProxy); } diff --git a/interfaces/dbusinterfaces.h b/interfaces/dbusinterfaces.h index 260a0e693..d42a28f9e 100644 --- a/interfaces/dbusinterfaces.h +++ b/interfaces/dbusinterfaces.h @@ -42,6 +42,8 @@ class KDECONNECTINTERFACES_EXPORT DaemonDbusInterface public: DaemonDbusInterface(QObject* parent = 0); virtual ~DaemonDbusInterface(); + + static QString activatedService(); }; class KDECONNECTINTERFACES_EXPORT DeviceDbusInterface diff --git a/interfaces/devicesmodel.cpp b/interfaces/devicesmodel.cpp index 6e41699a6..3ac68ab4c 100644 --- a/interfaces/devicesmodel.cpp +++ b/interfaces/devicesmodel.cpp @@ -27,6 +27,7 @@ #include #include #include +#include #include "dbusinterfaces.h" // #include "modeltest.h" @@ -53,6 +54,11 @@ DevicesModel::DevicesModel(QObject *parent) connect(m_dbusInterface, SIGNAL(deviceRemoved(QString)), this, SLOT(deviceRemoved(QString))); + QDBusServiceWatcher* watcher = new QDBusServiceWatcher(DaemonDbusInterface::activatedService(), + QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this); + connect(watcher, &QDBusServiceWatcher::serviceRegistered, this, &DevicesModel::refreshDeviceList); + connect(watcher, &QDBusServiceWatcher::serviceUnregistered, this, &DevicesModel::clearDevices); + refreshDeviceList(); } diff --git a/interfaces/notificationsmodel.cpp b/interfaces/notificationsmodel.cpp index 9c6d38dd6..aba45732d 100644 --- a/interfaces/notificationsmodel.cpp +++ b/interfaces/notificationsmodel.cpp @@ -44,6 +44,12 @@ NotificationsModel::NotificationsModel(QObject* parent) connect(this, SIGNAL(dataChanged(QModelIndex, QModelIndex)), this, SIGNAL(anyDismissableChanged())); + + + QDBusServiceWatcher* watcher = new QDBusServiceWatcher(DaemonDbusInterface::activatedService(), + QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this); + connect(watcher, &QDBusServiceWatcher::serviceRegistered, this, &NotificationsModel::refreshNotificationList); + connect(watcher, &QDBusServiceWatcher::serviceUnregistered, this, &NotificationsModel::clearNotifications); } QHash NotificationsModel::roleNames() const