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 "kconfig.h"
15#include "kconfigdata_p.h"
16#include "kconfiggroup.h"
17#include "kconfigini_p.h"
18
19#include <QDir>
20#include <QFile>
21#include <QStack>
22#include <QStringList>
23
24class KConfigPrivate
25{
26 friend class KConfig;
27
28public:
29 KConfig::OpenFlags openFlags;
30 QStandardPaths::StandardLocation resourceType;
31
32 void changeFileName(const QString &fileName);
33
34 // functions for KConfigGroup
35 bool canWriteEntry(const QString &group, QAnyStringView key, bool isDefault = false) const;
36 QString lookupData(const QString &group, QAnyStringView key, KEntryMap::SearchFlags flags, bool *expand) const;
37 QByteArray lookupData(const QString &group, QAnyStringView key, KEntryMap::SearchFlags flags) const;
38 KEntry lookupInternalEntry(const QString &group, QAnyStringView key, KEntryMap::SearchFlags flags) const;
39
40 void putData(const QString &groupName, const char *key, const QByteArray &value, KConfigBase::WriteConfigFlags flags, bool expand = false);
41 void setEntryData(const QString &groupName, const char *key, const QByteArray &value, KEntryMap::EntryOptions flags)
42 {
43 if (entryMap.setEntry(group: groupName, key, value, options: flags)) {
44 bDirty = true;
45 }
46 }
47 void revertEntry(const QString &group, QAnyStringView key, KConfigBase::WriteConfigFlags flags);
48 /*
49 * Returns a list of keys used with entries in a particular group.
50 *
51 * This does not include keys of deleted entries or those with default values.
52 * I.e. all the keys for which there will be also entries in KConfig::entryMap().
53 *
54 * Returns a sorted list of keys in the group specified.
55 * The returned list may be empty if the group is empty, or not found.
56 */
57 QStringList usedKeyList(const QString &theGroup) const;
58 QStringList groupList(const QString &groupName) const;
59 // copies the entries from @p source to @p otherGroup changing all occurrences
60 // of @p source with @p destination
61 void copyGroup(const QString &source, const QString &destination, KConfigGroup *otherGroup, KConfigBase::WriteConfigFlags flags) const;
62 QList<QByteArray> keyListImpl(const QString &groupName) const;
63 QSet<QString> allSubGroups(const QString &parentGroupName) const;
64 bool hasNonDeletedEntries(const QString &groupName) const;
65
66 void notifyClients(const QHash<QString, QByteArrayList> &changes, const QString &path);
67
68 static QString expandString(const QString &value);
69
70protected:
71 KConfigIniBackend mBackend;
72
73 KConfigPrivate(KConfig::OpenFlags flags,
74 QStandardPaths::StandardLocation type,
75 std::unique_ptr<KConfigIniBackendAbstractDevice> backend = std::make_unique<KConfigIniBackendNullDevice>());
76
77 virtual ~KConfigPrivate()
78 {
79 }
80
81private:
82 bool bDirty : 1;
83 bool bReadDefaults : 1;
84 bool bFileImmutable : 1;
85 bool bForceGlobal : 1;
86 bool bSuppressGlobal : 1;
87
88 static bool mappingsRegistered;
89
90 KEntryMap entryMap;
91 QString backendType;
92 QStack<QString> extraFiles;
93
94 QString locale;
95 QString fileName;
96 QString etc_kderc;
97 KConfigBase::AccessMode configState;
98
99 bool wantGlobals() const
100 {
101 return openFlags & KConfig::IncludeGlobals && !bSuppressGlobal;
102 }
103 bool wantDefaults() const
104 {
105 return openFlags & KConfig::CascadeConfig;
106 }
107 bool isSimple() const
108 {
109 return openFlags == KConfig::SimpleConfig;
110 }
111 bool isReadOnly() const
112 {
113 return configState == KConfig::ReadOnly;
114 }
115
116 bool setLocale(const QString &aLocale);
117 QStringList getGlobalFiles() const;
118 void parseGlobalFiles();
119#ifdef Q_OS_WIN
120 void parseWindowsDefaults();
121#endif
122 void parseConfigFiles();
123 void initCustomized(KConfig *);
124 bool lockLocal();
125};
126
127#endif // KCONFIG_P_H
128

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