8#include "polkitqt1-identity.h"
10#include <polkit/polkit.h>
17class Q_DECL_HIDDEN Identity::Data :
public QSharedData
20 Data() : identity(nullptr) {}
21 Data(
const Data& other)
23 , identity(other.identity)
26 g_object_ref(identity);
32 g_object_unref(identity);
36 PolkitIdentity *identity;
44Identity::Identity(PolkitIdentity *polkitIdentity)
47 d->identity = polkitIdentity;
50 g_object_ref(d->identity);
70bool Identity::isValid()
const
72 return d->identity !=
nullptr;
75PolkitIdentity *Identity::identity()
const
80void Identity::setIdentity(PolkitIdentity *identity)
82 if (d->identity == identity) {
87 g_object_unref(d->identity);
90 d->identity = identity;
93 g_object_ref(d->identity);
99 Q_ASSERT(d->identity);
105 GError *error =
nullptr;
106 PolkitIdentity *pkIdentity = polkit_identity_from_string(
string.toUtf8().data(), &error);
107 if (error !=
nullptr) {
108 qWarning() <<
QString(
"Cannot create Identity from string: %1").
arg(error->message);
124UnixUserIdentity Identity::toUnixUserIdentity()
126 UnixUserIdentity *uuid =
static_cast< UnixUserIdentity*
>(
this);
128 return UnixUserIdentity();
134UnixUserIdentity::UnixUserIdentity(
const QString &name)
137 GError *error =
nullptr;
138 setIdentity(polkit_unix_user_new_for_name(name.
toUtf8().
data(), &error));
139 if (error !=
nullptr) {
140 qWarning() <<
QString(
"Cannot create UnixUserIdentity: %1").
arg(error->message);
141 setIdentity(
nullptr);
145UnixUserIdentity::UnixUserIdentity(uid_t uid)
148 setIdentity(polkit_unix_user_new(
uid));
151UnixUserIdentity::UnixUserIdentity(PolkitUnixUser *pkUnixUser)
152 :
Identity((PolkitIdentity *)pkUnixUser)
157UnixUserIdentity::UnixUserIdentity()
165 return polkit_unix_user_get_uid((PolkitUnixUser *)
identity());
170 polkit_unix_user_set_uid((PolkitUnixUser *)
identity(),
uid);
173UnixGroupIdentity::UnixGroupIdentity(
const QString &name)
176 GError *error =
nullptr;
177 setIdentity(polkit_unix_group_new_for_name(name.
toUtf8().
data(), &error));
178 if (error !=
nullptr) {
179 qWarning() <<
QString(
"Cannot create UnixGroupIdentity: %1").
arg(error->message);
180 setIdentity(
nullptr);
184UnixGroupIdentity::UnixGroupIdentity(gid_t gid)
187 setIdentity(polkit_unix_group_new(
gid));
190UnixGroupIdentity::UnixGroupIdentity(PolkitUnixGroup *pkUnixGroup)
191 :
Identity((PolkitIdentity *) pkUnixGroup)
196UnixGroupIdentity::UnixGroupIdentity()
204 return polkit_unix_group_get_gid((PolkitUnixGroup *)
identity());
209 polkit_unix_group_set_gid((PolkitUnixGroup *)
identity(),
gid);
Abstract class representing identities.
PolkitIdentity * identity() const
Gets PolkitIdentity object.
An object representing a group identity on a UNIX system.
gid_t gid() const
Gets a group id.
void setGid(gid_t gid)
Sets the id of group.
uid_t uid() const
Gets an user id.
void setUid(uid_t uid)
Sets the id of user.
QString arg(Args &&... args) const const
QString fromUtf8(QByteArrayView str)
QByteArray toUtf8() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2024 The KDE developers.
Generated on Fri Dec 6 2024 12:06:51 by
doxygen 1.12.0 written
by
Dimitri van Heesch, © 1997-2006
KDE's Doxygen guidelines are available online.