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 https://invent.kde.org/plasma/systemsettings/-/merge_requests/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
This commit is contained in:
parent
5ff1a2f488
commit
1060c1a81a
6 changed files with 29 additions and 6 deletions
|
@ -10,6 +10,7 @@
|
||||||
#include <QNetworkAccessManager>
|
#include <QNetworkAccessManager>
|
||||||
#include <QDebug>
|
#include <QDebug>
|
||||||
#include <QPointer>
|
#include <QPointer>
|
||||||
|
#include <QProcess>
|
||||||
|
|
||||||
#include "core_debug.h"
|
#include "core_debug.h"
|
||||||
#include "kdeconnectconfig.h"
|
#include "kdeconnectconfig.h"
|
||||||
|
@ -331,3 +332,23 @@ QString Daemon::selfId() const
|
||||||
{
|
{
|
||||||
return KdeConnectConfig::instance().deviceId();
|
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 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_SIGNALS:
|
||||||
Q_SCRIPTABLE void deviceAdded(const QString& id);
|
Q_SCRIPTABLE void deviceAdded(const QString& id);
|
||||||
Q_SCRIPTABLE void deviceRemoved(const QString& id); //Note that paired devices will never be removed
|
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"));
|
notification->setActions(QStringList() << i18n("Accept") << i18n("Reject"));
|
||||||
connect(notification, &KNotification::action1Activated, device, &Device::acceptPairing);
|
connect(notification, &KNotification::action1Activated, device, &Device::acceptPairing);
|
||||||
connect(notification, &KNotification::action2Activated, device, &Device::rejectPairing);
|
connect(notification, &KNotification::action2Activated, device, &Device::rejectPairing);
|
||||||
connect(notification, QOverload<>::of(&KNotification::activated), this, []{
|
connect(notification, QOverload<>::of(&KNotification::activated), this, [this, device] {
|
||||||
QProcess::startDetached(QStringLiteral("kdeconnect-settings"), {});
|
openConfiguration(device->id());
|
||||||
});
|
});
|
||||||
notification->sendEvent();
|
notification->sendEvent();
|
||||||
}
|
}
|
||||||
|
|
|
@ -12,7 +12,6 @@ import org.kde.plasma.extras 2.0 as PlasmaExtras
|
||||||
import org.kde.kdeconnect 1.0 as KdeConnect
|
import org.kde.kdeconnect 1.0 as KdeConnect
|
||||||
import QtQuick.Layouts 1.9
|
import QtQuick.Layouts 1.9
|
||||||
import org.kde.kquickcontrolsaddons 2.0
|
import org.kde.kquickcontrolsaddons 2.0
|
||||||
|
|
||||||
import org.kde.kirigami 2.12 as Kirigami
|
import org.kde.kirigami 2.12 as Kirigami
|
||||||
|
|
||||||
Item {
|
Item {
|
||||||
|
@ -65,7 +64,7 @@ Item {
|
||||||
helpfulAction: Action {
|
helpfulAction: Action {
|
||||||
text: pairedDevicesModel.count == 0 ? i18n("Pair a Device...") : i18n("Configure...")
|
text: pairedDevicesModel.count == 0 ? i18n("Pair a Device...") : i18n("Configure...")
|
||||||
icon.name: pairedDevicesModel.count == 0 ? "list-add" : "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
|
enabled: KCMShell.authorize("kcm_kdeconnect.desktop").length > 0
|
||||||
}
|
}
|
||||||
|
|
||||||
|
|
|
@ -40,7 +40,7 @@ Item
|
||||||
Plasmoid.preferredRepresentation: isConstrained ? Plasmoid.compactRepresentation : Plasmoid.fullRepresentation
|
Plasmoid.preferredRepresentation: isConstrained ? Plasmoid.compactRepresentation : Plasmoid.fullRepresentation
|
||||||
|
|
||||||
function action_launchkcm() {
|
function action_launchkcm() {
|
||||||
KCMShell.open("kcm_kdeconnect");
|
DaemonDbusInterface.openConfiguration()
|
||||||
}
|
}
|
||||||
|
|
||||||
Component.onCompleted: {
|
Component.onCompleted: {
|
||||||
|
|
|
@ -23,6 +23,7 @@
|
||||||
|
|
||||||
#include <core/networkpacket.h>
|
#include <core/networkpacket.h>
|
||||||
#include <core/device.h>
|
#include <core/device.h>
|
||||||
|
#include <core/daemon.h>
|
||||||
|
|
||||||
#include "plugin_runcommand_debug.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());
|
QProcess::startDetached(QStringLiteral(COMMAND), QStringList()<< QStringLiteral(ARGS) << commandJson[QStringLiteral("command")].toString());
|
||||||
return true;
|
return true;
|
||||||
} else if (np.has(QStringLiteral("setup"))) {
|
} 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;
|
return false;
|
||||||
|
|
Loading…
Reference in a new issue