File indexing completed on 2024-04-28 15:29:43

0001 /*
0002     SPDX-FileCopyrightText: 2017 David Edmundson <davidedmundson@kde.org>
0003 
0004     SPDX-License-Identifier: LGPL-2.0-or-later
0005 */
0006 
0007 #pragma once
0008 
0009 #include <KRunner/AbstractRunner>
0010 
0011 #include "dbusutils_p.h"
0012 #include <QHash>
0013 #include <QImage>
0014 #include <QList>
0015 #include <QMutex>
0016 #include <QSet>
0017 
0018 class DBusRunner : public Plasma::AbstractRunner
0019 {
0020     Q_OBJECT
0021 
0022 public:
0023     explicit DBusRunner(QObject *parent, const KPluginMetaData &pluginMetaData, const QVariantList &args);
0024     ~DBusRunner() override;
0025 
0026     void match(Plasma::RunnerContext &context) override;
0027     void reloadConfiguration() override;
0028     void run(const Plasma::RunnerContext &context, const Plasma::QueryMatch &action) override;
0029     QList<QAction *> actionsForMatch(const Plasma::QueryMatch &match) override;
0030 
0031 public Q_SLOTS:
0032     void teardown();
0033     // This method should only be called from the main thread!
0034     void createQActionsFromRemoteActions(const QMap<QString, RemoteActions> &remoteActions);
0035 
0036 private:
0037     // Returns RemoteActions with service name as key
0038     QMap<QString, RemoteActions> requestActions();
0039     void requestConfig();
0040     static QImage decodeImage(const RemoteImage &remoteImage);
0041     QMutex m_mutex; // needed round any variable also accessed from Match
0042     QString m_path;
0043     QSet<QString> m_matchingServices;
0044     QHash<QString, QList<QAction *>> m_actions;
0045     bool m_hasUniqueResults = false;
0046     bool m_requestActionsOnce = false;
0047     bool m_actionsOnceRequested = false;
0048     bool m_actionsForSessionRequested = false;
0049     bool m_matchWasCalled = false;
0050     bool m_callLifecycleMethods = false;
0051     QSet<QString> m_requestedActionServices;
0052 };