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 #include "kdelibs_export.h"
00037
00038 class KConfigBackEnd;
00039 class KConfigBasePrivate;
00040 class KConfigGroup;
00041
00070 class KDECORE_EXPORT KConfigBase : public QObject
00071 {
00072 Q_OBJECT
00073
00074 friend class KConfigBackEnd;
00075 friend class KConfigINIBackEnd;
00076 friend class KConfigGroup;
00077 friend class KConfigLDAPBackEnd;
00078
00079 public:
00083 KConfigBase();
00084
00088 virtual ~KConfigBase();
00089
00093 void dumpConfig( const QString& ent, const QString& val, const QString& type ) const;
00094
00105 void setGroup( const QString& group );
00106
00111 void setDesktopGroup();
00112
00119 QString group() const;
00120
00127 bool hasGroup(const QString &group) const;
00128
00134 virtual QStringList groupList() const = 0;
00135
00141 QString locale() const;
00142
00151 QString readEntry(const QString& pKey,
00152 const QString& aDefault = QString::null ) const;
00153
00161 QString readEntry(const char *pKey,
00162 const QString& aDefault = QString::null ) const;
00163
00177 QVariant readPropertyEntry( const QString& pKey, QVariant::Type ) const;
00178
00193 QVariant readPropertyEntry( const char *pKey, QVariant::Type ) const;
00194
00209 QVariant readPropertyEntry( const QString& pKey,
00210 const QVariant &aDefault) const;
00211
00226 QVariant readPropertyEntry( const char *pKey,
00227 const QVariant &aDefault) const;
00228
00239 int readListEntry( const QString& pKey, QStrList &list, char sep = ',' ) const;
00240
00251 int readListEntry( const char *pKey, QStrList &list, char sep = ',' ) const;
00252
00260 QStringList readListEntry( const QString& pKey, char sep = ',' ) const;
00261
00269 QStringList readListEntry( const char *pKey, char sep = ',' ) const;
00270
00280 QStringList readListEntry( const char* pKey, const QStringList& aDefault,
00281 char sep = ',' ) const;
00282
00289 QValueList<int> readIntListEntry( const QString& pKey ) const;
00290
00297 QValueList<int> readIntListEntry( const char *pKey ) const;
00298
00310 QString readPathEntry( const QString& pKey, const QString & aDefault = QString::null ) const;
00311
00323 QString readPathEntry( const char *pKey, const QString & aDefault = QString::null ) const;
00324
00337 QStringList readPathListEntry( const QString& pKey, char sep = ',' ) const;
00338
00351 QStringList readPathListEntry( const char *pKey, char sep = ',' ) const;
00352
00353
00365 int readNumEntry( const QString& pKey, int nDefault = 0 ) const;
00366
00378 int readNumEntry( const char *pKey, int nDefault = 0 ) const;
00379
00391 unsigned int readUnsignedNumEntry( const QString& pKey, unsigned int nDefault = 0 ) const;
00392
00404 unsigned int readUnsignedNumEntry( const char *pKey, unsigned int nDefault = 0 ) const;
00405
00406
00418 long readLongNumEntry( const QString& pKey, long nDefault = 0 ) const;
00419
00431 long readLongNumEntry( const char *pKey, long nDefault = 0 ) const;
00432
00444 unsigned long readUnsignedLongNumEntry( const QString& pKey, unsigned long nDefault = 0 ) const;
00445
00457 unsigned long readUnsignedLongNumEntry( const char *pKey, unsigned long nDefault = 0 ) const;
00458
00470 Q_INT64 readNum64Entry( const QString& pKey, Q_INT64 nDefault = 0 ) const;
00471
00483 Q_INT64 readNum64Entry( const char *pKey, Q_INT64 nDefault = 0 ) const;
00484
00496 Q_UINT64 readUnsignedNum64Entry( const QString& pKey, Q_UINT64 nDefault = 0 ) const;
00497
00509 Q_UINT64 readUnsignedNum64Entry( const char *pKey, Q_UINT64 nDefault = 0 ) const;
00510
00522 double readDoubleNumEntry( const QString& pKey, double nDefault = 0.0 ) const;
00523
00535 double readDoubleNumEntry( const char *pKey, double nDefault = 0.0 ) const;
00536
00548 QFont readFontEntry( const QString& pKey, const QFont* pDefault = 0L ) const;
00549
00561 QFont readFontEntry( const char *pKey, const QFont* pDefault = 0L ) const;
00562
00574 bool readBoolEntry( const QString& pKey, bool bDefault = false ) const;
00575
00587 bool readBoolEntry( const char *pKey, bool bDefault = false ) const;
00588
00600 QRect readRectEntry( const QString& pKey, const QRect* pDefault = 0L ) const;
00601
00613 QRect readRectEntry( const char *pKey, const QRect* pDefault = 0L ) const;
00614
00626 QPoint readPointEntry( const QString& pKey, const QPoint* pDefault = 0L ) const;
00627
00639 QPoint readPointEntry( const char *pKey, const QPoint* pDefault = 0L ) const;
00640
00652 QSize readSizeEntry( const QString& pKey, const QSize* pDefault = 0L ) const;
00653
00665 QSize readSizeEntry( const char *pKey, const QSize* pDefault = 0L ) const;
00666
00667
00679 QColor readColorEntry( const QString& pKey, const QColor* pDefault = 0L ) const;
00680
00692 QColor readColorEntry( const char *pKey, const QColor* pDefault = 0L ) const;
00693
00706 QDateTime readDateTimeEntry( const QString& pKey, const QDateTime* pDefault = 0L ) const;
00707
00720 QDateTime readDateTimeEntry( const char *pKey, const QDateTime* pDefault = 0L ) const;
00721
00730 QString readEntryUntranslated( const QString& pKey,
00731 const QString& aDefault = QString::null ) const;
00732
00741 QString readEntryUntranslated( const char *pKey,
00742 const QString& aDefault = QString::null ) const;
00743
00763 void writeEntry( const QString& pKey, const QString& pValue,
00764 bool bPersistent = true, bool bGlobal = false,
00765 bool bNLS = false );
00766
00784 void writeEntry( const char *pKey, const QString& pValue,
00785 bool bPersistent = true, bool bGlobal = false,
00786 bool bNLS = false );
00787
00807 void writeEntry( const QString& pKey, const QVariant& rValue,
00808 bool bPersistent = true, bool bGlobal = false,
00809 bool bNLS = false );
00829 void writeEntry( const char *pKey, const QVariant& rValue,
00830 bool bPersistent = true, bool bGlobal = false,
00831 bool bNLS = false );
00832
00853 void writeEntry( const QString& pKey, const QStrList &rValue,
00854 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00875 void writeEntry( const char *pKey, const QStrList &rValue,
00876 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00877
00898 void writeEntry( const QString& pKey, const QStringList &rValue,
00899 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00920 void writeEntry( const char *pKey, const QStringList &rValue,
00921 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00922
00923
00943 void writeEntry( const QString& pKey, const QValueList<int>& rValue,
00944 bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00964 void writeEntry( const char *pKey, const QValueList<int>& rValue,
00965 bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00966
00984 void writeEntry( const QString& pKey, const char *pValue,
00985 bool bPersistent = true, bool bGlobal = false,
00986 bool bNLS = false )
00987 { writeEntry(pKey, QString::fromLatin1(pValue), bPersistent, bGlobal, bNLS); }
01005 void writeEntry( const char *pKey, const char *pValue,
01006 bool bPersistent = true, bool bGlobal = false,
01007 bool bNLS = false )
01008 { writeEntry(pKey, QString::fromLatin1(pValue), bPersistent, bGlobal, bNLS); }
01009
01025 void writeEntry( const QString& pKey, int nValue,
01026 bool bPersistent = true, bool bGlobal = false,
01027 bool bNLS = false );
01043 void writeEntry( const char *pKey, int nValue,
01044 bool bPersistent = true, bool bGlobal = false,
01045 bool bNLS = false );
01046
01062 void writeEntry( const QString& pKey, unsigned int nValue,
01063 bool bPersistent = true, bool bGlobal = false,
01064 bool bNLS = false );
01080 void writeEntry( const char *pKey, unsigned int nValue,
01081 bool bPersistent = true, bool bGlobal = false,
01082 bool bNLS = false );
01083
01098 void writeEntry( const QString& pKey, long nValue,
01099 bool bPersistent = true, bool bGlobal = false,
01100 bool bNLS = false );
01115 void writeEntry( const char *pKey, long nValue,
01116 bool bPersistent = true, bool bGlobal = false,
01117 bool bNLS = false );
01118
01133 void writeEntry( const QString& pKey, unsigned long nValue,
01134 bool bPersistent = true, bool bGlobal = false,
01135 bool bNLS = false );
01150 void writeEntry( const char *pKey, unsigned long nValue,
01151 bool bPersistent = true, bool bGlobal = false,
01152 bool bNLS = false );
01153
01168 void writeEntry( const QString& pKey, Q_INT64 nValue,
01169 bool bPersistent = true, bool bGlobal = false,
01170 bool bNLS = false );
01185 void writeEntry( const char *pKey, Q_INT64 nValue,
01186 bool bPersistent = true, bool bGlobal = false,
01187 bool bNLS = false );
01188
01203 void writeEntry( const QString& pKey, Q_UINT64 nValue,
01204 bool bPersistent = true, bool bGlobal = false,
01205 bool bNLS = false );
01220 void writeEntry( const char *pKey, Q_UINT64 nValue,
01221 bool bPersistent = true, bool bGlobal = false,
01222 bool bNLS = false );
01223
01241 void writeEntry( const QString& pKey, double nValue,
01242 bool bPersistent = true, bool bGlobal = false,
01243 char format = 'g', int precision = 6,
01244 bool bNLS = false );
01262 void writeEntry( const char *pKey, double nValue,
01263 bool bPersistent = true, bool bGlobal = false,
01264 char format = 'g', int precision = 6,
01265 bool bNLS = false );
01266
01281 void writeEntry( const QString& pKey, bool bValue,
01282 bool bPersistent = true, bool bGlobal = false,
01283 bool bNLS = false );
01298 void writeEntry( const char *pKey, bool bValue,
01299 bool bPersistent = true, bool bGlobal = false,
01300 bool bNLS = false );
01301
01316 void writeEntry( const QString& pKey, const QFont& rFont,
01317 bool bPersistent = true, bool bGlobal = false,
01318 bool bNLS = false );
01333 void writeEntry( const char *pKey, const QFont& rFont,
01334 bool bPersistent = true, bool bGlobal = false,
01335 bool bNLS = false );
01336
01354 void writeEntry( const QString& pKey, const QColor& rColor,
01355 bool bPersistent = true, bool bGlobal = false,
01356 bool bNLS = false );
01374 void writeEntry( const char *pKey, const QColor& rColor,
01375 bool bPersistent = true, bool bGlobal = false,
01376 bool bNLS = false );
01377
01395 void writeEntry( const QString& pKey, const QDateTime& rDateTime,
01396 bool bPersistent = true, bool bGlobal = false,
01397 bool bNLS = false );
01415 void writeEntry( const char *pKey, const QDateTime& rDateTime,
01416 bool bPersistent = true, bool bGlobal = false,
01417 bool bNLS = false );
01418
01419
01437 void writeEntry( const QString& pKey, const QRect& rValue,
01438 bool bPersistent = true, bool bGlobal = false,
01439 bool bNLS = false );
01457 void writeEntry( const char *pKey, const QRect& rValue,
01458 bool bPersistent = true, bool bGlobal = false,
01459 bool bNLS = false );
01460
01478 void writeEntry( const QString& pKey, const QPoint& rValue,
01479 bool bPersistent = true, bool bGlobal = false,
01480 bool bNLS = false );
01498 void writeEntry( const char *pKey, const QPoint& rValue,
01499 bool bPersistent = true, bool bGlobal = false,
01500 bool bNLS = false );
01501
01519 void writeEntry( const QString& pKey, const QSize& rValue,
01520 bool bPersistent = true, bool bGlobal = false,
01521 bool bNLS = false );
01539 void writeEntry( const char *pKey, const QSize& rValue,
01540 bool bPersistent = true, bool bGlobal = false,
01541 bool bNLS = false );
01542
01560 void writePathEntry( const QString& pKey, const QString & path,
01561 bool bPersistent = true, bool bGlobal = false,
01562 bool bNLS = false );
01580 void writePathEntry( const char *pKey, const QString & path,
01581 bool bPersistent = true, bool bGlobal = false,
01582 bool bNLS = false );
01583
01607 void writePathEntry( const QString& pKey, const QStringList &rValue,
01608 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
01632 void writePathEntry( const char *pKey, const QStringList &rValue,
01633 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
01634
01635
01644 void deleteEntry( const QString& pKey,
01645 bool bNLS = false, bool bGlobal = false);
01654 void deleteEntry( const char *pKey,
01655 bool bNLS = false, bool bGlobal = false);
01656
01674 bool deleteGroup( const QString& group, bool bDeep = true, bool bGlobal = false );
01675
01676
01684 void setDollarExpansion( bool _bExpand = true ) { bExpand = _bExpand; }
01685
01691 bool isDollarExpansion() const { return bExpand; }
01692
01707 virtual void rollback( bool bDeep = true );
01708
01722 virtual void sync();
01723
01728 bool isDirty() const { return bDirty; }
01729
01737 virtual void setReadOnly(bool _ro) { bReadOnly = _ro; }
01738
01744 bool isReadOnly() const { return bReadOnly; }
01745
01755 bool hasKey( const QString& key ) const;
01756
01767 virtual QMap<QString, QString> entryMap(const QString &group) const = 0;
01768
01781 virtual void reparseConfiguration() = 0;
01782
01787 bool isImmutable() const;
01788
01795 bool groupIsImmutable(const QString &group) const;
01796
01803 bool entryIsImmutable(const QString &key) const;
01804
01810 enum ConfigState { NoAccess, ReadOnly, ReadWrite };
01811
01825 ConfigState getConfigState() const;
01826
01833 bool checkConfigFilesWritable(bool warnUser);
01834
01841 void setReadDefaults(bool b);
01842
01848 bool readDefaults() const;
01849
01861 void revertToDefault(const QString &key);
01862
01889 bool hasDefault(const QString &key) const;
01890
01891 protected:
01897 void setLocale();
01898
01904 virtual void setDirty(bool _bDirty = true) { bDirty = _bDirty; }
01905
01911 virtual void parseConfigFiles();
01912
01928 virtual KEntryMap internalEntryMap( const QString& pGroup ) const = 0;
01929
01941 virtual KEntryMap internalEntryMap() const = 0;
01942
01958 virtual void putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup = true) = 0;
01959
01974 virtual KEntry lookupData(const KEntryKey &_key) const = 0;
01975
01976 virtual bool internalHasGroup(const QCString &group) const = 0;
01977
01981 KConfigBackEnd *backEnd;
01982 public:
01986 void setGroup( const QCString &pGroup );
01987 void setGroup( const char *pGroup );
01988 bool hasGroup(const QCString &_pGroup) const;
01989 bool hasGroup(const char *_pGroup) const;
01990 bool hasKey( const char *pKey ) const;
01991
01992 protected:
01993 QCString readEntryUtf8( const char *pKey) const;
01994
01997 QCString mGroup;
01998
02001 QCString aLocaleString;
02002
02006 bool bDirty;
02007
02008 bool bLocaleInitialized;
02009 bool bReadOnly;
02010 mutable bool bExpand;
02011
02012 protected:
02013 virtual void virtual_hook( int id, void* data );
02014 protected:
02015 class KConfigBasePrivate
02016 {
02017 public:
02018 KConfigBasePrivate() : readDefaults(false) { };
02019
02020 public:
02021 bool readDefaults;
02022 QPtrList<KConfigBackEnd> backEnds;
02023 };
02024
02025 KConfigBasePrivate *m_Private;
02026
02027 void writeEntry( const char *pKey, const QString &rValue,
02028 bool bPersistent, bool bGlobal, bool bNLS, bool bExpand );
02029 void writeEntry( const char *pKey, const QStringList &rValue,
02030 char sep, bool bPersistent, bool bGlobal, bool bNLS, bool bExpand );
02031
02032 };
02033
02034 class KConfigGroupSaverPrivate;
02035
02072 class KDECORE_EXPORT KConfigGroupSaver
02073 {
02074 public:
02084 KConfigGroupSaver( KConfigBase* config, QString group )
02085
02086 : _config(config), _oldgroup(config->group())
02087 { _config->setGroup( group ); }
02088
02089 KConfigGroupSaver( KConfigBase* config, const char *group )
02090 : _config(config), _oldgroup(config->group())
02091 { _config->setGroup( group ); }
02092
02093 KConfigGroupSaver( KConfigBase* config, const QCString &group )
02094 : _config(config), _oldgroup(config->group())
02095 { _config->setGroup( group ); }
02096
02097 ~KConfigGroupSaver() { _config->setGroup( _oldgroup ); }
02098
02099 KConfigBase* config() { return _config; };
02100
02101 private:
02102 KConfigBase* _config;
02103 QString _oldgroup;
02104
02105 KConfigGroupSaver(const KConfigGroupSaver&);
02106 KConfigGroupSaver& operator=(const KConfigGroupSaver&);
02107
02108 KConfigGroupSaverPrivate *d;
02109 };
02110
02111 class KConfigGroupPrivate;
02112
02116 class KDECORE_EXPORT KConfigGroup: public KConfigBase
02117 {
02118 public:
02123 KConfigGroup(KConfigBase *master, const QCString &group);
02130 KConfigGroup(KConfigBase *master, const QString &group);
02138 KConfigGroup(KConfigBase *master, const char * group);
02139
02146 void deleteGroup(bool bGlobal = false);
02147
02154 bool groupIsImmutable() const;
02155
02156
02157 virtual void setDirty(bool _bDirty);
02158 virtual void putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup = true);
02159 virtual KEntry lookupData(const KEntryKey &_key) const;
02160 virtual void sync();
02161
02162 private:
02163
02164 void setGroup() { }
02165 void setDesktopGroup() { }
02166 void group() { }
02167 void hasGroup() { }
02168 void setReadOnly(bool) { }
02169 void isDirty() { }
02170
02171
02172 virtual QStringList groupList() const { return QStringList(); }
02173 virtual void rollback(bool) { }
02174 virtual void reparseConfiguration() { }
02175 virtual QMap<QString, QString> entryMap(const QString &) const
02176 { return QMap<QString,QString>(); }
02177 virtual KEntryMap internalEntryMap( const QString&) const
02178 { return KEntryMap(); }
02179 virtual KEntryMap internalEntryMap() const
02180 { return KEntryMap(); }
02181 virtual bool internalHasGroup(const QCString &) const
02182 { return false; }
02183
02184 void getConfigState() { }
02185
02186 KConfigBase *mMaster;
02187 protected:
02188 virtual void virtual_hook( int id, void* data );
02189 private:
02190 KConfigGroupPrivate* d;
02191 };
02192
02193 #endif