Commit 3734d6ce authored by Aleix Pol Gonzalez's avatar Aleix Pol Gonzalez 🐧

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
parent fd64a8bc
......@@ -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();
......
......@@ -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 {};
}
......@@ -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
......
......@@ -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;
......
......@@ -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);
......
......@@ -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";
......
......@@ -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
......@@ -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);
}
......
......@@ -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();
......
......@@ -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 { }
......
......@@ -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";
......
......@@ -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;
......
......@@ -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;
......
......@@ -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
*/
......
......@@ -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";
......
......@@ -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
......@@ -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);
}
......
......@@ -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;
......
......@@ -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";
......
......@@ -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
......@@ -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;
......
......@@ -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;
......
......@@ -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;
......
......@@ -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();
......
......@@ -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();
......
......@@ -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";
......
......@@ -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;
};
......
......@@ -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";
......
......@@ -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;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment