2
* This file is part of the Polkit-qt project
3
* Copyright (C) 2009 Lukas Tinkl <ltinkl@redhat.com>
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.
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.
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.
23
#include <polkit/polkit.h>
25
#include <QtCore/QDebug>
27
using namespace PolkitQt;
29
class Identity::Private
32
Private(PolkitIdentity *i) : identity(i) {}
34
PolkitIdentity *identity;
43
Identity::Identity(PolkitIdentity *polkitIdentity)
44
: d(new Private(polkitIdentity))
51
g_object_unref(d->identity);
55
PolkitIdentity *Identity::identity() const
60
void Identity::setIdentity(PolkitIdentity *identity)
62
d->identity = identity;
65
QString Identity::toString() const
67
Q_ASSERT(d->identity);
68
return QString::fromUtf8(polkit_identity_to_string(d->identity));
71
Identity *Identity::fromString(const QString &string)
74
PolkitIdentity *pkIdentity = polkit_identity_from_string(string.toUtf8().data(), &error);
77
qWarning() << QString("Cannot create Identity from string: %1").arg(error->message);
80
return new Identity(pkIdentity);
83
UnixUserIdentity::UnixUserIdentity(const QString &name)
87
setIdentity(polkit_unix_user_new_for_name(name.toUtf8().data(), &error));
90
qWarning() << QString("Cannot create UnixUserIdentity: %1").arg(error->message);
95
UnixUserIdentity::UnixUserIdentity(uid_t uid)
98
setIdentity(polkit_unix_user_new(uid));
101
UnixUserIdentity::UnixUserIdentity(PolkitUnixUser *pkUnixUser)
102
: Identity((PolkitIdentity *)pkUnixUser)
107
uid_t UnixUserIdentity::uid() const
109
return polkit_unix_user_get_uid((PolkitUnixUser *) identity());
112
void UnixUserIdentity::setUid(uid_t uid)
114
polkit_unix_user_set_uid((PolkitUnixUser *) identity(), uid);
117
UnixGroupIdentity::UnixGroupIdentity(const QString &name)
120
GError *error = NULL;
121
setIdentity(polkit_unix_group_new_for_name(name.toUtf8().data(), &error));
124
qWarning() << QString("Cannot create UnixGroupIdentity: %1").arg(error->message);
129
UnixGroupIdentity::UnixGroupIdentity(gid_t gid)
132
setIdentity(polkit_unix_group_new(gid));
135
UnixGroupIdentity::UnixGroupIdentity(PolkitUnixGroup *pkUnixGroup)
136
: Identity((PolkitIdentity *) pkUnixGroup)
141
gid_t UnixGroupIdentity::gid() const
143
return polkit_unix_group_get_gid((PolkitUnixGroup *) identity());
146
void UnixGroupIdentity::setGid(gid_t gid)
148
polkit_unix_group_set_gid((PolkitUnixGroup *) identity(), gid);