00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef KCORECONFIGSKELETON_H
00024 #define KCORECONFIGSKELETON_H
00025
00026 #include <kdecore_export.h>
00027
00028 #include <kurl.h>
00029 #include <ksharedconfig.h>
00030 #include <kconfiggroup.h>
00031
00032 #include <QtCore/QDate>
00033 #include <QtCore/QHash>
00034 #include <QtCore/QRect>
00035 #include <QtCore/QStringList>
00036 #include <QtCore/QVariant>
00037
00038 class KConfigSkeletonItemPrivate;
00052 class KDECORE_EXPORT KConfigSkeletonItem
00053 {
00054 public:
00055 typedef QList < KConfigSkeletonItem * >List;
00056 typedef QHash < QString, KConfigSkeletonItem* > Dict;
00057 typedef QHash < QString, KConfigSkeletonItem* >::Iterator DictIterator;
00058
00065 KConfigSkeletonItem(const QString & _group, const QString & _key);
00066
00070 virtual ~KConfigSkeletonItem();
00071
00075 void setGroup( const QString &_group );
00076
00080 QString group() const;
00081
00085 void setKey( const QString &_key );
00086
00090 QString key() const;
00091
00095 void setName(const QString &_name);
00096
00100 QString name() const;
00101
00105 void setLabel( const QString &l );
00106
00110 QString label() const;
00111
00116 void setToolTip( const QString &t );
00117
00122 QString toolTip() const;
00123
00127 void setWhatsThis( const QString &w );
00128
00132 QString whatsThis() const;
00133
00138 virtual void readConfig(KConfig *) = 0;
00139
00144 virtual void writeConfig(KConfig *) = 0;
00145
00149 virtual void readDefault(KConfig *) = 0;
00150
00154 virtual void setProperty(const QVariant &p) = 0;
00155
00165 virtual bool isEqual(const QVariant &p) const = 0;
00166
00170 virtual QVariant property() const = 0;
00171
00175 virtual QVariant minValue() const;
00176
00180 virtual QVariant maxValue() const;
00181
00185 virtual void setDefault() = 0;
00186
00191 virtual void swapDefault() = 0;
00192
00196 bool isImmutable() const;
00197
00198 protected:
00203 void readImmutability(const KConfigGroup &group);
00204
00205 QString mGroup;
00206 QString mKey;
00207 QString mName;
00208
00209 private:
00210 KConfigSkeletonItemPrivate * const d;
00211 };
00212
00213
00217 template < typename T > class KConfigSkeletonGenericItem:public KConfigSkeletonItem
00218 {
00219 public:
00224 KConfigSkeletonGenericItem(const QString & _group, const QString & _key, T & reference,
00225 T defaultValue)
00226 : KConfigSkeletonItem(_group, _key), mReference(reference),
00227 mDefault(defaultValue), mLoadedValue(defaultValue)
00228 {
00229 }
00230
00234 void setValue(const T & v)
00235 {
00236 mReference = v;
00237 }
00238
00242 T & value()
00243 {
00244 return mReference;
00245 }
00246
00250 const T & value() const
00251 {
00252 return mReference;
00253 }
00254
00258 virtual void setDefaultValue( const T &v )
00259 {
00260 mDefault = v;
00261 }
00262
00266 virtual void setDefault()
00267 {
00268 mReference = mDefault;
00269 }
00270
00272 virtual void writeConfig(KConfig * config)
00273 {
00274 if ( mReference != mLoadedValue )
00275 {
00276 KConfigGroup cg(config, mGroup);
00277 if ((mDefault == mReference) && !cg.hasDefault( mKey))
00278 cg.revertToDefault( mKey );
00279 else
00280 cg.writeEntry(mKey, mReference);
00281 }
00282 }
00283
00285 void readDefault(KConfig * config)
00286 {
00287 config->setReadDefaults(true);
00288 readConfig(config);
00289 config->setReadDefaults(false);
00290 mDefault = mReference;
00291 }
00292
00294 void swapDefault()
00295 {
00296 T tmp = mReference;
00297 mReference = mDefault;
00298 mDefault = tmp;
00299 }
00300
00301 protected:
00302 T & mReference;
00303 T mDefault;
00304 T mLoadedValue;
00305 };
00306
00366 class KDECORE_EXPORT KCoreConfigSkeleton : public QObject
00367 {
00368 Q_OBJECT
00369 public:
00373 class KDECORE_EXPORT ItemString:public KConfigSkeletonGenericItem < QString >
00374 {
00375 public:
00376 enum Type { Normal, Password, Path };
00377
00395 ItemString(const QString & _group, const QString & _key,
00396 QString & reference,
00397 const QString & defaultValue = QLatin1String(""),
00398 Type type = Normal);
00399
00401 void writeConfig(KConfig * config);
00402
00404 void readConfig(KConfig * config);
00405
00407 void setProperty(const QVariant & p);
00408
00410 bool isEqual(const QVariant &p) const;
00411
00413 QVariant property() const;
00414
00415 private:
00416 Type mType;
00417 };
00418
00422 class KDECORE_EXPORT ItemPassword:public ItemString
00423 {
00424 public:
00426 ItemPassword(const QString & _group, const QString & _key,
00427 QString & reference,
00428 const QString & defaultValue = QLatin1String(""));
00429 };
00430
00434 class KDECORE_EXPORT ItemPath:public ItemString
00435 {
00436 public:
00438 ItemPath(const QString & _group, const QString & _key,
00439 QString & reference,
00440 const QString & defaultValue = QString());
00441 };
00442
00446 class KDECORE_EXPORT ItemUrl:public KConfigSkeletonGenericItem < KUrl >
00447 {
00448 public:
00449
00452 ItemUrl(const QString & _group, const QString & _key,
00453 KUrl & reference,
00454 const KUrl & defaultValue = KUrl());
00455
00457 void writeConfig(KConfig * config);
00458
00460 void readConfig(KConfig * config);
00461
00463 void setProperty(const QVariant & p);
00464
00466 bool isEqual(const QVariant &p) const;
00467
00469 QVariant property() const;
00470 };
00471
00475 class KDECORE_EXPORT ItemProperty:public KConfigSkeletonGenericItem < QVariant >
00476 {
00477 public:
00479 ItemProperty(const QString & _group, const QString & _key,
00480 QVariant & reference, const QVariant & defaultValue = 0);
00481
00482 void readConfig(KConfig * config);
00483 void setProperty(const QVariant & p);
00484
00486 bool isEqual(const QVariant &p) const;
00487
00489 QVariant property() const;
00490 };
00491
00492
00496 class KDECORE_EXPORT ItemBool:public KConfigSkeletonGenericItem < bool >
00497 {
00498 public:
00500 ItemBool(const QString & _group, const QString & _key, bool & reference,
00501 bool defaultValue = true);
00502
00504 void readConfig(KConfig * config);
00505
00507 void setProperty(const QVariant & p);
00508
00510 bool isEqual(const QVariant &p) const;
00511
00513 QVariant property() const;
00514 };
00515
00516
00520 class KDECORE_EXPORT ItemInt:public KConfigSkeletonGenericItem < qint32 >
00521 {
00522 public:
00524 ItemInt(const QString & _group, const QString & _key, qint32 &reference,
00525 qint32 defaultValue = 0);
00526
00528 void readConfig(KConfig * config);
00529
00531 void setProperty(const QVariant & p);
00532
00534 bool isEqual(const QVariant &p) const;
00535
00537 QVariant property() const;
00538
00540 QVariant minValue() const;
00541
00543 QVariant maxValue() const;
00544
00548 void setMinValue(qint32);
00549
00553 void setMaxValue(qint32);
00554
00555 private:
00556 bool mHasMin : 1;
00557 bool mHasMax : 1;
00558 qint32 mMin;
00559 qint32 mMax;
00560 };
00561
00565 class KDECORE_EXPORT ItemLongLong:public KConfigSkeletonGenericItem < qint64 >
00566 {
00567 public:
00569 ItemLongLong(const QString & _group, const QString & _key, qint64 &reference,
00570 qint64 defaultValue = 0);
00571
00573 void readConfig(KConfig * config);
00574
00576 void setProperty(const QVariant & p);
00577
00579 bool isEqual(const QVariant &p) const;
00580
00582 QVariant property() const;
00583
00585 QVariant minValue() const;
00586
00588 QVariant maxValue() const;
00589
00591 void setMinValue(qint64);
00592
00594 void setMaxValue(qint64);
00595
00596 private:
00597 bool mHasMin : 1;
00598 bool mHasMax : 1;
00599 qint64 mMin;
00600 qint64 mMax;
00601 };
00602 typedef KDE_DEPRECATED ItemLongLong ItemInt64;
00603
00607 class KDECORE_EXPORT ItemEnum:public ItemInt
00608 {
00609 public:
00610
00611 struct Choice
00612 {
00613 QString name;
00614 QString label;
00615 QString whatsThis;
00616 };
00617
00618 struct Choice2
00619 {
00620 QString name;
00621 QString label;
00622 QString toolTip;
00623 QString whatsThis;
00624 };
00625
00629 ItemEnum(const QString & _group, const QString & _key, qint32 &reference,
00630 const QList<Choice> &choices, qint32 defaultValue = 0);
00631
00635 ItemEnum(const QString & _group, const QString & _key, qint32 &reference,
00636 const QList<Choice2> &choices, qint32 defaultValue = 0);
00637
00638 QList<Choice> choices() const;
00639 QList<Choice2> choices2() const;
00640
00642 void readConfig(KConfig * config);
00643
00645 void writeConfig(KConfig * config);
00646
00647 private:
00648 QList<Choice2> mChoices;
00649 };
00650
00651
00655 class KDECORE_EXPORT ItemUInt:public KConfigSkeletonGenericItem < quint32 >
00656 {
00657 public:
00659 ItemUInt(const QString & _group, const QString & _key,
00660 quint32 &reference, quint32 defaultValue = 0);
00661
00663 void readConfig(KConfig * config);
00664
00666 void setProperty(const QVariant & p);
00667
00669 bool isEqual(const QVariant &p) const;
00670
00672 QVariant property() const;
00673
00675 QVariant minValue() const;
00676
00678 QVariant maxValue() const;
00679
00681 void setMinValue(quint32);
00682
00684 void setMaxValue(quint32);
00685
00686 private:
00687 bool mHasMin : 1;
00688 bool mHasMax : 1;
00689 quint32 mMin;
00690 quint32 mMax;
00691 };
00692
00696 class KDECORE_EXPORT ItemULongLong:public KConfigSkeletonGenericItem < quint64 >
00697 {
00698 public:
00700 ItemULongLong(const QString & _group, const QString & _key, quint64 &reference,
00701 quint64 defaultValue = 0);
00702
00704 void readConfig(KConfig * config);
00705
00707 void setProperty(const QVariant & p);
00708
00710 bool isEqual(const QVariant &p) const;
00711
00713 QVariant property() const;
00714
00716 QVariant minValue() const;
00717
00719 QVariant maxValue() const;
00720
00722 void setMinValue(quint64);
00723
00725 void setMaxValue(quint64);
00726
00727 private:
00728 bool mHasMin : 1;
00729 bool mHasMax : 1;
00730 quint64 mMin;
00731 quint64 mMax;
00732 };
00733 typedef KDE_DEPRECATED ItemULongLong ItemUInt64;
00734
00738 class KDECORE_EXPORT ItemDouble:public KConfigSkeletonGenericItem < double >
00739 {
00740 public:
00742 ItemDouble(const QString & _group, const QString & _key,
00743 double &reference, double defaultValue = 0);
00744
00746 void readConfig(KConfig * config);
00747
00749 void setProperty(const QVariant & p);
00750
00752 bool isEqual(const QVariant &p) const;
00753
00755 QVariant property() const;
00756
00758 QVariant minValue() const;
00759
00761 QVariant maxValue() const;
00762
00764 void setMinValue(double);
00765
00767 void setMaxValue(double);
00768
00769 private:
00770 bool mHasMin : 1;
00771 bool mHasMax : 1;
00772 double mMin;
00773 double mMax;
00774 };
00775
00776
00780 class KDECORE_EXPORT ItemRect:public KConfigSkeletonGenericItem < QRect >
00781 {
00782 public:
00784 ItemRect(const QString & _group, const QString & _key, QRect & reference,
00785 const QRect & defaultValue = QRect());
00786
00788 void readConfig(KConfig * config);
00789
00791 void setProperty(const QVariant & p);
00792
00794 bool isEqual(const QVariant &p) const;
00795
00797 QVariant property() const;
00798 };
00799
00800
00804 class KDECORE_EXPORT ItemPoint:public KConfigSkeletonGenericItem < QPoint >
00805 {
00806 public:
00808 ItemPoint(const QString & _group, const QString & _key, QPoint & reference,
00809 const QPoint & defaultValue = QPoint());
00810
00812 void readConfig(KConfig * config);
00813
00815 void setProperty(const QVariant & p);
00816
00818 bool isEqual(const QVariant &p) const;
00819
00821 QVariant property() const;
00822 };
00823
00824
00828 class KDECORE_EXPORT ItemSize:public KConfigSkeletonGenericItem < QSize >
00829 {
00830 public:
00832 ItemSize(const QString & _group, const QString & _key, QSize & reference,
00833 const QSize & defaultValue = QSize());
00834
00836 void readConfig(KConfig * config);
00837
00839 void setProperty(const QVariant & p);
00840
00842 bool isEqual(const QVariant &p) const;
00843
00845 QVariant property() const;
00846 };
00847
00848
00852 class KDECORE_EXPORT ItemDateTime:public KConfigSkeletonGenericItem < QDateTime >
00853 {
00854 public:
00856 ItemDateTime(const QString & _group, const QString & _key,
00857 QDateTime & reference,
00858 const QDateTime & defaultValue = QDateTime());
00859
00861 void readConfig(KConfig * config);
00862
00864 void setProperty(const QVariant & p);
00865
00867 bool isEqual(const QVariant &p) const;
00868
00870 QVariant property() const;
00871 };
00872
00873
00877 class KDECORE_EXPORT ItemStringList:public KConfigSkeletonGenericItem < QStringList >
00878 {
00879 public:
00881 ItemStringList(const QString & _group, const QString & _key,
00882 QStringList & reference,
00883 const QStringList & defaultValue = QStringList());
00884
00886 void readConfig(KConfig * config);
00887
00889 void setProperty(const QVariant & p);
00890
00892 bool isEqual(const QVariant &p) const;
00893
00895 QVariant property() const;
00896 };
00897
00898
00902 class KDECORE_EXPORT ItemPathList:public ItemStringList
00903 {
00904 public:
00906 ItemPathList(const QString & _group, const QString & _key,
00907 QStringList & reference,
00908 const QStringList & defaultValue = QStringList());
00909
00911 void readConfig(KConfig * config);
00913 void writeConfig(KConfig * config);
00914 };
00915
00919 class KDECORE_EXPORT ItemUrlList:public KConfigSkeletonGenericItem < KUrl::List >
00920 {
00921 public:
00923 ItemUrlList(const QString & _group, const QString & _key,
00924 KUrl::List & reference,
00925 const KUrl::List & defaultValue = KUrl::List());
00926
00928 void readConfig(KConfig * config);
00929
00931 void writeConfig(KConfig * config);
00932
00934 void setProperty(const QVariant & p);
00935
00937 bool isEqual(const QVariant &p) const;
00938
00940 QVariant property() const;
00941 };
00942
00946 class KDECORE_EXPORT ItemIntList:public KConfigSkeletonGenericItem < QList < int > >
00947 {
00948 public:
00950 ItemIntList(const QString & _group, const QString & _key,
00951 QList < int >&reference,
00952 const QList < int >&defaultValue = QList < int >());
00953
00955 void readConfig(KConfig * config);
00956
00958 void setProperty(const QVariant & p);
00959
00961 bool isEqual(const QVariant &p) const;
00962
00964 QVariant property() const;
00965 };
00966
00967
00968 public:
00976 explicit KCoreConfigSkeleton(const QString & configname = QString(), QObject* parent = 0);
00977
00984 explicit KCoreConfigSkeleton(KSharedConfig::Ptr config, QObject* parent = 0);
00985
00989 virtual ~KCoreConfigSkeleton();
00990
00999 virtual void setDefaults();
01000
01010 virtual void readConfig();
01011
01021 virtual void writeConfig();
01022
01028 void setCurrentGroup(const QString & group);
01029
01033 QString currentGroup() const;
01034
01044 void addItem(KConfigSkeletonItem *, const QString & name = QString() );
01045
01057 ItemString *addItemString(const QString & name, QString & reference,
01058 const QString & defaultValue = QLatin1String(""),
01059 const QString & key = QString());
01060
01074 ItemPassword *addItemPassword(const QString & name, QString & reference,
01075 const QString & defaultValue = QLatin1String(""),
01076 const QString & key = QString());
01077
01091 ItemPath *addItemPath(const QString & name, QString & reference,
01092 const QString & defaultValue = QLatin1String(""),
01093 const QString & key = QString());
01094
01108 ItemProperty *addItemProperty(const QString & name, QVariant & reference,
01109 const QVariant & defaultValue = QVariant(),
01110 const QString & key = QString());
01122 ItemBool *addItemBool(const QString & name, bool & reference,
01123 bool defaultValue = false,
01124 const QString & key = QString());
01125
01137 ItemInt *addItemInt(const QString & name, qint32 &reference, qint32 defaultValue = 0,
01138 const QString & key = QString());
01139
01151 ItemUInt *addItemUInt(const QString & name, quint32 &reference,
01152 quint32 defaultValue = 0,
01153 const QString & key = QString());
01154
01166 ItemLongLong *addItemLongLong(const QString & name, qint64 &reference,
01167 qint64 defaultValue = 0,
01168 const QString & key = QString());
01169
01174 KDE_DEPRECATED ItemLongLong *addItemInt64( const QString& name, qint64 &reference,
01175 qint64 defaultValue = 0,
01176 const QString & key = QString());
01177
01189 ItemULongLong *addItemULongLong(const QString & name, quint64 &reference,
01190 quint64 defaultValue = 0,
01191 const QString & key = QString());
01192
01197 KDE_DEPRECATED ItemULongLong *addItemUInt64(const QString & name, quint64 &reference,
01198 quint64 defaultValue = 0,
01199 const QString & key = QString());
01200
01212 ItemDouble *addItemDouble(const QString & name, double &reference,
01213 double defaultValue = 0.0,
01214 const QString & key = QString());
01215
01227 ItemRect *addItemRect(const QString & name, QRect & reference,
01228 const QRect & defaultValue = QRect(),
01229 const QString & key = QString());
01230
01242 ItemPoint *addItemPoint(const QString & name, QPoint & reference,
01243 const QPoint & defaultValue = QPoint(),
01244 const QString & key = QString());
01245
01257 ItemSize *addItemSize(const QString & name, QSize & reference,
01258 const QSize & defaultValue = QSize(),
01259 const QString & key = QString());
01260
01272 ItemDateTime *addItemDateTime(const QString & name, QDateTime & reference,
01273 const QDateTime & defaultValue = QDateTime(),
01274 const QString & key = QString());
01275
01287 ItemStringList *addItemStringList(const QString & name, QStringList & reference,
01288 const QStringList & defaultValue = QStringList(),
01289 const QString & key = QString());
01290
01302 ItemIntList *addItemIntList(const QString & name, QList < int >&reference,
01303 const QList < int >&defaultValue =
01304 QList < int >(),
01305 const QString & key = QString());
01306
01310 KConfig *config();
01311
01315 const KConfig *config() const;
01316
01320 void setSharedConfig(KSharedConfig::Ptr pConfig);
01321
01325 KConfigSkeletonItem::List items() const;
01326
01330 bool isImmutable(const QString & name);
01331
01335 KConfigSkeletonItem * findItem(const QString & name);
01336
01349 virtual bool useDefaults(bool b);
01350
01351 Q_SIGNALS:
01355 void configChanged();
01356
01357 protected:
01366 virtual bool usrUseDefaults(bool b);
01367
01373 virtual void usrSetDefaults();
01374
01380 virtual void usrReadConfig();
01381
01387 virtual void usrWriteConfig();
01388
01389 private:
01390 class Private;
01391 Private * const d;
01392 friend class KConfigSkeleton;
01393
01394 };
01395
01396 #endif