This file is indexed.

/usr/include/kconfiggroup.h is in kdelibs5-dev 4:4.14.38-0ubuntu3.

This file is owned by root:root, with mode 0o644.

The actual contents of the file can be viewed below.

  1
  2
  3
  4
  5
  6
  7
  8
  9
 10
 11
 12
 13
 14
 15
 16
 17
 18
 19
 20
 21
 22
 23
 24
 25
 26
 27
 28
 29
 30
 31
 32
 33
 34
 35
 36
 37
 38
 39
 40
 41
 42
 43
 44
 45
 46
 47
 48
 49
 50
 51
 52
 53
 54
 55
 56
 57
 58
 59
 60
 61
 62
 63
 64
 65
 66
 67
 68
 69
 70
 71
 72
 73
 74
 75
 76
 77
 78
 79
 80
 81
 82
 83
 84
 85
 86
 87
 88
 89
 90
 91
 92
 93
 94
 95
 96
 97
 98
 99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
/*
   This file is part of the KDE libraries
   Copyright (c) 2006, 2007 Thomas Braxton <kde.braxton@gmail.com>
   Copyright (c) 1999 Preston Brown <pbrown@kde.org>
   Copyright (c) 1997 Matthias Kalle Dalheimer <kalle@kde.org>
   Copyright (c) 2001 Waldo Bastian <bastian@kde.org>

   This library is free software; you can redistribute it and/or
   modify it under the terms of the GNU Library General Public
   License as published by the Free Software Foundation; either
   version 2 of the License, or (at your option) any later version.

   This library is distributed in the hope that it will be useful,
   but WITHOUT ANY WARRANTY; without even the implied warranty of
   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
   Library General Public License for more details.

   You should have received a copy of the GNU Library General Public License
   along with this library; see the file COPYING.LIB.  If not, write to
   the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
   Boston, MA 02110-1301, USA.
*/

#ifndef KCONFIGGROUP_H
#define KCONFIGGROUP_H

#include "kconfigbase.h"

#include <kdecore_export.h>

#include <QtCore/QExplicitlySharedDataPointer>
#include <QtCore/QVariant>
#include <QtCore/QStringList>

class KConfig;
class KConfigGroupPrivate;
class KSharedConfig;
template <typename T> class KSharedPtr;
typedef KSharedPtr<KSharedConfig> KSharedConfigPtr;

/**
 * \class KConfigGroup kconfiggroup.h <KConfigGroup>
 *
 * A class for one specific group in a KConfig object.
 *
 * If you want to access the top-level entries of a KConfig
 * object, which are not associated with any group, use an
 * empty group name.
 *
 * A KConfigGroup will be read-only if it is constructed from a
 * const config object or from another read-only group.
 */
class KDECORE_EXPORT KConfigGroup : public KConfigBase
{
public:
    /**
     * Constructs an invalid group.
     *
     * \see isValid
     */
    KConfigGroup();

    /**
     * Construct a config group corresponding to @p group in @p master.
     *
     * This allows the creation of subgroups by passing another
     * group as @p master.
     *
     * @p group is the group name encoded in UTF-8.
     */
    KConfigGroup(KConfigBase *master, const QString &group);
    /** Overload for KConfigGroup(KConfigBase*,const QString&) */
    KConfigGroup(KConfigBase *master, const char *group);

    /**
     * Construct a read-only config group.
     *
     * A read-only group will silently ignore any attempts to write to it.
     *
     * This allows the creation of subgroups by passing an existing group
     * as @p master.
     */
    KConfigGroup(const KConfigBase *master, const QString &group);
    /** Overload for KConfigGroup(const KConfigBase*,const QString&) */
    KConfigGroup(const KConfigBase *master, const char *group);

    /** Overload for KConfigGroup(const KConfigBase*,const QString&) */
    KConfigGroup(const KSharedConfigPtr &master, const QString &group);
    /** Overload for KConfigGroup(const KConfigBase*,const QString&) */
    KConfigGroup(const KSharedConfigPtr &master, const char *group);

    /**
     * Creates a read-only copy of a read-only group.
     */
    KConfigGroup(const KConfigGroup &);
    KConfigGroup &operator=(const KConfigGroup &);

    ~KConfigGroup();

    /**
     * Whether the group is valid.
     *
     * A group is invalid if it was constructed without arguments.
     *
     * You should not call any functions on an invalid group.
     *
     * @return @c true if the group is valid, @c false if it is invalid.
     */
    bool isValid() const;

    /**
     * The name of this group.
     *
     * The root group is named "<default>".
     */
    QString name() const;

    /**
     * Check whether the containing KConfig object acutally contains a
     * group with this name.
     */
    bool exists() const;

    /**
     * @reimp
     *
     * Syncs the parent config.
     */
    void sync();

    /// @reimp
    void markAsClean();

    /// @reimp
    AccessMode accessMode() const;

    /**
     * Return the config object that this group belongs to
     */
    KConfig* config();
    /**
     * Return the config object that this group belongs to
     */
    const KConfig* config() const;

    /**
     * Changes the group of the object
     *
     * @deprecated
     * Create another KConfigGroup from the parent of this group instead.
     */
#ifndef KDE_NO_DEPRECATED
    KDE_DEPRECATED void changeGroup(const QString &group);
#endif
    /**
     * Overload for changeGroup(const QString&)
     *
     * @deprecated
     * Create another KConfigGroup from the parent of this group instead.
     */
#ifndef KDE_NO_DEPRECATED
    KDE_DEPRECATED void changeGroup(const char *group);
#endif

    /**
     * Copies the entries in this group to another configuration object
     *
     * @note @p other can be either another group or a different file.
     *
     * @param other  the configuration object to copy this group's entries to
     * @param pFlags the flags to use when writing the entries to the
     *               other configuration object
     *
     * @since 4.1
     */
    void copyTo(KConfigBase *other, WriteConfigFlags pFlags = Normal) const;

    /**
     * Changes the configuration object that this group belongs to
     *
     * @note @p other can be another group, the top-level KConfig object or
     * a different KConfig object entirely.
     *
     * If @p parent is already the parent of this group, this method will have
     * no effect.
     *
     * @param parent the config object to place this group under
     * @param pFlags the flags to use in determining which storage source to
     *               write the data to
     *
     * @since 4.1
     */
    void reparent(KConfigBase *parent, WriteConfigFlags pFlags = Normal);

    /**
     * Returns the group that this group belongs to
     *
     * @return the parent group, or an invalid group if this is a top-level
     *          group
     *
     * @since 4.1
     */
    KConfigGroup parent() const;

    /**
     * @reimp
     */
    QStringList groupList() const;

    /**
     * Returns a list of keys this group contains
     */
    QStringList keyList() const;

    /**
     * Delete all entries in the entire group
     *
     * @param pFlags flags passed to KConfig::deleteGroup
     *
     * @see deleteEntry()
     */
    void deleteGroup(WriteConfigFlags pFlags = Normal);
    using KConfigBase::deleteGroup;

    /**
     * Reads the value of an entry specified by @p pKey in the current group
     *
     * This template method makes it possible to write
     *    QString foo = readEntry("...", QString("default"));
     * and the same with all other types supported by QVariant.
     *
     * The return type of the method is simply the same as the type of the default value.
     *
     * @note readEntry("...", Qt::white) will not compile because Qt::white is an enum.
     * You must turn it into readEntry("...", QColor(Qt::white)).
     *
     * @note Only the following QVariant types are allowed : String,
     * StringList, List, Font, Point, Rect, Size, Color, Int, UInt, Bool,
     * Double, LongLong, ULongLong, DateTime and Date.
     *
     * @param key The key to search for
     * @param aDefault A default value returned if the key was not found
     * @return The value for this key, or @p aDefault.
     *
     * @see writeEntry(), deleteEntry(), hasKey()
     */
    template <typename T>
        inline T readEntry(const QString &key, const T &aDefault) const
            { return readCheck(key.toUtf8().constData(), aDefault); }
    /** Overload for readEntry(const QString&, const T&) const */
    template <typename T>
        inline T readEntry(const char *key, const T &aDefault) const
            { return readCheck(key, aDefault); }

    /**
     * Reads the value of an entry specified by @p key in the current group
     *
     * @param key the key to search for
     * @param aDefault a default value returned if the key was not found
     * @return the value for this key, or @p aDefault if the key was not found
     *
     * @see writeEntry(), deleteEntry(), hasKey()
     */
    QVariant readEntry(const QString &key, const QVariant &aDefault) const;
    /** Overload for readEntry(const QString&, const QVariant&) */
    QVariant readEntry(const char *key, const QVariant &aDefault) const;

    /**
     * Reads the string value of an entry specified by @p key in the current group
     *
     * If you want to read a path, please use readPathEntry().
     *
     * @param key the key to search for
     * @param aDefault a default value returned if the key was not found
     * @return the value for this key, or @p aDefault if the key was not found
     *
     * @see readPathEntry(), writeEntry(), deleteEntry(), hasKey()
     */
    QString readEntry(const QString &key, const QString &aDefault) const;
    /** Overload for readEntry(const QString&, const QString&) */
    QString readEntry(const char *key, const QString &aDefault) const;

    /** Overload for readEntry(const QString&, const QString&) */
    QString readEntry(const QString &key, const char *aDefault = 0) const;
    /** Overload for readEntry(const QString&, const QString&) */
    QString readEntry(const char *key, const char *aDefault = 0) const;

    /**
     * @copydoc readEntry(const char*, const QStringList&) const
     *
     * @warning This function doesn't convert the items returned
     *          to any type. It's actually a list of QVariant::String's. If you
     *          want the items converted to a specific type use
     *          readEntry(const char*, const QList<T>&) const
     */
    QVariantList readEntry(const QString &key, const QVariantList &aDefault) const;
    /** Overload for readEntry(const QString&, const QVariantList&) */
    QVariantList readEntry(const char *key, const QVariantList &aDefault) const;

    /**
     * Reads a list of strings from the config object
     *
     * @param key The key to search for
     * @param aDefault The default value to use if the key does not exist
     * @return The list, or @p aDefault if @p key does not exist
     *
     * @see readXdgListEntry(), writeEntry(), deleteEntry(), hasKey()
     */
    QStringList readEntry(const QString &key, const QStringList &aDefault) const;
    /** Overload for readEntry(const QString&, const QStringList&) */
    QStringList readEntry(const char *key, const QStringList &aDefault) const;

    /**
     * Reads a list of values from the config object
     *
     * @param key the key to search for
     * @param aDefault the default value to use if the key does not exist
     * @return the list, or @p aDefault if @p key does not exist
     *
     * @see readXdgListEntry(), writeEntry(), deleteEntry(), hasKey()
     */
    template<typename T>
        inline QList<T> readEntry(const QString &key, const QList<T> &aDefault) const
            { return readListCheck(key.toUtf8().constData(), aDefault); }
    /** Overload for readEntry(const QString&, const QList<T>&) */
    template<typename T>
        inline QList<T> readEntry(const char *key, const QList<T> &aDefault) const
            { return readListCheck(key, aDefault); }

    /**
     * Reads a list of strings from the config object, following XDG
     * desktop entry spec separator semantics
     *
     * @param pKey the key to search for
     * @param aDefault the default value to use if the key does not exist
     * @return the list, or @p aDefault if @p pKey does not exist
     *
     * @see readEntry(const QString&, const QStringList&) const
     */
    QStringList readXdgListEntry(const QString &pKey, const QStringList &aDefault = QStringList()) const;
    /** Overload for readXdgListEntry(const QString&, const QStringList&) */
    QStringList readXdgListEntry(const char *pKey, const QStringList &aDefault = QStringList()) const;

    /**
     * Reads a path
     *
     * Read the value of an entry specified by @p pKey in the current group
     * and interpret it as a path. This means, dollar expansion is activated
     * for this value, so that e.g. $HOME gets expanded.
     *
     * @param pKey The key to search for.
     * @param aDefault A default value returned if the key was not found.
     * @return The value for this key. Can be QString() if @p aDefault is null.
     */
    QString readPathEntry(const QString &pKey, const QString &aDefault) const;
    /** Overload for readPathEntry(const QString&, const QString&) */
    QString readPathEntry(const char *key, const QString &aDefault) const;

    /**
     * Reads a list of paths
     *
     * Read the value of an entry specified by @p pKey in the current group
     * and interpret it as a list of paths. This means, dollar expansion is activated
     * for this value, so that e.g. $HOME gets expanded.
     *
     * @param pKey the key to search for
     * @param aDefault a default value returned if the key was not found
     * @return the list, or @p aDefault if the key does not exist
     */
    QStringList readPathEntry(const QString &pKey, const QStringList &aDefault) const;
    /** Overload for readPathEntry(const QString&, const QStringList&) */
    QStringList readPathEntry(const char *key, const QStringList &aDefault) const;

    /**
     * Reads an untranslated string entry
     *
     * You should not normally need to use this.
     *
     * @param pKey the key to search for
     * @param aDefault a default value returned if the key was not found
     * @return the value for this key, or @p aDefault if the key does not exist
     */
    QString readEntryUntranslated(const QString &pKey,
                                  const QString &aDefault = QString()) const;
    /** Overload for readEntryUntranslated(const QString&, const QString&) */
    QString readEntryUntranslated(const char *key,
                                  const QString &aDefault = QString()) const;

    /**
     * Writes a value to the configuration object.
     *
     * @param key the key to write to
     * @param value the value to write
     * @param pFlags the flags to use when writing this entry
     *
     * @see readEntry(), writeXdgListEntry(), deleteEntry()
     */
    void writeEntry(const QString &key, const QVariant &value,
                    WriteConfigFlags pFlags = Normal);
    /** Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) */
    void writeEntry(const char *key, const QVariant &value,
                    WriteConfigFlags pFlags = Normal);

    /** Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) */
    void writeEntry(const QString &key, const QString &value,
                    WriteConfigFlags pFlags = Normal);
    /** Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) */
    void writeEntry(const char *key, const QString &value,
                    WriteConfigFlags pFlags = Normal);

    /** Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) */
    void writeEntry(const QString &key, const QByteArray &value,
                    WriteConfigFlags pFlags = Normal);
    /** Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) */
    void writeEntry(const char *key, const QByteArray &value,
                    WriteConfigFlags pFlags = Normal);

    /** Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) */
    void writeEntry(const QString &key, const char *value, WriteConfigFlags pFlags = Normal);
    /** Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) */
    void writeEntry(const char *key, const char *value, WriteConfigFlags pFlags = Normal);

    /** Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) */
    template <typename T>
        inline void writeEntry(const char *key, const T &value, WriteConfigFlags pFlags = Normal)
            { writeCheck( key, value, pFlags ); }
    /** Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) */
    template <typename T>
        inline void writeEntry(const QString &key, const T &value, WriteConfigFlags pFlags = Normal)
            { writeCheck( key.toUtf8().constData(), value, pFlags ); }

    /** Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) */
    void writeEntry(const QString &key, const QStringList &value,
                    WriteConfigFlags pFlags = Normal);
    /** Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) */
    void writeEntry(const char *key, const QStringList &value,
                    WriteConfigFlags pFlags = Normal);

    /** Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) */
    void writeEntry(const QString &key, const QVariantList &value,
                    WriteConfigFlags pFlags = Normal);
    /** Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) */
    void writeEntry(const char *key, const QVariantList &value,
                    WriteConfigFlags pFlags = Normal);

    /** Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) */
    template <typename T>
        inline void writeEntry(const QString &key, const QList<T> &value, WriteConfigFlags pFlags = Normal)
            { writeListCheck( key.toUtf8().constData(), value, pFlags ); }
    /** Overload for writeEntry(const QString&, const QVariant&, WriteConfigFlags) */
    template <typename T>
        inline void writeEntry(const char *key, const QList<T> &value, WriteConfigFlags pFlags = Normal)
            { writeListCheck( key, value, pFlags ); }

    /**
     * Writes a list of strings to the config object, following XDG
     * desktop entry spec separator semantics
     *
     * @param pKey the key to write to
     * @param value the list to write
     * @param pFlags the flags to use when writing this entry
     *
     * @see writeEntry(), readXdgListEntry()
     */
    void writeXdgListEntry(const QString &pKey, const QStringList &value,
                           WriteConfigFlags pFlags = Normal);
    /** Overload for writeXdgListEntry(const QString&, const QStringList&, WriteConfigFlags) */
    void writeXdgListEntry(const char *pKey, const QStringList &value,
                           WriteConfigFlags pFlags = Normal);

    /**
     * Writes a file path to the configuration
     *
     * If the path is located under $HOME, the user's home directory
     * is replaced with $HOME in the persistent storage.
     * The path should therefore be read back with readPathEntry()
     *
     * @param pKey the key to write to
     * @param path the path to write
     * @param pFlags the flags to use when writing this entry
     *
     * @see writeEntry(), readPathEntry()
     */
    void writePathEntry(const QString &pKey, const QString &path,
                        WriteConfigFlags pFlags = Normal);
    /** Overload for writePathEntry(const QString&, const QString&, WriteConfigFlags) */
    void writePathEntry(const char *pKey, const QString &path,
                        WriteConfigFlags pFlags = Normal);

    /**
     * Writes a list of paths to the configuration
     *
     * If any of the paths are located under $HOME, the user's home directory
     * is replaced with $HOME in the persistent storage.
     * The paths should therefore be read back with readPathEntry()
     *
     * @param pKey the key to write to
     * @param value the list to write
     * @param pFlags the flags to use when writing this entry
     *
     * @see writeEntry(), readPathEntry()
     */
    void writePathEntry(const QString &pKey, const QStringList &value,
                        WriteConfigFlags pFlags = Normal);
    /** Overload for writePathEntry(const QString&, const QStringList&, WriteConfigFlags) */
    void writePathEntry(const char *pKey, const QStringList &value,
                        WriteConfigFlags pFlags = Normal);

    /**
     * Deletes the entry specified by @p pKey in the current group
     *
     * This also hides system wide defaults.
     *
     * @param pKey the key to delete
     * @param pFlags the flags to use when deleting this entry
     *
     * @see deleteGroup(), readEntry(), writeEntry()
     */
    void deleteEntry(const QString &pKey, WriteConfigFlags pFlags = Normal);
    /** Overload for deleteEntry(const QString&, WriteConfigFlags) */
    void deleteEntry(const char *pKey, WriteConfigFlags pFlags = Normal);

    /**
     * Checks whether the key has an entry in this group
     *
     * Use this to determine if a key is not specified for the current
     * group (hasKey() returns false).
     *
     * If this returns @c false for a key, readEntry() (and its variants)
     * will return the default value passed to them.
     *
     * @param key the key to search for
     * @return @c true if the key is defined in this group by any of the
     *         configuration sources, @c false otherwise
     *
     * @see readEntry()
     */
    bool hasKey(const QString &key) const;
    /** Overload for hasKey(const QString&) const */
    bool hasKey(const char *key) const;

    /**
     * Whether this group may be changed
     *
     * @return @c false if the group may be changed, @c true otherwise
     */
    bool isImmutable() const;

    /**
     * Checks if it is possible to change the given entry
     *
     * If isImmutable() returns @c true, then this method will return
     * @c true for all inputs.
     *
     * @param key the key to check
     * @return @c false if the key may be changed using this configuration
     *         group object, @c true otherwise
     */
    bool isEntryImmutable(const QString &key) const;
    /** Overload for isEntryImmutable(const QString&) const */
    bool isEntryImmutable(const char *key) const;

    /**
     * Reverts an entry to the default settings.
     *
     * Reverts the entry with key @p key in the current group in the
     * application specific config file to either the system wide (default)
     * value or the value specified in the global KDE config file.
     *
     * To revert entries in the global KDE config file, the global KDE config
     * file should be opened explicitly in a separate config object.
     *
     * @note This is @em not the same as deleting the key, as instead the
     * global setting will be copied to the configuration file that this
     * object manipulates.
     *
     * @param key The key of the entry to revert.
     */
    void revertToDefault(const QString &key);
    /** Overload for revertToDefault(const QString&) */
    void revertToDefault(const char* key);

    /**
     * Whether a default is specified for an entry in either the
     * system wide configuration file or the global KDE config file
     *
     * If an application computes a default value at runtime for
     * a certain entry, e.g. like:
     * \code
     * QColor computedDefault = qApp->palette().color(QPalette::Active, QPalette::Text)
     * QColor color = config->readEntry(key, computedDefault);
     * \endcode
     * then it may wish to make the following check before
     * writing back changes:
     * \code
     * if ( (value == computedDefault) && !config->hasDefault(key) )
     *    config->revertToDefault(key)
     * else
     *    config->writeEntry(key, value)
     * \endcode
     *
     * This ensures that as long as the entry is not modified to differ from
     * the computed default, the application will keep using the computed default
     * and will follow changes the computed default makes over time.
     *
     * @param key the key of the entry to check
     * @return @c true if the global or system settings files specify a default
     *          for @p key in this group, @c false otherwise
     */
    bool hasDefault(const QString &key) const;
    /** Overload for hasDefault(const QString&) const */
    bool hasDefault(const char *key) const;

    /**
     * Returns a map (tree) of entries for all entries in this group
     *
     * Only the actual entry string is returned, none of the
     * other internal data should be included.
     *
     * @return a map of entries in this group, indexed by key
     */
    QMap<QString, QString> entryMap() const;

protected:
    bool hasGroupImpl(const QByteArray &group) const;
    KConfigGroup groupImpl(const QByteArray &b);
    const KConfigGroup groupImpl(const QByteArray &b) const;
    void deleteGroupImpl(const QByteArray &group, WriteConfigFlags flags);
    bool isGroupImmutableImpl(const QByteArray &aGroup) const;

private:
    QExplicitlySharedDataPointer<KConfigGroupPrivate> d;

    template<typename T>
    inline T readCheck(const char *key, const T &defaultValue) const;

    template<typename T>
    inline QList<T> readListCheck(const char *key, const QList<T> &defaultValue) const;

    template<typename T>
    inline void writeCheck(const char *key, const T &value, WriteConfigFlags pFlags);

    template<typename T>
    inline void writeListCheck(const char *key, const QList<T> &value, WriteConfigFlags pFlags);

    friend class KConfigGroupPrivate;

    /**
     * Return the data in @p value converted to a QVariant
     *
     * @param pKey the name of the entry being converted, this is only used for error
     * reporting
     * @param value the UTF-8 data to be converted
     * @param aDefault the default value if @p pKey is not found
     * @return @p value converted to QVariant, or @p aDefault if @p value is invalid or cannot be converted.
     */
    static QVariant convertToQVariant(const char *pKey, const QByteArray &value, const QVariant &aDefault);
    friend class KServicePrivate; // XXX yeah, ugly^5
};

#define KCONFIGGROUP_ENUMERATOR_ERROR(ENUM) \
"The Qt MetaObject system does not seem to know about \"" ENUM \
"\" please use Q_ENUMS or Q_FLAGS to register it."

/**
 * To add support for your own enums in KConfig, you can declare them with Q_ENUMS()
 * in a QObject subclass (which will make moc generate the code to turn the
 * enum into a string and vice-versa), and then (in the cpp code)
 * use the macro
 * <code>KCONFIGGROUP_DECLARE_ENUM_QOBJECT(MyClass, MyEnum)</code>
 *
 * After that, you can use readEntry(group, key, value) and writeEntry(group, key, value[, flags]).
 * Note that those are global functions, NOT member functions of KConfigGroup.
 *
 */
#define KCONFIGGROUP_DECLARE_ENUM_QOBJECT(Class, Enum)                     \
inline Class::Enum readEntry(const KConfigGroup& group, const char* key, const Class::Enum& def) \
{                                                                          \
const QMetaObject* M_obj = &Class::staticMetaObject;                       \
const int M_index = M_obj->indexOfEnumerator(#Enum);                       \
kFatal(M_index == -1) << KCONFIGGROUP_ENUMERATOR_ERROR(#Enum) << endl;     \
const QMetaEnum M_enum = M_obj->enumerator(M_index);                       \
const QByteArray M_data = group.readEntry(key, QByteArray(M_enum.valueToKey(def)));\
return static_cast<Class::Enum>(M_enum.keyToValue(M_data.constData()));    \
}                                                                          \
inline void writeEntry(KConfigGroup& group, const char* key, const Class::Enum& value, KConfigBase::WriteConfigFlags flags = KConfigBase::Normal)\
{                                                                          \
const QMetaObject* M_obj = &Class::staticMetaObject;                       \
const int M_index = M_obj->indexOfEnumerator(#Enum);                       \
kFatal(M_index == -1) << KCONFIGGROUP_ENUMERATOR_ERROR(#Enum) << endl;     \
const QMetaEnum M_enum = M_obj->enumerator(M_index);                       \
group.writeEntry(key, QByteArray(M_enum.valueToKey(value)), flags);              \
}

/**
 * Similar to KCONFIGGROUP_DECLARE_ENUM_QOBJECT but for flags declared with Q_FLAGS()
 * (where multiple values can be set at the same time)
 */
#define KCONFIGGROUP_DECLARE_FLAGS_QOBJECT(Class, Flags)                    \
inline Class::Flags readEntry(const KConfigGroup& group, const char* key, const Class::Flags& def) \
{                                                                           \
const QMetaObject* M_obj = &Class::staticMetaObject;                        \
const int M_index = M_obj->indexOfEnumerator(#Flags);                       \
kFatal(M_index == -1) << KCONFIGGROUP_ENUMERATOR_ERROR(#Flags) << endl;     \
const QMetaEnum M_enum = M_obj->enumerator(M_index);                        \
const QByteArray M_data = group.readEntry(key, QByteArray(M_enum.valueToKeys(def)));\
return static_cast<Class::Flags>(M_enum.keysToValue(M_data.constData()));   \
}                                                                           \
inline void writeEntry(KConfigGroup& group, const char* key, const Class::Flags& value, KConfigBase::WriteConfigFlags flags = KConfigBase::Normal)\
{                                                                           \
const QMetaObject* M_obj = &Class::staticMetaObject;                        \
const int M_index = M_obj->indexOfEnumerator(#Flags);                       \
kFatal(M_index == -1) << KCONFIGGROUP_ENUMERATOR_ERROR(#Flags) << endl;     \
const QMetaEnum M_enum = M_obj->enumerator(M_index);                        \
group.writeEntry(key, QByteArray(M_enum.valueToKeys(value)), flags);              \
}

#include "conversion_check.h"

template <typename T>
T KConfigGroup::readCheck(const char *key, const T &defaultValue) const
{
  ConversionCheck::to_QVariant<T>();
  return qvariant_cast<T>(readEntry(key, qVariantFromValue(defaultValue)));
}

template <typename T>
QList<T> KConfigGroup::readListCheck(const char *key, const QList<T> &defaultValue) const
{
  ConversionCheck::to_QVariant<T>();
  ConversionCheck::to_QString<T>();

  QVariantList data;

  Q_FOREACH(const T& value, defaultValue)
    data.append(qVariantFromValue(value));

  QList<T> list;
  Q_FOREACH (const QVariant &value, readEntry<QVariantList>(key, data)) {
    Q_ASSERT(qVariantCanConvert<T>(value));
    list.append(qvariant_cast<T>(value));
  }

  return list;
}

template <typename T>
void KConfigGroup::writeCheck(const char *key, const T &value,
                              WriteConfigFlags pFlags)
{
    ConversionCheck::to_QVariant<T>();
    writeEntry(key, qVariantFromValue(value), pFlags);
}

template <typename T>
void KConfigGroup::writeListCheck(const char *key, const QList<T> &list,
                                  WriteConfigFlags pFlags)
{
  ConversionCheck::to_QVariant<T>();
  ConversionCheck::to_QString<T>();
  QVariantList data;
  Q_FOREACH(const T &value, list) {
    data.append(qVariantFromValue(value));
  }

  writeEntry(key, data, pFlags);
}

#endif // KCONFIGGROUP_H