Fixed outging capabilities

This commit is contained in:
Albert Vaca 2015-09-12 08:48:24 -07:00
parent 3269b7a9c2
commit 217d4b60ff
2 changed files with 8 additions and 4 deletions

View file

@ -110,6 +110,7 @@ void Device::reloadPlugins()
QMultiMap<QString, KdeConnectPlugin*> newPluginsByIncomingInterface;
QMultiMap<QString, KdeConnectPlugin*> newPluginsByOutgoingInterface;
QSet<QString> supportedIncomingInterfaces;
QSet<QString> supportedOutgoingInterfaces;
QStringList unsupportedPlugins;
if (isPaired() && isReachable()) { //Do not load any plugin for unpaired devices, nor useless loading them for unreachable devices
@ -119,7 +120,6 @@ void Device::reloadPlugins()
PluginLoader* loader = PluginLoader::instance();
const bool deviceSupportsCapabilities = !m_incomingCapabilities.isEmpty() || !m_outgoingCapabilities.isEmpty();
//Code borrowed from KWin
foreach (const QString& pluginName, loader->getPluginList()) {
const KPluginMetaData service = loader->getPluginInfo(pluginName);
const QSet<QString> incomingInterfaces = KPluginMetaData::readStringList(service.rawData(), "X-KdeConnect-SupportedPackageType").toSet();
@ -129,13 +129,13 @@ void Device::reloadPlugins()
if (pluginEnabled) {
supportedIncomingInterfaces += incomingInterfaces;
supportedOutgoingInterfaces += outgoingInterfaces;
}
//If we don't find intersection with the received on one end and the sent on the other, we don't
//let the plugin stay
//Also, if no capabilities are specified on the other end, we don't apply this optimizaton, as
//we assume that the other client doesn't know about capabilities.
const bool capabilitiesSupported = deviceSupportsCapabilities && (!incomingInterfaces.isEmpty() || !outgoingInterfaces.isEmpty());
if (capabilitiesSupported
&& (m_incomingCapabilities & outgoingInterfaces).isEmpty()
@ -159,6 +159,7 @@ void Device::reloadPlugins()
foreach(const QString& interface, outgoingInterfaces) {
newPluginsByOutgoingInterface.insert(interface, plugin);
}
newPluginMap[pluginName] = plugin;
}
}
@ -167,12 +168,14 @@ void Device::reloadPlugins()
//Erase all left plugins in the original map (meaning that we don't want
//them anymore, otherwise they would have been moved to the newPluginMap)
const QStringList newSupportedIncomingInterfaces = supportedIncomingInterfaces.toList();
const QStringList newSupportedOutgoingInterfaces = supportedOutgoingInterfaces.toList();
const bool capabilitiesChanged = (m_pluginsByOutgoingInterface != newPluginsByOutgoingInterface
|| m_supportedIncomingInterfaces != newSupportedIncomingInterfaces);
qDeleteAll(m_plugins);
m_plugins = newPluginMap;
m_pluginsByOutgoingInterface = newPluginsByOutgoingInterface;
m_supportedIncomingInterfaces = newSupportedIncomingInterfaces;
m_supportedOutgoingInterfaces = newSupportedOutgoingInterfaces;
m_pluginsByOutgoingInterface = newPluginsByOutgoingInterface;
m_pluginsByIncomingInterface = newPluginsByIncomingInterface;
m_unsupportedPlugins = unsupportedPlugins;
@ -185,7 +188,7 @@ void Device::reloadPlugins()
{
NetworkPackage np(PACKAGE_TYPE_CAPABILITIES);
np.set<QStringList>("IncomingCapabilities", newSupportedIncomingInterfaces);
np.set<QStringList>("OutgoingCapabilities", newPluginsByOutgoingInterface.keys());
np.set<QStringList>("OutgoingCapabilities", newSupportedOutgoingInterfaces);
sendPackage(np);
}
}

View file

@ -159,6 +159,7 @@ private: //Fields (TODO: dPointer!)
QSet<QString> m_incomingCapabilities;
QSet<QString> m_outgoingCapabilities;
QStringList m_supportedIncomingInterfaces;
QStringList m_supportedOutgoingInterfaces;
QStringList m_unsupportedPlugins;
};