diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp index b4be11d5a..7ad6814bc 100644 --- a/kcm/kcm.cpp +++ b/kcm/kcm.cpp @@ -89,6 +89,15 @@ void KdeConnectKcm::resetSelection() void KdeConnectKcm::deviceSelected(const QModelIndex& current) { + if (currentDevice) { + disconnect(currentDevice,SIGNAL(pairingSuccesful()), + this, SLOT(pairingSuccesful())); + disconnect(currentDevice,SIGNAL(pairingFailed(QString)), + this, SLOT(pairingFailed(QString))); + disconnect(currentDevice,SIGNAL(unpaired()), + this, SLOT(unpaired())); + } + //Store previous device config pluginsConfigChanged(); @@ -134,6 +143,13 @@ void KdeConnectKcm::deviceSelected(const QModelIndex& current) kcmUi->name_label->setText(currentDevice->name()); kcmUi->status_label->setText(currentDevice->isPaired()? i18n("(paired)") : i18n("(unpaired)")); + connect(currentDevice,SIGNAL(pairingSuccesful()), + this, SLOT(pairingSuccesful())); + connect(currentDevice,SIGNAL(pairingFailed(QString)), + this, SLOT(pairingFailed(QString))); + connect(currentDevice,SIGNAL(unpaired()), + this, SLOT(unpaired())); + KService::List offers = KServiceTypeTrader::self()->query("KdeConnect/Plugin"); QList scriptinfos = KPluginInfo::fromServices(offers); @@ -143,64 +159,72 @@ void KdeConnectKcm::deviceSelected(const QModelIndex& current) connect(kcmUi->pluginSelector, SIGNAL(changed(bool)), this, SLOT(pluginsConfigChanged())); + } void KdeConnectKcm::requestPair() { - if (!currentDevice) return; + if (!currentDevice) { + return; + } kcmUi->messages->hide(); kcmUi->pair_button->setVisible(false); kcmUi->progressBar->setVisible(true); - connect(currentDevice,SIGNAL(pairingSuccesful()), - this, SLOT(pairingSuccesful())); - connect(currentDevice,SIGNAL(pairingFailed(QString)), - this, SLOT(pairingFailed(QString))); - currentDevice->requestPair(); } void KdeConnectKcm::unpair() { - if (!currentDevice) return; + if (!currentDevice) { + return; + } + + currentDevice->unpair(); +} + +void KdeConnectKcm::unpaired() +{ + DeviceDbusInterface* senderDevice = (DeviceDbusInterface*) sender(); + devicesModel->deviceStatusChanged(senderDevice->id()); + + if (senderDevice != currentDevice) return; kcmUi->pair_button->setVisible(true); kcmUi->unpair_button->setVisible(false); kcmUi->progressBar->setVisible(false); kcmUi->ping_button->setVisible(false); - - currentDevice->unpair(); - kcmUi->status_label->setText(i18n("(unpaired)")); - - devicesModel->deviceStatusChanged(currentDevice->id()); } void KdeConnectKcm::pairingFailed(const QString& error) { if (sender() != currentDevice) return; + kcmUi->pair_button->setVisible(true); + kcmUi->unpair_button->setVisible(false); + kcmUi->progressBar->setVisible(false); + kcmUi->ping_button->setVisible(false); + kcmUi->status_label->setText(i18n("(unpaired)")); + kcmUi->messages->setText(i18n("Error trying to pair: %1",error)); kcmUi->messages->animatedShow(); - kcmUi->progressBar->setVisible(false); - kcmUi->pair_button->setVisible(true); } void KdeConnectKcm::pairingSuccesful() { - DeviceDbusInterface* sender = (DeviceDbusInterface*) sender(); - devicesModel->deviceStatusChanged(sender->id()); + DeviceDbusInterface* senderDevice = (DeviceDbusInterface*) sender(); + devicesModel->deviceStatusChanged(senderDevice->id()); - if (sender != currentDevice) return; + if (senderDevice != currentDevice) return; - kcmUi->progressBar->setVisible(false); - kcmUi->unpair_button->setVisible(true); kcmUi->pair_button->setVisible(false); + kcmUi->unpair_button->setVisible(true); + kcmUi->progressBar->setVisible(false); kcmUi->ping_button->setVisible(true); - kcmUi->status_label->setText(i18n("(paired)")); } diff --git a/kcm/kcm.h b/kcm/kcm.h index 32aac2063..072c544bc 100644 --- a/kcm/kcm.h +++ b/kcm/kcm.h @@ -61,6 +61,7 @@ private Q_SLOTS: void resetSelection(); void pairingSuccesful(); void pairingFailed(const QString& error); + void unpaired(); private: Ui::KdeConnectKcmUi* kcmUi; diff --git a/kded/device.cpp b/kded/device.cpp index b67b3dafa..b13a1bdb2 100644 --- a/kded/device.cpp +++ b/kded/device.cpp @@ -177,6 +177,8 @@ void Device::unpair() reloadPlugins(); //Will unload the plugins + Q_EMIT unpaired(); + } void Device::pairingTimeout() @@ -333,6 +335,7 @@ void Device::privateReceivedPackage(const NetworkPackage& np) KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnectrc"); config->group("trusted_devices").deleteGroup(id()); reloadPlugins(); + Q_EMIT unpaired(); } m_pairStatus = Device::NotPaired; diff --git a/kded/device.h b/kded/device.h index a017db17e..f7e8e6817 100644 --- a/kded/device.h +++ b/kded/device.h @@ -100,6 +100,7 @@ Q_SIGNALS: Q_SCRIPTABLE void pluginsChanged(); Q_SCRIPTABLE void pairingSuccesful(); Q_SCRIPTABLE void pairingFailed(const QString& error); + Q_SCRIPTABLE void unpaired(); private: QString m_deviceId;