00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028 #ifndef _KCONFIGBASE_H
00029 #define _KCONFIGBASE_H
00030
00031 #include <vector>
00032 #include "kconfigdata.h"
00033 using std::vector;
00034
00035 namespace config {
00036
00037 class KConfigBackEnd;
00038 class KConfigBasePrivate;
00039 class KConfigGroup;
00040
00065 class KConfigBase
00066 {
00067
00068 friend class KConfigBackEnd;
00069 friend class KConfigINIBackEnd;
00070 friend class KConfigGroup;
00071
00072 public:
00076 KConfigBase();
00077
00081 virtual ~KConfigBase();
00082
00093 void setGroup( const string& group );
00094 void setGroup( const char* group );
00095
00102 string group() const;
00103
00110 bool hasGroup(const string &group) const;
00111
00117 virtual vector<string> groupList() const = 0;
00118
00124 string locale() const;
00125
00133 string readEntry( const string& pKey,
00134 const string& aDefault = "" ) const;
00135 string readEntry( const char *pKey,
00136 const string& aDefault = "" ) const;
00137
00138
00149 int readListEntry( const string& pKey, vector<string> &list, char sep = ',' ) const;
00150 int readListEntry( const char *pKey, vector<string> &list, char sep = ',' ) const;
00151
00159 vector<string> readListEntry( const string& pKey, char sep = ',' ) const;
00160 vector<string> readListEntry( const char *pKey, char sep = ',' ) const;
00161
00168 vector<int> readIntListEntry( const string& pKey ) const;
00169 vector<int> readIntListEntry( const char *pKey ) const;
00170
00182 string readPathEntry( const string& pKey, const string & aDefault = "" ) const;
00183 string readPathEntry( const char *pKey, const string & aDefault = "" ) const;
00184
00196 int readNumEntry( const string& pKey, int nDefault = 0 ) const;
00197 int readNumEntry( const char *pKey, int nDefault = 0 ) const;
00198
00210 unsigned int readUnsignedNumEntry( const string& pKey, unsigned int nDefault = 0 ) const;
00211 unsigned int readUnsignedNumEntry( const char *pKey, unsigned int nDefault = 0 ) const;
00212
00213
00225 long readLongNumEntry( const string& pKey, long nDefault = 0 ) const;
00226 long readLongNumEntry( const char *pKey, long nDefault = 0 ) const;
00227
00239 unsigned long readUnsignedLongNumEntry( const string& pKey, unsigned long nDefault = 0 ) const;
00240 unsigned long readUnsignedLongNumEntry( const char *pKey, unsigned long nDefault = 0 ) const;
00241
00253 double readDoubleNumEntry( const string& pKey, double nDefault = 0.0 ) const;
00254 double readDoubleNumEntry( const char *pKey, double nDefault = 0.0 ) const;
00255
00267 bool readBoolEntry( const string& pKey, const bool bDefault = false ) const;
00268 bool readBoolEntry( const char *pKey, const bool bDefault = false ) const;
00269
00278 string readEntryUntranslated( const string& pKey,
00279 const string& aDefault = "" ) const;
00280 string readEntryUntranslated( const char *pKey,
00281 const string& aDefault = "" ) const;
00282
00300 void writeEntry( const string& pKey, const string& pValue,
00301 bool bPersistent = true, bool bGlobal = false,
00302 bool bNLS = false );
00303
00304 void writeEntry( const char *pKey, const string& pValue,
00305 bool bPersistent = true, bool bGlobal = false,
00306 bool bNLS = false );
00307
00327 void writeEntry( const string& pKey, const vector<string> &rValue,
00328 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00329 void writeEntry( const char *pKey, const vector<string> &rValue,
00330 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00331
00332
00352 void writeEntry( const string& pKey, const vector<int>& rValue,
00353 bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00354 void writeEntry( const char *pKey, const vector<int>& rValue,
00355 bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00356
00374 void writeEntry( const string& pKey, const char *pValue,
00375 bool bPersistent = true, bool bGlobal = false,
00376 bool bNLS = false )
00377 { writeEntry(pKey, string(pValue), bPersistent, bGlobal, bNLS); }
00378 void writeEntry( const char *pKey, const char *pValue,
00379 bool bPersistent = true, bool bGlobal = false,
00380 bool bNLS = false )
00381 { writeEntry(pKey, string(pValue), bPersistent, bGlobal, bNLS); }
00382
00398 void writeEntry( const string& pKey, int nValue,
00399 bool bPersistent = true, bool bGlobal = false,
00400 bool bNLS = false );
00401 void writeEntry( const char *pKey, int nValue,
00402 bool bPersistent = true, bool bGlobal = false,
00403 bool bNLS = false );
00404
00420 void writeEntry( const string& pKey, unsigned int nValue,
00421 bool bPersistent = true, bool bGlobal = false,
00422 bool bNLS = false );
00423 void writeEntry( const char *pKey, unsigned int nValue,
00424 bool bPersistent = true, bool bGlobal = false,
00425 bool bNLS = false );
00426
00441 void writeEntry( const string& pKey, long nValue,
00442 bool bPersistent = true, bool bGlobal = false,
00443 bool bNLS = false );
00444 void writeEntry( const char *pKey, long nValue,
00445 bool bPersistent = true, bool bGlobal = false,
00446 bool bNLS = false );
00447
00462 void writeEntry( const string& pKey, unsigned long nValue,
00463 bool bPersistent = true, bool bGlobal = false,
00464 bool bNLS = false );
00465 void writeEntry( const char *pKey, unsigned long nValue,
00466 bool bPersistent = true, bool bGlobal = false,
00467 bool bNLS = false );
00468
00486 void writeEntry( const string& pKey, double nValue,
00487 bool bPersistent = true, bool bGlobal = false,
00488 char format = 'g', int precision = 6,
00489 bool bNLS = false );
00490 void writeEntry( const char *pKey, double nValue,
00491 bool bPersistent = true, bool bGlobal = false,
00492 char format = 'g', int precision = 6,
00493 bool bNLS = false );
00494
00509 void writeEntry( const string& pKey, bool bValue,
00510 bool bPersistent = true, bool bGlobal = false,
00511 bool bNLS = false );
00512 void writeEntry( const char *pKey, bool bValue,
00513 bool bPersistent = true, bool bGlobal = false,
00514 bool bNLS = false );
00515
00533 void writePathEntry( const string& pKey, const string & path,
00534 bool bPersistent = true, bool bGlobal = false,
00535 bool bNLS = false );
00536 void writePathEntry( const char *pKey, const string & path,
00537 bool bPersistent = true, bool bGlobal = false,
00538 bool bNLS = false );
00539
00548 void deleteEntry( const string& pKey,
00549 bool bNLS = false, bool bGlobal = false);
00550 void deleteEntry( const char *pKey,
00551 bool bNLS = false, bool bGlobal = false);
00552
00570 bool deleteGroup( const string& group, bool bDeep = true, bool bGlobal = false );
00571
00579 void setDollarExpansion( bool _bExpand = true ) { bExpand = _bExpand; }
00580
00586 bool isDollarExpansion() const { return bExpand; }
00587
00602 virtual void rollback( bool bDeep = true );
00603
00617 virtual void sync();
00618
00622 bool isDirty() const { return bDirty; }
00623
00631 virtual void setReadOnly(bool _ro) { bReadOnly = _ro; }
00632
00638 bool isReadOnly() const { return bReadOnly; }
00639
00649 bool hasKey( const string& key ) const;
00650
00661 virtual map<string, string> entryMap(const string &group) const = 0;
00662
00675 virtual void reparseConfiguration() = 0;
00676
00680 bool isImmutable() const;
00681
00686 bool groupIsImmutable(const string &group) const;
00687
00692 bool entryIsImmutable(const string &key) const;
00693
00699 enum ConfigState { NoAccess, ReadOnly, ReadWrite };
00700
00713 ConfigState getConfigState() const;
00714
00715 protected:
00721 void setLocale();
00722
00728 virtual void setDirty(bool _bDirty = true) { bDirty = _bDirty; }
00729
00735 virtual void parseConfigFiles();
00736
00752 virtual KEntryMap internalEntryMap( const string& pGroup ) const = 0;
00753
00765 virtual KEntryMap internalEntryMap() const = 0;
00766
00782 virtual void putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup = true) = 0;
00783
00798 virtual KEntry lookupData(const KEntryKey &_key) const = 0;
00799
00800 virtual bool internalHasGroup(const string &group) const = 0;
00801
00805 KConfigBackEnd *backEnd;
00806 public:
00810
00811 bool hasGroup(const char *_pGroup) const;
00812 bool hasKey( const char *pKey ) const;
00813
00814 protected:
00815 string readEntryUtf8( const char *pKey) const;
00816
00819 string mGroup;
00820
00823 string aLocaleString;
00824
00828 bool bDirty;
00829
00830 bool bLocaleInitialized;
00831 bool bReadOnly;
00832 mutable bool bExpand;
00833
00834 protected:
00835 virtual void virtual_hook( int id, void* data );
00836 private:
00837 KConfigBasePrivate *d;
00838 };
00839
00840 class KConfigGroupSaverPrivate;
00841
00875 class KConfigGroupSaver
00876 {
00877 public:
00886 KConfigGroupSaver( KConfigBase* config, string group )
00887 : _config(config), _oldgroup(config->group())
00888 { _config->setGroup( group ); }
00889
00890 KConfigGroupSaver( KConfigBase* config, const char *group )
00891 : _config(config), _oldgroup(config->group())
00892 { _config->setGroup( group ); }
00893
00894 KConfigGroupSaver( KConfigBase* config, const string &group )
00895 : _config(config), _oldgroup(config->group())
00896 { _config->setGroup( group ); }
00897
00898 ~KConfigGroupSaver() { _config->setGroup( _oldgroup ); }
00899
00900 KConfigBase* config() { return _config; };
00901
00902 private:
00903 KConfigBase* _config;
00904 string _oldgroup;
00905
00906 KConfigGroupSaver(const KConfigGroupSaver&);
00907 KConfigGroupSaver& operator=(const KConfigGroupSaver&);
00908
00909 KConfigGroupSaverPrivate *d;
00910 };
00911
00912 class KConfigGroupPrivate;
00913
00914 class KConfigGroup: public KConfigBase
00915 {
00916 public:
00921 KConfigGroup(KConfigBase *master, const string &group);
00929 KConfigGroup(KConfigBase *master, const char * group);
00930
00937 void deleteGroup(bool bGlobal = false);
00938
00939
00940 virtual void setDirty(bool b);
00941 virtual void putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup = true);
00942 virtual KEntry lookupData(const KEntryKey &_key) const;
00943 virtual void sync();
00944
00945 private:
00946
00947 void setGroup() { }
00948 void setDesktopGroup() { }
00949 void group() { }
00950 void hasGroup() { }
00951 void setReadOnly(bool) { }
00952 void isDirty() { }
00953
00954
00955 virtual vector<string> groupList() const { return vector<string>(); }
00956 virtual void rollback(bool) { }
00957 virtual void reparseConfiguration() { }
00958 virtual map<string, string> entryMap(const string &) const
00959 { return map<string,string>(); }
00960 virtual KEntryMap internalEntryMap( const string&) const
00961 { return KEntryMap(); }
00962 virtual KEntryMap internalEntryMap() const
00963 { return KEntryMap(); }
00964 virtual bool internalHasGroup(const string &) const
00965 { return false; }
00966
00967 void getConfigState() { }
00968
00969 KConfigBase *mMaster;
00970 protected:
00971 virtual void virtual_hook( int id, void* data );
00972 private:
00973 KConfigGroupPrivate* d;
00974 };
00975 };
00976
00977 #endif