File indexing completed on 2024-05-19 16:39:09

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, const QVariantList &args)
0023     : AbstractRunner(parent, metaData, args)
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(RunnerSyntax(m_desktopConsoleKeyword,
0029                            i18n("Opens the Plasma desktop interactive console "
0030                                 "with a file path to a script on disk.")));
0031     addSyntax(RunnerSyntax(i18nc("Note this is a KRunner keyword", "desktop console :q:"),
0032                            i18n("Opens the Plasma desktop interactive console "
0033                                 "with a file path to a script on disk.")));
0034     addSyntax(RunnerSyntax(m_kwinConsoleKeyword,
0035                            i18n("Opens the KWin interactive console "
0036                                 "with a file path to a script on disk.")));
0037     addSyntax(RunnerSyntax(i18nc("Note this is a KRunner keyword", "wm console :q:"),
0038                            i18n("Opens the KWin interactive console "
0039                                 "with a file path to a script on disk.")));
0040 }
0041 
0042 PlasmaDesktopRunner::~PlasmaDesktopRunner()
0043 {
0044 }
0045 
0046 void PlasmaDesktopRunner::match(RunnerContext &context)
0047 {
0048     if (context.query().startsWith(m_desktopConsoleKeyword, Qt::CaseInsensitive)) {
0049         QueryMatch match(this);
0050         match.setId(QStringLiteral("plasma-desktop-console"));
0051         match.setType(QueryMatch::ExactMatch);
0052         match.setIconName(QStringLiteral("plasma"));
0053         match.setText(i18n("Open Plasma desktop interactive console"));
0054         match.setRelevance(1.0);
0055         context.addMatch(match);
0056     }
0057     if (context.query().startsWith(m_kwinConsoleKeyword, Qt::CaseInsensitive)) {
0058         QueryMatch match(this);
0059         match.setId(QStringLiteral("plasma-desktop-console"));
0060         match.setType(QueryMatch::ExactMatch);
0061         match.setIconName(QStringLiteral("kwin"));
0062         match.setText(i18n("Open KWin interactive console"));
0063         match.setRelevance(1.0);
0064         context.addMatch(match);
0065     }
0066 }
0067 
0068 void PlasmaDesktopRunner::run(const RunnerContext &context, const QueryMatch &match)
0069 {
0070     Q_UNUSED(match)
0071 
0072     bool showPlasmaConsole = context.query().startsWith(m_desktopConsoleKeyword, Qt::CaseInsensitive);
0073     QStringList args{showPlasmaConsole ? QStringLiteral("--plasma") : QStringLiteral("--kwin")};
0074     auto job = new KIO::CommandLauncherJob(QStringLiteral("plasma-interactiveconsole"), args);
0075     job->start();
0076 }
0077 
0078 #include "plasma-desktop-runner.moc"