1 /****************************************************************************
3 ** Copyright (C) 2009 Nokia Corporation and/or its subsidiary(-ies).
4 ** All rights reserved.
5 ** Contact: Nokia Corporation (qt-info@nokia.com)
7 ** This file is part of the QtCore module of the Qt Toolkit.
9 ** $QT_BEGIN_LICENSE:LGPL$
10 ** No Commercial Usage
11 ** This file contains pre-release code and may not be distributed.
12 ** You may use this file in accordance with the terms and conditions
13 ** contained in the Technology Preview License Agreement accompanying
16 ** GNU Lesser General Public License Usage
17 ** Alternatively, this file may be used under the terms of the GNU Lesser
18 ** General Public License version 2.1 as published by the Free Software
19 ** Foundation and appearing in the file LICENSE.LGPL included in the
20 ** packaging of this file. Please review the following information to
21 ** ensure the GNU Lesser General Public License version 2.1 requirements
22 ** will be met: http://www.gnu.org/licenses/old-licenses/lgpl-2.1.html.
24 ** In addition, as a special exception, Nokia gives you certain additional
25 ** rights. These rights are described in the Nokia Qt LGPL Exception
26 ** version 1.1, included in the file LGPL_EXCEPTION.txt in this package.
28 ** If you have questions regarding the use of this file, please contact
29 ** Nokia at qt-info@nokia.com.
40 ****************************************************************************/
45 #include <QtCore/qobject.h>
46 #include <QtCore/qvariant.h>
47 #include <QtCore/qstring.h>
55 #ifndef QT_NO_SETTINGS
58 #include <QtCore/qstringlist.h>
65 #ifdef Status // we seem to pick up a macro Status --> int somewhere
70 class QSettingsPrivate
;
73 class Q_CORE_EXPORT QSettings
: public QObject
75 class Q_CORE_EXPORT QSettings
81 QScopedPointer
<QSettingsPrivate
> d_ptr
;
83 Q_DECLARE_PRIVATE(QSettings
)
125 #ifndef QT_NO_QOBJECT
126 explicit QSettings(const QString
&organization
,
127 const QString
&application
= QString(), QObject
*parent
= 0);
128 QSettings(Scope scope
, const QString
&organization
,
129 const QString
&application
= QString(), QObject
*parent
= 0);
130 QSettings(Format format
, Scope scope
, const QString
&organization
,
131 const QString
&application
= QString(), QObject
*parent
= 0);
132 QSettings(const QString
&fileName
, Format format
, QObject
*parent
= 0);
133 explicit QSettings(QObject
*parent
= 0);
135 explicit QSettings(const QString
&organization
,
136 const QString
&application
= QString());
137 QSettings(Scope scope
, const QString
&organization
,
138 const QString
&application
= QString());
139 QSettings(Format format
, Scope scope
, const QString
&organization
,
140 const QString
&application
= QString());
141 QSettings(const QString
&fileName
, Format format
);
147 Status
status() const;
149 void beginGroup(const QString
&prefix
);
151 QString
group() const;
153 int beginReadArray(const QString
&prefix
);
154 void beginWriteArray(const QString
&prefix
, int size
= -1);
156 void setArrayIndex(int i
);
158 QStringList
allKeys() const;
159 QStringList
childKeys() const;
160 QStringList
childGroups() const;
161 bool isWritable() const;
163 void setValue(const QString
&key
, const QVariant
&value
);
164 QVariant
value(const QString
&key
, const QVariant
&defaultValue
= QVariant()) const;
166 void remove(const QString
&key
);
167 bool contains(const QString
&key
) const;
169 void setFallbacksEnabled(bool b
);
170 bool fallbacksEnabled() const;
172 QString
fileName() const;
173 Format
format() const;
175 QString
organizationName() const;
176 QString
applicationName() const;
178 #ifndef QT_NO_TEXTCODEC
179 void setIniCodec(QTextCodec
*codec
);
180 void setIniCodec(const char *codecName
);
181 QTextCodec
*iniCodec() const;
184 static void setDefaultFormat(Format format
);
185 static Format
defaultFormat();
186 static void setSystemIniPath(const QString
&dir
); // ### remove in 5.0 (use setPath() instead)
187 static void setUserIniPath(const QString
&dir
); // ### remove in 5.0 (use setPath() instead)
188 static void setPath(Format format
, Scope scope
, const QString
&path
);
190 typedef QMap
<QString
, QVariant
> SettingsMap
;
191 typedef bool (*ReadFunc
)(QIODevice
&device
, SettingsMap
&map
);
192 typedef bool (*WriteFunc
)(QIODevice
&device
, const SettingsMap
&map
);
194 static Format
registerFormat(const QString
&extension
, ReadFunc readFunc
, WriteFunc writeFunc
,
195 Qt::CaseSensitivity caseSensitivity
= Qt::CaseSensitive
);
198 inline QT3_SUPPORT
bool writeEntry(const QString
&key
, bool value
)
199 { setValue(key
, value
); return isWritable(); }
200 inline QT3_SUPPORT
bool writeEntry(const QString
&key
, double value
)
201 { setValue(key
, value
); return isWritable(); }
202 inline QT3_SUPPORT
bool writeEntry(const QString
&key
, int value
)
203 { setValue(key
, value
); return isWritable(); }
204 inline QT3_SUPPORT
bool writeEntry(const QString
&key
, const char *value
)
205 { setValue(key
, QString::fromAscii(value
)); return isWritable(); }
206 inline QT3_SUPPORT
bool writeEntry(const QString
&key
, const QString
&value
)
207 { setValue(key
, value
); return isWritable(); }
208 inline QT3_SUPPORT
bool writeEntry(const QString
&key
, const QStringList
&value
)
209 { setValue(key
, value
); return isWritable(); }
210 inline QT3_SUPPORT
bool writeEntry(const QString
&key
, const QStringList
&value
, QChar separator
)
211 { setValue(key
, value
.join(QString(separator
))); return isWritable(); }
212 inline QT3_SUPPORT QStringList
readListEntry(const QString
&key
, bool *ok
= 0)
216 return value(key
).toStringList();
218 inline QT3_SUPPORT QStringList
readListEntry(const QString
&key
, QChar separator
, bool *ok
= 0)
222 QString str
= value(key
).toString();
224 return QStringList();
225 return str
.split(separator
);
227 inline QT3_SUPPORT QString
readEntry(const QString
&key
, const QString
&defaultValue
= QString(),
232 return value(key
, defaultValue
).toString();
234 inline QT3_SUPPORT
int readNumEntry(const QString
&key
, int defaultValue
= 0, bool *ok
= 0)
238 return value(key
, defaultValue
).toInt();
240 inline QT3_SUPPORT
double readDoubleEntry(const QString
&key
, double defaultValue
= 0,
245 return value(key
, defaultValue
).toDouble();
247 inline QT3_SUPPORT
bool readBoolEntry(const QString
&key
, bool defaultValue
= false,
252 return value(key
, defaultValue
).toBool();
254 inline QT3_SUPPORT
bool removeEntry(const QString
&key
)
255 { remove(key
); return true; }
257 enum System
{ Unix
, Windows
, Mac
};
258 inline QT3_SUPPORT
void insertSearchPath(System
, const QString
&) {}
259 inline QT3_SUPPORT
void removeSearchPath(System
, const QString
&) {}
261 inline QT3_SUPPORT
void setPath(const QString
&organization
, const QString
&application
,
262 Scope scope
= Global
)
264 setPath_helper(scope
== Global
? QSettings::SystemScope
: QSettings::UserScope
,
265 organization
, application
);
267 inline QT3_SUPPORT
void resetGroup()
269 while (!group().isEmpty())
272 inline QT3_SUPPORT QStringList
entryList(const QString
&key
) const
274 QSettings
*that
= const_cast<QSettings
*>(this);
277 that
->beginGroup(key
);
278 result
= that
->childKeys();
282 inline QT3_SUPPORT QStringList
subkeyList(const QString
&key
) const
284 QSettings
*that
= const_cast<QSettings
*>(this);
287 that
->beginGroup(key
);
288 result
= that
->childGroups();
295 #ifndef QT_NO_QOBJECT
296 bool event(QEvent
*event
);
301 void setPath_helper(Scope scope
, const QString
&organization
, const QString
&application
);
304 Q_DISABLE_COPY(QSettings
)
309 #endif // QT_NO_SETTINGS
313 #endif // QSETTINGS_H