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

KDECore

  • 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
35struct 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.
72inline 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
79inline bool operator !=(const KEntry &k1, const KEntry &k2)
80{
81 return !(k1 == k2);
82}
83
89struct 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
124inline 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
142QDebug operator<<(QDebug dbg, const KEntryKey& key);
143QDebug operator<<(QDebug dbg, const KEntry& entry);
144
152class 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};
218Q_DECLARE_OPERATORS_FOR_FLAGS(KEntryMap::SearchFlags)
219Q_DECLARE_OPERATORS_FOR_FLAGS(KEntryMap::EntryOptions)
220
221
226typedef QMap<KEntryKey, KEntry>::Iterator KEntryMapIterator;
227
235typedef QMap<KEntryKey, KEntry>::ConstIterator KEntryMapConstIterator;
236
237#endif
KEntryMap
type specifying a map of entries (key,value pairs).
Definition: kconfigdata.h:153
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::findExactEntry
Iterator findExactEntry(const QByteArray &group, const QByteArray &key=QByteArray(), SearchFlags flags=SearchFlags())
Definition: kconfigdata.cpp:42
KEntryMap::revertEntry
bool revertEntry(const QByteArray &group, const QByteArray &key, SearchFlags flags=SearchFlags())
Definition: kconfigdata.cpp:289
KEntryMap::getEntryOption
bool getEntryOption(const QByteArray &group, const QByteArray &key, SearchFlags flags, EntryOption option) const
Definition: kconfigdata.h:203
KEntryMap::findEntry
Iterator findEntry(const QByteArray &group, const QByteArray &key=QByteArray(), SearchFlags flags=SearchFlags())
KEntryMap::setEntry
void setEntry(const QByteArray &group, const QByteArray &key, const QString &value, EntryOptions options)
Definition: kconfigdata.h:188
KEntryMap::setEntryOption
void setEntryOption(const QByteArray &group, const QByteArray &key, SearchFlags flags, EntryOption option, bool bf)
Definition: kconfigdata.h:210
KEntryMap::getEntryOption
bool getEntryOption(const ConstIterator &it, EntryOption option) const
KEntryMap::setEntryOption
void setEntryOption(Iterator it, EntryOption option, bool bf)
KEntryMap::EntryOption
EntryOption
Definition: kconfigdata.h:161
KEntryMap::EntryImmutable
@ EntryImmutable
Definition: kconfigdata.h:164
KEntryMap::EntryDirty
@ EntryDirty
Definition: kconfigdata.h:162
KEntryMap::EntryLocalized
@ EntryLocalized
Definition: kconfigdata.h:169
KEntryMap::EntryExpansion
@ EntryExpansion
Definition: kconfigdata.h:166
KEntryMap::EntryGlobal
@ EntryGlobal
Definition: kconfigdata.h:163
KEntryMap::EntryRawKey
@ EntryRawKey
Definition: kconfigdata.h:167
KEntryMap::EntryDeleted
@ EntryDeleted
Definition: kconfigdata.h:165
KEntryMap::EntryDefault
@ EntryDefault
Definition: kconfigdata.h:168
KEntryMap::SearchFlag
SearchFlag
Definition: kconfigdata.h:155
KEntryMap::SearchLocalized
@ SearchLocalized
Definition: kconfigdata.h:157
KEntryMap::SearchDefaults
@ SearchDefaults
Definition: kconfigdata.h:156
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.
KEntryMap::findEntry
ConstIterator findEntry(const QByteArray &group, const QByteArray &key=QByteArray(), SearchFlags flags=SearchFlags()) const
KEntryMap::hasEntry
bool hasEntry(const QByteArray &group, const QByteArray &key=QByteArray(), SearchFlags flags=SearchFlags()) const
Definition: kconfigdata.cpp:226
QMap
QString
defaultValue
QString defaultValue(const QString &t)
Definition: kconfig_compiler.cpp:950
operator<<
QDebug operator<<(QDebug dbg, const KEntryKey &key)
Definition: kconfigdata.cpp:25
operator==
bool operator==(const KEntry &k1, const KEntry &k2)
Definition: kconfigdata.h:72
operator<
bool operator<(const KEntryKey &k1, const KEntryKey &k2)
Compares two KEntryKeys (needed for QMap).
Definition: kconfigdata.h:124
operator!=
bool operator!=(const KEntry &k1, const KEntry &k2)
Definition: kconfigdata.h:79
KEntryKey
key structure holding both the actual key and the group to which it belongs.
Definition: kconfigdata.h:90
KEntryKey::mKey
QByteArray mKey
The actual key of the entry in question.
Definition: kconfigdata.h:103
KEntryKey::bDefault
bool bDefault
Entry indicates if this is a default value.
Definition: kconfigdata.h:111
KEntryKey::bRaw
bool bRaw
Definition: kconfigdata.h:116
KEntryKey::mGroup
QByteArray mGroup
The "group" to which this EntryKey belongs.
Definition: kconfigdata.h:99
KEntryKey::bLocal
bool bLocal
Entry is localised or not.
Definition: kconfigdata.h:107
KEntryKey::KEntryKey
KEntryKey(const QByteArray &_group=QByteArray(), const QByteArray &_key=QByteArray(), bool isLocalized=false, bool isDefault=false)
Constructor.
Definition: kconfigdata.h:92
KEntry
map/dict/list config node entry.
Definition: kconfigdata.h:36
KEntry::bImmutable
bool bImmutable
Entry can not be modified.
Definition: kconfigdata.h:54
KEntry::KEntry
KEntry()
Constructor.
Definition: kconfigdata.h:38
KEntry::bGlobal
bool bGlobal
Entry should be written to the global config file.
Definition: kconfigdata.h:50
KEntry::bExpand
bool bExpand
Whether to apply dollar expansion or not.
Definition: kconfigdata.h:62
KEntry::KEntryMapIterator
QMap< KEntryKey, KEntry >::Iterator KEntryMapIterator
type for iterating over keys in a KEntryMap in sorted order.
Definition: kconfigdata.h:226
KEntry::bDirty
bool bDirty
Must the entry be written back to disk?
Definition: kconfigdata.h:46
KEntry::bReverted
bool bReverted
Entry has been reverted to its default value (from a more global file).
Definition: kconfigdata.h:66
KEntry::bDeleted
bool bDeleted
Entry has been deleted.
Definition: kconfigdata.h:58
KEntry::mValue
QByteArray mValue
Definition: kconfigdata.h:42
KEntry::KEntryMapConstIterator
QMap< KEntryKey, KEntry >::ConstIterator KEntryMapConstIterator
type for iterating over keys in a KEntryMap in sorted order.
Definition: kconfigdata.h:235
This file is part of the KDE documentation.
Documentation copyright © 1996-2023 The KDE developers.
Generated on Mon Feb 20 2023 00:00:00 by doxygen 1.9.6 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-4.14.38 API Reference

Skip menu "kdelibs-4.14.38 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
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