Qtopia library API Documentation

config.h

00001 /**********************************************************************
00002 ** Copyright (C) 2000 Trolltech AS.  All rights reserved.
00003 **
00004 ** This file is part of Qtopia Environment.
00005 **
00006 ** This file may be distributed and/or modified under the terms of the
00007 ** GNU General Public License version 2 as published by the Free Software
00008 ** Foundation and appearing in the file LICENSE.GPL included in the
00009 ** packaging of this file.
00010 **
00011 ** This file is provided AS IS with NO WARRANTY OF ANY KIND, INCLUDING THE
00012 ** WARRANTY OF DESIGN, MERCHANTABILITY AND FITNESS FOR A PARTICULAR PURPOSE.
00013 **
00014 ** See http://www.trolltech.com/gpl/ for GPL licensing information.
00015 **
00016 ** Contact info@trolltech.com if any conditions of this licensing are
00017 ** not clear to you.
00018 **
00019 **********************************************************************/
00020 
00021 #ifndef CONFIG_H
00022 #define CONFIG_H
00023 
00024 // ##### could use QSettings with Qt 3.0
00025 
00026 #include <qmap.h>
00027 #include <qstringlist.h>
00028 
00029 class ConfigPrivate;
00030 class Config
00031 {
00032 public:
00033     typedef QMap< QString, QString > ConfigGroup;
00034     
00035     enum Domain { File, User };
00036     Config( const QString &name, Domain domain=User );
00037     ~Config();
00038     
00039     bool operator == ( const Config & other ) const { return (filename == other.filename); }
00040     bool operator != ( const Config & other ) const { return (filename != other.filename); }
00041     
00042     bool isValid() const;
00043     bool hasKey( const QString &key ) const;
00044 
00045     // inline for better SharpROM BC
00046     inline bool hasGroup ( const QString &gname ) const  { return ( groups. find ( gname ) != groups. end ( )); };
00047     inline QStringList groupList ( ) const { QStringList sl; for ( QMap< QString, ConfigGroup >::ConstIterator it = groups. begin ( ); it != groups. end ( ); ++it ) { sl << it.key(); } return sl; };
00048     
00049     void setGroup( const QString &gname );
00050     void writeEntry( const QString &key, const char* value );
00051     void writeEntry( const QString &key, const QString &value );
00052     void writeEntryCrypt( const QString &key, const QString &value );
00053     void writeEntry( const QString &key, int num );
00054 #ifdef Q_HAS_BOOL_TYPE
00055     void writeEntry( const QString &key, bool b );
00056 #endif
00057     void writeEntry( const QString &key, const QStringList &lst, const QChar &sep );
00058     void removeEntry( const QString &key );
00059     
00060     QString readEntry( const QString &key, const QString &deflt = QString::null ) const;
00061     QString readEntryCrypt( const QString &key, const QString &deflt = QString::null ) const;
00062     QString readEntryDirect( const QString &key, const QString &deflt = QString::null ) const;
00063     int readNumEntry( const QString &key, int deflt = -1 ) const;
00064     bool readBoolEntry( const QString &key, bool deflt = FALSE ) const;
00065     QStringList readListEntry( const QString &key, const QChar &sep ) const;
00066 
00067     // For compatibility, non-const versions.
00068     QString readEntry( const QString &key, const QString &deflt );
00069     QString readEntryCrypt( const QString &key, const QString &deflt );
00070     QString readEntryDirect( const QString &key, const QString &deflt );
00071     int readNumEntry( const QString &key, int deflt );
00072     bool readBoolEntry( const QString &key, bool deflt );
00073     QStringList readListEntry( const QString &key, const QChar &sep );
00074     
00075     void clearGroup();
00076     
00077     void write( const QString &fn = QString::null );
00078     
00079 protected:
00080     void read();
00081     bool parse( const QString &line );
00082     
00083     QMap< QString, ConfigGroup > groups;
00084     QMap< QString, ConfigGroup >::Iterator git;
00085     QString filename;
00086     QString lang;
00087     QString glang;
00088     bool changed;
00089     ConfigPrivate *d;
00090     static QString configFilename(const QString& name, Domain);
00091 
00092 private: // Sharp ROM compatibility
00093     Config( const QString &name, bool what );
00094 };
00095 
00096 inline QString Config::readEntry( const QString &key, const QString &deflt ) const
00097 { return ((Config*)this)->readEntry(key,deflt); }
00098 inline QString Config::readEntryCrypt( const QString &key, const QString &deflt ) const
00099 { return ((Config*)this)->readEntryCrypt(key,deflt); }
00100 inline QString Config::readEntryDirect( const QString &key, const QString &deflt ) const
00101 { return ((Config*)this)->readEntryDirect(key,deflt); }
00102 inline int Config::readNumEntry( const QString &key, int deflt ) const
00103 { return ((Config*)this)->readNumEntry(key,deflt); }
00104 inline bool Config::readBoolEntry( const QString &key, bool deflt ) const
00105 { return ((Config*)this)->readBoolEntry(key,deflt); }
00106 inline QStringList Config::readListEntry( const QString &key, const QChar &sep ) const
00107 { return ((Config*)this)->readListEntry(key,sep); }
00108 
00109 #endif
KDE Logo
This file is part of the documentation for OPIE Version 1.5.5.
Documentation copyright © 1997-2003 the KDE developers. 2003 OPIE developers
Generated on Tue Feb 10 20:24:03 2004 by doxygen 1.3.5 written by Dimitri van Heesch, © 1997-2001