Paste P562

Masterwork From Distant Lands
ActivePublic

Authored by davidedmundson on Mar 25 2020, 1:40 PM.
diff --git a/src/gui/commandlauncherjob.cpp b/src/gui/commandlauncherjob.cpp
index 49527cf8..ac23627e 100644
--- a/src/gui/commandlauncherjob.cpp
+++ b/src/gui/commandlauncherjob.cpp
@@ -88,8 +88,19 @@ void KIO::CommandLauncherJob::start()
if (d->m_iconName.isEmpty()) {
d->m_iconName = d->m_executable;
}
- d->m_processRunner = new KProcessRunner(d->m_command, d->m_desktopName, d->m_executable,
- d->m_iconName, d->m_startupId,
+
+ KService::Ptr service;
+ if (!d->m_desktopName.isEmpty()) {
+ KService::Ptr service = KService::serviceByDesktopName(d->m_desktopName);
+ }
+ if (!service) {
+ service = KService::Ptr(new KService(d->m_executable, d->m_executable, d->m_iconName));
+ }
+ service->setExec(d->m_executable);
+
+ d->m_processRunner = new KProcessRunner(d->m_command,
+ service,
+ d->m_startupId,
d->m_workingDirectory);
connect(d->m_processRunner, &KProcessRunner::error, this, [this](const QString &errorText) {
setError(KJob::UserDefinedError);
diff --git a/src/gui/kprocessrunner.cpp b/src/gui/kprocessrunner.cpp
index 6a89bd72..65a2663c 100644
--- a/src/gui/kprocessrunner.cpp
+++ b/src/gui/kprocessrunner.cpp
@@ -41,7 +41,7 @@ static int s_instanceCount = 0; // for the unittest
KProcessRunner::KProcessRunner(const KService::Ptr &service, const QList<QUrl> &urls,
KIO::ApplicationLauncherJob::RunFlags flags, const QString &suggestedFileName, const QByteArray &asn)
: m_process{new KProcess},
- m_executable(KIO::DesktopExecParser::executablePath(service->exec()))
+ m_executable(service->exec())
{
++s_instanceCount;
KIO::DesktopExecParser execParser(*service, urls);
@@ -99,32 +99,22 @@ KProcessRunner::KProcessRunner(const KService::Ptr &service, const QList<QUrl> &
}
}
- init(service, service->name(), service->icon(), asn);
+ init(service, asn);
}
-KProcessRunner::KProcessRunner(const QString &cmd, const QString &desktopName, const QString &execName, const QString &iconName, const QByteArray &asn, const QString &workingDirectory)
+KProcessRunner::KProcessRunner(const QString &cmd, const KService::Ptr &service, const QByteArray &asn, const QString &workingDirectory)
: m_process{new KProcess},
- m_executable(execName)
+ m_executable(service->exec())
{
++s_instanceCount;
m_process->setShellCommand(cmd);
if (!workingDirectory.isEmpty()) {
m_process->setWorkingDirectory(workingDirectory);
}
- if (!desktopName.isEmpty()) {
- KService::Ptr service = KService::serviceByDesktopName(desktopName);
- if (service) {
- if (m_executable.isEmpty()) {
- m_executable = KIO::DesktopExecParser::executablePath(service->exec());
- }
- init(service, service->name(), service->icon(), asn);
- return;
- }
- }
- init(KService::Ptr(), execName /*user-visible name*/, iconName, asn);
+ init(service, asn);
}
-void KProcessRunner::init(const KService::Ptr &service, const QString &userVisibleName, const QString &iconName, const QByteArray &asn)
+void KProcessRunner::init(const KService::Ptr &service, const QByteArray &asn)
{
if (service && !service->entryPath().isEmpty()
&& !KDesktopFile::isAuthorizedDesktopFile(service->entryPath())) {
@@ -146,17 +136,13 @@ void KProcessRunner::init(const KService::Ptr &service, const QString &userVisib
data.setHostname();
// When it comes from a desktop file, m_executable can be a full shell command, so <bin> here is not 100% reliable.
// E.g. it could be "cd", which isn't an existing binary. It's just a heuristic anyway.
- const QString bin = KIO::DesktopExecParser::executableName(m_executable);
+ const QString bin = KIO::DesktopExecParser::executableName(service->exec());
data.setBin(bin);
- if (!userVisibleName.isEmpty()) {
- data.setName(userVisibleName);
- } else if (service && !service->name().isEmpty()) {
+ if (!service->name().isEmpty()) {
data.setName(service->name());
}
data.setDescription(i18n("Launching %1", data.name()));
- if (!iconName.isEmpty()) {
- data.setIcon(iconName);
- } else if (service && !service->icon().isEmpty()) {
+ if (service->icon().isEmpty()) {
data.setIcon(service->icon());
}
if (!wmclass.isEmpty()) {
diff --git a/src/gui/kprocessrunner_p.h b/src/gui/kprocessrunner_p.h
index 300acbae..e0d2821c 100644
--- a/src/gui/kprocessrunner_p.h
+++ b/src/gui/kprocessrunner_p.h
@@ -64,16 +64,14 @@ public:
/**
* Run a shell command
* @param cmd must be a shell command. No need to append "&" to it.
- * @param desktopName name of the desktop file, if known.
- * @param execName the name of the executable, if known.
- * @param iconName icon for the startup notification
+ * @param service the service to run. It can be created with known parameters if not installed
+ * @param execName the name of the executable, if known and different to service
* @param asn Application startup notification id, if any (otherwise "").
* @param workingDirectory the working directory for the started process. The default
* (if passing an empty string) is the user's document path.
* This allows a command like "kwrite file.txt" to find file.txt from the right place.
*/
- KProcessRunner(const QString &cmd, const QString &desktopName, const QString &execName, const QString &iconName,
- const QByteArray &asn = {}, const QString &workingDirectory = {});
+ KProcessRunner(const QString &cmd, const KService::Ptr &service, const QByteArray &asn = {}, const QString &workingDirectory = {});
/**
* @return the PID of the process that was started, on success
@@ -104,15 +102,14 @@ private Q_SLOTS:
void slotProcessStarted();
private:
- void init(const KService::Ptr &service, const QString &userVisibleName,
- const QString &iconName, const QByteArray &asn);
+ void init(const KService::Ptr &service, const QByteArray &asn);
void startProcess();
void terminateStartupNotification();
void emitDelayedError(const QString &errorMsg);
std::unique_ptr<KProcess> m_process;
- QString m_executable; // can be a full path
KStartupInfoId m_startupId;
+ QString m_executable;
qint64 m_pid = 0;
Q_DISABLE_COPY(KProcessRunner)
davidedmundson edited the content of this paste. (Show Details)Mar 25 2020, 1:40 PM
davidedmundson changed the title of this paste from untitled to Masterwork From Distant Lands.