diff --git a/runners/services/CMakeLists.txt b/runners/services/CMakeLists.txt --- a/runners/services/CMakeLists.txt +++ b/runners/services/CMakeLists.txt @@ -13,8 +13,9 @@ add_library(krunner_services_static STATIC ${krunner_services_SRCS}) target_link_libraries(krunner_services_static KF5::CoreAddons - KF5::KIOWidgets + KF5::KIOGui KF5::I18n + KF5::Notifications KF5::Runner KF5::Service KF5::Activities diff --git a/runners/services/servicerunner.cpp b/runners/services/servicerunner.cpp --- a/runners/services/servicerunner.cpp +++ b/runners/services/servicerunner.cpp @@ -20,6 +20,8 @@ #include "servicerunner.h" +#include + #include #include @@ -30,11 +32,14 @@ #include #include -#include +#include #include +#include #include #include +#include + #include "debug.h" namespace { @@ -167,7 +172,10 @@ const QString name = service->name(); match.setText(name); - match.setData(service->storageId()); + + QUrl url(service->storageId()); + url.setScheme(QStringLiteral("applications")); + match.setData(url); if (!service->genericName().isEmpty() && service->genericName() != name) { match.setSubtext(service->genericName()); @@ -358,7 +366,15 @@ } match.setText(i18nc("Jump list search result, %1 is action (eg. open new tab), %2 is application (eg. browser)", "%1 - %2", action.text(), service->name())); - match.setData(QStringLiteral("exec::") + action.exec()); + + QUrl url(service->storageId()); + url.setScheme(QStringLiteral("applications")); + + QUrlQuery query; + query.addQueryItem(QStringLiteral("action"), action.name()); + url.setQuery(query); + + match.setData(url); qreal relevance = 0.5; if (matchIndex == 0) { @@ -426,23 +442,37 @@ { Q_UNUSED(context); - const QString dataString = match.data().toString(); + const QUrl dataUrl = match.data().toUrl(); - const QString execPrefix = QStringLiteral("exec::"); - if (dataString.startsWith(execPrefix)) { - KRun::run(dataString.mid(execPrefix.length()), {}, nullptr); - return; + KService::Ptr service = KService::serviceByStorageId(dataUrl.path()); + if (!service) { + return; } - KService::Ptr service = KService::serviceByStorageId(dataString); - if (service) { - KActivities::ResourceInstance::notifyAccessed( - QUrl(QStringLiteral("applications:") + service->storageId()), - QStringLiteral("org.kde.krunner") - ); + KActivities::ResourceInstance::notifyAccessed( + QUrl(QStringLiteral("applications:") + service->storageId()), + QStringLiteral("org.kde.krunner") + ); + + KIO::ApplicationLauncherJob *job = nullptr; - KRun::runService(*service, {}, nullptr, true); + const QString actionName = QUrlQuery(dataUrl).queryItemValue(QStringLiteral("action")); + if (actionName.isEmpty()) { + job = new KIO::ApplicationLauncherJob(service); + } else { + const auto actions = service->actions(); + auto it = std::find_if(actions.begin(), actions.end(), [&actionName](const KServiceAction &action) { + return action.name() == actionName; + }); + Q_ASSERT(it != actions.end()); + + job = new KIO::ApplicationLauncherJob(*it); } + + auto *delegate = new KNotificationJobUiDelegate; + delegate->setAutoErrorHandlingEnabled(true); + job->setUiDelegate(delegate); + job->start(); } QMimeData * ServiceRunner::mimeDataForMatch(const Plasma::QueryMatch &match) diff --git a/runners/shell/CMakeLists.txt b/runners/shell/CMakeLists.txt --- a/runners/shell/CMakeLists.txt +++ b/runners/shell/CMakeLists.txt @@ -5,8 +5,9 @@ add_library(krunner_shell MODULE ${krunner_shell_SRCS}) target_link_libraries(krunner_shell KF5::KIOCore - KF5::KIOWidgets + KF5::KIOGui KF5::I18n + KF5::Notifications KF5::Plasma KF5::Runner KF5::Completion diff --git a/runners/shell/shellrunner.cpp b/runners/shell/shellrunner.cpp --- a/runners/shell/shellrunner.cpp +++ b/runners/shell/shellrunner.cpp @@ -21,9 +21,11 @@ #include #include -#include +#include #include +#include + K_EXPORT_PLASMA_RUNNER(shell, ShellRunner) ShellRunner::ShellRunner(QObject *parent, const QVariantList &args) @@ -67,9 +69,14 @@ { if (match.selectedAction()) { KToolInvocation::invokeTerminal(context.query()); - } else { - KRun::runCommand(context.query(), nullptr); + return; } + + auto *job = new KIO::CommandLauncherJob(context.query()); + auto *delegate = new KNotificationJobUiDelegate; + delegate->setAutoErrorHandlingEnabled(true); + job->setUiDelegate(delegate); + job->start(); } QList ShellRunner::actionsForMatch(const Plasma::QueryMatch &match)