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, QStandardPaths::StandardLocation type);
74
75 virtual ~KConfigPrivate()
76 {
77 }
78
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#ifdef Q_OS_WIN
118 void parseWindowsDefaults();
119#endif
120 void parseConfigFiles();
121 void initCustomized(KConfig *);
122 bool lockLocal();
123};
124
125#endif // KCONFIG_P_H
126

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