00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023 #ifndef _TDECONFIGBASE_H
00024 #define _TDECONFIGBASE_H
00025
00026 #include <tqobject.h>
00027 #include <tqcolor.h>
00028 #include <tqfont.h>
00029 #include <tqdatetime.h>
00030 #include <tqstrlist.h>
00031 #include <tqstringlist.h>
00032 #include <tqvariant.h>
00033 #include <tqmap.h>
00034
00035 #include "tdeconfigdata.h"
00036 #include "tdelibs_export.h"
00037
00038 class TDEConfigBackEnd;
00039 class TDEConfigBasePrivate;
00040 class TDEConfigGroup;
00041
00070 class TDECORE_EXPORT TDEConfigBase : public TQObject
00071 {
00072 Q_OBJECT
00073
00074
00075 friend class TDEConfigBackEnd;
00076 friend class TDEConfigINIBackEnd;
00077 friend class TDEConfigGroup;
00078
00079 public:
00083 TDEConfigBase();
00084
00088 virtual ~TDEConfigBase();
00089
00100 void setGroup( const TQString& group );
00101
00106 void setDesktopGroup();
00107
00114 TQString group() const;
00115
00122 bool hasGroup(const TQString &group) const;
00123
00129 virtual TQStringList groupList() const = 0;
00130
00136 TQString locale() const;
00137
00146 TQString readEntry(const TQString& pKey,
00147 const TQString& aDefault = TQString::null ) const;
00148
00156 TQString readEntry(const char *pKey,
00157 const TQString& aDefault = TQString::null ) const;
00158
00172 TQVariant readPropertyEntry( const TQString& pKey, TQVariant::Type ) const;
00173
00188 TQVariant readPropertyEntry( const char *pKey, TQVariant::Type ) const;
00189
00204 TQVariant readPropertyEntry( const TQString& pKey,
00205 const TQVariant &aDefault) const;
00206
00221 TQVariant readPropertyEntry( const char *pKey,
00222 const TQVariant &aDefault) const;
00223
00234 int readListEntry( const TQString& pKey, TQStrList &list, char sep = ',' ) const;
00235
00246 int readListEntry( const char *pKey, TQStrList &list, char sep = ',' ) const;
00247
00255 TQStringList readListEntry( const TQString& pKey, char sep = ',' ) const;
00256
00264 TQStringList readListEntry( const char *pKey, char sep = ',' ) const;
00265
00275 TQStringList readListEntry( const char* pKey, const TQStringList& aDefault,
00276 char sep = ',' ) const;
00277
00284 TQValueList<int> readIntListEntry( const TQString& pKey ) const;
00285
00292 TQValueList<int> readIntListEntry( const char *pKey ) const;
00293
00305 TQString readPathEntry( const TQString& pKey, const TQString & aDefault = TQString::null ) const;
00306
00318 TQString readPathEntry( const char *pKey, const TQString & aDefault = TQString::null ) const;
00319
00332 TQStringList readPathListEntry( const TQString& pKey, char sep = ',' ) const;
00333
00346 TQStringList readPathListEntry( const char *pKey, char sep = ',' ) const;
00347
00348
00360 int readNumEntry( const TQString& pKey, int nDefault = 0 ) const;
00361
00373 int readNumEntry( const char *pKey, int nDefault = 0 ) const;
00374
00386 unsigned int readUnsignedNumEntry( const TQString& pKey, unsigned int nDefault = 0 ) const;
00387
00399 unsigned int readUnsignedNumEntry( const char *pKey, unsigned int nDefault = 0 ) const;
00400
00401
00413 long readLongNumEntry( const TQString& pKey, long nDefault = 0 ) const;
00414
00426 long readLongNumEntry( const char *pKey, long nDefault = 0 ) const;
00427
00439 unsigned long readUnsignedLongNumEntry( const TQString& pKey, unsigned long nDefault = 0 ) const;
00440
00452 unsigned long readUnsignedLongNumEntry( const char *pKey, unsigned long nDefault = 0 ) const;
00453
00465 TQ_INT64 readNum64Entry( const TQString& pKey, TQ_INT64 nDefault = 0 ) const;
00466
00478 TQ_INT64 readNum64Entry( const char *pKey, TQ_INT64 nDefault = 0 ) const;
00479
00491 TQ_UINT64 readUnsignedNum64Entry( const TQString& pKey, TQ_UINT64 nDefault = 0 ) const;
00492
00504 TQ_UINT64 readUnsignedNum64Entry( const char *pKey, TQ_UINT64 nDefault = 0 ) const;
00505
00517 double readDoubleNumEntry( const TQString& pKey, double nDefault = 0.0 ) const;
00518
00530 double readDoubleNumEntry( const char *pKey, double nDefault = 0.0 ) const;
00531
00543 TQFont readFontEntry( const TQString& pKey, const TQFont* pDefault = 0L ) const;
00544
00556 TQFont readFontEntry( const char *pKey, const TQFont* pDefault = 0L ) const;
00557
00569 bool readBoolEntry( const TQString& pKey, bool bDefault = false ) const;
00570
00582 bool readBoolEntry( const char *pKey, bool bDefault = false ) const;
00583
00595 TQRect readRectEntry( const TQString& pKey, const TQRect* pDefault = 0L ) const;
00596
00608 TQRect readRectEntry( const char *pKey, const TQRect* pDefault = 0L ) const;
00609
00621 TQPoint readPointEntry( const TQString& pKey, const TQPoint* pDefault = 0L ) const;
00622
00634 TQPoint readPointEntry( const char *pKey, const TQPoint* pDefault = 0L ) const;
00635
00647 TQSize readSizeEntry( const TQString& pKey, const TQSize* pDefault = 0L ) const;
00648
00660 TQSize readSizeEntry( const char *pKey, const TQSize* pDefault = 0L ) const;
00661
00662
00674 TQColor readColorEntry( const TQString& pKey, const TQColor* pDefault = 0L ) const;
00675
00687 TQColor readColorEntry( const char *pKey, const TQColor* pDefault = 0L ) const;
00688
00701 TQDateTime readDateTimeEntry( const TQString& pKey, const TQDateTime* pDefault = 0L ) const;
00702
00715 TQDateTime readDateTimeEntry( const char *pKey, const TQDateTime* pDefault = 0L ) const;
00716
00725 TQString readEntryUntranslated( const TQString& pKey,
00726 const TQString& aDefault = TQString::null ) const;
00727
00736 TQString readEntryUntranslated( const char *pKey,
00737 const TQString& aDefault = TQString::null ) const;
00738
00758 void writeEntry( const TQString& pKey, const TQString& pValue,
00759 bool bPersistent = true, bool bGlobal = false,
00760 bool bNLS = false );
00761
00779 void writeEntry( const char *pKey, const TQString& pValue,
00780 bool bPersistent = true, bool bGlobal = false,
00781 bool bNLS = false );
00782
00802 void writeEntry( const TQString& pKey, const TQVariant& rValue,
00803 bool bPersistent = true, bool bGlobal = false,
00804 bool bNLS = false );
00824 void writeEntry( const char *pKey, const TQVariant& rValue,
00825 bool bPersistent = true, bool bGlobal = false,
00826 bool bNLS = false );
00827
00848 void writeEntry( const TQString& pKey, const TQStrList &rValue,
00849 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00870 void writeEntry( const char *pKey, const TQStrList &rValue,
00871 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00872
00893 void writeEntry( const TQString& pKey, const TQStringList &rValue,
00894 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00915 void writeEntry( const char *pKey, const TQStringList &rValue,
00916 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00917
00918
00938 void writeEntry( const TQString& pKey, const TQValueList<int>& rValue,
00939 bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00959 void writeEntry( const char *pKey, const TQValueList<int>& rValue,
00960 bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00961
00979 void writeEntry( const TQString& pKey, const char *pValue,
00980 bool bPersistent = true, bool bGlobal = false,
00981 bool bNLS = false )
00982 { writeEntry(pKey, TQString::fromLatin1(pValue), bPersistent, bGlobal, bNLS); }
01000 void writeEntry( const char *pKey, const char *pValue,
01001 bool bPersistent = true, bool bGlobal = false,
01002 bool bNLS = false )
01003 { writeEntry(pKey, TQString::fromLatin1(pValue), bPersistent, bGlobal, bNLS); }
01004
01020 void writeEntry( const TQString& pKey, int nValue,
01021 bool bPersistent = true, bool bGlobal = false,
01022 bool bNLS = false );
01038 void writeEntry( const char *pKey, int nValue,
01039 bool bPersistent = true, bool bGlobal = false,
01040 bool bNLS = false );
01041
01057 void writeEntry( const TQString& pKey, unsigned int nValue,
01058 bool bPersistent = true, bool bGlobal = false,
01059 bool bNLS = false );
01075 void writeEntry( const char *pKey, unsigned int nValue,
01076 bool bPersistent = true, bool bGlobal = false,
01077 bool bNLS = false );
01078
01093 void writeEntry( const TQString& pKey, long nValue,
01094 bool bPersistent = true, bool bGlobal = false,
01095 bool bNLS = false );
01110 void writeEntry( const char *pKey, long nValue,
01111 bool bPersistent = true, bool bGlobal = false,
01112 bool bNLS = false );
01113
01128 void writeEntry( const TQString& pKey, unsigned long nValue,
01129 bool bPersistent = true, bool bGlobal = false,
01130 bool bNLS = false );
01145 void writeEntry( const char *pKey, unsigned long nValue,
01146 bool bPersistent = true, bool bGlobal = false,
01147 bool bNLS = false );
01148
01163 void writeEntry( const TQString& pKey, TQ_INT64 nValue,
01164 bool bPersistent = true, bool bGlobal = false,
01165 bool bNLS = false );
01180 void writeEntry( const char *pKey, TQ_INT64 nValue,
01181 bool bPersistent = true, bool bGlobal = false,
01182 bool bNLS = false );
01183
01198 void writeEntry( const TQString& pKey, TQ_UINT64 nValue,
01199 bool bPersistent = true, bool bGlobal = false,
01200 bool bNLS = false );
01215 void writeEntry( const char *pKey, TQ_UINT64 nValue,
01216 bool bPersistent = true, bool bGlobal = false,
01217 bool bNLS = false );
01218
01236 void writeEntry( const TQString& pKey, double nValue,
01237 bool bPersistent = true, bool bGlobal = false,
01238 char format = 'g', int precision = 6,
01239 bool bNLS = false );
01257 void writeEntry( const char *pKey, double nValue,
01258 bool bPersistent = true, bool bGlobal = false,
01259 char format = 'g', int precision = 6,
01260 bool bNLS = false );
01261
01276 void writeEntry( const TQString& pKey, bool bValue,
01277 bool bPersistent = true, bool bGlobal = false,
01278 bool bNLS = false );
01293 void writeEntry( const char *pKey, bool bValue,
01294 bool bPersistent = true, bool bGlobal = false,
01295 bool bNLS = false );
01296
01311 void writeEntry( const TQString& pKey, const TQFont& rFont,
01312 bool bPersistent = true, bool bGlobal = false,
01313 bool bNLS = false );
01328 void writeEntry( const char *pKey, const TQFont& rFont,
01329 bool bPersistent = true, bool bGlobal = false,
01330 bool bNLS = false );
01331
01349 void writeEntry( const TQString& pKey, const TQColor& rColor,
01350 bool bPersistent = true, bool bGlobal = false,
01351 bool bNLS = false );
01369 void writeEntry( const char *pKey, const TQColor& rColor,
01370 bool bPersistent = true, bool bGlobal = false,
01371 bool bNLS = false );
01372
01390 void writeEntry( const TQString& pKey, const TQDateTime& rDateTime,
01391 bool bPersistent = true, bool bGlobal = false,
01392 bool bNLS = false );
01410 void writeEntry( const char *pKey, const TQDateTime& rDateTime,
01411 bool bPersistent = true, bool bGlobal = false,
01412 bool bNLS = false );
01413
01414
01432 void writeEntry( const TQString& pKey, const TQRect& rValue,
01433 bool bPersistent = true, bool bGlobal = false,
01434 bool bNLS = false );
01452 void writeEntry( const char *pKey, const TQRect& rValue,
01453 bool bPersistent = true, bool bGlobal = false,
01454 bool bNLS = false );
01455
01473 void writeEntry( const TQString& pKey, const TQPoint& rValue,
01474 bool bPersistent = true, bool bGlobal = false,
01475 bool bNLS = false );
01493 void writeEntry( const char *pKey, const TQPoint& rValue,
01494 bool bPersistent = true, bool bGlobal = false,
01495 bool bNLS = false );
01496
01514 void writeEntry( const TQString& pKey, const TQSize& rValue,
01515 bool bPersistent = true, bool bGlobal = false,
01516 bool bNLS = false );
01534 void writeEntry( const char *pKey, const TQSize& rValue,
01535 bool bPersistent = true, bool bGlobal = false,
01536 bool bNLS = false );
01537
01555 void writePathEntry( const TQString& pKey, const TQString & path,
01556 bool bPersistent = true, bool bGlobal = false,
01557 bool bNLS = false );
01575 void writePathEntry( const char *pKey, const TQString & path,
01576 bool bPersistent = true, bool bGlobal = false,
01577 bool bNLS = false );
01578
01598 void writePathEntry( const char *pKey, const TQString & path,
01599 bool bPersistent, bool bGlobal,
01600 bool bNLS, bool expand );
01601
01625 void writePathEntry( const TQString& pKey, const TQStringList &rValue,
01626 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
01650 void writePathEntry( const char *pKey, const TQStringList &rValue,
01651 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
01652
01653
01662 void deleteEntry( const TQString& pKey,
01663 bool bNLS = false, bool bGlobal = false);
01672 void deleteEntry( const char *pKey,
01673 bool bNLS = false, bool bGlobal = false);
01674
01692 bool deleteGroup( const TQString& group, bool bDeep = true, bool bGlobal = false );
01693
01694
01702 void setDollarExpansion( bool _bExpand = true ) { bExpand = _bExpand; }
01703
01709 bool isDollarExpansion() const { return bExpand; }
01710
01725 virtual void rollback( bool bDeep = true );
01726
01740 virtual void sync();
01741
01746 bool isDirty() const { return bDirty; }
01747
01755 virtual void setReadOnly(bool _ro) { bReadOnly = _ro; }
01756
01762 bool isReadOnly() const { return bReadOnly; }
01763
01773 bool hasKey( const TQString& key ) const;
01774
01785 virtual TQMap<TQString, TQString> entryMap(const TQString &group) const = 0;
01786
01799 virtual void reparseConfiguration() = 0;
01800
01805 bool isImmutable() const;
01806
01813 bool groupIsImmutable(const TQString &group) const;
01814
01821 bool entryIsImmutable(const TQString &key) const;
01822
01828 enum ConfigState { NoAccess, ReadOnly, ReadWrite };
01829
01843 ConfigState getConfigState() const;
01844
01851 bool checkConfigFilesWritable(bool warnUser);
01852
01859 void setReadDefaults(bool b);
01860
01866 bool readDefaults() const;
01867
01879 void revertToDefault(const TQString &key);
01880
01907 bool hasDefault(const TQString &key) const;
01908
01909 protected:
01915 void setLocale();
01916
01922 virtual void setDirty(bool _bDirty = true) { bDirty = _bDirty; }
01923
01929 virtual void parseConfigFiles();
01930
01946 virtual KEntryMap internalEntryMap( const TQString& pGroup ) const = 0;
01947
01959 virtual KEntryMap internalEntryMap() const = 0;
01960
01976 virtual void putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup = true) = 0;
01977
01992 virtual KEntry lookupData(const KEntryKey &_key) const = 0;
01993
01994 virtual bool internalHasGroup(const TQCString &group) const = 0;
01995
01999 TDEConfigBackEnd *backEnd;
02000 public:
02004 void setGroup( const TQCString &pGroup );
02005 void setGroup( const char *pGroup );
02006 bool hasGroup(const TQCString &_pGroup) const;
02007 bool hasGroup(const char *_pGroup) const;
02008 bool hasKey( const char *pKey ) const;
02009
02010 protected:
02011 TQCString readEntryUtf8( const char *pKey) const;
02012 bool hasTranslatedKey( const char *pKey ) const;
02013
02016 TQCString mGroup;
02017
02020 TQCString aLocaleString;
02021
02025 bool bDirty;
02026
02027 bool bLocaleInitialized;
02028 bool bReadOnly;
02029 mutable bool bExpand;
02030
02031 protected:
02032 virtual void virtual_hook( int id, void* data );
02033 private:
02034 class TDEConfigBasePrivate;
02035 TDEConfigBasePrivate *d;
02036
02037 void writeEntry( const char *pKey, const TQString &rValue,
02038 bool bPersistent, bool bGlobal, bool bNLS, bool bExpand );
02039 void writeEntry( const char *pKey, const TQStringList &rValue,
02040 char sep, bool bPersistent, bool bGlobal, bool bNLS, bool bExpand );
02041
02042 };
02043
02044 class TDEConfigGroupSaverPrivate;
02045
02082 class TDECORE_EXPORT TDEConfigGroupSaver
02083 {
02084 public:
02094 TDEConfigGroupSaver( TDEConfigBase* config, TQString group )
02095
02096 : _config(config), _oldgroup(config->group())
02097 { _config->setGroup( group ); }
02098
02099 TDEConfigGroupSaver( TDEConfigBase* config, const char *group )
02100 : _config(config), _oldgroup(config->group())
02101 { _config->setGroup( group ); }
02102
02103 TDEConfigGroupSaver( TDEConfigBase* config, const TQCString &group )
02104 : _config(config), _oldgroup(config->group())
02105 { _config->setGroup( group ); }
02106
02107 ~TDEConfigGroupSaver() { _config->setGroup( _oldgroup ); }
02108
02109 TDEConfigBase* config() { return _config; };
02110
02111 private:
02112 TDEConfigBase* _config;
02113 TQString _oldgroup;
02114
02115 TDEConfigGroupSaver(const TDEConfigGroupSaver&);
02116 TDEConfigGroupSaver& operator=(const TDEConfigGroupSaver&);
02117
02118 TDEConfigGroupSaverPrivate *d;
02119 };
02120
02121 class TDEConfigGroupPrivate;
02122
02126 class TDECORE_EXPORT TDEConfigGroup: public TDEConfigBase
02127 {
02128 public:
02133 TDEConfigGroup(TDEConfigBase *master, const TQCString &group);
02140 TDEConfigGroup(TDEConfigBase *master, const TQString &group);
02148 TDEConfigGroup(TDEConfigBase *master, const char * group);
02149
02156 void deleteGroup(bool bGlobal = false);
02157
02164 bool groupIsImmutable() const;
02165
02166
02167 virtual void setDirty(bool _bDirty);
02168 virtual void putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup = true);
02169 virtual KEntry lookupData(const KEntryKey &_key) const;
02170 virtual void sync();
02171
02172 private:
02173
02174 void setGroup() { }
02175 void setDesktopGroup() { }
02176 void group() { }
02177 void hasGroup() { }
02178 void setReadOnly(bool) { }
02179 void isDirty() { }
02180
02181
02182 virtual TQStringList groupList() const { return TQStringList(); }
02183 virtual void rollback(bool) { }
02184 virtual void reparseConfiguration() { }
02185 virtual TQMap<TQString, TQString> entryMap(const TQString &) const
02186 { return TQMap<TQString,TQString>(); }
02187 virtual KEntryMap internalEntryMap( const TQString&) const
02188 { return KEntryMap(); }
02189 virtual KEntryMap internalEntryMap() const
02190 { return KEntryMap(); }
02191 virtual bool internalHasGroup(const TQCString &) const
02192 { return false; }
02193
02194 void getConfigState() { }
02195
02196 TDEConfigBase *mMaster;
02197 protected:
02198 virtual void virtual_hook( int id, void* data );
02199 private:
02200 TDEConfigGroupPrivate* d;
02201 };
02202
02203 #endif