• Skip to content
  • Skip to link menu
KDE API Reference
  • KDE API Reference
  • kdelibs API Reference
  • KDE Home
  • Contact Us
 

KDECore

  • sources
  • kde-4.14
  • kdelibs
  • kdecore
  • config
kconfigdata.h
Go to the documentation of this file.
1 /*
2  This file is part of the KDE libraries
3  Copyright (c) 2006, 2007 Thomas Braxton <kde.braxton@gmail.com>
4  Copyright (c) 1999-2000 Preston Brown <pbrown@kde.org>
5  Copyright (C) 1996-2000 Matthias Kalle Dalheimer <kalle@kde.org>
6 
7  This library is free software; you can redistribute it and/or
8  modify it under the terms of the GNU Library General Public
9  License as published by the Free Software Foundation; either
10  version 2 of the License, or (at your option) any later version.
11 
12  This library is distributed in the hope that it will be useful,
13  but WITHOUT ANY WARRANTY; without even the implied warranty of
14  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
15  Library General Public License for more details.
16 
17  You should have received a copy of the GNU Library General Public License
18  along with this library; see the file COPYING.LIB. If not, write to
19  the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
20  Boston, MA 02110-1301, USA.
21 */
22 
23 #ifndef KCONFIGDATA_H
24 #define KCONFIGDATA_H
25 
26 #include <QtCore/QByteArray>
27 #include <QtCore/QString>
28 #include <QtCore/QMap>
29 #include <QtCore/QDebug>
30 
35 struct KEntry
36 {
38  KEntry()
39  : mValue(), bDirty(false),
40  bGlobal(false), bImmutable(false), bDeleted(false), bExpand(false), bReverted(false) {}
42  QByteArray mValue;
46  bool bDirty :1;
50  bool bGlobal:1;
54  bool bImmutable:1;
58  bool bDeleted:1;
62  bool bExpand:1;
66  bool bReverted:1;
67 };
68 
69 // These operators are used to check whether an entry which is about
70 // to be written equals the previous value. As such, this intentionally
71 // omits the dirty flag from the comparison.
72 inline bool operator ==(const KEntry &k1, const KEntry &k2)
73 {
74  return k1.bGlobal == k2.bGlobal && k1.bImmutable == k2.bImmutable
75  && k1.bDeleted == k2.bDeleted && k1.bExpand == k2.bExpand
76  && k1.mValue == k2.mValue;
77 }
78 
79 inline bool operator !=(const KEntry &k1, const KEntry &k2)
80 {
81  return !(k1 == k2);
82 }
83 
89 struct KEntryKey
90 {
92  KEntryKey(const QByteArray& _group = QByteArray(),
93  const QByteArray& _key = QByteArray(), bool isLocalized=false, bool isDefault=false)
94  : mGroup(_group), mKey(_key), bLocal(isLocalized), bDefault(isDefault), bRaw(false)
95  { ; }
99  QByteArray mGroup;
103  QByteArray mKey;
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  return (!k1.bDefault && k2.bDefault);
139 }
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  EntryDefault=(SearchDefaults<<16),
169  EntryLocalized=(SearchLocalized<<16)
170  };
171  Q_DECLARE_FLAGS(EntryOptions, EntryOption)
172 
173  Iterator findExactEntry(const QByteArray& group, const QByteArray& key = QByteArray(),
174  SearchFlags flags = SearchFlags());
175 
176  Iterator findEntry(const QByteArray& group, const QByteArray& key = QByteArray(),
177  SearchFlags flags = SearchFlags());
178 
179  ConstIterator findEntry(const QByteArray& group, const QByteArray& key = QByteArray(),
180  SearchFlags flags = SearchFlags()) const;
181 
185  bool setEntry(const QByteArray& group, const QByteArray& key,
186  const QByteArray& value, EntryOptions options);
187 
188  void setEntry(const QByteArray& group, const QByteArray& key,
189  const QString & value, EntryOptions options)
190  {
191  setEntry(group, key, value.toUtf8(), options);
192  }
193 
194  QString getEntry(const QByteArray& group, const QByteArray& key,
195  const QString & defaultValue = QString(),
196  SearchFlags flags = SearchFlags(),
197  bool * expand=0) const;
198 
199  bool hasEntry(const QByteArray& group, const QByteArray& key = QByteArray(),
200  SearchFlags flags = SearchFlags()) const;
201 
202  bool getEntryOption(const ConstIterator& it, EntryOption option) const;
203  bool getEntryOption(const QByteArray& group, const QByteArray& key,
204  SearchFlags flags, EntryOption option) const
205  {
206  return getEntryOption(findEntry(group, key, flags), option);
207  }
208 
209  void setEntryOption(Iterator it, EntryOption option, bool bf);
210  void setEntryOption(const QByteArray& group, const QByteArray& key, SearchFlags flags,
211  EntryOption option, bool bf)
212  {
213  setEntryOption(findEntry(group, key, flags), option, bf);
214  }
215 
216  bool revertEntry(const QByteArray& group, const QByteArray& key, SearchFlags flags=SearchFlags());
217 };
218 Q_DECLARE_OPERATORS_FOR_FLAGS(KEntryMap::SearchFlags)
219 Q_DECLARE_OPERATORS_FOR_FLAGS(KEntryMap::EntryOptions)
220 
226 typedef QMap<KEntryKey, KEntry>::Iterator KEntryMapIterator;
227 
235 typedef QMap<KEntryKey, KEntry>::ConstIterator KEntryMapConstIterator;
236 
237 #endif
KEntry::KEntryMapIterator
QMap< KEntryKey, KEntry >::Iterator KEntryMapIterator
Definition: kconfigdata.h:226
KEntryMap::EntryDeleted
Definition: kconfigdata.h:165
KEntryMap::EntryDirty
Definition: kconfigdata.h:162
KEntryMap
Definition: kconfigdata.h:152
KEntry::bDeleted
bool bDeleted
Entry has been deleted.
Definition: kconfigdata.h:58
KEntryMap::EntryImmutable
Definition: kconfigdata.h:164
QByteArray
KEntry
map/dict/list config node entry.
Definition: kconfigdata.h:35
KEntry::bReverted
bool bReverted
Entry has been reverted to its default value (from a more global file).
Definition: kconfigdata.h:66
KMacroExpander::group
Definition: kmacroexpander_unix.cpp:34
KEntryMap::EntryRawKey
Definition: kconfigdata.h:167
operator<
bool operator<(const KEntryKey &k1, const KEntryKey &k2)
Compares two KEntryKeys (needed for QMap).
Definition: kconfigdata.h:124
KEntry::KEntry
KEntry()
Constructor.
Definition: kconfigdata.h:38
QMap
KEntryKey::bDefault
bool bDefault
Entry indicates if this is a default value.
Definition: kconfigdata.h:111
KEntryMap::EntryOption
EntryOption
Definition: kconfigdata.h:161
operator<<
QDebug operator<<(QDebug dbg, const KEntryKey &key)
Definition: kconfigdata.cpp:25
typedef
operator!=
bool operator!=(const KEntry &k1, const KEntry &k2)
Definition: kconfigdata.h:79
KEntryMap::EntryExpansion
Definition: kconfigdata.h:166
operator==
bool operator==(const KEntry &k1, const KEntry &k2)
Definition: kconfigdata.h:72
KEntryMap::EntryLocalized
Definition: kconfigdata.h:169
KEntry::bImmutable
bool bImmutable
Entry can not be modified.
Definition: kconfigdata.h:54
KEntryKey
key structure holding both the actual key and the group to which it belongs.
Definition: kconfigdata.h:89
KEntryKey::mGroup
QByteArray mGroup
The "group" to which this EntryKey belongs.
Definition: kconfigdata.h:99
KEntryMap::hasEntry
bool hasEntry(const QByteArray &group, const QByteArray &key=QByteArray(), SearchFlags flags=SearchFlags()) const
Definition: kconfigdata.cpp:226
KEntryKey::bLocal
bool bLocal
Entry is localised or not.
Definition: kconfigdata.h:107
KEntryMap::getEntryOption
bool getEntryOption(const QByteArray &group, const QByteArray &key, SearchFlags flags, EntryOption option) const
Definition: kconfigdata.h:203
QString
KEntryMap::getEntry
QString getEntry(const QByteArray &group, const QByteArray &key, const QString &defaultValue=QString(), SearchFlags flags=SearchFlags(), bool *expand=0) const
Definition: kconfigdata.cpp:209
KEntryMap::setEntryOption
void setEntryOption(const QByteArray &group, const QByteArray &key, SearchFlags flags, EntryOption option, bool bf)
Definition: kconfigdata.h:210
KEntry::KEntryMapConstIterator
QMap< KEntryKey, KEntry >::ConstIterator KEntryMapConstIterator
Definition: kconfigdata.h:235
KEntryKey::KEntryKey
KEntryKey(const QByteArray &_group=QByteArray(), const QByteArray &_key=QByteArray(), bool isLocalized=false, bool isDefault=false)
Constructor.
Definition: kconfigdata.h:92
KEntryMap::setEntry
bool setEntry(const QByteArray &group, const QByteArray &key, const QByteArray &value, EntryOptions options)
Returns true if the entry gets dirtied or false in other case.
QDebug
QMap< KEntryKey, KEntry >::key
const Key key(const T &value) const
KEntry::bGlobal
bool bGlobal
Entry should be written to the global config file.
Definition: kconfigdata.h:50
KEntryMap::findEntry
Iterator findEntry(const QByteArray &group, const QByteArray &key=QByteArray(), SearchFlags flags=SearchFlags())
KEntry::mValue
QByteArray mValue
Definition: kconfigdata.h:42
KEntryKey::mKey
QByteArray mKey
The actual key of the entry in question.
Definition: kconfigdata.h:103
KEntryKey::bRaw
bool bRaw
Definition: kconfigdata.h:116
KEntryMap::getEntryOption
bool getEntryOption(const ConstIterator &it, EntryOption option) const
KEntryMap::SearchFlag
SearchFlag
Definition: kconfigdata.h:155
KEntryMap::SearchLocalized
Definition: kconfigdata.h:157
KEntryMap::setEntryOption
void setEntryOption(Iterator it, EntryOption option, bool bf)
QMap< KEntryKey, KEntry >::Iterator
typedef Iterator
QMap< KEntryKey, KEntry >::ConstIterator
typedef ConstIterator
KEntryMap::EntryGlobal
Definition: kconfigdata.h:163
KEntry::bExpand
bool bExpand
Whether to apply dollar expansion or not.
Definition: kconfigdata.h:62
KEntryMap::SearchDefaults
Definition: kconfigdata.h:156
KEntryMap::findExactEntry
Iterator findExactEntry(const QByteArray &group, const QByteArray &key=QByteArray(), SearchFlags flags=SearchFlags())
Definition: kconfigdata.cpp:42
KEntry::bDirty
bool bDirty
Must the entry be written back to disk?
Definition: kconfigdata.h:46
KEntryMap::EntryDefault
Definition: kconfigdata.h:168
KEntryMap::revertEntry
bool revertEntry(const QByteArray &group, const QByteArray &key, SearchFlags flags=SearchFlags())
Definition: kconfigdata.cpp:289
defaultValue
QString defaultValue(const QString &t)
Definition: kconfig_compiler.cpp:950
QMap< KEntryKey, KEntry >::value
const T value(const Key &key) const
This file is part of the KDE documentation.
Documentation copyright © 1996-2020 The KDE developers.
Generated on Mon Jun 22 2020 13:22:11 by doxygen 1.8.7 written by Dimitri van Heesch, © 1997-2006

KDE's Doxygen guidelines are available online.

KDECore

Skip menu "KDECore"
  • Main Page
  • Namespace List
  • Namespace Members
  • Alphabetical List
  • Class List
  • Class Hierarchy
  • Class Members
  • File List
  • File Members
  • Modules
  • Related Pages

kdelibs API Reference

Skip menu "kdelibs API Reference"
  • DNSSD
  • Interfaces
  •   KHexEdit
  •   KMediaPlayer
  •   KSpeech
  •   KTextEditor
  • kconf_update
  • KDE3Support
  •   KUnitTest
  • KDECore
  • KDED
  • KDEsu
  • KDEUI
  • KDEWebKit
  • KDocTools
  • KFile
  • KHTML
  • KImgIO
  • KInit
  • kio
  • KIOSlave
  • KJS
  •   KJS-API
  •   WTF
  • kjsembed
  • KNewStuff
  • KParts
  • KPty
  • Kross
  • KUnitConversion
  • KUtils
  • Nepomuk
  • Plasma
  • Solid
  • Sonnet
  • ThreadWeaver

Search



Report problems with this website to our bug tracking system.
Contact the specific authors with questions and comments about the page contents.

KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. | Legal