KConfig

kconfigdata.h
1 /*
2  This file is part of the KDE libraries
3  SPDX-FileCopyrightText: 2006, 2007 Thomas Braxton <[email protected]>
4  SPDX-FileCopyrightText: 1999-2000 Preston Brown <[email protected]>
5  SPDX-FileCopyrightText: 1996-2000 Matthias Kalle Dalheimer <[email protected]>
6 
7  SPDX-License-Identifier: LGPL-2.0-or-later
8 */
9 
10 #ifndef KCONFIGDATA_H
11 #define KCONFIGDATA_H
12 
13 #include <QByteArray>
14 #include <QString>
15 #include <QMap>
16 #include <QDebug>
17 
22 struct KEntry {
25  : mValue(), bDirty(false),
26  bGlobal(false), bImmutable(false), bDeleted(false), bExpand(false), bReverted(false),
27  bLocalizedCountry(false), bNotify(false), bOverridesGlobal(false) {}
33  bool bDirty : 1;
37  bool bGlobal: 1;
41  bool bImmutable: 1;
45  bool bDeleted: 1;
49  bool bExpand: 1;
53  bool bReverted: 1;
59 
60  bool bNotify: 1;
61 
66 };
67 
68 // These operators are used to check whether an entry which is about
69 // to be written equals the previous value. As such, this intentionally
70 // omits the dirty/notify flag from the comparison.
71 inline bool operator ==(const KEntry &k1, const KEntry &k2)
72 {
73  return k1.bGlobal == k2.bGlobal && k1.bImmutable == k2.bImmutable
74  && k1.bDeleted == k2.bDeleted && k1.bExpand == k2.bExpand
75  && k1.mValue == k2.mValue;
76 }
77 
78 inline bool operator !=(const KEntry &k1, const KEntry &k2)
79 {
80  return !(k1 == k2);
81 }
82 
88 struct KEntryKey {
90  KEntryKey(const QByteArray &_group = QByteArray(),
91  const QByteArray &_key = QByteArray(), bool isLocalized = false, bool isDefault = false)
92  : mGroup(_group), mKey(_key), bLocal(isLocalized), bDefault(isDefault), bRaw(false)
93  {
94  ;
95  }
107  bool bLocal : 1;
111  bool bDefault: 1;
116  bool bRaw: 1;
117 };
118 
124 inline bool operator <(const KEntryKey &k1, const KEntryKey &k2)
125 {
126  int result = qstrcmp(k1.mGroup, k2.mGroup);
127  if (result != 0) {
128  return result < 0;
129  }
130 
131  result = qstrcmp(k1.mKey, k2.mKey);
132  if (result != 0) {
133  return result < 0;
134  }
135 
136  if (k1.bLocal != k2.bLocal) {
137  return k1.bLocal;
138  }
139  return (!k1.bDefault && k2.bDefault);
140 }
141 
142 QDebug operator<<(QDebug dbg, const KEntryKey &key);
143 QDebug operator<<(QDebug dbg, const KEntry &entry);
144 
152 class KEntryMap : public QMap<KEntryKey, KEntry>
153 {
154 public:
155  enum SearchFlag {
156  SearchDefaults = 1,
157  SearchLocalized = 2
158  };
159  Q_DECLARE_FLAGS(SearchFlags, SearchFlag)
160 
161  enum EntryOption {
162  EntryDirty = 1,
163  EntryGlobal = 2,
164  EntryImmutable = 4,
165  EntryDeleted = 8,
166  EntryExpansion = 16,
167  EntryRawKey = 32,
168  EntryLocalizedCountry = 64,
169  EntryNotify = 128,
170  EntryDefault = (SearchDefaults << 16),
171  EntryLocalized = (SearchLocalized << 16)
172  };
173  Q_DECLARE_FLAGS(EntryOptions, EntryOption)
174 
175  Iterator findExactEntry(const QByteArray &group, const QByteArray &key = QByteArray(),
176  SearchFlags flags = SearchFlags());
177 
178  Iterator findEntry(const QByteArray &group, const QByteArray &key = QByteArray(),
179  SearchFlags flags = SearchFlags());
180 
181  ConstIterator findEntry(const QByteArray &group, const QByteArray &key = QByteArray(),
182  SearchFlags flags = SearchFlags()) const;
183 
187  bool setEntry(const QByteArray &group, const QByteArray &key,
188  const QByteArray &value, EntryOptions options);
189 
190  void setEntry(const QByteArray &group, const QByteArray &key,
191  const QString &value, EntryOptions options)
192  {
193  setEntry(group, key, value.toUtf8(), options);
194  }
195 
196  QString getEntry(const QByteArray &group, const QByteArray &key,
197  const QString &defaultValue = QString(),
198  SearchFlags flags = SearchFlags(),
199  bool *expand = nullptr) const;
200 
201  bool hasEntry(const QByteArray &group, const QByteArray &key = QByteArray(),
202  SearchFlags flags = SearchFlags()) const;
203 
204  bool getEntryOption(const ConstIterator &it, EntryOption option) const;
205  bool getEntryOption(const QByteArray &group, const QByteArray &key,
206  SearchFlags flags, EntryOption option) const
207  {
208  return getEntryOption(findEntry(group, key, flags), option);
209  }
210 
211  void setEntryOption(Iterator it, EntryOption option, bool bf);
212  void setEntryOption(const QByteArray &group, const QByteArray &key, SearchFlags flags,
213  EntryOption option, bool bf)
214  {
215  setEntryOption(findEntry(group, key, flags), option, bf);
216  }
217 
218  bool revertEntry(const QByteArray &group, const QByteArray &key, EntryOptions options, SearchFlags flags = SearchFlags());
219 };
220 Q_DECLARE_OPERATORS_FOR_FLAGS(KEntryMap::SearchFlags)
221 Q_DECLARE_OPERATORS_FOR_FLAGS(KEntryMap::EntryOptions)
222 
223 
229 
237 typedef QMap<KEntryKey, KEntry>::ConstIterator KEntryMapConstIterator;
238 
239 #endif
QMap< KEntryKey, KEntry >::Iterator KEntryMapIterator
Definition: kconfigdata.h:228
bool bOverridesGlobal
Entry will need to be written on a non global file even if it matches default value.
Definition: kconfigdata.h:65
bool bDeleted
Entry has been deleted.
Definition: kconfigdata.h:45
map/dict/list config node entry.
Definition: kconfigdata.h:22
bool bReverted
Entry has been reverted to its default value (from a more global file).
Definition: kconfigdata.h:53
KEntry()
Constructor.
Definition: kconfigdata.h:24
bool bDefault
Entry indicates if this is a default value.
Definition: kconfigdata.h:111
bool bImmutable
Entry can not be modified.
Definition: kconfigdata.h:41
key structure holding both the actual key and the group to which it belongs.
Definition: kconfigdata.h:88
QByteArray mGroup
The "group" to which this EntryKey belongs.
Definition: kconfigdata.h:99
bool bLocal
Entry is localised or not.
Definition: kconfigdata.h:107
QMap< KEntryKey, KEntry >::ConstIterator KEntryMapConstIterator
Definition: kconfigdata.h:237
KEntryKey(const QByteArray &_group=QByteArray(), const QByteArray &_key=QByteArray(), bool isLocalized=false, bool isDefault=false)
Constructor.
Definition: kconfigdata.h:90
bool bGlobal
Entry should be written to the global config file.
Definition: kconfigdata.h:37
QDataStream & operator<<(QDataStream &out, const KDateTime::Spec &spec)
QByteArray mValue
Definition: kconfigdata.h:29
QByteArray mKey
The actual key of the entry in question.
Definition: kconfigdata.h:103
bool bLocalizedCountry
Entry is for a localized key.
Definition: kconfigdata.h:58
bool bExpand
Whether to apply dollar expansion or not.
Definition: kconfigdata.h:49
bool bDirty
Must the entry be written back to disk?
Definition: kconfigdata.h:33
QByteArray toUtf8() const const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Sat Jul 11 2020 22:47:24 by doxygen 1.8.11 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.