00001
00002
00003
00004
00005
00006
00007
00008
00009
00010
00011
00012
00013
00014
00015
00016
00017
00018
00019
00020
00021
00022
00023
00024
00025
00026
00027
00028
00029
00030
00031
00032
00033
00034
00035
00036
00037
00038
00039
00040
00041
00042 #ifndef QSETTINGS_H
00043 #define QSETTINGS_H
00044
00045 #include <QtCore/qobject.h>
00046 #include <QtCore/qvariant.h>
00047 #include <QtCore/qstring.h>
00048
00049 QT_BEGIN_HEADER
00050
00051 QT_BEGIN_NAMESPACE
00052 QT_MODULE(Core)
00053 QT_END_NAMESPACE
00054
00055 #ifndef QT_NO_SETTINGS
00056
00057 #ifdef QT3_SUPPORT
00058 #include <QtCore/qstringlist.h>
00059 #endif
00060
00061 #include <ctype.h>
00062
00063 QT_BEGIN_NAMESPACE
00064
00065 #ifdef Status // we seem to pick up a macro Status --> int somewhere
00066 #undef Status
00067 #endif
00068
00069 class QIODevice;
00070 class QSettingsPrivate;
00071
00072 #ifndef QT_NO_QOBJECT
00073 class Q_CORE_EXPORT QSettings : public QObject
00074 #else
00075 class Q_CORE_EXPORT QSettings
00076 #endif
00077 {
00078 #ifndef QT_NO_QOBJECT
00079 Q_OBJECT
00080 #else
00081 QScopedPointer<QSettingsPrivate> d_ptr;
00082 #endif
00083 Q_DECLARE_PRIVATE(QSettings)
00084
00085 public:
00086 enum Status {
00087 NoError = 0,
00088 AccessError,
00089 FormatError
00090 };
00091
00092 enum Format {
00093 NativeFormat,
00094 IniFormat,
00095
00096 InvalidFormat = 16,
00097 CustomFormat1,
00098 CustomFormat2,
00099 CustomFormat3,
00100 CustomFormat4,
00101 CustomFormat5,
00102 CustomFormat6,
00103 CustomFormat7,
00104 CustomFormat8,
00105 CustomFormat9,
00106 CustomFormat10,
00107 CustomFormat11,
00108 CustomFormat12,
00109 CustomFormat13,
00110 CustomFormat14,
00111 CustomFormat15,
00112 CustomFormat16
00113 };
00114
00115 enum Scope {
00116 UserScope,
00117 SystemScope
00118 #ifdef QT3_SUPPORT
00119 ,
00120 User = UserScope,
00121 Global = SystemScope
00122 #endif
00123 };
00124
00125 #ifndef QT_NO_QOBJECT
00126 explicit QSettings(const QString &organization,
00127 const QString &application = QString(), QObject *parent = 0);
00128 QSettings(Scope scope, const QString &organization,
00129 const QString &application = QString(), QObject *parent = 0);
00130 QSettings(Format format, Scope scope, const QString &organization,
00131 const QString &application = QString(), QObject *parent = 0);
00132 QSettings(const QString &fileName, Format format, QObject *parent = 0);
00133 explicit QSettings(QObject *parent = 0);
00134 #else
00135 explicit QSettings(const QString &organization,
00136 const QString &application = QString());
00137 QSettings(Scope scope, const QString &organization,
00138 const QString &application = QString());
00139 QSettings(Format format, Scope scope, const QString &organization,
00140 const QString &application = QString());
00141 QSettings(const QString &fileName, Format format);
00142 #endif
00143 ~QSettings();
00144
00145 void clear();
00146 void sync();
00147 Status status() const;
00148
00149 void beginGroup(const QString &prefix);
00150 void endGroup();
00151 QString group() const;
00152
00153 int beginReadArray(const QString &prefix);
00154 void beginWriteArray(const QString &prefix, int size = -1);
00155 void endArray();
00156 void setArrayIndex(int i);
00157
00158 QStringList allKeys() const;
00159 QStringList childKeys() const;
00160 QStringList childGroups() const;
00161 bool isWritable() const;
00162
00163 void setValue(const QString &key, const QVariant &value);
00164 QVariant value(const QString &key, const QVariant &defaultValue = QVariant()) const;
00165
00166 void remove(const QString &key);
00167 bool contains(const QString &key) const;
00168
00169 void setFallbacksEnabled(bool b);
00170 bool fallbacksEnabled() const;
00171
00172 QString fileName() const;
00173 Format format() const;
00174 Scope scope() const;
00175 QString organizationName() const;
00176 QString applicationName() const;
00177
00178 #ifndef QT_NO_TEXTCODEC
00179 void setIniCodec(QTextCodec *codec);
00180 void setIniCodec(const char *codecName);
00181 QTextCodec *iniCodec() const;
00182 #endif
00183
00184 static void setDefaultFormat(Format format);
00185 static Format defaultFormat();
00186 static void setSystemIniPath(const QString &dir);
00187 static void setUserIniPath(const QString &dir);
00188 static void setPath(Format format, Scope scope, const QString &path);
00189
00190 typedef QMap<QString, QVariant> SettingsMap;
00191 typedef bool (*ReadFunc)(QIODevice &device, SettingsMap &map);
00192 typedef bool (*WriteFunc)(QIODevice &device, const SettingsMap &map);
00193
00194 static Format registerFormat(const QString &extension, ReadFunc readFunc, WriteFunc writeFunc,
00195 Qt::CaseSensitivity caseSensitivity = Qt::CaseSensitive);
00196
00197 #ifdef QT3_SUPPORT
00198 inline QT3_SUPPORT bool writeEntry(const QString &key, bool value)
00199 { setValue(key, value); return isWritable(); }
00200 inline QT3_SUPPORT bool writeEntry(const QString &key, double value)
00201 { setValue(key, value); return isWritable(); }
00202 inline QT3_SUPPORT bool writeEntry(const QString &key, int value)
00203 { setValue(key, value); return isWritable(); }
00204 inline QT3_SUPPORT bool writeEntry(const QString &key, const char *value)
00205 { setValue(key, QString::fromAscii(value)); return isWritable(); }
00206 inline QT3_SUPPORT bool writeEntry(const QString &key, const QString &value)
00207 { setValue(key, value); return isWritable(); }
00208 inline QT3_SUPPORT bool writeEntry(const QString &key, const QStringList &value)
00209 { setValue(key, value); return isWritable(); }
00210 inline QT3_SUPPORT bool writeEntry(const QString &key, const QStringList &value, QChar separator)
00211 { setValue(key, value.join(QString(separator))); return isWritable(); }
00212 inline QT3_SUPPORT QStringList readListEntry(const QString &key, bool *ok = 0)
00213 {
00214 if (ok)
00215 *ok = contains(key);
00216 return value(key).toStringList();
00217 }
00218 inline QT3_SUPPORT QStringList readListEntry(const QString &key, QChar separator, bool *ok = 0)
00219 {
00220 if (ok)
00221 *ok = contains(key);
00222 QString str = value(key).toString();
00223 if (str.isEmpty())
00224 return QStringList();
00225 return str.split(separator);
00226 }
00227 inline QT3_SUPPORT QString readEntry(const QString &key, const QString &defaultValue = QString(),
00228 bool *ok = 0)
00229 {
00230 if (ok)
00231 *ok = contains(key);
00232 return value(key, defaultValue).toString();
00233 }
00234 inline QT3_SUPPORT int readNumEntry(const QString &key, int defaultValue = 0, bool *ok = 0)
00235 {
00236 if (ok)
00237 *ok = contains(key);
00238 return value(key, defaultValue).toInt();
00239 }
00240 inline QT3_SUPPORT double readDoubleEntry(const QString &key, double defaultValue = 0,
00241 bool *ok = 0)
00242 {
00243 if (ok)
00244 *ok = contains(key);
00245 return value(key, defaultValue).toDouble();
00246 }
00247 inline QT3_SUPPORT bool readBoolEntry(const QString &key, bool defaultValue = false,
00248 bool *ok = 0)
00249 {
00250 if (ok)
00251 *ok = contains(key);
00252 return value(key, defaultValue).toBool();
00253 }
00254 inline QT3_SUPPORT bool removeEntry(const QString &key)
00255 { remove(key); return true; }
00256
00257 enum System { Unix, Windows, Mac };
00258 inline QT3_SUPPORT void insertSearchPath(System, const QString &) {}
00259 inline QT3_SUPPORT void removeSearchPath(System, const QString &) {}
00260
00261 inline QT3_SUPPORT void setPath(const QString &organization, const QString &application,
00262 Scope scope = Global)
00263 {
00264 setPath_helper(scope == Global ? QSettings::SystemScope : QSettings::UserScope,
00265 organization, application);
00266 }
00267 inline QT3_SUPPORT void resetGroup()
00268 {
00269 while (!group().isEmpty())
00270 endGroup();
00271 }
00272 inline QT3_SUPPORT QStringList entryList(const QString &key) const
00273 {
00274 QSettings *that = const_cast<QSettings *>(this);
00275 QStringList result;
00276
00277 that->beginGroup(key);
00278 result = that->childKeys();
00279 that->endGroup();
00280 return result;
00281 }
00282 inline QT3_SUPPORT QStringList subkeyList(const QString &key) const
00283 {
00284 QSettings *that = const_cast<QSettings *>(this);
00285 QStringList result;
00286
00287 that->beginGroup(key);
00288 result = that->childGroups();
00289 that->endGroup();
00290 return result;
00291 }
00292 #endif
00293
00294 protected:
00295 #ifndef QT_NO_QOBJECT
00296 bool event(QEvent *event);
00297 #endif
00298
00299 private:
00300 #ifdef QT3_SUPPORT
00301 void setPath_helper(Scope scope, const QString &organization, const QString &application);
00302 #endif
00303
00304 Q_DISABLE_COPY(QSettings)
00305 };
00306
00307 QT_END_NAMESPACE
00308
00309 #endif // QT_NO_SETTINGS
00310
00311 QT_END_HEADER
00312
00313 #endif // QSETTINGS_H