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 proces= s. 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, co= nst QString &executable, +static qint64 runCommandInternal(KProcess *proc, const KService *service, = const QString &executable, const QString &userVisibleName, const QStri= ng &iconName, QWidget *window, const QByteArray &asn) { @@ -299,7 +299,7 @@ static bool runCommandInternal(KProcess *proc, const KS= ervice *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 =3D KIO::DesktopExecParser::executableName(executable); @@ -342,20 +342,20 @@ static bool runCommandInternal(KProcess *proc, const = KService *service, const QS } KStartupInfo::sendStartup(id, data); } - int pid =3D KProcessRunner::run(proc, executable, id); + qint64 pid =3D KProcessRunner::run(proc, executable, id); if (startup_notify && pid) { KStartupInfoData data; data.addPid(pid); KStartupInfo::sendChange(id, data); KStartupInfo::resetStartupEnv(); } - return pid !=3D 0; + return pid; } #else Q_UNUSED(userVisibleName); Q_UNUSED(iconName); #endif - return KProcessRunner::run(proc, bin, KStartupInfoId()) !=3D 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 &_u= rls, QWidget *window, +static qint64 runTempService(const KService &_service, const QList &= _urls, QWidget *window, bool tempFiles, const QString &suggestedFileNam= e, const QByteArray &asn) { //qDebug() << "runTempService:" << _urls; @@ -425,7 +425,7 @@ static bool runTempService(const KService &_service, co= nst QList &_urls, Q const QStringList args =3D 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=3D" << args; = @@ -700,10 +700,16 @@ static bool makeServiceExecutable(const KService &ser= vice, QWidget *window) bool KRun::run(const KService &_service, const QList &_urls, QWidget= *window, bool tempFiles, const QString &suggestedFileName, const QBy= teArray &asn) { + return runService(_service, _urls, window, tempFiles, suggestedFileNam= e, asn) !=3D 0; +} + +qint64 KRun::runService(const KService &_service, const QList &_urls= , QWidget *window, + bool tempFiles, const QString &suggestedFileName, co= nst 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 &_urls, QWidget *wind //qDebug() << "Running" << _service.entryPath() << _urls << "using kla= uncher"; = QString error; - int pid =3D 0; //TODO: change KToolInvokation to take a qint64*? + int pid =3D 0; //TODO KF6: change KToolInvokation to take a qint64* = QByteArray myasn =3D asn; // startServiceByDesktopPath() doesn't take QWidget*, add it to the st= artup info now @@ -764,11 +770,11 @@ bool KRun::run(const KService &_service, const QList<= QUrl> &_urls, QWidget *wind if (i !=3D 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 &_urls, QWidget *wi= ndow, 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 slotPr= ocessExited*/, execName /*user-visible name*/, - iconName, window, asn); + iconName, window, asn) !=3D 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 &urls, QWid= get *window, + static KIOWIDGETS_DEPRECATED bool run(const KService &service, const Q= List &urls, QWidget *window, bool tempFiles =3D false, const QString &suggestedFile= Name =3D QString(), const QByteArray &asn =3D 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 obj= ect. + * @param tempFiles if true and urls are local files, they will be del= eted + * 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 &u= rls, QWidget *window, + bool tempFiles =3D false, const QString &sugg= estedFileName =3D QString(), + const QByteArray &asn =3D QByteArray()); + + /** * Open a list of URLs with an executable. * * @param exec the name of the executable, for example