1/*
2 This file is part of the KDE libraries
3 SPDX-FileCopyrightText: 2006, 2007 Thomas Braxton <kde.braxton@gmail.com>
4 SPDX-FileCopyrightText: 2001 Waldo Bastian <bastian@kde.org>
5 SPDX-FileCopyrightText: 1999 Preston Brown <pbrown@kde.org>
6 SPDX-FileCopyrightText: 1997 Matthias Kalle Dalheimer <kalle@kde.org>
7
8 SPDX-License-Identifier: LGPL-2.0-or-later
9*/
10
11#ifndef KCONFIG_P_H
12#define KCONFIG_P_H
13
14#include "kconfigbackend_p.h"
15#include "kconfigdata_p.h"
16#include "kconfiggroup.h"
17
18#include <QDir>
19#include <QFile>
20#include <QStack>
21#include <QStringList>
22
23class KConfigPrivate
24{
25 friend class KConfig;
26
27public:
28 KConfig::OpenFlags openFlags;
29 QStandardPaths::StandardLocation resourceType;
30
31 void changeFileName(const QString &fileName);
32
33 // functions for KConfigGroup
34 bool canWriteEntry(const QString &group, QAnyStringView key, bool isDefault = false) const;
35 QString lookupData(const QString &group, QAnyStringView key, KEntryMap::SearchFlags flags, bool *expand) const;
36 QByteArray lookupData(const QString &group, QAnyStringView key, KEntryMap::SearchFlags flags) const;
37 KEntry lookupInternalEntry(const QString &group, QAnyStringView key, KEntryMap::SearchFlags flags) const;
38
39 void putData(const QString &groupName, const char *key, const QByteArray &value, KConfigBase::WriteConfigFlags flags, bool expand = false);
40 void setEntryData(const QString &groupName, const char *key, const QByteArray &value, KEntryMap::EntryOptions flags)
41 {
42 if (entryMap.setEntry(group: groupName, key, value, options: flags)) {
43 bDirty = true;
44 }
45 }
46 void revertEntry(const QString &group, QAnyStringView key, KConfigBase::WriteConfigFlags flags);
47 /**
48 * Returns a list of keys used with entries in a particular group.
49 *
50 * This does not include keys of deleted entries or those with default values.
51 * I.e. all the keys for which there will be also entries in KConfig::entryMap().
52 *
53 * @return A sorted list of keys in the group specified.
54 * The returned list may be empty if the group is empty, or not found.
55 */
56 QStringList usedKeyList(const QString &theGroup) const;
57 QStringList groupList(const QString &groupName) const;
58 // copies the entries from @p source to @p otherGroup changing all occurrences
59 // of @p source with @p destination
60 void copyGroup(const QString &source, const QString &destination, KConfigGroup *otherGroup, KConfigBase::WriteConfigFlags flags) const;
61 QList<QByteArray> keyListImpl(const QString &groupName) const;
62 QSet<QString> allSubGroups(const QString &parentGroupName) const;
63 bool hasNonDeletedEntries(const QString &groupName) const;
64
65 void notifyClients(const QHash<QString, QByteArrayList> &changes, const QString &path);
66
67 static QString expandString(const QString &value);
68
69protected:
70 QExplicitlySharedDataPointer<KConfigBackend> mBackend;
71
72 KConfigPrivate(KConfig::OpenFlags flags, QStandardPaths::StandardLocation type);
73
74 virtual ~KConfigPrivate()
75 {
76 }
77
78 bool bDynamicBackend : 1; // do we own the backend?
79private:
80 bool bDirty : 1;
81 bool bReadDefaults : 1;
82 bool bFileImmutable : 1;
83 bool bForceGlobal : 1;
84 bool bSuppressGlobal : 1;
85
86 static bool mappingsRegistered;
87
88 KEntryMap entryMap;
89 QString backendType;
90 QStack<QString> extraFiles;
91
92 QString locale;
93 QString fileName;
94 QString etc_kderc;
95 KConfigBase::AccessMode configState;
96
97 bool wantGlobals() const
98 {
99 return openFlags & KConfig::IncludeGlobals && !bSuppressGlobal;
100 }
101 bool wantDefaults() const
102 {
103 return openFlags & KConfig::CascadeConfig;
104 }
105 bool isSimple() const
106 {
107 return openFlags == KConfig::SimpleConfig;
108 }
109 bool isReadOnly() const
110 {
111 return configState == KConfig::ReadOnly;
112 }
113
114 bool setLocale(const QString &aLocale);
115 QStringList getGlobalFiles() const;
116 void parseGlobalFiles();
117 void parseConfigFiles();
118 void initCustomized(KConfig *);
119 bool lockLocal();
120};
121
122#endif // KCONFIG_P_H
123

source code of kconfig/src/core/kconfig_p.h