Paste P552

Masterwork From Distant Lands
ActivePublic

Authored by davidedmundson on Mar 2 2020, 3:29 PM.
commit b0d440786d8b1a9ed48c3b423cb47f388c8ea4ac
Author: David Edmundson <kde@davidedmundson.co.uk>
Date: Tue Feb 18 16:52:02 2020 +0000
start in scope
diff --git a/src/widgets/kprocessrunner.cpp b/src/widgets/kprocessrunner.cpp
index 7a960064..72cb260c 100644
--- a/src/widgets/kprocessrunner.cpp
+++ b/src/widgets/kprocessrunner.cpp
@@ -26,10 +26,12 @@
#include <QFile>
#include <QGuiApplication>
+#include <QDBusMetaType>
#include <QDBusConnection>
#include <QDBusConnectionInterface>
#include <QDBusInterface>
#include <QDBusReply>
+#include <QUuid>
#include <KProcess>
#include <KLocalizedString>
@@ -41,6 +43,7 @@
#include <kio/desktopexecparser.h>
#include "krecentdocument.h"
+
#include "kio_widgets_debug.h"
KProcessRunner::KProcessRunner(const KService::Ptr &service, const QList<QUrl> &urls, WId windowId,
@@ -169,6 +172,16 @@ void KProcessRunner::init(const KService::Ptr &service, const QString &bin, cons
Q_UNUSED(userVisibleName);
Q_UNUSED(iconName);
#endif
+
+ if (service) {
+ m_scopeId = service->menuId();
+ }
+ if (m_scopeId.isEmpty() && service) {
+ m_scopeId = service->desktopEntryName() + QStringLiteral(".desktop");
+ } else if (m_scopeId.isEmpty()) {
+ m_scopeId = m_executable + QStringLiteral(".desktop");
+ }
+
startProcess();
}
@@ -178,6 +191,31 @@ void KProcessRunner::startProcess()
this, &KProcessRunner::slotProcessExited);
m_process->start();
+
+ QDBusMessage message = QDBusMessage::createMethodCall(QStringLiteral("org.freedesktop.systemd1"),
+ QStringLiteral("/org/freedesktop/systemd1"),
+ QStringLiteral("org.freedesktop.systemd1.Manager"),
+ QStringLiteral("StartTransientUnit"));
+
+ typedef QPair<QString, QDBusVariant> NamedVariant;
+ typedef QList<NamedVariant> NamedVariantList;
+
+ qDBusRegisterMetaType<NamedVariant>();
+ qDBusRegisterMetaType<NamedVariantList>();
+ qDBusRegisterMetaType<QPair<QString, NamedVariantList>>();
+ qDBusRegisterMetaType<QList<QPair<QString, NamedVariantList>>>();
+
+ const QString name = QStringLiteral("app-%1-%2.scope").arg(m_scopeId, QUuid::createUuid().toString(QUuid::Id128));
+ const QString mode = QStringLiteral("fail"); // mode defines what to do in the case of a conflict, in this case, just do nothing
+ NamedVariantList properties;
+ QList<QPair<QString, NamedVariantList>> aux; // unused, but we need the signatue to be correct;
+
+ QList<uint> pidList = {static_cast<quint32>(m_process->pid())};
+ properties << NamedVariant({QStringLiteral("PIDs"), QDBusVariant(QVariant::fromValue(pidList))});
+
+ message.setArguments({name, mode, QVariant::fromValue(properties), QVariant::fromValue(aux)});
+ QDBusMessage reply = QDBusConnection::sessionBus().call(message);
+
if (!m_process->waitForStarted()) {
//qDebug() << "wait for started failed, exitCode=" << process->exitCode()
// << "exitStatus=" << process->exitStatus();
diff --git a/src/widgets/kprocessrunner_p.h b/src/widgets/kprocessrunner_p.h
index ea585aa8..e81e6ef0 100644
--- a/src/widgets/kprocessrunner_p.h
+++ b/src/widgets/kprocessrunner_p.h
@@ -95,6 +95,7 @@ private:
std::unique_ptr<KProcess> m_process;
const QString m_executable; // can be a full path
KStartupInfoId m_startupId;
+ QString m_scopeId;
qint64 m_pid = 0;
Q_DISABLE_COPY(KProcessRunner)
davidedmundson edited the content of this paste. (Show Details)Mar 2 2020, 3:29 PM
davidedmundson changed the title of this paste from untitled to Masterwork From Distant Lands.