config.h
00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021 #ifndef CONFIG_H
00022 #define CONFIG_H
00023
00024
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
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
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:
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
This file is part of the documentation for OPIE Version 1.5.5.