Commit 6e660cf9 authored by Kai Uwe Broulik's avatar Kai Uwe Broulik 🍇

Port services and shell runner away from KRun

Use ApplicationLauncherJob and CommandLauncherJob.
Also, for services runner pass a KServiceAction to the job so it invokes the appropriate jump list action

Differential Revision: https://phabricator.kde.org/D28347
parent ca94149e
......@@ -13,8 +13,9 @@ ecm_qt_declare_logging_category(krunner_services_SRCS
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
......
......@@ -20,6 +20,8 @@
#include "servicerunner.h"
#include <algorithm>
#include <QMimeData>
#include <QDebug>
......@@ -30,11 +32,14 @@
#include <KActivities/ResourceInstance>
#include <KLocalizedString>
#include <KRun>
#include <KNotificationJobUiDelegate>
#include <KService>
#include <KServiceAction>
#include <KServiceTypeTrader>
#include <KStringHandler>
#include <KIO/ApplicationLauncherJob>
#include "debug.h"
namespace {
......@@ -167,7 +172,10 @@ private:
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 @@ private:
}
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 @@ void ServiceRunner::run(const Plasma::RunnerContext &context, const Plasma::Quer
{
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)
......
......@@ -5,8 +5,9 @@ set(krunner_shell_SRCS shellrunner.cpp)
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
......
......@@ -21,9 +21,11 @@
#include <KAuthorized>
#include <KLocalizedString>
#include <KRun>
#include <KNotificationJobUiDelegate>
#include <KToolInvocation>
#include <KIO/CommandLauncherJob>
K_EXPORT_PLASMA_RUNNER(shell, ShellRunner)
ShellRunner::ShellRunner(QObject *parent, const QVariantList &args)
......@@ -67,9 +69,14 @@ void ShellRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryM
{
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<QAction *> ShellRunner::actionsForMatch(const Plasma::QueryMatch &match)
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment