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:
parent
320779b719
commit
06493a8192
4 changed files with 22 additions and 8 deletions
|
@ -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);
|
||||
}
|
||||
|
|
|
@ -42,6 +42,8 @@ class KDECONNECTINTERFACES_EXPORT DaemonDbusInterface
|
|||
public:
|
||||
DaemonDbusInterface(QObject* parent = 0);
|
||||
virtual ~DaemonDbusInterface();
|
||||
|
||||
static QString activatedService();
|
||||
};
|
||||
|
||||
class KDECONNECTINTERFACES_EXPORT DeviceDbusInterface
|
||||
|
|
|
@ -27,6 +27,7 @@
|
|||
#include <QDBusInterface>
|
||||
#include <QDBusPendingReply>
|
||||
#include <QIcon>
|
||||
#include <QDBusServiceWatcher>
|
||||
|
||||
#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();
|
||||
}
|
||||
|
||||
|
|
|
@ -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<int, QByteArray> NotificationsModel::roleNames() const
|
||||
|
|
Loading…
Reference in a new issue