Commit 989d9b17 authored by Alexander Lohnau's avatar Alexander Lohnau 💬 Committed by Nate Graham
Browse files

Set new KRunner property to reduce duplicates and make IDs comparable

CCBUG: 406292
parent 1cf02aad
......@@ -26,6 +26,7 @@
#include <QDesktopServices>
#include <QDir>
#include <QIcon>
#include <QTimer>
#include <KApplicationTrader>
#include <KLocalizedString>
......@@ -39,7 +40,8 @@ InstallerRunner::InstallerRunner(QObject *parent, const KPluginMetaData &metaDat
: Plasma::AbstractRunner(parent, metaData, args)
{
setObjectName(QStringLiteral("Installation Suggestions"));
setPriority(AbstractRunner::HighestPriority);
// We want to give the other runners time to check if there are matching applications already installed
setPriority(AbstractRunner::LowestPriority);
addSyntax(Plasma::RunnerSyntax(":q:", i18n("Looks for non-installed components according to :q:")));
setMinLetterCount(3);
......@@ -80,6 +82,25 @@ static QIcon componentIcon(const AppStream::Component &comp)
void InstallerRunner::match(Plasma::RunnerContext &context)
{
// Give the other runners a bit of time to produce results
QEventLoop loop;
QTimer::singleShot(200, &loop, [&loop]() {
loop.quit();
});
loop.exec();
if (!context.isValid()) {
return;
}
// Check if other plugins have already found an executable, if that is the case we do
// not want to ask the user to install anything else
const QList<Plasma::QueryMatch> matches = context.matches();
for (const auto &match : matches) {
if (match.id().startsWith(QLatin1String("exec://"))) {
return;
}
}
const auto components = findComponentsByString(context.query()).mid(0, 3);
for (const AppStream::Component &component : components) {
......
......@@ -172,7 +172,7 @@ RemoteMatches SearchRunner::matchInternal(const QString &searchTerm, const QStri
foundUrls.insert(url);
match.id = it.filePath();
match.id = url.toString();
match.text = url.fileName();
match.iconName = mimeDb.mimeTypeForFile(localUrl).iconName();
match.relevance = relevance;
......@@ -197,7 +197,7 @@ RemoteMatches SearchRunner::matchInternal(const QString &searchTerm, const QStri
void SearchRunner::Run(const QString &id, const QString &actionId)
{
const QUrl url = QUrl::fromLocalFile(id);
const QUrl url(id);
if (actionId == s_openParentDirId) {
KIO::highlightInFileManager({url});
return;
......
......@@ -110,3 +110,5 @@ X-Plasma-DBusRunner-Service=org.kde.runners.baloo
X-Plasma-DBusRunner-Path=/runner
X-Plasma-Request-Actions-Once=true
X-Plasma-Runner-Min-Letter-Count=3
X-Plasma-Runner-Unique-Results=true
X-Plasma-Runner-Weak-Results=true
......@@ -47,3 +47,4 @@ X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-License=LGPL
X-Plasma-AdvertiseSingleRunnerQueryMode=true
X-KDE-PluginInfo-EnabledByDefault=true
X-Plasma-Runner-Unique-Results=true
......@@ -97,6 +97,7 @@ void RecentDocuments::match(Plasma::RunnerContext &context)
match.setRelevance(relevance);
match.setData(QVariant(url));
match.setUrls({url});
match.setId(url.toString());
if (url.isLocalFile()) {
match.setActions(actions().values());
}
......
......@@ -175,3 +175,4 @@ X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-License=LGPL
X-KDE-PluginInfo-EnabledByDefault=true
X-Plasma-AdvertiseSingleRunnerQueryMode=true
X-Plasma-Runner-Unique-Results=true
......@@ -40,6 +40,7 @@
#include <KSycoca>
#include <KIO/ApplicationLauncherJob>
#include <KIO/DesktopExecParser>
#include "debug.h"
......@@ -177,6 +178,13 @@ private:
QUrl url(service->storageId());
url.setScheme(QStringLiteral("applications"));
match.setData(url);
QString exec = service->exec();
// We have a snap, remove the ENV variable
if (exec.contains(QLatin1String("BAMF_DESKTOP_FILE_HINT"))) {
const static QRegularExpression snapCleanupRegex(QStringLiteral("env BAMF_DESKTOP_FILE_HINT=.+ "));
exec.remove(snapCleanupRegex);
}
match.setId(QStringLiteral("exec://") + KIO::DesktopExecParser::executableName(exec));
if (!service->genericName().isEmpty() && service->genericName() != name) {
match.setSubtext(service->genericName());
......
......@@ -164,3 +164,5 @@ X-KDE-PluginInfo-Version=1.0
X-KDE-PluginInfo-License=LGPL
X-Plasma-AdvertiseSingleRunnerQueryMode=true
X-KDE-PluginInfo-EnabledByDefault=true
X-Plasma-Runner-Unique-Results=true
X-Plasma-Runner-Weak-Results=true
......@@ -36,7 +36,8 @@ ShellRunner::ShellRunner(QObject *parent, const KPluginMetaData &metaData, const
: Plasma::AbstractRunner(parent, metaData, args)
{
setObjectName(QStringLiteral("Command"));
setPriority(AbstractRunner::HighestPriority);
// The results from the services runner are preferred, consequently we set a low priority
setPriority(AbstractRunner::LowestPriority);
// If the runner is not authorized we can suspend it
bool enabled = KAuthorized::authorize(QStringLiteral("run_command")) && KAuthorized::authorize(QStringLiteral("shell_access"));
suspendMatching(!enabled);
......@@ -57,7 +58,7 @@ void ShellRunner::match(Plasma::RunnerContext &context)
if (parseShellCommand(context.query(), envs, command)) {
const QString term = context.query();
Plasma::QueryMatch match(this);
match.setId(term);
match.setId(QStringLiteral("exec://") + context.query());
match.setType(Plasma::QueryMatch::ExactMatch);
match.setIcon(m_matchIcon);
match.setText(i18n("Run %1", term));
......
Supports Markdown
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