Mark incompatible plugins as such in the kcm

If a plugin isn't available, display it as unsupported by the device. This
is figured out through capabilities.

Reviewed by Albert Vaca
This commit is contained in:
Aleix Pol 2015-09-07 18:50:26 +02:00
parent c37cc90762
commit 91351773fd
3 changed files with 23 additions and 3 deletions

View file

@ -111,6 +111,7 @@ void Device::reloadPlugins()
QHash<QString, KdeConnectPlugin*> newPluginMap;
QMultiMap<QString, KdeConnectPlugin*> newPluginsByIncomingInterface;
QMultiMap<QString, KdeConnectPlugin*> newPluginsByOutgoingInterface;
QStringList missingPlugins;
if (isPaired() && isReachable()) { //Do not load any plugin for unpaired devices, nor useless loading them for unreachable devices
@ -145,7 +146,9 @@ void Device::reloadPlugins()
&& (m_incomingCapabilities & outgoingInterfaces.toSet()).isEmpty()
&& (m_outgoingCapabilities & incomingInterfaces.toSet()).isEmpty()
) {
qCWarning(KDECONNECT_CORE) << "not loading " << pluginName << "because of unmatched capabilities";
delete plugin;
missingPlugins.append(pluginName);
continue;
}
@ -170,6 +173,7 @@ void Device::reloadPlugins()
m_plugins = newPluginMap;
m_pluginsByIncomingInterface = newPluginsByIncomingInterface;
m_pluginsByOutgoingInterface = newPluginsByOutgoingInterface;
m_missingPlugins = missingPlugins;
Q_FOREACH(KdeConnectPlugin* plugin, m_plugins) {
plugin->connected();

View file

@ -45,6 +45,7 @@ class KDECONNECTCORE_EXPORT Device
Q_PROPERTY(QString statusIconName READ statusIconName)
Q_PROPERTY(bool isReachable READ isReachable NOTIFY reachableStatusChanged)
Q_PROPERTY(bool isPaired READ isPaired NOTIFY pairingChanged)
Q_PROPERTY(QStringList missingPlugins READ missingPlugins NOTIFY pluginsChanged)
enum PairStatus {
NotPaired,
@ -86,6 +87,7 @@ public:
QString type() const { return type2str(m_deviceType); };
QString iconName() const;
QString statusIconName() const;
QStringList missingPlugins() const { return m_missingPlugins; }
//Add and remove links
void addLink(const NetworkPackage& identityPackage, DeviceLink*);
@ -154,7 +156,7 @@ private: //Fields (TODO: dPointer!)
QTimer m_pairingTimeut;
const QSet<QString> m_incomingCapabilities;
const QSet<QString> m_outgoingCapabilities;
QStringList m_missingPlugins;
};
Q_DECLARE_METATYPE(Device*)

View file

@ -213,9 +213,23 @@ void KdeConnectKcm::deviceSelected(const QModelIndex& current)
connect(currentDevice,SIGNAL(pairingFailed(QString)),
this, SLOT(pairingFailed(QString)));
const QList<KPluginInfo> pluginInfo = KPluginInfo::fromMetaData(KPluginLoader::findPlugins("kdeconnect/"));
QList<KPluginInfo> pluginInfo = KPluginInfo::fromMetaData(KPluginLoader::findPlugins("kdeconnect/"));
QList<KPluginInfo> missingPluginInfo;
QStringList missingPluginNames = currentDevice->missingPlugins();
missingPluginNames = QStringList("kdeconnect_mpriscontrol");
for (auto it = pluginInfo.begin(), itEnd = pluginInfo.end(); it!=itEnd; ) {
if (missingPluginNames.contains(it->pluginName())) {
missingPluginInfo.append(*it);
it = pluginInfo.erase(it);
} else {
++it;
}
}
KSharedConfigPtr deviceConfig = KSharedConfig::openConfig(currentDevice->pluginsConfigFile());
kcmUi->pluginSelector->addPlugins(pluginInfo, KPluginSelector::ReadConfigFile, i18n("Plugins"), QString(), deviceConfig);
kcmUi->pluginSelector->addPlugins(pluginInfo, KPluginSelector::ReadConfigFile, i18n("Available plugins"), QString(), deviceConfig);
kcmUi->pluginSelector->addPlugins(missingPluginInfo, KPluginSelector::ReadConfigFile, i18n("Plugins unsupported by the device"), QString(), deviceConfig);
connect(kcmUi->pluginSelector, SIGNAL(changed(bool)),
this, SLOT(pluginsConfigChanged()));