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
00141 QString readEntry(const QString& pKey,
00142 const QString& aDefault = QString::null ) const;
00143
00151 QString readEntry(const char *pKey,
00152 const QString& aDefault = QString::null ) const;
00153
00167 QVariant readPropertyEntry( const QString& pKey, QVariant::Type ) const;
00168
00183 QVariant readPropertyEntry( const char *pKey, QVariant::Type ) const;
00184
00199 QVariant readPropertyEntry( const QString& pKey,
00200 const QVariant &aDefault) const;
00201
00216 QVariant readPropertyEntry( const char *pKey,
00217 const QVariant &aDefault) const;
00218
00229 int readListEntry( const QString& pKey, QStrList &list, char sep = ',' ) const;
00230
00241 int readListEntry( const char *pKey, QStrList &list, char sep = ',' ) const;
00242
00250 QStringList readListEntry( const QString& pKey, char sep = ',' ) const;
00251
00259 QStringList readListEntry( const char *pKey, char sep = ',' ) const;
00260
00270 QStringList readListEntry( const char* pKey, const QStringList& aDefault,
00271 char sep = ',' ) const;
00272
00279 QValueList<int> readIntListEntry( const QString& pKey ) const;
00280
00287 QValueList<int> readIntListEntry( const char *pKey ) const;
00288
00300 QString readPathEntry( const QString& pKey, const QString & aDefault = QString::null ) const;
00301
00313 QString readPathEntry( const char *pKey, const QString & aDefault = QString::null ) const;
00314
00327 QStringList readPathListEntry( const QString& pKey, char sep = ',' ) const;
00328
00341 QStringList readPathListEntry( const char *pKey, char sep = ',' ) const;
00342
00343
00355 int readNumEntry( const QString& pKey, int nDefault = 0 ) const;
00356
00368 int readNumEntry( const char *pKey, int nDefault = 0 ) const;
00369
00381 unsigned int readUnsignedNumEntry( const QString& pKey, unsigned int nDefault = 0 ) const;
00382
00394 unsigned int readUnsignedNumEntry( const char *pKey, unsigned int nDefault = 0 ) const;
00395
00396
00408 long readLongNumEntry( const QString& pKey, long nDefault = 0 ) const;
00409
00421 long readLongNumEntry( const char *pKey, long nDefault = 0 ) const;
00422
00434 unsigned long readUnsignedLongNumEntry( const QString& pKey, unsigned long nDefault = 0 ) const;
00435
00447 unsigned long readUnsignedLongNumEntry( const char *pKey, unsigned long nDefault = 0 ) const;
00448
00460 Q_INT64 readNum64Entry( const QString& pKey, Q_INT64 nDefault = 0 ) const;
00461
00473 Q_INT64 readNum64Entry( const char *pKey, Q_INT64 nDefault = 0 ) const;
00474
00486 Q_UINT64 readUnsignedNum64Entry( const QString& pKey, Q_UINT64 nDefault = 0 ) const;
00487
00499 Q_UINT64 readUnsignedNum64Entry( const char *pKey, Q_UINT64 nDefault = 0 ) const;
00500
00512 double readDoubleNumEntry( const QString& pKey, double nDefault = 0.0 ) const;
00513
00525 double readDoubleNumEntry( const char *pKey, double nDefault = 0.0 ) const;
00526
00538 QFont readFontEntry( const QString& pKey, const QFont* pDefault = 0L ) const;
00539
00551 QFont readFontEntry( const char *pKey, const QFont* pDefault = 0L ) const;
00552
00564 bool readBoolEntry( const QString& pKey, bool bDefault = false ) const;
00565
00577 bool readBoolEntry( const char *pKey, bool bDefault = false ) const;
00578
00590 QRect readRectEntry( const QString& pKey, const QRect* pDefault = 0L ) const;
00591
00603 QRect readRectEntry( const char *pKey, const QRect* pDefault = 0L ) const;
00604
00616 QPoint readPointEntry( const QString& pKey, const QPoint* pDefault = 0L ) const;
00617
00629 QPoint readPointEntry( const char *pKey, const QPoint* pDefault = 0L ) const;
00630
00642 QSize readSizeEntry( const QString& pKey, const QSize* pDefault = 0L ) const;
00643
00655 QSize readSizeEntry( const char *pKey, const QSize* pDefault = 0L ) const;
00656
00657
00669 QColor readColorEntry( const QString& pKey, const QColor* pDefault = 0L ) const;
00670
00682 QColor readColorEntry( const char *pKey, const QColor* pDefault = 0L ) const;
00683
00696 QDateTime readDateTimeEntry( const QString& pKey, const QDateTime* pDefault = 0L ) const;
00697
00710 QDateTime readDateTimeEntry( const char *pKey, const QDateTime* pDefault = 0L ) const;
00711
00720 QString readEntryUntranslated( const QString& pKey,
00721 const QString& aDefault = QString::null ) const;
00722
00731 QString readEntryUntranslated( const char *pKey,
00732 const QString& aDefault = QString::null ) const;
00733
00751 void writeEntry( const QString& pKey, const QString& pValue,
00752 bool bPersistent = true, bool bGlobal = false,
00753 bool bNLS = false );
00754
00772 void writeEntry( const char *pKey, const QString& pValue,
00773 bool bPersistent = true, bool bGlobal = false,
00774 bool bNLS = false );
00775
00795 void writeEntry( const QString& pKey, const QVariant& rValue,
00796 bool bPersistent = true, bool bGlobal = false,
00797 bool bNLS = false );
00817 void writeEntry( const char *pKey, const QVariant& rValue,
00818 bool bPersistent = true, bool bGlobal = false,
00819 bool bNLS = false );
00820
00841 void writeEntry( const QString& pKey, const QStrList &rValue,
00842 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00863 void writeEntry( const char *pKey, const QStrList &rValue,
00864 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00865
00886 void writeEntry( const QString& pKey, const QStringList &rValue,
00887 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00908 void writeEntry( const char *pKey, const QStringList &rValue,
00909 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00910
00911
00931 void writeEntry( const QString& pKey, const QValueList<int>& rValue,
00932 bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00952 void writeEntry( const char *pKey, const QValueList<int>& rValue,
00953 bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00954
00972 void writeEntry( const QString& pKey, const char *pValue,
00973 bool bPersistent = true, bool bGlobal = false,
00974 bool bNLS = false )
00975 { writeEntry(pKey, QString::fromLatin1(pValue), bPersistent, bGlobal, bNLS); }
00993 void writeEntry( const char *pKey, const char *pValue,
00994 bool bPersistent = true, bool bGlobal = false,
00995 bool bNLS = false )
00996 { writeEntry(pKey, QString::fromLatin1(pValue), bPersistent, bGlobal, bNLS); }
00997
01013 void writeEntry( const QString& pKey, int nValue,
01014 bool bPersistent = true, bool bGlobal = false,
01015 bool bNLS = false );
01031 void writeEntry( const char *pKey, int nValue,
01032 bool bPersistent = true, bool bGlobal = false,
01033 bool bNLS = false );
01034
01050 void writeEntry( const QString& pKey, unsigned int nValue,
01051 bool bPersistent = true, bool bGlobal = false,
01052 bool bNLS = false );
01068 void writeEntry( const char *pKey, unsigned int nValue,
01069 bool bPersistent = true, bool bGlobal = false,
01070 bool bNLS = false );
01071
01086 void writeEntry( const QString& pKey, long nValue,
01087 bool bPersistent = true, bool bGlobal = false,
01088 bool bNLS = false );
01103 void writeEntry( const char *pKey, long nValue,
01104 bool bPersistent = true, bool bGlobal = false,
01105 bool bNLS = false );
01106
01121 void writeEntry( const QString& pKey, unsigned long nValue,
01122 bool bPersistent = true, bool bGlobal = false,
01123 bool bNLS = false );
01138 void writeEntry( const char *pKey, unsigned long nValue,
01139 bool bPersistent = true, bool bGlobal = false,
01140 bool bNLS = false );
01141
01156 void writeEntry( const QString& pKey, Q_INT64 nValue,
01157 bool bPersistent = true, bool bGlobal = false,
01158 bool bNLS = false );
01173 void writeEntry( const char *pKey, Q_INT64 nValue,
01174 bool bPersistent = true, bool bGlobal = false,
01175 bool bNLS = false );
01176
01191 void writeEntry( const QString& pKey, Q_UINT64 nValue,
01192 bool bPersistent = true, bool bGlobal = false,
01193 bool bNLS = false );
01208 void writeEntry( const char *pKey, Q_UINT64 nValue,
01209 bool bPersistent = true, bool bGlobal = false,
01210 bool bNLS = false );
01211
01229 void writeEntry( const QString& pKey, double nValue,
01230 bool bPersistent = true, bool bGlobal = false,
01231 char format = 'g', int precision = 6,
01232 bool bNLS = false );
01250 void writeEntry( const char *pKey, double nValue,
01251 bool bPersistent = true, bool bGlobal = false,
01252 char format = 'g', int precision = 6,
01253 bool bNLS = false );
01254
01269 void writeEntry( const QString& pKey, bool bValue,
01270 bool bPersistent = true, bool bGlobal = false,
01271 bool bNLS = false );
01286 void writeEntry( const char *pKey, bool bValue,
01287 bool bPersistent = true, bool bGlobal = false,
01288 bool bNLS = false );
01289
01304 void writeEntry( const QString& pKey, const QFont& rFont,
01305 bool bPersistent = true, bool bGlobal = false,
01306 bool bNLS = false );
01321 void writeEntry( const char *pKey, const QFont& rFont,
01322 bool bPersistent = true, bool bGlobal = false,
01323 bool bNLS = false );
01324
01342 void writeEntry( const QString& pKey, const QColor& rColor,
01343 bool bPersistent = true, bool bGlobal = false,
01344 bool bNLS = false );
01362 void writeEntry( const char *pKey, const QColor& rColor,
01363 bool bPersistent = true, bool bGlobal = false,
01364 bool bNLS = false );
01365
01383 void writeEntry( const QString& pKey, const QDateTime& rDateTime,
01384 bool bPersistent = true, bool bGlobal = false,
01385 bool bNLS = false );
01403 void writeEntry( const char *pKey, const QDateTime& rDateTime,
01404 bool bPersistent = true, bool bGlobal = false,
01405 bool bNLS = false );
01406
01407
01425 void writeEntry( const QString& pKey, const QRect& rValue,
01426 bool bPersistent = true, bool bGlobal = false,
01427 bool bNLS = false );
01445 void writeEntry( const char *pKey, const QRect& rValue,
01446 bool bPersistent = true, bool bGlobal = false,
01447 bool bNLS = false );
01448
01466 void writeEntry( const QString& pKey, const QPoint& rValue,
01467 bool bPersistent = true, bool bGlobal = false,
01468 bool bNLS = false );
01486 void writeEntry( const char *pKey, const QPoint& rValue,
01487 bool bPersistent = true, bool bGlobal = false,
01488 bool bNLS = false );
01489
01507 void writeEntry( const QString& pKey, const QSize& rValue,
01508 bool bPersistent = true, bool bGlobal = false,
01509 bool bNLS = false );
01527 void writeEntry( const char *pKey, const QSize& rValue,
01528 bool bPersistent = true, bool bGlobal = false,
01529 bool bNLS = false );
01530
01548 void writePathEntry( const QString& pKey, const QString & path,
01549 bool bPersistent = true, bool bGlobal = false,
01550 bool bNLS = false );
01568 void writePathEntry( const char *pKey, const QString & path,
01569 bool bPersistent = true, bool bGlobal = false,
01570 bool bNLS = false );
01571
01595 void writePathEntry( const QString& pKey, const QStringList &rValue,
01596 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
01620 void writePathEntry( const char *pKey, const QStringList &rValue,
01621 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
01622
01623
01632 void deleteEntry( const QString& pKey,
01633 bool bNLS = false, bool bGlobal = false);
01642 void deleteEntry( const char *pKey,
01643 bool bNLS = false, bool bGlobal = false);
01644
01662 bool deleteGroup( const QString& group, bool bDeep = true, bool bGlobal = false );
01663
01664
01672 void setDollarExpansion( bool _bExpand = true ) { bExpand = _bExpand; }
01673
01679 bool isDollarExpansion() const { return bExpand; }
01680
01695 virtual void rollback( bool bDeep = true );
01696
01710 virtual void sync();
01711
01716 bool isDirty() const { return bDirty; }
01717
01725 virtual void setReadOnly(bool _ro) { bReadOnly = _ro; }
01726
01732 bool isReadOnly() const { return bReadOnly; }
01733
01743 bool hasKey( const QString& key ) const;
01744
01755 virtual QMap<QString, QString> entryMap(const QString &group) const = 0;
01756
01769 virtual void reparseConfiguration() = 0;
01770
01775 bool isImmutable() const;
01776
01783 bool groupIsImmutable(const QString &group) const;
01784
01791 bool entryIsImmutable(const QString &key) const;
01792
01798 enum ConfigState { NoAccess, ReadOnly, ReadWrite };
01799
01813 ConfigState getConfigState() const;
01814
01821 bool checkConfigFilesWritable(bool warnUser);
01822
01829 void setReadDefaults(bool b);
01830
01836 bool readDefaults() const;
01837
01849 void revertToDefault(const QString &key);
01850
01877 bool hasDefault(const QString &key) const;
01878
01879 protected:
01885 void setLocale();
01886
01892 virtual void setDirty(bool _bDirty = true) { bDirty = _bDirty; }
01893
01899 virtual void parseConfigFiles();
01900
01916 virtual KEntryMap internalEntryMap( const QString& pGroup ) const = 0;
01917
01929 virtual KEntryMap internalEntryMap() const = 0;
01930
01946 virtual void putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup = true) = 0;
01947
01962 virtual KEntry lookupData(const KEntryKey &_key) const = 0;
01963
01964 virtual bool internalHasGroup(const QCString &group) const = 0;
01965
01969 KConfigBackEnd *backEnd;
01970 public:
01974 void setGroup( const QCString &pGroup );
01975 void setGroup( const char *pGroup );
01976 bool hasGroup(const QCString &_pGroup) const;
01977 bool hasGroup(const char *_pGroup) const;
01978 bool hasKey( const char *pKey ) const;
01979
01980 protected:
01981 QCString readEntryUtf8( const char *pKey) const;
01982
01985 QCString mGroup;
01986
01989 QCString aLocaleString;
01990
01994 bool bDirty;
01995
01996 bool bLocaleInitialized;
01997 bool bReadOnly;
01998 mutable bool bExpand;
01999
02000 protected:
02001 virtual void virtual_hook( int id, void* data );
02002 private:
02003 class KConfigBasePrivate;
02004 KConfigBasePrivate *d;
02005 };
02006
02007 class KConfigGroupSaverPrivate;
02008
02045 class KConfigGroupSaver
02046 {
02047 public:
02057 KConfigGroupSaver( KConfigBase* config, QString group )
02058
02059 : _config(config), _oldgroup(config->group())
02060 { _config->setGroup( group ); }
02061
02062 KConfigGroupSaver( KConfigBase* config, const char *group )
02063 : _config(config), _oldgroup(config->group())
02064 { _config->setGroup( group ); }
02065
02066 KConfigGroupSaver( KConfigBase* config, const QCString &group )
02067 : _config(config), _oldgroup(config->group())
02068 { _config->setGroup( group ); }
02069
02070 ~KConfigGroupSaver() { _config->setGroup( _oldgroup ); }
02071
02072 KConfigBase* config() { return _config; };
02073
02074 private:
02075 KConfigBase* _config;
02076 QString _oldgroup;
02077
02078 KConfigGroupSaver(const KConfigGroupSaver&);
02079 KConfigGroupSaver& operator=(const KConfigGroupSaver&);
02080
02081 KConfigGroupSaverPrivate *d;
02082 };
02083
02084 class KConfigGroupPrivate;
02085
02089 class KConfigGroup: public KConfigBase
02090 {
02091 public:
02096 KConfigGroup(KConfigBase *master, const QCString &group);
02103 KConfigGroup(KConfigBase *master, const QString &group);
02111 KConfigGroup(KConfigBase *master, const char * group);
02112
02119 void deleteGroup(bool bGlobal = false);
02120
02121
02122 virtual void setDirty(bool b);
02123 virtual void putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup = true);
02124 virtual KEntry lookupData(const KEntryKey &_key) const;
02125 virtual void sync();
02126
02127 private:
02128
02129 void setGroup() { }
02130 void setDesktopGroup() { }
02131 void group() { }
02132 void hasGroup() { }
02133 void setReadOnly(bool) { }
02134 void isDirty() { }
02135
02136
02137 virtual QStringList groupList() const { return QStringList(); }
02138 virtual void rollback(bool) { }
02139 virtual void reparseConfiguration() { }
02140 virtual QMap<QString, QString> entryMap(const QString &) const
02141 { return QMap<QString,QString>(); }
02142 virtual KEntryMap internalEntryMap( const QString&) const
02143 { return KEntryMap(); }
02144 virtual KEntryMap internalEntryMap() const
02145 { return KEntryMap(); }
02146 virtual bool internalHasGroup(const QCString &) const
02147 { return false; }
02148
02149 void getConfigState() { }
02150
02151 KConfigBase *mMaster;
02152 protected:
02153 virtual void virtual_hook( int id, void* data );
02154 private:
02155 KConfigGroupPrivate* d;
02156 };
02157
02158 #endif