Warning, file /plasma/plasma-desktop/runners/kwin/kwin-runner.cpp was not indexed or was modified since last indexation (in which case cross-reference links may be missing, inaccurate or erroneous).

0001 /*
0002     SPDX-FileCopyrightText: 2009 Aaron Seigo <aseigo@kde.org>
0003     SPDX-FileCopyrightText: 2016 Martin Gräßlin <mgraesslin@kde.org>
0004 
0005     SPDX-License-Identifier: LGPL-2.0-only
0006 */
0007 
0008 #include "kwin-runner.h"
0009 
0010 #include <QDBusConnection>
0011 #include <QDBusConnectionInterface>
0012 #include <QDBusServiceWatcher>
0013 
0014 #include <KLocalizedString>
0015 
0016 K_PLUGIN_CLASS_WITH_JSON(KWinRunner, "plasma-runner-kwin.json")
0017 
0018 static const QString s_kwinService = QStringLiteral("org.kde.KWin");
0019 static const QString s_keyword = QStringLiteral("KWin");
0020 
0021 KWinRunner::KWinRunner(QObject *parent, const KPluginMetaData &metaData, const QVariantList &args)
0022     : AbstractRunner(parent, metaData, args)
0023 {
0024     setObjectName(s_keyword);
0025     QDBusServiceWatcher *watcher = new QDBusServiceWatcher(s_kwinService, QDBusConnection::sessionBus(), QDBusServiceWatcher::WatchForOwnerChange, this);
0026     connect(watcher, &QDBusServiceWatcher::serviceOwnerChanged, this, &KWinRunner::checkAvailability);
0027     checkAvailability(QString(), QString(), QString());
0028 }
0029 
0030 KWinRunner::~KWinRunner()
0031 {
0032 }
0033 
0034 void KWinRunner::match(RunnerContext &context)
0035 {
0036     if (m_enabled && context.query().compare(s_keyword, Qt::CaseInsensitive) == 0) {
0037         QueryMatch match(this);
0038         match.setId(QStringLiteral("kwin"));
0039         match.setType(QueryMatch::ExactMatch);
0040         match.setIconName(QStringLiteral("kwin"));
0041         match.setText(i18n("Open KWin debug console"));
0042         match.setRelevance(1.0);
0043         context.addMatch(match);
0044     }
0045 }
0046 
0047 void KWinRunner::run(const RunnerContext &context, const QueryMatch &match)
0048 {
0049     Q_UNUSED(match)
0050 
0051     if (m_enabled && context.query().compare(s_keyword, Qt::CaseInsensitive) == 0) {
0052         QDBusMessage message = QDBusMessage::createMethodCall(s_kwinService, QStringLiteral("/KWin"), s_kwinService, QStringLiteral("showDebugConsole"));
0053         QDBusConnection::sessionBus().asyncCall(message);
0054     }
0055 }
0056 
0057 void KWinRunner::checkAvailability(const QString &name, const QString &oldOwner, const QString &newOwner)
0058 {
0059     Q_UNUSED(oldOwner)
0060 
0061     bool enabled = false;
0062     if (name.isEmpty()) {
0063         enabled = QDBusConnection::sessionBus().interface()->isServiceRegistered(s_kwinService).value();
0064     } else {
0065         enabled = !newOwner.isEmpty();
0066     }
0067 
0068     if (m_enabled != enabled) {
0069         m_enabled = enabled;
0070 
0071         if (m_enabled) {
0072             addSyntax(RunnerSyntax(s_keyword, i18n("Opens the KWin (Plasma Window Manager) debug console.")));
0073         } else {
0074             setSyntaxes(QList<RunnerSyntax>());
0075         }
0076     }
0077 }
0078 
0079 #include "kwin-runner.moc"