| # kdecore Library API Documentation
Overview | Class Hierarchy | Classes | Classes (annotated) | Members | Namespaces | Source Files

# 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., 59 Temple Place - Suite 330,
    00020    Boston, MA 02111-1307, 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 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
    00145    QString readEntry(const QString& pKey,
    00146                      const QString& aDefault = QString::null ) const;
    00147
    00155    QString readEntry(const char *pKey,
    00156                      const QString& aDefault = QString::null ) const;
    00157
    00171   QVariant readPropertyEntry( const QString& pKey, QVariant::Type ) const;
    00172
    00187   QVariant readPropertyEntry( const char *pKey, QVariant::Type ) const;
    00188
    00203   QVariant readPropertyEntry( const QString& pKey,
    00204                               const QVariant &aDefault) const;
    00205
    00220   QVariant readPropertyEntry( const char *pKey,
    00221                               const QVariant &aDefault) const;
    00222
    00233   int readListEntry( const QString& pKey, QStrList &list, char sep = ',' ) const;
    00234
    00245   int readListEntry( const char *pKey, QStrList &list, char sep = ',' ) const;
    00246
    00254   QStringList readListEntry( const QString& pKey, char sep = ',' ) const;
    00255
    00263   QStringList readListEntry( const char *pKey, char sep = ',' ) const;
    00264
    00274   QStringList readListEntry( const char* pKey, const QStringList& aDefault,
    00275           char sep = ',' ) const;
    00276
    00283   QValueList<int> readIntListEntry( const QString& pKey ) const;
    00284
    00291   QValueList<int> readIntListEntry( const char *pKey ) const;
    00292
    00304   QString readPathEntry( const QString& pKey, const QString & aDefault = QString::null ) const;
    00305
    00317   QString readPathEntry( const char *pKey, const QString & aDefault = QString::null ) const;
    00318
    00331   QStringList readPathListEntry( const QString& pKey, char sep = ',' ) const;
    00332
    00345   QStringList readPathListEntry( const char *pKey, char sep = ',' ) const;
    00346
    00347
    00359   int readNumEntry( const QString& pKey, int nDefault = 0 ) const;
    00360
    00372   int readNumEntry( const char *pKey, int nDefault = 0 ) const;
    00373
    00385   unsigned int readUnsignedNumEntry( const QString& pKey, unsigned int nDefault = 0 ) const;
    00386
    00398   unsigned int readUnsignedNumEntry( const char *pKey, unsigned int nDefault = 0 ) const;
    00399
    00400
    00412   long readLongNumEntry( const QString& pKey, long nDefault = 0 ) const;
    00413
    00425   long readLongNumEntry( const char *pKey, long nDefault = 0 ) const;
    00426
    00438   unsigned long readUnsignedLongNumEntry( const QString& pKey, unsigned long nDefault = 0 ) const;
    00439
    00451   unsigned long readUnsignedLongNumEntry( const char *pKey, unsigned long nDefault = 0 ) const;
    00452
    00464   Q_INT64 readNum64Entry( const QString& pKey, Q_INT64 nDefault = 0 ) const;
    00465
    00477   Q_INT64 readNum64Entry( const char *pKey, Q_INT64 nDefault = 0 ) const;
    00478
    00490   Q_UINT64 readUnsignedNum64Entry( const QString& pKey, Q_UINT64 nDefault = 0 ) const;
    00491
    00503   Q_UINT64 readUnsignedNum64Entry( const char *pKey, Q_UINT64 nDefault = 0 ) const;
    00504
    00516   double readDoubleNumEntry( const QString& pKey, double nDefault = 0.0 ) const;
    00517
    00529   double readDoubleNumEntry( const char *pKey, double nDefault = 0.0 ) const;
    00530
    00542   QFont readFontEntry( const QString& pKey, const QFont* pDefault = 0L ) const;
    00543
    00555   QFont readFontEntry( const char *pKey, const QFont* pDefault = 0L ) const;
    00556
    00568   bool readBoolEntry( const QString& pKey, bool bDefault = false ) const;
    00569
    00581   bool readBoolEntry( const char *pKey, bool bDefault = false ) const;
    00582
    00594   QRect readRectEntry( const QString& pKey, const QRect* pDefault = 0L ) const;
    00595
    00607   QRect readRectEntry( const char *pKey, const QRect* pDefault = 0L ) const;
    00608
    00620   QPoint readPointEntry( const QString& pKey, const QPoint* pDefault = 0L ) const;
    00621
    00633   QPoint readPointEntry( const char *pKey, const QPoint* pDefault = 0L ) const;
    00634
    00646   QSize readSizeEntry( const QString& pKey, const QSize* pDefault = 0L ) const;
    00647
    00659   QSize readSizeEntry( const char *pKey, const QSize* pDefault = 0L ) const;
    00660
    00661
    00673   QColor readColorEntry( const QString& pKey, const QColor* pDefault = 0L ) const;
    00674
    00686   QColor readColorEntry( const char *pKey, const QColor* pDefault = 0L ) const;
    00687
    00700   QDateTime readDateTimeEntry( const QString& pKey, const QDateTime* pDefault = 0L ) const;
    00701
    00714   QDateTime readDateTimeEntry( const char *pKey, const QDateTime* pDefault = 0L ) const;
    00715
    00724    QString readEntryUntranslated( const QString& pKey,
    00725                      const QString& aDefault = QString::null ) const;
    00726
    00735    QString readEntryUntranslated( const char *pKey,
    00736                      const QString& aDefault = QString::null ) const;
    00737
    00757   void writeEntry( const QString& pKey, const QString& pValue,
    00758                       bool bPersistent = true, bool bGlobal = false,
    00759                       bool bNLS = false );
    00760
    00778   void writeEntry( const char *pKey, const QString& pValue,
    00779                       bool bPersistent = true, bool bGlobal = false,
    00780                       bool bNLS = false );
    00781
    00801   void writeEntry( const QString& pKey, const QVariant& rValue,
    00802                     bool bPersistent = true, bool bGlobal = false,
    00803                     bool bNLS = false );
    00823   void writeEntry( const char *pKey, const QVariant& rValue,
    00824                     bool bPersistent = true, bool bGlobal = false,
    00825                     bool bNLS = false );
    00826
    00847   void writeEntry( const QString& pKey, const QStrList &rValue,
    00848            char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
    00869   void writeEntry( const char *pKey, const QStrList &rValue,
    00870            char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
    00871
    00892   void writeEntry( const QString& pKey, const QStringList &rValue,
    00893            char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
    00914   void writeEntry( const char *pKey, const QStringList &rValue,
    00915            char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
    00916
    00917
    00937   void writeEntry( const QString& pKey, const QValueList<int>& rValue,
    00938            bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
    00958   void writeEntry( const char *pKey, const QValueList<int>& rValue,
    00959            bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
    00960
    00978   void writeEntry( const QString& pKey, const char *pValue,
    00979                       bool bPersistent = true, bool bGlobal = false,
    00980                       bool bNLS = false )
    00981     { writeEntry(pKey, QString::fromLatin1(pValue), bPersistent, bGlobal, bNLS); }
    00999   void writeEntry( const char *pKey, const char *pValue,
    01000                       bool bPersistent = true, bool bGlobal = false,
    01001                       bool bNLS = false )
    01002     { writeEntry(pKey, QString::fromLatin1(pValue), bPersistent, bGlobal, bNLS); }
    01003
    01019   void writeEntry( const QString& pKey, int nValue,
    01020                       bool bPersistent = true, bool bGlobal = false,
    01021                       bool bNLS = false );
    01037   void writeEntry( const char *pKey, int nValue,
    01038                       bool bPersistent = true, bool bGlobal = false,
    01039                       bool bNLS = false );
    01040
    01056   void writeEntry( const QString& pKey, unsigned int nValue,
    01057                       bool bPersistent = true, bool bGlobal = false,
    01058                       bool bNLS = false );
    01074   void writeEntry( const char *pKey, unsigned int nValue,
    01075                       bool bPersistent = true, bool bGlobal = false,
    01076                       bool bNLS = false );
    01077
    01092   void writeEntry( const QString& pKey, long nValue,
    01093                       bool bPersistent = true, bool bGlobal = false,
    01094                       bool bNLS = false );
    01109   void writeEntry( const char *pKey, long nValue,
    01110                       bool bPersistent = true, bool bGlobal = false,
    01111                       bool bNLS = false );
    01112
    01127   void writeEntry( const QString& pKey, unsigned long nValue,
    01128                       bool bPersistent = true, bool bGlobal = false,
    01129                       bool bNLS = false );
    01144   void writeEntry( const char *pKey, unsigned long nValue,
    01145                       bool bPersistent = true, bool bGlobal = false,
    01146                       bool bNLS = false );
    01147
    01162   void writeEntry( const QString& pKey, Q_INT64 nValue,
    01163                       bool bPersistent = true, bool bGlobal = false,
    01164                       bool bNLS = false );
    01179   void writeEntry( const char *pKey, Q_INT64 nValue,
    01180                       bool bPersistent = true, bool bGlobal = false,
    01181                       bool bNLS = false );
    01182
    01197   void writeEntry( const QString& pKey, Q_UINT64 nValue,
    01198                       bool bPersistent = true, bool bGlobal = false,
    01199                       bool bNLS = false );
    01214   void writeEntry( const char *pKey, Q_UINT64 nValue,
    01215                       bool bPersistent = true, bool bGlobal = false,
    01216                       bool bNLS = false );
    01217
    01235   void writeEntry( const QString& pKey, double nValue,
    01236                       bool bPersistent = true, bool bGlobal = false,
    01237                       char format = 'g', int precision = 6,
    01238                       bool bNLS = false );
    01256   void writeEntry( const char *pKey, double nValue,
    01257                       bool bPersistent = true, bool bGlobal = false,
    01258                       char format = 'g', int precision = 6,
    01259                       bool bNLS = false );
    01260
    01275   void writeEntry( const QString& pKey, bool bValue,
    01276                       bool bPersistent = true, bool bGlobal = false,
    01277                       bool bNLS = false );
    01292   void writeEntry( const char *pKey, bool bValue,
    01293                       bool bPersistent = true, bool bGlobal = false,
    01294                       bool bNLS = false );
    01295
    01310   void writeEntry( const QString& pKey, const QFont& rFont,
    01311                       bool bPersistent = true, bool bGlobal = false,
    01312                       bool bNLS = false );
    01327   void writeEntry( const char *pKey, const QFont& rFont,
    01328                       bool bPersistent = true, bool bGlobal = false,
    01329                       bool bNLS = false );
    01330
    01348   void writeEntry( const QString& pKey, const QColor& rColor,
    01349                    bool bPersistent = true, bool bGlobal = false,
    01350                    bool bNLS = false );
    01368   void writeEntry( const char *pKey, const QColor& rColor,
    01369                    bool bPersistent = true, bool bGlobal = false,
    01370                    bool bNLS = false );
    01371
    01389   void writeEntry( const QString& pKey, const QDateTime& rDateTime,
    01390                    bool bPersistent = true, bool bGlobal = false,
    01391                    bool bNLS = false );
    01409   void writeEntry( const char *pKey, const QDateTime& rDateTime,
    01410                    bool bPersistent = true, bool bGlobal = false,
    01411                    bool bNLS = false );
    01412
    01413
    01431   void writeEntry( const QString& pKey, const QRect& rValue,
    01432                    bool bPersistent = true, bool bGlobal = false,
    01433                    bool bNLS = false );
    01451   void writeEntry( const char *pKey, const QRect& rValue,
    01452                    bool bPersistent = true, bool bGlobal = false,
    01453                    bool bNLS = false );
    01454
    01472   void writeEntry( const QString& pKey, const QPoint& rValue,
    01473                    bool bPersistent = true, bool bGlobal = false,
    01474                    bool bNLS = false );
    01492   void writeEntry( const char *pKey, const QPoint& rValue,
    01493                    bool bPersistent = true, bool bGlobal = false,
    01494                    bool bNLS = false );
    01495
    01513   void writeEntry( const QString& pKey, const QSize& rValue,
    01514                    bool bPersistent = true, bool bGlobal = false,
    01515                    bool bNLS = false );
    01533   void writeEntry( const char *pKey, const QSize& rValue,
    01534                    bool bPersistent = true, bool bGlobal = false,
    01535                    bool bNLS = false );
    01536
    01554   void writePathEntry( const QString& pKey, const QString & path,
    01555                        bool bPersistent = true, bool bGlobal = false,
    01556                        bool bNLS = false );
    01574   void writePathEntry( const char *pKey, const QString & path,
    01575                        bool bPersistent = true, bool bGlobal = false,
    01576                        bool bNLS = false );
    01577
    01601   void writePathEntry( const QString& pKey, const QStringList &rValue,
    01602            char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
    01626   void writePathEntry( const char *pKey, const QStringList &rValue,
    01627            char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
    01628
    01629
    01638    void deleteEntry( const QString& pKey,
    01639                    bool bNLS = false, bool bGlobal = false);
    01648    void deleteEntry( const char *pKey,
    01649                    bool bNLS = false, bool bGlobal = false);
    01650
    01668   bool deleteGroup( const QString& group, bool bDeep = true, bool bGlobal = false );
    01669
    01670
    01678   void setDollarExpansion( bool _bExpand = true ) { bExpand = _bExpand; }
    01679
    01685   bool isDollarExpansion() const { return bExpand; }
    01686
    01701   virtual void rollback( bool bDeep = true );
    01702
    01716   virtual void sync();
    01717
    01722   bool isDirty() const { return bDirty; }
    01723
    01731   virtual void setReadOnly(bool _ro) { bReadOnly = _ro; }
    01732
    01738   bool isReadOnly() const { return bReadOnly; }
    01739
    01749   bool hasKey( const QString& key ) const;
    01750
    01761   virtual QMap<QString, QString> entryMap(const QString &group) const = 0;
    01762
    01775   virtual void reparseConfiguration() = 0;
    01776
    01781   bool isImmutable() const;
    01782
    01789   bool groupIsImmutable(const QString &group) const;
    01790
    01797   bool entryIsImmutable(const QString &key) const;
    01798
    01804   enum ConfigState { NoAccess, ReadOnly, ReadWrite };
    01805
    01819   ConfigState getConfigState() const;
    01820
    01827   bool checkConfigFilesWritable(bool warnUser);
    01828
    01835   void setReadDefaults(bool b);
    01836
    01842   bool readDefaults() const;
    01843
    01855   void revertToDefault(const QString &key);
    01856
    01883   bool hasDefault(const QString &key) const;
    01884
    01885 protected:
    01891   void setLocale();
    01892
    01898   virtual void setDirty(bool _bDirty = true) { bDirty = _bDirty; }
    01899
    01905   virtual void parseConfigFiles();
    01906
    01922   virtual KEntryMap internalEntryMap( const QString& pGroup ) const = 0;
    01923
    01935   virtual KEntryMap internalEntryMap() const = 0;
    01936
    01952   virtual void putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup = true) = 0;
    01953
    01968   virtual KEntry lookupData(const KEntryKey &_key) const = 0;
    01969
    01970   virtual bool internalHasGroup(const QCString &group) const = 0;
    01971
    01975   KConfigBackEnd *backEnd;
    01976 public:
    01980   void setGroup( const QCString &pGroup );
    01981   void setGroup( const char *pGroup );
    01982   bool hasGroup(const QCString &_pGroup) const;
    01983   bool hasGroup(const char *_pGroup) const;
    01984   bool hasKey( const char *pKey ) const;
    01985
    01986 protected:
    01987   QCString readEntryUtf8( const char *pKey) const;
    01988
    01991   QCString mGroup;
    01992
    01995   QCString aLocaleString;
    01996
    02000   bool bDirty;
    02001
    02002   bool bLocaleInitialized;
    02003   bool bReadOnly;           // currently only used by KSimpleConfig
    02004   mutable bool bExpand;     // whether dollar expansion is used
    02005
    02006 protected:
    02007   virtual void virtual_hook( int id, void* data );
    02008 private:
    02009   class KConfigBasePrivate;
    02010   KConfigBasePrivate *d;
    02011 };
    02012
    02013 class KConfigGroupSaverPrivate;
    02014
    02051 class KDECORE_EXPORT KConfigGroupSaver // KDE4 remove
    02052 {
    02053 public:
    02063   KConfigGroupSaver( KConfigBase* config, QString group )
    02064       /* KDE 4 : make the second parameter const QString & */
    02065       : _config(config), _oldgroup(config->group())
    02066         { _config->setGroup( group ); }
    02067
    02068   KConfigGroupSaver( KConfigBase* config, const char *group )
    02069       : _config(config), _oldgroup(config->group())
    02070         { _config->setGroup( group ); }
    02071
    02072   KConfigGroupSaver( KConfigBase* config, const QCString &group )
    02073       : _config(config), _oldgroup(config->group())
    02074         { _config->setGroup( group ); }
    02075
    02076   ~KConfigGroupSaver() { _config->setGroup( _oldgroup ); }
    02077
    02078     KConfigBase* config() { return _config; };
    02079
    02080 private:
    02081   KConfigBase* _config;
    02082   QString _oldgroup;
    02083
    02084   KConfigGroupSaver(const KConfigGroupSaver&);
    02085   KConfigGroupSaver& operator=(const KConfigGroupSaver&);
    02086
    02087   KConfigGroupSaverPrivate *d;
    02088 };
    02089
    02090 class KConfigGroupPrivate;
    02091
    02095 class KDECORE_EXPORT KConfigGroup: public KConfigBase
    02096 {
    02097 public:
    02102    KConfigGroup(KConfigBase *master, const QCString &group);
    02109    KConfigGroup(KConfigBase *master, const QString &group);
    02117    KConfigGroup(KConfigBase *master, const char * group);
    02118
    02125    void deleteGroup(bool bGlobal = false);
    02126
    02133   bool groupIsImmutable() const;
    02134
    02135    // The following functions are reimplemented:
    02136    virtual void setDirty(bool b);
    02137    virtual void putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup = true);
    02138    virtual KEntry lookupData(const KEntryKey &_key) const;
    02139    virtual void sync();
    02140
    02141 private:
    02142    // Hide the following members:
    02143    void setGroup() { }
    02144    void setDesktopGroup() { }
    02145    void group() { }
    02146    void hasGroup() { }
    02147    void setReadOnly(bool) { }
    02148    void isDirty() { }
    02149
    02150    // The following members are not used.
    02151    virtual QStringList groupList() const { return QStringList(); }
    02152    virtual void rollback(bool) { }
    02153    virtual void reparseConfiguration() { }
    02154    virtual QMap<QString, QString> entryMap(const QString &) const
    02155     { return QMap<QString,QString>(); }
    02156    virtual KEntryMap internalEntryMap( const QString&) const
    02157     { return KEntryMap(); }
    02158    virtual KEntryMap internalEntryMap() const
    02159     { return KEntryMap(); }
    02160    virtual bool internalHasGroup(const QCString &) const
    02161     { return false; }
    02162
    02163    void getConfigState() { }
    02164
    02165    KConfigBase *mMaster;
    02166 protected:
    02167    virtual void virtual_hook( int id, void* data );
    02168 private:
    02169    KConfigGroupPrivate* d;
    02170 };
    02171
    02172 #endif

This file is part of the documentation for kdecore Library Version 3.4.1.
Documentation copyright © 1996-2004 the KDE developers.
Generated on Sat Jun 11 20:18:03 2005 by doxygen 1.4.1 written by Dimitri van Heesch, © 1997-2003