[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
wilder-5.22
Kai Uwe Broulik 5 years ago
parent e6b9b04005
commit 7da3e583ca
  1. 31
      runners/locations/locationrunner.cpp

@ -24,10 +24,12 @@
#include <QDir>
#include <QDebug>
#include <KApplicationTrader>
#include <KRun>
#include <KLocalizedString>
#include <KProtocolInfo>
#include <KUriFilter>
#include <KIO/DesktopExecParser>
#include <KIO/Global>
#include <KShell>
@ -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) {

Loading…
Cancel
Save