00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _KCONFIGBASE_H
00024 #define _KCONFIGBASE_H
00025
00026 #include <qobject.h>
00027 #include <qcolor.h>
00028 #include <qfont.h>
00029 #include <qdatetime.h>
00030 #include <qstrlist.h>
00031 #include <qstringlist.h>
00032 #include <qvariant.h>
00033 #include <qmap.h>
00034
00035 #include "kconfigdata.h"
00036
00037 class KConfigBackEnd;
00038 class KConfigBasePrivate;
00039 class KConfigGroup;
00040
00067 class KConfigBase : public QObject
00068 {
00069 Q_OBJECT
00070
00071 friend class KConfigBackEnd;
00072 friend class KConfigINIBackEnd;
00073 friend class KConfigGroup;
00074
00075 public:
00079 KConfigBase();
00080
00084 virtual ~KConfigBase();
00085
00096 void setGroup( const QString& group );
00097
00102 void setDesktopGroup();
00103
00110 QString group() const;
00111
00118 bool hasGroup(const QString &group) const;
00119
00125 virtual QStringList groupList() const = 0;
00126
00132 QString locale() const;
00133
00142 QString readEntry(const QString& pKey,
00143 const QString& aDefault = QString::null ) const;
00144
00152 QString readEntry(const char *pKey,
00153 const QString& aDefault = QString::null ) const;
00154
00168 QVariant readPropertyEntry( const QString& pKey, QVariant::Type ) const;
00169
00184 QVariant readPropertyEntry( const char *pKey, QVariant::Type ) const;
00185
00200 QVariant readPropertyEntry( const QString& pKey,
00201 const QVariant &aDefault) const;
00202
00217 QVariant readPropertyEntry( const char *pKey,
00218 const QVariant &aDefault) const;
00219
00230 int readListEntry( const QString& pKey, QStrList &list, char sep = ',' ) const;
00231
00242 int readListEntry( const char *pKey, QStrList &list, char sep = ',' ) const;
00243
00251 QStringList readListEntry( const QString& pKey, char sep = ',' ) const;
00252
00260 QStringList readListEntry( const char *pKey, char sep = ',' ) const;
00261
00271 QStringList readListEntry( const char* pKey, const QStringList& aDefault,
00272 char sep = ',' ) const;
00273
00280 QValueList<int> readIntListEntry( const QString& pKey ) const;
00281
00288 QValueList<int> readIntListEntry( const char *pKey ) const;
00289
00301 QString readPathEntry( const QString& pKey, const QString & aDefault = QString::null ) const;
00302
00314 QString readPathEntry( const char *pKey, const QString & aDefault = QString::null ) const;
00315
00328 QStringList readPathListEntry( const QString& pKey, char sep = ',' ) const;
00329
00342 QStringList readPathListEntry( const char *pKey, char sep = ',' ) const;
00343
00344
00356 int readNumEntry( const QString& pKey, int nDefault = 0 ) const;
00357
00369 int readNumEntry( const char *pKey, int nDefault = 0 ) const;
00370
00382 unsigned int readUnsignedNumEntry( const QString& pKey, unsigned int nDefault = 0 ) const;
00383
00395 unsigned int readUnsignedNumEntry( const char *pKey, unsigned int nDefault = 0 ) const;
00396
00397
00409 long readLongNumEntry( const QString& pKey, long nDefault = 0 ) const;
00410
00422 long readLongNumEntry( const char *pKey, long nDefault = 0 ) const;
00423
00435 unsigned long readUnsignedLongNumEntry( const QString& pKey, unsigned long nDefault = 0 ) const;
00436
00448 unsigned long readUnsignedLongNumEntry( const char *pKey, unsigned long nDefault = 0 ) const;
00449
00461 Q_INT64 readNum64Entry( const QString& pKey, Q_INT64 nDefault = 0 ) const;
00462
00474 Q_INT64 readNum64Entry( const char *pKey, Q_INT64 nDefault = 0 ) const;
00475
00487 Q_UINT64 readUnsignedNum64Entry( const QString& pKey, Q_UINT64 nDefault = 0 ) const;
00488
00500 Q_UINT64 readUnsignedNum64Entry( const char *pKey, Q_UINT64 nDefault = 0 ) const;
00501
00513 double readDoubleNumEntry( const QString& pKey, double nDefault = 0.0 ) const;
00514
00526 double readDoubleNumEntry( const char *pKey, double nDefault = 0.0 ) const;
00527
00539 QFont readFontEntry( const QString& pKey, const QFont* pDefault = 0L ) const;
00540
00552 QFont readFontEntry( const char *pKey, const QFont* pDefault = 0L ) const;
00553
00565 bool readBoolEntry( const QString& pKey, bool bDefault = false ) const;
00566
00578 bool readBoolEntry( const char *pKey, bool bDefault = false ) const;
00579
00591 QRect readRectEntry( const QString& pKey, const QRect* pDefault = 0L ) const;
00592
00604 QRect readRectEntry( const char *pKey, const QRect* pDefault = 0L ) const;
00605
00617 QPoint readPointEntry( const QString& pKey, const QPoint* pDefault = 0L ) const;
00618
00630 QPoint readPointEntry( const char *pKey, const QPoint* pDefault = 0L ) const;
00631
00643 QSize readSizeEntry( const QString& pKey, const QSize* pDefault = 0L ) const;
00644
00656 QSize readSizeEntry( const char *pKey, const QSize* pDefault = 0L ) const;
00657
00658
00670 QColor readColorEntry( const QString& pKey, const QColor* pDefault = 0L ) const;
00671
00683 QColor readColorEntry( const char *pKey, const QColor* pDefault = 0L ) const;
00684
00697 QDateTime readDateTimeEntry( const QString& pKey, const QDateTime* pDefault = 0L ) const;
00698
00711 QDateTime readDateTimeEntry( const char *pKey, const QDateTime* pDefault = 0L ) const;
00712
00721 QString readEntryUntranslated( const QString& pKey,
00722 const QString& aDefault = QString::null ) const;
00723
00732 QString readEntryUntranslated( const char *pKey,
00733 const QString& aDefault = QString::null ) const;
00734
00754 void writeEntry( const QString& pKey, const QString& pValue,
00755 bool bPersistent = true, bool bGlobal = false,
00756 bool bNLS = false );
00757
00775 void writeEntry( const char *pKey, const QString& pValue,
00776 bool bPersistent = true, bool bGlobal = false,
00777 bool bNLS = false );
00778
00798 void writeEntry( const QString& pKey, const QVariant& rValue,
00799 bool bPersistent = true, bool bGlobal = false,
00800 bool bNLS = false );
00820 void writeEntry( const char *pKey, const QVariant& rValue,
00821 bool bPersistent = true, bool bGlobal = false,
00822 bool bNLS = false );
00823
00844 void writeEntry( const QString& pKey, const QStrList &rValue,
00845 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00866 void writeEntry( const char *pKey, const QStrList &rValue,
00867 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00868
00889 void writeEntry( const QString& pKey, const QStringList &rValue,
00890 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00911 void writeEntry( const char *pKey, const QStringList &rValue,
00912 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00913
00914
00934 void writeEntry( const QString& pKey, const QValueList<int>& rValue,
00935 bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00955 void writeEntry( const char *pKey, const QValueList<int>& rValue,
00956 bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00957
00975 void writeEntry( const QString& pKey, const char *pValue,
00976 bool bPersistent = true, bool bGlobal = false,
00977 bool bNLS = false )
00978 { writeEntry(pKey, QString::fromLatin1(pValue), bPersistent, bGlobal, bNLS); }
00996 void writeEntry( const char *pKey, const char *pValue,
00997 bool bPersistent = true, bool bGlobal = false,
00998 bool bNLS = false )
00999 { writeEntry(pKey, QString::fromLatin1(pValue), bPersistent, bGlobal, bNLS); }
01000
01016 void writeEntry( const QString& pKey, int nValue,
01017 bool bPersistent = true, bool bGlobal = false,
01018 bool bNLS = false );
01034 void writeEntry( const char *pKey, int nValue,
01035 bool bPersistent = true, bool bGlobal = false,
01036 bool bNLS = false );
01037
01053 void writeEntry( const QString& pKey, unsigned int nValue,
01054 bool bPersistent = true, bool bGlobal = false,
01055 bool bNLS = false );
01071 void writeEntry( const char *pKey, unsigned int nValue,
01072 bool bPersistent = true, bool bGlobal = false,
01073 bool bNLS = false );
01074
01089 void writeEntry( const QString& pKey, long nValue,
01090 bool bPersistent = true, bool bGlobal = false,
01091 bool bNLS = false );
01106 void writeEntry( const char *pKey, long nValue,
01107 bool bPersistent = true, bool bGlobal = false,
01108 bool bNLS = false );
01109
01124 void writeEntry( const QString& pKey, unsigned long nValue,
01125 bool bPersistent = true, bool bGlobal = false,
01126 bool bNLS = false );
01141 void writeEntry( const char *pKey, unsigned long nValue,
01142 bool bPersistent = true, bool bGlobal = false,
01143 bool bNLS = false );
01144
01159 void writeEntry( const QString& pKey, Q_INT64 nValue,
01160 bool bPersistent = true, bool bGlobal = false,
01161 bool bNLS = false );
01176 void writeEntry( const char *pKey, Q_INT64 nValue,
01177 bool bPersistent = true, bool bGlobal = false,
01178 bool bNLS = false );
01179
01194 void writeEntry( const QString& pKey, Q_UINT64 nValue,
01195 bool bPersistent = true, bool bGlobal = false,
01196 bool bNLS = false );
01211 void writeEntry( const char *pKey, Q_UINT64 nValue,
01212 bool bPersistent = true, bool bGlobal = false,
01213 bool bNLS = false );
01214
01232 void writeEntry( const QString& pKey, double nValue,
01233 bool bPersistent = true, bool bGlobal = false,
01234 char format = 'g', int precision = 6,
01235 bool bNLS = false );
01253 void writeEntry( const char *pKey, double nValue,
01254 bool bPersistent = true, bool bGlobal = false,
01255 char format = 'g', int precision = 6,
01256 bool bNLS = false );
01257
01272 void writeEntry( const QString& pKey, bool bValue,
01273 bool bPersistent = true, bool bGlobal = false,
01274 bool bNLS = false );
01289 void writeEntry( const char *pKey, bool bValue,
01290 bool bPersistent = true, bool bGlobal = false,
01291 bool bNLS = false );
01292
01307 void writeEntry( const QString& pKey, const QFont& rFont,
01308 bool bPersistent = true, bool bGlobal = false,
01309 bool bNLS = false );
01324 void writeEntry( const char *pKey, const QFont& rFont,
01325 bool bPersistent = true, bool bGlobal = false,
01326 bool bNLS = false );
01327
01345 void writeEntry( const QString& pKey, const QColor& rColor,
01346 bool bPersistent = true, bool bGlobal = false,
01347 bool bNLS = false );
01365 void writeEntry( const char *pKey, const QColor& rColor,
01366 bool bPersistent = true, bool bGlobal = false,
01367 bool bNLS = false );
01368
01386 void writeEntry( const QString& pKey, const QDateTime& rDateTime,
01387 bool bPersistent = true, bool bGlobal = false,
01388 bool bNLS = false );
01406 void writeEntry( const char *pKey, const QDateTime& rDateTime,
01407 bool bPersistent = true, bool bGlobal = false,
01408 bool bNLS = false );
01409
01410
01428 void writeEntry( const QString& pKey, const QRect& rValue,
01429 bool bPersistent = true, bool bGlobal = false,
01430 bool bNLS = false );
01448 void writeEntry( const char *pKey, const QRect& rValue,
01449 bool bPersistent = true, bool bGlobal = false,
01450 bool bNLS = false );
01451
01469 void writeEntry( const QString& pKey, const QPoint& rValue,
01470 bool bPersistent = true, bool bGlobal = false,
01471 bool bNLS = false );
01489 void writeEntry( const char *pKey, const QPoint& rValue,
01490 bool bPersistent = true, bool bGlobal = false,
01491 bool bNLS = false );
01492
01510 void writeEntry( const QString& pKey, const QSize& rValue,
01511 bool bPersistent = true, bool bGlobal = false,
01512 bool bNLS = false );
01530 void writeEntry( const char *pKey, const QSize& rValue,
01531 bool bPersistent = true, bool bGlobal = false,
01532 bool bNLS = false );
01533
01551 void writePathEntry( const QString& pKey, const QString & path,
01552 bool bPersistent = true, bool bGlobal = false,
01553 bool bNLS = false );
01571 void writePathEntry( const char *pKey, const QString & path,
01572 bool bPersistent = true, bool bGlobal = false,
01573 bool bNLS = false );
01574
01598 void writePathEntry( const QString& pKey, const QStringList &rValue,
01599 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
01623 void writePathEntry( const char *pKey, const QStringList &rValue,
01624 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
01625
01626
01635 void deleteEntry( const QString& pKey,
01636 bool bNLS = false, bool bGlobal = false);
01645 void deleteEntry( const char *pKey,
01646 bool bNLS = false, bool bGlobal = false);
01647
01665 bool deleteGroup( const QString& group, bool bDeep = true, bool bGlobal = false );
01666
01667
01675 void setDollarExpansion( bool _bExpand = true ) { bExpand = _bExpand; }
01676
01682 bool isDollarExpansion() const { return bExpand; }
01683
01698 virtual void rollback( bool bDeep = true );
01699
01713 virtual void sync();
01714
01719 bool isDirty() const { return bDirty; }
01720
01728 virtual void setReadOnly(bool _ro) { bReadOnly = _ro; }
01729
01735 bool isReadOnly() const { return bReadOnly; }
01736
01746 bool hasKey( const QString& key ) const;
01747
01758 virtual QMap<QString, QString> entryMap(const QString &group) const = 0;
01759
01772 virtual void reparseConfiguration() = 0;
01773
01778 bool isImmutable() const;
01779
01786 bool groupIsImmutable(const QString &group) const;
01787
01794 bool entryIsImmutable(const QString &key) const;
01795
01801 enum ConfigState { NoAccess, ReadOnly, ReadWrite };
01802
01816 ConfigState getConfigState() const;
01817
01824 bool checkConfigFilesWritable(bool warnUser);
01825
01832 void setReadDefaults(bool b);
01833
01839 bool readDefaults() const;
01840
01852 void revertToDefault(const QString &key);
01853
01880 bool hasDefault(const QString &key) const;
01881
01882 protected:
01888 void setLocale();
01889
01895 virtual void setDirty(bool _bDirty = true) { bDirty = _bDirty; }
01896
01902 virtual void parseConfigFiles();
01903
01919 virtual KEntryMap internalEntryMap( const QString& pGroup ) const = 0;
01920
01932 virtual KEntryMap internalEntryMap() const = 0;
01933
01949 virtual void putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup = true) = 0;
01950
01965 virtual KEntry lookupData(const KEntryKey &_key) const = 0;
01966
01967 virtual bool internalHasGroup(const QCString &group) const = 0;
01968
01972 KConfigBackEnd *backEnd;
01973 public:
01977 void setGroup( const QCString &pGroup );
01978 void setGroup( const char *pGroup );
01979 bool hasGroup(const QCString &_pGroup) const;
01980 bool hasGroup(const char *_pGroup) const;
01981 bool hasKey( const char *pKey ) const;
01982
01983 protected:
01984 QCString readEntryUtf8( const char *pKey) const;
01985
01988 QCString mGroup;
01989
01992 QCString aLocaleString;
01993
01997 bool bDirty;
01998
01999 bool bLocaleInitialized;
02000 bool bReadOnly;
02001 mutable bool bExpand;
02002
02003 protected:
02004 virtual void virtual_hook( int id, void* data );
02005 private:
02006 class KConfigBasePrivate;
02007 KConfigBasePrivate *d;
02008 };
02009
02010 class KConfigGroupSaverPrivate;
02011
02048 class KConfigGroupSaver
02049 {
02050 public:
02060 KConfigGroupSaver( KConfigBase* config, QString group )
02061
02062 : _config(config), _oldgroup(config->group())
02063 { _config->setGroup( group ); }
02064
02065 KConfigGroupSaver( KConfigBase* config, const char *group )
02066 : _config(config), _oldgroup(config->group())
02067 { _config->setGroup( group ); }
02068
02069 KConfigGroupSaver( KConfigBase* config, const QCString &group )
02070 : _config(config), _oldgroup(config->group())
02071 { _config->setGroup( group ); }
02072
02073 ~KConfigGroupSaver() { _config->setGroup( _oldgroup ); }
02074
02075 KConfigBase* config() { return _config; };
02076
02077 private:
02078 KConfigBase* _config;
02079 QString _oldgroup;
02080
02081 KConfigGroupSaver(const KConfigGroupSaver&);
02082 KConfigGroupSaver& operator=(const KConfigGroupSaver&);
02083
02084 KConfigGroupSaverPrivate *d;
02085 };
02086
02087 class KConfigGroupPrivate;
02088
02092 class KConfigGroup: public KConfigBase
02093 {
02094 public:
02099 KConfigGroup(KConfigBase *master, const QCString &group);
02106 KConfigGroup(KConfigBase *master, const QString &group);
02114 KConfigGroup(KConfigBase *master, const char * group);
02115
02122 void deleteGroup(bool bGlobal = false);
02123
02124
02125 virtual void setDirty(bool b);
02126 virtual void putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup = true);
02127 virtual KEntry lookupData(const KEntryKey &_key) const;
02128 virtual void sync();
02129
02130 private:
02131
02132 void setGroup() { }
02133 void setDesktopGroup() { }
02134 void group() { }
02135 void hasGroup() { }
02136 void setReadOnly(bool) { }
02137 void isDirty() { }
02138
02139
02140 virtual QStringList groupList() const { return QStringList(); }
02141 virtual void rollback(bool) { }
02142 virtual void reparseConfiguration() { }
02143 virtual QMap<QString, QString> entryMap(const QString &) const
02144 { return QMap<QString,QString>(); }
02145 virtual KEntryMap internalEntryMap( const QString&) const
02146 { return KEntryMap(); }
02147 virtual KEntryMap internalEntryMap() const
02148 { return KEntryMap(); }
02149 virtual bool internalHasGroup(const QCString &) const
02150 { return false; }
02151
02152 void getConfigState() { }
02153
02154 KConfigBase *mMaster;
02155 protected:
02156 virtual void virtual_hook( int id, void* data );
02157 private:
02158 KConfigGroupPrivate* d;
02159 };
02160
02161 #endif