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
This commit is contained in:
Aleix Pol 2015-06-25 21:19:23 +02:00
parent 320779b719
commit 06493a8192
4 changed files with 22 additions and 8 deletions

View file

@ -20,14 +20,14 @@
#include "dbusinterfaces.h" #include "dbusinterfaces.h"
QString activatedService() { QString DaemonDbusInterface::activatedService() {
static const QString service = "org.kde.kdeconnect"; static const QString service = "org.kde.kdeconnect";
QDBusConnection::sessionBus().interface()->startService(service); QDBusConnection::sessionBus().interface()->startService(service);
return service; return service;
} }
DaemonDbusInterface::DaemonDbusInterface(QObject* parent) 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) 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) , m_id(id)
{ {
connect(this, &OrgKdeKdeconnectDeviceInterface::pairingChanged, this, &DeviceDbusInterface::pairingChangedProxy); 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) 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) 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) 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) 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) 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); connect(this, &OrgKdeKdeconnectDeviceMprisremoteInterface::propertiesChanged, this, &MprisDbusInterface::propertiesChangedProxy);
} }

View file

@ -42,6 +42,8 @@ class KDECONNECTINTERFACES_EXPORT DaemonDbusInterface
public: public:
DaemonDbusInterface(QObject* parent = 0); DaemonDbusInterface(QObject* parent = 0);
virtual ~DaemonDbusInterface(); virtual ~DaemonDbusInterface();
static QString activatedService();
}; };
class KDECONNECTINTERFACES_EXPORT DeviceDbusInterface class KDECONNECTINTERFACES_EXPORT DeviceDbusInterface

View file

@ -27,6 +27,7 @@
#include <QDBusInterface> #include <QDBusInterface>
#include <QDBusPendingReply> #include <QDBusPendingReply>
#include <QIcon> #include <QIcon>
#include <QDBusServiceWatcher>
#include "dbusinterfaces.h" #include "dbusinterfaces.h"
// #include "modeltest.h" // #include "modeltest.h"
@ -53,6 +54,11 @@ DevicesModel::DevicesModel(QObject *parent)
connect(m_dbusInterface, SIGNAL(deviceRemoved(QString)), connect(m_dbusInterface, SIGNAL(deviceRemoved(QString)),
this, SLOT(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(); refreshDeviceList();
} }

View file

@ -44,6 +44,12 @@ NotificationsModel::NotificationsModel(QObject* parent)
connect(this, SIGNAL(dataChanged(QModelIndex, QModelIndex)), connect(this, SIGNAL(dataChanged(QModelIndex, QModelIndex)),
this, SIGNAL(anyDismissableChanged())); 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<int, QByteArray> NotificationsModel::roleNames() const QHash<int, QByteArray> NotificationsModel::roleNames() const