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:
parent
4a4e8216aa
commit
dd031d3deb
4 changed files with 25 additions and 3 deletions
|
@ -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)
|
||||
|
|
|
@ -71,6 +71,7 @@ public:
|
|||
|
||||
Q_SCRIPTABLE DeviceDbusInterface* getDevice(int row) const;
|
||||
QHash<int, QByteArray> 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;
|
||||
|
|
21
kcm/kcm.cpp
21
kcm/kcm.cpp
|
@ -46,7 +46,7 @@ K_PLUGIN_FACTORY(KdeConnectKcmFactory, registerPlugin<KdeConnectKcm>();)
|
|||
|
||||
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()
|
||||
|
|
|
@ -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<QString>(QStringLiteral("commands"),QStringLiteral("{}"));
|
||||
NetworkPacket np(PACKET_TYPE_RUNCOMMAND, {{"commandList", commands}});
|
||||
np.set<bool>(QStringLiteral("canAddCommand"), true);
|
||||
sendPacket(np);
|
||||
}
|
||||
|
||||
|
|
Loading…
Reference in a new issue