File indexing completed on 2024-04-21 04:43:22
0001 /* 0002 This file is part of the Polkit-qt project 0003 SPDX-FileCopyrightText: 2009 Radek Novacek <rnovacek@redhat.com> 0004 0005 SPDX-License-Identifier: LGPL-2.0-or-later 0006 */ 0007 0008 #include "polkitqt1-details.h" 0009 0010 #include <QStringList> 0011 0012 #include <polkit/polkit.h> 0013 0014 namespace PolkitQt1 0015 { 0016 0017 class Q_DECL_HIDDEN Details::Data : public QSharedData 0018 { 0019 public: 0020 Data() {} 0021 Data(const Data &other) 0022 : QSharedData(other) 0023 , polkitDetails(other.polkitDetails) 0024 { 0025 if (polkitDetails != nullptr) { 0026 g_object_ref(polkitDetails); 0027 } 0028 } 0029 ~Data() 0030 { 0031 if (polkitDetails != nullptr) { 0032 g_object_unref(polkitDetails); 0033 } 0034 } 0035 0036 PolkitDetails *polkitDetails; 0037 }; 0038 0039 Details::Details() 0040 : d(new Data) 0041 { 0042 d->polkitDetails = polkit_details_new(); 0043 } 0044 0045 Details::Details(PolkitDetails *pkDetails) 0046 : d(new Data) 0047 { 0048 d->polkitDetails = pkDetails; 0049 0050 if (d->polkitDetails != nullptr) { 0051 g_object_ref(d->polkitDetails); 0052 } 0053 } 0054 0055 Details::~Details() 0056 { 0057 } 0058 0059 Details::Details(const Details &other) = default; 0060 0061 Details& Details::operator=(const PolkitQt1::Details& other) 0062 { 0063 d = other.d; 0064 return *this; 0065 } 0066 0067 QString Details::lookup(const QString &key) const 0068 { 0069 const gchar *result = polkit_details_lookup(d->polkitDetails, key.toUtf8().data()); 0070 if (result != nullptr) { 0071 return QString::fromUtf8(result); 0072 } else { 0073 return QString(); 0074 } 0075 } 0076 0077 void Details::insert(const QString &key, const QString &value) 0078 { 0079 polkit_details_insert(d->polkitDetails, key.toUtf8().data(), value.toUtf8().data()); 0080 } 0081 0082 QStringList Details::keys() const 0083 { 0084 gchar **result = polkit_details_get_keys(d->polkitDetails); 0085 QStringList list; 0086 int len = g_strv_length(result); 0087 for (int i = 0; i < len; i++) { 0088 list.append(QString::fromUtf8(result[i])); 0089 } 0090 g_strfreev(result); 0091 return list; 0092 } 0093 0094 }