From 3734d6ce4d3b3d699b142df2ebea87b34ba63e41 Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Fri, 30 Dec 2016 16:38:12 +0100 Subject: [PATCH] Reduce API exposed through dbus Summary: Don't use QDBusConnection::ExportAllContents No need to make connect and receivedPackage public slots (they're are the parent's already) Fixes T4975 Test Plan: Rough manual test Reviewers: #kde_connect, albertvaka Reviewed By: #kde_connect, albertvaka Maniphest Tasks: T4975 Differential Revision: https://phabricator.kde.org/D3871 --- core/device.cpp | 6 ++++++ core/kdeconnectplugin.cpp | 5 +++++ core/kdeconnectplugin.h | 2 ++ plugins/battery/batteryplugin.h | 1 - plugins/clipboard/clipboardplugin.h | 3 +-- plugins/findmyphone/findmyphoneplugin.cpp | 5 ----- plugins/findmyphone/findmyphoneplugin.h | 7 ++----- plugins/lockdevice/lockdeviceplugin.cpp | 2 -- plugins/lockdevice/lockdeviceplugin.h | 2 +- plugins/mpriscontrol/mpriscontrolplugin.h | 1 - plugins/mprisremote/mprisremoteplugin.cpp | 5 ----- plugins/mprisremote/mprisremoteplugin.h | 13 ++++++------- plugins/notifications/notificationsplugin.h | 1 - plugins/pausemusic/pausemusicplugin.h | 2 +- plugins/ping/pingplugin.cpp | 5 ----- plugins/ping/pingplugin.h | 6 ++---- plugins/remotecommands/remotecommandsplugin.cpp | 2 -- plugins/remotecommands/remotecommandsplugin.h | 10 +++++----- plugins/remotecontrol/remotecontrolplugin.cpp | 5 ----- plugins/remotecontrol/remotecontrolplugin.h | 10 ++++------ plugins/runcommand/runcommandplugin.h | 2 -- .../screensaver-inhibit/screensaverinhibitplugin.h | 1 - plugins/sendnotifications/sendnotificationsplugin.h | 1 - plugins/sftp/sftpplugin.cpp | 5 ----- plugins/sftp/sftpplugin.h | 10 +++++----- plugins/share/shareplugin.cpp | 5 ----- plugins/share/shareplugin.h | 6 +++--- plugins/telephony/telephonyplugin.cpp | 5 ----- plugins/telephony/telephonyplugin.h | 4 ++-- 29 files changed, 45 insertions(+), 87 deletions(-) diff --git a/core/device.cpp b/core/device.cpp index 23589fc94..822d14cc4 100644 --- a/core/device.cpp +++ b/core/device.cpp @@ -134,8 +134,14 @@ void Device::reloadPlugins() m_pluginsByIncomingCapability = newPluginsByIncomingCapability; //TODO: see how it works in Android (only done once, when created) + QDBusConnection bus = QDBusConnection::sessionBus(); Q_FOREACH(KdeConnectPlugin* plugin, m_plugins) { plugin->connected(); + + const QString dbusPath = plugin->dbusPath(); + if (!dbusPath.isEmpty()) { + bus.registerObject(dbusPath, plugin, QDBusConnection::ExportAllProperties | QDBusConnection::ExportScriptableInvokables); + } } if (differentPlugins) { Q_EMIT pluginsChanged(); diff --git a/core/kdeconnectplugin.cpp b/core/kdeconnectplugin.cpp index b439985d0..b922e6fea 100644 --- a/core/kdeconnectplugin.cpp +++ b/core/kdeconnectplugin.cpp @@ -75,3 +75,8 @@ bool KdeConnectPlugin::sendPackage(NetworkPackage& np) const // qCWarning(KDECONNECT_CORE) << metaObject()->className() << "sends" << np.type() << ". Supported:" << d->mOutgoingTypes; return d->mDevice->sendPackage(np); } + +QString KdeConnectPlugin::dbusPath() const +{ + return {}; +} diff --git a/core/kdeconnectplugin.h b/core/kdeconnectplugin.h index 08fadffe1..0216db811 100644 --- a/core/kdeconnectplugin.h +++ b/core/kdeconnectplugin.h @@ -47,6 +47,8 @@ public: KdeConnectPluginConfig* config() const; + virtual QString dbusPath() const; + public Q_SLOTS: /** * Returns true if it has handled the package in some way diff --git a/plugins/battery/batteryplugin.h b/plugins/battery/batteryplugin.h index 9fe457d55..cc78479c4 100644 --- a/plugins/battery/batteryplugin.h +++ b/plugins/battery/batteryplugin.h @@ -38,7 +38,6 @@ public: explicit BatteryPlugin(QObject *parent, const QVariantList &args); ~BatteryPlugin() override; -public Q_SLOTS: bool receivePackage(const NetworkPackage& np) override; void connected() override; diff --git a/plugins/clipboard/clipboardplugin.h b/plugins/clipboard/clipboardplugin.h index d7ae42516..243ca2c38 100644 --- a/plugins/clipboard/clipboardplugin.h +++ b/plugins/clipboard/clipboardplugin.h @@ -37,10 +37,9 @@ class ClipboardPlugin public: explicit ClipboardPlugin(QObject *parent, const QVariantList &args); -public Q_SLOTS: bool receivePackage(const NetworkPackage& np) override; void connected() override { } - + private Q_SLOTS: void propagateClipboard(const QString& content); diff --git a/plugins/findmyphone/findmyphoneplugin.cpp b/plugins/findmyphone/findmyphoneplugin.cpp index 2bfb09daa..3f7bfd437 100644 --- a/plugins/findmyphone/findmyphoneplugin.cpp +++ b/plugins/findmyphone/findmyphoneplugin.cpp @@ -48,11 +48,6 @@ void FindMyPhonePlugin::ring() sendPackage(np); } -void FindMyPhonePlugin::connected() -{ - QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportAllContents); -} - QString FindMyPhonePlugin::dbusPath() const { return "/modules/kdeconnect/devices/" + device()->id() + "/findmyphone"; diff --git a/plugins/findmyphone/findmyphoneplugin.h b/plugins/findmyphone/findmyphoneplugin.h index 459015c15..94f9b4ea9 100644 --- a/plugins/findmyphone/findmyphoneplugin.h +++ b/plugins/findmyphone/findmyphoneplugin.h @@ -39,12 +39,9 @@ public: Q_SCRIPTABLE void ring(); -public Q_SLOTS: - void connected() override; + QString dbusPath() const override; + void connected() override {} bool receivePackage(const NetworkPackage& np) override; - -private: - QString dbusPath() const; }; #endif diff --git a/plugins/lockdevice/lockdeviceplugin.cpp b/plugins/lockdevice/lockdeviceplugin.cpp index a4029e400..27d600272 100644 --- a/plugins/lockdevice/lockdeviceplugin.cpp +++ b/plugins/lockdevice/lockdeviceplugin.cpp @@ -91,8 +91,6 @@ OrgFreedesktopScreenSaverInterface* LockDevicePlugin::iface() void LockDevicePlugin::connected() { - QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportAllContents); - NetworkPackage np(PACKAGE_TYPE_LOCK_REQUEST, {{"requestLocked", QVariant()}}); sendPackage(np); } diff --git a/plugins/lockdevice/lockdeviceplugin.h b/plugins/lockdevice/lockdeviceplugin.h index e1aa0c7e0..44fc134be 100644 --- a/plugins/lockdevice/lockdeviceplugin.h +++ b/plugins/lockdevice/lockdeviceplugin.h @@ -44,6 +44,7 @@ public: bool isLocked() const; void setLocked(bool b); + QString dbusPath() const override; void connected() override; bool receivePackage(const NetworkPackage & np) override; @@ -51,7 +52,6 @@ Q_SIGNALS: void lockedChanged(bool locked); private: - QString dbusPath() const; bool m_remoteLocked; OrgFreedesktopScreenSaverInterface* iface(); diff --git a/plugins/mpriscontrol/mpriscontrolplugin.h b/plugins/mpriscontrol/mpriscontrolplugin.h index 2c12fac73..773454938 100644 --- a/plugins/mpriscontrol/mpriscontrolplugin.h +++ b/plugins/mpriscontrol/mpriscontrolplugin.h @@ -40,7 +40,6 @@ class MprisControlPlugin public: explicit MprisControlPlugin(QObject *parent, const QVariantList &args); -public Q_SLOTS: bool receivePackage(const NetworkPackage& np) override; void connected() override { } diff --git a/plugins/mprisremote/mprisremoteplugin.cpp b/plugins/mprisremote/mprisremoteplugin.cpp index 3b004d6d4..a26a0c68f 100644 --- a/plugins/mprisremote/mprisremoteplugin.cpp +++ b/plugins/mprisremote/mprisremoteplugin.cpp @@ -85,11 +85,6 @@ long MprisRemotePlugin::position() const } } -void MprisRemotePlugin::connected() -{ - QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportAllContents); -} - QString MprisRemotePlugin::dbusPath() const { return "/modules/kdeconnect/devices/" + device()->id() + "/mprisremote"; diff --git a/plugins/mprisremote/mprisremoteplugin.h b/plugins/mprisremote/mprisremoteplugin.h index 9b34b7658..508190b97 100644 --- a/plugins/mprisremote/mprisremoteplugin.h +++ b/plugins/mprisremote/mprisremoteplugin.h @@ -57,20 +57,19 @@ public: void setPosition(int position); void setPlayer(const QString& player); -public Q_SLOTS: bool receivePackage(const NetworkPackage& np) override; - void connected() override; + void connected() override {} + QString dbusPath() const override; - void seek(int offset) const; - void requestPlayerStatus(); - void requestPlayerList(); - void sendAction(const QString& action); + Q_SCRIPTABLE void seek(int offset) const; + Q_SCRIPTABLE void requestPlayerList(); + Q_SCRIPTABLE void sendAction(const QString& action); Q_SIGNALS: void propertiesChanged(); private: - QString dbusPath() const; + void requestPlayerStatus(); QString m_player; bool m_playing; diff --git a/plugins/notifications/notificationsplugin.h b/plugins/notifications/notificationsplugin.h index ad6f45088..13731f231 100644 --- a/plugins/notifications/notificationsplugin.h +++ b/plugins/notifications/notificationsplugin.h @@ -44,7 +44,6 @@ public: explicit NotificationsPlugin(QObject *parent, const QVariantList &args); ~NotificationsPlugin() override; -public Q_SLOTS: bool receivePackage(const NetworkPackage& np) override; void connected() override; diff --git a/plugins/pausemusic/pausemusicplugin.h b/plugins/pausemusic/pausemusicplugin.h index f4c712a3e..bfa5bafc6 100644 --- a/plugins/pausemusic/pausemusicplugin.h +++ b/plugins/pausemusic/pausemusicplugin.h @@ -35,10 +35,10 @@ class PauseMusicPlugin public: explicit PauseMusicPlugin(QObject *parent, const QVariantList &args); -public Q_SLOTS: bool receivePackage(const NetworkPackage& np) override; void connected() override { } +public Q_SLOTS: /** * @returns 0 if not muted, 1 if muted or -1 if there was an error */ diff --git a/plugins/ping/pingplugin.cpp b/plugins/ping/pingplugin.cpp index 0d4b73da9..14b51271a 100644 --- a/plugins/ping/pingplugin.cpp +++ b/plugins/ping/pingplugin.cpp @@ -74,11 +74,6 @@ void PingPlugin::sendPing(const QString& customMessage) qCDebug(KDECONNECT_PLUGIN_PING) << "sendPing:" << success; } -void PingPlugin::connected() -{ - QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportAllContents); -} - QString PingPlugin::dbusPath() const { return "/modules/kdeconnect/devices/" + device()->id() + "/ping"; diff --git a/plugins/ping/pingplugin.h b/plugins/ping/pingplugin.h index 967e165b2..2965a7674 100644 --- a/plugins/ping/pingplugin.h +++ b/plugins/ping/pingplugin.h @@ -40,12 +40,10 @@ public: Q_SCRIPTABLE void sendPing(); Q_SCRIPTABLE void sendPing(const QString& customMessage); -public Q_SLOTS: bool receivePackage(const NetworkPackage& np) override; - void connected() override; + void connected() override {} -private: - QString dbusPath() const; + QString dbusPath() const override; }; #endif diff --git a/plugins/remotecommands/remotecommandsplugin.cpp b/plugins/remotecommands/remotecommandsplugin.cpp index fe0724821..d8a4109f1 100644 --- a/plugins/remotecommands/remotecommandsplugin.cpp +++ b/plugins/remotecommands/remotecommandsplugin.cpp @@ -59,8 +59,6 @@ bool RemoteCommandsPlugin::receivePackage(const NetworkPackage& np) void RemoteCommandsPlugin::connected() { - QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportAllContents); - NetworkPackage np(PACKAGE_TYPE_RUNCOMMAND_REQUEST, {{"requestCommandList", true}}); sendPackage(np); } diff --git a/plugins/remotecommands/remotecommandsplugin.h b/plugins/remotecommands/remotecommandsplugin.h index cc9563d78..a5416f0ca 100644 --- a/plugins/remotecommands/remotecommandsplugin.h +++ b/plugins/remotecommands/remotecommandsplugin.h @@ -41,17 +41,17 @@ public: explicit RemoteCommandsPlugin(QObject *parent, const QVariantList &args); ~RemoteCommandsPlugin() override; - Q_INVOKABLE void triggerCommand(const QString &key); + Q_SCRIPTABLE void triggerCommand(const QString &key); QByteArray commands() const { return m_commands; } + bool receivePackage(const NetworkPackage& np) override; + void connected() override; + QString dbusPath() const override; + Q_SIGNALS: void commandsChanged(const QByteArray& commands); private: - bool receivePackage(const NetworkPackage& np) override; - void connected() override; - - QString dbusPath() const; void setCommands(const QByteArray &commands); QByteArray m_commands; diff --git a/plugins/remotecontrol/remotecontrolplugin.cpp b/plugins/remotecontrol/remotecontrolplugin.cpp index 43724a462..a0e95897d 100644 --- a/plugins/remotecontrol/remotecontrolplugin.cpp +++ b/plugins/remotecontrol/remotecontrolplugin.cpp @@ -57,11 +57,6 @@ void RemoteControlPlugin::sendCommand(const QString &name, bool val) sendPackage(np); } -void RemoteControlPlugin::connected() -{ - QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportAllContents); -} - QString RemoteControlPlugin::dbusPath() const { return "/modules/kdeconnect/devices/" + device()->id() + "/remotecontrol"; diff --git a/plugins/remotecontrol/remotecontrolplugin.h b/plugins/remotecontrol/remotecontrolplugin.h index 0019c7ce9..53d2feceb 100644 --- a/plugins/remotecontrol/remotecontrolplugin.h +++ b/plugins/remotecontrol/remotecontrolplugin.h @@ -38,13 +38,11 @@ public: ~RemoteControlPlugin() override; bool receivePackage(const NetworkPackage& /*np*/) override { return false; } - void connected() override; + void connected() override {} + QString dbusPath() const override; - Q_INVOKABLE void moveCursor(const QPoint &p); - Q_INVOKABLE void sendCommand(const QString &name, bool val); - -private: - QString dbusPath() const; + Q_SCRIPTABLE void moveCursor(const QPoint &p); + Q_SCRIPTABLE void sendCommand(const QString &name, bool val); }; #endif diff --git a/plugins/runcommand/runcommandplugin.h b/plugins/runcommand/runcommandplugin.h index 33cba0b02..d362038ff 100644 --- a/plugins/runcommand/runcommandplugin.h +++ b/plugins/runcommand/runcommandplugin.h @@ -39,8 +39,6 @@ public: explicit RunCommandPlugin(QObject *parent, const QVariantList &args); ~RunCommandPlugin() override; - -public Q_SLOTS: bool receivePackage(const NetworkPackage& np) override; void connected() override; diff --git a/plugins/screensaver-inhibit/screensaverinhibitplugin.h b/plugins/screensaver-inhibit/screensaverinhibitplugin.h index 3ab32dcf6..f54b62280 100644 --- a/plugins/screensaver-inhibit/screensaverinhibitplugin.h +++ b/plugins/screensaver-inhibit/screensaverinhibitplugin.h @@ -34,7 +34,6 @@ public: explicit ScreensaverInhibitPlugin(QObject *parent, const QVariantList &args); ~ScreensaverInhibitPlugin() override; -public Q_SLOTS: bool receivePackage(const NetworkPackage& np) override; void connected() override; diff --git a/plugins/sendnotifications/sendnotificationsplugin.h b/plugins/sendnotifications/sendnotificationsplugin.h index 340ff2c06..3c5807aa1 100644 --- a/plugins/sendnotifications/sendnotificationsplugin.h +++ b/plugins/sendnotifications/sendnotificationsplugin.h @@ -42,7 +42,6 @@ public: explicit SendNotificationsPlugin(QObject *parent, const QVariantList &args); ~SendNotificationsPlugin() override; -public Q_SLOTS: bool receivePackage(const NetworkPackage& np) override; void connected() override; diff --git a/plugins/sftp/sftpplugin.cpp b/plugins/sftp/sftpplugin.cpp index 4f3dad364..196ce39ed 100644 --- a/plugins/sftp/sftpplugin.cpp +++ b/plugins/sftp/sftpplugin.cpp @@ -82,11 +82,6 @@ void SftpPlugin::removeFromDolphin() } } -void SftpPlugin::connected() -{ - QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportScriptableContents); -} - void SftpPlugin::mount() { qCDebug(KDECONNECT_PLUGIN_SFTP) << "Mount device:" << device()->name(); diff --git a/plugins/sftp/sftpplugin.h b/plugins/sftp/sftpplugin.h index 18d8db0e7..8b8ce577e 100644 --- a/plugins/sftp/sftpplugin.h +++ b/plugins/sftp/sftpplugin.h @@ -38,15 +38,16 @@ public: explicit SftpPlugin(QObject *parent, const QVariantList &args); ~SftpPlugin() override; + bool receivePackage(const NetworkPackage& np) override; + void connected() override {} + QString dbusPath() const override { return "/modules/kdeconnect/devices/" + deviceId + "/sftp"; } + Q_SIGNALS: void packageReceived(const NetworkPackage& np); Q_SCRIPTABLE void mounted(); Q_SCRIPTABLE void unmounted(); - -public Q_SLOTS: - bool receivePackage(const NetworkPackage& np) override; - void connected() override; +public Q_SLOTS: Q_SCRIPTABLE void mount(); Q_SCRIPTABLE void unmount(); Q_SCRIPTABLE bool mountAndWait(); @@ -62,7 +63,6 @@ private Q_SLOTS: void onFailed(const QString& message); private: - QString dbusPath() const { return "/modules/kdeconnect/devices/" + deviceId + "/sftp"; } void knotify(int type, const QString& text, const QPixmap& icon) const; void addToDolphin(); void removeFromDolphin(); diff --git a/plugins/share/shareplugin.cpp b/plugins/share/shareplugin.cpp index 5f73af0ef..0915e2db8 100644 --- a/plugins/share/shareplugin.cpp +++ b/plugins/share/shareplugin.cpp @@ -158,11 +158,6 @@ void SharePlugin::shareUrl(const QUrl& url) sendPackage(package); } -void SharePlugin::connected() -{ - QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportScriptableInvokables); -} - QString SharePlugin::dbusPath() const { return "/modules/kdeconnect/devices/" + device()->id() + "/share"; diff --git a/plugins/share/shareplugin.h b/plugins/share/shareplugin.h index b4bca03e4..8eb0bca1f 100644 --- a/plugins/share/shareplugin.h +++ b/plugins/share/shareplugin.h @@ -39,9 +39,10 @@ public: ///Helper method, QDBus won't recognize QUrl Q_SCRIPTABLE void shareUrl(const QString& url) { shareUrl(QUrl(url)); } -public Q_SLOTS: + bool receivePackage(const NetworkPackage& np) override; - void connected() override; + void connected() override {} + QString dbusPath() const override; private Q_SLOTS: void finished(KJob*); @@ -53,7 +54,6 @@ Q_SIGNALS: private: void shareUrl(const QUrl& url); - QString dbusPath() const; QUrl destinationDir() const; }; diff --git a/plugins/telephony/telephonyplugin.cpp b/plugins/telephony/telephonyplugin.cpp index a07fa9305..516c3a536 100644 --- a/plugins/telephony/telephonyplugin.cpp +++ b/plugins/telephony/telephonyplugin.cpp @@ -161,11 +161,6 @@ void TelephonyPlugin::showSendSmsDialog() dialog->show(); } -void TelephonyPlugin::connected() -{ - QDBusConnection::sessionBus().registerObject(dbusPath(), this, QDBusConnection::ExportScriptableContents); -} - QString TelephonyPlugin::dbusPath() const { return "/modules/kdeconnect/devices/" + device()->id() + "/telephony"; diff --git a/plugins/telephony/telephonyplugin.h b/plugins/telephony/telephonyplugin.h index 55450b6ff..ff4fe07c1 100644 --- a/plugins/telephony/telephonyplugin.h +++ b/plugins/telephony/telephonyplugin.h @@ -43,7 +43,8 @@ public: explicit TelephonyPlugin(QObject *parent, const QVariantList &args); bool receivePackage(const NetworkPackage& np) override; - void connected() override; + void connected() override {} + QString dbusPath() const override; public Q_SLOTS: Q_SCRIPTABLE void sendSms(const QString& phoneNumber, const QString& messageBody); @@ -53,7 +54,6 @@ private Q_SLOTS: void showSendSmsDialog(); private: - QString dbusPath() const; KNotification* createNotification(const NetworkPackage& np); QDBusInterface m_telepathyInterface;