From 3e5ae3b2472b60d37ca9baf10691f42faa1edc61 Mon Sep 17 00:00:00 2001 From: Alexander Lohnau Date: Sun, 17 Dec 2023 12:26:00 +0100 Subject: [PATCH] windowsrunner: Deduplicate/optimize strings --- .../windowsrunnerinterface.cpp | 50 +++++++++---------- .../windowsrunnerinterface.h | 3 +- 2 files changed, 26 insertions(+), 27 deletions(-) diff --git a/src/plugins/krunner-integration/windowsrunnerinterface.cpp b/src/plugins/krunner-integration/windowsrunnerinterface.cpp index 63cc3e35be..a03dbb1adb 100644 --- a/src/plugins/krunner-integration/windowsrunnerinterface.cpp +++ b/src/plugins/krunner-integration/windowsrunnerinterface.cpp @@ -36,38 +36,38 @@ RemoteMatches WindowsRunner::Match(const QString &searchTerm) { RemoteMatches matches; - auto term = searchTerm; + QString term = searchTerm; WindowsRunnerAction action = ActivateAction; - if (term.endsWith(i18nc("Note this is a KRunner keyword", "activate"), Qt::CaseInsensitive)) { + if (QString keyword = i18nc("Note this is a KRunner keyword", "activate"); term.endsWith(keyword, Qt::CaseInsensitive)) { action = ActivateAction; - term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "activate")) - 1); - } else if (term.endsWith(i18nc("Note this is a KRunner keyword", "close"), Qt::CaseInsensitive)) { + term = term.left(term.lastIndexOf(keyword) - 1); + } else if (QString keyword = i18nc("Note this is a KRunner keyword", "close"); term.endsWith(keyword, Qt::CaseInsensitive)) { action = CloseAction; - term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "close")) - 1); - } else if (term.endsWith(i18nc("Note this is a KRunner keyword", "min"), Qt::CaseInsensitive)) { + term = term.left(term.lastIndexOf(keyword) - 1); + } else if (QString keyword = i18nc("Note this is a KRunner keyword", "min"); term.endsWith(keyword, Qt::CaseInsensitive)) { action = MinimizeAction; - term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "min")) - 1); - } else if (term.endsWith(i18nc("Note this is a KRunner keyword", "minimize"), Qt::CaseInsensitive)) { + term = term.left(term.lastIndexOf(keyword) - 1); + } else if (QString keyword = i18nc("Note this is a KRunner keyword", "minimize"); term.endsWith(keyword, Qt::CaseInsensitive)) { action = MinimizeAction; - term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "minimize")) - 1); - } else if (term.endsWith(i18nc("Note this is a KRunner keyword", "max"), Qt::CaseInsensitive)) { + term = term.left(term.lastIndexOf(keyword) - 1); + } else if (QString keyword = i18nc("Note this is a KRunner keyword", "max"); term.endsWith(keyword, Qt::CaseInsensitive)) { action = MaximizeAction; - term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "max")) - 1); + term = term.left(term.lastIndexOf(keyword) - 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(i18nc("Note this is a KRunner keyword", "fullscreen"), Qt::CaseInsensitive)) { + } else if (QString keyword = i18nc("Note this is a KRunner keyword", "fullscreen"); term.endsWith(keyword, Qt::CaseInsensitive)) { action = FullscreenAction; - term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "fullscreen")) - 1); - } else if (term.endsWith(i18nc("Note this is a KRunner keyword", "shade"), Qt::CaseInsensitive)) { + term = term.left(term.lastIndexOf(keyword) - 1); + } else if (QString keyword = i18nc("Note this is a KRunner keyword", "shade"); term.endsWith(keyword, Qt::CaseInsensitive)) { action = ShadeAction; - term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "shade")) - 1); - } else if (term.endsWith(i18nc("Note this is a KRunner keyword", "keep above"), Qt::CaseInsensitive)) { + term = term.left(term.lastIndexOf(keyword) - 1); + } else if (QString keyword = i18nc("Note this is a KRunner keyword", "keep above"); term.endsWith(keyword, 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)) { + term = term.left(term.lastIndexOf(keyword) - 1); + } else if (QString keyword = i18nc("Note this is a KRunner keyword", "keep below"); term.endsWith(keyword, Qt::CaseInsensitive)) { action = KeepBelowAction; - term = term.left(term.lastIndexOf(i18nc("Note this is a KRunner keyword", "keep below")) - 1); + term = term.left(term.lastIndexOf(keyword) - 1); } // keyword match: when term starts with "window" we list all windows @@ -82,12 +82,12 @@ RemoteMatches WindowsRunner::Match(const QString &searchTerm) if (keyword.endsWith(QLatin1Char('='))) { continue; } - if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "name") + QStringLiteral("="), Qt::CaseInsensitive)) { - windowName = keyword.split(QStringLiteral("="))[1]; - } else if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "appname") + QStringLiteral("="), Qt::CaseInsensitive)) { - windowAppName = keyword.split(QStringLiteral("="))[1]; - } else if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "desktop") + QStringLiteral("="), Qt::CaseInsensitive)) { - desktopId = keyword.split(QStringLiteral("="))[1]; + if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "name") + QLatin1Char('='), Qt::CaseInsensitive)) { + windowName = keyword.split(QLatin1Char('='))[1]; + } else if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "appname") + QLatin1Char('='), Qt::CaseInsensitive)) { + windowAppName = keyword.split(QLatin1Char('='))[1]; + } else if (keyword.startsWith(i18nc("Note this is a KRunner keyword", "desktop") + QLatin1Char('='), Qt::CaseInsensitive)) { + desktopId = keyword.split(QLatin1Char('='))[1]; for (const auto desktop : VirtualDesktopManager::self()->desktops()) { if (desktop->name().contains(desktopId.toString(), Qt::CaseInsensitive) || desktop->x11DesktopNumber() == desktopId.toUInt()) { targetDesktop = desktop; diff --git a/src/plugins/krunner-integration/windowsrunnerinterface.h b/src/plugins/krunner-integration/windowsrunnerinterface.h index 8990462a6a..32243309e1 100644 --- a/src/plugins/krunner-integration/windowsrunnerinterface.h +++ b/src/plugins/krunner-integration/windowsrunnerinterface.h @@ -32,7 +32,6 @@ class WindowsRunner : public Plugin, protected QDBusContext Q_CLASSINFO("D-Bus Interface", "org.kde.KWin.WindowsRunner") public: explicit WindowsRunner(); - ~WindowsRunner() override; RemoteActions Actions() { @@ -53,7 +52,7 @@ private: KeepAboveAction, KeepBelowAction, // Desktop related actions - ActivateDesktopAction + ActivateDesktopAction, }; RemoteMatch desktopMatch(const VirtualDesktop *desktop, const WindowsRunnerAction action = ActivateDesktopAction, qreal relevance = 1.0) const;