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
This commit is contained in:
Aleix Pol 2018-04-19 02:28:02 +02:00
parent 4a4e8216aa
commit dd031d3deb
4 changed files with 25 additions and 3 deletions

View file

@ -8,7 +8,7 @@ set(KDECONNECT_VERSION_PATCH 0)
set(KDECONNECT_VERSION "${KDECONNECT_VERSION_MAJOR}.${KDECONNECT_VERSION_MINOR}.${KDECONNECT_VERSION_PATCH}") set(KDECONNECT_VERSION "${KDECONNECT_VERSION_MAJOR}.${KDECONNECT_VERSION_MINOR}.${KDECONNECT_VERSION_PATCH}")
set(QT_MIN_VERSION "5.7.0") 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) find_package(ECM ${KF5_MIN_VERSION} REQUIRED NO_MODULE)
set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_SOURCE_DIR}/cmake) set(CMAKE_MODULE_PATH ${ECM_MODULE_PATH} ${ECM_KDE_MODULE_DIR} ${CMAKE_SOURCE_DIR}/cmake)

View file

@ -71,6 +71,7 @@ public:
Q_SCRIPTABLE DeviceDbusInterface* getDevice(int row) const; Q_SCRIPTABLE DeviceDbusInterface* getDevice(int row) const;
QHash<int, QByteArray> roleNames() const override; QHash<int, QByteArray> roleNames() const override;
int rowForDevice(const QString& id) const;
private Q_SLOTS: private Q_SLOTS:
void deviceAdded(const QString& id); void deviceAdded(const QString& id);
@ -84,7 +85,6 @@ Q_SIGNALS:
void rowsChanged(); void rowsChanged();
private: private:
int rowForDevice(const QString& id) const;
void clearDevices(); void clearDevices();
void appendDevice(DeviceDbusInterface* dev); void appendDevice(DeviceDbusInterface* dev);
bool passesFilter(DeviceDbusInterface* dev) const; bool passesFilter(DeviceDbusInterface* dev) const;

View file

@ -46,7 +46,7 @@ K_PLUGIN_FACTORY(KdeConnectKcmFactory, registerPlugin<KdeConnectKcm>();)
static QString createId() { return QStringLiteral("kcm")+QString::number(QCoreApplication::applicationPid()); } 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) : KCModule(KAboutData::pluginData(QStringLiteral("kdeconnect-kcm")), parent)
, kcmUi(new Ui::KdeConnectKcmUi()) , kcmUi(new Ui::KdeConnectKcmUi())
, daemon(new DaemonDbusInterface(this)) , daemon(new DaemonDbusInterface(this))
@ -115,6 +115,25 @@ KdeConnectKcm::KdeConnectKcm(QWidget* parent, const QVariantList&)
this, &KdeConnectKcm::renameShow); this, &KdeConnectKcm::renameShow);
daemon->acquireDiscoveryMode(createId()); 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() void KdeConnectKcm::renameShow()

View file

@ -68,6 +68,8 @@ bool RunCommandPlugin::receivePacket(const NetworkPacket& np)
qCInfo(KDECONNECT_PLUGIN_RUNCOMMAND) << "Running:" << "/bin/sh" << "-c" << commandJson[QStringLiteral("command")].toString(); qCInfo(KDECONNECT_PLUGIN_RUNCOMMAND) << "Running:" << "/bin/sh" << "-c" << commandJson[QStringLiteral("command")].toString();
QProcess::startDetached(QStringLiteral("/bin/sh"), QStringList()<< QStringLiteral("-c") << commandJson[QStringLiteral("command")].toString()); QProcess::startDetached(QStringLiteral("/bin/sh"), QStringList()<< QStringLiteral("-c") << commandJson[QStringLiteral("command")].toString());
return true; return true;
} else if (np.has("setup")) {
QProcess::startDetached(QStringLiteral("kcmshell5"), {QStringLiteral("kdeconnect"), QStringLiteral("--args"), QString(device()->id() + QStringLiteral(":kdeconnect_runcommand")) });
} }
return false; return false;
@ -83,6 +85,7 @@ void RunCommandPlugin::sendConfig()
{ {
QString commands = config()->get<QString>(QStringLiteral("commands"),QStringLiteral("{}")); QString commands = config()->get<QString>(QStringLiteral("commands"),QStringLiteral("{}"));
NetworkPacket np(PACKET_TYPE_RUNCOMMAND, {{"commandList", commands}}); NetworkPacket np(PACKET_TYPE_RUNCOMMAND, {{"commandList", commands}});
np.set<bool>(QStringLiteral("canAddCommand"), true);
sendPacket(np); sendPacket(np);
} }