KCM updated when pairing state changes externally
Added an unpaired() signal to KDED's Device exported by dbus
This commit is contained in:
parent
95cbc13fa9
commit
f8825e013e
4 changed files with 49 additions and 20 deletions
64
kcm/kcm.cpp
64
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<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()
|
||||
|
@ -344,6 +346,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;
|
||||
|
|
Loading…
Reference in a new issue