File indexing completed on 2024-04-21 04:43:22
0001 /* 0002 This file is part of the Polkit-qt project 0003 SPDX-FileCopyrightText: 2009 Jaroslav Reznik <jreznik@redhat.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef POLKITQT1_AGENT_LISTENER_H 0009 #define POLKITQT1_AGENT_LISTENER_H 0010 0011 #include <QObject> 0012 #include <QScopedPointer> 0013 0014 #include "polkitqt1-agent-session.h" 0015 0016 #define POLKIT_AGENT_I_KNOW_API_IS_SUBJECT_TO_CHANGE 1 0017 0018 typedef struct _PolkitAgentListener PolkitAgentListener; 0019 0020 namespace PolkitQt1 0021 { 0022 class Subject; 0023 class Identity; 0024 class Details; 0025 } 0026 0027 namespace PolkitQt1 0028 { 0029 0030 namespace Agent 0031 { 0032 0033 class ListenerPrivate; 0034 /** 0035 * \class Listener polkitqt1-agent-listener.h Listener 0036 * \author Jaroslav Reznik <jreznik@redhat.com> 0037 * 0038 * \brief Listener is abstract class used for implementing authentication agents. 0039 * 0040 * To implement an authentication agent, just subclass this class and implement 0041 * virtual functions initiateAuthentication, initiateAuthenticationFinish 0042 * and cancelAuthentication. 0043 * 0044 * You can also use Session class to authenticate users however it isn't required. 0045 * \sa Session 0046 */ 0047 class POLKITQT1_AGENT_EXPORT Listener : public QObject 0048 { 0049 Q_OBJECT 0050 Q_DISABLE_COPY(Listener) 0051 public: 0052 /** 0053 * \brief Constructor of Listener class 0054 */ 0055 Listener(QObject *parent = nullptr); 0056 0057 /** 0058 * \brief Constructor of Listener class from PolkitAgentListener 0059 * 0060 * \warning Use this only if you are completely aware of what are you doing! 0061 * 0062 * \param listener Pointer to the PolkitAgentListener 0063 * \param parent 0064 */ 0065 explicit Listener(PolkitAgentListener *listener, QObject *parent = nullptr); 0066 0067 ~Listener() override; 0068 0069 /** 0070 * \brief Registers listener with polkit daemon as an authentication agent for \p subject. 0071 * 0072 * This is implemented by registering a DBus object at \p objectPath on the unique 0073 * name assigned by the system message bus. 0074 * 0075 * Whenever the polkit daemon needs to authenticate a processes that is related to \p subject, 0076 * the methods initiateAuthentication and initiateAuthenticationFinish will be evoked. 0077 * 0078 * \param subject Subject that listener will be registered for 0079 * \param objectPath DBus object path 0080 * \return \c True if the polkitqt1-agent-listener.has been registered, \c False otherwise 0081 */ 0082 bool registerListener(const PolkitQt1::Subject &subject, const QString &objectPath); 0083 0084 /** 0085 * \brief Returns pointer to the PolkitAgentListener. 0086 * 0087 * \warning Use this only if you are completely aware of what are you doing! 0088 * 0089 * \return PolkitAgentListener 0090 */ 0091 const PolkitAgentListener *listener(); 0092 0093 public Q_SLOTS: 0094 /** 0095 * \brief Initiate authentication for the action 0096 * 0097 * This method will be called on a registered authentication agent when the user owning 0098 * the session needs to prove he is one of the identities listed in \p identities. 0099 * 0100 * \note You have to reimplement this method in the subclass. 0101 * 0102 * \param actionId The action to authenticate for 0103 * \param message The message to present to the user 0104 * \param iconName The name of the icon which is representing the action 0105 * \param details Details describing the action 0106 * \param cookie The cookie for the authentization request 0107 * \param identities A list of Identity object that the user can choose to authenticate as 0108 * \param result This AsyncResult MUST be completed by using complete() method when the 0109 * authentication is done. You can pass it to the constructor of the Session class 0110 * and then call session->result()->complete() to mark the action as done. 0111 */ 0112 virtual void initiateAuthentication(const QString &actionId, 0113 const QString &message, 0114 const QString &iconName, 0115 const PolkitQt1::Details &details, 0116 const QString &cookie, 0117 const PolkitQt1::Identity::List &identities, 0118 PolkitQt1::Agent::AsyncResult *result) = 0; 0119 0120 /** 0121 * TODO: Is this method really required ? 0122 * \brief Finishes an authentication request from the polkit daemon. 0123 * 0124 * \note You have to reimplement this method in the subclass. 0125 * 0126 * \see initiateAuthentication 0127 */ 0128 virtual bool initiateAuthenticationFinish() = 0; 0129 0130 /** 0131 * TODO: Is this method really required ? 0132 * \brief Cancels an authentication request from the polkit daemon. 0133 * 0134 * \note You have to reimplement this method in the subclass. 0135 * 0136 * \see initiateAuthentication 0137 */ 0138 virtual void cancelAuthentication() = 0; 0139 0140 private: 0141 QScopedPointer<ListenerPrivate> d; 0142 }; 0143 } 0144 0145 } 0146 0147 #endif