diff --git a/src/gui/commandlauncherjob.cpp b/src/gui/commandlauncherjob.cpp index 49527cf8..43fc46b6 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 (!desktopName.isEmpty()) { + KService::Ptr service = KService::serviceByDesktopName(desktopName); + } + if (!service) { + service = KService(d->m_executable, d->m_executable, d->m_iconName); + } + service->setExecutable(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..1e4f98c0 100644 --- a/src/gui/kprocessrunner.cpp +++ b/src/gui/kprocessrunner.cpp @@ -41,7 +41,6 @@ static int s_instanceCount = 0; // for the unittest KProcessRunner::KProcessRunner(const KService::Ptr &service, const QList &urls, KIO::ApplicationLauncherJob::RunFlags flags, const QString &suggestedFileName, const QByteArray &asn) : m_process{new KProcess}, - m_executable(KIO::DesktopExecParser::executablePath(service->exec())) { ++s_instanceCount; KIO::DesktopExecParser execParser(*service, urls); @@ -99,32 +98,21 @@ KProcessRunner::KProcessRunner(const KService::Ptr &service, const QList & } } - init(service, service->name(), service->icon(), asn); + init(service, service->name(), asn); } -KProcessRunner::KProcessRunner(const QString &cmd, const QString &desktopName, const QString &execName, const QString &iconName, const QByteArray &asn, const QString &workingDirectory) - : m_process{new KProcess}, - m_executable(execName) +KProcessRunner::KProcessRunner(const QString &cmd, const KService &service, const QByteArray &asn, const QString &workingDirectory) + : m_process{new KProcess} { ++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,7 +134,7 @@ 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 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); @@ -154,9 +142,7 @@ void KProcessRunner::init(const KService::Ptr &service, const QString &userVisib 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()) { @@ -202,7 +188,7 @@ void KProcessRunner::slotProcessError(QProcess::ProcessError errorCode) // E.g. the process crashed. // This is unlikely to happen while the ApplicationLauncherJob is still connected to the KProcessRunner. // So the emit does nothing, this is really just for debugging. - qCDebug(KIO_GUI) << m_executable << "error=" << errorCode << m_process->errorString(); + qCDebug(KIO_GUI) << service->exec() << "error=" << errorCode << m_process->errorString(); Q_EMIT error(m_process->errorString()); } diff --git a/src/gui/kprocessrunner_p.h b/src/gui/kprocessrunner_p.h index 300acbae..38b4f0e5 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