File indexing completed on 2024-05-19 09:31:38
0001 /* 0002 SPDX-FileCopyrightText: 2008 Dario Freddi <drf@kdemod.ath.cx> 0003 0004 SPDX-License-Identifier: GPL-2.0-or-later 0005 */ 0006 0007 #pragma once 0008 0009 #include <KLocalizedString> 0010 #include <KRunner/AbstractRunner> 0011 #include <QDBusConnection> 0012 0013 class SessionManagement; 0014 0015 struct RunnerKeyword { 0016 inline RunnerKeyword(KLocalizedString str, bool partialMatch = true) 0017 : triggerWord(str.untranslatedText()) 0018 , translatedTriggerWord(str.toString()) 0019 , supportPartialMatch(partialMatch) 0020 { 0021 } 0022 const QString triggerWord; 0023 const QString translatedTriggerWord; 0024 const bool supportPartialMatch = true; 0025 }; 0026 0027 class PowerDevilRunner : public KRunner::AbstractRunner 0028 { 0029 Q_OBJECT 0030 public: 0031 PowerDevilRunner(QObject *parent, const KPluginMetaData &metaData); 0032 0033 void match(KRunner::RunnerContext &context) override; 0034 void run(const KRunner::RunnerContext &context, const KRunner::QueryMatch &action) override; 0035 0036 private: 0037 void updateSyntaxes(); 0038 void addSuspendMatch(int value, QList<KRunner::QueryMatch> &matches, KRunner::QueryMatch::CategoryRelevance categoryRelevance); 0039 // Returns -1 if there is no match, otherwise the percentage that the user has entered 0040 int matchesScreenBrightnessKeywords(const QString &query) const; 0041 bool matchesRunnerKeywords(const QList<RunnerKeyword> &keywords, KRunner::QueryMatch::CategoryRelevance &categoryRelevance, const QString &query) const; 0042 void addSyntaxForKeyword(const QList<RunnerKeyword> &keywords, const QString &description); 0043 0044 SessionManagement *m_session; 0045 const RunnerKeyword m_power; 0046 const RunnerKeyword m_suspend, m_toRam; 0047 const RunnerKeyword m_sleep; 0048 const RunnerKeyword m_hibernate, m_toDisk; 0049 const RunnerKeyword m_hybridSuspend, m_hybrid; 0050 const RunnerKeyword m_dimScreen; 0051 const RunnerKeyword m_screenBrightness; 0052 };