[prev in list] [next in list] [prev in thread] [next in thread] 

List:       kde-commits
Subject:    [kio] src/widgets: Add KRun::runService, to be able to get the PID of the newly started process.
From:       David Faure <faure () kde ! org>
Date:       2014-12-31 23:25:13
Message-ID: E1Y6Sdd-0007xE-TA () scm ! kde ! org
[Download RAW message or body]

Git commit be226ce43b56c5fc03872045df67badbdd836f7a by David Faure.
Committed on 30/12/2014 at 08:32.
Pushed by dfaure into branch 'master'.

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.

CHANGELOG: New method KRun::runService, like KRun::run but returns the PID of the \
newly started process.

Change-Id: I70f8c8b6609d969f0facdfde5943b36f7d935213

M  +18   -12   src/widgets/krun.cpp
M  +22   -1    src/widgets/krun.h

http://commits.kde.org/kio/be226ce43b56c5fc03872045df67badbdd836f7a

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 @@ QString KRun::binaryName(const QString &execLine, bool \
removePath)  }
 #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 @@ static bool runCommandInternal(KProcess *proc, const KService \
                *service, const QS
         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 @@ static bool runCommandInternal(KProcess *proc, const KService \
*service, const QS  }
             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 @@ bool KRun::checkStartupNotify(const QString & /*binName*/, const \
KService *servi  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 @@ static bool runTempService(const KService &_service, const \
QList<QUrl> &_urls, Q  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 @@ static bool makeServiceExecutable(const KService &service, \
QWidget *window)  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 @@ bool KRun::run(const KService &_service, const QList<QUrl> \
                &_urls, QWidget *wind
     //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 @@ bool KRun::run(const KService &_service, const QList<QUrl> \
&_urls, QWidget *wind  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 @@ bool KRun::runCommand(const QString &cmd, \
const QString &execName, const QString  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 @@ public:
      * @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


[prev in list] [next in list] [prev in thread] [next in thread] 

Configure | About | News | Add a list | Sponsored by KoreLogic