1/*
2 * This file is part of the Polkit-qt project
3 * Copyright (C) 2009 Lukas Tinkl <ltinkl@redhat.com>
4 *
5 * This library is free software; you can redistribute it and/or
6 * modify it under the terms of the GNU Library General Public
7 * License as published by the Free Software Foundation; either
8 * version 2 of the License, or (at your option) any later version.
9 *
10 * This library is distributed in the hope that it will be useful,
11 * but WITHOUT ANY WARRANTY; without even the implied warranty of
12 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13 * Library General Public License for more details.
14 *
15 * You should have received a copy of the GNU Library General Public License
16 * along with this library; see the file COPYING.LIB. If not, write to
17 * the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
18 * Boston, MA 02110-1301, USA.
19 */
20
21#ifndef POLKITQT1_IDENTITY_H
22#define POLKITQT1_IDENTITY_H
23
24#include "polkitqt1-export.h"
25
26#include <unistd.h>
27
28#include <QtCore/QObject>
29#include <QtCore/QSharedData>
30
31typedef struct _PolkitIdentity PolkitIdentity;
32typedef struct _PolkitUnixUser PolkitUnixUser;
33typedef struct _PolkitUnixGroup PolkitUnixGroup;
34
35/**
36 * \namespace PolkitQt1 PolkitQt
37 *
38 * \brief Namespace wrapping Polkit-Qt classes
39 *
40 * This namespace wraps all Polkit-Qt classes.
41 */
42namespace PolkitQt1
43{
44
45class UnixUserIdentity;
46class UnixGroupIdentity;
47
48/**
49 * \class Identity polkitqt1-identity.h Identity
50 * \author Lukas Tinkl <ltinkl@redhat.com>
51 *
52 * This class encapsulates the PolkitIdentity interface.
53 *
54 * \brief Abstract class representing identities
55 *
56 * \see UnixGroup
57 * \see UnixUser
58 */
59class POLKITQT1_EXPORT Identity
60{
61public:
62 typedef QList< Identity > List;
63
64 Identity();
65 explicit Identity(PolkitIdentity *polkitIdentity);
66 Identity(const Identity &other);
67
68 ~Identity();
69
70 Identity &operator=(const Identity &other);
71
72 bool isValid() const;
73
74 /**
75 * Serialization of object to the string
76 *
77 * \return Serialized Identity object
78 */
79 QString toString() const;
80
81 /**
82 * Creates the Identity object from string representation
83 *
84 * \param string string representation of the object
85 *
86 * \return Pointer to new Identity instance
87 */
88 static Identity fromString(const QString &string);
89
90 UnixUserIdentity toUnixUserIdentity();
91 UnixGroupIdentity toUnixGroupIdentity();
92
93 /**
94 * Gets PolkitIdentity object.
95 *
96 * \warning It shouldn't be used directly unless you are completely aware of what are you doing
97 *
98 * \return Pointer to PolkitIdentity instance
99 */
100 PolkitIdentity *identity() const;
101protected:
102 void setIdentity(PolkitIdentity *identity);
103
104private:
105 class Data;
106 QExplicitlySharedDataPointer< Data > d;
107};
108
109/**
110 * \class UnixUserIdentity polkitqt1-identity.h Identity
111 *
112 * An object representing a user identity on a UNIX system.
113 *
114 * \brief UNIX user identity
115 * \sa Identity
116 */
117class POLKITQT1_EXPORT UnixUserIdentity : public Identity
118{
119public:
120 UnixUserIdentity();
121 /**
122 * Creates UnixUser object by UID of the user
123 *
124 * \param uid user id
125 */
126 explicit UnixUserIdentity(uid_t uid);
127
128 /**
129 * Creates UnixUser object by unix name of the user
130 *
131 * \param name Unix name
132 */
133 explicit UnixUserIdentity(const QString &name);
134
135 /**
136 * Creates UnixUser object from PolkitUnixUser object
137 *
138 * \warning Use this only if you are completely aware of what are you doing!
139 *
140 * \param pkUnixUser The PolkitUnixUser object
141 */
142 explicit UnixUserIdentity(PolkitUnixUser *pkUnixUser);
143
144 /**
145 * Gets an user id
146 *
147 * \return user id
148 */
149 uid_t uid() const;
150
151 /**
152 * Sets the id of user
153 *
154 * \param uid user id
155 */
156 void setUid(uid_t uid);
157};
158
159/**
160 * \class UnixGroupIdentity polkitqt1-identity.h Identity
161 *
162 * An object representing a group identity on a UNIX system.
163 *
164 * \brief UNIX group identity
165 * \sa Identity
166 */
167class POLKITQT1_EXPORT UnixGroupIdentity : public Identity
168{
169public:
170 UnixGroupIdentity();
171 /**
172 * Creates UnixGroup object by GID of the group
173 *
174 * \param gid group id
175 */
176 explicit UnixGroupIdentity(gid_t gid);
177
178 /**
179 * Creates UnixGroup object by unix name of the group
180 *
181 * \param name group name
182 */
183 explicit UnixGroupIdentity(const QString &name);
184
185 /**
186 * Creates UnixGroup object from PolkitUnixGroup object
187 *
188 * \warning Use this only if you are completely aware of what are you doing!
189 *
190 * \param pkUnixGroup The PolkitUnixGroup object
191 */
192 explicit UnixGroupIdentity(PolkitUnixGroup *pkUnixGroup);
193
194 /**
195 * Gets a group id
196 *
197 * \return group id
198 */
199 gid_t gid() const;
200
201 /**
202 * Sets the id of group
203 *
204 * \param gid group id
205 */
206 void setGid(gid_t gid);
207};
208
209}
210
211#endif // POLKIT_QT_IDENTITY_H
212