kconfigbase.h

00001 /*
00002    This file is part of the KDE libraries
00003    Copyright (c) 1999 Preston Brown <pbrown@kde.org>
00004    Copyright (c) 1997 Matthias Kalle Dalheimer <kalle@kde.org>
00005    Copyright (c) 2001 Waldo Bastian <bastian@kde.org>
00006 
00007    This library is free software; you can redistribute it and/or
00008    modify it under the terms of the GNU Library General Public
00009    License as published by the Free Software Foundation; either
00010    version 2 of the License, or (at your option) any later version.
00011 
00012    This library is distributed in the hope that it will be useful,
00013    but WITHOUT ANY WARRANTY; without even the implied warranty of
00014    MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
00015    Library General Public License for more details.
00016 
00017    You should have received a copy of the GNU Library General Public License
00018    along with this library; see the file COPYING.LIB.  If not, write to
00019    the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
00020    Boston, MA 02110-1301, USA.
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 KConfigLDAPBackEnd;
00077   friend class KConfigGroup;
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;           // currently only used by KSimpleConfig
02010   mutable bool bExpand;     // whether dollar expansion is used
02011 
02012 protected:
02013   virtual void virtual_hook( int id, void* data );
02014   
02015 protected:
02016   class KConfigBasePrivate
02017   {
02018   public:
02019      KConfigBasePrivate() : readDefaults(false) { };
02020 
02021   public:
02022      bool                       readDefaults;
02023      QPtrList<KConfigBackEnd>   backEnds;
02024   };
02025 
02026   KConfigBasePrivate *m_Private;
02027 };
02028 
02029 class KConfigGroupSaverPrivate;
02030 
02067 class KDECORE_EXPORT KConfigGroupSaver // KDE4 remove
02068 {
02069 public:
02079   KConfigGroupSaver( KConfigBase* config, QString group )
02080       /* KDE 4 : make the second parameter const QString & */
02081       : _config(config), _oldgroup(config->group())
02082         { _config->setGroup( group ); }
02083 
02084   KConfigGroupSaver( KConfigBase* config, const char *group )
02085       : _config(config), _oldgroup(config->group())
02086         { _config->setGroup( group ); }
02087 
02088   KConfigGroupSaver( KConfigBase* config, const QCString &group )
02089       : _config(config), _oldgroup(config->group())
02090         { _config->setGroup( group ); }
02091 
02092   ~KConfigGroupSaver() { _config->setGroup( _oldgroup ); }
02093 
02094     KConfigBase* config() { return _config; };
02095 
02096 private:
02097   KConfigBase* _config;
02098   QString _oldgroup;
02099 
02100   KConfigGroupSaver(const KConfigGroupSaver&);
02101   KConfigGroupSaver& operator=(const KConfigGroupSaver&);
02102 
02103   KConfigGroupSaverPrivate *d;
02104 };
02105 
02106 class KConfigGroupPrivate;
02107 
02111 class KDECORE_EXPORT KConfigGroup: public KConfigBase
02112 {
02113 public:
02118    KConfigGroup(KConfigBase *master, const QCString &group);
02125    KConfigGroup(KConfigBase *master, const QString &group);
02133    KConfigGroup(KConfigBase *master, const char * group);
02134 
02141    void deleteGroup(bool bGlobal = false);
02142 
02149   bool groupIsImmutable() const;
02150 
02151    // The following functions are reimplemented:
02152    virtual void setDirty(bool _bDirty);
02153    virtual void putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup = true);
02154    virtual KEntry lookupData(const KEntryKey &_key) const;
02155    virtual void sync();
02156 
02157 private:
02158    // Hide the following members:
02159    void setGroup() { }
02160    void setDesktopGroup() { }
02161    void group() { }
02162    void hasGroup() { }
02163    void setReadOnly(bool) { }
02164    void isDirty() { }
02165 
02166    // The following members are not used.
02167    virtual QStringList groupList() const { return QStringList(); }
02168    virtual void rollback(bool) { }
02169    virtual void reparseConfiguration() { }
02170    virtual QMap<QString, QString> entryMap(const QString &) const
02171     { return QMap<QString,QString>(); }
02172    virtual KEntryMap internalEntryMap( const QString&) const
02173     { return KEntryMap(); }
02174    virtual KEntryMap internalEntryMap() const
02175     { return KEntryMap(); }
02176    virtual bool internalHasGroup(const QCString &) const
02177     { return false; }
02178 
02179    void getConfigState() { }
02180 
02181    KConfigBase *mMaster;
02182 protected:
02183    virtual void virtual_hook( int id, void* data );
02184 private:
02185    KConfigGroupPrivate* d;
02186 };
02187 
02188 #endif
KDE Home | KDE Accessibility Home | Description of Access Keys