File indexing completed on 2024-04-21 04:43:23
0001 /* 0002 This file is part of the Polkit-qt project 0003 SPDX-FileCopyrightText: 2009 Lukas Tinkl <ltinkl@redhat.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #ifndef POLKITQT1_IDENTITY_H 0009 #define POLKITQT1_IDENTITY_H 0010 0011 #include "polkitqt1-core-export.h" 0012 0013 #include <unistd.h> 0014 0015 #include <QObject> 0016 #include <QSharedData> 0017 0018 typedef struct _PolkitIdentity PolkitIdentity; 0019 typedef struct _PolkitUnixUser PolkitUnixUser; 0020 typedef struct _PolkitUnixGroup PolkitUnixGroup; 0021 0022 /** 0023 * \namespace PolkitQt1 PolkitQt 0024 * 0025 * \brief Namespace wrapping Polkit-Qt classes 0026 * 0027 * This namespace wraps all Polkit-Qt classes. 0028 */ 0029 namespace PolkitQt1 0030 { 0031 0032 class UnixUserIdentity; 0033 class UnixGroupIdentity; 0034 0035 /** 0036 * \class Identity polkitqt1-identity.h Identity 0037 * \author Lukas Tinkl <ltinkl@redhat.com> 0038 * 0039 * This class encapsulates the PolkitIdentity interface. 0040 * 0041 * \brief Abstract class representing identities 0042 * 0043 * \see UnixGroup 0044 * \see UnixUser 0045 */ 0046 class POLKITQT1_CORE_EXPORT Identity 0047 { 0048 public: 0049 typedef QList< Identity > List; 0050 0051 Identity(); 0052 explicit Identity(PolkitIdentity *polkitIdentity); 0053 Identity(const Identity &other); 0054 0055 ~Identity(); 0056 0057 Identity &operator=(const Identity &other); 0058 0059 bool isValid() const; 0060 0061 /** 0062 * Serialization of object to the string 0063 * 0064 * \return Serialized Identity object 0065 */ 0066 QString toString() const; 0067 0068 /** 0069 * Creates the Identity object from string representation 0070 * 0071 * \param string string representation of the object 0072 * 0073 * \return Pointer to new Identity instance 0074 */ 0075 static Identity fromString(const QString &string); 0076 0077 UnixUserIdentity toUnixUserIdentity(); 0078 UnixGroupIdentity toUnixGroupIdentity(); 0079 0080 /** 0081 * Gets PolkitIdentity object. 0082 * 0083 * \warning It shouldn't be used directly unless you are completely aware of what are you doing 0084 * 0085 * \return Pointer to PolkitIdentity instance 0086 */ 0087 PolkitIdentity *identity() const; 0088 protected: 0089 void setIdentity(PolkitIdentity *identity); 0090 0091 private: 0092 class Data; 0093 QExplicitlySharedDataPointer< Data > d; 0094 }; 0095 0096 /** 0097 * \class UnixUserIdentity polkitqt1-identity.h Identity 0098 * 0099 * An object representing a user identity on a UNIX system. 0100 * 0101 * \brief UNIX user identity 0102 * \sa Identity 0103 */ 0104 class POLKITQT1_CORE_EXPORT UnixUserIdentity : public Identity 0105 { 0106 public: 0107 UnixUserIdentity(); 0108 /** 0109 * Creates UnixUser object by UID of the user 0110 * 0111 * \param uid user id 0112 */ 0113 explicit UnixUserIdentity(uid_t uid); 0114 0115 /** 0116 * Creates UnixUser object by unix name of the user 0117 * 0118 * \param name Unix name 0119 */ 0120 explicit UnixUserIdentity(const QString &name); 0121 0122 /** 0123 * Creates UnixUser object from PolkitUnixUser object 0124 * 0125 * \warning Use this only if you are completely aware of what are you doing! 0126 * 0127 * \param pkUnixUser The PolkitUnixUser object 0128 */ 0129 explicit UnixUserIdentity(PolkitUnixUser *pkUnixUser); 0130 0131 /** 0132 * Gets an user id 0133 * 0134 * \return user id 0135 */ 0136 uid_t uid() const; 0137 0138 /** 0139 * Sets the id of user 0140 * 0141 * \param uid user id 0142 */ 0143 void setUid(uid_t uid); 0144 }; 0145 0146 /** 0147 * \class UnixGroupIdentity polkitqt1-identity.h Identity 0148 * 0149 * An object representing a group identity on a UNIX system. 0150 * 0151 * \brief UNIX group identity 0152 * \sa Identity 0153 */ 0154 class POLKITQT1_CORE_EXPORT UnixGroupIdentity : public Identity 0155 { 0156 public: 0157 UnixGroupIdentity(); 0158 /** 0159 * Creates UnixGroup object by GID of the group 0160 * 0161 * \param gid group id 0162 */ 0163 explicit UnixGroupIdentity(gid_t gid); 0164 0165 /** 0166 * Creates UnixGroup object by unix name of the group 0167 * 0168 * \param name group name 0169 */ 0170 explicit UnixGroupIdentity(const QString &name); 0171 0172 /** 0173 * Creates UnixGroup object from PolkitUnixGroup object 0174 * 0175 * \warning Use this only if you are completely aware of what are you doing! 0176 * 0177 * \param pkUnixGroup The PolkitUnixGroup object 0178 */ 0179 explicit UnixGroupIdentity(PolkitUnixGroup *pkUnixGroup); 0180 0181 /** 0182 * Gets a group id 0183 * 0184 * \return group id 0185 */ 0186 gid_t gid() const; 0187 0188 /** 0189 * Sets the id of group 0190 * 0191 * \param gid group id 0192 */ 0193 void setGid(gid_t gid); 0194 }; 0195 0196 } 0197 0198 #endif // POLKIT_QT_IDENTITY_H