File indexing completed on 2024-05-12 05:35:54
0001 /* 0002 SPDX-FileCopyrightText: 2009 Aaron Seigo <aseigo@kde.org> 0003 0004 SPDX-License-Identifier: LGPL-2.0-only 0005 */ 0006 0007 #include "plasma-desktop-runner.h" 0008 0009 #include <KIO/CommandLauncherJob> 0010 #include <QDBusConnection> 0011 #include <QDBusConnectionInterface> 0012 #include <QDBusServiceWatcher> 0013 0014 #include <QDebug> 0015 0016 #include <KLocalizedString> 0017 0018 K_PLUGIN_CLASS_WITH_JSON(PlasmaDesktopRunner, "plasma-runner-plasma-desktop.json") 0019 0020 static const QString s_plasmaService = QLatin1String("org.kde.plasmashell"); 0021 0022 PlasmaDesktopRunner::PlasmaDesktopRunner(QObject *parent, const KPluginMetaData &metaData) 0023 : AbstractRunner(parent, metaData) 0024 , m_desktopConsoleKeyword(i18nc("Note this is a KRunner keyword", "desktop console")) 0025 , m_kwinConsoleKeyword(i18nc("Note this is a KRunner keyword", "wm console")) 0026 { 0027 setObjectName(QLatin1String("Plasma-Desktop")); 0028 addSyntax(m_desktopConsoleKeyword, i18n("Opens the Plasma desktop interactive console with a file path to a script on disk.")); 0029 addSyntax(i18nc("Note this is a KRunner keyword", "desktop console :q:"), 0030 i18n("Opens the Plasma desktop interactive console with a file path to a script on disk.")); 0031 addSyntax(m_kwinConsoleKeyword, i18n("Opens the KWin interactive console with a file path to a script on disk.")); 0032 addSyntax(i18nc("Note this is a KRunner keyword", "wm console :q:"), i18n("Opens the KWin interactive console with a file path to a script on disk.")); 0033 } 0034 0035 void PlasmaDesktopRunner::match(RunnerContext &context) 0036 { 0037 if (context.query().startsWith(m_desktopConsoleKeyword, Qt::CaseInsensitive)) { 0038 QueryMatch match(this); 0039 match.setId(QStringLiteral("plasma-desktop-console")); 0040 match.setCategoryRelevance(QueryMatch::CategoryRelevance::Highest); 0041 match.setIconName(QStringLiteral("plasma")); 0042 match.setText(i18n("Open Plasma desktop interactive console")); 0043 match.setRelevance(1.0); 0044 context.addMatch(match); 0045 } 0046 if (context.query().startsWith(m_kwinConsoleKeyword, Qt::CaseInsensitive)) { 0047 QueryMatch match(this); 0048 match.setId(QStringLiteral("plasma-desktop-console")); 0049 match.setCategoryRelevance(QueryMatch::CategoryRelevance::Highest); 0050 match.setIconName(QStringLiteral("kwin")); 0051 match.setText(i18n("Open KWin interactive console")); 0052 match.setRelevance(1.0); 0053 context.addMatch(match); 0054 } 0055 } 0056 0057 void PlasmaDesktopRunner::run(const RunnerContext &context, const QueryMatch & /*match*/) 0058 { 0059 bool showPlasmaConsole = context.query().startsWith(m_desktopConsoleKeyword, Qt::CaseInsensitive); 0060 QStringList args{showPlasmaConsole ? QStringLiteral("--plasma") : QStringLiteral("--kwin")}; 0061 auto job = new KIO::CommandLauncherJob(QStringLiteral("plasma-interactiveconsole"), args); 0062 job->start(); 0063 } 0064 0065 #include "plasma-desktop-runner.moc"