[Service Runner] Search for Jump List Actions

This makes the service runner find also additional actions provided by applications,
eg. "big picture" now finds Steam's "Big Picture" mode which isn't a separate application
service but instead an action on the main application.

Differential Revision: https://phabricator.kde.org/D1504
wilder-5.14
Kai Uwe Broulik 10 years ago
parent 00506521cd
commit 00593d47e0
  1. 49
      runners/services/servicerunner.cpp

@ -237,6 +237,48 @@ void ServiceRunner::match(Plasma::RunnerContext &context)
}
}
// search for jump list actions
if (term.length() >= 3) {
query = QStringLiteral("exist Actions"); // doesn't work
services = KServiceTypeTrader::self()->query(QStringLiteral("Application"));//, query);
foreach (const KService::Ptr &service, services) {
if (service->noDisplay()) {
continue;
}
foreach (const KServiceAction &action, service->actions()) {
if (action.text().isEmpty() || action.exec().isEmpty() || seen.contains(action.exec())) {
continue;
}
if (!action.text().contains(term, Qt::CaseInsensitive)) {
continue;
}
Plasma::QueryMatch match(this);
match.setType(Plasma::QueryMatch::HelperMatch);
if (!action.icon().isEmpty()) {
match.setIcon(QIcon::fromTheme(action.icon()));
} else {
match.setIcon(QIcon::fromTheme(service->icon()));
}
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(action.exec());
qreal relevance = 0.5;
if (action.text().startsWith(term, Qt::CaseInsensitive)) {
relevance += 0.05;
}
match.setRelevance(relevance);
matches << match;
}
}
}
//context.addMatches(term, matches);
context.addMatches(matches);
}
@ -244,9 +286,14 @@ void ServiceRunner::match(Plasma::RunnerContext &context)
void ServiceRunner::run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &match)
{
Q_UNUSED(context);
if (match.type() == Plasma::QueryMatch::HelperMatch) { // Jump List Action
KRun::run(match.data().toString(), {}, nullptr);
return;
}
KService::Ptr service = KService::serviceByStorageId(match.data().toString());
if (service) {
KRun::run(*service, QList<QUrl>(), 0);
KRun::runService(*service, {}, nullptr);
}
}

Loading…
Cancel
Save