~ubuntu-branches/ubuntu/oneiric/polkit-qt-1/oneiric-proposed

« back to all changes in this revision

Viewing changes to core/identity.cpp

  • Committer: Bazaar Package Importer
  • Author(s): Jonathan Thomas
  • Date: 2009-12-13 09:08:07 UTC
  • Revision ID: james.westby@ubuntu.com-20091213090807-ibl3mdtee5964009
Tags: upstream-0.95.0~svn1057107
ImportĀ upstreamĀ versionĀ 0.95.0~svn1057107

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
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
#include "identity.h"
 
22
 
 
23
#include <polkit/polkit.h>
 
24
 
 
25
#include <QtCore/QDebug>
 
26
 
 
27
using namespace PolkitQt;
 
28
 
 
29
class Identity::Private
 
30
{
 
31
    public:
 
32
        Private(PolkitIdentity *i) : identity(i) {}
 
33
 
 
34
        PolkitIdentity *identity;
 
35
};
 
36
 
 
37
Identity::Identity()
 
38
        : d(new Private(0))
 
39
{
 
40
    g_type_init();
 
41
}
 
42
 
 
43
Identity::Identity(PolkitIdentity *polkitIdentity)
 
44
        : d(new Private(polkitIdentity))
 
45
{
 
46
    g_type_init();
 
47
}
 
48
 
 
49
Identity::~Identity()
 
50
{
 
51
    g_object_unref(d->identity);
 
52
    delete d;
 
53
}
 
54
 
 
55
PolkitIdentity *Identity::identity() const
 
56
{
 
57
    return d->identity;
 
58
}
 
59
 
 
60
void Identity::setIdentity(PolkitIdentity *identity)
 
61
{
 
62
    d->identity = identity;
 
63
}
 
64
 
 
65
QString Identity::toString() const
 
66
{
 
67
    Q_ASSERT(d->identity);
 
68
    return QString::fromUtf8(polkit_identity_to_string(d->identity));
 
69
}
 
70
 
 
71
Identity *Identity::fromString(const QString &string)
 
72
{
 
73
    GError *error = NULL;
 
74
    PolkitIdentity *pkIdentity = polkit_identity_from_string(string.toUtf8().data(), &error);
 
75
    if (error != NULL)
 
76
    {
 
77
        qWarning() << QString("Cannot create Identity from string: %1").arg(error->message);
 
78
        return NULL;
 
79
    }
 
80
    return new Identity(pkIdentity);
 
81
}
 
82
 
 
83
UnixUserIdentity::UnixUserIdentity(const QString &name)
 
84
        : Identity()
 
85
{
 
86
    GError *error = NULL;
 
87
    setIdentity(polkit_unix_user_new_for_name(name.toUtf8().data(), &error));
 
88
    if (error != NULL)
 
89
    {
 
90
        qWarning() << QString("Cannot create UnixUserIdentity: %1").arg(error->message);
 
91
        setIdentity(NULL);
 
92
    }
 
93
}
 
94
 
 
95
UnixUserIdentity::UnixUserIdentity(uid_t uid)
 
96
        : Identity()
 
97
{
 
98
    setIdentity(polkit_unix_user_new(uid));
 
99
}
 
100
 
 
101
UnixUserIdentity::UnixUserIdentity(PolkitUnixUser *pkUnixUser)
 
102
        : Identity((PolkitIdentity *)pkUnixUser)
 
103
{
 
104
 
 
105
}
 
106
 
 
107
uid_t UnixUserIdentity::uid() const
 
108
{
 
109
    return polkit_unix_user_get_uid((PolkitUnixUser *) identity());
 
110
}
 
111
 
 
112
void UnixUserIdentity::setUid(uid_t uid)
 
113
{
 
114
    polkit_unix_user_set_uid((PolkitUnixUser *) identity(), uid);
 
115
}
 
116
 
 
117
UnixGroupIdentity::UnixGroupIdentity(const QString &name)
 
118
        : Identity()
 
119
{
 
120
    GError *error = NULL;
 
121
    setIdentity(polkit_unix_group_new_for_name(name.toUtf8().data(), &error));
 
122
    if (error != NULL)
 
123
    {
 
124
        qWarning() << QString("Cannot create UnixGroupIdentity: %1").arg(error->message);
 
125
        setIdentity(NULL);
 
126
    }
 
127
}
 
128
 
 
129
UnixGroupIdentity::UnixGroupIdentity(gid_t gid)
 
130
        : Identity()
 
131
{
 
132
    setIdentity(polkit_unix_group_new(gid));
 
133
}
 
134
 
 
135
UnixGroupIdentity::UnixGroupIdentity(PolkitUnixGroup *pkUnixGroup)
 
136
        : Identity((PolkitIdentity *) pkUnixGroup)
 
137
{
 
138
 
 
139
}
 
140
 
 
141
gid_t UnixGroupIdentity::gid() const
 
142
{
 
143
    return polkit_unix_group_get_gid((PolkitUnixGroup *) identity());
 
144
}
 
145
 
 
146
void UnixGroupIdentity::setGid(gid_t gid)
 
147
{
 
148
    polkit_unix_group_set_gid((PolkitUnixGroup *) identity(), gid);
 
149
}