Commit 844a92a5 authored by Albert Vaca Cintora's avatar Albert Vaca Cintora

KCM updated when pairing state changes externally

Added an unpaired() signal to KDED's Device exported by dbus
parent 29271df3
......@@ -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<KPluginInfo> 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)"));
}
......
......@@ -61,6 +61,7 @@ private Q_SLOTS:
void resetSelection();
void pairingSuccesful();
void pairingFailed(const QString& error);
void unpaired();
private:
Ui::KdeConnectKcmUi* kcmUi;
......
......@@ -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;
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment