PolkitQt-1

polkitqt1-agent-session.h
1/*
2 This file is part of the PolKit1-qt project
3 SPDX-FileCopyrightText: 2009 Radek Novacek <rnovacek@redhat.com>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#ifndef POLKITQT1_AGENT_SESSION_H
9#define POLKITQT1_AGENT_SESSION_H
10
11#include <QObject>
12#include "polkitqt1-identity.h"
13#include "polkitqt1-agent-export.h"
14
15typedef struct _GSimpleAsyncResult GSimpleAsyncResult;
16typedef struct _PolkitAgentSession PolkitAgentSession;
17
18namespace PolkitQt1
19{
20
21/**
22 * \namespace Agent Agent
23 *
24 * \brief Namespace wrapping Polkit-Qt Agent classes
25 *
26 * This namespace wraps all Polkit-Qt Agent classes.
27 */
28
29namespace Agent
30{
31
32/**
33 * \internal
34 * \brief Encapsulation of GSimpleAsyncResult to QObject class
35 */
36class POLKITQT1_AGENT_EXPORT AsyncResult
37{
38public:
39 explicit AsyncResult(GSimpleAsyncResult *result);
40 virtual ~AsyncResult();
41
42 /**
43 * \brief Mark the action that is tied to this result as completed.
44 */
45 void setCompleted();
46
47 /**
48 * \brief Sets an error for the asynchronous result.
49 * Method complete() must be called anyway.
50 *
51 * \param text text of the error message
52 */
53 void setError(const QString &text);
54
55private:
56 class Private;
57 Private * const d;
58};
59
60/**
61 * \class Session polkitqt1-agent-session.h Session
62 * \author Radek Novacek <rnovacek@redhat.com>
63 *
64 * This class is interface for interacting with native
65 * authentication system for obtaining authorizations.
66 *
67 */
68class POLKITQT1_AGENT_EXPORT Session : public QObject
69{
70 Q_OBJECT
71 Q_DISABLE_COPY(Session)
72public:
73 /**
74 * Create a new authentication session.
75 *
76 * \param identity The identity to authenticate
77 * \param cookie The cookie obtained from the PolicyKit daemon
78 * \param result Result of the authentication action. Must be finished using complete() method.
79 * \param parent
80 */
81 Session(const PolkitQt1::Identity& identity, const QString &cookie, AsyncResult *result = nullptr, QObject *parent = nullptr);
82
83 /**
84 * Create a new authentication session from PolkitAgentSession object
85 *
86 * \warning Use this only if you are completely aware of what are you doing!
87 *
88 * \param pkAgentSession PolkitAgentSession object
89 * \param parent
90 */
91 explicit Session(PolkitAgentSession *pkAgentSession, QObject *parent = nullptr);
92
93 /**
94 * Destroy authentication session.
95 */
96 ~Session() override;
97
98 /**
99 * Initiate the authentication session.
100 *
101 * Use cancel() to cancel the session.
102 */
103 void initiate();
104
105 /**
106 * Method for providing response to requests received via request signal.
107 *
108 * \param response Response from the user, typically a password
109 */
110 void setResponse(const QString &response);
111
112 /**
113 * Cancel the authentication session.
114 * This will emit the completed() signal.
115 */
116 void cancel();
117
118 /**
119 * Get AsyncResult that can be used to finish authentication operation
120 *
121 * \return AsyncResult object or NULL if it is not set
122 */
123 AsyncResult *result();
124
125Q_SIGNALS:
126 /**
127 * This signal will be emitted when the authentication
128 * polkitqt1-agent-session.has been completed or cancelled.
129 *
130 * \param gainedAuthorization \c True if authorization was successfully obtained.
131 */
132 void completed(bool gainedAuthorization);
133
134 /**
135 * This signal will be emitted when user is requested to answer a question.
136 *
137 * \param request The request to show the user, e.g. "name: " or "password: ".
138 * \param echo \c True if the response to the request SHOULD be echoed on the screen,
139 * \c False if the response MUST NOT be echoed to the screen.
140 */
141 void request(const QString &request, bool echo);
142
143 /**
144 * This signal will be emitted when there is information
145 * related to an error condition to be displayed to the user.
146 *
147 * \param text An error string to display to the user.
148 */
149 void showError(const QString &text);
150
151 /**
152 * This signal will be emitted when there is information
153 * to be displayed to the user.
154 *
155 * \param text A string to be displayed to the user.
156 */
157 void showInfo(const QString &text);
158
159private:
160 class Private;
161 Private * const d;
162};
163
164}
165
166}
167
168#endif // SESSION_H
Encapsulation of GSimpleAsyncResult to QObject class.
void completed(bool gainedAuthorization)
This signal will be emitted when the authentication polkitqt1-agent-session.has been completed or can...
void request(const QString &request, bool echo)
This signal will be emitted when user is requested to answer a question.
void showInfo(const QString &text)
This signal will be emitted when there is information to be displayed to the user.
void showError(const QString &text)
This signal will be emitted when there is information related to an error condition to be displayed t...
Abstract class representing identities.
Agent.
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Nov 15 2024 11:56:27 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.