~ubuntu-branches/ubuntu/trusty/polkit-qt-1/trusty

« back to all changes in this revision

Viewing changes to core/details.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 Radek Novacek <rnovacek@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 "details.h"
 
22
 
 
23
#include <QtCore/QStringList>
 
24
 
 
25
#include <polkit/polkit.h>
 
26
 
 
27
using namespace PolkitQt;
 
28
 
 
29
class Details::Private
 
30
{
 
31
    public:
 
32
        Private() {}
 
33
 
 
34
        PolkitDetails *polkitDetails;
 
35
};
 
36
 
 
37
Details::Details(QObject *parent)
 
38
        : QObject(parent)
 
39
        , d(new Private)
 
40
{
 
41
    g_type_init();
 
42
    d->polkitDetails = polkit_details_new();
 
43
}
 
44
 
 
45
Details::Details(PolkitDetails *pkDetails, QObject *parent)
 
46
        : QObject(parent)
 
47
        , d(new Private)
 
48
{
 
49
    g_type_init();
 
50
    d->polkitDetails = pkDetails;
 
51
}
 
52
 
 
53
Details::~Details()
 
54
{
 
55
    g_object_unref(d->polkitDetails);
 
56
    delete d;
 
57
}
 
58
 
 
59
QString Details::lookup(const QString &key) const
 
60
{
 
61
    const gchar *result = polkit_details_lookup(d->polkitDetails, key.toUtf8().data());
 
62
    if (result != NULL)
 
63
        return QString::fromUtf8(result);
 
64
    else
 
65
        return QString();
 
66
}
 
67
 
 
68
void Details::insert(const QString &key, const QString &value)
 
69
{
 
70
    polkit_details_insert(d->polkitDetails, key.toUtf8().data(), value.toUtf8().data());
 
71
}
 
72
 
 
73
QStringList Details::getKeys() const
 
74
{
 
75
    gchar **result = polkit_details_get_keys(d->polkitDetails);
 
76
    QStringList list;
 
77
    int len = g_strv_length(result);
 
78
    for (int i = 0; i < len; i++)
 
79
    {
 
80
        list.append(QString::fromUtf8(result[i]));
 
81
    }
 
82
    g_strfreev(result);
 
83
    return list;
 
84
}