Change in kio[master]: Add KRun::runService, to be able to get the PID of the newly...

David Faure (Code Review) noreply at kde.org
Tue Dec 30 08:39:26 UTC 2014


David Faure has uploaded a new change for review.

  https://gerrit.vesnicky.cesnet.cz/r/285

Change subject: Add KRun::runService, to be able to get the PID of the newly started process.
......................................................................

Add KRun::runService, to be able to get the PID of the newly started process.

The first use for this will be the unittest that needs to kill kioexec
after starting it.

Change-Id: I70f8c8b6609d969f0facdfde5943b36f7d935213
---
M src/widgets/krun.cpp
M src/widgets/krun.h
2 files changed, 40 insertions(+), 13 deletions(-)


  git pull ssh://gerrit.vesnicky.cesnet.cz:29418/kio refs/changes/85/285/1

diff --git a/src/widgets/krun.cpp b/src/widgets/krun.cpp
index 026e2e1..b9ad4e0 100644
--- a/src/widgets/krun.cpp
+++ b/src/widgets/krun.cpp
@@ -287,7 +287,7 @@
 }
 #endif
 
-static bool runCommandInternal(KProcess *proc, const KService *service, const QString &executable,
+static qint64 runCommandInternal(KProcess *proc, const KService *service, const QString &executable,
                                const QString &userVisibleName, const QString &iconName, QWidget *window,
                                const QByteArray &asn)
 {
@@ -299,7 +299,7 @@
         qWarning() << "No authorization to execute " << service->entryPath();
         KMessageBox::sorry(window, i18n("You are not authorized to execute this file."));
         delete proc;
-        return false;
+        return 0;
     }
 
     QString bin = KIO::DesktopExecParser::executableName(executable);
@@ -342,20 +342,20 @@
             }
             KStartupInfo::sendStartup(id, data);
         }
-        int pid = KProcessRunner::run(proc, executable, id);
+        qint64 pid = KProcessRunner::run(proc, executable, id);
         if (startup_notify && pid) {
             KStartupInfoData data;
             data.addPid(pid);
             KStartupInfo::sendChange(id, data);
             KStartupInfo::resetStartupEnv();
         }
-        return pid != 0;
+        return pid;
     }
 #else
     Q_UNUSED(userVisibleName);
     Q_UNUSED(iconName);
 #endif
-    return KProcessRunner::run(proc, bin, KStartupInfoId()) != 0;
+    return KProcessRunner::run(proc, bin, KStartupInfoId());
 }
 
 // This code is also used in klauncher.
@@ -398,7 +398,7 @@
     return true;
 }
 
-static bool runTempService(const KService &_service, const QList<QUrl> &_urls, QWidget *window,
+static qint64 runTempService(const KService &_service, const QList<QUrl> &_urls, QWidget *window,
                            bool tempFiles, const QString &suggestedFileName, const QByteArray &asn)
 {
     //qDebug() << "runTempService:" << _urls;
@@ -425,7 +425,7 @@
     const QStringList args = execParser.resultingArguments();
     if (args.isEmpty()) {
         KMessageBox::sorry(window, i18n("Error processing Exec field in %1", _service.entryPath()));
-        return false;
+        return 0;
     }
     //qDebug() << "runTempService: KProcess args=" << args;
 
@@ -700,10 +700,16 @@
 bool KRun::run(const KService &_service, const QList<QUrl> &_urls, QWidget *window,
                bool tempFiles, const QString &suggestedFileName, const QByteArray &asn)
 {
+    return runService(_service, _urls, window, tempFiles, suggestedFileName, asn) != 0;
+}
+
+qint64 KRun::runService(const KService &_service, const QList<QUrl> &_urls, QWidget *window,
+                      bool tempFiles, const QString &suggestedFileName, const QByteArray &asn)
+{
     if (!_service.entryPath().isEmpty() &&
             !KDesktopFile::isAuthorizedDesktopFile(_service.entryPath()) &&
             !::makeServiceExecutable(_service, window)) {
-        return false;
+        return 0;
     }
 
     if (!tempFiles) {
@@ -740,7 +746,7 @@
     //qDebug() << "Running" << _service.entryPath() << _urls << "using klauncher";
 
     QString error;
-    int pid = 0; //TODO: change KToolInvokation to take a qint64*?
+    int pid = 0; //TODO KF6: change KToolInvokation to take a qint64*
 
     QByteArray myasn = asn;
     // startServiceByDesktopPath() doesn't take QWidget*, add it to the startup info now
@@ -764,11 +770,11 @@
     if (i != 0) {
         //qDebug() << error;
         KMessageBox::sorry(window, error);
-        return false;
+        return 0;
     }
 
     //qDebug() << "startServiceByDesktopPath worked fine";
-    return true;
+    return pid;
 }
 
 bool KRun::run(const QString &_exec, const QList<QUrl> &_urls, QWidget *window, const QString &_name,
@@ -815,7 +821,7 @@
     return runCommandInternal(proc, service.data(),
                               execName /*executable to check for in slotProcessExited*/,
                               execName /*user-visible name*/,
-                              iconName, window, asn);
+                              iconName, window, asn) != 0;
 }
 
 KRun::KRun(const QUrl &url, QWidget *window,
diff --git a/src/widgets/krun.h b/src/widgets/krun.h
index 6d33c2f..f6ce8a0 100644
--- a/src/widgets/krun.h
+++ b/src/widgets/krun.h
@@ -200,12 +200,33 @@
      * @param suggestedFileName see setSuggestedFileName
      * @param asn Application startup notification id, if any (otherwise "").
      * @return @c true on success, @c false on error
+     *
+     * @deprecated since 5.6, use runService instead. No change needed on the application side,
+     * the only difference is the return value (qint64 instead of bool).
      */
-    static bool run(const KService &service, const QList<QUrl> &urls, QWidget *window,
+    static KIOWIDGETS_DEPRECATED bool run(const KService &service, const QList<QUrl> &urls, QWidget *window,
                     bool tempFiles = false, const QString &suggestedFileName = QString(),
                     const QByteArray &asn = QByteArray());
 
     /**
+     * Open a list of URLs with a certain service (application).
+     *
+     * @param service the service to run
+     * @param urls the list of URLs, can be empty (app launched
+     *        without argument)
+     * @param window The top-level widget of the app that invoked this object.
+     * @param tempFiles if true and urls are local files, they will be deleted
+     *        when the application exits.
+     * @param suggestedFileName see setSuggestedFileName
+     * @param asn Application startup notification id, if any (otherwise "").
+     * @return 0 on error, the process ID on success
+     * @since 5.6
+     */
+    static qint64 runService(const KService &service, const QList<QUrl> &urls, QWidget *window,
+                             bool tempFiles = false, const QString &suggestedFileName = QString(),
+                             const QByteArray &asn = QByteArray());
+
+    /**
      * Open a list of URLs with an executable.
      *
      * @param exec the name of the executable, for example

-- 
To view, visit https://gerrit.vesnicky.cesnet.cz/r/285
To unsubscribe, visit https://gerrit.vesnicky.cesnet.cz/r/settings

Gerrit-MessageType: newchange
Gerrit-Change-Id: I70f8c8b6609d969f0facdfde5943b36f7d935213
Gerrit-PatchSet: 1
Gerrit-Project: kio
Gerrit-Branch: master
Gerrit-Owner: David Faure <faure at kde.org>
Gerrit-Reviewer: Alexander Richardson <arichardson.kde at gmail.com>
Gerrit-Reviewer: Martin Gräßlin <mgraesslin at kde.org>
Gerrit-Reviewer: Sysadmin Testing Account <null at kde.org>


More information about the Kde-frameworks-devel mailing list