plasma: match the untranslated terms as fallback in runners

see the previous commit

Signed-off-by: Ivailo Monev <xakepa10@gmail.com>
This commit is contained in:
Ivailo Monev 2023-08-04 05:42:03 +03:00
parent 4275b7f7fc
commit 9c2fb0b928
10 changed files with 104 additions and 36 deletions

View file

@ -42,8 +42,10 @@ BookmarksRunner::BookmarksRunner( QObject* parent, const QVariantList &args )
kDebug(kdbg_code) << "Creating BookmarksRunner";
setObjectName( QLatin1String("Bookmarks" ));
addSyntax(Plasma::RunnerSyntax(":q:", i18n("Finds web browser bookmarks matching :q:.")));
setDefaultSyntax(Plasma::RunnerSyntax(i18nc("list of all web browser bookmarks", "bookmarks"),
i18n("List all web browser bookmarks")));
setDefaultSyntax(
Plasma::RunnerSyntax(i18nc("list of all web browser bookmarks", "bookmarks"),
i18n("List all web browser bookmarks"))
);
connect(this, SIGNAL(prepare()), this, SLOT(prep()));
}

View file

@ -30,7 +30,6 @@
#include <QApplication>
#include <QClipboard>
#include <KProtocolManager>
#include <KDebug>
#include <KLocale>

View file

@ -42,6 +42,7 @@ KillRunner::~KillRunner()
void KillRunner::reloadConfiguration()
{
#warning TODO: untranslated keyword match, why is it even translated when it is configurable?
KConfigGroup grp = config();
m_triggerWord.clear();
if (grp.readEntry(CONFIG_USE_TRIGGERWORD, true)) {

View file

@ -86,7 +86,10 @@ void PlacesRunnerHelper::match(Plasma::RunnerContext *c)
}
QList<Plasma::QueryMatch> matches;
const bool all = term.compare(i18n("places"), Qt::CaseInsensitive) == 0;
bool all = term.compare(i18n("places"), Qt::CaseInsensitive) == 0;
if (!all) {
all = term.compare(QLatin1String("places"), Qt::CaseInsensitive) == 0;
}
for (int i = 0; i <= m_places.rowCount(); i++) {
QModelIndex current_index = m_places.index(i, 0);
Plasma::QueryMatch::Type type = Plasma::QueryMatch::NoMatch;

View file

@ -30,10 +30,11 @@
#include <plasma/theme.h>
static const QString s_plasmaService = "org.kde.plasma-desktop";
static const char* s_desktopConsole = "desktop console";
PlasmaDesktopRunner::PlasmaDesktopRunner(QObject *parent, const QVariantList &args)
: Plasma::AbstractRunner(parent, args),
m_desktopConsoleKeyword(i18nc("Note this is a KRunner keyword", "desktop console")),
m_desktopConsoleKeyword(i18nc("Note this is a KRunner keyword", s_desktopConsole)),
m_enabled(false)
{
setObjectName( QLatin1String("Plasma-Desktop" ));
@ -53,7 +54,12 @@ PlasmaDesktopRunner::~PlasmaDesktopRunner()
void PlasmaDesktopRunner::match(Plasma::RunnerContext &context)
{
if (m_enabled && context.query().startsWith(m_desktopConsoleKeyword, Qt::CaseInsensitive)) {
const QString query = context.query();
bool matches = query.startsWith(m_desktopConsoleKeyword, Qt::CaseInsensitive);
if (!matches) {
matches = query.startsWith(QLatin1String(s_desktopConsole), Qt::CaseInsensitive);
}
if (m_enabled && matches) {
Plasma::QueryMatch match(this);
match.setId("plasma-desktop-console");
match.setType(Plasma::QueryMatch::ExactMatch);
@ -72,7 +78,8 @@ void PlasmaDesktopRunner::run(const Plasma::RunnerContext &context, const Plasma
QDBusMessage message;
QString query = context.query();
if (query.compare(m_desktopConsoleKeyword, Qt::CaseInsensitive) == 0) {
if (query.compare(m_desktopConsoleKeyword, Qt::CaseInsensitive) == 0
|| query.compare(QLatin1String(s_desktopConsole), Qt::CaseInsensitive) == 0) {
message = QDBusMessage::createMethodCall(s_plasmaService, "/MainApplication",
QString(), "showInteractiveConsole");
} else if (query.startsWith(m_desktopConsoleKeyword)) {

View file

@ -103,7 +103,8 @@ void PowerDevilRunner::match(Plasma::RunnerContext &context)
}
QList<Plasma::QueryMatch> matches;
if (term.compare(i18nc("Note this is a KRunner keyword", "suspend"), Qt::CaseInsensitive) == 0) {
if (term.compare(i18nc("Note this is a KRunner keyword", "suspend"), Qt::CaseInsensitive) == 0 ||
term.compare(QLatin1String("suspend"), Qt::CaseInsensitive) == 0) {
QSet< Solid::PowerManagement::SleepState > states = Solid::PowerManagement::supportedSleepStates();
if (states.contains(Solid::PowerManagement::SuspendState)) {
@ -117,13 +118,19 @@ void PowerDevilRunner::match(Plasma::RunnerContext &context)
if (states.contains(Solid::PowerManagement::HybridSuspendState)) {
addSuspendMatch(Solid::PowerManagement::HybridSuspendState, matches);
}
#warning TODO: do not match these when not supported by the system
} else if (term.compare(i18nc("Note this is a KRunner keyword", "sleep"), Qt::CaseInsensitive) == 0 ||
term.compare(i18nc("Note this is a KRunner keyword", "to ram"), Qt::CaseInsensitive) == 0) {
term.compare(QLatin1String("sleep"), Qt::CaseInsensitive) == 0 ||
term.compare(i18nc("Note this is a KRunner keyword", "to ram"), Qt::CaseInsensitive) == 0 ||
term.compare(QLatin1String("to ram"), Qt::CaseInsensitive) == 0) {
addSuspendMatch(Solid::PowerManagement::SuspendState, matches);
} else if (term.compare(i18nc("Note this is a KRunner keyword", "hibernate"), Qt::CaseInsensitive) == 0 ||
term.compare(i18nc("Note this is a KRunner keyword", "to disk"), Qt::CaseInsensitive) == 0) {
term.compare(QLatin1String("hibernate"), Qt::CaseInsensitive) == 0 ||
term.compare(i18nc("Note this is a KRunner keyword", "to disk"), Qt::CaseInsensitive) == 0 ||
term.compare(QLatin1String("to disk"), Qt::CaseInsensitive) == 0) {
addSuspendMatch(Solid::PowerManagement::HibernateState, matches);
} else if (term.compare(i18nc("Note this is a KRunner keyword", "hybrid"), Qt::CaseInsensitive) == 0) {
} else if (term.compare(i18nc("Note this is a KRunner keyword", "hybrid"), Qt::CaseInsensitive) == 0 ||
term.compare(QLatin1String("hybrid"), Qt::CaseInsensitive) == 0) {
addSuspendMatch(Solid::PowerManagement::HybridSuspendState, matches);
}

View file

@ -178,8 +178,7 @@ void ServiceRunner::match(Plasma::RunnerContext &context)
setupMatch(service, match);
qreal relevance = 0.6;
if (service->categories().contains("X-KDE-More") ||
!service->showInKDE()) {
if (service->categories().contains("X-KDE-More") || !service->showInKDE()) {
relevance = 0.5;
}

View file

@ -31,7 +31,7 @@ SessionRunner::SessionRunner(QObject *parent, const QVariantList &args)
{
Q_UNUSED(args)
setObjectName( QLatin1String("Sessions" ));
setObjectName(QLatin1String("Sessions"));
setPriority(LowPriority);
setIgnoredTypes(Plasma::RunnerContext::Directory | Plasma::RunnerContext::File |
Plasma::RunnerContext::NetworkLocation);
@ -67,10 +67,12 @@ SessionRunner::~SessionRunner()
{
}
void SessionRunner::matchCommands(QList<Plasma::QueryMatch> &matches, const QString& term)
void SessionRunner::matchCommands(QList<Plasma::QueryMatch> &matches, const QString &term)
{
if (term.compare(i18nc("log out command","logout"), Qt::CaseInsensitive) == 0 ||
term.compare(i18n("log out"), Qt::CaseInsensitive) == 0) {
if (term.compare(i18nc("log out command", "logout"), Qt::CaseInsensitive) == 0 ||
term.compare(QLatin1String("logout"), Qt::CaseInsensitive) == 0 ||
term.compare(i18n("log out"), Qt::CaseInsensitive) == 0 ||
term.compare(QLatin1String("log out"), Qt::CaseInsensitive) == 0) {
Plasma::QueryMatch match(this);
match.setText(i18nc("log out command","Logout"));
match.setIcon(KIcon("system-log-out"));
@ -79,7 +81,9 @@ void SessionRunner::matchCommands(QList<Plasma::QueryMatch> &matches, const QStr
match.setRelevance(0.9);
matches << match;
} else if (term.compare(i18nc("restart computer command", "restart"), Qt::CaseInsensitive) == 0 ||
term.compare(i18nc("restart computer command", "reboot"), Qt::CaseInsensitive) == 0) {
term.compare(QLatin1String("restart"), Qt::CaseInsensitive) == 0 ||
term.compare(i18nc("restart computer command", "reboot"), Qt::CaseInsensitive) == 0 ||
term.compare(QLatin1String("reboot"), Qt::CaseInsensitive) == 0) {
Plasma::QueryMatch match(this);
match.setText(i18n("Restart the computer"));
match.setIcon(KIcon("system-reboot"));
@ -87,7 +91,8 @@ void SessionRunner::matchCommands(QList<Plasma::QueryMatch> &matches, const QStr
match.setType(Plasma::QueryMatch::ExactMatch);
match.setRelevance(0.9);
matches << match;
} else if (term.compare(i18nc("shutdown computer command","shutdown"), Qt::CaseInsensitive) == 0) {
} else if (term.compare(i18nc("shutdown computer command", "shutdown"), Qt::CaseInsensitive) == 0 ||
term.compare(QLatin1String("shutdown"), Qt::CaseInsensitive) == 0) {
Plasma::QueryMatch match(this);
match.setText(i18n("Shutdown the computer"));
match.setIcon(KIcon("system-shutdown"));
@ -95,7 +100,8 @@ void SessionRunner::matchCommands(QList<Plasma::QueryMatch> &matches, const QStr
match.setType(Plasma::QueryMatch::ExactMatch);
match.setRelevance(0.9);
matches << match;
} else if (term.compare(i18nc("lock screen command","lock"), Qt::CaseInsensitive) == 0) {
} else if (term.compare(i18nc("lock screen command", "lock"), Qt::CaseInsensitive) == 0 ||
term.compare(QLatin1String("lock"), Qt::CaseInsensitive) == 0) {
Plasma::QueryMatch match(this);
match.setText(i18n("Lock the screen"));
match.setIcon(KIcon("system-lock-screen"));
@ -121,8 +127,10 @@ void SessionRunner::match(Plasma::RunnerContext &context)
// first compare with SESSIONS. this must *NOT* be translated (i18n)
// as it is used as an internal command trigger (e.g. via d-bus),
// not as a user supplied query. and yes, "Ugh, magic strings"
bool listAll = term.compare("SESSIONS", Qt::CaseInsensitive) == 0 ||
term.compare(i18nc("User sessions", "sessions"), Qt::CaseInsensitive) == 0;
bool listAll = (
term.compare("SESSIONS", Qt::CaseInsensitive) == 0 ||
term.compare(i18nc("User sessions", "sessions"), Qt::CaseInsensitive) == 0
);
if (!listAll) {
//no luck, try the "switch" user command

View file

@ -134,31 +134,37 @@ void SolidRunner::createOrUpdateMatches(const QStringList &udiList)
bool onlyOptical = false;
bool forceEject = false;
bool showDevices = false;
if (keywords[0].startsWith(i18nc("Note this is a KRunner keyword", "device") , Qt::CaseInsensitive)) {
if (keywords[0].startsWith(i18nc("Note this is a KRunner keyword", "device"), Qt::CaseInsensitive) ||
keywords[0].startsWith(QLatin1String("device"), Qt::CaseInsensitive)) {
showDevices = true;
keywords.removeFirst();
}
if (!keywords.isEmpty()) {
if (keywords[0].startsWith(i18nc("Note this is a KRunner keyword", "mount") , Qt::CaseInsensitive)) {
if (keywords[0].startsWith(i18nc("Note this is a KRunner keyword", "mount"), Qt::CaseInsensitive) ||
keywords[0].startsWith(QLatin1String("mount"), Qt::CaseInsensitive)) {
showDevices = true;
onlyMountable = true;
keywords.removeFirst();
} else if (keywords[0].startsWith(i18nc("Note this is a KRunner keyword", "unmount") , Qt::CaseInsensitive)) {
} else if (keywords[0].startsWith(i18nc("Note this is a KRunner keyword", "unmount"), Qt::CaseInsensitive) ||
keywords[0].startsWith(QLatin1String("unmount"), Qt::CaseInsensitive)) {
showDevices = true;
onlyMounted = true;
keywords.removeFirst();
} else if (keywords[0].startsWith(i18nc("Note this is a KRunner keyword", "eject") , Qt::CaseInsensitive)) {
} else if (keywords[0].startsWith(i18nc("Note this is a KRunner keyword", "eject"), Qt::CaseInsensitive) ||
keywords[0].startsWith(QLatin1String("eject"), Qt::CaseInsensitive)) {
showDevices = true;
onlyOptical = true;
forceEject = true;
keywords.removeFirst();
} else if (keywords[0].startsWith(i18nc("Note this is a KRunner keyword", "unlock") , Qt::CaseInsensitive)) {
} else if (keywords[0].startsWith(i18nc("Note this is a KRunner keyword", "unlock"), Qt::CaseInsensitive) ||
keywords[0].startsWith(QLatin1String("unlock"), Qt::CaseInsensitive)) {
showDevices = true;
onlyMountable = true;
onlyEncrypted = true;
keywords.removeFirst();
} else if (keywords[0].startsWith(i18nc("Note this is a KRunner keyword", "lock") , Qt::CaseInsensitive)) {
} else if (keywords[0].startsWith(i18nc("Note this is a KRunner keyword", "lock"), Qt::CaseInsensitive) ||
keywords[0].startsWith(QLatin1String("lock"), Qt::CaseInsensitive)) {
showDevices = true;
onlyMounted = true;
onlyEncrypted = true;

View file

@ -125,41 +125,72 @@ void WindowsRunner::match(Plasma::RunnerContext& context)
// check if the search term ends with an action keyword
WindowAction action = ActivateAction;
if (term.endsWith(i18nc("Note this is a KRunner keyword", "activate") , Qt::CaseInsensitive)) {
if (term.endsWith(i18nc("Note this is a KRunner keyword", "activate"), Qt::CaseInsensitive)) {
action = ActivateAction;
term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "activate")) - 1);
} else if (term.endsWith(QLatin1String("activate"), Qt::CaseInsensitive)) {
action = ActivateAction;
term = term.left(term.lastIndexOf(QLatin1String("activate")) - 1);
} else if (term.endsWith(i18nc("Note this is a KRunner keyword", "close") , Qt::CaseInsensitive)) {
action = CloseAction;
term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "close")) - 1);
} else if (term.endsWith(QLatin1String("close") , Qt::CaseInsensitive)) {
action = CloseAction;
term = term.left(term.lastIndexOf(QLatin1String("close")) - 1);
} else if (term.endsWith(i18nc("Note this is a KRunner keyword", "min") , Qt::CaseInsensitive)) {
action = MinimizeAction;
term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "min")) - 1);
} else if (term.endsWith(QLatin1String("min") , Qt::CaseInsensitive)) {
action = MinimizeAction;
term = term.left(term.lastIndexOf(QLatin1String("min")) - 1);
} else if (term.endsWith(i18nc("Note this is a KRunner keyword", "minimize") , Qt::CaseInsensitive)) {
action = MinimizeAction;
term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "minimize")) - 1);
} else if (term.endsWith(QLatin1String("minimize") , Qt::CaseInsensitive)) {
action = MinimizeAction;
term = term.left(term.lastIndexOf(QLatin1String("minimize")) - 1);
} else if (term.endsWith(i18nc("Note this is a KRunner keyword", "max") , Qt::CaseInsensitive)) {
action = MaximizeAction;
term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "max")) - 1);
} else if (term.endsWith(QLatin1String("max") , Qt::CaseInsensitive)) {
action = MaximizeAction;
term = term.left(term.lastIndexOf(QLatin1String("max")) - 1);
} else if (term.endsWith(i18nc("Note this is a KRunner keyword", "maximize") , Qt::CaseInsensitive)) {
action = MaximizeAction;
term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "maximize")) - 1);
} else if (term.endsWith(QLatin1String("maximize") , Qt::CaseInsensitive)) {
action = MaximizeAction;
term = term.left(term.lastIndexOf(QLatin1String("maximize")) - 1);
} else if (term.endsWith(i18nc("Note this is a KRunner keyword", "fullscreen") , Qt::CaseInsensitive)) {
action = FullscreenAction;
term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "fullscreen")) - 1);
} else if (term.endsWith(QLatin1String("fullscreen") , Qt::CaseInsensitive)) {
action = FullscreenAction;
term = term.left(term.lastIndexOf(QLatin1String("fullscreen")) - 1);
} else if (term.endsWith(i18nc("Note this is a KRunner keyword", "shade") , Qt::CaseInsensitive)) {
action = ShadeAction;
term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "shade")) - 1);
} else if (term.endsWith(QLatin1String("shade") , Qt::CaseInsensitive)) {
action = ShadeAction;
term = term.left(term.lastIndexOf(QLatin1String("shade")) - 1);
} else if (term.endsWith(i18nc("Note this is a KRunner keyword", "keep above") , Qt::CaseInsensitive)) {
action = KeepAboveAction;
term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "keep above")) - 1);
} else if (term.endsWith(i18nc("Note this is a KRunner keyword", "keep below") , Qt::CaseInsensitive)) {
} else if (term.endsWith(QLatin1String("keep above") , Qt::CaseInsensitive)) {
action = KeepAboveAction;
term = term.left(term.lastIndexOf(QLatin1String("keep above")) - 1);
} else if (term.endsWith(i18nc("Note this is a KRunner keyword", "keep below"), Qt::CaseInsensitive)) {
action = KeepBelowAction;
term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "keep below")) - 1);
} else if (term.endsWith(QLatin1String("keep below") , Qt::CaseInsensitive)) {
action = KeepBelowAction;
term = term.left(term.lastIndexOf(QLatin1String("keep below")) - 1);
}
// keyword match: when term starts with "window" we list all windows
// the list can be restricted to windows matching a given name, class, role or desktop
if (term.startsWith(i18nc("Note this is a KRunner keyword", "window") , Qt::CaseInsensitive)) {
if (term.startsWith(i18nc("Note this is a KRunner keyword", "window"), Qt::CaseInsensitive) ||
term.startsWith(QLatin1String("window"), Qt::CaseInsensitive)) {
const QStringList keywords = term.split(" ");
QString windowName;
QString windowClass;
@ -169,13 +200,17 @@ void WindowsRunner::match(Plasma::RunnerContext& context)
if (keyword.endsWith('=')) {
continue;
}
if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "name") + "=" , Qt::CaseInsensitive)) {
if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "name") + "=" , Qt::CaseInsensitive) ||
keyword.startsWith(QLatin1String("name="), Qt::CaseInsensitive)) {
windowName = keyword.split("=")[1];
} else if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "class") + "=" , Qt::CaseInsensitive)) {
} else if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "class") + "=" , Qt::CaseInsensitive) ||
keyword.startsWith(QLatin1String("class="), Qt::CaseInsensitive)) {
windowClass = keyword.split("=")[1];
} else if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "role") + "=" , Qt::CaseInsensitive)) {
} else if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "role") + "=" , Qt::CaseInsensitive) ||
keyword.startsWith(QLatin1String("role="), Qt::CaseInsensitive)) {
windowRole = keyword.split("=")[1];
} else if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "desktop") + "=" , Qt::CaseInsensitive)) {
} else if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "desktop") + "=", Qt::CaseInsensitive) ||
keyword.startsWith(QLatin1String("desktop="), Qt::CaseInsensitive)) {
bool ok;
desktop = keyword.split("=")[1].toInt(&ok);
if (!ok || desktop > KWindowSystem::numberOfDesktops()) {
@ -237,7 +272,8 @@ void WindowsRunner::match(Plasma::RunnerContext& context)
bool desktopAdded = false;
// check for desktop keyword
if (term.startsWith(i18nc("Note this is a KRunner keyword", "desktop") , Qt::CaseInsensitive)) {
if (term.startsWith(i18nc("Note this is a KRunner keyword", "desktop") , Qt::CaseInsensitive) ||
term.startsWith(QLatin1String("desktop") , Qt::CaseInsensitive)) {
const QStringList parts = term.split(" ");
if (parts.size() == 1) {
// only keyword - list all desktops