Commit 1060c1a8 authored by Nicolas Fella's avatar Nicolas Fella

Add API for opening the KCM to daemon

We have a few places that open the KCM, with different arguments.

Centralize the implementation in one place.

This makes it easier to switch to invoking systemsettings5 in the future (once plasma/systemsettings!11 is in).

It also makes sure the relevant device is selected when clicking on a pairing notification.

The function is exposed to DBus for the Plasmoid and potential third-party users.

CCBUG: 425660
parent 5ff1a2f4
Pipeline #38037 passed with stage
in 15 minutes and 58 seconds
......@@ -10,6 +10,7 @@
#include <QNetworkAccessManager>
#include <QDebug>
#include <QPointer>
#include <QProcess>
#include "core_debug.h"
#include "kdeconnectconfig.h"
......@@ -331,3 +332,23 @@ QString Daemon::selfId() const
{
return KdeConnectConfig::instance().deviceId();
}
void Daemon::openConfiguration(const QString &deviceId, const QString &pluginId)
{
QStringList args;
QString argument;
if (!deviceId.isEmpty()) {
args << QStringLiteral("--args");
argument = deviceId;
if (!pluginId.isEmpty()) {
argument += QLatin1Char(':') + pluginId;
}
args << argument;
}
QProcess::startDetached(QStringLiteral("kdeconnect-settings"), args);
}
......@@ -74,6 +74,8 @@ public Q_SLOTS:
Q_SCRIPTABLE virtual void sendSimpleNotification(const QString &eventId, const QString &title, const QString &text, const QString &iconName) = 0;
Q_SCRIPTABLE void openConfiguration(const QString &deviceId = QString(), const QString &pluginId = QString());
Q_SIGNALS:
Q_SCRIPTABLE void deviceAdded(const QString& id);
Q_SCRIPTABLE void deviceRemoved(const QString& id); //Note that paired devices will never be removed
......
......@@ -53,8 +53,8 @@ public:
notification->setActions(QStringList() << i18n("Accept") << i18n("Reject"));
connect(notification, &KNotification::action1Activated, device, &Device::acceptPairing);
connect(notification, &KNotification::action2Activated, device, &Device::rejectPairing);
connect(notification, QOverload<>::of(&KNotification::activated), this, []{
QProcess::startDetached(QStringLiteral("kdeconnect-settings"), {});
connect(notification, QOverload<>::of(&KNotification::activated), this, [this, device] {
openConfiguration(device->id());
});
notification->sendEvent();
}
......
......@@ -12,7 +12,6 @@ import org.kde.plasma.extras 2.0 as PlasmaExtras
import org.kde.kdeconnect 1.0 as KdeConnect
import QtQuick.Layouts 1.9
import org.kde.kquickcontrolsaddons 2.0
import org.kde.kirigami 2.12 as Kirigami
Item {
......@@ -65,7 +64,7 @@ Item {
helpfulAction: Action {
text: pairedDevicesModel.count == 0 ? i18n("Pair a Device...") : i18n("Configure...")
icon.name: pairedDevicesModel.count == 0 ? "list-add" : "configure"
onTriggered: KCMShell.open("kcm_kdeconnect")
onTriggered: KdeConnect.DaemonDbusInterface.openConfiguration()
enabled: KCMShell.authorize("kcm_kdeconnect.desktop").length > 0
}
......
......@@ -40,7 +40,7 @@ Item
Plasmoid.preferredRepresentation: isConstrained ? Plasmoid.compactRepresentation : Plasmoid.fullRepresentation
function action_launchkcm() {
KCMShell.open("kcm_kdeconnect");
DaemonDbusInterface.openConfiguration()
}
Component.onCompleted: {
......
......@@ -23,6 +23,7 @@
#include <core/networkpacket.h>
#include <core/device.h>
#include <core/daemon.h>
#include "plugin_runcommand_debug.h"
......@@ -70,7 +71,7 @@ bool RunCommandPlugin::receivePacket(const NetworkPacket& np)
QProcess::startDetached(QStringLiteral(COMMAND), QStringList()<< QStringLiteral(ARGS) << commandJson[QStringLiteral("command")].toString());
return true;
} else if (np.has(QStringLiteral("setup"))) {
QProcess::startDetached(QStringLiteral("kdeconnect-settings"), { QStringLiteral("--args"), QString(device()->id() + QStringLiteral(":kdeconnect_runcommand")) });
Daemon::instance()->openConfiguration(device()->id(), QStringLiteral("kdeconnect_runcommand"));
}
return false;
......
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