00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
#ifndef _KCONFIGSKELETON_H
00024
#define _KCONFIGSKELETON_H
00025
00026
#include <qcolor.h>
00027
#include <qdatetime.h>
00028
#include <qfont.h>
00029
#include <qpoint.h>
00030
#include <qptrlist.h>
00031
#include <qdict.h>
00032
#include <qrect.h>
00033
#include <qsize.h>
00034
#include <qstringlist.h>
00035
#include <qvariant.h>
00036
#include <kconfig.h>
00037
#include <kglobalsettings.h>
00038
00050 class KConfigSkeletonItem
00051 {
00052
public:
00053
typedef QValueList < KConfigSkeletonItem * >
List;
00054
typedef QDict < KConfigSkeletonItem >
Dict;
00055
typedef QDictIterator < KConfigSkeletonItem >
DictIterator;
00056
00063 KConfigSkeletonItem(
const QString & group,
const QString & key)
00064 :mGroup(group),mKey(key), mIsImmutable(true)
00065 {
00066 }
00067
00071 virtual ~KConfigSkeletonItem()
00072 {
00073 }
00074
00078 void setGroup(
const QString &group )
00079 {
00080 mGroup = group;
00081 }
00082
00086 QString group()
const
00087
{
00088
return mGroup;
00089 }
00090
00094 void setKey(
const QString &key )
00095 {
00096 mKey = key;
00097 }
00098
00102 QString key()
const
00103
{
00104
return mKey;
00105 }
00106
00110 void setName(
const QString &name)
00111 {
00112 mName = name;
00113 }
00114
00118 QString name()
const
00119
{
00120
return mName;
00121 }
00122
00126 void setLabel(
const QString &l )
00127 {
00128 mLabel = l;
00129 }
00130
00134 QString label()
const
00135
{
00136
return mLabel;
00137 }
00138
00142 void setWhatsThis(
const QString &w )
00143 {
00144 mWhatsThis = w;
00145 }
00146
00150 QString whatsThis()
const
00151
{
00152
return mWhatsThis;
00153 }
00154
00160
virtual void readConfig(
KConfig *) = 0;
00161
00166
virtual void writeConfig(
KConfig *) = 0;
00167
00171
virtual void readDefault(
KConfig *) = 0;
00172
00176
virtual void setProperty(
const QVariant &p) = 0;
00177
00181
virtual QVariant property() const = 0;
00182
00186 virtual
QVariant minValue()
const {
return QVariant(); }
00187
00191 virtual QVariant maxValue()
const {
return QVariant(); }
00192
00196
virtual void setDefault() = 0;
00197
00202
virtual void swapDefault() = 0;
00203
00207 bool isImmutable()
const
00208
{
00209
return mIsImmutable;
00210 }
00211
00212
protected:
00217
void readImmutability(
KConfig *config);
00218
00219
QString mGroup;
00220
QString mKey;
00221
QString mName;
00222
00223
private:
00224
bool mIsImmutable;
00225
00226
QString mLabel;
00227
QString mWhatsThis;
00228 };
00229
00230
00231
template <
typename T >
class KConfigSkeletonGenericItem:
public KConfigSkeletonItem
00232 {
00233
public:
00234 KConfigSkeletonGenericItem(
const QString & group,
const QString & key, T & reference,
00235 T defaultValue)
00236 :
KConfigSkeletonItem(group,
key), mReference(reference),
00237 mDefault(defaultValue), mLoadedValue(defaultValue)
00238 {
00239 }
00240
00244
void setValue(
const T & v)
00245 {
00246 mReference = v;
00247 }
00248
00252 T & value()
00253 {
00254
return mReference;
00255 }
00256
00260
const T & value()
const
00261
{
00262
return mReference;
00263 }
00264
00268
virtual void setDefaultValue(
const T &v )
00269 {
00270 mDefault = v;
00271 }
00272
00273
virtual void setDefault()
00274 {
00275 mReference = mDefault;
00276 }
00277
00278
virtual void writeConfig(
KConfig * config)
00279 {
00280
if ( mReference != mLoadedValue )
00281 {
00282 config->
setGroup(mGroup);
00283
if ((mDefault == mReference) && !config->
hasDefault( mKey))
00284 config->
revertToDefault( mKey );
00285
else
00286 config->
writeEntry(mKey, mReference);
00287 }
00288 }
00289
00290
void readDefault(
KConfig * config)
00291 {
00292 config->
setReadDefaults(
true);
00293
readConfig(config);
00294 config->
setReadDefaults(
false);
00295 mDefault = mReference;
00296 }
00297
00298
void swapDefault()
00299 {
00300 T tmp = mReference;
00301 mReference = mDefault;
00302 mDefault = tmp;
00303 }
00304
00305
protected:
00306 T & mReference;
00307 T mDefault;
00308 T mLoadedValue;
00309 };
00310
00365 class KConfigSkeleton
00366 {
00367
public:
00368
00372 class ItemString:
public KConfigSkeletonGenericItem < QString >
00373 {
00374
public:
00375
enum Type { Normal, Password, Path };
00376
00377
ItemString(
const QString & group,
const QString & key,
00378
QString & reference,
00379
const QString & defaultValue = QString::fromLatin1(
""),
00380 Type type = Normal);
00381
00382
void writeConfig(
KConfig * config);
00383
void readConfig(
KConfig * config);
00384
void setProperty(
const QVariant & p);
00385
QVariant property()
const;
00386
00387
private:
00388 Type mType;
00389 };
00390
00394 class ItemPassword:
public ItemString
00395 {
00396
public:
00397
ItemPassword(
const QString & group,
const QString & key,
00398
QString & reference,
00399
const QString & defaultValue = QString::fromLatin1(
""));
00400 };
00401
00405 class ItemPath:
public ItemString
00406 {
00407
public:
00408
ItemPath(
const QString & group,
const QString & key,
00409
QString & reference,
00410
const QString & defaultValue = QString::null);
00411 };
00412
00413
00417 class ItemProperty:
public KConfigSkeletonGenericItem < QVariant >
00418 {
00419
public:
00420
ItemProperty(
const QString & group,
const QString & key,
00421
QVariant & reference,
QVariant defaultValue = 0);
00422
00423
void readConfig(
KConfig * config);
00424
void setProperty(
const QVariant & p);
00425
QVariant property()
const;
00426 };
00427
00428
00432 class ItemBool:
public KConfigSkeletonGenericItem < bool >
00433 {
00434
public:
00435
ItemBool(
const QString & group,
const QString & key,
bool & reference,
00436
bool defaultValue =
true);
00437
00438
void readConfig(
KConfig * config);
00439
void setProperty(
const QVariant & p);
00440
QVariant property()
const;
00441 };
00442
00443
00447 class ItemInt:
public KConfigSkeletonGenericItem < int >
00448 {
00449
public:
00450
ItemInt(
const QString & group,
const QString & key,
int &reference,
00451
int defaultValue = 0);
00452
00453
void readConfig(
KConfig * config);
00454
void setProperty(
const QVariant & p);
00455
QVariant property()
const;
00456
QVariant minValue()
const;
00457
QVariant maxValue()
const;
00458
00459
void setMinValue(
int);
00460
void setMaxValue(
int);
00461
00462
private:
00463
bool mHasMin : 1;
00464
bool mHasMax : 1;
00465
int mMin;
00466
int mMax;
00467 };
00468
00472 class ItemInt64:
public KConfigSkeletonGenericItem < Q_INT64 >
00473 {
00474
public:
00475
ItemInt64(
const QString & group,
const QString & key, Q_INT64 &reference,
00476 Q_INT64 defaultValue = 0);
00477
00478
void readConfig(
KConfig * config);
00479
void setProperty(
const QVariant & p);
00480
QVariant property()
const;
00481
00482
QVariant minValue()
const;
00483
QVariant maxValue()
const;
00484
00485
void setMinValue(Q_INT64);
00486
void setMaxValue(Q_INT64);
00487
00488
private:
00489
bool mHasMin : 1;
00490
bool mHasMax : 1;
00491 Q_INT64 mMin;
00492 Q_INT64 mMax;
00493 };
00494
00498 class ItemEnum:
public ItemInt
00499 {
00500
public:
00501
struct Choice
00502 {
00503
QString name;
00504
QString label;
00505
QString whatsThis;
00506 };
00507
00508
ItemEnum(
const QString & group,
const QString & key,
int &reference,
00509
const QValueList<Choice> &choices,
int defaultValue = 0);
00510
00511
QValueList<Choice> choices()
const;
00512
00513
void readConfig(
KConfig * config);
00514
void writeConfig(
KConfig * config);
00515
00516
private:
00517
QValueList<Choice> mChoices;
00518 };
00519
00520
00524 class ItemUInt:
public KConfigSkeletonGenericItem < unsigned int >
00525 {
00526
public:
00527
ItemUInt(
const QString & group,
const QString & key,
00528
unsigned int &reference,
unsigned int defaultValue = 0);
00529
00530
void readConfig(
KConfig * config);
00531
void setProperty(
const QVariant & p);
00532
QVariant property()
const;
00533
QVariant minValue()
const;
00534
QVariant maxValue()
const;
00535
00536
void setMinValue(
unsigned int);
00537
void setMaxValue(
unsigned int);
00538
00539
private:
00540
bool mHasMin : 1;
00541
bool mHasMax : 1;
00542
unsigned int mMin;
00543
unsigned int mMax;
00544 };
00545
00546
00550 class ItemLong:
public KConfigSkeletonGenericItem < long >
00551 {
00552
public:
00553
ItemLong(
const QString & group,
const QString & key,
long &reference,
00554
long defaultValue = 0);
00555
00556
void readConfig(
KConfig * config);
00557
void setProperty(
const QVariant & p);
00558
QVariant property()
const;
00559
QVariant minValue()
const;
00560
QVariant maxValue()
const;
00561
00562
void setMinValue(
long);
00563
void setMaxValue(
long);
00564
00565
private:
00566
bool mHasMin : 1;
00567
bool mHasMax : 1;
00568
long mMin;
00569
long mMax;
00570 };
00571
00572
00576 class ItemULong:
public KConfigSkeletonGenericItem < unsigned long >
00577 {
00578
public:
00579
ItemULong(
const QString & group,
const QString & key,
00580
unsigned long &reference,
unsigned long defaultValue = 0);
00581
00582
void readConfig(
KConfig * config);
00583
void setProperty(
const QVariant & p);
00584
QVariant property()
const;
00585
QVariant minValue()
const;
00586
QVariant maxValue()
const;
00587
00588
void setMinValue(
unsigned long);
00589
void setMaxValue(
unsigned long);
00590
00591
private:
00592
bool mHasMin : 1;
00593
bool mHasMax : 1;
00594
unsigned long mMin;
00595
unsigned long mMax;
00596 };
00597
00601 class ItemUInt64:
public KConfigSkeletonGenericItem < Q_UINT64 >
00602 {
00603
public:
00604
ItemUInt64(
const QString & group,
const QString & key, Q_UINT64 &reference,
00605 Q_UINT64 defaultValue = 0);
00606
00607
void readConfig(
KConfig * config);
00608
void setProperty(
const QVariant & p);
00609
QVariant property()
const;
00610
00611
QVariant minValue()
const;
00612
QVariant maxValue()
const;
00613
00614
void setMinValue(Q_UINT64);
00615
void setMaxValue(Q_UINT64);
00616
00617
private:
00618
bool mHasMin : 1;
00619
bool mHasMax : 1;
00620 Q_UINT64 mMin;
00621 Q_UINT64 mMax;
00622 };
00623
00627 class ItemDouble:
public KConfigSkeletonGenericItem < double >
00628 {
00629
public:
00630
ItemDouble(
const QString & group,
const QString & key,
00631
double &reference,
double defaultValue = 0);
00632
00633
void readConfig(
KConfig * config);
00634
void setProperty(
const QVariant & p);
00635
QVariant property()
const;
00636
QVariant minValue()
const;
00637
QVariant maxValue()
const;
00638
00639
void setMinValue(
double);
00640
void setMaxValue(
double);
00641
00642
private:
00643
bool mHasMin : 1;
00644
bool mHasMax : 1;
00645
double mMin;
00646
double mMax;
00647 };
00648
00649
00653 class ItemColor:
public KConfigSkeletonGenericItem < QColor >
00654 {
00655
public:
00656
ItemColor(
const QString & group,
const QString & key,
00657
QColor & reference,
00658
const QColor & defaultValue =
QColor(128, 128, 128));
00659
00660
void readConfig(
KConfig * config);
00661
void setProperty(
const QVariant & p);
00662
QVariant property()
const;
00663 };
00664
00665
00669 class ItemFont:
public KConfigSkeletonGenericItem < QFont >
00670 {
00671
public:
00672
ItemFont(
const QString & group,
const QString & key,
QFont & reference,
00673
const QFont & defaultValue = KGlobalSettings::generalFont());
00674
00675
void readConfig(
KConfig * config);
00676
void setProperty(
const QVariant & p);
00677
QVariant property()
const;
00678 };
00679
00680
00684 class ItemRect:
public KConfigSkeletonGenericItem < QRect >
00685 {
00686
public:
00687
ItemRect(
const QString & group,
const QString & key,
QRect & reference,
00688
const QRect & defaultValue =
QRect());
00689
00690
void readConfig(
KConfig * config);
00691
void setProperty(
const QVariant & p);
00692
QVariant property()
const;
00693 };
00694
00695
00699 class ItemPoint:
public KConfigSkeletonGenericItem < QPoint >
00700 {
00701
public:
00702
ItemPoint(
const QString & group,
const QString & key,
QPoint & reference,
00703
const QPoint & defaultValue =
QPoint());
00704
00705
void readConfig(
KConfig * config);
00706
void setProperty(
const QVariant & p);
00707
QVariant property()
const;
00708 };
00709
00710
00714 class ItemSize:
public KConfigSkeletonGenericItem < QSize >
00715 {
00716
public:
00717
ItemSize(
const QString & group,
const QString & key,
QSize & reference,
00718
const QSize & defaultValue =
QSize());
00719
00720
void readConfig(
KConfig * config);
00721
void setProperty(
const QVariant & p);
00722
QVariant property()
const;
00723 };
00724
00725
00729 class ItemDateTime:
public KConfigSkeletonGenericItem < QDateTime >
00730 {
00731
public:
00732
ItemDateTime(
const QString & group,
const QString & key,
00733
QDateTime & reference,
00734
const QDateTime & defaultValue =
QDateTime());
00735
00736
void readConfig(
KConfig * config);
00737
void setProperty(
const QVariant & p);
00738
QVariant property()
const;
00739 };
00740
00741
00745 class ItemStringList:
public KConfigSkeletonGenericItem < QStringList >
00746 {
00747
public:
00748
ItemStringList(
const QString & group,
const QString & key,
00749
QStringList & reference,
00750
const QStringList & defaultValue =
QStringList());
00751
00752
void readConfig(
KConfig * config);
00753
void setProperty(
const QVariant & p);
00754
QVariant property()
const;
00755 };
00756
00757
00761 class ItemIntList:
public KConfigSkeletonGenericItem < QValueList < int > >
00762 {
00763
public:
00764
ItemIntList(
const QString & group,
const QString & key,
00765 QValueList < int >&reference,
00766
const QValueList < int >&defaultValue = QValueList < int >());
00767
00768
void readConfig(
KConfig * config);
00769
void setProperty(
const QVariant & p);
00770
QVariant property()
const;
00771 };
00772
00773
00774
public:
00781
KConfigSkeleton(
const QString & configname = QString::null);
00782
00788
KConfigSkeleton(
KSharedConfig::Ptr config);
00789
00793
virtual ~ KConfigSkeleton();
00794
00798
void setDefaults();
00799
00804
void readConfig();
00805
00810
void writeConfig();
00811
00817
void setCurrentGroup(
const QString & group);
00818
00822 QString currentGroup()
00823 {
00824
return mCurrentGroup;
00825 }
00826
00833
void addItem(
KConfigSkeletonItem *,
const QString & name = QString::null );
00834
00846 ItemString *
addItemString(
const QString & name,
QString & reference,
00847
const QString & defaultValue = QString::fromLatin1(
""),
00848
const QString & key = QString::null);
00849
00863 ItemPassword *
addItemPassword(
const QString & name,
QString & reference,
00864
const QString & defaultValue = QString::fromLatin1(
""),
00865
const QString & key = QString::null);
00866
00880 ItemPath *
addItemPath(
const QString & name,
QString & reference,
00881
const QString & defaultValue = QString::fromLatin1(
""),
00882
const QString & key = QString::null);
00883
00897 ItemProperty *
addItemProperty(
const QString & name,
QVariant & reference,
00898
const QVariant & defaultValue =
QVariant(),
00899
const QString & key = QString::null);
00911 ItemBool *
addItemBool(
const QString & name,
bool & reference,
00912
bool defaultValue =
false,
00913
const QString & key = QString::null);
00914
00926 ItemInt *
addItemInt(
const QString & name,
int &reference,
int defaultValue = 0,
00927
const QString & key = QString::null);
00928
00940 ItemUInt *
addItemUInt(
const QString & name,
unsigned int &reference,
00941
unsigned int defaultValue = 0,
00942
const QString & key = QString::null);
00943
00955 ItemLong *
addItemLong(
const QString & name,
long &reference,
00956
long defaultValue = 0,
00957
const QString & key = QString::null);
00958
00970 ItemULong *
addItemULong(
const QString & name,
unsigned long &reference,
00971
unsigned long defaultValue = 0,
00972
const QString & key = QString::null);
00973
00985 ItemInt64 *
addItemInt64(
const QString & name, Q_INT64 &reference,
00986 Q_INT64 defaultValue = 0,
00987
const QString & key = QString::null);
00988
01000 ItemUInt64 *
addItemUInt64(
const QString & name, Q_UINT64 &reference,
01001 Q_UINT64 defaultValue = 0,
01002
const QString & key = QString::null);
01003
01015 ItemDouble *
addItemDouble(
const QString & name,
double &reference,
01016
double defaultValue = 0.0,
01017
const QString & key = QString::null);
01018
01030 ItemColor *
addItemColor(
const QString & name,
QColor & reference,
01031
const QColor & defaultValue =
QColor(128, 128, 128),
01032
const QString & key = QString::null);
01033
01045 ItemFont *
addItemFont(
const QString & name,
QFont & reference,
01046
const QFont & defaultValue =
01047 KGlobalSettings::generalFont(),
01048
const QString & key = QString::null);
01049
01061 ItemRect *
addItemRect(
const QString & name,
QRect & reference,
01062
const QRect & defaultValue =
QRect(),
01063
const QString & key = QString::null);
01064
01076 ItemPoint *
addItemPoint(
const QString & name,
QPoint & reference,
01077
const QPoint & defaultValue =
QPoint(),
01078
const QString & key = QString::null);
01079
01091 ItemSize *
addItemSize(
const QString & name,
QSize & reference,
01092
const QSize & defaultValue =
QSize(),
01093
const QString & key = QString::null);
01094
01106 ItemDateTime *
addItemDateTime(
const QString & name,
QDateTime & reference,
01107
const QDateTime & defaultValue =
QDateTime(),
01108
const QString & key = QString::null);
01109
01121 ItemStringList *
addItemStringList(
const QString & name,
QStringList & reference,
01122
const QStringList & defaultValue =
QStringList(),
01123
const QString & key = QString::null);
01124
01136 ItemIntList *
addItemIntList(
const QString & name, QValueList < int >&reference,
01137
const QValueList < int >&defaultValue =
01138 QValueList < int >(),
01139
const QString & key = QString::null);
01140
01144
KConfig *
config() const;
01145
01149 KConfigSkeletonItem::List items()
const
01150
{
01151
return mItems;
01152 }
01153
01157
bool isImmutable(
const QString & name);
01158
01162
KConfigSkeletonItem *
findItem(
const QString & name);
01163
01170
bool useDefaults(
bool b);
01171
01172
protected:
01178 virtual void usrUseDefaults(
bool)
01179 {
01180 }
01181
01182
virtual void usrSetDefaults()
01183 {
01184 }
01185
01189 virtual void usrReadConfig()
01190 {
01191 }
01192
01196 virtual void usrWriteConfig()
01197 {
01198 }
01199
01200
private:
01201
QString mCurrentGroup;
01202
01203 KSharedConfig::Ptr mConfig;
01204
01205
KConfigSkeletonItem::List mItems;
01206
KConfigSkeletonItem::Dict mItemDict;
01207
01208
bool mUseDefaults;
01209
01210
class Private;
01211 Private *d;
01212
01213 };
01214
01215
#endif