PolkitQt-1

polkitqt1-details.cpp
1/*
2 This file is part of the Polkit-qt project
3 SPDX-FileCopyrightText: 2009 Radek Novacek <rnovacek@redhat.com>
4
5 SPDX-License-Identifier: LGPL-2.0-or-later
6*/
7
8#include "polkitqt1-details.h"
9
10#include <QStringList>
11
12#include <polkit/polkit.h>
13
14namespace PolkitQt1
15{
16
17class Q_DECL_HIDDEN Details::Data : public QSharedData
18{
19public:
20 Data() {}
21 Data(const Data &other)
22 : QSharedData(other)
23 , polkitDetails(other.polkitDetails)
24 {
25 if (polkitDetails != nullptr) {
26 g_object_ref(polkitDetails);
27 }
28 }
29 ~Data()
30 {
31 if (polkitDetails != nullptr) {
32 g_object_unref(polkitDetails);
33 }
34 }
35
36 PolkitDetails *polkitDetails;
37};
38
40 : d(new Data)
41{
42 d->polkitDetails = polkit_details_new();
43}
44
45Details::Details(PolkitDetails *pkDetails)
46 : d(new Data)
47{
48 d->polkitDetails = pkDetails;
49
50 if (d->polkitDetails != nullptr) {
51 g_object_ref(d->polkitDetails);
52 }
53}
54
55Details::~Details()
56{
57}
58
59Details::Details(const Details &other) = default;
60
61Details& Details::operator=(const PolkitQt1::Details& other)
62{
63 d = other.d;
64 return *this;
65}
66
68{
69 const gchar *result = polkit_details_lookup(d->polkitDetails, key.toUtf8().data());
70 if (result != nullptr) {
71 return QString::fromUtf8(result);
72 } else {
73 return QString();
74 }
75}
76
77void Details::insert(const QString &key, const QString &value)
78{
79 polkit_details_insert(d->polkitDetails, key.toUtf8().data(), value.toUtf8().data());
80}
81
83{
84 gchar **result = polkit_details_get_keys(d->polkitDetails);
85 QStringList list;
86 int len = g_strv_length(result);
87 for (int i = 0; i < len; i++) {
88 list.append(QString::fromUtf8(result[i]));
89 }
90 g_strfreev(result);
91 return list;
92}
93
94}
Class used for passing details around.
void insert(const QString &key, const QString &value)
Inserts key key with value value.
Details()
Creates a new Details object.
QStringList keys() const
Gets a list of all keys.
QString lookup(const QString &key) const
Get the value for key.
char * data()
void append(QList< T > &&value)
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 Mon Nov 18 2024 12:13:57 by doxygen 1.12.0 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.