From 2707d1f0a840226c561eb2abc2841fd963c352ee Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Sat, 12 Sep 2015 19:43:15 +0200 Subject: [PATCH] Fix reload when changing current device on the kcm --- kcm/kcm.cpp | 68 +++++++++++++++++++++++++++-------------------------- kcm/kcm.h | 2 ++ 2 files changed, 37 insertions(+), 33 deletions(-) diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp index 85dfcc641..98d5bb63d 100644 --- a/kcm/kcm.cpp +++ b/kcm/kcm.cpp @@ -172,15 +172,6 @@ void KdeConnectKcm::deviceSelected(const QModelIndex& current) currentIndex = sortProxyModel->mapToSource(current); currentDevice = devicesModel->getDevice(currentIndex.row()); - resetCurrentDevice(); - - connect(currentDevice, SIGNAL(pluginsChanged()), this, SLOT(resetCurrentDevice())); - connect(currentDevice, SIGNAL(pairingChanged(bool)), this, SLOT(pairingChanged(bool))); - connect(currentDevice, SIGNAL(pairingFailed(QString)), this, SLOT(pairingFailed(QString))); -} - -void KdeConnectKcm::resetCurrentDevice() -{ kcmUi->noDevicePlaceholder->setVisible(false); bool valid = (currentDevice != nullptr && currentDevice->isValid()); kcmUi->deviceInfo->setVisible(valid); @@ -206,41 +197,52 @@ void KdeConnectKcm::resetCurrentDevice() kcmUi->ping_button->setVisible(false); } } + resetDeviceView(); + connect(currentDevice, SIGNAL(pluginsChanged()), this, SLOT(resetCurrentDevice())); + connect(currentDevice, SIGNAL(pairingChanged(bool)), this, SLOT(pairingChanged(bool))); + connect(currentDevice, SIGNAL(pairingFailed(QString)), this, SLOT(pairingFailed(QString))); +} + +void KdeConnectKcm::resetCurrentDevice() +{ const QStringList unsupportedPluginNames = currentDevice->unsupportedPlugins(); if (m_oldUnsupportedPluginNames != unsupportedPluginNames) { - //KPluginSelector has no way to remove a list of plugins and load another, so we need to destroy and recreate it each time - delete kcmUi->pluginSelector; - kcmUi->pluginSelector = new KPluginSelector(this); - kcmUi->deviceInfo_layout->addWidget(kcmUi->pluginSelector); + resetDeviceView(); + } +} - kcmUi->pluginSelector->setConfigurationArguments(QStringList(currentDevice->id())); +void KdeConnectKcm::resetDeviceView() +{ + //KPluginSelector has no way to remove a list of plugins and load another, so we need to destroy and recreate it each time + delete kcmUi->pluginSelector; + kcmUi->pluginSelector = new KPluginSelector(this); + kcmUi->deviceInfo_layout->addWidget(kcmUi->pluginSelector); - kcmUi->name_label->setText(currentDevice->name()); - kcmUi->status_label->setText(currentDevice->isPaired()? i18n("(paired)") : i18n("(unpaired)")); + kcmUi->pluginSelector->setConfigurationArguments(QStringList(currentDevice->id())); - const QList pluginInfo = KPluginInfo::fromMetaData(KPluginLoader::findPlugins("kdeconnect/")); - QList availablePluginInfo; - QList unsupportedPluginInfo; + kcmUi->name_label->setText(currentDevice->name()); + kcmUi->status_label->setText(currentDevice->isPaired()? i18n("(paired)") : i18n("(unpaired)")); - for (auto it = pluginInfo.cbegin(), itEnd = pluginInfo.cend(); it!=itEnd; ++it) { - if (unsupportedPluginNames.contains(it->pluginName())) { - unsupportedPluginInfo.append(*it); - } else { - availablePluginInfo.append(*it); - } + const QList pluginInfo = KPluginInfo::fromMetaData(KPluginLoader::findPlugins("kdeconnect/")); + QList availablePluginInfo; + QList unsupportedPluginInfo; + + m_oldUnsupportedPluginNames = currentDevice->unsupportedPlugins(); + for (auto it = pluginInfo.cbegin(), itEnd = pluginInfo.cend(); it!=itEnd; ++it) { + if (m_oldUnsupportedPluginNames.contains(it->pluginName())) { + unsupportedPluginInfo.append(*it); + } else { + availablePluginInfo.append(*it); } - - KSharedConfigPtr deviceConfig = KSharedConfig::openConfig(currentDevice->pluginsConfigFile()); - kcmUi->pluginSelector->addPlugins(availablePluginInfo, KPluginSelector::ReadConfigFile, i18n("Available plugins"), QString(), deviceConfig); - kcmUi->pluginSelector->addPlugins(unsupportedPluginInfo, KPluginSelector::ReadConfigFile, i18n("Plugins unsupported by the device"), QString(), deviceConfig); - - m_oldUnsupportedPluginNames = unsupportedPluginNames; } - connect(kcmUi->pluginSelector, SIGNAL(changed(bool)), - this, SLOT(pluginsConfigChanged())); + KSharedConfigPtr deviceConfig = KSharedConfig::openConfig(currentDevice->pluginsConfigFile()); + kcmUi->pluginSelector->addPlugins(availablePluginInfo, KPluginSelector::ReadConfigFile, i18n("Available plugins"), QString(), deviceConfig); + kcmUi->pluginSelector->addPlugins(unsupportedPluginInfo, KPluginSelector::ReadConfigFile, i18n("Plugins unsupported by the device"), QString(), deviceConfig); + connect(kcmUi->pluginSelector, SIGNAL(changed(bool)), this, SLOT(pluginsConfigChanged())); + } void KdeConnectKcm::requestPair() diff --git a/kcm/kcm.h b/kcm/kcm.h index 38873fee7..890b2bec0 100644 --- a/kcm/kcm.h +++ b/kcm/kcm.h @@ -62,6 +62,8 @@ private Q_SLOTS: void resetCurrentDevice(); private: + void resetDeviceView(); + Ui::KdeConnectKcmUi* kcmUi; DaemonDbusInterface* daemon; DevicesModel* devicesModel;