From dd031d3debaf53cc10fdb99af64770827a5cfa4a Mon Sep 17 00:00:00 2001 From: Aleix Pol Date: Thu, 19 Apr 2018 02:28:02 +0200 Subject: [PATCH] Show the KCM with the run commands open when a setup packet is received Summary: Depends on D11683. Test Plan: Tested the `kcmshell kdeconnect --args mydeviceid:kdeconnect_runcommand` works Reviewers: #kde_connect, nicolasfella Reviewed By: #kde_connect, nicolasfella Subscribers: nicolasfella Tags: #kde_connect Differential Revision: https://phabricator.kde.org/D11684 --- CMakeLists.txt | 2 +- interfaces/devicesmodel.h | 2 +- kcm/kcm.cpp | 21 ++++++++++++++++++++- plugins/runcommand/runcommandplugin.cpp | 3 +++ 4 files changed, 25 insertions(+), 3 deletions(-) diff --git a/CMakeLists.txt b/CMakeLists.txt index 3e4fed27c..499f6452d 100644 --- a/CMakeLists.txt +++ b/CMakeLists.txt @@ -8,7 +8,7 @@ set(KDECONNECT_VERSION_PATCH 0) set(KDECONNECT_VERSION "${KDECONNECT_VERSION_MAJOR}.${KDECONNECT_VERSION_MINOR}.${KDECONNECT_VERSION_PATCH}") set(QT_MIN_VERSION "5.7.0") -set(KF5_MIN_VERSION "5.42.0") +set(KF5_MIN_VERSION "5.45.0") find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_SOURCE_DIR}/cmake) diff --git a/interfaces/devicesmodel.h b/interfaces/devicesmodel.h index f208136f1..00b98c4b0 100644 --- a/interfaces/devicesmodel.h +++ b/interfaces/devicesmodel.h @@ -71,6 +71,7 @@ public: Q_SCRIPTABLE DeviceDbusInterface* getDevice(int row) const; QHash roleNames() const override; + int rowForDevice(const QString& id) const; private Q_SLOTS: void deviceAdded(const QString& id); @@ -84,7 +85,6 @@ Q_SIGNALS: void rowsChanged(); private: - int rowForDevice(const QString& id) const; void clearDevices(); void appendDevice(DeviceDbusInterface* dev); bool passesFilter(DeviceDbusInterface* dev) const; diff --git a/kcm/kcm.cpp b/kcm/kcm.cpp index 421afacd4..9e59719e7 100644 --- a/kcm/kcm.cpp +++ b/kcm/kcm.cpp @@ -46,7 +46,7 @@ K_PLUGIN_FACTORY(KdeConnectKcmFactory, registerPlugin();) static QString createId() { return QStringLiteral("kcm")+QString::number(QCoreApplication::applicationPid()); } -KdeConnectKcm::KdeConnectKcm(QWidget* parent, const QVariantList&) +KdeConnectKcm::KdeConnectKcm(QWidget* parent, const QVariantList& args) : KCModule(KAboutData::pluginData(QStringLiteral("kdeconnect-kcm")), parent) , kcmUi(new Ui::KdeConnectKcmUi()) , daemon(new DaemonDbusInterface(this)) @@ -115,6 +115,25 @@ KdeConnectKcm::KdeConnectKcm(QWidget* parent, const QVariantList&) this, &KdeConnectKcm::renameShow); daemon->acquireDiscoveryMode(createId()); + + if (!args.isEmpty() && args.first().type() == QVariant::String) { + const QString input = args.first().toString(); + const auto colonIdx = input.indexOf(QLatin1Char(':')); + const QString deviceId = input.left(colonIdx); + const QString pluginCM = colonIdx < 0 ? QString() : input.mid(colonIdx+1); + + connect(devicesModel, &DevicesModel::rowsInserted, this, [this, deviceId, pluginCM]() { + auto row = devicesModel->rowForDevice(deviceId); + if (row >= 0) { + const QModelIndex idx = sortProxyModel->mapFromSource(devicesModel->index(row)); + kcmUi->deviceList->selectionModel()->setCurrentIndex(idx, QItemSelectionModel::ClearAndSelect); + } + if (!pluginCM.isEmpty()) { + kcmUi->pluginSelector->showConfiguration(pluginCM); + } + disconnect(devicesModel, &DevicesModel::rowsInserted, this, nullptr); + }); + } } void KdeConnectKcm::renameShow() diff --git a/plugins/runcommand/runcommandplugin.cpp b/plugins/runcommand/runcommandplugin.cpp index 3c19c0cfc..482501e46 100644 --- a/plugins/runcommand/runcommandplugin.cpp +++ b/plugins/runcommand/runcommandplugin.cpp @@ -68,6 +68,8 @@ bool RunCommandPlugin::receivePacket(const NetworkPacket& np) qCInfo(KDECONNECT_PLUGIN_RUNCOMMAND) << "Running:" << "/bin/sh" << "-c" << commandJson[QStringLiteral("command")].toString(); QProcess::startDetached(QStringLiteral("/bin/sh"), QStringList()<< QStringLiteral("-c") << commandJson[QStringLiteral("command")].toString()); return true; + } else if (np.has("setup")) { + QProcess::startDetached(QStringLiteral("kcmshell5"), {QStringLiteral("kdeconnect"), QStringLiteral("--args"), QString(device()->id() + QStringLiteral(":kdeconnect_runcommand")) }); } return false; @@ -83,6 +85,7 @@ void RunCommandPlugin::sendConfig() { QString commands = config()->get(QStringLiteral("commands"),QStringLiteral("{}")); NetworkPacket np(PACKET_TYPE_RUNCOMMAND, {{"commandList", commands}}); + np.set(QStringLiteral("canAddCommand"), true); sendPacket(np); }