KCM updated when pairing state changes externally

Added an unpaired() signal to KDED's Device exported by dbus
This commit is contained in:
Albert Vaca 2013-09-16 16:52:40 +02:00
parent dfe6c1273a
commit 2054288cac
4 changed files with 49 additions and 20 deletions

View file

@ -89,6 +89,15 @@ void KdeConnectKcm::resetSelection()
void KdeConnectKcm::deviceSelected(const QModelIndex& current) 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 //Store previous device config
pluginsConfigChanged(); pluginsConfigChanged();
@ -134,6 +143,13 @@ void KdeConnectKcm::deviceSelected(const QModelIndex& current)
kcmUi->name_label->setText(currentDevice->name()); kcmUi->name_label->setText(currentDevice->name());
kcmUi->status_label->setText(currentDevice->isPaired()? i18n("(paired)") : i18n("(unpaired)")); 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"); KService::List offers = KServiceTypeTrader::self()->query("KdeConnect/Plugin");
QList<KPluginInfo> scriptinfos = KPluginInfo::fromServices(offers); QList<KPluginInfo> scriptinfos = KPluginInfo::fromServices(offers);
@ -143,64 +159,72 @@ void KdeConnectKcm::deviceSelected(const QModelIndex& current)
connect(kcmUi->pluginSelector, SIGNAL(changed(bool)), connect(kcmUi->pluginSelector, SIGNAL(changed(bool)),
this, SLOT(pluginsConfigChanged())); this, SLOT(pluginsConfigChanged()));
} }
void KdeConnectKcm::requestPair() void KdeConnectKcm::requestPair()
{ {
if (!currentDevice) return; if (!currentDevice) {
return;
}
kcmUi->messages->hide(); kcmUi->messages->hide();
kcmUi->pair_button->setVisible(false); kcmUi->pair_button->setVisible(false);
kcmUi->progressBar->setVisible(true); kcmUi->progressBar->setVisible(true);
connect(currentDevice,SIGNAL(pairingSuccesful()),
this, SLOT(pairingSuccesful()));
connect(currentDevice,SIGNAL(pairingFailed(QString)),
this, SLOT(pairingFailed(QString)));
currentDevice->requestPair(); currentDevice->requestPair();
} }
void KdeConnectKcm::unpair() 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->pair_button->setVisible(true);
kcmUi->unpair_button->setVisible(false); kcmUi->unpair_button->setVisible(false);
kcmUi->progressBar->setVisible(false); kcmUi->progressBar->setVisible(false);
kcmUi->ping_button->setVisible(false); kcmUi->ping_button->setVisible(false);
currentDevice->unpair();
kcmUi->status_label->setText(i18n("(unpaired)")); kcmUi->status_label->setText(i18n("(unpaired)"));
devicesModel->deviceStatusChanged(currentDevice->id());
} }
void KdeConnectKcm::pairingFailed(const QString& error) void KdeConnectKcm::pairingFailed(const QString& error)
{ {
if (sender() != currentDevice) return; 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->setText(i18n("Error trying to pair: %1",error));
kcmUi->messages->animatedShow(); kcmUi->messages->animatedShow();
kcmUi->progressBar->setVisible(false);
kcmUi->pair_button->setVisible(true);
} }
void KdeConnectKcm::pairingSuccesful() void KdeConnectKcm::pairingSuccesful()
{ {
DeviceDbusInterface* sender = (DeviceDbusInterface*) sender(); DeviceDbusInterface* senderDevice = (DeviceDbusInterface*) sender();
devicesModel->deviceStatusChanged(sender->id()); 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->pair_button->setVisible(false);
kcmUi->unpair_button->setVisible(true);
kcmUi->progressBar->setVisible(false);
kcmUi->ping_button->setVisible(true); kcmUi->ping_button->setVisible(true);
kcmUi->status_label->setText(i18n("(paired)")); kcmUi->status_label->setText(i18n("(paired)"));
} }

View file

@ -61,6 +61,7 @@ private Q_SLOTS:
void resetSelection(); void resetSelection();
void pairingSuccesful(); void pairingSuccesful();
void pairingFailed(const QString& error); void pairingFailed(const QString& error);
void unpaired();
private: private:
Ui::KdeConnectKcmUi* kcmUi; Ui::KdeConnectKcmUi* kcmUi;

View file

@ -177,6 +177,8 @@ void Device::unpair()
reloadPlugins(); //Will unload the plugins reloadPlugins(); //Will unload the plugins
Q_EMIT unpaired();
} }
void Device::pairingTimeout() void Device::pairingTimeout()
@ -333,6 +335,7 @@ void Device::privateReceivedPackage(const NetworkPackage& np)
KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnectrc"); KSharedConfigPtr config = KSharedConfig::openConfig("kdeconnectrc");
config->group("trusted_devices").deleteGroup(id()); config->group("trusted_devices").deleteGroup(id());
reloadPlugins(); reloadPlugins();
Q_EMIT unpaired();
} }
m_pairStatus = Device::NotPaired; m_pairStatus = Device::NotPaired;

View file

@ -100,6 +100,7 @@ Q_SIGNALS:
Q_SCRIPTABLE void pluginsChanged(); Q_SCRIPTABLE void pluginsChanged();
Q_SCRIPTABLE void pairingSuccesful(); Q_SCRIPTABLE void pairingSuccesful();
Q_SCRIPTABLE void pairingFailed(const QString& error); Q_SCRIPTABLE void pairingFailed(const QString& error);
Q_SCRIPTABLE void unpaired();
private: private:
QString m_deviceId; QString m_deviceId;