summaryrefslogtreecommitdiffstats
path: root/tdecore/tdeconfigskeleton.h
blob: d9424e9dfb3ff8098ea378cd721a7a75266d3d7e (plain)
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
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
1001
1002
1003
1004
1005
1006
1007
1008
1009
1010
1011
1012
1013
1014
1015
1016
1017
1018
1019
1020
1021
1022
1023
1024
1025
1026
1027
1028
1029
1030
1031
1032
1033
1034
1035
1036
1037
1038
1039
1040
1041
1042
1043
1044
1045
1046
1047
1048
1049
1050
1051
1052
1053
1054
1055
1056
1057
1058
1059
1060
1061
1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
1076
1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
1110
1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
1151
1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
1168
1169
1170
1171
1172
1173
1174
1175
1176
1177
1178
1179
1180
1181
1182
1183
1184
1185
1186
1187
1188
1189
1190
1191
1192
1193
1194
1195
1196
1197
1198
1199
1200
1201
1202
1203
1204
1205
1206
1207
1208
1209
1210
1211
1212
1213
1214
1215
1216
1217
1218
1219
1220
1221
1222
1223
1224
1225
1226
1227
1228
1229
1230
/*
 * This file is part of KDE.
 * 
 * Copyright (c) 2001,2002,2003 Cornelius Schumacher <schumacher@kde.org>
 * Copyright (c) 2003 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 _KCONFIGSKELETON_H
#define _KCONFIGSKELETON_H

#include <tqcolor.h>
#include <tqdatetime.h>
#include <tqfont.h>
#include <tqpoint.h>
#include <tqptrlist.h>
#include <tqdict.h>
#include <tqrect.h>
#include <tqsize.h>
#include <tqstringlist.h>
#include <tqvariant.h>
#include <tdeconfig.h>
#include <kglobalsettings.h>

  /**
   * @short Class for storing a preferences setting
   * @author Cornelius Schumacher
   * @see TDEConfigSkeleton
   * 
   * This class represents one preferences setting as used by @ref TDEConfigSkeleton.
   * Subclasses of TDEConfigSkeletonItem implement storage functions for a certain type of
   * setting. Normally you don't have to use this class directly. Use the special
   * addItem() functions of TDEConfigSkeleton instead. If you subclass this class you will
   * have to register instances with the function TDEConfigSkeleton::addItem().
   */
  class TDECORE_EXPORT TDEConfigSkeletonItem
  {
  public:
    typedef TQValueList < TDEConfigSkeletonItem * >List;
    typedef TQDict < TDEConfigSkeletonItem > Dict;
    typedef TQDictIterator < TDEConfigSkeletonItem > DictIterator;

    /**
     * Constructor.
     * 
     * @param group Config file group.
     * @param key Config file key.
     */
    TDEConfigSkeletonItem(const TQString & group, const TQString & key)
      :mGroup(group),mKey(key), mIsImmutable(true)
    {
    }

    /**
     * Destructor.
     */
    virtual ~TDEConfigSkeletonItem()
    {
    }

    /**
     * Set config file group.
     */
    void setGroup( const TQString &group )
    {
      mGroup = group;
    }

    /**
     * Return config file group.
     */
    TQString group() const
    {
      return mGroup;
    }

    /**
     * Set config file key.
     */
    void setKey( const TQString &key )
    {
      mKey = key;
    }
    
    /**
     * Return config file key.
     */
    TQString key() const
    {
      return mKey;
    }

    /**
     * Set internal name of entry.
     */
    void setName(const TQString &name)
    {
      mName = name;
    }

    /**
     * Return internal name of entry.
     */
    TQString name() const
    {
      return mName;
    }

    /**
      Set label providing a translated one-line description of the item.
    */
    void setLabel( const TQString &l )
    {
      mLabel = l;
    }
    
    /**
      Return label of item. See setLabel().
    */
    TQString label() const
    {
      return mLabel;
    }

    /**
      Set WhatsThis description og item.
    */
    void setWhatsThis( const TQString &w )
    {
      mWhatsThis = w;
    }
    
    /**
      Return WhatsThis description of item. See setWhatsThis().
    */
    TQString whatsThis() const
    {
      return mWhatsThis;
    }

    /**
     * This function is called by @ref TDEConfigSkeleton to read the value for this setting
     * from a config file.
     * value.
     */
    virtual void readConfig(TDEConfig *) = 0;

    /**
     * This function is called by @ref TDEConfigSkeleton to write the value of this setting
     * to a config file.
     */
    virtual void writeConfig(TDEConfig *) = 0;

    /**
     * Read global default value.
     */
    virtual void readDefault(TDEConfig *) = 0;

    /**
     * Set item to @p p
     */
    virtual void setProperty(const TQVariant &p) = 0;
    
    /**
     * Return item as property
     */
    virtual TQVariant property() const = 0;

    /**
     * Return minimum value of item or invalid if not specified
     */
    virtual TQVariant minValue() const { return TQVariant(); }

    /**
     * Return maximum value of item or invalid if not specified
     */
    virtual TQVariant maxValue() const { return TQVariant(); }

    /**
      Sets the current value to the default value.
    */
    virtual void setDefault() = 0;

    /**
     * Exchanges the current value with the default value
     * Used by TDEConfigSkeleton::useDefaults(bool);
     */
    virtual void swapDefault() = 0;

    /**
     * Return if the entry can be modified.
     */
    bool isImmutable() const
    {
      return mIsImmutable;
    }

  protected:
    /**
     * sets mIsImmutable to true if mKey in config is immutable
     * @param config TDEConfig to check if mKey is immutable in
     */
    void readImmutability(TDEConfig *config);

    TQString mGroup;
    TQString mKey;
    TQString mName;

  private:
    bool mIsImmutable;

    TQString mLabel;
    TQString mWhatsThis;
  };


template < typename T > class TDEConfigSkeletonGenericItem:public TDEConfigSkeletonItem
  {
  public:
    TDEConfigSkeletonGenericItem(const TQString & group, const TQString & key, T & reference,
                T defaultValue)
      : TDEConfigSkeletonItem(group, key), mReference(reference),
        mDefault(defaultValue), mLoadedValue(defaultValue)
    {
    }

    /**
     * Set value of this TDEConfigSkeletonItem.
     */
    void setValue(const T & v)
    {
      mReference = v;
    }

    /**
     * Return value of this TDEConfigSkeletonItem.
     */
    T & value()
    {
      return mReference;
    }

    /**
     * Return const value of this TDEConfigSkeletonItem.
     */
    const T & value() const
    {
      return mReference;
    }

    /**
      Set default value for this item.
    */
    virtual void setDefaultValue( const T &v )
    {
      mDefault = v;
    }

    virtual void setDefault()
    {
      mReference = mDefault;
    }

    virtual void writeConfig(TDEConfig * config)
    {
      if ( mReference != mLoadedValue ) // Is this needed?
      {
        config->setGroup(mGroup);
        if ((mDefault == mReference) && !config->hasDefault( mKey))
          config->revertToDefault( mKey );
        else
          config->writeEntry(mKey, mReference);
      }
    }

    void readDefault(TDEConfig * config)
    {
      config->setReadDefaults(true);
      readConfig(config);
      config->setReadDefaults(false);
      mDefault = mReference;
    }

    void swapDefault()
    {
      T tmp = mReference;
      mReference = mDefault;
      mDefault = tmp;
    }

  protected:
    T & mReference;
    T mDefault;
    T mLoadedValue;
  };

  /**
   * @short Class for handling preferences settings for an application.
   * @author Cornelius Schumacher
   * @see TDEConfigSkeletonItem
   * 
   * This class provides an interface to preferences settings. Preferences items
   * can be registered by the addItem() function corresponding to the data type of
   * the seetting. TDEConfigSkeleton then handles reading and writing of config files and
   * setting of default values.
   * 
   * Normally you will subclass TDEConfigSkeleton, add data members for the preferences
   * settings and register the members in the constructor of the subclass.
   * 
   * Example:
   * \code
   * class MyPrefs : public TDEConfigSkeleton
   * {
   *   public:
   *     MyPrefs()
   *     {
   *       setCurrentGroup("MyGroup");
   *       addItemBool("MySetting1",mMyBool,false);
   *       addItemColor("MySetting2",mMyColor,TQColor(1,2,3));
   * 
   *       setCurrentGroup("MyOtherGroup");
   *       addItemFont("MySetting3",mMyFont,TQFont("helvetica",12));
   *     }
   * 
   *     bool mMyBool;
   *     TQColor mMyColor;
   *     TQFont mMyFont;
   * }
   * \endcode
   * 
   * It might be convenient in many cases to make this subclass of TDEConfigSkeleton a
   * singleton for global access from all over the application without passing
   * references to the TDEConfigSkeleton object around.
   * 
   * You can write the data to the configuration file by calling @ref writeConfig()
   * and read the data from the configuration file by calling @ref readConfig().
   * 
   * If you have items, which are not covered by the existing addItem() functions
   * you can add customized code for reading, writing and default setting by
   * implementing the functions @ref usrUseDefaults(), @ref usrReadConfig() and
   * @ref usrWriteConfig().
   * 
   * Internally preferences settings are stored in instances of subclasses of
   * @ref TDEConfigSkeletonItem. You can also add TDEConfigSkeletonItem subclasses 
   * for your own types and call the generic @ref addItem() to register them.
   *
   * In many cases you don't have to write the specific TDEConfigSkeleton
   * subclasses yourself, but you can use \ref tdeconfig_compiler to automatically
   * generate the C++ code from an XML description of the configuration options.
   */
class TDECORE_EXPORT TDEConfigSkeleton
{
public:

  /**
   * Class for handling a string preferences item.
   */
  class TDECORE_EXPORT ItemString:public TDEConfigSkeletonGenericItem < TQString >
  {
  public:
    enum Type { Normal, Password, Path };

    ItemString(const TQString & group, const TQString & key,
               TQString & reference,
               const TQString & defaultValue = TQString::fromLatin1(""), // NOT TQString::null !!
               Type type = Normal);

    void writeConfig(TDEConfig * config);
    void readConfig(TDEConfig * config);
    void setProperty(const TQVariant & p);
    TQVariant property() const;

  private:
    Type mType;
  };

  /**
   * Class for handling a password preferences item.
   */
  class TDECORE_EXPORT ItemPassword:public ItemString
  {
  public:
    ItemPassword(const TQString & group, const TQString & key,
               TQString & reference,
               const TQString & defaultValue = TQString::fromLatin1("")); // NOT TQString::null !!
  };

  /**
   * Class for handling a path preferences item.
   */
  class TDECORE_EXPORT ItemPath:public ItemString
  {
  public:
    ItemPath(const TQString & group, const TQString & key,
             TQString & reference,
             const TQString & defaultValue = TQString::null);
  };


  /**
   * Class for handling a TQVariant preferences item.
   */
  class TDECORE_EXPORT ItemProperty:public TDEConfigSkeletonGenericItem < TQVariant >
  {
  public:
    ItemProperty(const TQString & group, const TQString & key,
                 TQVariant & reference, TQVariant defaultValue = 0);

    void readConfig(TDEConfig * config);
    void setProperty(const TQVariant & p);
    TQVariant property() const;
  };


  /**
   * Class for handling a bool preferences item.
   */
  class TDECORE_EXPORT ItemBool:public TDEConfigSkeletonGenericItem < bool >
  {
  public:
    ItemBool(const TQString & group, const TQString & key, bool & reference,
             bool defaultValue = true);

    void readConfig(TDEConfig * config);
    void setProperty(const TQVariant & p);
    TQVariant property() const;
  };


  /**
   * Class for handling an integer preferences item.
   */
  class TDECORE_EXPORT ItemInt:public TDEConfigSkeletonGenericItem < int >
  {
  public:
    ItemInt(const TQString & group, const TQString & key, int &reference,
            int defaultValue = 0);

    void readConfig(TDEConfig * config);
    void setProperty(const TQVariant & p);
    TQVariant property() const;
    TQVariant minValue() const;
    TQVariant maxValue() const;

    void setMinValue(int);
    void setMaxValue(int);
    
  private:  
    bool mHasMin : 1;
    bool mHasMax : 1;
    int mMin;
    int mMax;
  };

  /**
   * Class for handling an 64-bit integer preferences item.
   */
  class TDECORE_EXPORT ItemInt64:public TDEConfigSkeletonGenericItem < TQ_INT64 >
  {
  public:
    ItemInt64(const TQString & group, const TQString & key, TQ_INT64 &reference,
            TQ_INT64 defaultValue = 0);

    void readConfig(TDEConfig * config);
    void setProperty(const TQVariant & p);
    TQVariant property() const;

    TQVariant minValue() const;
    TQVariant maxValue() const;

    void setMinValue(TQ_INT64);
    void setMaxValue(TQ_INT64);
    
  private:  
    bool mHasMin : 1;
    bool mHasMax : 1;
    TQ_INT64 mMin;
    TQ_INT64 mMax;
  };

  /**
   * Class for handling enums.
   */
  class TDECORE_EXPORT ItemEnum:public ItemInt
  {
  public:
    struct Choice
    {
      TQString name;
      TQString label;
      TQString whatsThis;
    };

    ItemEnum(const TQString & group, const TQString & key, int &reference,
             const TQValueList<Choice> &choices, int defaultValue = 0);

    TQValueList<Choice> choices() const;

    void readConfig(TDEConfig * config);
    void writeConfig(TDEConfig * config);

  private:
      TQValueList<Choice> mChoices;
  };


  /**
   * Class for handling an unsingend integer preferences item.
   */
  class TDECORE_EXPORT ItemUInt:public TDEConfigSkeletonGenericItem < unsigned int >
  {
  public:
    ItemUInt(const TQString & group, const TQString & key,
             unsigned int &reference, unsigned int defaultValue = 0);

    void readConfig(TDEConfig * config);
    void setProperty(const TQVariant & p);
    TQVariant property() const;
    TQVariant minValue() const;
    TQVariant maxValue() const;

    void setMinValue(unsigned int);
    void setMaxValue(unsigned int);
    
  private:  
    bool mHasMin : 1;
    bool mHasMax : 1;
    unsigned int mMin;
    unsigned int mMax;
  };


  /**
   * Class for hanlding a long integer preferences item.
   */
  class TDECORE_EXPORT ItemLong:public TDEConfigSkeletonGenericItem < long >
  {
  public:
    ItemLong(const TQString & group, const TQString & key, long &reference,
             long defaultValue = 0);

    void readConfig(TDEConfig * config);
    void setProperty(const TQVariant & p);
    TQVariant property() const;
    TQVariant minValue() const;
    TQVariant maxValue() const;

    void setMinValue(long);
    void setMaxValue(long);
    
  private:  
    bool mHasMin : 1;
    bool mHasMax : 1;
    long mMin;
    long mMax;
  };


  /**
   * Class for handling an unsigned long integer preferences item.
   */
  class TDECORE_EXPORT ItemULong:public TDEConfigSkeletonGenericItem < unsigned long >
  {
  public:
    ItemULong(const TQString & group, const TQString & key,
              unsigned long &reference, unsigned long defaultValue = 0);

    void readConfig(TDEConfig * config);
    void setProperty(const TQVariant & p);
    TQVariant property() const;
    TQVariant minValue() const;
    TQVariant maxValue() const;

    void setMinValue(unsigned long);
    void setMaxValue(unsigned long);
    
  private:  
    bool mHasMin : 1;
    bool mHasMax : 1;
    unsigned long mMin;
    unsigned long mMax;
  };

  /**
   * Class for handling unsigned 64-bit integer preferences item.
   */
  class TDECORE_EXPORT ItemUInt64:public TDEConfigSkeletonGenericItem < TQ_UINT64 >
  {
  public:
    ItemUInt64(const TQString & group, const TQString & key, TQ_UINT64 &reference,
            TQ_UINT64 defaultValue = 0);

    void readConfig(TDEConfig * config);
    void setProperty(const TQVariant & p);
    TQVariant property() const;

    TQVariant minValue() const;
    TQVariant maxValue() const;

    void setMinValue(TQ_UINT64);
    void setMaxValue(TQ_UINT64);
    
  private:  
    bool mHasMin : 1;
    bool mHasMax : 1;
    TQ_UINT64 mMin;
    TQ_UINT64 mMax;
  };

  /**
   * Class for handling a floating point preference item.
   */
  class TDECORE_EXPORT ItemDouble:public TDEConfigSkeletonGenericItem < double >
  {
  public:
    ItemDouble(const TQString & group, const TQString & key,
               double &reference, double defaultValue = 0);

    void readConfig(TDEConfig * config);
    void setProperty(const TQVariant & p);
    TQVariant property() const;
    TQVariant minValue() const;
    TQVariant maxValue() const;

    void setMinValue(double);
    void setMaxValue(double);
    
  private:  
    bool mHasMin : 1;
    bool mHasMax : 1;
    double mMin;
    double mMax;
  };


  /**
   * Class for handling a color preferences item.
   */
  class TDECORE_EXPORT ItemColor:public TDEConfigSkeletonGenericItem < TQColor >
  {
  public:
    ItemColor(const TQString & group, const TQString & key,
              TQColor & reference,
              const TQColor & defaultValue = TQColor(128, 128, 128));

    void readConfig(TDEConfig * config);
    void setProperty(const TQVariant & p);
    TQVariant property() const;
  };


  /**
   * Class for handling a font preferences item.
   */
  class TDECORE_EXPORT ItemFont:public TDEConfigSkeletonGenericItem < TQFont >
  {
  public:
    ItemFont(const TQString & group, const TQString & key, TQFont & reference,
             const TQFont & defaultValue = TDEGlobalSettings::generalFont());

    void readConfig(TDEConfig * config);
    void setProperty(const TQVariant & p);
    TQVariant property() const;
  };


  /**
   * Class for handling a TQRect preferences item.
   */
  class TDECORE_EXPORT ItemRect:public TDEConfigSkeletonGenericItem < TQRect >
  {
  public:
    ItemRect(const TQString & group, const TQString & key, TQRect & reference,
             const TQRect & defaultValue = TQRect());

    void readConfig(TDEConfig * config);
    void setProperty(const TQVariant & p);
    TQVariant property() const;
  };


  /**
   * Class for handling a TQPoint preferences item.
   */
  class TDECORE_EXPORT ItemPoint:public TDEConfigSkeletonGenericItem < TQPoint >
  {
  public:
    ItemPoint(const TQString & group, const TQString & key, TQPoint & reference,
              const TQPoint & defaultValue = TQPoint());

    void readConfig(TDEConfig * config);
    void setProperty(const TQVariant & p);
    TQVariant property() const;
  };


  /**
   * Class for handling a TQSize preferences item.
   */
  class TDECORE_EXPORT ItemSize:public TDEConfigSkeletonGenericItem < TQSize >
  {
  public:
    ItemSize(const TQString & group, const TQString & key, TQSize & reference,
             const TQSize & defaultValue = TQSize());

    void readConfig(TDEConfig * config);
    void setProperty(const TQVariant & p);
    TQVariant property() const;
  };


  /**
   * Class for handling a TQDateTime preferences item.
   */
  class TDECORE_EXPORT ItemDateTime:public TDEConfigSkeletonGenericItem < TQDateTime >
  {
  public:
    ItemDateTime(const TQString & group, const TQString & key,
                 TQDateTime & reference,
                 const TQDateTime & defaultValue = TQDateTime());

    void readConfig(TDEConfig * config);
    void setProperty(const TQVariant & p);
    TQVariant property() const;
  };


  /**
   * Class for handling a string list preferences item.
   */
  class TDECORE_EXPORT ItemStringList:public TDEConfigSkeletonGenericItem < TQStringList >
  {
  public:
    ItemStringList(const TQString & group, const TQString & key,
                   TQStringList & reference,
                   const TQStringList & defaultValue = TQStringList());

    void readConfig(TDEConfig * config);
    void setProperty(const TQVariant & p);
    TQVariant property() const;
  };


  /**
   * Class for handling a path list preferences item.
   */
  class TDECORE_EXPORT ItemPathList:public ItemStringList
  {
  public:
    ItemPathList(const TQString & group, const TQString & key,
                   TQStringList & reference,
                   const TQStringList & defaultValue = TQStringList());

    void readConfig(TDEConfig * config);
    void writeConfig(TDEConfig * config);
  };


  /**
   * Class for handling an integer list preferences item.
   */
  class TDECORE_EXPORT ItemIntList:public TDEConfigSkeletonGenericItem < TQValueList < int > >
  {
  public:
    ItemIntList(const TQString & group, const TQString & key,
                TQValueList < int >&reference,
                const TQValueList < int >&defaultValue = TQValueList < int >());

    void readConfig(TDEConfig * config);
    void setProperty(const TQVariant & p);
    TQVariant property() const;
  };


public:
  /**
   * Constructor.
   * 
   * @param configname name of config file. If no name is given, the default
   * config file as returned by kapp()->config() is used.
   */
  TDEConfigSkeleton(const TQString & configname = TQString::null);

  /**
   * Constructor.
   * 
   * @param config configuration object to use.
   */
  TDEConfigSkeleton(KSharedConfig::Ptr config);

  /**
   * Destructor
   */
    virtual ~ TDEConfigSkeleton();

  /**
    Set all registered items to their default values.
  */
  void setDefaults();

  /**
   * Read preferences from config file. All registered items are set to the
   * values read from disk.
   */
  void readConfig();

  /**
   * Write preferences to config file. The values of all registered items are
   * written to disk.
   */
  void writeConfig();

  /**
   * Set the config file group for subsequent addItem() calls. It is valid
   * until setCurrentGroup() is called with a new argument. Call this before
   * you add any items. The default value is "No Group".
   */
  void setCurrentGroup(const TQString & group);

  /**
   * Returns the current group used for addItem() calls. 
   */
  TQString currentGroup() // ### KDE 4.0: make const
  {
    return mCurrentGroup;
  }

  /**
   * Register a custom @ref TDEConfigSkeletonItem with a given name. If the name
   * parameter is null, take the name from TDEConfigSkeletonItem::key().
   * Note that all names must be unique but that multiple entries can have
   * the same key if they reside in different groups. 
   */
  void addItem(TDEConfigSkeletonItem *, const TQString & name = TQString::null );

  /**
   * Register an item of type TQString.
   * 
   * @param name Name used to indentify this setting. Names must be unique.
   * @param reference Pointer to the variable, which is set by readConfig()
   * calls and read by writeConfig() calls.
   * @param defaultValue Default value, which is used when the config file 
   * does not yet contain the key of this item.
   * @param key Key used in config file. If key is null, name is used as key.
   * @return The created item
   */
  ItemString *addItemString(const TQString & name, TQString & reference,
                            const TQString & defaultValue = TQString::fromLatin1(""), // NOT TQString::null !!
                            const TQString & key = TQString::null);

  /**
   * Register a password item of type TQString. The string value is written 
   * encrypted to the config file. Note that the current encryption scheme 
   * is very weak.
   * 
   * @param name Name used to indentify this setting. Names must be unique.
   * @param reference Pointer to the variable, which is set by readConfig()
   * calls and read by writeConfig() calls.
   * @param defaultValue Default value, which is used when the config file
   * does not yet contain the key of this item.
   * @param key Key used in config file. If key is null, name is used as key.
   * @return The created item
   */
  ItemPassword *addItemPassword(const TQString & name, TQString & reference,
                              const TQString & defaultValue = TQString::fromLatin1(""),
                              const TQString & key = TQString::null);

  /**
   * Register a path item of type TQString. The string value is interpreted
   * as a path. This means, dollar expension is activated for this value, so
   * that e.g. $HOME gets expanded. 
   * 
   * @param name Name used to indentify this setting. Names must be unique.
   * @param reference Pointer to the variable, which is set by readConfig()
   * calls and read by writeConfig() calls.
   * @param defaultValue Default value, which is used when the config file
   * does not yet contain the key of this item.
   * @param key Key used in config file. If key is null, name is used as key.
   * @return The created item
   */
  ItemPath *addItemPath(const TQString & name, TQString & reference,
                          const TQString & defaultValue = TQString::fromLatin1(""),
                          const TQString & key = TQString::null);

  /**
   * Register a property item of type TQVariant. Note that only the following
   * TQVariant types are allowed: String, StringList, Font, Point, Rect, Size,
   * Color, Int, UInt, Bool, Double, DateTime and Date.
   * 
   * @param name Name used to indentify this setting. Names must be unique.
   * @param reference Pointer to the variable, which is set by readConfig()
   * calls and read by writeConfig() calls.
   * @param defaultValue Default value, which is used when the config file
   * does not yet contain the key of this item.
   * @param key Key used in config file. If key is null, name is used as key.
   * @return The created item
   */
  ItemProperty *addItemProperty(const TQString & name, TQVariant & reference,
                                const TQVariant & defaultValue = TQVariant(),
                                const TQString & key = TQString::null);
  /**
   * Register an item of type bool.
   * 
   * @param name Name used to indentify this setting. Names must be unique.
   * @param reference Pointer to the variable, which is set by readConfig()
   * calls and read by writeConfig() calls.
   * @param defaultValue Default value, which is used when the config file
   * does not yet contain the key of this item.
   * @param key Key used in config file. If key is null, name is used as key.
   * @return The created item
   */
  ItemBool *addItemBool(const TQString & name, bool & reference,
                        bool defaultValue = false,
                        const TQString & key = TQString::null);

  /**
   * Register an item of type int.
   * 
   * @param name Name used to indentify this setting. Names must be unique.
   * @param reference Pointer to the variable, which is set by readConfig()
   * calls and read by writeConfig() calls.
   * @param defaultValue Default value, which is used when the config file
   * does not yet contain the key of this item.
   * @param key Key used in config file. If key is null, name is used as key.
   * @return The created item
   */
  ItemInt *addItemInt(const TQString & name, int &reference, int defaultValue = 0,
                      const TQString & key = TQString::null);

  /**
   * Register an item of type unsigned int.
   * 
   * @param name Name used to indentify this setting. Names must be unique.
   * @param reference Pointer to the variable, which is set by readConfig()
   * calls and read by writeConfig() calls.
   * @param defaultValue Default value, which is used when the config file
   * does not yet contain the key of this item.
   * @param key Key used in config file. If key is null, name is used as key.
   * @return The created item
   */
  ItemUInt *addItemUInt(const TQString & name, unsigned int &reference,
                        unsigned int defaultValue = 0,
                        const TQString & key = TQString::null);

  /**
   * Register an item of type long.
   * 
   * @param name Name used to indentify this setting. Names must be unique.
   * @param reference Pointer to the variable, which is set by readConfig()
   * calls and read by writeConfig() calls.
   * @param defaultValue Default value, which is used when the config file
   * does not yet contain the key of this item.
   * @param key Key used in config file. If key is null, name is used as key.
   * @return The created item
   */
  ItemLong *addItemLong(const TQString & name, long &reference,
                        long defaultValue = 0,
                        const TQString & key = TQString::null);

  /**
   * Register an item of type unsigned long.
   * 
   * @param name Name used to indentify this setting. Names must be unique.
   * @param reference Pointer to the variable, which is set by readConfig()
   * calls and read by writeConfig() calls.
   * @param defaultValue Default value, which is used when the config file
   * does not yet contain the key of this item.
   * @param key Key used in config file. If key is null, name is used as key.
   * @return The created item
   */
  ItemULong *addItemULong(const TQString & name, unsigned long &reference,
                          unsigned long defaultValue = 0,
                          const TQString & key = TQString::null);

  /**
   * Register an item of type TQ_INT64.
   * 
   * @param name Name used to indentify this setting. Names must be unique.
   * @param reference Pointer to the variable, which is set by readConfig()
   * calls and read by writeConfig() calls.
   * @param defaultValue Default value, which is used when the config file
   * does not yet contain the key of this item.
   * @param key Key used in config file. If key is null, name is used as key.
   * @return The created item
   */
  ItemInt64 *addItemInt64(const TQString & name, TQ_INT64 &reference,
                          TQ_INT64 defaultValue = 0,
                          const TQString & key = TQString::null);

  /**
   * Register an item of type TQ_UINT64
   * 
   * @param name Name used to indentify this setting. Names must be unique.
   * @param reference Pointer to the variable, which is set by readConfig()
   * calls and read by writeConfig() calls.
   * @param defaultValue Default value, which is used when the config file
   * does not yet contain the key of this item.
   * @param key Key used in config file. If key is null, name is used as key.
   * @return The created item
   */
  ItemUInt64 *addItemUInt64(const TQString & name, TQ_UINT64 &reference,
                            TQ_UINT64 defaultValue = 0,
                            const TQString & key = TQString::null);

  /**
   * Register an item of type double.
   * 
   * @param name Name used to indentify this setting. Names must be unique.
   * @param reference Pointer to the variable, which is set by readConfig()
   * calls and read by writeConfig() calls.
   * @param defaultValue Default value, which is used when the config file
   * does not yet contain the key of this item.
   * @param key Key used in config file. If key is null, name is used as key.
   * @return The created item
   */
  ItemDouble *addItemDouble(const TQString & name, double &reference,
                            double defaultValue = 0.0,
                            const TQString & key = TQString::null);

  /**
   * Register an item of type TQColor.
   * 
   * @param name Name used to indentify this setting. Names must be unique.
   * @param reference Pointer to the variable, which is set by readConfig()
   * calls and read by writeConfig() calls.
   * @param defaultValue Default value, which is used when the config file
   * does not yet contain the key of this item.
   * @param key Key used in config file. If key is null, name is used as key.
   * @return The created item
   */
  ItemColor *addItemColor(const TQString & name, TQColor & reference,
                          const TQColor & defaultValue = TQColor(128, 128, 128),
                          const TQString & key = TQString::null);

  /**
   * Register an item of type TQFont.
   * 
   * @param name Name used to indentify this setting. Names must be unique.
   * @param reference Pointer to the variable, which is set by readConfig()
   * calls and read by writeConfig() calls.
   * @param defaultValue Default value, which is used when the config file
   * does not yet contain the key of this item.
   * @param key Key used in config file. If key is null, name is used as key.
   * @return The created item
   */
  ItemFont *addItemFont(const TQString & name, TQFont & reference,
                        const TQFont & defaultValue =
                        TDEGlobalSettings::generalFont(),
                        const TQString & key = TQString::null);

  /**
   * Register an item of type TQRect.
   * 
   * @param name Name used to indentify this setting. Names must be unique.
   * @param reference Pointer to the variable, which is set by readConfig()
   * calls and read by writeConfig() calls.
   * @param defaultValue Default value, which is used when the config file
   * does not yet contain the key of this item.
   * @param key Key used in config file. If key is null, name is used as key.
   * @return The created item
   */
  ItemRect *addItemRect(const TQString & name, TQRect & reference,
                        const TQRect & defaultValue = TQRect(),
                        const TQString & key = TQString::null);

  /**
   * Register an item of type TQPoint.
   * 
   * @param name Name used to indentify this setting. Names must be unique.
   * @param reference Pointer to the variable, which is set by readConfig()
   * calls and read by writeConfig() calls.
   * @param defaultValue Default value, which is used when the config file
   * does not yet contain the key of this item.
   * @param key Key used in config file. If key is null, name is used as key.
   * @return The created item
   */
  ItemPoint *addItemPoint(const TQString & name, TQPoint & reference,
                          const TQPoint & defaultValue = TQPoint(),
                          const TQString & key = TQString::null);

  /**
   * Register an item of type TQSize.
   * 
   * @param name Name used to indentify this setting. Names must be unique.
   * @param reference Pointer to the variable, which is set by readConfig()
   * calls and read by writeConfig() calls.
   * @param defaultValue Default value, which is used when the config file
   * does not yet contain the key of this item.
   * @param key Key used in config file. If key is null, name is used as key.
   * @return The created item
   */
  ItemSize *addItemSize(const TQString & name, TQSize & reference,
                        const TQSize & defaultValue = TQSize(),
                        const TQString & key = TQString::null);

  /**
   * Register an item of type TQDateTime.
   * 
   * @param name Name used to indentify this setting. Names must be unique.
   * @param reference Pointer to the variable, which is set by readConfig()
   * calls and read by writeConfig() calls.
   * @param defaultValue Default value, which is used when the config file
   * does not yet contain the key of this item.
   * @param key Key used in config file. If key is null, name is used as key.
   * @return The created item
   */
  ItemDateTime *addItemDateTime(const TQString & name, TQDateTime & reference,
                                const TQDateTime & defaultValue = TQDateTime(),
                                const TQString & key = TQString::null);

  /**
   * Register an item of type TQStringList.
   * 
   * @param name Name used to indentify this setting. Names must be unique.
   * @param reference Pointer to the variable, which is set by readConfig()
   * calls and read by writeConfig() calls.
   * @param defaultValue Default value, which is used when the config file
   * does not yet contain the key of this item.
   * @param key Key used in config file. If key is null, name is used as key.
   * @return The created item
   */
  ItemStringList *addItemStringList(const TQString & name, TQStringList & reference,
                                    const TQStringList & defaultValue = TQStringList(),
                                    const TQString & key = TQString::null);

  /**
   * Register an item of type TQValueList<int>.
   * 
   * @param name Name used to indentify this setting. Names must be unique.
   * @param reference Pointer to the variable, which is set by readConfig()
   * calls and read by writeConfig() calls.
   * @param defaultValue Default value, which is used when the config file
   * does not yet contain the key of this item.
   * @param key Key used in config file. If key is null, name is used as key.
   * @return The created item
   */
  ItemIntList *addItemIntList(const TQString & name, TQValueList < int >&reference,
                              const TQValueList < int >&defaultValue =
                              TQValueList < int >(),
                              const TQString & key = TQString::null);

  /**
   * Return the @ref TDEConfig object used for reading and writing the settings.
   */
  TDEConfig *config() const;

  /**
   * Return list of items managed by this TDEConfigSkeleton object.
   */
  TDEConfigSkeletonItem::List items() const
  {
    return mItems;
  }

  /**
   * Return whether a certain item is immutable
   */
  bool isImmutable(const TQString & name);

  /**
   * Lookup item by name
   */
  TDEConfigSkeletonItem * findItem(const TQString & name);

  /**
   * Indicate whether this object should reflect the actual
   * values or the default values.
   * @param b If true this object reflects the default values.
   * @return The state prior to this call
   */
  bool useDefaults(bool b);

protected:
  /**
   * Implemented by subclasses that use special defaults.
   * It should replace the default values with the actual
   * values and vice versa.
   */
  virtual void usrUseDefaults(bool)
  {
  }

  virtual void usrSetDefaults()
  {
  }

  /**
   * Implemented by subclasses that read special config values.
   */
  virtual void usrReadConfig()
  {
  }

  /**
   * Implemented by subclasses that write special config values.
   */
  virtual void usrWriteConfig()
  {
  }

private:
  TQString mCurrentGroup;

  KSharedConfig::Ptr mConfig; // pointer to TDEConfig object

  TDEConfigSkeletonItem::List mItems;
  TDEConfigSkeletonItem::Dict mItemDict;
  
  bool mUseDefaults;

  class Private;
  Private *d;

};

#endif