kdecore Library API Documentation

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 // $Id: kconfigbase.h,v 1.83 2002/09/08 14:55:41 tjansen Exp $
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 
00317   int readNumEntry( const QString& pKey, int nDefault = 0 ) const;
00318 
00330   int readNumEntry( const char *pKey, int nDefault = 0 ) const;
00331 
00343   unsigned int readUnsignedNumEntry( const QString& pKey, unsigned int nDefault = 0 ) const;
00344 
00356   unsigned int readUnsignedNumEntry( const char *pKey, unsigned int nDefault = 0 ) const;
00357 
00358 
00370   long readLongNumEntry( const QString& pKey, long nDefault = 0 ) const;
00371 
00383   long readLongNumEntry( const char *pKey, long nDefault = 0 ) const;
00384 
00396   unsigned long readUnsignedLongNumEntry( const QString& pKey, unsigned long nDefault = 0 ) const;
00397 
00409   unsigned long readUnsignedLongNumEntry( const char *pKey, unsigned long nDefault = 0 ) const;
00410 
00422   double readDoubleNumEntry( const QString& pKey, double nDefault = 0.0 ) const;
00423 
00435   double readDoubleNumEntry( const char *pKey, double nDefault = 0.0 ) const;
00436 
00448   QFont readFontEntry( const QString& pKey, const QFont* pDefault = 0L ) const;
00449 
00461   QFont readFontEntry( const char *pKey, const QFont* pDefault = 0L ) const;
00462 
00474   bool readBoolEntry( const QString& pKey, const bool bDefault = false ) const;
00475 
00487   bool readBoolEntry( const char *pKey, const bool bDefault = false ) const;
00488 
00500   QRect readRectEntry( const QString& pKey, const QRect* pDefault = 0L ) const;
00501 
00513   QRect readRectEntry( const char *pKey, const QRect* pDefault = 0L ) const;
00514 
00526   QPoint readPointEntry( const QString& pKey, const QPoint* pDefault = 0L ) const;
00527 
00539   QPoint readPointEntry( const char *pKey, const QPoint* pDefault = 0L ) const;
00540 
00552   QSize readSizeEntry( const QString& pKey, const QSize* pDefault = 0L ) const;
00553 
00565   QSize readSizeEntry( const char *pKey, const QSize* pDefault = 0L ) const;
00566 
00567 
00579   QColor readColorEntry( const QString& pKey, const QColor* pDefault = 0L ) const;
00580 
00592   QColor readColorEntry( const char *pKey, const QColor* pDefault = 0L ) const;
00593 
00606   QDateTime readDateTimeEntry( const QString& pKey, const QDateTime* pDefault = 0L ) const;
00607 
00620   QDateTime readDateTimeEntry( const char *pKey, const QDateTime* pDefault = 0L ) const;
00621 
00630    QString readEntryUntranslated( const QString& pKey,
00631                      const QString& aDefault = QString::null ) const;
00632 
00641    QString readEntryUntranslated( const char *pKey,
00642                      const QString& aDefault = QString::null ) const;
00643 
00661   void writeEntry( const QString& pKey, const QString& pValue,
00662                       bool bPersistent = true, bool bGlobal = false,
00663                       bool bNLS = false );
00664 
00682   void writeEntry( const char *pKey, const QString& pValue,
00683                       bool bPersistent = true, bool bGlobal = false,
00684                       bool bNLS = false );
00685 
00705   void writeEntry( const QString& pKey, const QVariant& rValue,
00706                     bool bPersistent = true, bool bGlobal = false,
00707                     bool bNLS = false );
00727   void writeEntry( const char *pKey, const QVariant& rValue,
00728                     bool bPersistent = true, bool bGlobal = false,
00729                     bool bNLS = false );
00730 
00750   void writeEntry( const QString& pKey, const QStrList &rValue,
00751            char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00771   void writeEntry( const char *pKey, const QStrList &rValue,
00772            char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00773 
00793   void writeEntry( const QString& pKey, const QStringList &rValue,
00794            char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00814   void writeEntry( const char *pKey, const QStringList &rValue,
00815            char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00816 
00817 
00837   void writeEntry( const QString& pKey, const QValueList<int>& rValue,
00838            bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00858   void writeEntry( const char *pKey, const QValueList<int>& rValue,
00859            bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
00860 
00878   void writeEntry( const QString& pKey, const char *pValue,
00879                       bool bPersistent = true, bool bGlobal = false,
00880                       bool bNLS = false )
00881     { writeEntry(pKey, QString::fromLatin1(pValue), bPersistent, bGlobal, bNLS); }
00899   void writeEntry( const char *pKey, const char *pValue,
00900                       bool bPersistent = true, bool bGlobal = false,
00901                       bool bNLS = false )
00902     { writeEntry(pKey, QString::fromLatin1(pValue), bPersistent, bGlobal, bNLS); }
00903 
00919   void writeEntry( const QString& pKey, int nValue,
00920                       bool bPersistent = true, bool bGlobal = false,
00921                       bool bNLS = false );
00937   void writeEntry( const char *pKey, int nValue,
00938                       bool bPersistent = true, bool bGlobal = false,
00939                       bool bNLS = false );
00940 
00956   void writeEntry( const QString& pKey, unsigned int nValue,
00957                       bool bPersistent = true, bool bGlobal = false,
00958                       bool bNLS = false );
00974   void writeEntry( const char *pKey, unsigned int nValue,
00975                       bool bPersistent = true, bool bGlobal = false,
00976                       bool bNLS = false );
00977 
00992   void writeEntry( const QString& pKey, long nValue,
00993                       bool bPersistent = true, bool bGlobal = false,
00994                       bool bNLS = false );
01009   void writeEntry( const char *pKey, long nValue,
01010                       bool bPersistent = true, bool bGlobal = false,
01011                       bool bNLS = false );
01012 
01027   void writeEntry( const QString& pKey, unsigned long nValue,
01028                       bool bPersistent = true, bool bGlobal = false,
01029                       bool bNLS = false );
01044   void writeEntry( const char *pKey, unsigned long nValue,
01045                       bool bPersistent = true, bool bGlobal = false,
01046                       bool bNLS = false );
01047 
01065   void writeEntry( const QString& pKey, double nValue,
01066                       bool bPersistent = true, bool bGlobal = false,
01067                       char format = 'g', int precision = 6,
01068                       bool bNLS = false );
01086   void writeEntry( const char *pKey, double nValue,
01087                       bool bPersistent = true, bool bGlobal = false,
01088                       char format = 'g', int precision = 6,
01089                       bool bNLS = false );
01090 
01105   void writeEntry( const QString& pKey, bool bValue,
01106                       bool bPersistent = true, bool bGlobal = false,
01107                       bool bNLS = false );
01122   void writeEntry( const char *pKey, bool bValue,
01123                       bool bPersistent = true, bool bGlobal = false,
01124                       bool bNLS = false );
01125 
01140   void writeEntry( const QString& pKey, const QFont& rFont,
01141                       bool bPersistent = true, bool bGlobal = false,
01142                       bool bNLS = false );
01157   void writeEntry( const char *pKey, const QFont& rFont,
01158                       bool bPersistent = true, bool bGlobal = false,
01159                       bool bNLS = false );
01160 
01178   void writeEntry( const QString& pKey, const QColor& rColor,
01179                    bool bPersistent = true, bool bGlobal = false,
01180                    bool bNLS = false );
01198   void writeEntry( const char *pKey, const QColor& rColor,
01199                    bool bPersistent = true, bool bGlobal = false,
01200                    bool bNLS = false );
01201 
01219   void writeEntry( const QString& pKey, const QDateTime& rDateTime,
01220                    bool bPersistent = true, bool bGlobal = false,
01221                    bool bNLS = false );
01239   void writeEntry( const char *pKey, const QDateTime& rDateTime,
01240                    bool bPersistent = true, bool bGlobal = false,
01241                    bool bNLS = false );
01242 
01243 
01261   void writeEntry( const QString& pKey, const QRect& rValue,
01262                    bool bPersistent = true, bool bGlobal = false,
01263                    bool bNLS = false );
01281   void writeEntry( const char *pKey, const QRect& rValue,
01282                    bool bPersistent = true, bool bGlobal = false,
01283                    bool bNLS = false );
01284 
01302   void writeEntry( const QString& pKey, const QPoint& rValue,
01303                    bool bPersistent = true, bool bGlobal = false,
01304                    bool bNLS = false );
01322   void writeEntry( const char *pKey, const QPoint& rValue,
01323                    bool bPersistent = true, bool bGlobal = false,
01324                    bool bNLS = false );
01325 
01343   void writeEntry( const QString& pKey, const QSize& rValue,
01344                    bool bPersistent = true, bool bGlobal = false,
01345                    bool bNLS = false );
01363   void writeEntry( const char *pKey, const QSize& rValue,
01364                    bool bPersistent = true, bool bGlobal = false,
01365                    bool bNLS = false );
01366 
01384   void writePathEntry( const QString& pKey, const QString & path,
01385                        bool bPersistent = true, bool bGlobal = false,
01386                        bool bNLS = false );
01404   void writePathEntry( const char *pKey, const QString & path,
01405                        bool bPersistent = true, bool bGlobal = false,
01406                        bool bNLS = false );
01407 
01408 
01417    void deleteEntry( const QString& pKey,
01418                    bool bNLS = false, bool bGlobal = false);
01427    void deleteEntry( const char *pKey,
01428                    bool bNLS = false, bool bGlobal = false);
01429 
01447   bool deleteGroup( const QString& group, bool bDeep = true, bool bGlobal = false );
01448 
01449 
01457   void setDollarExpansion( bool _bExpand = true ) { bExpand = _bExpand; }
01458 
01464   bool isDollarExpansion() const { return bExpand; }
01465 
01480   virtual void rollback( bool bDeep = true );
01481 
01495   virtual void sync();
01496 
01501   bool isDirty() const { return bDirty; }
01502 
01510   virtual void setReadOnly(bool _ro) { bReadOnly = _ro; }
01511 
01517   bool isReadOnly() const { return bReadOnly; }
01518 
01528   bool hasKey( const QString& key ) const;
01529 
01540   virtual QMap<QString, QString> entryMap(const QString &group) const = 0;
01541 
01554   virtual void reparseConfiguration() = 0;
01555 
01560   bool isImmutable() const;
01561 
01568   bool groupIsImmutable(const QString &group) const;
01569 
01576   bool entryIsImmutable(const QString &key) const;
01577 
01583   enum ConfigState { NoAccess, ReadOnly, ReadWrite };
01584 
01598   ConfigState getConfigState() const;
01599 
01600 protected:
01606   void setLocale();
01607 
01613   virtual void setDirty(bool _bDirty = true) { bDirty = _bDirty; }
01614 
01620   virtual void parseConfigFiles();
01621 
01637   virtual KEntryMap internalEntryMap( const QString& pGroup ) const = 0;
01638 
01650   virtual KEntryMap internalEntryMap() const = 0;
01651 
01667   virtual void putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup = true) = 0;
01668 
01683   virtual KEntry lookupData(const KEntryKey &_key) const = 0;
01684 
01685   virtual bool internalHasGroup(const QCString &group) const = 0;
01686 
01690   KConfigBackEnd *backEnd;
01691 public:
01695   void setGroup( const QCString &pGroup );
01696   void setGroup( const char *pGroup );
01697   bool hasGroup(const QCString &_pGroup) const;
01698   bool hasGroup(const char *_pGroup) const;
01699   bool hasKey( const char *pKey ) const;
01700 
01701 protected:
01702   QCString readEntryUtf8( const char *pKey) const;
01703 
01706   QCString mGroup;
01707 
01710   QCString aLocaleString;
01711 
01715   bool bDirty;
01716 
01717   bool bLocaleInitialized;
01718   bool bReadOnly;           // currently only used by KSimpleConfig
01719   mutable bool bExpand;     // whether dollar expansion is used
01720 
01721 protected:
01722   virtual void virtual_hook( int id, void* data );
01723 private:
01724   KConfigBasePrivate *d;
01725 };
01726 
01727 class KConfigGroupSaverPrivate;
01728 
01762 class KConfigGroupSaver
01763 {
01764 public:
01773   KConfigGroupSaver( KConfigBase* config, QString group )
01774       : _config(config), _oldgroup(config->group())
01775         { _config->setGroup( group ); }
01776 
01777   KConfigGroupSaver( KConfigBase* config, const char *group )
01778       : _config(config), _oldgroup(config->group())
01779         { _config->setGroup( group ); }
01780 
01781   KConfigGroupSaver( KConfigBase* config, const QCString &group )
01782       : _config(config), _oldgroup(config->group())
01783         { _config->setGroup( group ); }
01784 
01785   ~KConfigGroupSaver() { _config->setGroup( _oldgroup ); }
01786 
01787     KConfigBase* config() { return _config; };
01788 
01789 private:
01790   KConfigBase* _config;
01791   QString _oldgroup;
01792 
01793   KConfigGroupSaver(const KConfigGroupSaver&);
01794   KConfigGroupSaver& operator=(const KConfigGroupSaver&);
01795 
01796   KConfigGroupSaverPrivate *d;
01797 };
01798 
01799 class KConfigGroupPrivate;
01800 
01801 class KConfigGroup: public KConfigBase
01802 {
01803 public:
01808    KConfigGroup(KConfigBase *master, const QCString &group);
01815    KConfigGroup(KConfigBase *master, const QString &group);
01823    KConfigGroup(KConfigBase *master, const char * group);
01824 
01831    void deleteGroup(bool bGlobal = false);
01832 
01833    // The following functions are reimplemented:
01834    virtual void setDirty(bool b);
01835    virtual void putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup = true);
01836    virtual KEntry lookupData(const KEntryKey &_key) const;
01837    virtual void sync();
01838 
01839 private:
01840    // Hide the following members:
01841    void setGroup() { }
01842    void setDesktopGroup() { }
01843    void group() { }
01844    void hasGroup() { }
01845    void setReadOnly(bool) { }
01846    void isDirty() { }
01847 
01848    // The following members are not used.
01849    virtual QStringList groupList() const { return QStringList(); }
01850    virtual void rollback(bool) { }
01851    virtual void reparseConfiguration() { }
01852    virtual QMap<QString, QString> entryMap(const QString &) const
01853     { return QMap<QString,QString>(); }
01854    virtual KEntryMap internalEntryMap( const QString&) const
01855     { return KEntryMap(); }
01856    virtual KEntryMap internalEntryMap() const
01857     { return KEntryMap(); }
01858    virtual bool internalHasGroup(const QCString &) const
01859     { return false; }
01860 
01861    void getConfigState() { }
01862 
01863    KConfigBase *mMaster;
01864 protected:
01865    virtual void virtual_hook( int id, void* data );
01866 private:
01867    KConfigGroupPrivate* d;
01868 };
01869 
01870 #endif
KDE Logo
This file is part of the documentation for kdelibs Version 3.1.0.
Documentation copyright © 1996-2002 the KDE developers.
Generated on Wed Oct 8 12:20:40 2003 by doxygen 1.2.18 written by Dimitri van Heesch, © 1997-2001