Commit a3f22cde authored by Harald Sitter's avatar Harald Sitter 🏳🌈
Browse files

adjust relevance of kcms in service runner

kcms are handy but not nearly as handy as an actual application. this is
particular notable with the test case where the user could type 'virt'
but that wouldn't have pushed virtualization software to the top but kcms
since kcms are kde things so they always get a .09 bump to
relevance.

the revised scoring excludes kcms from the bump and further reduces the
relvance by the tiniest fraction. this results in all applications that
match at least as well as the KCM to outscore the KCM
parent 3e2e0dd2
......@@ -4,3 +4,4 @@ include(ECMAddTests)
ecm_add_test(servicerunnertest.cpp TEST_NAME servicerunnertest
LINK_LIBRARIES Qt5::Test krunner_services_static)
set_target_properties(servicerunnertest PROPERTIES CXX_STANDARD 17) # std::optional
[Desktop Entry]
Exec=kcmshell5 kcm_kwin_virtualdesktops
Icon=preferences-desktop-virtual
Type=Service
X-KDE-ServiceTypes=KCModule
X-DocPath=kcontrol/kwin_virtualdesktops/index.html
X-KDE-Library=kcm_kwin_virtualdesktops
X-KDE-ParentApp=kcontrol
X-KDE-FormFactors=desktop
X-KDE-System-Settings-Parent-Category=desktopbehavior
X-KDE-Weight=60
Name=Virtual Desktops
Comment=Configure navigation, number and layout of virtual desktops
X-KDE-Keywords=desktop,desktops,number,virtual desktop,multiple desktops,pager,pager widget,pager applet,pager settings
Categories=Qt;KDE;X-KDE-settings-translations;
[Desktop Entry]
Exec=virtthings
Icon=preferences-system
Type=Application
X-DocPath=systemsettings/index.html
X-KDE-StartupNotify=true
OnlyShowIn=KDE;
GenericName=VirtThings ServiceRunnerTest
Name=VirtThings ServiceRunnerTest
X-DBUS-StartupType=Unique
Categories=Qt;KDE;Settings;
[Desktop Entry]
Name=Virtual Machine Manager
Comment=Manage virtual machines
Icon=virt-manager
Exec=virt-manager
Type=Application
Terminal=false
Categories=System;
......@@ -30,6 +30,7 @@
#include "../servicerunner.h"
#include <clocale>
#include <optional>
class ServiceRunnerTest : public QObject
{
......@@ -41,6 +42,7 @@ private Q_SLOTS:
void testChromeAppsRelevance();
void testKonsoleVsYakuakeComment();
void testSystemSettings();
void testForeignAppsOutscoreKCMs();
};
void ServiceRunnerTest::initTestCase()
......@@ -163,6 +165,45 @@ void ServiceRunnerTest::testSystemSettings()
QVERIFY(!foreignSystemSettingsFound);
}
void ServiceRunnerTest::testForeignAppsOutscoreKCMs()
{
// Our software outscores other things, but foreign applications should still
// outscore our KCMs.
ServiceRunner runner(this, QVariantList());
Plasma::RunnerContext context;
context.setQuery(QStringLiteral("virt"));
runner.match(context);
std::optional<qreal> virtManRelevance;
std::optional<qreal> virtThingsRelevance;
std::optional<qreal> kcmRelevance;
const auto matches = context.matches();
for (const auto &match : matches) {
const QUrl url = match.data().toUrl();
if (url == QUrl(QStringLiteral("applications:virt-manager.desktop"))) {
virtManRelevance = match.relevance();
} else if (url == QUrl(QStringLiteral("applications:kcm_kwin_virtualdesktops.desktop"))) {
kcmRelevance = match.relevance();
} else if (url == QUrl(QStringLiteral("applications:org.kde.virtthings.desktop"))) {
virtThingsRelevance = match.relevance();
}
}
QVERIFY(virtManRelevance.has_value());
QVERIFY(virtThingsRelevance.has_value());
QVERIFY(kcmRelevance.has_value());
// KDE app should be >= non-KDE app
QVERIFY2(virtThingsRelevance >= virtManRelevance,
qPrintable(QStringLiteral("%1 >= %2").arg(virtThingsRelevance.value()).arg(virtManRelevance.value())));
// KDE app strictly greater KDE kcm
QVERIFY2(virtThingsRelevance > kcmRelevance,
qPrintable(QStringLiteral("%1 > %2").arg(virtThingsRelevance.value()).arg(kcmRelevance.value())));
// non-KDE app also strictly greater (because it is an app)
QVERIFY2(virtManRelevance > kcmRelevance,
qPrintable(QStringLiteral("%1 > %2").arg(virtManRelevance.value()).arg(kcmRelevance.value())));
}
QTEST_MAIN(ServiceRunnerTest)
#include "servicerunnertest.moc"
......@@ -286,20 +286,26 @@ private:
}
}
if (service->categories().contains(QLatin1String("KDE")) || service->serviceTypes().contains(QLatin1String("KCModule"))) {
const bool isKCM = service->serviceTypes().contains(QLatin1String("KCModule"));
if (!isKCM && (service->categories().contains(QLatin1String("KDE")) || service->serviceTypes().contains(QLatin1String("KCModule")))) {
qCDebug(RUNNER_SERVICES) << "found a kde thing" << id << match.subtext() << relevance;
relevance += .09;
}
qCDebug(RUNNER_SERVICES) << service->name() << "is this relevant:" << relevance;
match.setRelevance(relevance);
if (service->serviceTypes().contains(QLatin1String("KCModule"))) {
if (isKCM) {
if (service->parentApp() == QStringLiteral("kinfocenter")) {
match.setMatchCategory(i18n("System Information"));
} else {
match.setMatchCategory(i18n("System Settings"));
}
// KCMs are, on the balance, less relevant. Drop it ever so much. So they may get outscored
// by an otherwise equally applicable match.
relevance -= .001;
}
qCDebug(RUNNER_SERVICES) << service->name() << "is this relevant:" << relevance;
match.setRelevance(relevance);
matches << 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