Document in the desktop files the outgoing types for the plugins

This way we narrow the things a plugin can send, to its own scope. Still
every plugin can set a list of types, so it should be ok.
This commit is contained in:
Aleix Pol 2014-06-14 20:35:00 +02:00
parent 9459001fbe
commit 6ce0b6b874
22 changed files with 65 additions and 29 deletions

View file

@ -105,7 +105,8 @@ QStringList Device::loadedPlugins() const
void Device::reloadPlugins() void Device::reloadPlugins()
{ {
QMap<QString, KdeConnectPlugin*> newPluginMap; QMap<QString, KdeConnectPlugin*> newPluginMap;
QMultiMap<QString, KdeConnectPlugin*> newPluginsByInterface; QMultiMap<QString, KdeConnectPlugin*> newPluginsByIncomingInterface;
QMultiMap<QString, KdeConnectPlugin*> newPluginsByOutgoingInterface;
if (isPaired() && isReachable()) { //Do not load any plugin for unpaired devices, nor useless loading them for unreachable devices if (isPaired() && isReachable()) { //Do not load any plugin for unpaired devices, nor useless loading them for unreachable devices
@ -123,16 +124,21 @@ void Device::reloadPlugins()
if (isPluginEnabled) { if (isPluginEnabled) {
KdeConnectPlugin* plugin = m_plugins.take(pluginName); KdeConnectPlugin* plugin = m_plugins.take(pluginName);
QStringList interfaces; QStringList incomingInterfaces, outgoingInterfaces;
if (plugin) { if (plugin) {
interfaces = m_pluginsByinterface.keys(plugin); incomingInterfaces = m_pluginsByIncomingInterface.keys(plugin);
outgoingInterfaces = m_pluginsByOutgoingInterface.keys(plugin);
} else { } else {
PluginData data = loader->instantiatePluginForDevice(pluginName, this); PluginData data = loader->instantiatePluginForDevice(pluginName, this);
plugin = data.plugin; plugin = data.plugin;
interfaces = data.interfaces; incomingInterfaces = data.incomingInterfaces;
outgoingInterfaces = data.outgoingInterfaces;
} }
foreach(const QString& interface, interfaces) { foreach(const QString& interface, incomingInterfaces) {
newPluginsByInterface.insert(interface, plugin); newPluginsByIncomingInterface.insert(interface, plugin);
}
foreach(const QString& interface, outgoingInterfaces) {
newPluginsByOutgoingInterface.insert(interface, plugin);
} }
newPluginMap[pluginName] = plugin; newPluginMap[pluginName] = plugin;
} }
@ -143,7 +149,8 @@ void Device::reloadPlugins()
//them anymore, otherwise they would have been moved to the newPluginMap) //them anymore, otherwise they would have been moved to the newPluginMap)
qDeleteAll(m_plugins); qDeleteAll(m_plugins);
m_plugins = newPluginMap; m_plugins = newPluginMap;
m_pluginsByinterface = newPluginsByInterface; m_pluginsByIncomingInterface = newPluginsByIncomingInterface;
m_pluginsByOutgoingInterface = newPluginsByOutgoingInterface;
Q_FOREACH(KdeConnectPlugin* plugin, m_plugins) { Q_FOREACH(KdeConnectPlugin* plugin, m_plugins) {
plugin->connected(); plugin->connected();
@ -377,7 +384,7 @@ void Device::privateReceivedPackage(const NetworkPackage& np)
} }
} else if (isPaired()) { } else if (isPaired()) {
QList<KdeConnectPlugin*> plugins = m_pluginsByinterface.values(np.type()); QList<KdeConnectPlugin*> plugins = m_pluginsByIncomingInterface.values(np.type());
foreach(KdeConnectPlugin* plugin, plugins) { foreach(KdeConnectPlugin* plugin, plugins) {
plugin->receivePackage(np); plugin->receivePackage(np);
} }

View file

@ -132,7 +132,8 @@ private:
QList<DeviceLink*> m_deviceLinks; QList<DeviceLink*> m_deviceLinks;
QMap<QString, KdeConnectPlugin*> m_plugins; QMap<QString, KdeConnectPlugin*> m_plugins;
QMultiMap<QString, KdeConnectPlugin*> m_pluginsByinterface; QMultiMap<QString, KdeConnectPlugin*> m_pluginsByIncomingInterface;
QMultiMap<QString, KdeConnectPlugin*> m_pluginsByOutgoingInterface;
QTimer m_pairingTimeut; QTimer m_pairingTimeut;

View file

@ -23,6 +23,7 @@
struct KdeConnectPluginPrivate struct KdeConnectPluginPrivate
{ {
Device* mDevice; Device* mDevice;
QSet<QString> mOutgoingTypes;
// The Initializer object sets things up, and also does cleanup when it goes out of scope // The Initializer object sets things up, and also does cleanup when it goes out of scope
// Since the plugins use their own memory, they need their own initializer in order to send encrypted packages // Since the plugins use their own memory, they need their own initializer in order to send encrypted packages
@ -34,13 +35,14 @@ KdeConnectPlugin::KdeConnectPlugin(QObject* parent, const QVariantList& args)
, d(new KdeConnectPluginPrivate) , d(new KdeConnectPluginPrivate)
{ {
d->mDevice = qvariant_cast< Device* >(args.first()); d->mDevice = qvariant_cast< Device* >(args.first());
d->mOutgoingTypes = args.last().toStringList().toSet();
} }
KdeConnectPlugin::~KdeConnectPlugin() KdeConnectPlugin::~KdeConnectPlugin()
{ {
} }
Device* KdeConnectPlugin::device() const Device* KdeConnectPlugin::device()
{ {
return d->mDevice; return d->mDevice;
} }
@ -49,3 +51,13 @@ Device const* KdeConnectPlugin::device() const
{ {
return d->mDevice; return d->mDevice;
} }
bool KdeConnectPlugin::sendPackage(NetworkPackage& np) const
{
if(!d->mOutgoingTypes.contains(np.type())) {
qWarning() << metaObject()->className() << "tried to send an unsupported package type" << np.type() << ". Supported:" << d->mOutgoingTypes;
return false;
}
// qWarning() << metaObject()->className() << "sends" << np.type() << ". Supported:" << d->mOutgoingTypes;
return d->mDevice->sendPackage(np);
}

View file

@ -42,9 +42,11 @@ public:
KdeConnectPlugin(QObject* parent, const QVariantList& args); KdeConnectPlugin(QObject* parent, const QVariantList& args);
virtual ~KdeConnectPlugin(); virtual ~KdeConnectPlugin();
Device* device(); const Device* device();
Device const* device() const; Device const* device() const;
bool sendPackage(NetworkPackage& np) const;
public Q_SLOTS: public Q_SLOTS:
/** /**
* Returns true if it has handled the package in some way * Returns true if it has handled the package in some way

View file

@ -73,12 +73,13 @@ PluginData PluginLoader::instantiatePluginForDevice(const QString& name, Device*
return ret; return ret;
} }
ret.interfaces = service->property("X-KdeConnect-SupportedPackageType", QVariant::StringList).toStringList(); ret.incomingInterfaces = service->property("X-KdeConnect-SupportedPackageType", QVariant::StringList).toStringList();
ret.outgoingInterfaces = service->property("X-KdeConnect-OutgoingPackageType", QVariant::StringList).toStringList();
QVariant deviceVariant = QVariant::fromValue<Device*>(device); QVariant deviceVariant = QVariant::fromValue<Device*>(device);
//FIXME any reason to use QObject in template param instead KdeConnectPlugin? //FIXME any reason to use QObject in template param instead KdeConnectPlugin?
ret.plugin = factory->create<KdeConnectPlugin>(device, QVariantList() << deviceVariant); ret.plugin = factory->create<KdeConnectPlugin>(device, QVariantList() << deviceVariant << ret.outgoingInterfaces);
if (!ret.plugin) { if (!ret.plugin) {
kDebug(kdeconnect_kded()) << "Error loading plugin"; kDebug(kdeconnect_kded()) << "Error loading plugin";
return ret; return ret;

View file

@ -36,7 +36,8 @@ struct PluginData
{ {
PluginData() : plugin(0) {} PluginData() : plugin(0) {}
KdeConnectPlugin* plugin; KdeConnectPlugin* plugin;
QStringList interfaces; QStringList incomingInterfaces;
QStringList outgoingInterfaces;
}; };
class PluginLoader class PluginLoader

View file

@ -44,7 +44,7 @@ void BatteryPlugin::connected()
{ {
NetworkPackage np(PACKAGE_TYPE_BATTERY); NetworkPackage np(PACKAGE_TYPE_BATTERY);
np.set("request",true); np.set("request",true);
device()->sendPackage(np); sendPackage(np);
} }
BatteryPlugin::~BatteryPlugin() BatteryPlugin::~BatteryPlugin()

View file

@ -58,3 +58,4 @@ Comment[uk]=Показ даних щодо рівня заряду акумул
Comment[x-test]=xxShow your phone battery next to your computer batteryxx Comment[x-test]=xxShow your phone battery next to your computer batteryxx
X-KdeConnect-SupportedPackageType=kdeconnect.battery X-KdeConnect-SupportedPackageType=kdeconnect.battery
X-KdeConnect-OutgoingPackageType=kdeconnect.battery

View file

@ -45,7 +45,7 @@ void ClipboardPlugin::clipboardChanged(QClipboard::Mode mode)
//kDebug(kdeconnect_kded()) << "ClipboardChanged"; //kDebug(kdeconnect_kded()) << "ClipboardChanged";
NetworkPackage np(PACKAGE_TYPE_CLIPBOARD); NetworkPackage np(PACKAGE_TYPE_CLIPBOARD);
np.set("content",clipboard->text()); np.set("content",clipboard->text());
device()->sendPackage(np); sendPackage(np);
} }
bool ClipboardPlugin::receivePackage(const NetworkPackage& np) bool ClipboardPlugin::receivePackage(const NetworkPackage& np)

View file

@ -29,3 +29,6 @@ Name[x-test]=xxKDEConnect Pluginxx
# mandatory, list of all the package types supported # mandatory, list of all the package types supported
[PropertyDef::X-KdeConnect-SupportedPackageType] [PropertyDef::X-KdeConnect-SupportedPackageType]
Type=QStringList Type=QStringList
[PropertyDef::X-KdeConnect-OutgoingPackageType]
Type=QStringList

View file

@ -57,3 +57,4 @@ Comment[uk]=Віддалене керування відтворенням му
Comment[x-test]=xxRemote control your music and videosxx Comment[x-test]=xxRemote control your music and videosxx
X-KdeConnect-SupportedPackageType=kdeconnect.mpris X-KdeConnect-SupportedPackageType=kdeconnect.mpris
X-KdeConnect-OutgoingPackageType=kdeconnect.mpris

View file

@ -125,7 +125,7 @@ void MprisControlPlugin::propertiesChanged(const QString& propertyInterface, con
const QString& service = interface->service(); const QString& service = interface->service();
const QString& player = playerList.key(service); const QString& player = playerList.key(service);
np.set("player", player); np.set("player", player);
device()->sendPackage(np); sendPackage(np);
} }
} }
@ -202,7 +202,7 @@ bool MprisControlPlugin::receivePackage (const NetworkPackage& np)
} }
if (somethingToSend) { if (somethingToSend) {
answer.set("player", player); answer.set("player", player);
device()->sendPackage(answer); sendPackage(answer);
} }
return true; return true;
@ -213,5 +213,5 @@ void MprisControlPlugin::sendPlayerList()
{ {
NetworkPackage np(PACKAGE_TYPE_MPRIS); NetworkPackage np(PACKAGE_TYPE_MPRIS);
np.set("playerList",playerList.keys()); np.set("playerList",playerList.keys());
device()->sendPackage(np); sendPackage(np);
} }

View file

@ -58,3 +58,4 @@ Comment[uk]=Показ сповіщень з телефону у KDE та під
Comment[x-test]=xxShow phone notifications in KDE and keep them in syncxx Comment[x-test]=xxShow phone notifications in KDE and keep them in syncxx
X-KdeConnect-SupportedPackageType=kdeconnect.notification X-KdeConnect-SupportedPackageType=kdeconnect.notification
X-KdeConnect-OutgoingPackageType=kdeconnect.notification

View file

@ -30,9 +30,10 @@
#include <core/filetransferjob.h> #include <core/filetransferjob.h>
#include "notificationsplugin.h" #include "notificationsplugin.h"
NotificationsDbusInterface::NotificationsDbusInterface(Device* device, QObject *parent) NotificationsDbusInterface::NotificationsDbusInterface(KdeConnectPlugin* plugin)
: QDBusAbstractAdaptor(parent) : QDBusAbstractAdaptor(plugin)
, mDevice(device) , mDevice(plugin->device())
, mPlugin(plugin)
, mLastId(0) , mLastId(0)
, imagesDir(QDir::temp().absoluteFilePath("kdeconnect")) , imagesDir(QDir::temp().absoluteFilePath("kdeconnect"))
{ {
@ -134,7 +135,7 @@ void NotificationsDbusInterface::dismissRequested(Notification* notification)
NetworkPackage np(PACKAGE_TYPE_NOTIFICATION); NetworkPackage np(PACKAGE_TYPE_NOTIFICATION);
np.set<QString>("cancel", internalId); np.set<QString>("cancel", internalId);
mDevice->sendPackage(np); mPlugin->sendPackage(np);
//This should be called automatically back from server //This should be called automatically back from server
//removeNotification(internalId); //removeNotification(internalId);

View file

@ -37,7 +37,7 @@ class NotificationsDbusInterface
Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.notifications") Q_CLASSINFO("D-Bus Interface", "org.kde.kdeconnect.device.notifications")
public: public:
explicit NotificationsDbusInterface(Device* device, QObject *parent); explicit NotificationsDbusInterface(KdeConnectPlugin* plugin);
virtual ~NotificationsDbusInterface(); virtual ~NotificationsDbusInterface();
void processPackage(const NetworkPackage& np); void processPackage(const NetworkPackage& np);
@ -56,7 +56,8 @@ private /*methods*/:
QString newId(); //Generates successive identifitiers to use as public ids QString newId(); //Generates successive identifitiers to use as public ids
private /*attributes*/: private /*attributes*/:
Device* mDevice; const Device* mDevice;
KdeConnectPlugin* mPlugin;
QHash<QString, Notification*> mNotifications; QHash<QString, Notification*> mNotifications;
QHash<QString, QString> mInternalIdToPublicId; QHash<QString, QString> mInternalIdToPublicId;
int mLastId; int mLastId;

View file

@ -31,14 +31,14 @@ K_EXPORT_PLUGIN( KdeConnectPluginFactory("kdeconnect_notifications", "kdeconnect
NotificationsPlugin::NotificationsPlugin(QObject* parent, const QVariantList& args) NotificationsPlugin::NotificationsPlugin(QObject* parent, const QVariantList& args)
: KdeConnectPlugin(parent, args) : KdeConnectPlugin(parent, args)
{ {
notificationsDbusInterface = new NotificationsDbusInterface(device(), parent); notificationsDbusInterface = new NotificationsDbusInterface(this);
} }
void NotificationsPlugin::connected() void NotificationsPlugin::connected()
{ {
NetworkPackage np(PACKAGE_TYPE_NOTIFICATION); NetworkPackage np(PACKAGE_TYPE_NOTIFICATION);
np.set("request", true); np.set("request", true);
device()->sendPackage(np); sendPackage(np);
} }
NotificationsPlugin::~NotificationsPlugin() NotificationsPlugin::~NotificationsPlugin()

View file

@ -59,3 +59,4 @@ Comment[uk]=Надсилання і отримання сигналів підт
Comment[x-test]=xxSend and receive pingsxx Comment[x-test]=xxSend and receive pingsxx
X-KdeConnect-SupportedPackageType=kdeconnect.ping X-KdeConnect-SupportedPackageType=kdeconnect.ping
# X-KdeConnect-OutgoingPackageType=kdeconnect.ping

View file

@ -49,3 +49,4 @@ Comment[uk]=Перегляд файлових систем на сторонні
Comment[x-test]=xxBrowse the remote device filesystem using SFTPxx Comment[x-test]=xxBrowse the remote device filesystem using SFTPxx
X-KdeConnect-SupportedPackageType=kdeconnect.sftp X-KdeConnect-SupportedPackageType=kdeconnect.sftp
X-KdeConnect-OutgoingPackageType=kdeconnect.sftp

View file

@ -231,7 +231,7 @@ void Mounter::start()
np.set("start", true); np.set("start", true);
np.set("id", m_id); np.set("id", m_id);
np.set("idleTimeout", m_idleTimer.interval()); np.set("idleTimeout", m_idleTimer.interval());
m_sftp->device()->sendPackage(np); m_sftp->sendPackage(np);
m_connectTimer.start(); m_connectTimer.start();
} }

View file

@ -50,3 +50,4 @@ Comment[uk]=Спрощене отримання і надсилання файл
Comment[x-test]=xxReceive and send files, URLs or plain text easilyxx Comment[x-test]=xxReceive and send files, URLs or plain text easilyxx
X-KdeConnect-SupportedPackageType=kdeconnect.share X-KdeConnect-SupportedPackageType=kdeconnect.share
X-KdeConnect-OutgoingPackageType=kdeconnect.share

View file

@ -154,7 +154,7 @@ void SharePlugin::shareUrl(const QUrl& url)
} else { } else {
package.set<QString>("url", url.toString()); package.set<QString>("url", url.toString());
} }
device()->sendPackage(package); sendPackage(package);
} }
void SharePlugin::connected() void SharePlugin::connected()

View file

@ -58,3 +58,4 @@ Comment[uk]=Показ сповіщень щодо дзвінків і SMS (ск
Comment[x-test]=xxShow notifications for calls and SMS (answering coming soon)xx Comment[x-test]=xxShow notifications for calls and SMS (answering coming soon)xx
X-KdeConnect-SupportedPackageType=kdeconnect.telephony X-KdeConnect-SupportedPackageType=kdeconnect.telephony
X-KdeConnect-OutgoingPackageType=