PolkitQt-1

polkitqt1-details.cpp
1 /*
2  This file is part of the Polkit-qt project
3  SPDX-FileCopyrightText: 2009 Radek Novacek <[email protected]>
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 
14 namespace PolkitQt1
15 {
16 
17 class Q_DECL_HIDDEN Details::Data : public QSharedData
18 {
19 public:
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 
45 Details::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 
55 Details::~Details()
56 {
57 }
58 
59 Details::Details(const Details &other) = default;
60 
61 Details& Details::operator=(const PolkitQt1::Details& other)
62 {
63  d = other.d;
64  return *this;
65 }
66 
67 QString Details::lookup(const QString &key) const
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 
77 void 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 }
void append(const T &value)
QString fromUtf8(const char *str, int size)
void insert(const QString &key, const QString &value)
Inserts key key with value value.
QString lookup(const QString &key) const
Get the value for key.
Details()
Creates a new Details object.
QByteArray toUtf8() const const
QStringList keys() const
Gets a list of all keys.
Class used for passing details around.
Namespace wrapping Polkit-Qt classes.
char * data()
This file is part of the KDE documentation.
Documentation copyright © 1996-2022 The KDE developers.
Generated on Sun Jun 26 2022 04:06:09 by doxygen 1.8.17 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.