File indexing completed on 2024-04-14 03:50:31
0001 /* 0002 SPDX-FileCopyrightText: 2008 Nicola Gigante <nicola.gigante@gmail.com> 0003 SPDX-FileCopyrightText: 2009 Dario Freddi <drf@kde.org> 0004 SPDX-FileCopyrightText: 2020 Harald Sitter <sitter@kde.org> 0005 0006 SPDX-License-Identifier: LGPL-2.1-or-later 0007 */ 0008 0009 #ifndef DBUS_HELPER_PROXY_H 0010 #define DBUS_HELPER_PROXY_H 0011 0012 #include "HelperProxy.h" 0013 #include "actionreply.h" 0014 0015 #include <QDBusConnection> 0016 #include <QDBusContext> 0017 #include <QVariant> 0018 0019 namespace KAuth 0020 { 0021 class DBusHelperProxy : public HelperProxy, protected QDBusContext 0022 { 0023 Q_OBJECT 0024 Q_PLUGIN_METADATA(IID "org.kde.DBusHelperProxy") 0025 Q_INTERFACES(KAuth::HelperProxy) 0026 0027 QObject *responder; 0028 QString m_name; 0029 QString m_currentAction; 0030 bool m_stopRequest; 0031 QList<QString> m_actionsInProgress; 0032 QDBusConnection m_busConnection; 0033 0034 enum SignalType { 0035 ActionStarted, // The blob argument is empty 0036 ActionPerformed, // The blob argument contains the ActionReply 0037 DebugMessage, // The blob argument contains the debug level and the message (in this order) 0038 ProgressStepIndicator, // The blob argument contains the step indicator 0039 ProgressStepData, // The blob argument contains the QVariantMap 0040 }; 0041 0042 public: 0043 DBusHelperProxy(); 0044 DBusHelperProxy(const QDBusConnection &busConnection); 0045 0046 ~DBusHelperProxy() override; 0047 0048 virtual void 0049 executeAction(const QString &action, const QString &helperID, const DetailsMap &details, const QVariantMap &arguments, int timeout = -1) override; 0050 void stopAction(const QString &action, const QString &helperID) override; 0051 0052 bool initHelper(const QString &name) override; 0053 void setHelperResponder(QObject *o) override; 0054 bool hasToStopAction() override; 0055 void sendDebugMessage(int level, const char *msg) override; 0056 void sendProgressStep(int step) override; 0057 void sendProgressStepData(const QVariantMap &data) override; 0058 0059 int callerUid() const override; 0060 0061 public Q_SLOTS: 0062 void stopAction(const QString &action); 0063 QByteArray performAction(const QString &action, const QByteArray &callerID, const QVariantMap &details, QByteArray arguments); 0064 0065 Q_SIGNALS: 0066 void remoteSignal(int type, const QString &action, const QByteArray &blob); // This signal is sent from the helper to the app 0067 0068 private Q_SLOTS: 0069 void remoteSignalReceived(int type, const QString &action, QByteArray blob); 0070 0071 private: 0072 bool isCallerAuthorized(const QString &action, const QByteArray &callerID, const QVariantMap &details); 0073 }; 0074 0075 } // namespace Auth 0076 0077 #endif