From 50530a7739e0d4c6c486e55513adf43f8687ccae Mon Sep 17 00:00:00 2001 From: David Faure Date: Fri, 22 May 2020 22:36:25 +0200 Subject: [PATCH] Port plasma-framework away from KRun --- src/plasma/CMakeLists.txt | 2 +- .../private/associatedapplicationmanager.cpp | 27 +++++++++++++------ 2 files changed, 20 insertions(+), 9 deletions(-) diff --git a/src/plasma/CMakeLists.txt b/src/plasma/CMakeLists.txt index 936983ff9..45759557e 100644 --- a/src/plasma/CMakeLists.txt +++ b/src/plasma/CMakeLists.txt @@ -125,7 +125,7 @@ PRIVATE KF5::GuiAddons #kimagecache KF5::I18n KF5::KIOCore #ServiceJob - KF5::KIOWidgets #KRun + KF5::KIOWidgets #KIO::JobUiDelegate KF5::WindowSystem #compositingActive KF5::Declarative #runtimePlatform KF5::XmlGui #KActionCollection diff --git a/src/plasma/private/associatedapplicationmanager.cpp b/src/plasma/private/associatedapplicationmanager.cpp index 5d5beb78f..34645a4ed 100644 --- a/src/plasma/private/associatedapplicationmanager.cpp +++ b/src/plasma/private/associatedapplicationmanager.cpp @@ -33,8 +33,10 @@ #include #include #include - -#include +#include +#include +#include +#include #include "plasma/applet.h" @@ -192,13 +194,22 @@ QList AssociatedApplicationManager::urls(const Plasma::Applet *applet) con void AssociatedApplicationManager::run(Plasma::Applet *applet) { if (d->applicationNames.contains(applet)) { - bool success = KRun::run(d->applicationNames.value(applet), d->urlLists.value(applet), nullptr); - if (!success) { - qCWarning(LOG_PLASMA) << "couldn't run" << d->applicationNames.value(applet) << d->urlLists.value(applet); - } + const QString exec = d->applicationNames.value(applet); + KService::Ptr service(new KService(exec, exec, QString() /*icon*/)); + KIO::ApplicationLauncherJob *job = new KIO::ApplicationLauncherJob(service); + job->setUrls(d->urlLists.value(applet)); + job->setUiDelegate(new KNotificationJobUiDelegate(KJobUiDelegate::AutoHandlingEnabled)); + connect(job, &KJob::result, this, [this, applet](KJob *job) { + if (job->error()) { + qCWarning(LOG_PLASMA) << "couldn't run" << d->applicationNames.value(applet) << d->urlLists.value(applet) << job->errorString(); + } + }); + job->start(); } else if (d->urlLists.contains(applet)) { - KRun *krun = new KRun(d->urlLists.value(applet).first(), nullptr); - krun->setAutoDelete(true); + KIO::OpenUrlJob *job = new KIO::OpenUrlJob(d->urlLists.value(applet).first()); + // TODO use a KNotifications-based ui delegate that supports the Open With dialog + job->setUiDelegate(new KIO::JobUiDelegate(KJobUiDelegate::AutoHandlingEnabled, nullptr)); + job->start(); } }