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 #ifndef _KCONFIGBASE_H
00026 #define _KCONFIGBASE_H
00027
00028 #include <qobject.h>
00029 #include <qcolor.h>
00030 #include <qfont.h>
00031 #include <qdatetime.h>
00032 #include <qstrlist.h>
00033 #include <qstringlist.h>
00034 #include <qvariant.h>
00035 #include <qmap.h>
00036
00037 #include "kconfigdata.h"
00038
00039 class KConfigBackEnd;
00040 class KConfigBasePrivate;
00041 class KConfigGroup;
00042
00070 class KConfigBase : public QObject
00071 {
00072 Q_OBJECT
00073
00074 friend class KConfigBackEnd;
00075 friend class KConfigINIBackEnd;
00076 friend class KConfigGroup;
00077
00078 public:
00082 KConfigBase();
00083
00087 virtual ~KConfigBase();
00088
00099 void setGroup( const QString& group );
00100
00105 void setDesktopGroup();
00106
00113 QString group() const;
00114
00121 bool hasGroup(const QString &group) const;
00122
00128 virtual QStringList groupList() const = 0;
00129
00135 QString locale() const;
00136
00144 QString readEntry(const QString& pKey,
00145 const QString& aDefault = QString::null ) const;
00146
00154 QString readEntry(const char *pKey,
00155 const QString& aDefault = QString::null ) const;
00156
00170 QVariant readPropertyEntry( const QString& pKey, QVariant::Type ) const;
00171
00186 QVariant readPropertyEntry( const char *pKey, QVariant::Type ) const;
00187
00202 QVariant readPropertyEntry( const QString& pKey,
00203 const QVariant &adefault) const;
00204
00219 QVariant readPropertyEntry( const char *pKey,
00220 const QVariant &aDefault) const;
00221
00232 int readListEntry( const QString& pKey, QStrList &list, char sep = ',' ) const;
00233
00244 int readListEntry( const char *pKey, QStrList &list, char sep = ',' ) const;
00245
00253 QStringList readListEntry( const QString& pKey, char sep = ',' ) const;
00254
00262 QStringList readListEntry( const char *pKey, char sep = ',' ) const;
00263
00270 QValueList<int> readIntListEntry( const QString& pKey ) const;
00271
00278 QValueList<int> readIntListEntry( const char *pKey ) const;
00279
00291 QString readPathEntry( const QString& pKey, const QString & aDefault = QString::null ) const;
00292
00304 QString readPathEntry( const char *pKey, const QString & aDefault = QString::null ) const;
00305
00318 QStringList readPathListEntry( const QString& pKey, char sep = ',' ) const;
00319
00332 QStringList readPathListEntry( const char *pKey, char sep = ',' ) const;
00333
00334
00346 int readNumEntry( const QString& pKey, int nDefault = 0 ) const;
00347
00359 int readNumEntry( const char *pKey, int nDefault = 0 ) const;
00360
00372 unsigned int readUnsignedNumEntry( const QString& pKey, unsigned int nDefault = 0 ) const;
00373
00385 unsigned int readUnsignedNumEntry( const char *pKey, unsigned int nDefault = 0 ) const;
00386
00387
00399 long readLongNumEntry( const QString& pKey, long nDefault = 0 ) const;
00400
00412 long readLongNumEntry( const char *pKey, long nDefault = 0 ) const;
00413
00425 unsigned long readUnsignedLongNumEntry( const QString& pKey, unsigned long nDefault = 0 ) const;
00426
00438 unsigned long readUnsignedLongNumEntry( const char *pKey, unsigned long nDefault = 0 ) const;
00439
00451 double readDoubleNumEntry( const QString& pKey, double nDefault = 0.0 ) const;
00452
00464 double readDoubleNumEntry( const char *pKey, double nDefault = 0.0 ) const;
00465
00477 QFont readFontEntry( const QString& pKey, const QFont* pDefault = 0L ) const;
00478
00490 QFont readFontEntry( const char *pKey, const QFont* pDefault = 0L ) const;
00491
00503 bool readBoolEntry( const QString& pKey, const bool bDefault = false ) const;
00504
00516 bool readBoolEntry( const char *pKey, const bool bDefault = false ) const;
00517
00529 QRect readRectEntry( const QString& pKey, const QRect* pDefault = 0L ) const;
00530
00542 QRect readRectEntry( const char *pKey, const QRect* pDefault = 0L ) const;
00543
00555 QPoint readPointEntry( const QString& pKey, const QPoint* pDefault = 0L ) const;
00556
00568 QPoint readPointEntry( const char *pKey, const QPoint* pDefault = 0L ) const;
00569
00581 QSize readSizeEntry( const QString& pKey, const QSize* pDefault = 0L ) const;
00582
00594 QSize readSizeEntry( const char *pKey, const QSize* pDefault = 0L ) const;
00595
00596
00608 QColor readColorEntry( const QString& pKey, const QColor* pDefault = 0L ) const;
00609
00621 QColor readColorEntry( const char *pKey, const QColor* pDefault = 0L ) const;
00622
00635 QDateTime readDateTimeEntry( const QString& pKey, const QDateTime* pDefault = 0L ) const;
00636
00649 QDateTime readDateTimeEntry( const char *pKey, const QDateTime* pDefault = 0L ) const;
00650
00659 QString readEntryUntranslated( const QString& pKey,
00660 const QString& aDefault = QString::null ) const;
00661
00670 QString readEntryUntranslated( const char *pKey,
00671 const QString& aDefault = QString::null ) const;
00672
00690 void writeEntry( const QString& pKey, const QString& pValue,
00691 bool bPersistent = true, bool bGlobal = false,
00692 bool bNLS = false );
00693
00711 void writeEntry( const char *pKey, const QString& pValue,
00712 bool bPersistent = true, bool bGlobal = false,
00713 bool bNLS = false );
00714
00734 void writeEntry( const QString& pKey, const QVariant& rValue,
00735 bool bPersistent = true, bool bGlobal = false,
00736 bool bNLS = false );
00756 void writeEntry( const char *pKey, const QVariant& rValue,
00757 bool bPersistent = true, bool bGlobal = false,
00758 bool bNLS = false );
00759
00779 void writeEntry( const QString& pKey, const QStrList &rValue,
00780 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00800 void writeEntry( const char *pKey, const QStrList &rValue,
00801 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00802
00822 void writeEntry( const QString& pKey, const QStringList &rValue,
00823 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00843 void writeEntry( const char *pKey, const QStringList &rValue,
00844 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00845
00846
00866 void writeEntry( const QString& pKey, const QValueList<int>& rValue,
00867 bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00887 void writeEntry( const char *pKey, const QValueList<int>& rValue,
00888 bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00889
00907 void writeEntry( const QString& pKey, const char *pValue,
00908 bool bPersistent = true, bool bGlobal = false,
00909 bool bNLS = false )
00910 { writeEntry(pKey, QString::fromLatin1(pValue), bPersistent, bGlobal, bNLS); }
00928 void writeEntry( const char *pKey, const char *pValue,
00929 bool bPersistent = true, bool bGlobal = false,
00930 bool bNLS = false )
00931 { writeEntry(pKey, QString::fromLatin1(pValue), bPersistent, bGlobal, bNLS); }
00932
00948 void writeEntry( const QString& pKey, int nValue,
00949 bool bPersistent = true, bool bGlobal = false,
00950 bool bNLS = false );
00966 void writeEntry( const char *pKey, int nValue,
00967 bool bPersistent = true, bool bGlobal = false,
00968 bool bNLS = false );
00969
00985 void writeEntry( const QString& pKey, unsigned int nValue,
00986 bool bPersistent = true, bool bGlobal = false,
00987 bool bNLS = false );
01003 void writeEntry( const char *pKey, unsigned int nValue,
01004 bool bPersistent = true, bool bGlobal = false,
01005 bool bNLS = false );
01006
01021 void writeEntry( const QString& pKey, long nValue,
01022 bool bPersistent = true, bool bGlobal = false,
01023 bool bNLS = false );
01038 void writeEntry( const char *pKey, long nValue,
01039 bool bPersistent = true, bool bGlobal = false,
01040 bool bNLS = false );
01041
01056 void writeEntry( const QString& pKey, unsigned long nValue,
01057 bool bPersistent = true, bool bGlobal = false,
01058 bool bNLS = false );
01073 void writeEntry( const char *pKey, unsigned long nValue,
01074 bool bPersistent = true, bool bGlobal = false,
01075 bool bNLS = false );
01076
01094 void writeEntry( const QString& pKey, double nValue,
01095 bool bPersistent = true, bool bGlobal = false,
01096 char format = 'g', int precision = 6,
01097 bool bNLS = false );
01115 void writeEntry( const char *pKey, double nValue,
01116 bool bPersistent = true, bool bGlobal = false,
01117 char format = 'g', int precision = 6,
01118 bool bNLS = false );
01119
01134 void writeEntry( const QString& pKey, bool bValue,
01135 bool bPersistent = true, bool bGlobal = false,
01136 bool bNLS = false );
01151 void writeEntry( const char *pKey, bool bValue,
01152 bool bPersistent = true, bool bGlobal = false,
01153 bool bNLS = false );
01154
01169 void writeEntry( const QString& pKey, const QFont& rFont,
01170 bool bPersistent = true, bool bGlobal = false,
01171 bool bNLS = false );
01186 void writeEntry( const char *pKey, const QFont& rFont,
01187 bool bPersistent = true, bool bGlobal = false,
01188 bool bNLS = false );
01189
01207 void writeEntry( const QString& pKey, const QColor& rColor,
01208 bool bPersistent = true, bool bGlobal = false,
01209 bool bNLS = false );
01227 void writeEntry( const char *pKey, const QColor& rColor,
01228 bool bPersistent = true, bool bGlobal = false,
01229 bool bNLS = false );
01230
01248 void writeEntry( const QString& pKey, const QDateTime& rDateTime,
01249 bool bPersistent = true, bool bGlobal = false,
01250 bool bNLS = false );
01268 void writeEntry( const char *pKey, const QDateTime& rDateTime,
01269 bool bPersistent = true, bool bGlobal = false,
01270 bool bNLS = false );
01271
01272
01290 void writeEntry( const QString& pKey, const QRect& rValue,
01291 bool bPersistent = true, bool bGlobal = false,
01292 bool bNLS = false );
01310 void writeEntry( const char *pKey, const QRect& rValue,
01311 bool bPersistent = true, bool bGlobal = false,
01312 bool bNLS = false );
01313
01331 void writeEntry( const QString& pKey, const QPoint& rValue,
01332 bool bPersistent = true, bool bGlobal = false,
01333 bool bNLS = false );
01351 void writeEntry( const char *pKey, const QPoint& rValue,
01352 bool bPersistent = true, bool bGlobal = false,
01353 bool bNLS = false );
01354
01372 void writeEntry( const QString& pKey, const QSize& rValue,
01373 bool bPersistent = true, bool bGlobal = false,
01374 bool bNLS = false );
01392 void writeEntry( const char *pKey, const QSize& rValue,
01393 bool bPersistent = true, bool bGlobal = false,
01394 bool bNLS = false );
01395
01413 void writePathEntry( const QString& pKey, const QString & path,
01414 bool bPersistent = true, bool bGlobal = false,
01415 bool bNLS = false );
01433 void writePathEntry( const char *pKey, const QString & path,
01434 bool bPersistent = true, bool bGlobal = false,
01435 bool bNLS = false );
01436
01459 void writePathEntry( const QString& pKey, const QStringList &rValue,
01460 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
01483 void writePathEntry( const char *pKey, const QStringList &rValue,
01484 char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
01485
01486
01495 void deleteEntry( const QString& pKey,
01496 bool bNLS = false, bool bGlobal = false);
01505 void deleteEntry( const char *pKey,
01506 bool bNLS = false, bool bGlobal = false);
01507
01525 bool deleteGroup( const QString& group, bool bDeep = true, bool bGlobal = false );
01526
01527
01535 void setDollarExpansion( bool _bExpand = true ) { bExpand = _bExpand; }
01536
01542 bool isDollarExpansion() const { return bExpand; }
01543
01558 virtual void rollback( bool bDeep = true );
01559
01573 virtual void sync();
01574
01579 bool isDirty() const { return bDirty; }
01580
01588 virtual void setReadOnly(bool _ro) { bReadOnly = _ro; }
01589
01595 bool isReadOnly() const { return bReadOnly; }
01596
01606 bool hasKey( const QString& key ) const;
01607
01618 virtual QMap<QString, QString> entryMap(const QString &group) const = 0;
01619
01632 virtual void reparseConfiguration() = 0;
01633
01638 bool isImmutable() const;
01639
01646 bool groupIsImmutable(const QString &group) const;
01647
01654 bool entryIsImmutable(const QString &key) const;
01655
01661 enum ConfigState { NoAccess, ReadOnly, ReadWrite };
01662
01676 ConfigState getConfigState() const;
01677
01678 protected:
01684 void setLocale();
01685
01691 virtual void setDirty(bool _bDirty = true) { bDirty = _bDirty; }
01692
01698 virtual void parseConfigFiles();
01699
01715 virtual KEntryMap internalEntryMap( const QString& pGroup ) const = 0;
01716
01728 virtual KEntryMap internalEntryMap() const = 0;
01729
01745 virtual void putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup = true) = 0;
01746
01761 virtual KEntry lookupData(const KEntryKey &_key) const = 0;
01762
01763 virtual bool internalHasGroup(const QCString &group) const = 0;
01764
01768 KConfigBackEnd *backEnd;
01769 public:
01773 void setGroup( const QCString &pGroup );
01774 void setGroup( const char *pGroup );
01775 bool hasGroup(const QCString &_pGroup) const;
01776 bool hasGroup(const char *_pGroup) const;
01777 bool hasKey( const char *pKey ) const;
01778
01779 protected:
01780 QCString readEntryUtf8( const char *pKey) const;
01781
01784 QCString mGroup;
01785
01788 QCString aLocaleString;
01789
01793 bool bDirty;
01794
01795 bool bLocaleInitialized;
01796 bool bReadOnly;
01797 mutable bool bExpand;
01798
01799 protected:
01800 virtual void virtual_hook( int id, void* data );
01801 private:
01802 KConfigBasePrivate *d;
01803 };
01804
01805 class KConfigGroupSaverPrivate;
01806
01840 class KConfigGroupSaver
01841 {
01842 public:
01851 KConfigGroupSaver( KConfigBase* config, QString group )
01852 : _config(config), _oldgroup(config->group())
01853 { _config->setGroup( group ); }
01854
01855 KConfigGroupSaver( KConfigBase* config, const char *group )
01856 : _config(config), _oldgroup(config->group())
01857 { _config->setGroup( group ); }
01858
01859 KConfigGroupSaver( KConfigBase* config, const QCString &group )
01860 : _config(config), _oldgroup(config->group())
01861 { _config->setGroup( group ); }
01862
01863 ~KConfigGroupSaver() { _config->setGroup( _oldgroup ); }
01864
01865 KConfigBase* config() { return _config; };
01866
01867 private:
01868 KConfigBase* _config;
01869 QString _oldgroup;
01870
01871 KConfigGroupSaver(const KConfigGroupSaver&);
01872 KConfigGroupSaver& operator=(const KConfigGroupSaver&);
01873
01874 KConfigGroupSaverPrivate *d;
01875 };
01876
01877 class KConfigGroupPrivate;
01878
01879 class KConfigGroup: public KConfigBase
01880 {
01881 public:
01886 KConfigGroup(KConfigBase *master, const QCString &group);
01893 KConfigGroup(KConfigBase *master, const QString &group);
01901 KConfigGroup(KConfigBase *master, const char * group);
01902
01909 void deleteGroup(bool bGlobal = false);
01910
01911
01912 virtual void setDirty(bool b);
01913 virtual void putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup = true);
01914 virtual KEntry lookupData(const KEntryKey &_key) const;
01915 virtual void sync();
01916
01917 private:
01918
01919 void setGroup() { }
01920 void setDesktopGroup() { }
01921 void group() { }
01922 void hasGroup() { }
01923 void setReadOnly(bool) { }
01924 void isDirty() { }
01925
01926
01927 virtual QStringList groupList() const { return QStringList(); }
01928 virtual void rollback(bool) { }
01929 virtual void reparseConfiguration() { }
01930 virtual QMap<QString, QString> entryMap(const QString &) const
01931 { return QMap<QString,QString>(); }
01932 virtual KEntryMap internalEntryMap( const QString&) const
01933 { return KEntryMap(); }
01934 virtual KEntryMap internalEntryMap() const
01935 { return KEntryMap(); }
01936 virtual bool internalHasGroup(const QCString &) const
01937 { return false; }
01938
01939 void getConfigState() { }
01940
01941 KConfigBase *mMaster;
01942 protected:
01943 virtual void virtual_hook( int id, void* data );
01944 private:
01945 KConfigGroupPrivate* d;
01946 };
01947
01948 #endif