From 7da3e583cab231b7505acb3dbc6ee63c6d557929 Mon Sep 17 00:00:00 2001 From: Kai Uwe Broulik Date: Fri, 13 Nov 2020 14:25:44 +0100 Subject: [PATCH] [Location Runner] Also explicitly look for URL scheme handlers KProtocolInfo handles only protocols KIO knows but apps can also register to be a URL scheme handler independently of this. This patch makes the location runner also query for the preferred URL scheme handler when no known protocol is found. It also prefers the scheme handler over the helper protocol since a service has a name. While at it, also format the protocol "exec" using DesktopExecParser to avoid showing placeholders like '%u' to the user. Also use PreferLocalFile for "go to". BUG: 416257 --- runners/locations/locationrunner.cpp | 31 ++++++++++++++++++++-------- 1 file changed, 22 insertions(+), 9 deletions(-) diff --git a/runners/locations/locationrunner.cpp b/runners/locations/locationrunner.cpp index 2c57961f7..e92093d2f 100644 --- a/runners/locations/locationrunner.cpp +++ b/runners/locations/locationrunner.cpp @@ -24,10 +24,12 @@ #include #include +#include #include #include #include #include +#include #include #include @@ -85,24 +87,35 @@ void LocationsRunner::match(Plasma::RunnerContext &context) QUrl url(term); - if (url.isEmpty() || !KProtocolInfo::isKnownProtocol(url.scheme())) { + if (url.isEmpty()) { return; } Plasma::QueryMatch match(this); - match.setIconName(KProtocolInfo::icon(url.scheme())); match.setData(url.url()); - if (KProtocolInfo::isHelperProtocol(url.scheme())) { - //qDebug() << "helper protocol" << url.protocol() <<"call external application" ; - if (url.scheme() == QLatin1String("mailto")) { - match.setText(i18n("Send email to %1",url.path())); + const QString protocol = url.scheme(); + + if (!KProtocolInfo::isKnownProtocol(protocol) || KProtocolInfo::isHelperProtocol(protocol)) { + const KService::Ptr service = KApplicationTrader::preferredService(QLatin1String("x-scheme-handler/") + protocol); + if (service) { + match.setIconName(service->icon()); + match.setText(i18n("Launch with %1", service->name())); + } else if (KProtocolInfo::isKnownProtocol(protocol)) { + Q_ASSERT(KProtocolInfo::isHelperProtocol(protocol)); + match.setIconName(KProtocolInfo::icon(protocol)); + match.setText(i18n("Launch with %1", KIO::DesktopExecParser::executableName( + KProtocolInfo::exec(protocol)))); } else { - match.setText(i18n("Launch with %1", KProtocolInfo::exec(url.scheme()))); + return; } } else { - //qDebug() << "protocol managed by browser" << url.protocol(); - match.setText(i18n("Go to %1", url.toDisplayString())); + match.setIconName(KProtocolInfo::icon(protocol)); + match.setText(i18n("Go to %1", url.toDisplayString(QUrl::PreferLocalFile))); + } + + if (url.scheme() == QLatin1String("mailto")) { + match.setText(i18n("Send email to %1", url.path())); } if (type == Plasma::RunnerContext::UnknownType) {