Fix reload when changing current device on the kcm

This commit is contained in:
Aleix Pol 2015-09-12 19:43:15 +02:00
parent 217d4b60ff
commit 2707d1f0a8
2 changed files with 37 additions and 33 deletions

View file

@ -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<KPluginInfo> pluginInfo = KPluginInfo::fromMetaData(KPluginLoader::findPlugins("kdeconnect/"));
QList<KPluginInfo> availablePluginInfo;
QList<KPluginInfo> 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<KPluginInfo> pluginInfo = KPluginInfo::fromMetaData(KPluginLoader::findPlugins("kdeconnect/"));
QList<KPluginInfo> availablePluginInfo;
QList<KPluginInfo> 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()

View file

@ -62,6 +62,8 @@ private Q_SLOTS:
void resetCurrentDevice();
private:
void resetDeviceView();
Ui::KdeConnectKcmUi* kcmUi;
DaemonDbusInterface* daemon;
DevicesModel* devicesModel;