diff --git a/core/device.cpp b/core/device.cpp index 264e78b70..d2ceb8467 100644 --- a/core/device.cpp +++ b/core/device.cpp @@ -226,7 +226,7 @@ void Device::unpairInternal() m_pairStatus = Device::NotPaired; KdeConnectConfig::instance()->removeTrustedDevice(id()); reloadPlugins(); //Will unload the plugins - Q_EMIT unpaired(); + Q_EMIT pairingChanged(false); } void Device::pairingTimeout() @@ -440,7 +440,7 @@ void Device::setAsPaired() reloadPlugins(); //Will actually load the plugins - Q_EMIT pairingSuccesful(); + Q_EMIT pairingChanged(true); } diff --git a/core/device.h b/core/device.h index f1610c2ed..1512721c5 100644 --- a/core/device.h +++ b/core/device.h @@ -45,7 +45,7 @@ class KDECONNECTCORE_EXPORT Device Q_PROPERTY(QString iconName READ iconName CONSTANT) Q_PROPERTY(QString statusIconName READ statusIconName) Q_PROPERTY(bool isReachable READ isReachable NOTIFY reachableStatusChanged) - Q_PROPERTY(bool isPaired READ isPaired) + Q_PROPERTY(bool isPaired READ isPaired NOTIFY pairingChanged) enum PairStatus { NotPaired, @@ -123,9 +123,8 @@ private Q_SLOTS: Q_SIGNALS: Q_SCRIPTABLE void reachableStatusChanged(); Q_SCRIPTABLE void pluginsChanged(); - Q_SCRIPTABLE void pairingSuccesful(); + Q_SCRIPTABLE void pairingChanged(bool paired); Q_SCRIPTABLE void pairingFailed(const QString& error); - Q_SCRIPTABLE void unpaired(); Q_SCRIPTABLE void nameChanged(const QString& name); private: //Methods @@ -134,6 +133,7 @@ private: //Methods void unpairInternal(); void setAsPaired(); bool sendOwnPublicKey(); + void setPairing(PairStatus newPairing); private: //Fields (TODO: dPointer!) const QString m_deviceId; diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp index cf422e3bc..dc61e1d0b 100644 --- a/kcm/kcm.cpp +++ b/kcm/kcm.cpp @@ -140,12 +140,10 @@ void KdeConnectKcm::deviceSelected(const QModelIndex& current) kcmUi->noDevicePlaceholder->setVisible(false); if (currentDevice) { - disconnect(currentDevice,SIGNAL(pairingSuccesful()), - this, SLOT(pairingSuccesful())); + disconnect(currentDevice,SIGNAL(pairingChanged(bool)), + this, SLOT(pairingChanged(bool))); disconnect(currentDevice,SIGNAL(pairingFailed(QString)), this, SLOT(pairingFailed(QString))); - disconnect(currentDevice,SIGNAL(unpaired()), - this, SLOT(unpaired())); } //Store previous device config @@ -194,12 +192,10 @@ 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(pairingChanged(bool)), + this, SLOT(pairingChanged(bool))); connect(currentDevice,SIGNAL(pairingFailed(QString)), this, SLOT(pairingFailed(QString))); - connect(currentDevice,SIGNAL(unpaired()), - this, SLOT(unpaired())); const QList pluginInfo = KPluginInfo::fromMetaData(KPluginLoader::findPlugins("kdeconnect/")); KSharedConfigPtr deviceConfig = KSharedConfig::openConfig(currentDevice->pluginsConfigFile()); @@ -234,46 +230,28 @@ void KdeConnectKcm::unpair() 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); - kcmUi->status_label->setText(i18n("(unpaired)")); -} - 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)")); + pairingChanged(false); kcmUi->messages->setText(i18n("Error trying to pair: %1",error)); kcmUi->messages->animatedShow(); } -void KdeConnectKcm::pairingSuccesful() +void KdeConnectKcm::pairingChanged(bool pairing) { DeviceDbusInterface* senderDevice = (DeviceDbusInterface*) sender(); devicesModel->deviceStatusChanged(senderDevice->id()); if (senderDevice != currentDevice) return; - 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)")); + kcmUi->pair_button->setVisible(!pairing); + kcmUi->unpair_button->setVisible(pairing); + kcmUi->progressBar->setVisible(!pairing); + kcmUi->ping_button->setVisible(pairing); + kcmUi->status_label->setText(pairing ? i18n("(paired)") : i18n("(unpaired)")); } void KdeConnectKcm::pluginsConfigChanged() diff --git a/kcm/kcm.h b/kcm/kcm.h index 1c2b0dad7..75bcd9e6a 100644 --- a/kcm/kcm.h +++ b/kcm/kcm.h @@ -53,9 +53,8 @@ private Q_SLOTS: void pluginsConfigChanged(); void sendPing(); void resetSelection(); - void pairingSuccesful(); + void pairingChanged(bool); void pairingFailed(const QString& error); - void unpaired(); void refresh(); void renameShow(); void renameDone();