KDE Connect Devices list auto updating

This commit is contained in:
Victor Tran 2018-05-13 11:01:17 +10:00
parent 9828b0f67c
commit 04f3b7c18d
No known key found for this signature in database
GPG key ID: FBA10B22D602BAC1
2 changed files with 21 additions and 0 deletions

View file

@ -9,16 +9,34 @@ KdeConnectDevicesModel::KdeConnectDevicesModel(QObject *parent)
QDBusConnection::sessionBus().connect("org.kde.kdeconnect", "/modules/kdeconnect", "org.kde.kdeconnect.daemon", "deviceAdded", this, SLOT(updateData()));
QDBusConnection::sessionBus().connect("org.kde.kdeconnect", "/modules/kdeconnect", "org.kde.kdeconnect.daemon", "deviceRemoved", this, SLOT(updateData()));
QDBusConnection::sessionBus().connect("org.kde.kdeconnect", "/modules/kdeconnect", "org.kde.kdeconnect.daemon", "deviceRemoved", this, SLOT(deviceVisibilityChanged()));
updateData();
}
void KdeConnectDevicesModel::updateData() {
for (QString device : devices) {
QDBusConnection::sessionBus().disconnect("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + device, "org.kde.kdeconnect.device", "reachableChanged", this, SLOT(updateData()));
QDBusConnection::sessionBus().disconnect("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + device, "org.kde.kdeconnect.device", "pluginsChanged", this, SLOT(updateData()));
QDBusConnection::sessionBus().disconnect("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + device, "org.kde.kdeconnect.device", "trustedChanged", this, SLOT(updateData()));
QDBusConnection::sessionBus().disconnect("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + device, "org.kde.kdeconnect.device", "nameChanged", this, SLOT(updateData()));
QDBusConnection::sessionBus().disconnect("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + device, "org.kde.kdeconnect.device", "hasPairingRequestsChanged", this, SLOT(updateData()));
}
if (daemon->isValid()) {
devices = daemon->call("devices", false, false).arguments().first().toStringList();
} else {
devices.clear();
}
for (QString device : devices) {
QDBusConnection::sessionBus().connect("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + device, "org.kde.kdeconnect.device", "reachableChanged", this, SLOT(updateData()));
QDBusConnection::sessionBus().connect("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + device, "org.kde.kdeconnect.device", "pluginsChanged", this, SLOT(updateData()));
QDBusConnection::sessionBus().connect("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + device, "org.kde.kdeconnect.device", "trustedChanged", this, SLOT(updateData()));
QDBusConnection::sessionBus().connect("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + device, "org.kde.kdeconnect.device", "nameChanged", this, SLOT(updateData()));
QDBusConnection::sessionBus().connect("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + device, "org.kde.kdeconnect.device", "hasPairingRequestsChanged", this, SLOT(updateData()));
}
this->dataChanged(this->index(0), this->index(this->rowCount()));
}

View file

@ -46,12 +46,14 @@ void KdeConnectWidget::kdeConnectGone() {
devicesModel->updateData();
ui->announcedName->setText(tr("KDE Connect is not running"));
ui->panes->setCurrentIndex(5);
ui->devicesView->clearSelection();
}
void KdeConnectWidget::selectedDeviceChanged(QModelIndex current, QModelIndex previous) {
Q_UNUSED(previous)
if (currentId != "") {
QDBusConnection::sessionBus().disconnect("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + currentId, "org.kde.kdeconnect.device", "reachableChanged", this, SLOT(updateCurrentDevice()));
QDBusConnection::sessionBus().disconnect("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + currentId, "org.kde.kdeconnect.device", "pluginsChanged", this, SLOT(updateCurrentDevice()));
QDBusConnection::sessionBus().disconnect("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + currentId, "org.kde.kdeconnect.device", "trustedChanged", this, SLOT(updateCurrentDevice()));
QDBusConnection::sessionBus().disconnect("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + currentId, "org.kde.kdeconnect.device", "nameChanged", this, SLOT(updateCurrentDevice()));
@ -62,6 +64,7 @@ void KdeConnectWidget::selectedDeviceChanged(QModelIndex current, QModelIndex pr
ui->panes->setCurrentIndex(1);
currentId = current.data(Qt::UserRole + 1).toString();
QDBusConnection::sessionBus().connect("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + currentId, "org.kde.kdeconnect.device", "reachableChanged", this, SLOT(updateCurrentDevice()));
QDBusConnection::sessionBus().connect("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + currentId, "org.kde.kdeconnect.device", "pluginsChanged", this, SLOT(updateCurrentDevice()));
QDBusConnection::sessionBus().connect("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + currentId, "org.kde.kdeconnect.device", "trustedChanged", this, SLOT(updateCurrentDevice()));
QDBusConnection::sessionBus().connect("org.kde.kdeconnect", "/modules/kdeconnect/devices/" + currentId, "org.kde.kdeconnect.device", "nameChanged", this, SLOT(updateCurrentDevice()));