• Skip to content
  • Skip to link menu
Trinity API Reference
  • Trinity API Reference
  • kdecore
 

kdecore

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 <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 "kconfigdata.h"
00036 #include "kdelibs_export.h"
00037 
00038 class KConfigBackEnd;
00039 class KConfigBasePrivate;
00040 class KConfigGroup;
00041 
00070 class KDECORE_EXPORT KConfigBase : public TQObject
00071 {
00072   Q_OBJECT
00073   TQ_OBJECT
00074 
00075   friend class KConfigBackEnd;
00076   friend class KConfigINIBackEnd;
00077   friend class KConfigGroup;
00078 
00079 public:
00083   KConfigBase();
00084 
00088   virtual ~KConfigBase();
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 
01602   void writePathEntry( const TQString& pKey, const TQStringList &rValue,
01603            char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
01627   void writePathEntry( const char *pKey, const TQStringList &rValue,
01628            char sep = ',', bool bPersistent = true, bool bGlobal = false, bool bNLS = false );
01629 
01630 
01639    void deleteEntry( const TQString& pKey,
01640                    bool bNLS = false, bool bGlobal = false);
01649    void deleteEntry( const char *pKey,
01650                    bool bNLS = false, bool bGlobal = false);
01651 
01669   bool deleteGroup( const TQString& group, bool bDeep = true, bool bGlobal = false );
01670 
01671 
01679   void setDollarExpansion( bool _bExpand = true ) { bExpand = _bExpand; }
01680 
01686   bool isDollarExpansion() const { return bExpand; }
01687 
01702   virtual void rollback( bool bDeep = true );
01703 
01717   virtual void sync();
01718 
01723   bool isDirty() const { return bDirty; }
01724 
01732   virtual void setReadOnly(bool _ro) { bReadOnly = _ro; }
01733 
01739   bool isReadOnly() const { return bReadOnly; }
01740 
01750   bool hasKey( const TQString& key ) const;
01751 
01762   virtual TQMap<TQString, TQString> entryMap(const TQString &group) const = 0;
01763 
01776   virtual void reparseConfiguration() = 0;
01777 
01782   bool isImmutable() const;
01783 
01790   bool groupIsImmutable(const TQString &group) const;
01791 
01798   bool entryIsImmutable(const TQString &key) const;
01799 
01805   enum ConfigState { NoAccess, ReadOnly, ReadWrite };
01806 
01820   ConfigState getConfigState() const;
01821 
01828   bool checkConfigFilesWritable(bool warnUser);
01829 
01836   void setReadDefaults(bool b);
01837 
01843   bool readDefaults() const;
01844 
01856   void revertToDefault(const TQString &key);
01857 
01884   bool hasDefault(const TQString &key) const;
01885 
01886 protected:
01892   void setLocale();
01893 
01899   virtual void setDirty(bool _bDirty = true) { bDirty = _bDirty; }
01900 
01906   virtual void parseConfigFiles();
01907 
01923   virtual KEntryMap internalEntryMap( const TQString& pGroup ) const = 0;
01924 
01936   virtual KEntryMap internalEntryMap() const = 0;
01937 
01953   virtual void putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup = true) = 0;
01954 
01969   virtual KEntry lookupData(const KEntryKey &_key) const = 0;
01970 
01971   virtual bool internalHasGroup(const TQCString &group) const = 0;
01972 
01976   KConfigBackEnd *backEnd;
01977 public:
01981   void setGroup( const TQCString &pGroup );
01982   void setGroup( const char *pGroup );
01983   bool hasGroup(const TQCString &_pGroup) const;
01984   bool hasGroup(const char *_pGroup) const;
01985   bool hasKey( const char *pKey ) const;
01986 
01987 protected:
01988   TQCString readEntryUtf8( const char *pKey) const;
01989   bool hasTranslatedKey( const char *pKey ) const;
01990 
01993   TQCString mGroup;
01994 
01997   TQCString aLocaleString;
01998 
02002   bool bDirty;
02003 
02004   bool bLocaleInitialized;
02005   bool bReadOnly;           // currently only used by KSimpleConfig
02006   mutable bool bExpand;     // whether dollar expansion is used
02007 
02008 protected:
02009   virtual void virtual_hook( int id, void* data );
02010 private:
02011   class KConfigBasePrivate;
02012   KConfigBasePrivate *d;
02013 
02014   void writeEntry( const char *pKey, const TQString &rValue,
02015     bool bPersistent, bool bGlobal, bool bNLS, bool bExpand );
02016   void writeEntry( const char *pKey, const TQStringList &rValue,
02017     char sep, bool bPersistent, bool bGlobal, bool bNLS, bool bExpand );
02018 
02019 };
02020 
02021 class KConfigGroupSaverPrivate;
02022 
02059 class KDECORE_EXPORT KConfigGroupSaver // KDE4 remove
02060 {
02061 public:
02071   KConfigGroupSaver( KConfigBase* config, TQString group )
02072       /* KDE 4 : make the second parameter const TQString & */
02073       : _config(config), _oldgroup(config->group())
02074         { _config->setGroup( group ); }
02075 
02076   KConfigGroupSaver( KConfigBase* config, const char *group )
02077       : _config(config), _oldgroup(config->group())
02078         { _config->setGroup( group ); }
02079 
02080   KConfigGroupSaver( KConfigBase* config, const TQCString &group )
02081       : _config(config), _oldgroup(config->group())
02082         { _config->setGroup( group ); }
02083 
02084   ~KConfigGroupSaver() { _config->setGroup( _oldgroup ); }
02085 
02086     KConfigBase* config() { return _config; };
02087 
02088 private:
02089   KConfigBase* _config;
02090   TQString _oldgroup;
02091 
02092   KConfigGroupSaver(const KConfigGroupSaver&);
02093   KConfigGroupSaver& operator=(const KConfigGroupSaver&);
02094 
02095   KConfigGroupSaverPrivate *d;
02096 };
02097 
02098 class KConfigGroupPrivate;
02099 
02103 class KDECORE_EXPORT KConfigGroup: public KConfigBase
02104 {
02105 public:
02110    KConfigGroup(KConfigBase *master, const TQCString &group);
02117    KConfigGroup(KConfigBase *master, const TQString &group);
02125    KConfigGroup(KConfigBase *master, const char * group);
02126 
02133    void deleteGroup(bool bGlobal = false);
02134 
02141   bool groupIsImmutable() const;
02142 
02143    // The following functions are reimplemented:
02144    virtual void setDirty(bool _bDirty);
02145    virtual void putData(const KEntryKey &_key, const KEntry &_data, bool _checkGroup = true);
02146    virtual KEntry lookupData(const KEntryKey &_key) const;
02147    virtual void sync();
02148 
02149 private:
02150    // Hide the following members:
02151    void setGroup() { }
02152    void setDesktopGroup() { }
02153    void group() { }
02154    void hasGroup() { }
02155    void setReadOnly(bool) { }
02156    void isDirty() { }
02157 
02158    // The following members are not used.
02159    virtual TQStringList groupList() const { return TQStringList(); }
02160    virtual void rollback(bool) { }
02161    virtual void reparseConfiguration() { }
02162    virtual TQMap<TQString, TQString> entryMap(const TQString &) const
02163     { return TQMap<TQString,TQString>(); }
02164    virtual KEntryMap internalEntryMap( const TQString&) const
02165     { return KEntryMap(); }
02166    virtual KEntryMap internalEntryMap() const
02167     { return KEntryMap(); }
02168    virtual bool internalHasGroup(const TQCString &) const
02169     { return false; }
02170 
02171    void getConfigState() { }
02172 
02173    KConfigBase *mMaster;
02174 protected:
02175    virtual void virtual_hook( int id, void* data );
02176 private:
02177    KConfigGroupPrivate* d;
02178 };
02179 
02180 #endif

kdecore

Skip menu "kdecore"
  • Main Page
  • Modules
  • Namespace List
  • Class Hierarchy
  • Alphabetical List
  • Class List
  • File List
  • Namespace Members
  • Class Members
  • Related Pages

kdecore

Skip menu "kdecore"
  • arts
  • dcop
  • dnssd
  • interfaces
  •     interface
  •     library
  •   kspeech
  •   ktexteditor
  • kabc
  • kate
  • kcmshell
  • kdecore
  • kded
  • kdefx
  • kdeprint
  • kdesu
  • kdeui
  • kdoctools
  • khtml
  • kimgio
  • kinit
  • kio
  •   bookmarks
  •   httpfilter
  •   kfile
  •   kio
  •   kioexec
  •   kpasswdserver
  •   kssl
  • kioslave
  •   http
  • kjs
  • kmdi
  •   kmdi
  • knewstuff
  • kparts
  • krandr
  • kresources
  • kspell2
  • kunittest
  • kutils
  • kwallet
  • libkmid
  • libkscreensaver
Generated for kdecore by doxygen 1.7.6.1
This website is maintained by Timothy Pearson.
KDE® and the K Desktop Environment® logo are registered trademarks of KDE e.V. |