Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qsettings.cpp |
Switch to Source code | Preprocessed file |
Line | Source | Count | ||||||||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | - | |||||||||||||||||||
2 | - | |||||||||||||||||||
3 | - | |||||||||||||||||||
4 | - | |||||||||||||||||||
5 | - | |||||||||||||||||||
6 | - | |||||||||||||||||||
7 | - | |||||||||||||||||||
8 | - | |||||||||||||||||||
9 | - | |||||||||||||||||||
10 | - | |||||||||||||||||||
11 | - | |||||||||||||||||||
12 | - | |||||||||||||||||||
13 | - | |||||||||||||||||||
14 | - | |||||||||||||||||||
15 | - | |||||||||||||||||||
16 | - | |||||||||||||||||||
17 | struct QConfFileCustomFormat | - | ||||||||||||||||||
18 | { | - | ||||||||||||||||||
19 | QString extension; | - | ||||||||||||||||||
20 | QSettings::ReadFunc readFunc; | - | ||||||||||||||||||
21 | QSettings::WriteFunc writeFunc; | - | ||||||||||||||||||
22 | Qt::CaseSensitivity caseSensitivity; | - | ||||||||||||||||||
23 | }; | - | ||||||||||||||||||
24 | template<> class QTypeInfo<QConfFileCustomFormat > { public: enum { isComplex = (((Q_MOVABLE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_MOVABLE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_MOVABLE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(QConfFileCustomFormat)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< QConfFileCustomFormat >::value, isDummy = (((Q_MOVABLE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(QConfFileCustomFormat) }; static inline const char *name() { return "QConfFileCustomFormat"; } }; | - | ||||||||||||||||||
25 | - | |||||||||||||||||||
26 | typedef QHash<QString, QConfFile *> ConfFileHash; | - | ||||||||||||||||||
27 | typedef QCache<QString, QConfFile> ConfFileCache; | - | ||||||||||||||||||
28 | typedef QHash<int, QString> PathHash; | - | ||||||||||||||||||
29 | typedef QVector<QConfFileCustomFormat> CustomFormatVector; | - | ||||||||||||||||||
30 | - | |||||||||||||||||||
31 | namespace { namespace Q_QGS_usedHashFunc { typedef ConfFileHash Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<ConfFileHash, Q_QGS_usedHashFunc::innerFunction, Q_QGS_usedHashFunc::guard> usedHashFunc; | - | ||||||||||||||||||
32 | namespace { namespace Q_QGS_unusedCacheFunc { typedef ConfFileCache Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<ConfFileCache, Q_QGS_unusedCacheFunc::innerFunction, Q_QGS_unusedCacheFunc::guard> unusedCacheFunc; | - | ||||||||||||||||||
33 | namespace { namespace Q_QGS_pathHashFunc { typedef PathHash Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<PathHash, Q_QGS_pathHashFunc::innerFunction, Q_QGS_pathHashFunc::guard> pathHashFunc; | - | ||||||||||||||||||
34 | namespace { namespace Q_QGS_customFormatVectorFunc { typedef CustomFormatVector Type; QBasicAtomicInt guard = { QtGlobalStatic::Uninitialized }; __attribute__((visibility("hidden"))) inline Type *innerFunction() { struct HolderBase { ~HolderBase() noexcept { if (guard.load() == QtGlobalStatic::Initialized) guard.store(QtGlobalStatic::Destroyed); } }; static struct Holder : public HolderBase { Type value; Holder() noexcept(noexcept(Type ())) : value () { guard.store(QtGlobalStatic::Initialized); } } holder; return &holder.value; } } } static QGlobalStatic<CustomFormatVector, Q_QGS_customFormatVectorFunc::innerFunction, Q_QGS_customFormatVectorFunc::guard> customFormatVectorFunc; | - | ||||||||||||||||||
35 | - | |||||||||||||||||||
36 | static QBasicMutex settingsGlobalMutex; | - | ||||||||||||||||||
37 | - | |||||||||||||||||||
38 | static QSettings::Format globalDefaultFormat = QSettings::NativeFormat; | - | ||||||||||||||||||
39 | - | |||||||||||||||||||
40 | QConfFile::QConfFile(const QString &fileName, bool _userPerms) | - | ||||||||||||||||||
41 | : name(fileName), size(0), ref(1), userPerms(_userPerms) | - | ||||||||||||||||||
42 | { | - | ||||||||||||||||||
43 | usedHashFunc()->insert(name, this); | - | ||||||||||||||||||
44 | } | - | ||||||||||||||||||
45 | - | |||||||||||||||||||
46 | QConfFile::~QConfFile() | - | ||||||||||||||||||
47 | { | - | ||||||||||||||||||
48 | if (usedHashFunc()) | - | ||||||||||||||||||
49 | usedHashFunc()->remove(name); | - | ||||||||||||||||||
50 | } | - | ||||||||||||||||||
51 | - | |||||||||||||||||||
52 | ParsedSettingsMap QConfFile::mergedKeyMap() const | - | ||||||||||||||||||
53 | { | - | ||||||||||||||||||
54 | ParsedSettingsMap result = originalKeys; | - | ||||||||||||||||||
55 | ParsedSettingsMap::const_iterator i; | - | ||||||||||||||||||
56 | - | |||||||||||||||||||
57 | for (i = removedKeys.begin(); i != removedKeys.end(); ++i) | - | ||||||||||||||||||
58 | result.remove(i.key()); | - | ||||||||||||||||||
59 | for (i = addedKeys.begin(); i != addedKeys.end(); ++i) | - | ||||||||||||||||||
60 | result.insert(i.key(), i.value()); | - | ||||||||||||||||||
61 | return result; | - | ||||||||||||||||||
62 | } | - | ||||||||||||||||||
63 | - | |||||||||||||||||||
64 | bool QConfFile::isWritable() const | - | ||||||||||||||||||
65 | { | - | ||||||||||||||||||
66 | QFileInfo fileInfo(name); | - | ||||||||||||||||||
67 | - | |||||||||||||||||||
68 | - | |||||||||||||||||||
69 | if (fileInfo.exists()) { | - | ||||||||||||||||||
70 | - | |||||||||||||||||||
71 | QFile file(name); | - | ||||||||||||||||||
72 | return file.open(QFile::ReadWrite); | - | ||||||||||||||||||
73 | - | |||||||||||||||||||
74 | } else { | - | ||||||||||||||||||
75 | - | |||||||||||||||||||
76 | QDir dir(fileInfo.absolutePath()); | - | ||||||||||||||||||
77 | if (!dir.exists()) { | - | ||||||||||||||||||
78 | if (!dir.mkpath(dir.absolutePath())) | - | ||||||||||||||||||
79 | return false; | - | ||||||||||||||||||
80 | } | - | ||||||||||||||||||
81 | - | |||||||||||||||||||
82 | - | |||||||||||||||||||
83 | QTemporaryFile file(name); | - | ||||||||||||||||||
84 | return file.open(); | - | ||||||||||||||||||
85 | } | - | ||||||||||||||||||
86 | - | |||||||||||||||||||
87 | } | - | ||||||||||||||||||
88 | - | |||||||||||||||||||
89 | QConfFile *QConfFile::fromName(const QString &fileName, bool _userPerms) | - | ||||||||||||||||||
90 | { | - | ||||||||||||||||||
91 | QString absPath = QFileInfo(fileName).absoluteFilePath(); | - | ||||||||||||||||||
92 | - | |||||||||||||||||||
93 | ConfFileHash *usedHash = usedHashFunc(); | - | ||||||||||||||||||
94 | ConfFileCache *unusedCache = unusedCacheFunc(); | - | ||||||||||||||||||
95 | - | |||||||||||||||||||
96 | QConfFile *confFile = 0; | - | ||||||||||||||||||
97 | QMutexLocker locker(&settingsGlobalMutex); | - | ||||||||||||||||||
98 | - | |||||||||||||||||||
99 | if (!(confFile = usedHash->value(absPath))) { | - | ||||||||||||||||||
100 | if ((confFile = unusedCache->take(absPath))) | - | ||||||||||||||||||
101 | usedHash->insert(absPath, confFile); | - | ||||||||||||||||||
102 | } | - | ||||||||||||||||||
103 | if (confFile) { | - | ||||||||||||||||||
104 | confFile->ref.ref(); | - | ||||||||||||||||||
105 | return confFile; | - | ||||||||||||||||||
106 | } | - | ||||||||||||||||||
107 | return new QConfFile(absPath, _userPerms); | - | ||||||||||||||||||
108 | } | - | ||||||||||||||||||
109 | - | |||||||||||||||||||
110 | void QConfFile::clearCache() | - | ||||||||||||||||||
111 | { | - | ||||||||||||||||||
112 | QMutexLocker locker(&settingsGlobalMutex); | - | ||||||||||||||||||
113 | unusedCacheFunc()->clear(); | - | ||||||||||||||||||
114 | } | - | ||||||||||||||||||
115 | - | |||||||||||||||||||
116 | - | |||||||||||||||||||
117 | - | |||||||||||||||||||
118 | - | |||||||||||||||||||
119 | QSettingsPrivate::QSettingsPrivate(QSettings::Format format) | - | ||||||||||||||||||
120 | : format(format), scope(QSettings::UserScope ), iniCodec(0), spec(0), fallbacks(true), | - | ||||||||||||||||||
121 | pendingChanges(false), status(QSettings::NoError) | - | ||||||||||||||||||
122 | { | - | ||||||||||||||||||
123 | } | - | ||||||||||||||||||
124 | - | |||||||||||||||||||
125 | QSettingsPrivate::QSettingsPrivate(QSettings::Format format, QSettings::Scope scope, | - | ||||||||||||||||||
126 | const QString &organization, const QString &application) | - | ||||||||||||||||||
127 | : format(format), scope(scope), organizationName(organization), applicationName(application), | - | ||||||||||||||||||
128 | iniCodec(0), spec(0), fallbacks(true), pendingChanges(false), status(QSettings::NoError) | - | ||||||||||||||||||
129 | { | - | ||||||||||||||||||
130 | } | - | ||||||||||||||||||
131 | - | |||||||||||||||||||
132 | QSettingsPrivate::~QSettingsPrivate() | - | ||||||||||||||||||
133 | { | - | ||||||||||||||||||
134 | } | - | ||||||||||||||||||
135 | - | |||||||||||||||||||
136 | QString QSettingsPrivate::actualKey(const QString &key) const | - | ||||||||||||||||||
137 | { | - | ||||||||||||||||||
138 | QString n = normalizedKey(key); | - | ||||||||||||||||||
139 | ((!(!n.isEmpty())) ? qt_assert_x("QSettings", "empty key",__FILE__,245251) : qt_noop()); | - | ||||||||||||||||||
140 | n.prepend(groupPrefix);return executed 48963 times by 30 tests: groupPrefix + n;return groupPrefix + n; Executed by:
executed 48963 times by 30 tests: return groupPrefix + n; Executed by:
| 48963 | ||||||||||||||||||
141 | } | - | ||||||||||||||||||
142 | QString QSettingsPrivate::normalizedKey(const QString &key) | - | ||||||||||||||||||
143 | { | - | ||||||||||||||||||
144 | QString result = key; | - | ||||||||||||||||||
145 | - | |||||||||||||||||||
146 | int i = 0; | - | ||||||||||||||||||
147 | while (i < result.size()) { | - | ||||||||||||||||||
148 | while (result.at(i) == QLatin1Char('/')) { | - | ||||||||||||||||||
149 | result.remove(i, 1); | - | ||||||||||||||||||
150 | if (i == result.size()) | - | ||||||||||||||||||
151 | goto after_loop; | - | ||||||||||||||||||
152 | } | - | ||||||||||||||||||
153 | while (result.at(i) != QLatin1Char('/')) { | - | ||||||||||||||||||
154 | ++i; | - | ||||||||||||||||||
155 | if (i == result.size()) | - | ||||||||||||||||||
156 | return result; | - | ||||||||||||||||||
157 | } | - | ||||||||||||||||||
158 | ++i; | - | ||||||||||||||||||
159 | } | - | ||||||||||||||||||
160 | - | |||||||||||||||||||
161 | after_loop: | - | ||||||||||||||||||
162 | if (!result.isEmpty()) | - | ||||||||||||||||||
163 | result.truncate(i - 1); | - | ||||||||||||||||||
164 | return result; | - | ||||||||||||||||||
165 | } | - | ||||||||||||||||||
166 | - | |||||||||||||||||||
167 | - | |||||||||||||||||||
168 | - | |||||||||||||||||||
169 | - | |||||||||||||||||||
170 | QSettingsPrivate *QSettingsPrivate::create(QSettings::Format format, QSettings::Scope scope, | - | ||||||||||||||||||
171 | const QString &organization, const QString &application) | - | ||||||||||||||||||
172 | { | - | ||||||||||||||||||
173 | return new QConfFileSettingsPrivate(format, scope, organization, application); | - | ||||||||||||||||||
174 | } | - | ||||||||||||||||||
175 | - | |||||||||||||||||||
176 | - | |||||||||||||||||||
177 | - | |||||||||||||||||||
178 | QSettingsPrivate *QSettingsPrivate::create(const QString &fileName, QSettings::Format format) | - | ||||||||||||||||||
179 | { | - | ||||||||||||||||||
180 | return new QConfFileSettingsPrivate(fileName, format); | - | ||||||||||||||||||
181 | } | - | ||||||||||||||||||
182 | - | |||||||||||||||||||
183 | - | |||||||||||||||||||
184 | void QSettingsPrivate::processChild(QStringRef key, ChildSpec spec, QStringList &result) | - | ||||||||||||||||||
185 | { | - | ||||||||||||||||||
186 | if (spec != AllKeys) { | - | ||||||||||||||||||
187 | int slashPos = key.indexOf(QLatin1Char('/')); | - | ||||||||||||||||||
188 | if (slashPos == -1) { | - | ||||||||||||||||||
189 | if (spec != ChildKeys) | - | ||||||||||||||||||
190 | return; | - | ||||||||||||||||||
191 | } else { | - | ||||||||||||||||||
192 | if (spec != ChildGroups) | - | ||||||||||||||||||
193 | return; | - | ||||||||||||||||||
194 | key.truncate(slashPos); | - | ||||||||||||||||||
195 | } | - | ||||||||||||||||||
196 | } | - | ||||||||||||||||||
197 | result.append(key.toString()); | - | ||||||||||||||||||
198 | } | - | ||||||||||||||||||
199 | - | |||||||||||||||||||
200 | void QSettingsPrivate::beginGroupOrArray(const QSettingsGroup &group) | - | ||||||||||||||||||
201 | { | - | ||||||||||||||||||
202 | groupStack.push(group); | - | ||||||||||||||||||
203 | if (!const QString name = group.name().(); | - | ||||||||||||||||||
204 | if (!name.
| 43-1343 | ||||||||||||||||||
205 | {groupPrefix += group.name (); executed 1343 times by 6 tests: groupPrefix += name + QLatin1Char('/'); Executed by:
| 1343 | ||||||||||||||||||
groupPrefix += executed 1343 times by 6 tests: groupPrefix += name + QLatin1Char('/'); Executed by:
executed 1343 times by 6 tests: + QLatin1Char('/');groupPrefix += name + QLatin1Char('/'); Executed by:
executed 1343 times by 6 tests: groupPrefix += name + QLatin1Char('/'); Executed by:
| ||||||||||||||||||||
}} executed 1386 times by 6 tests: end of block Executed by:
| ||||||||||||||||||||
207 | - | |||||||||||||||||||
208 | - | |||||||||||||||||||
209 | - | |||||||||||||||||||
210 | - | |||||||||||||||||||
211 | - | |||||||||||||||||||
212 | - | |||||||||||||||||||
213 | void QSettingsPrivate::setStatus(QSettings::Status status) const | - | ||||||||||||||||||
214 | { | - | ||||||||||||||||||
215 | if (status == QSettings::NoError || this->status == QSettings::NoError) | - | ||||||||||||||||||
216 | this->status = status; | - | ||||||||||||||||||
217 | } | - | ||||||||||||||||||
218 | - | |||||||||||||||||||
219 | void QSettingsPrivate::update() | - | ||||||||||||||||||
220 | { | - | ||||||||||||||||||
221 | flush(); | - | ||||||||||||||||||
222 | pendingChanges = false; | - | ||||||||||||||||||
223 | } | - | ||||||||||||||||||
224 | - | |||||||||||||||||||
225 | void QSettingsPrivate::requestUpdate() | - | ||||||||||||||||||
226 | { | - | ||||||||||||||||||
227 | if (!pendingChanges) { | - | ||||||||||||||||||
228 | pendingChanges = true; | - | ||||||||||||||||||
229 | - | |||||||||||||||||||
230 | QSettings * const q = q_func(); | - | ||||||||||||||||||
231 | QCoreApplication::postEvent(q, new QEvent(QEvent::UpdateRequest)); | - | ||||||||||||||||||
232 | - | |||||||||||||||||||
233 | - | |||||||||||||||||||
234 | - | |||||||||||||||||||
235 | } | - | ||||||||||||||||||
236 | } | - | ||||||||||||||||||
237 | - | |||||||||||||||||||
238 | QStringList QSettingsPrivate::variantListToStringList(const QVariantList &l) | - | ||||||||||||||||||
239 | { | - | ||||||||||||||||||
240 | QStringList result; | - | ||||||||||||||||||
241 | result.reserve(l.count()); | - | ||||||||||||||||||
242 | QVariantList::const_iterator it = l.constBegin(); | - | ||||||||||||||||||
243 | for (; it != l.constEnd(); ++it) | - | ||||||||||||||||||
244 | result.append(variantToString(*it)); | - | ||||||||||||||||||
245 | return result; | - | ||||||||||||||||||
246 | } | - | ||||||||||||||||||
247 | - | |||||||||||||||||||
248 | QVariant QSettingsPrivate::stringListToVariantList(const QStringList &l) | - | ||||||||||||||||||
249 | { | - | ||||||||||||||||||
250 | QStringList outStringList = l; | - | ||||||||||||||||||
251 | for (int i = 0; i < outStringList.count(); ++i) { | - | ||||||||||||||||||
252 | const QString &str = outStringList.at(i); | - | ||||||||||||||||||
253 | - | |||||||||||||||||||
254 | if (str.startsWith(QLatin1Char('@'))) { | - | ||||||||||||||||||
255 | if (str.length() >= 2 && str.at(1) == QLatin1Char('@')) { | - | ||||||||||||||||||
256 | outStringList[i].remove(0, 1); | - | ||||||||||||||||||
257 | } else { | - | ||||||||||||||||||
258 | QVariantList variantList; | - | ||||||||||||||||||
259 | const int stringCount = l.count(); | - | ||||||||||||||||||
260 | variantList.reserve(stringCount); | - | ||||||||||||||||||
261 | for (int j = 0; j < stringCount; ++j) | - | ||||||||||||||||||
262 | variantList.append(stringToVariant(l.at(j))); | - | ||||||||||||||||||
263 | return variantList; | - | ||||||||||||||||||
264 | } | - | ||||||||||||||||||
265 | } | - | ||||||||||||||||||
266 | } | - | ||||||||||||||||||
267 | return outStringList; | - | ||||||||||||||||||
268 | } | - | ||||||||||||||||||
269 | - | |||||||||||||||||||
270 | QString QSettingsPrivate::variantToString(const QVariant &v) | - | ||||||||||||||||||
271 | { | - | ||||||||||||||||||
272 | QString result; | - | ||||||||||||||||||
273 | - | |||||||||||||||||||
274 | switch (v.type()) { | - | ||||||||||||||||||
275 | case never executed: QVariant::Invalid:case QVariant::Invalid: never executed: case QVariant::Invalid: | 0 | ||||||||||||||||||
276 | result = QLatin1String("@Invalid()"); | - | ||||||||||||||||||
277 | break; never executed: break; | 0 | ||||||||||||||||||
278 | - | |||||||||||||||||||
279 | case executed 253 times by 6 tests: QVariant::ByteArray:case QVariant::ByteArray: Executed by:
executed 253 times by 6 tests: {case QVariant::ByteArray: Executed by:
| 253 | ||||||||||||||||||
280 | QByteArray a = v.toByteArray(); | - | ||||||||||||||||||
281 | result = QLatin1String("@ByteArray("); | - | ||||||||||||||||||
result += QString::fromLatin1) | ||||||||||||||||||||
282 | + QLatin1String(a.constData(), a.size()); | - | ||||||||||||||||||
result +=()) | ||||||||||||||||||||
283 | + QLatin1Char(')'); | - | ||||||||||||||||||
284 | break; executed 253 times by 6 tests: break; Executed by:
| 253 | ||||||||||||||||||
285 | } | - | ||||||||||||||||||
286 | - | |||||||||||||||||||
287 | case executed 1867 times by 6 tests: QVariant::String:case QVariant::String: Executed by:
executed 1867 times by 6 tests: case QVariant::String: Executed by:
| 1867 | ||||||||||||||||||
288 | case never executed: QVariant::LongLong:case QVariant::LongLong: never executed: case QVariant::LongLong: | 0 | ||||||||||||||||||
289 | case never executed: QVariant::ULongLong:case QVariant::ULongLong: never executed: case QVariant::ULongLong: | 0 | ||||||||||||||||||
290 | case executed 631 times by 5 tests: QVariant::Int:case QVariant::Int: Executed by:
executed 631 times by 5 tests: case QVariant::Int: Executed by:
| 631 | ||||||||||||||||||
291 | case executed 96 times by 2 tests: QVariant::UInt:case QVariant::UInt: Executed by:
executed 96 times by 2 tests: case QVariant::UInt: Executed by:
| 96 | ||||||||||||||||||
292 | case executed 4 times by 1 test: QVariant::Bool:case QVariant::Bool: Executed by:
executed 4 times by 1 test: case QVariant::Bool: Executed by:
| 4 | ||||||||||||||||||
293 | case never executed: QVariant::Double:case QVariant::Double: never executed: case QVariant::Double: | 0 | ||||||||||||||||||
294 | case executed 2 times by 1 test: QVariant::KeySequence:case QVariant::KeySequence: Executed by:
executed 2 times by 1 test: {case QVariant::KeySequence: Executed by:
| 2 | ||||||||||||||||||
295 | result = v.toString(); | - | ||||||||||||||||||
296 | if (result.contains(QChar::Null)
| 2-2598 | ||||||||||||||||||
297 | result = QLatin1String("@String(") + result + QLatin1Char(')'); executed 2 times by 1 test: result = QLatin1String("@String(") + result + QLatin1Char(')'); Executed by:
| 2 | ||||||||||||||||||
298 | else if (result.startsWith(QLatin1Char('@'))
| 7-2591 | ||||||||||||||||||
299 | result.prepend(QLatin1Char('@')); executed 7 times by 1 test: result.prepend(QLatin1Char('@')); Executed by:
| 7 | ||||||||||||||||||
300 | break; executed 2600 times by 6 tests: break; Executed by:
| 2600 | ||||||||||||||||||
301 | } | - | ||||||||||||||||||
302 | - | |||||||||||||||||||
303 | case executed 43 times by 1 test: QVariant::Rect:case QVariant::Rect: Executed by:
executed 43 times by 1 test: {case QVariant::Rect: Executed by:
| 43 | ||||||||||||||||||
304 | QRect r = qvariant_cast<QRect>(v); | - | ||||||||||||||||||
305 | result += QLatin1String= QString::asprintf("@Rect(%d %d %d %d)"); | - | ||||||||||||||||||
result += QString::number(, r.x()); | ||||||||||||||||||||
result += QLatin1Char(' '); | ||||||||||||||||||||
result += QString::number((), r.y()); | ||||||||||||||||||||
result += QLatin1Char(' '); | ||||||||||||||||||||
result += QString::number((), r.width()); | ||||||||||||||||||||
result += QLatin1Char(' '); | ||||||||||||||||||||
result += QString::number((), r.height()); | ||||||||||||||||||||
306 | result += QLatin1Char(')');break; executed 43 times by 1 test: break; Executed by:
| 43 | ||||||||||||||||||
307 | } | - | ||||||||||||||||||
308 | case executed 41 times by 1 test: QVariant::Size:case QVariant::Size: Executed by:
executed 41 times by 1 test: {case QVariant::Size: Executed by:
| 41 | ||||||||||||||||||
309 | QSize s = qvariant_cast<QSize>(v); | - | ||||||||||||||||||
310 | result += QLatin1String= QString::asprintf("@Size(%d %d)"); | - | ||||||||||||||||||
result += QString::number(, s.width()); | ||||||||||||||||||||
result += QLatin1Char(' '); | ||||||||||||||||||||
result += QString::number((), s.height()); | ||||||||||||||||||||
311 | result += QLatin1Char(')');break; executed 41 times by 1 test: break; Executed by:
| 41 | ||||||||||||||||||
312 | } | - | ||||||||||||||||||
313 | case executed 39 times by 1 test: QVariant::Point:case QVariant::Point: Executed by:
executed 39 times by 1 test: {case QVariant::Point: Executed by:
| 39 | ||||||||||||||||||
314 | QPoint p = qvariant_cast<QPoint>(v); | - | ||||||||||||||||||
315 | result += QLatin1String= QString::asprintf("@Point(%d %d)"); | - | ||||||||||||||||||
result += QString::number(, p.x()); | ||||||||||||||||||||
result += QLatin1Char(' '); | ||||||||||||||||||||
result += QString::number((), p.y()); | ||||||||||||||||||||
316 | result += QLatin1Char(')');break; executed 39 times by 1 test: break; Executed by:
| 39 | ||||||||||||||||||
317 | } | - | ||||||||||||||||||
318 | - | |||||||||||||||||||
319 | - | |||||||||||||||||||
320 | default executed 176 times by 1 test: :default: Executed by:
executed 176 times by 1 test: {default: Executed by:
| 176 | ||||||||||||||||||
321 | - | |||||||||||||||||||
322 | QDataStream::Version version; | - | ||||||||||||||||||
323 | const char *typeSpec; | - | ||||||||||||||||||
324 | if (v.type() == QVariant::DateTime
| 4-172 | ||||||||||||||||||
325 | version = QDataStream::Qt_5_6; | - | ||||||||||||||||||
326 | typeSpec = "@DateTime("; | - | ||||||||||||||||||
327 | } executed 4 times by 1 test: else {end of block Executed by:
| 4 | ||||||||||||||||||
328 | version = QDataStream::Qt_4_0; | - | ||||||||||||||||||
329 | typeSpec = "@Variant("; | - | ||||||||||||||||||
330 | } executed 172 times by 1 test: end of block Executed by:
| 172 | ||||||||||||||||||
331 | QByteArray a; | - | ||||||||||||||||||
332 | { | - | ||||||||||||||||||
333 | QDataStream s(&a, QIODevice::WriteOnly); | - | ||||||||||||||||||
334 | s.setVersion(version); | - | ||||||||||||||||||
335 | s << v; | - | ||||||||||||||||||
336 | } | - | ||||||||||||||||||
337 | - | |||||||||||||||||||
338 | result = QLatin1String(typeSpec); | - | ||||||||||||||||||
result += QString::fromLatin1) | ||||||||||||||||||||
339 | + QLatin1String(a.constData(), a.size()); | - | ||||||||||||||||||
result +=()) | ||||||||||||||||||||
340 | + QLatin1Char(')'); | - | ||||||||||||||||||
341 | - | |||||||||||||||||||
342 | - | |||||||||||||||||||
343 | - | |||||||||||||||||||
344 | break; executed 176 times by 1 test: break; Executed by:
| 176 | ||||||||||||||||||
345 | } | - | ||||||||||||||||||
346 | } | - | ||||||||||||||||||
347 | - | |||||||||||||||||||
348 | return executed 3152 times by 6 tests: result;return result; Executed by:
executed 3152 times by 6 tests: return result; Executed by:
| 3152 | ||||||||||||||||||
349 | } | - | ||||||||||||||||||
350 | - | |||||||||||||||||||
351 | - | |||||||||||||||||||
352 | QVariant QSettingsPrivate::stringToVariant(const QString &s) | - | ||||||||||||||||||
353 | { | - | ||||||||||||||||||
354 | if (s.startsWith(QLatin1Char('@'))) { | - | ||||||||||||||||||
355 | if (s.endsWith(QLatin1Char(')'))) { | - | ||||||||||||||||||
356 | if (s.startsWith(QLatin1String("@ByteArray("))) { | - | ||||||||||||||||||
357 | return QVariant(s.midRef(11, s.size() - 12).toLatin1()); | - | ||||||||||||||||||
358 | } else if (s.startsWith(QLatin1String("@String("))) { | - | ||||||||||||||||||
359 | return QVariant(s.midRef(8, s.size() - 9).toString()); | - | ||||||||||||||||||
360 | } else if (s.startsWith(QLatin1String("@Variant(")) | - | ||||||||||||||||||
361 | || s.startsWith(QLatin1String("@DateTime("))) { | - | ||||||||||||||||||
362 | - | |||||||||||||||||||
363 | QDataStream::Version version; | - | ||||||||||||||||||
364 | int offset; | - | ||||||||||||||||||
365 | if (s.at(1) == QLatin1Char('D')) { | - | ||||||||||||||||||
366 | version = QDataStream::Qt_5_6; | - | ||||||||||||||||||
367 | offset = 10; | - | ||||||||||||||||||
368 | } else { | - | ||||||||||||||||||
369 | version = QDataStream::Qt_4_0; | - | ||||||||||||||||||
370 | offset = 9; | - | ||||||||||||||||||
371 | } | - | ||||||||||||||||||
372 | QByteArray a = s.midRef(offset).toLatin1(); | - | ||||||||||||||||||
373 | QDataStream stream(&a, QIODevice::ReadOnly); | - | ||||||||||||||||||
374 | stream.setVersion(version); | - | ||||||||||||||||||
375 | QVariant result; | - | ||||||||||||||||||
376 | stream >> result; | - | ||||||||||||||||||
377 | return result; | - | ||||||||||||||||||
378 | - | |||||||||||||||||||
379 | - | |||||||||||||||||||
380 | - | |||||||||||||||||||
381 | - | |||||||||||||||||||
382 | } else if (s.startsWith(QLatin1String("@Rect("))) { | - | ||||||||||||||||||
383 | QStringList args = QSettingsPrivate::splitArgs(s, 5); | - | ||||||||||||||||||
384 | if (args.size() == 4) | - | ||||||||||||||||||
385 | return QVariant(QRect(args[0].toInt(), args[1].toInt(), args[2].toInt(), args[3].toInt())); | - | ||||||||||||||||||
386 | } else if (s.startsWith(QLatin1String("@Size("))) { | - | ||||||||||||||||||
387 | QStringList args = QSettingsPrivate::splitArgs(s, 5); | - | ||||||||||||||||||
388 | if (args.size() == 2) | - | ||||||||||||||||||
389 | return QVariant(QSize(args[0].toInt(), args[1].toInt())); | - | ||||||||||||||||||
390 | } else if (s.startsWith(QLatin1String("@Point("))) { | - | ||||||||||||||||||
391 | QStringList args = QSettingsPrivate::splitArgs(s, 6); | - | ||||||||||||||||||
392 | if (args.size() == 2) | - | ||||||||||||||||||
393 | return QVariant(QPoint(args[0].toInt(), args[1].toInt())); | - | ||||||||||||||||||
394 | - | |||||||||||||||||||
395 | } else if (s == QLatin1String("@Invalid()")) { | - | ||||||||||||||||||
396 | return QVariant(); | - | ||||||||||||||||||
397 | } | - | ||||||||||||||||||
398 | - | |||||||||||||||||||
399 | } | - | ||||||||||||||||||
400 | if (s.startsWith(QLatin1String("@@"))) | - | ||||||||||||||||||
401 | return QVariant(s.mid(1)); | - | ||||||||||||||||||
402 | } | - | ||||||||||||||||||
403 | - | |||||||||||||||||||
404 | return QVariant(s); | - | ||||||||||||||||||
405 | } | - | ||||||||||||||||||
406 | - | |||||||||||||||||||
407 | static const char hexDigits[] = "0123456789ABCDEF"; | - | ||||||||||||||||||
408 | - | |||||||||||||||||||
409 | void QSettingsPrivate::iniEscapedKey(const QString &key, QByteArray &result) | - | ||||||||||||||||||
410 | { | - | ||||||||||||||||||
411 | result.reserve(result.length() + key.length() * 3 / 2); | - | ||||||||||||||||||
412 | for (int i = 0; i < key.size(); ++i) { | - | ||||||||||||||||||
413 | uint ch = key.at(i).unicode(); | - | ||||||||||||||||||
414 | - | |||||||||||||||||||
415 | if (ch == '/') { | - | ||||||||||||||||||
416 | result += '\\'; | - | ||||||||||||||||||
417 | } else if ((ch >= 'a' && ch <= 'z') || (ch >= 'A' && ch <= 'Z') || (ch >= '0' && ch <= '9') | - | ||||||||||||||||||
418 | || ch == '_' || ch == '-' || ch == '.') { | - | ||||||||||||||||||
419 | result += (char)ch; | - | ||||||||||||||||||
420 | } else if (ch <= 0xFF) { | - | ||||||||||||||||||
421 | result += '%'; | - | ||||||||||||||||||
422 | result += hexDigits[ch / 16]; | - | ||||||||||||||||||
423 | result += hexDigits[ch % 16]; | - | ||||||||||||||||||
424 | } else { | - | ||||||||||||||||||
425 | result += "%U"; | - | ||||||||||||||||||
426 | QByteArray hexCode; | - | ||||||||||||||||||
427 | for (int i = 0; i < 4; ++i) { | - | ||||||||||||||||||
428 | hexCode.prepend(hexDigits[ch % 16]); | - | ||||||||||||||||||
429 | ch >>= 4; | - | ||||||||||||||||||
430 | } | - | ||||||||||||||||||
431 | result += hexCode; | - | ||||||||||||||||||
432 | } | - | ||||||||||||||||||
433 | } | - | ||||||||||||||||||
434 | } | - | ||||||||||||||||||
435 | - | |||||||||||||||||||
436 | bool QSettingsPrivate::iniUnescapedKey(const QByteArray &key, int from, int to, QString &result) | - | ||||||||||||||||||
437 | { | - | ||||||||||||||||||
438 | bool lowercaseOnly = true; | - | ||||||||||||||||||
439 | int i = from; | - | ||||||||||||||||||
440 | result.reserve(result.length() + (to - from)); | - | ||||||||||||||||||
441 | while (i < to) { | - | ||||||||||||||||||
442 | int ch = (uchar)key.at(i); | - | ||||||||||||||||||
443 | - | |||||||||||||||||||
444 | if (ch == '\\') { | - | ||||||||||||||||||
445 | result += QLatin1Char('/'); | - | ||||||||||||||||||
446 | ++i; | - | ||||||||||||||||||
447 | continue; | - | ||||||||||||||||||
448 | } | - | ||||||||||||||||||
449 | - | |||||||||||||||||||
450 | if (ch != '%' || i == to - 1) { | - | ||||||||||||||||||
451 | if (uint(ch - 'A') <= 'Z' - 'A') | - | ||||||||||||||||||
452 | lowercaseOnly = false; | - | ||||||||||||||||||
453 | result += QLatin1Char(ch); | - | ||||||||||||||||||
454 | ++i; | - | ||||||||||||||||||
455 | continue; | - | ||||||||||||||||||
456 | } | - | ||||||||||||||||||
457 | - | |||||||||||||||||||
458 | int numDigits = 2; | - | ||||||||||||||||||
459 | int firstDigitPos = i + 1; | - | ||||||||||||||||||
460 | - | |||||||||||||||||||
461 | ch = key.at(i + 1); | - | ||||||||||||||||||
462 | if (ch == 'U') { | - | ||||||||||||||||||
463 | ++firstDigitPos; | - | ||||||||||||||||||
464 | numDigits = 4; | - | ||||||||||||||||||
465 | } | - | ||||||||||||||||||
466 | - | |||||||||||||||||||
467 | if (firstDigitPos + numDigits > to) { | - | ||||||||||||||||||
468 | result += QLatin1Char('%'); | - | ||||||||||||||||||
469 | - | |||||||||||||||||||
470 | ++i; | - | ||||||||||||||||||
471 | continue; | - | ||||||||||||||||||
472 | } | - | ||||||||||||||||||
473 | - | |||||||||||||||||||
474 | bool ok; | - | ||||||||||||||||||
475 | ch = key.mid(firstDigitPos, numDigits).toInt(&ok, 16); | - | ||||||||||||||||||
476 | if (!ok) { | - | ||||||||||||||||||
477 | result += QLatin1Char('%'); | - | ||||||||||||||||||
478 | - | |||||||||||||||||||
479 | ++i; | - | ||||||||||||||||||
480 | continue; | - | ||||||||||||||||||
481 | } | - | ||||||||||||||||||
482 | - | |||||||||||||||||||
483 | QChar qch(ch); | - | ||||||||||||||||||
484 | if (qch.isUpper()) | - | ||||||||||||||||||
485 | lowercaseOnly = false; | - | ||||||||||||||||||
486 | result += qch; | - | ||||||||||||||||||
487 | i = firstDigitPos + numDigits; | - | ||||||||||||||||||
488 | } | - | ||||||||||||||||||
489 | return lowercaseOnly; | - | ||||||||||||||||||
490 | } | - | ||||||||||||||||||
491 | - | |||||||||||||||||||
492 | void QSettingsPrivate::iniEscapedString(const QString &str, QByteArray &result, QTextCodec *codec) | - | ||||||||||||||||||
493 | { | - | ||||||||||||||||||
494 | bool needsQuotes = false; | - | ||||||||||||||||||
495 | bool escapeNextIfDigit = false; | - | ||||||||||||||||||
496 | bool useCodec = codec
| 1-3175 | ||||||||||||||||||
497 | && !str.startsWith(QLatin1String("@Variant("))
| 0-2 | ||||||||||||||||||
498 | - | |||||||||||||||||||
499 | int i; | - | ||||||||||||||||||
500 | int startPos = result.size(); | - | ||||||||||||||||||
501 | - | |||||||||||||||||||
502 | result.reserve(startPos + str.size() * 3 / 2); | - | ||||||||||||||||||
503 | const QChar *unicode = str.unicode(); | - | ||||||||||||||||||
504 | for (i = 0; i < str.size()
| 3178-89650 | ||||||||||||||||||
505 | uint ch = unicode[i].unicode(); | - | ||||||||||||||||||
506 | if (ch == ';'
| 3-89647 | ||||||||||||||||||
507 | needsQuotes = true; executed 11 times by 1 test: needsQuotes = true; Executed by:
| 11 | ||||||||||||||||||
508 | - | |||||||||||||||||||
509 | if (escapeNextIfDigit
| 37254-52396 | ||||||||||||||||||
510 | && ((ch >= '0'
| 16-31758 | ||||||||||||||||||
511 | || (ch >= 'a'
| 824-32343 | ||||||||||||||||||
512 | || (ch >= 'A'
| 527-31759 | ||||||||||||||||||
513 | result += "\\x" ; | - | ||||||||||||||||||
result +=+ QByteArray::number(ch, 16); | ||||||||||||||||||||
514 | continue; executed 1367 times by 6 tests: continue; Executed by:
| 1367 | ||||||||||||||||||
515 | } | - | ||||||||||||||||||
516 | - | |||||||||||||||||||
517 | escapeNextIfDigit = false; | - | ||||||||||||||||||
518 | - | |||||||||||||||||||
519 | switch (ch) { | - | ||||||||||||||||||
520 | case executed 28726 times by 6 tests: '\0':case '\0': Executed by:
executed 28726 times by 6 tests: case '\0': Executed by:
| 28726 | ||||||||||||||||||
521 | result += "\\0"; | - | ||||||||||||||||||
522 | escapeNextIfDigit = true; | - | ||||||||||||||||||
523 | break; executed 28726 times by 6 tests: break; Executed by:
| 28726 | ||||||||||||||||||
524 | case executed 3 times by 1 test: '\a':case '\a': Executed by:
executed 3 times by 1 test: case '\a': Executed by:
| 3 | ||||||||||||||||||
525 | result += "\\a"; | - | ||||||||||||||||||
526 | break; executed 3 times by 1 test: break; Executed by:
| 3 | ||||||||||||||||||
527 | case executed 125 times by 1 test: '\b':case '\b': Executed by:
executed 125 times by 1 test: case '\b': Executed by:
| 125 | ||||||||||||||||||
528 | result += "\\b"; | - | ||||||||||||||||||
529 | break; executed 125 times by 1 test: break; Executed by:
| 125 | ||||||||||||||||||
530 | case executed 4 times by 1 test: '\f':case '\f': Executed by:
executed 4 times by 1 test: case '\f': Executed by:
| 4 | ||||||||||||||||||
531 | result += "\\f"; | - | ||||||||||||||||||
532 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||||||||
533 | case executed 229 times by 1 test: '\n':case '\n': Executed by:
executed 229 times by 1 test: case '\n': Executed by:
| 229 | ||||||||||||||||||
534 | result += "\\n"; | - | ||||||||||||||||||
535 | break; executed 229 times by 1 test: break; Executed by:
| 229 | ||||||||||||||||||
536 | case executed 4 times by 1 test: '\r':case '\r': Executed by:
executed 4 times by 1 test: case '\r': Executed by:
| 4 | ||||||||||||||||||
537 | result += "\\r"; | - | ||||||||||||||||||
538 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||||||||
539 | case executed 28 times by 1 test: '\t':case '\t': Executed by:
executed 28 times by 1 test: case '\t': Executed by:
| 28 | ||||||||||||||||||
540 | result += "\\t"; | - | ||||||||||||||||||
541 | break; executed 28 times by 1 test: break; Executed by:
| 28 | ||||||||||||||||||
542 | case executed 8 times by 1 test: '\v':case '\v': Executed by:
executed 8 times by 1 test: case '\v': Executed by:
| 8 | ||||||||||||||||||
543 | result += "\\v"; | - | ||||||||||||||||||
544 | break; executed 8 times by 1 test: break; Executed by:
| 8 | ||||||||||||||||||
545 | case executed 3 times by 1 test: '"':case '"': Executed by:
executed 3 times by 1 test: case '"': Executed by:
| 3 | ||||||||||||||||||
546 | case executed 4 times by 1 test: '\\':case '\\': Executed by:
executed 4 times by 1 test: case '\\': Executed by:
| 4 | ||||||||||||||||||
547 | result += '\\'; | - | ||||||||||||||||||
548 | result += (char)ch; | - | ||||||||||||||||||
549 | break; executed 7 times by 1 test: break; Executed by:
| 7 | ||||||||||||||||||
550 | default executed 59149 times by 6 tests: :default: Executed by:
executed 59149 times by 6 tests: default: Executed by:
| 59149 | ||||||||||||||||||
551 | if (ch <= 0x1F
| 4-55478 | ||||||||||||||||||
552 | result += "\\x"; | - | ||||||||||||||||||
result +=+ QByteArray::number(ch, 16); | ||||||||||||||||||||
553 | escapeNextIfDigit = true; | - | ||||||||||||||||||
554 | - | |||||||||||||||||||
555 | } executed 7165 times by 6 tests: else if (useCodecend of block Executed by:
| 26-51958 | ||||||||||||||||||
556 | - | |||||||||||||||||||
557 | result += codec->fromUnicode(&unicode[i], 1); | - | ||||||||||||||||||
558 | - | |||||||||||||||||||
559 | } executed 26 times by 1 test: else {end of block Executed by:
| 26 | ||||||||||||||||||
560 | result += (char)ch; | - | ||||||||||||||||||
561 | } executed 51958 times by 6 tests: end of block Executed by:
| 51958 | ||||||||||||||||||
562 | } | - | ||||||||||||||||||
563 | } | - | ||||||||||||||||||
564 | - | |||||||||||||||||||
565 | if (needsQuotes
| 8-3170 | ||||||||||||||||||
566 | || (startPos < result.size()
| 3-3134 | ||||||||||||||||||
567 | || result.at(result.size() - 1) == ' '
| 3-3128 | ||||||||||||||||||
568 | result.insert(startPos, '"'); | - | ||||||||||||||||||
569 | result += '"'; | - | ||||||||||||||||||
570 | } executed 14 times by 1 test: end of block Executed by:
| 14 | ||||||||||||||||||
571 | } executed 3178 times by 6 tests: end of block Executed by:
| 3178 | ||||||||||||||||||
572 | - | |||||||||||||||||||
573 | inline static void iniChopTrailingSpaces(QString &str, int limit) | - | ||||||||||||||||||
574 | { | - | ||||||||||||||||||
575 | int n = str.size() - 1; | - | ||||||||||||||||||
576 | QChar ch; | - | ||||||||||||||||||
577 | while (n >= limit && ((ch = str.at(n)) == QLatin1Char(' ') || ch == QLatin1Char('\t'))) | - | ||||||||||||||||||
578 | str.truncate(n--); | - | ||||||||||||||||||
579 | } | - | ||||||||||||||||||
580 | - | |||||||||||||||||||
581 | void QSettingsPrivate::iniEscapedStringList(const QStringList &strs, QByteArray &result, QTextCodec *codec) | - | ||||||||||||||||||
582 | { | - | ||||||||||||||||||
583 | if (strs.isEmpty()) { | - | ||||||||||||||||||
584 | result += "@Invalid()"; | - | ||||||||||||||||||
585 | } else { | - | ||||||||||||||||||
586 | for (int i = 0; i < strs.size(); ++i) { | - | ||||||||||||||||||
587 | if (i != 0) | - | ||||||||||||||||||
588 | result += ", "; | - | ||||||||||||||||||
589 | iniEscapedString(strs.at(i), result, codec); | - | ||||||||||||||||||
590 | } | - | ||||||||||||||||||
591 | } | - | ||||||||||||||||||
592 | } | - | ||||||||||||||||||
593 | - | |||||||||||||||||||
594 | bool QSettingsPrivate::iniUnescapedStringList(const QByteArray &str, int from, int to, | - | ||||||||||||||||||
595 | QString &stringResult, QStringList &stringListResult, | - | ||||||||||||||||||
596 | QTextCodec *codec) | - | ||||||||||||||||||
597 | { | - | ||||||||||||||||||
598 | static const char escapeCodes[][2] = | - | ||||||||||||||||||
599 | { | - | ||||||||||||||||||
600 | { 'a', '\a' }, | - | ||||||||||||||||||
601 | { 'b', '\b' }, | - | ||||||||||||||||||
602 | { 'f', '\f' }, | - | ||||||||||||||||||
603 | { 'n', '\n' }, | - | ||||||||||||||||||
604 | { 'r', '\r' }, | - | ||||||||||||||||||
605 | { 't', '\t' }, | - | ||||||||||||||||||
606 | { 'v', '\v' }, | - | ||||||||||||||||||
607 | { '"', '"' }, | - | ||||||||||||||||||
608 | { '?', '?' }, | - | ||||||||||||||||||
609 | { '\'', '\'' }, | - | ||||||||||||||||||
610 | { '\\', '\\' } | - | ||||||||||||||||||
611 | }; | - | ||||||||||||||||||
612 | static const int numEscapeCodes = sizeof(escapeCodes) / sizeof(escapeCodes[0]); | - | ||||||||||||||||||
613 | - | |||||||||||||||||||
614 | bool isStringList = false; | - | ||||||||||||||||||
615 | bool inQuotedString = false; | - | ||||||||||||||||||
616 | bool currentValueIsQuoted = false; | - | ||||||||||||||||||
617 | int escapeVal = 0; | - | ||||||||||||||||||
618 | int i = from; | - | ||||||||||||||||||
619 | char ch; | - | ||||||||||||||||||
620 | - | |||||||||||||||||||
621 | StSkipSpaces: | - | ||||||||||||||||||
622 | while (i < to && ((ch = str.at(i)) == ' ' || ch == '\t')) | - | ||||||||||||||||||
623 | ++i; | - | ||||||||||||||||||
624 | - | |||||||||||||||||||
625 | - | |||||||||||||||||||
626 | StNormal: | - | ||||||||||||||||||
627 | int chopLimit = stringResult.length(); | - | ||||||||||||||||||
628 | while (i < to) { | - | ||||||||||||||||||
629 | switch (str.at(i)) { | - | ||||||||||||||||||
630 | case '\\': | - | ||||||||||||||||||
631 | ++i; | - | ||||||||||||||||||
632 | if (i >= to) | - | ||||||||||||||||||
633 | goto end; | - | ||||||||||||||||||
634 | - | |||||||||||||||||||
635 | ch = str.at(i++); | - | ||||||||||||||||||
636 | for (int j = 0; j < numEscapeCodes; ++j) { | - | ||||||||||||||||||
637 | if (ch == escapeCodes[j][0]) { | - | ||||||||||||||||||
638 | stringResult += QLatin1Char(escapeCodes[j][1]); | - | ||||||||||||||||||
639 | goto StNormal; | - | ||||||||||||||||||
640 | } | - | ||||||||||||||||||
641 | } | - | ||||||||||||||||||
642 | - | |||||||||||||||||||
643 | if (ch == 'x') { | - | ||||||||||||||||||
644 | escapeVal = 0; | - | ||||||||||||||||||
645 | - | |||||||||||||||||||
646 | if (i >= to) | - | ||||||||||||||||||
647 | goto end; | - | ||||||||||||||||||
648 | - | |||||||||||||||||||
649 | ch = str.at(i); | - | ||||||||||||||||||
650 | if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F') || (ch >= 'a' && ch <= 'f')) | - | ||||||||||||||||||
651 | goto StHexEscape; | - | ||||||||||||||||||
652 | } else if (ch >= '0' && ch <= '7') { | - | ||||||||||||||||||
653 | escapeVal = ch - '0'; | - | ||||||||||||||||||
654 | goto StOctEscape; | - | ||||||||||||||||||
655 | } else if (ch == '\n' || ch == '\r') { | - | ||||||||||||||||||
656 | if (i < to) { | - | ||||||||||||||||||
657 | char ch2 = str.at(i); | - | ||||||||||||||||||
658 | - | |||||||||||||||||||
659 | if ((ch2 == '\n' || ch2 == '\r') && ch2 != ch) | - | ||||||||||||||||||
660 | ++i; | - | ||||||||||||||||||
661 | } | - | ||||||||||||||||||
662 | } else { | - | ||||||||||||||||||
663 | - | |||||||||||||||||||
664 | } | - | ||||||||||||||||||
665 | chopLimit = stringResult.length(); | - | ||||||||||||||||||
666 | break; | - | ||||||||||||||||||
667 | case '"': | - | ||||||||||||||||||
668 | ++i; | - | ||||||||||||||||||
669 | currentValueIsQuoted = true; | - | ||||||||||||||||||
670 | inQuotedString = !inQuotedString; | - | ||||||||||||||||||
671 | if (!inQuotedString) | - | ||||||||||||||||||
672 | goto StSkipSpaces; | - | ||||||||||||||||||
673 | break; | - | ||||||||||||||||||
674 | case ',': | - | ||||||||||||||||||
675 | if (!inQuotedString) { | - | ||||||||||||||||||
676 | if (!currentValueIsQuoted) | - | ||||||||||||||||||
677 | iniChopTrailingSpaces(stringResult, chopLimit); | - | ||||||||||||||||||
678 | if (!isStringList) { | - | ||||||||||||||||||
679 | isStringList = true; | - | ||||||||||||||||||
680 | stringListResult.clear(); | - | ||||||||||||||||||
681 | stringResult.squeeze(); | - | ||||||||||||||||||
682 | } | - | ||||||||||||||||||
683 | stringListResult.append(stringResult); | - | ||||||||||||||||||
684 | stringResult.clear(); | - | ||||||||||||||||||
685 | currentValueIsQuoted = false; | - | ||||||||||||||||||
686 | ++i; | - | ||||||||||||||||||
687 | goto StSkipSpaces; | - | ||||||||||||||||||
688 | } | - | ||||||||||||||||||
689 | - | |||||||||||||||||||
690 | default: { | - | ||||||||||||||||||
691 | int j = i + 1; | - | ||||||||||||||||||
692 | while (j < to) { | - | ||||||||||||||||||
693 | ch = str.at(j); | - | ||||||||||||||||||
694 | if (ch == '\\' || ch == '"' || ch == ',') | - | ||||||||||||||||||
695 | break; | - | ||||||||||||||||||
696 | ++j; | - | ||||||||||||||||||
697 | } | - | ||||||||||||||||||
698 | - | |||||||||||||||||||
699 | - | |||||||||||||||||||
700 | - | |||||||||||||||||||
701 | - | |||||||||||||||||||
702 | if (codec) { | - | ||||||||||||||||||
703 | stringResult += codec->toUnicode(str.constData() + i, j - i); | - | ||||||||||||||||||
704 | } else | - | ||||||||||||||||||
705 | - | |||||||||||||||||||
706 | { | - | ||||||||||||||||||
707 | int n = stringResult.size(); | - | ||||||||||||||||||
708 | stringResult.resize(n + (j - i)); | - | ||||||||||||||||||
709 | QChar *resultData = stringResult.data() + n; | - | ||||||||||||||||||
710 | for (int k = i; k < j; ++k) | - | ||||||||||||||||||
711 | *resultData++ = QLatin1Char(str.at(k)); | - | ||||||||||||||||||
712 | } | - | ||||||||||||||||||
713 | i = j; | - | ||||||||||||||||||
714 | } | - | ||||||||||||||||||
715 | } | - | ||||||||||||||||||
716 | } | - | ||||||||||||||||||
717 | if (!currentValueIsQuoted) | - | ||||||||||||||||||
718 | iniChopTrailingSpaces(stringResult, chopLimit); | - | ||||||||||||||||||
719 | goto end; | - | ||||||||||||||||||
720 | - | |||||||||||||||||||
721 | StHexEscape: | - | ||||||||||||||||||
722 | if (i >= to) { | - | ||||||||||||||||||
723 | stringResult += QChar(escapeVal); | - | ||||||||||||||||||
724 | goto end; | - | ||||||||||||||||||
725 | } | - | ||||||||||||||||||
726 | - | |||||||||||||||||||
727 | ch = str.at(i); | - | ||||||||||||||||||
728 | if (ch >= 'a') | - | ||||||||||||||||||
729 | ch -= 'a' - 'A'; | - | ||||||||||||||||||
730 | if ((ch >= '0' && ch <= '9') || (ch >= 'A' && ch <= 'F')) { | - | ||||||||||||||||||
731 | escapeVal <<= 4; | - | ||||||||||||||||||
732 | escapeVal += strchr(hexDigits, ch) - hexDigits; | - | ||||||||||||||||||
733 | ++i; | - | ||||||||||||||||||
734 | goto StHexEscape; | - | ||||||||||||||||||
735 | } else { | - | ||||||||||||||||||
736 | stringResult += QChar(escapeVal); | - | ||||||||||||||||||
737 | goto StNormal; | - | ||||||||||||||||||
738 | } | - | ||||||||||||||||||
739 | - | |||||||||||||||||||
740 | StOctEscape: | - | ||||||||||||||||||
741 | if (i >= to) { | - | ||||||||||||||||||
742 | stringResult += QChar(escapeVal); | - | ||||||||||||||||||
743 | goto end; | - | ||||||||||||||||||
744 | } | - | ||||||||||||||||||
745 | - | |||||||||||||||||||
746 | ch = str.at(i); | - | ||||||||||||||||||
747 | if (ch >= '0' && ch <= '7') { | - | ||||||||||||||||||
748 | escapeVal <<= 3; | - | ||||||||||||||||||
749 | escapeVal += ch - '0'; | - | ||||||||||||||||||
750 | ++i; | - | ||||||||||||||||||
751 | goto StOctEscape; | - | ||||||||||||||||||
752 | } else { | - | ||||||||||||||||||
753 | stringResult += QChar(escapeVal); | - | ||||||||||||||||||
754 | goto StNormal; | - | ||||||||||||||||||
755 | } | - | ||||||||||||||||||
756 | - | |||||||||||||||||||
757 | end: | - | ||||||||||||||||||
758 | if (isStringList) | - | ||||||||||||||||||
759 | stringListResult.append(stringResult); | - | ||||||||||||||||||
760 | return isStringList; | - | ||||||||||||||||||
761 | } | - | ||||||||||||||||||
762 | - | |||||||||||||||||||
763 | QStringList QSettingsPrivate::splitArgs(const QString &s, int idx) | - | ||||||||||||||||||
764 | { | - | ||||||||||||||||||
765 | int l = s.length(); | - | ||||||||||||||||||
766 | ((!(l > 0)) ? qt_assert("l > 0",__FILE__,912898) : qt_noop()); | - | ||||||||||||||||||
767 | ((!(s.at(idx) == QLatin1Char('('))) ? qt_assert("s.at(idx) == QLatin1Char('(')",__FILE__,913899) : qt_noop()); | - | ||||||||||||||||||
768 | ((!(s.at(l - 1) == QLatin1Char(')'))) ? qt_assert("s.at(l - 1) == QLatin1Char(')')",__FILE__,914900) : qt_noop()); | - | ||||||||||||||||||
769 | - | |||||||||||||||||||
770 | QStringList result; | - | ||||||||||||||||||
771 | QString item; | - | ||||||||||||||||||
772 | - | |||||||||||||||||||
773 | for (++idx; idx < l; ++idx) { | - | ||||||||||||||||||
774 | QChar c = s.at(idx); | - | ||||||||||||||||||
775 | if (c == QLatin1Char(')')) { | - | ||||||||||||||||||
776 | ((!(idx == l - 1)) ? qt_assert("idx == l - 1",__FILE__,922908) : qt_noop()); | - | ||||||||||||||||||
777 | result.append(item); | - | ||||||||||||||||||
778 | } else if (c == QLatin1Char(' ')) { | - | ||||||||||||||||||
779 | result.append(item); | - | ||||||||||||||||||
780 | item.clear(); | - | ||||||||||||||||||
781 | } else { | - | ||||||||||||||||||
782 | item.append(c); | - | ||||||||||||||||||
783 | } | - | ||||||||||||||||||
784 | } | - | ||||||||||||||||||
785 | - | |||||||||||||||||||
786 | return result; | - | ||||||||||||||||||
787 | } | - | ||||||||||||||||||
788 | - | |||||||||||||||||||
789 | - | |||||||||||||||||||
790 | - | |||||||||||||||||||
791 | - | |||||||||||||||||||
792 | void QConfFileSettingsPrivate::initFormat() | - | ||||||||||||||||||
793 | { | - | ||||||||||||||||||
794 | extension = (format == QSettings::NativeFormat) ? QLatin1String(".conf") : QLatin1String(".ini"); | - | ||||||||||||||||||
795 | readFunc = 0; | - | ||||||||||||||||||
796 | writeFunc = 0; | - | ||||||||||||||||||
797 | - | |||||||||||||||||||
798 | - | |||||||||||||||||||
799 | - | |||||||||||||||||||
800 | caseSensitivity = IniCaseSensitivity; | - | ||||||||||||||||||
801 | - | |||||||||||||||||||
802 | - | |||||||||||||||||||
803 | if (format > QSettings::IniFormat) { | - | ||||||||||||||||||
804 | QMutexLocker locker(&settingsGlobalMutex); | - | ||||||||||||||||||
805 | const CustomFormatVector *customFormatVector = customFormatVectorFunc(); | - | ||||||||||||||||||
806 | - | |||||||||||||||||||
807 | int i = (int)format - (int)QSettings::CustomFormat1; | - | ||||||||||||||||||
808 | if (i >= 0 && i < customFormatVector->size()) { | - | ||||||||||||||||||
809 | QConfFileCustomFormat info = customFormatVector->at(i); | - | ||||||||||||||||||
810 | extension = info.extension; | - | ||||||||||||||||||
811 | readFunc = info.readFunc; | - | ||||||||||||||||||
812 | writeFunc = info.writeFunc; | - | ||||||||||||||||||
813 | caseSensitivity = info.caseSensitivity; | - | ||||||||||||||||||
814 | } | - | ||||||||||||||||||
815 | } | - | ||||||||||||||||||
816 | } | - | ||||||||||||||||||
817 | - | |||||||||||||||||||
818 | void QConfFileSettingsPrivate::initAccess() | - | ||||||||||||||||||
819 | { | - | ||||||||||||||||||
820 | if (confFiles[spec]) { | - | ||||||||||||||||||
821 | if (format > QSettings::IniFormat) { | - | ||||||||||||||||||
822 | if (!readFunc) | - | ||||||||||||||||||
823 | setStatus(QSettings::AccessError); | - | ||||||||||||||||||
824 | } | - | ||||||||||||||||||
825 | } | - | ||||||||||||||||||
826 | - | |||||||||||||||||||
827 | sync(); | - | ||||||||||||||||||
828 | } | - | ||||||||||||||||||
829 | static inline int pathHashKey(QSettings::Format format, QSettings::Scope scope) | - | ||||||||||||||||||
830 | { | - | ||||||||||||||||||
831 | return int((uint(format) << 1) | uint(scope == QSettings::SystemScope)); | - | ||||||||||||||||||
832 | } | - | ||||||||||||||||||
833 | - | |||||||||||||||||||
834 | - | |||||||||||||||||||
835 | static QString make_user_path() | - | ||||||||||||||||||
836 | { | - | ||||||||||||||||||
837 | static constexpr QChar sep = QLatin1Char('/'); | - | ||||||||||||||||||
838 | return executed 7 times by 7 tests: QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + sep;return QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + sep; Executed by:
executed 7 times by 7 tests: return QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation) + sep; Executed by:
| 7 | ||||||||||||||||||
839 | - | |||||||||||||||||||
840 | } | - | ||||||||||||||||||
841 | - | |||||||||||||||||||
842 | - | |||||||||||||||||||
843 | static void initDefaultPaths(QMutexLocker *locker) | - | ||||||||||||||||||
844 | { | - | ||||||||||||||||||
845 | PathHash *pathHash = pathHashFunc(); | - | ||||||||||||||||||
QString systemPath; | ||||||||||||||||||||
846 | - | |||||||||||||||||||
847 | locker->unlock(); | - | ||||||||||||||||||
848 | - | |||||||||||||||||||
849 | - | |||||||||||||||||||
850 | - | |||||||||||||||||||
851 | - | |||||||||||||||||||
852 | - | |||||||||||||||||||
853 | - | |||||||||||||||||||
854 | QString systemPath = QLibraryInfo::location(QLibraryInfo::SettingsPath); | - | ||||||||||||||||||
systemPath) +=+ QLatin1Char('/'); | ||||||||||||||||||||
855 | - | |||||||||||||||||||
856 | locker->relock(); | - | ||||||||||||||||||
857 | if (pathHash->isEmpty()
| 0-7 | ||||||||||||||||||
858 | const QString userPath = QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); | - | ||||||||||||||||||
userPath += QLatin1Char('/'); | ||||||||||||||||||||
make_user_path(); | ||||||||||||||||||||
859 | pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::UserScope), userPath); | - | ||||||||||||||||||
860 | pathHash->insert(pathHashKey(QSettings::IniFormat, QSettings::SystemScope), systemPath); | - | ||||||||||||||||||
861 | - | |||||||||||||||||||
862 | pathHash->insert(pathHashKey(QSettings::NativeFormat, QSettings::UserScope), userPath); | - | ||||||||||||||||||
863 | pathHash->insert(pathHashKey(QSettings::NativeFormat, QSettings::SystemScope), systemPath); | - | ||||||||||||||||||
864 | - | |||||||||||||||||||
865 | - | |||||||||||||||||||
866 | } executed 7 times by 7 tests: end of block Executed by:
| 7 | ||||||||||||||||||
867 | } executed 7 times by 7 tests: end of block Executed by:
| 7 | ||||||||||||||||||
868 | - | |||||||||||||||||||
869 | static QString getPath(QSettings::Format format, QSettings::Scope scope) | - | ||||||||||||||||||
870 | { | - | ||||||||||||||||||
871 | ((!((int)QSettings::NativeFormat == 0)) ? qt_assert("(int)QSettings::NativeFormat == 0",__FILE__,11151099) : qt_noop()); | - | ||||||||||||||||||
872 | ((!((int)QSettings::IniFormat == 1)) ? qt_assert("(int)QSettings::IniFormat == 1",__FILE__,11161100) : qt_noop()); | - | ||||||||||||||||||
873 | - | |||||||||||||||||||
874 | QMutexLocker locker(&settingsGlobalMutex); | - | ||||||||||||||||||
875 | PathHash *pathHash = pathHashFunc(); | - | ||||||||||||||||||
876 | if (pathHash->isEmpty()) | - | ||||||||||||||||||
877 | initDefaultPaths(&locker); | - | ||||||||||||||||||
878 | - | |||||||||||||||||||
879 | QString result = pathHash->value(pathHashKey(format, scope)); | - | ||||||||||||||||||
880 | if (!result.isEmpty()) | - | ||||||||||||||||||
881 | return result; | - | ||||||||||||||||||
882 | - | |||||||||||||||||||
883 | - | |||||||||||||||||||
884 | return pathHash->value(pathHashKey(QSettings::IniFormat, scope)); | - | ||||||||||||||||||
885 | } | - | ||||||||||||||||||
886 | - | |||||||||||||||||||
887 | QConfFileSettingsPrivate::QConfFileSettingsPrivate(QSettings::Format format, | - | ||||||||||||||||||
888 | QSettings::Scope scope, | - | ||||||||||||||||||
889 | const QString &organization, | - | ||||||||||||||||||
890 | const QString &application) | - | ||||||||||||||||||
891 | : QSettingsPrivate(format, scope, organization, application), | - | ||||||||||||||||||
892 | nextPosition(0x40000000) | - | ||||||||||||||||||
893 | { | - | ||||||||||||||||||
894 | int i; | - | ||||||||||||||||||
895 | initFormat(); | - | ||||||||||||||||||
896 | - | |||||||||||||||||||
897 | QString org = organization; | - | ||||||||||||||||||
898 | if (org.isEmpty()
| 8-1420 | ||||||||||||||||||
899 | setStatus(QSettings::AccessError); | - | ||||||||||||||||||
900 | org = QLatin1String("Unknown Organization"); | - | ||||||||||||||||||
901 | } executed 8 times by 1 test: end of block Executed by:
| 8 | ||||||||||||||||||
executed 8 times by 1 test: end of block Executed by:
| ||||||||||||||||||||
902 | - | |||||||||||||||||||
903 | QString appFile = org + QDir::separator() + application + extension; | - | ||||||||||||||||||
904 | QString orgFile = org + extension; | - | ||||||||||||||||||
905 | - | |||||||||||||||||||
906 | if (scope == QSettings::UserScope
| 107-1321 | ||||||||||||||||||
907 | QString userPath = getPath(format, QSettings::UserScope); | - | ||||||||||||||||||
908 | if (!application.isEmpty()
| 256-1065 | ||||||||||||||||||
909 | confFiles[F_User | F_Application].reset(QConfFile::fromName(userPath + appFile, true)); executed 256 times by 2 tests: confFiles[F_User | F_Application].reset(QConfFile::fromName(userPath + appFile, true)); Executed by:
| 256 | ||||||||||||||||||
910 | confFiles[F_User | F_Organization].reset(QConfFile::fromName(userPath + orgFile, true)); | - | ||||||||||||||||||
911 | } executed 1321 times by 7 tests: end of block Executed by:
| 1321 | ||||||||||||||||||
912 | - | |||||||||||||||||||
913 | QString systemPath = getPath(format, QSettings::SystemScope); | - | ||||||||||||||||||
914 | if (!application.isEmpty()
| 298-1130 | ||||||||||||||||||
915 | confFiles[F_System | F_Application].reset(QConfFile::fromName(systemPath + appFile, false)); executed 298 times by 2 tests: confFiles[F_System | F_Application].reset(QConfFile::fromName(systemPath + appFile, false)); Executed by:
| 298 | ||||||||||||||||||
916 | confFiles[F_System | F_Organization].reset(QConfFile::fromName(systemPath + orgFile, false)); | - | ||||||||||||||||||
917 | - | |||||||||||||||||||
918 | for (i = 0; i < NumConfFiles
| 0-2772 | ||||||||||||||||||
919 | if (confFiles[i]
| 1344-1428 | ||||||||||||||||||
920 | spec = i; | - | ||||||||||||||||||
921 | break; executed 1428 times by 7 tests: break; Executed by:
| 1428 | ||||||||||||||||||
922 | } | - | ||||||||||||||||||
923 | } executed 1344 times by 6 tests: end of block Executed by:
| 1344 | ||||||||||||||||||
924 | - | |||||||||||||||||||
925 | initAccess(); | - | ||||||||||||||||||
926 | } executed 1428 times by 7 tests: end of block Executed by:
| 1428 | ||||||||||||||||||
927 | - | |||||||||||||||||||
928 | QConfFileSettingsPrivate::QConfFileSettingsPrivate(const QString &fileName, | - | ||||||||||||||||||
929 | QSettings::Format format) | - | ||||||||||||||||||
930 | : QSettingsPrivate(format), | - | ||||||||||||||||||
931 | nextPosition(0x40000000) | - | ||||||||||||||||||
932 | { | - | ||||||||||||||||||
933 | initFormat(); | - | ||||||||||||||||||
934 | - | |||||||||||||||||||
935 | confFiles[0].reset(QConfFile::fromName(fileName, true)); | - | ||||||||||||||||||
936 | - | |||||||||||||||||||
937 | initAccess(); | - | ||||||||||||||||||
938 | } | - | ||||||||||||||||||
939 | - | |||||||||||||||||||
940 | QConfFileSettingsPrivate::~QConfFileSettingsPrivate() | - | ||||||||||||||||||
941 | { | - | ||||||||||||||||||
942 | QMutexLocker locker(&settingsGlobalMutex); | - | ||||||||||||||||||
943 | ConfFileHash *usedHash = usedHashFunc(); | - | ||||||||||||||||||
944 | ConfFileCache *unusedCache = unusedCacheFunc(); | - | ||||||||||||||||||
945 | - | |||||||||||||||||||
946 | for (int i = 0; i < NumConfFiles; ++i) { | - | ||||||||||||||||||
947 | if (confFiles[i] && !confFiles[i]->ref.deref()) { | - | ||||||||||||||||||
948 | if (confFiles[i]->size == 0) { | - | ||||||||||||||||||
949 | delete confFiles[i].take(); | - | ||||||||||||||||||
950 | } else { | - | ||||||||||||||||||
951 | if (usedHash) | - | ||||||||||||||||||
952 | usedHash->remove(confFiles[i]->name); | - | ||||||||||||||||||
953 | if (unusedCache) { | - | ||||||||||||||||||
954 | try { | - | ||||||||||||||||||
955 | - | |||||||||||||||||||
956 | unusedCache->insert(confFiles[i]->name, confFiles[i].data(), | - | ||||||||||||||||||
957 | 10 + (confFiles[i]->originalKeys.size() / 4)); | - | ||||||||||||||||||
958 | confFiles[i].take(); | - | ||||||||||||||||||
959 | } catch (...) { | - | ||||||||||||||||||
960 | - | |||||||||||||||||||
961 | delete confFiles[i].take(); | - | ||||||||||||||||||
962 | } | - | ||||||||||||||||||
963 | } else { | - | ||||||||||||||||||
964 | - | |||||||||||||||||||
965 | delete confFiles[i].take(); | - | ||||||||||||||||||
966 | } | - | ||||||||||||||||||
967 | } | - | ||||||||||||||||||
968 | } | - | ||||||||||||||||||
969 | - | |||||||||||||||||||
970 | confFiles[i].take(); | - | ||||||||||||||||||
971 | } | - | ||||||||||||||||||
972 | } | - | ||||||||||||||||||
973 | - | |||||||||||||||||||
974 | void QConfFileSettingsPrivate::remove(const QString &key) | - | ||||||||||||||||||
975 | { | - | ||||||||||||||||||
976 | QConfFile *confFile = confFiles[spec].data(); | - | ||||||||||||||||||
977 | if (!confFile) | - | ||||||||||||||||||
978 | return; | - | ||||||||||||||||||
979 | - | |||||||||||||||||||
980 | QSettingsKey theKey(key, caseSensitivity); | - | ||||||||||||||||||
981 | QSettingsKey prefix(key + QLatin1Char('/'), caseSensitivity); | - | ||||||||||||||||||
982 | QMutexLocker locker(&confFile->mutex); | - | ||||||||||||||||||
983 | - | |||||||||||||||||||
984 | ensureSectionParsed(confFile, theKey); | - | ||||||||||||||||||
985 | ensureSectionParsed(confFile, prefix); | - | ||||||||||||||||||
986 | - | |||||||||||||||||||
987 | ParsedSettingsMap::iterator i = confFile->addedKeys.lowerBound(prefix); | - | ||||||||||||||||||
988 | while (i != confFile->addedKeys.end() && i.key().startsWith(prefix)) | - | ||||||||||||||||||
989 | i = confFile->addedKeys.erase(i); | - | ||||||||||||||||||
990 | confFile->addedKeys.remove(theKey); | - | ||||||||||||||||||
991 | - | |||||||||||||||||||
992 | ParsedSettingsMap::const_iterator j = const_cast<const ParsedSettingsMap *>(&confFile->originalKeys)->lowerBound(prefix); | - | ||||||||||||||||||
993 | while (j != confFile->originalKeys.constEnd() && j.key().startsWith(prefix)) { | - | ||||||||||||||||||
994 | confFile->removedKeys.insert(j.key(), QVariant()); | - | ||||||||||||||||||
995 | ++j; | - | ||||||||||||||||||
996 | } | - | ||||||||||||||||||
997 | if (confFile->originalKeys.contains(theKey)) | - | ||||||||||||||||||
998 | confFile->removedKeys.insert(theKey, QVariant()); | - | ||||||||||||||||||
999 | } | - | ||||||||||||||||||
1000 | - | |||||||||||||||||||
1001 | void QConfFileSettingsPrivate::set(const QString &key, const QVariant &value) | - | ||||||||||||||||||
1002 | { | - | ||||||||||||||||||
1003 | QConfFile *confFile = confFiles[spec].data(); | - | ||||||||||||||||||
1004 | if (!confFile) | - | ||||||||||||||||||
1005 | return; | - | ||||||||||||||||||
1006 | - | |||||||||||||||||||
1007 | QSettingsKey theKey(key, caseSensitivity, nextPosition++); | - | ||||||||||||||||||
1008 | QMutexLocker locker(&confFile->mutex); | - | ||||||||||||||||||
1009 | confFile->removedKeys.remove(theKey); | - | ||||||||||||||||||
1010 | confFile->addedKeys.insert(theKey, value); | - | ||||||||||||||||||
1011 | } | - | ||||||||||||||||||
1012 | - | |||||||||||||||||||
1013 | bool QConfFileSettingsPrivate::get(const QString &key, QVariant *value) const | - | ||||||||||||||||||
1014 | { | - | ||||||||||||||||||
1015 | QSettingsKey theKey(key, caseSensitivity); | - | ||||||||||||||||||
1016 | ParsedSettingsMap::const_iterator j; | - | ||||||||||||||||||
1017 | bool found = false; | - | ||||||||||||||||||
1018 | - | |||||||||||||||||||
1019 | for (int i = 0; i < NumConfFiles; ++i) { | - | ||||||||||||||||||
1020 | if (QConfFile *confFile = confFiles[i].data()) { | - | ||||||||||||||||||
1021 | QMutexLocker locker(&confFile->mutex); | - | ||||||||||||||||||
1022 | - | |||||||||||||||||||
1023 | if (!confFile->addedKeys.isEmpty()) { | - | ||||||||||||||||||
1024 | j = confFile->addedKeys.constFind(theKey); | - | ||||||||||||||||||
1025 | found = (j != confFile->addedKeys.constEnd()); | - | ||||||||||||||||||
1026 | } | - | ||||||||||||||||||
1027 | if (!found) { | - | ||||||||||||||||||
1028 | ensureSectionParsed(confFile, theKey); | - | ||||||||||||||||||
1029 | j = confFile->originalKeys.constFind(theKey); | - | ||||||||||||||||||
1030 | found = (j != confFile->originalKeys.constEnd() | - | ||||||||||||||||||
1031 | && !confFile->removedKeys.contains(theKey)); | - | ||||||||||||||||||
1032 | } | - | ||||||||||||||||||
1033 | - | |||||||||||||||||||
1034 | if (found && value) | - | ||||||||||||||||||
1035 | *value = *j; | - | ||||||||||||||||||
1036 | - | |||||||||||||||||||
1037 | if (found) | - | ||||||||||||||||||
1038 | return true; | - | ||||||||||||||||||
1039 | if (!fallbacks) | - | ||||||||||||||||||
1040 | break; | - | ||||||||||||||||||
1041 | } | - | ||||||||||||||||||
1042 | } | - | ||||||||||||||||||
1043 | return false; | - | ||||||||||||||||||
1044 | } | - | ||||||||||||||||||
1045 | - | |||||||||||||||||||
1046 | QStringList QConfFileSettingsPrivate::children(const QString &prefix, ChildSpec spec) const | - | ||||||||||||||||||
1047 | { | - | ||||||||||||||||||
1048 | QStringList result; | - | ||||||||||||||||||
1049 | ParsedSettingsMap::const_iterator j; | - | ||||||||||||||||||
1050 | - | |||||||||||||||||||
1051 | QSettingsKey thePrefix(prefix, caseSensitivity); | - | ||||||||||||||||||
1052 | int startPos = prefix.size(); | - | ||||||||||||||||||
1053 | - | |||||||||||||||||||
1054 | for (int i = 0; i < NumConfFiles; ++i) { | - | ||||||||||||||||||
1055 | if (QConfFile *confFile = confFiles[i].data()) { | - | ||||||||||||||||||
1056 | QMutexLocker locker(&confFile->mutex); | - | ||||||||||||||||||
1057 | - | |||||||||||||||||||
1058 | if (thePrefix.isEmpty()) { | - | ||||||||||||||||||
1059 | ensureAllSectionsParsed(confFile); | - | ||||||||||||||||||
1060 | } else { | - | ||||||||||||||||||
1061 | ensureSectionParsed(confFile, thePrefix); | - | ||||||||||||||||||
1062 | } | - | ||||||||||||||||||
1063 | - | |||||||||||||||||||
1064 | j = const_cast<const ParsedSettingsMap *>( | - | ||||||||||||||||||
1065 | &confFile->originalKeys)->lowerBound( thePrefix); | - | ||||||||||||||||||
1066 | while (j != confFile->originalKeys.constEnd() && j.key().startsWith(thePrefix)) { | - | ||||||||||||||||||
1067 | if (!confFile->removedKeys.contains(j.key())) | - | ||||||||||||||||||
1068 | processChild(j.key().originalCaseKey().midRef(startPos), spec, result); | - | ||||||||||||||||||
1069 | ++j; | - | ||||||||||||||||||
1070 | } | - | ||||||||||||||||||
1071 | - | |||||||||||||||||||
1072 | j = const_cast<const ParsedSettingsMap *>( | - | ||||||||||||||||||
1073 | &confFile->addedKeys)->lowerBound(thePrefix); | - | ||||||||||||||||||
1074 | while (j != confFile->addedKeys.constEnd() && j.key().startsWith(thePrefix)) { | - | ||||||||||||||||||
1075 | processChild(j.key().originalCaseKey().midRef(startPos), spec, result); | - | ||||||||||||||||||
1076 | ++j; | - | ||||||||||||||||||
1077 | } | - | ||||||||||||||||||
1078 | - | |||||||||||||||||||
1079 | if (!fallbacks) | - | ||||||||||||||||||
1080 | break; | - | ||||||||||||||||||
1081 | } | - | ||||||||||||||||||
1082 | } | - | ||||||||||||||||||
1083 | std::sort(result.begin(), result.end()); | - | ||||||||||||||||||
1084 | result.erase(std::unique(result.begin(), result.end()), | - | ||||||||||||||||||
1085 | result.end()); | - | ||||||||||||||||||
1086 | return result; | - | ||||||||||||||||||
1087 | } | - | ||||||||||||||||||
1088 | - | |||||||||||||||||||
1089 | void QConfFileSettingsPrivate::clear() | - | ||||||||||||||||||
1090 | { | - | ||||||||||||||||||
1091 | QConfFile *confFile = confFiles[spec].data(); | - | ||||||||||||||||||
1092 | if (!confFile) | - | ||||||||||||||||||
1093 | return; | - | ||||||||||||||||||
1094 | - | |||||||||||||||||||
1095 | QMutexLocker locker(&confFile->mutex); | - | ||||||||||||||||||
1096 | ensureAllSectionsParsed(confFile); | - | ||||||||||||||||||
1097 | confFile->addedKeys.clear(); | - | ||||||||||||||||||
1098 | confFile->removedKeys = confFile->originalKeys; | - | ||||||||||||||||||
1099 | } | - | ||||||||||||||||||
1100 | - | |||||||||||||||||||
1101 | void QConfFileSettingsPrivate::sync() | - | ||||||||||||||||||
1102 | { | - | ||||||||||||||||||
1103 | - | |||||||||||||||||||
1104 | - | |||||||||||||||||||
1105 | - | |||||||||||||||||||
1106 | for (int i = 0; i < NumConfFiles; ++i) { | - | ||||||||||||||||||
1107 | QConfFile *confFile = confFiles[i].data(); | - | ||||||||||||||||||
1108 | if (confFile) { | - | ||||||||||||||||||
1109 | QMutexLocker locker(&confFile->mutex); | - | ||||||||||||||||||
1110 | syncConfFile(i); | - | ||||||||||||||||||
1111 | } | - | ||||||||||||||||||
1112 | } | - | ||||||||||||||||||
1113 | } | - | ||||||||||||||||||
1114 | - | |||||||||||||||||||
1115 | void QConfFileSettingsPrivate::flush() | - | ||||||||||||||||||
1116 | { | - | ||||||||||||||||||
1117 | sync(); | - | ||||||||||||||||||
1118 | } | - | ||||||||||||||||||
1119 | - | |||||||||||||||||||
1120 | QString QConfFileSettingsPrivate::fileName() const | - | ||||||||||||||||||
1121 | { | - | ||||||||||||||||||
1122 | QConfFile *confFile = confFiles[spec].data(); | - | ||||||||||||||||||
1123 | if (!confFile) | - | ||||||||||||||||||
1124 | return QString(); | - | ||||||||||||||||||
1125 | return confFile->name; | - | ||||||||||||||||||
1126 | } | - | ||||||||||||||||||
1127 | - | |||||||||||||||||||
1128 | bool QConfFileSettingsPrivate::isWritable() const | - | ||||||||||||||||||
1129 | { | - | ||||||||||||||||||
1130 | if (format > QSettings::IniFormat && !writeFunc) | - | ||||||||||||||||||
1131 | return false; | - | ||||||||||||||||||
1132 | - | |||||||||||||||||||
1133 | QConfFile *confFile = confFiles[spec].data(); | - | ||||||||||||||||||
1134 | if (!confFile) | - | ||||||||||||||||||
1135 | return false; | - | ||||||||||||||||||
1136 | - | |||||||||||||||||||
1137 | return confFile->isWritable(); | - | ||||||||||||||||||
1138 | } | - | ||||||||||||||||||
1139 | - | |||||||||||||||||||
1140 | void QConfFileSettingsPrivate::syncConfFile(int confFileNo) | - | ||||||||||||||||||
1141 | { | - | ||||||||||||||||||
1142 | QConfFile *confFile = confFiles[confFileNo].data(); | - | ||||||||||||||||||
1143 | bool readOnly = confFile->addedKeys.isEmpty() && confFile->removedKeys.isEmpty(); | - | ||||||||||||||||||
1144 | bool ok; | - | ||||||||||||||||||
1145 | - | |||||||||||||||||||
1146 | - | |||||||||||||||||||
1147 | - | |||||||||||||||||||
1148 | - | |||||||||||||||||||
1149 | - | |||||||||||||||||||
1150 | if (readOnly && confFile->size > 0) { | - | ||||||||||||||||||
1151 | QFileInfo fileInfo(confFile->name); | - | ||||||||||||||||||
1152 | if (confFile->size == fileInfo.size() && confFile->timeStamp == fileInfo.lastModified()) | - | ||||||||||||||||||
1153 | return; | - | ||||||||||||||||||
1154 | } | - | ||||||||||||||||||
1155 | QLockFile lockFile(confFile->name + QLatin1String(".lock")); | - | ||||||||||||||||||
1156 | - | |||||||||||||||||||
1157 | if (!readOnly) { | - | ||||||||||||||||||
1158 | if (!confFile->isWritable() | - | ||||||||||||||||||
1159 | - | |||||||||||||||||||
1160 | || !lockFile.lock() | - | ||||||||||||||||||
1161 | - | |||||||||||||||||||
1162 | ) { | - | ||||||||||||||||||
1163 | setStatus(QSettings::AccessError); | - | ||||||||||||||||||
1164 | return; | - | ||||||||||||||||||
1165 | } | - | ||||||||||||||||||
1166 | } | - | ||||||||||||||||||
1167 | - | |||||||||||||||||||
1168 | - | |||||||||||||||||||
1169 | - | |||||||||||||||||||
1170 | - | |||||||||||||||||||
1171 | - | |||||||||||||||||||
1172 | QFileInfo fileInfo(confFile->name); | - | ||||||||||||||||||
1173 | bool mustReadFile = true; | - | ||||||||||||||||||
1174 | bool createFile = !fileInfo.exists(); | - | ||||||||||||||||||
1175 | - | |||||||||||||||||||
1176 | if (!readOnly) | - | ||||||||||||||||||
1177 | mustReadFile = (confFile->size != fileInfo.size() | - | ||||||||||||||||||
1178 | || (confFile->size != 0 && confFile->timeStamp != fileInfo.lastModified())); | - | ||||||||||||||||||
1179 | - | |||||||||||||||||||
1180 | if (mustReadFile) { | - | ||||||||||||||||||
1181 | confFile->unparsedIniSections.clear(); | - | ||||||||||||||||||
1182 | confFile->originalKeys.clear(); | - | ||||||||||||||||||
1183 | - | |||||||||||||||||||
1184 | QFile file(confFile->name); | - | ||||||||||||||||||
1185 | if (!createFile && !file.open(QFile::ReadOnly)) { | - | ||||||||||||||||||
1186 | setStatus(QSettings::AccessError); | - | ||||||||||||||||||
1187 | return; | - | ||||||||||||||||||
1188 | } | - | ||||||||||||||||||
1189 | - | |||||||||||||||||||
1190 | - | |||||||||||||||||||
1191 | - | |||||||||||||||||||
1192 | - | |||||||||||||||||||
1193 | - | |||||||||||||||||||
1194 | if (file.isReadable() && fileInfo.size() != 0) { | - | ||||||||||||||||||
1195 | - | |||||||||||||||||||
1196 | - | |||||||||||||||||||
1197 | - | |||||||||||||||||||
1198 | - | |||||||||||||||||||
1199 | - | |||||||||||||||||||
1200 | { | - | ||||||||||||||||||
1201 | if (format <= QSettings::IniFormat) { | - | ||||||||||||||||||
1202 | QByteArray data = file.readAll(); | - | ||||||||||||||||||
1203 | ok = readIniFile(data, &confFile->unparsedIniSections); | - | ||||||||||||||||||
1204 | } else { | - | ||||||||||||||||||
1205 | if (readFunc) { | - | ||||||||||||||||||
1206 | QSettings::SettingsMap tempNewKeys; | - | ||||||||||||||||||
1207 | ok = readFunc(file, tempNewKeys); | - | ||||||||||||||||||
1208 | - | |||||||||||||||||||
1209 | if (ok) { | - | ||||||||||||||||||
1210 | QSettings::SettingsMap::const_iterator i = tempNewKeys.constBegin(); | - | ||||||||||||||||||
1211 | while (i != tempNewKeys.constEnd()) { | - | ||||||||||||||||||
1212 | confFile->originalKeys.insert(QSettingsKey(i.key(), | - | ||||||||||||||||||
1213 | caseSensitivity), | - | ||||||||||||||||||
1214 | i.value()); | - | ||||||||||||||||||
1215 | ++i; | - | ||||||||||||||||||
1216 | } | - | ||||||||||||||||||
1217 | } | - | ||||||||||||||||||
1218 | } else { | - | ||||||||||||||||||
1219 | ok = false; | - | ||||||||||||||||||
1220 | } | - | ||||||||||||||||||
1221 | } | - | ||||||||||||||||||
1222 | } | - | ||||||||||||||||||
1223 | - | |||||||||||||||||||
1224 | if (!ok) | - | ||||||||||||||||||
1225 | setStatus(QSettings::FormatError); | - | ||||||||||||||||||
1226 | } | - | ||||||||||||||||||
1227 | - | |||||||||||||||||||
1228 | confFile->size = fileInfo.size(); | - | ||||||||||||||||||
1229 | confFile->timeStamp = fileInfo.lastModified(); | - | ||||||||||||||||||
1230 | } | - | ||||||||||||||||||
1231 | - | |||||||||||||||||||
1232 | - | |||||||||||||||||||
1233 | - | |||||||||||||||||||
1234 | - | |||||||||||||||||||
1235 | - | |||||||||||||||||||
1236 | if (!readOnly) { | - | ||||||||||||||||||
1237 | ensureAllSectionsParsed(confFile); | - | ||||||||||||||||||
1238 | ParsedSettingsMap mergedKeys = confFile->mergedKeyMap(); | - | ||||||||||||||||||
1239 | - | |||||||||||||||||||
1240 | - | |||||||||||||||||||
1241 | - | |||||||||||||||||||
1242 | - | |||||||||||||||||||
1243 | - | |||||||||||||||||||
1244 | - | |||||||||||||||||||
1245 | { | - | ||||||||||||||||||
1246 | - | |||||||||||||||||||
1247 | QSaveFile sf(confFile->name); | - | ||||||||||||||||||
1248 | - | |||||||||||||||||||
1249 | - | |||||||||||||||||||
1250 | - | |||||||||||||||||||
1251 | if (!sf.open(QIODevice::WriteOnly)) { | - | ||||||||||||||||||
1252 | setStatus(QSettings::AccessError); | - | ||||||||||||||||||
1253 | ok = false; | - | ||||||||||||||||||
1254 | } else if (format <= QSettings::IniFormat) { | - | ||||||||||||||||||
1255 | ok = writeIniFile(sf, mergedKeys); | - | ||||||||||||||||||
1256 | } else { | - | ||||||||||||||||||
1257 | if (writeFunc) { | - | ||||||||||||||||||
1258 | QSettings::SettingsMap tempOriginalKeys; | - | ||||||||||||||||||
1259 | - | |||||||||||||||||||
1260 | ParsedSettingsMap::const_iterator i = mergedKeys.constBegin(); | - | ||||||||||||||||||
1261 | while (i != mergedKeys.constEnd()) { | - | ||||||||||||||||||
1262 | tempOriginalKeys.insert(i.key(), i.value()); | - | ||||||||||||||||||
1263 | ++i; | - | ||||||||||||||||||
1264 | } | - | ||||||||||||||||||
1265 | ok = writeFunc(sf, tempOriginalKeys); | - | ||||||||||||||||||
1266 | } else { | - | ||||||||||||||||||
1267 | ok = false; | - | ||||||||||||||||||
1268 | } | - | ||||||||||||||||||
1269 | } | - | ||||||||||||||||||
1270 | - | |||||||||||||||||||
1271 | if (ok) | - | ||||||||||||||||||
1272 | ok = sf.commit(); | - | ||||||||||||||||||
1273 | - | |||||||||||||||||||
1274 | } | - | ||||||||||||||||||
1275 | - | |||||||||||||||||||
1276 | if (ok) { | - | ||||||||||||||||||
1277 | confFile->unparsedIniSections.clear(); | - | ||||||||||||||||||
1278 | confFile->originalKeys = mergedKeys; | - | ||||||||||||||||||
1279 | confFile->addedKeys.clear(); | - | ||||||||||||||||||
1280 | confFile->removedKeys.clear(); | - | ||||||||||||||||||
1281 | - | |||||||||||||||||||
1282 | QFileInfo fileInfo(confFile->name); | - | ||||||||||||||||||
1283 | confFile->size = fileInfo.size(); | - | ||||||||||||||||||
1284 | confFile->timeStamp = fileInfo.lastModified(); | - | ||||||||||||||||||
1285 | - | |||||||||||||||||||
1286 | - | |||||||||||||||||||
1287 | if (createFile) { | - | ||||||||||||||||||
1288 | QFile::Permissions perms = fileInfo.permissions() | QFile::ReadOwner | QFile::WriteOwner; | - | ||||||||||||||||||
1289 | if (!confFile->userPerms) | - | ||||||||||||||||||
1290 | perms |= QFile::ReadGroup | QFile::ReadOther; | - | ||||||||||||||||||
1291 | QFile(confFile->name).setPermissions(perms); | - | ||||||||||||||||||
1292 | } | - | ||||||||||||||||||
1293 | } else { | - | ||||||||||||||||||
1294 | setStatus(QSettings::AccessError); | - | ||||||||||||||||||
1295 | } | - | ||||||||||||||||||
1296 | } | - | ||||||||||||||||||
1297 | } | - | ||||||||||||||||||
1298 | - | |||||||||||||||||||
1299 | enum { Space = 0x1, Special = 0x2 }; | - | ||||||||||||||||||
1300 | - | |||||||||||||||||||
1301 | static const char charTraits[256] = | - | ||||||||||||||||||
1302 | { | - | ||||||||||||||||||
1303 | - | |||||||||||||||||||
1304 | - | |||||||||||||||||||
1305 | - | |||||||||||||||||||
1306 | 0, 0, 0, 0, 0, 0, 0, 0, 0, Space, Space | Special, 0, 0, Space | Special, 0, 0, | - | ||||||||||||||||||
1307 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||
1308 | Space, 0, Special, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||
1309 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Special, 0, Special, 0, 0, | - | ||||||||||||||||||
1310 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||
1311 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, Special, 0, 0, 0, | - | ||||||||||||||||||
1312 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||
1313 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||
1314 | - | |||||||||||||||||||
1315 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||
1316 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||
1317 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||
1318 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||
1319 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||
1320 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||
1321 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, | - | ||||||||||||||||||
1322 | 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0 | - | ||||||||||||||||||
1323 | }; | - | ||||||||||||||||||
1324 | - | |||||||||||||||||||
1325 | bool QConfFileSettingsPrivate::readIniLine(const QByteArray &data, int &dataPos, | - | ||||||||||||||||||
1326 | int &lineStart, int &lineLen, int &equalsPos) | - | ||||||||||||||||||
1327 | { | - | ||||||||||||||||||
1328 | int dataLen = data.length(); | - | ||||||||||||||||||
1329 | bool inQuotes = false; | - | ||||||||||||||||||
1330 | - | |||||||||||||||||||
1331 | equalsPos = -1; | - | ||||||||||||||||||
1332 | - | |||||||||||||||||||
1333 | lineStart = dataPos; | - | ||||||||||||||||||
1334 | while (lineStart < dataLen && (charTraits[uint(uchar(data.at(lineStart)))] & Space)) | - | ||||||||||||||||||
1335 | ++lineStart; | - | ||||||||||||||||||
1336 | - | |||||||||||||||||||
1337 | int i = lineStart; | - | ||||||||||||||||||
1338 | while (i < dataLen) { | - | ||||||||||||||||||
1339 | while (!(charTraits[uint(uchar(data.at(i)))] & Special)) { | - | ||||||||||||||||||
1340 | if (++i == dataLen) | - | ||||||||||||||||||
1341 | goto break_out_of_outer_loop; | - | ||||||||||||||||||
1342 | } | - | ||||||||||||||||||
1343 | - | |||||||||||||||||||
1344 | char ch = data.at(i++); | - | ||||||||||||||||||
1345 | if (ch == '=') { | - | ||||||||||||||||||
1346 | if (!inQuotes && equalsPos == -1) | - | ||||||||||||||||||
1347 | equalsPos = i - 1; | - | ||||||||||||||||||
1348 | } else if (ch == '\n' || ch == '\r') { | - | ||||||||||||||||||
1349 | if (i == lineStart + 1) { | - | ||||||||||||||||||
1350 | ++lineStart; | - | ||||||||||||||||||
1351 | } else if (!inQuotes) { | - | ||||||||||||||||||
1352 | --i; | - | ||||||||||||||||||
1353 | goto break_out_of_outer_loop; | - | ||||||||||||||||||
1354 | } | - | ||||||||||||||||||
1355 | } else if (ch == '\\') { | - | ||||||||||||||||||
1356 | if (i < dataLen) { | - | ||||||||||||||||||
1357 | char ch = data.at(i++); | - | ||||||||||||||||||
1358 | if (i < dataLen) { | - | ||||||||||||||||||
1359 | char ch2 = data.at(i); | - | ||||||||||||||||||
1360 | - | |||||||||||||||||||
1361 | if ((ch == '\n' && ch2 == '\r') || (ch == '\r' && ch2 == '\n')) | - | ||||||||||||||||||
1362 | ++i; | - | ||||||||||||||||||
1363 | } | - | ||||||||||||||||||
1364 | } | - | ||||||||||||||||||
1365 | } else if (ch == '"') { | - | ||||||||||||||||||
1366 | inQuotes = !inQuotes; | - | ||||||||||||||||||
1367 | } else { | - | ||||||||||||||||||
1368 | ((!(ch == ';')) ? qt_assert("ch == ';'",__FILE__,16291605) : qt_noop()); | - | ||||||||||||||||||
1369 | - | |||||||||||||||||||
1370 | if (i == lineStart + 1) { | - | ||||||||||||||||||
1371 | char ch; | - | ||||||||||||||||||
1372 | while (i < dataLen && (((ch = data.at(i)) != '\n') && ch != '\r')) | - | ||||||||||||||||||
1373 | ++i; | - | ||||||||||||||||||
1374 | lineStart = i; | - | ||||||||||||||||||
1375 | } else if (!inQuotes) { | - | ||||||||||||||||||
1376 | --i; | - | ||||||||||||||||||
1377 | goto break_out_of_outer_loop; | - | ||||||||||||||||||
1378 | } | - | ||||||||||||||||||
1379 | } | - | ||||||||||||||||||
1380 | } | - | ||||||||||||||||||
1381 | - | |||||||||||||||||||
1382 | break_out_of_outer_loop: | - | ||||||||||||||||||
1383 | dataPos = i; | - | ||||||||||||||||||
1384 | lineLen = i - lineStart; | - | ||||||||||||||||||
1385 | return lineLen > 0; | - | ||||||||||||||||||
1386 | } | - | ||||||||||||||||||
1387 | - | |||||||||||||||||||
1388 | - | |||||||||||||||||||
1389 | - | |||||||||||||||||||
1390 | - | |||||||||||||||||||
1391 | - | |||||||||||||||||||
1392 | - | |||||||||||||||||||
1393 | bool QConfFileSettingsPrivate::readIniFile(const QByteArray &data, | - | ||||||||||||||||||
1394 | UnparsedSettingsMap *unparsedIniSections) | - | ||||||||||||||||||
1395 | { | - | ||||||||||||||||||
1396 | QString currentSection; | - | ||||||||||||||||||
1397 | int currentSectionStart = 0; | - | ||||||||||||||||||
1398 | int dataPos = 0; | - | ||||||||||||||||||
1399 | int lineStart; | - | ||||||||||||||||||
1400 | int lineLen; | - | ||||||||||||||||||
1401 | int equalsPos; | - | ||||||||||||||||||
1402 | int position = 0; | - | ||||||||||||||||||
1403 | int sectionPosition = 0; | - | ||||||||||||||||||
1404 | bool ok = true; | - | ||||||||||||||||||
1405 | - | |||||||||||||||||||
1406 | - | |||||||||||||||||||
1407 | - | |||||||||||||||||||
1408 | const uchar *dd = (const uchar *)data.constData(); | - | ||||||||||||||||||
1409 | if (data.size() >= 3 && dd[0] == 0xef && dd[1] == 0xbb && dd[2] == 0xbf) { | - | ||||||||||||||||||
1410 | iniCodec = QTextCodec::codecForName("UTF-8"); | - | ||||||||||||||||||
1411 | dataPos = 3; | - | ||||||||||||||||||
1412 | } | - | ||||||||||||||||||
1413 | - | |||||||||||||||||||
1414 | - | |||||||||||||||||||
1415 | while (readIniLine(data, dataPos, lineStart, lineLen, equalsPos)) { | - | ||||||||||||||||||
1416 | char ch = data.at(lineStart); | - | ||||||||||||||||||
1417 | if (ch == '[') { | - | ||||||||||||||||||
1418 | { QByteArray §ionData = (*unparsedIniSections)[QSettingsKey(currentSection, IniCaseSensitivity, sectionPosition)]; if (!sectionData.isEmpty()) sectionData.append('\n'); sectionData += data.mid(currentSectionStart, lineStart - currentSectionStart); sectionPosition = ++position; }; | - | ||||||||||||||||||
1419 | - | |||||||||||||||||||
1420 | - | |||||||||||||||||||
1421 | QByteArray iniSection; | - | ||||||||||||||||||
1422 | int idx = data.indexOf(']', lineStart); | - | ||||||||||||||||||
1423 | if (idx == -1 || idx >= lineStart + lineLen) { | - | ||||||||||||||||||
1424 | ok = false; | - | ||||||||||||||||||
1425 | iniSection = data.mid(lineStart + 1, lineLen - 1); | - | ||||||||||||||||||
1426 | } else { | - | ||||||||||||||||||
1427 | iniSection = data.mid(lineStart + 1, idx - lineStart - 1); | - | ||||||||||||||||||
1428 | } | - | ||||||||||||||||||
1429 | - | |||||||||||||||||||
1430 | iniSection = iniSection.trimmed(); | - | ||||||||||||||||||
1431 | - | |||||||||||||||||||
1432 | if (qstricmp(iniSection.constData(), "general") == 0) { | - | ||||||||||||||||||
1433 | currentSection.clear(); | - | ||||||||||||||||||
1434 | } else { | - | ||||||||||||||||||
1435 | if (qstricmp(iniSection.constData(), "%general") == 0) { | - | ||||||||||||||||||
1436 | currentSection = QLatin1String(iniSection.constData() + 1); | - | ||||||||||||||||||
1437 | } else { | - | ||||||||||||||||||
1438 | currentSection.clear(); | - | ||||||||||||||||||
1439 | iniUnescapedKey(iniSection, 0, iniSection.size(), currentSection); | - | ||||||||||||||||||
1440 | } | - | ||||||||||||||||||
1441 | currentSection += QLatin1Char('/'); | - | ||||||||||||||||||
1442 | } | - | ||||||||||||||||||
1443 | currentSectionStart = dataPos; | - | ||||||||||||||||||
1444 | } | - | ||||||||||||||||||
1445 | ++position; | - | ||||||||||||||||||
1446 | } | - | ||||||||||||||||||
1447 | - | |||||||||||||||||||
1448 | ((!(lineStart == data.length())) ? qt_assert("lineStart == data.length()",__FILE__,17201696) : qt_noop()); | - | ||||||||||||||||||
1449 | { QByteArray §ionData = (*unparsedIniSections)[QSettingsKey(currentSection, IniCaseSensitivity, sectionPosition)]; if (!sectionData.isEmpty()) sectionData.append('\n'); sectionData += data.mid(currentSectionStart, lineStart - currentSectionStart); sectionPosition = ++position; }; | - | ||||||||||||||||||
1450 | - | |||||||||||||||||||
1451 | return ok; | - | ||||||||||||||||||
1452 | - | |||||||||||||||||||
1453 | - | |||||||||||||||||||
1454 | } | - | ||||||||||||||||||
1455 | - | |||||||||||||||||||
1456 | bool QConfFileSettingsPrivate::readIniSection(const QSettingsKey §ion, const QByteArray &data, | - | ||||||||||||||||||
1457 | ParsedSettingsMap *settingsMap, QTextCodec *codec) | - | ||||||||||||||||||
1458 | { | - | ||||||||||||||||||
1459 | QStringList strListValue; | - | ||||||||||||||||||
1460 | bool sectionIsLowercase = (section == section.originalCaseKey()); | - | ||||||||||||||||||
1461 | int equalsPos; | - | ||||||||||||||||||
1462 | - | |||||||||||||||||||
1463 | bool ok = true; | - | ||||||||||||||||||
1464 | int dataPos = 0; | - | ||||||||||||||||||
1465 | int lineStart; | - | ||||||||||||||||||
1466 | int lineLen; | - | ||||||||||||||||||
1467 | int position = section.originalKeyPosition(); | - | ||||||||||||||||||
1468 | - | |||||||||||||||||||
1469 | while (readIniLine(data, dataPos, lineStart, lineLen, equalsPos)) { | - | ||||||||||||||||||
1470 | char ch = data.at(lineStart); | - | ||||||||||||||||||
1471 | ((!(ch != '[')) ? qt_assert("ch != '['",__FILE__,17431719) : qt_noop()); | - | ||||||||||||||||||
1472 | - | |||||||||||||||||||
1473 | if (equalsPos == -1) { | - | ||||||||||||||||||
1474 | if (ch != ';') | - | ||||||||||||||||||
1475 | ok = false; | - | ||||||||||||||||||
1476 | continue; | - | ||||||||||||||||||
1477 | } | - | ||||||||||||||||||
1478 | - | |||||||||||||||||||
1479 | int keyEnd = equalsPos; | - | ||||||||||||||||||
1480 | while (keyEnd > lineStart && ((ch = data.at(keyEnd - 1)) == ' ' || ch == '\t')) | - | ||||||||||||||||||
1481 | --keyEnd; | - | ||||||||||||||||||
1482 | int valueStart = equalsPos + 1; | - | ||||||||||||||||||
1483 | - | |||||||||||||||||||
1484 | QString key = section.originalCaseKey(); | - | ||||||||||||||||||
1485 | bool keyIsLowercase = (iniUnescapedKey(data, lineStart, keyEnd, key) && sectionIsLowercase); | - | ||||||||||||||||||
1486 | - | |||||||||||||||||||
1487 | QString strValue; | - | ||||||||||||||||||
1488 | strValue.reserve(lineLen - (valueStart - lineStart)); | - | ||||||||||||||||||
1489 | bool isStringList = iniUnescapedStringList(data, valueStart, lineStart + lineLen, | - | ||||||||||||||||||
1490 | strValue, strListValue, codec); | - | ||||||||||||||||||
1491 | QVariant variant; | - | ||||||||||||||||||
1492 | if (isStringList) { | - | ||||||||||||||||||
1493 | variant = stringListToVariantList(strListValue); | - | ||||||||||||||||||
1494 | } else { | - | ||||||||||||||||||
1495 | variant = stringToVariant(strValue); | - | ||||||||||||||||||
1496 | } | - | ||||||||||||||||||
1497 | - | |||||||||||||||||||
1498 | - | |||||||||||||||||||
1499 | - | |||||||||||||||||||
1500 | - | |||||||||||||||||||
1501 | - | |||||||||||||||||||
1502 | - | |||||||||||||||||||
1503 | settingsMap->insert(QSettingsKey(key, keyIsLowercase ? Qt::CaseSensitive | - | ||||||||||||||||||
1504 | : IniCaseSensitivity, | - | ||||||||||||||||||
1505 | position), | - | ||||||||||||||||||
1506 | variant); | - | ||||||||||||||||||
1507 | ++position; | - | ||||||||||||||||||
1508 | } | - | ||||||||||||||||||
1509 | - | |||||||||||||||||||
1510 | return ok; | - | ||||||||||||||||||
1511 | } | - | ||||||||||||||||||
1512 | - | |||||||||||||||||||
1513 | class QSettingsIniKey : public QString | - | ||||||||||||||||||
1514 | { | - | ||||||||||||||||||
1515 | public: | - | ||||||||||||||||||
1516 | inline QSettingsIniKey() : position(-1) {} | - | ||||||||||||||||||
1517 | inline QSettingsIniKey(const QString &str, int pos = -1) : QString(str), position(pos) {} | - | ||||||||||||||||||
1518 | - | |||||||||||||||||||
1519 | int position; | - | ||||||||||||||||||
1520 | }; | - | ||||||||||||||||||
1521 | template<> class QTypeInfo<QSettingsIniKey > { public: enum { isComplex = (((Q_MOVABLE_TYPE) & Q_PRIMITIVE_TYPE) == 0), isStatic = (((Q_MOVABLE_TYPE) & (Q_MOVABLE_TYPE | Q_PRIMITIVE_TYPE)) == 0), isRelocatable = !isStatic || ((Q_MOVABLE_TYPE) & Q_RELOCATABLE_TYPE), isLarge = (sizeof(QSettingsIniKey)>sizeof(void*)), isPointer = false, isIntegral = QtPrivate::is_integral< QSettingsIniKey >::value, isDummy = (((Q_MOVABLE_TYPE) & Q_DUMMY_TYPE) != 0), sizeOf = sizeof(QSettingsIniKey) }; static inline const char *name() { return "QSettingsIniKey"; } }; | - | ||||||||||||||||||
1522 | - | |||||||||||||||||||
1523 | static bool operator<(const QSettingsIniKey &k1, const QSettingsIniKey &k2) | - | ||||||||||||||||||
1524 | { | - | ||||||||||||||||||
1525 | if (k1.position != k2.position) | - | ||||||||||||||||||
1526 | return k1.position < k2.position; | - | ||||||||||||||||||
1527 | return static_cast<const QString &>(k1) < static_cast<const QString &>(k2); | - | ||||||||||||||||||
1528 | } | - | ||||||||||||||||||
1529 | - | |||||||||||||||||||
1530 | typedef QMap<QSettingsIniKey, QVariant> IniKeyMap; | - | ||||||||||||||||||
1531 | - | |||||||||||||||||||
1532 | struct QSettingsIniSection | - | ||||||||||||||||||
1533 | { | - | ||||||||||||||||||
1534 | int position; | - | ||||||||||||||||||
1535 | IniKeyMap keyMap; | - | ||||||||||||||||||
1536 | - | |||||||||||||||||||
1537 | inline QSettingsIniSection() : position(-1) {} | - | ||||||||||||||||||
1538 | }; | - | ||||||||||||||||||
1539 | - | |||||||||||||||||||
1540 | typedef QMap<QString, QSettingsIniSection> IniMap; | - | ||||||||||||||||||
1541 | - | |||||||||||||||||||
1542 | - | |||||||||||||||||||
1543 | - | |||||||||||||||||||
1544 | - | |||||||||||||||||||
1545 | - | |||||||||||||||||||
1546 | bool QConfFileSettingsPrivate::writeIniFile(QIODevice &device, const ParsedSettingsMap &map) | - | ||||||||||||||||||
1547 | { | - | ||||||||||||||||||
1548 | IniMap iniMap; | - | ||||||||||||||||||
1549 | IniMap::const_iterator i; | - | ||||||||||||||||||
1550 | - | |||||||||||||||||||
1551 | - | |||||||||||||||||||
1552 | - | |||||||||||||||||||
1553 | - | |||||||||||||||||||
1554 | const char eol = '\n'; | - | ||||||||||||||||||
1555 | - | |||||||||||||||||||
1556 | - | |||||||||||||||||||
1557 | for (ParsedSettingsMap::const_iterator j = map.constBegin(); j != map.constEnd(); ++j) { | - | ||||||||||||||||||
1558 | QString section; | - | ||||||||||||||||||
1559 | QSettingsIniKey key(j.key().originalCaseKey(), j.key().originalKeyPosition()); | - | ||||||||||||||||||
1560 | int slashPos; | - | ||||||||||||||||||
1561 | - | |||||||||||||||||||
1562 | if ((slashPos = key.indexOf(QLatin1Char('/'))) != -1) { | - | ||||||||||||||||||
1563 | section = key.left(slashPos); | - | ||||||||||||||||||
1564 | key.remove(0, slashPos + 1); | - | ||||||||||||||||||
1565 | } | - | ||||||||||||||||||
1566 | - | |||||||||||||||||||
1567 | QSettingsIniSection &iniSection = iniMap[section]; | - | ||||||||||||||||||
1568 | - | |||||||||||||||||||
1569 | - | |||||||||||||||||||
1570 | if (uint(key.position) < uint(iniSection.position)) | - | ||||||||||||||||||
1571 | iniSection.position = key.position; | - | ||||||||||||||||||
1572 | iniSection.keyMap[key] = j.value(); | - | ||||||||||||||||||
1573 | } | - | ||||||||||||||||||
1574 | - | |||||||||||||||||||
1575 | const int sectionCount = iniMap.size(); | - | ||||||||||||||||||
1576 | QVector<QSettingsIniKey> sections; | - | ||||||||||||||||||
1577 | sections.reserve(sectionCount); | - | ||||||||||||||||||
1578 | for (i = iniMap.constBegin(); i != iniMap.constEnd(); ++i) | - | ||||||||||||||||||
1579 | sections.append(QSettingsIniKey(i.key(), i.value().position)); | - | ||||||||||||||||||
1580 | std::sort(sections.begin(), sections.end()); | - | ||||||||||||||||||
1581 | - | |||||||||||||||||||
1582 | bool writeError = false; | - | ||||||||||||||||||
1583 | for (int j = 0; !writeError && j < sectionCount; ++j) { | - | ||||||||||||||||||
1584 | i = iniMap.constFind(sections.at(j)); | - | ||||||||||||||||||
1585 | ((!(i != iniMap.constEnd())) ? qt_assert("i != iniMap.constEnd()",__FILE__,18571833) : qt_noop()); | - | ||||||||||||||||||
1586 | - | |||||||||||||||||||
1587 | QByteArray realSection; | - | ||||||||||||||||||
1588 | - | |||||||||||||||||||
1589 | iniEscapedKey(i.key(), realSection); | - | ||||||||||||||||||
1590 | - | |||||||||||||||||||
1591 | if (realSection.isEmpty()) { | - | ||||||||||||||||||
1592 | realSection = "[General]"; | - | ||||||||||||||||||
1593 | } else if (qstricmp(realSection.constData(), "general") == 0) { | - | ||||||||||||||||||
1594 | realSection = "[%General]"; | - | ||||||||||||||||||
1595 | } else { | - | ||||||||||||||||||
1596 | realSection.prepend('['); | - | ||||||||||||||||||
1597 | realSection.append(']'); | - | ||||||||||||||||||
1598 | } | - | ||||||||||||||||||
1599 | - | |||||||||||||||||||
1600 | if (j != 0) | - | ||||||||||||||||||
1601 | realSection.prepend(eol); | - | ||||||||||||||||||
1602 | realSection += eol; | - | ||||||||||||||||||
1603 | - | |||||||||||||||||||
1604 | device.write(realSection); | - | ||||||||||||||||||
1605 | - | |||||||||||||||||||
1606 | const IniKeyMap &ents = i.value().keyMap; | - | ||||||||||||||||||
1607 | for (IniKeyMap::const_iterator j = ents.constBegin(); j != ents.constEnd(); ++j) { | - | ||||||||||||||||||
1608 | QByteArray block; | - | ||||||||||||||||||
1609 | iniEscapedKey(j.key(), block); | - | ||||||||||||||||||
1610 | block += '='; | - | ||||||||||||||||||
1611 | - | |||||||||||||||||||
1612 | const QVariant &value = j.value(); | - | ||||||||||||||||||
1613 | - | |||||||||||||||||||
1614 | - | |||||||||||||||||||
1615 | - | |||||||||||||||||||
1616 | - | |||||||||||||||||||
1617 | - | |||||||||||||||||||
1618 | - | |||||||||||||||||||
1619 | if (value.type() == QVariant::StringList | - | ||||||||||||||||||
1620 | || (value.type() == QVariant::List && value.toList().size() != 1)) { | - | ||||||||||||||||||
1621 | iniEscapedStringList(variantListToStringList(value.toList()), block, iniCodec); | - | ||||||||||||||||||
1622 | } else { | - | ||||||||||||||||||
1623 | iniEscapedString(variantToString(value), block, iniCodec); | - | ||||||||||||||||||
1624 | } | - | ||||||||||||||||||
1625 | block += eol; | - | ||||||||||||||||||
1626 | if (device.write(block) == -1) { | - | ||||||||||||||||||
1627 | writeError = true; | - | ||||||||||||||||||
1628 | break; | - | ||||||||||||||||||
1629 | } | - | ||||||||||||||||||
1630 | } | - | ||||||||||||||||||
1631 | } | - | ||||||||||||||||||
1632 | return !writeError; | - | ||||||||||||||||||
1633 | } | - | ||||||||||||||||||
1634 | - | |||||||||||||||||||
1635 | void QConfFileSettingsPrivate::ensureAllSectionsParsed(QConfFile *confFile) const | - | ||||||||||||||||||
1636 | { | - | ||||||||||||||||||
1637 | UnparsedSettingsMap::const_iterator i = confFile->unparsedIniSections.constBegin(); | - | ||||||||||||||||||
1638 | const UnparsedSettingsMap::const_iterator end = confFile->unparsedIniSections.constEnd(); | - | ||||||||||||||||||
1639 | - | |||||||||||||||||||
1640 | for (; i != end; ++i) { | - | ||||||||||||||||||
1641 | if (!QConfFileSettingsPrivate::readIniSection(i.key(), i.value(), &confFile->originalKeys, iniCodec)) | - | ||||||||||||||||||
1642 | setStatus(QSettings::FormatError); | - | ||||||||||||||||||
1643 | } | - | ||||||||||||||||||
1644 | confFile->unparsedIniSections.clear(); | - | ||||||||||||||||||
1645 | } | - | ||||||||||||||||||
1646 | - | |||||||||||||||||||
1647 | void QConfFileSettingsPrivate::ensureSectionParsed(QConfFile *confFile, | - | ||||||||||||||||||
1648 | const QSettingsKey &key) const | - | ||||||||||||||||||
1649 | { | - | ||||||||||||||||||
1650 | if (confFile->unparsedIniSections.isEmpty()) | - | ||||||||||||||||||
1651 | return; | - | ||||||||||||||||||
1652 | - | |||||||||||||||||||
1653 | UnparsedSettingsMap::iterator i; | - | ||||||||||||||||||
1654 | - | |||||||||||||||||||
1655 | int indexOfSlash = key.indexOf(QLatin1Char('/')); | - | ||||||||||||||||||
1656 | if (indexOfSlash != -1) { | - | ||||||||||||||||||
1657 | i = confFile->unparsedIniSections.upperBound(key); | - | ||||||||||||||||||
1658 | if (i == confFile->unparsedIniSections.begin()) | - | ||||||||||||||||||
1659 | return; | - | ||||||||||||||||||
1660 | --i; | - | ||||||||||||||||||
1661 | if (i.key().isEmpty() || !key.startsWith(i.key())) | - | ||||||||||||||||||
1662 | return; | - | ||||||||||||||||||
1663 | } else { | - | ||||||||||||||||||
1664 | i = confFile->unparsedIniSections.begin(); | - | ||||||||||||||||||
1665 | if (i == confFile->unparsedIniSections.end() || !i.key().isEmpty()) | - | ||||||||||||||||||
1666 | return; | - | ||||||||||||||||||
1667 | } | - | ||||||||||||||||||
1668 | - | |||||||||||||||||||
1669 | if (!QConfFileSettingsPrivate::readIniSection(i.key(), i.value(), &confFile->originalKeys, iniCodec)) | - | ||||||||||||||||||
1670 | setStatus(QSettings::FormatError); | - | ||||||||||||||||||
1671 | confFile->unparsedIniSections.erase(i); | - | ||||||||||||||||||
1672 | } | - | ||||||||||||||||||
1673 | QSettings::QSettings(const QString &organization, const QString &application, QObject *parent) | - | ||||||||||||||||||
1674 | : QObject(*QSettingsPrivate::create(NativeFormat, UserScope, organization, application), | - | ||||||||||||||||||
1675 | parent) | - | ||||||||||||||||||
1676 | { | - | ||||||||||||||||||
1677 | } | - | ||||||||||||||||||
1678 | QSettings::QSettings(Scope scope, const QString &organization, const QString &application, | - | ||||||||||||||||||
1679 | QObject *parent) | - | ||||||||||||||||||
1680 | : QObject(*QSettingsPrivate::create(NativeFormat, scope, organization, application), parent) | - | ||||||||||||||||||
1681 | { | - | ||||||||||||||||||
1682 | } | - | ||||||||||||||||||
1683 | QSettings::QSettings(Format format, Scope scope, const QString &organization, | - | ||||||||||||||||||
1684 | const QString &application, QObject *parent) | - | ||||||||||||||||||
1685 | : QObject(*QSettingsPrivate::create(format, scope, organization, application), parent) | - | ||||||||||||||||||
1686 | { | - | ||||||||||||||||||
1687 | } | - | ||||||||||||||||||
1688 | QSettings::QSettings(const QString &fileName, Format format, QObject *parent) | - | ||||||||||||||||||
1689 | : QObject(*QSettingsPrivate::create(fileName, format), parent) | - | ||||||||||||||||||
1690 | { | - | ||||||||||||||||||
1691 | } | - | ||||||||||||||||||
1692 | QSettings::QSettings(QObject *parent) | - | ||||||||||||||||||
1693 | : QObject(*QSettingsPrivate::create(globalDefaultFormat, UserScope, | - | ||||||||||||||||||
1694 | - | |||||||||||||||||||
1695 | - | |||||||||||||||||||
1696 | - | |||||||||||||||||||
1697 | - | |||||||||||||||||||
1698 | - | |||||||||||||||||||
1699 | QCoreApplication::organizationName().isEmpty() | - | ||||||||||||||||||
1700 | ? QCoreApplication::organizationDomain() | - | ||||||||||||||||||
1701 | : QCoreApplication::organizationName() | - | ||||||||||||||||||
1702 | - | |||||||||||||||||||
1703 | , QCoreApplication::applicationName()), | - | ||||||||||||||||||
1704 | parent) | - | ||||||||||||||||||
1705 | { | - | ||||||||||||||||||
1706 | } | - | ||||||||||||||||||
1707 | QSettings::~QSettings() | - | ||||||||||||||||||
1708 | { | - | ||||||||||||||||||
1709 | QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1710 | if (d->pendingChanges) { | - | ||||||||||||||||||
1711 | try { | - | ||||||||||||||||||
1712 | d->flush(); | - | ||||||||||||||||||
1713 | } catch (...) { | - | ||||||||||||||||||
1714 | ; | - | ||||||||||||||||||
1715 | } | - | ||||||||||||||||||
1716 | } | - | ||||||||||||||||||
1717 | } | - | ||||||||||||||||||
1718 | void QSettings::clear() | - | ||||||||||||||||||
1719 | { | - | ||||||||||||||||||
1720 | QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1721 | d->clear(); | - | ||||||||||||||||||
1722 | d->requestUpdate(); | - | ||||||||||||||||||
1723 | } | - | ||||||||||||||||||
1724 | void QSettings::sync() | - | ||||||||||||||||||
1725 | { | - | ||||||||||||||||||
1726 | QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1727 | d->sync(); | - | ||||||||||||||||||
1728 | } | - | ||||||||||||||||||
1729 | QString QSettings::fileName() const | - | ||||||||||||||||||
1730 | { | - | ||||||||||||||||||
1731 | const QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1732 | return d->fileName(); | - | ||||||||||||||||||
1733 | } | - | ||||||||||||||||||
1734 | QSettings::Format QSettings::format() const | - | ||||||||||||||||||
1735 | { | - | ||||||||||||||||||
1736 | const QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1737 | return d->format; | - | ||||||||||||||||||
1738 | } | - | ||||||||||||||||||
1739 | QSettings::Scope QSettings::scope() const | - | ||||||||||||||||||
1740 | { | - | ||||||||||||||||||
1741 | const QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1742 | return d->scope; | - | ||||||||||||||||||
1743 | } | - | ||||||||||||||||||
1744 | QString QSettings::organizationName() const | - | ||||||||||||||||||
1745 | { | - | ||||||||||||||||||
1746 | const QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1747 | return d->organizationName; | - | ||||||||||||||||||
1748 | } | - | ||||||||||||||||||
1749 | QString QSettings::applicationName() const | - | ||||||||||||||||||
1750 | { | - | ||||||||||||||||||
1751 | const QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1752 | return d->applicationName; | - | ||||||||||||||||||
1753 | } | - | ||||||||||||||||||
1754 | void QSettings::setIniCodec(QTextCodec *codec) | - | ||||||||||||||||||
1755 | { | - | ||||||||||||||||||
1756 | QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1757 | d->iniCodec = codec; | - | ||||||||||||||||||
1758 | } | - | ||||||||||||||||||
1759 | void QSettings::setIniCodec(const char *codecName) | - | ||||||||||||||||||
1760 | { | - | ||||||||||||||||||
1761 | QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1762 | if (QTextCodec *codec = QTextCodec::codecForName(codecName)) | - | ||||||||||||||||||
1763 | d->iniCodec = codec; | - | ||||||||||||||||||
1764 | } | - | ||||||||||||||||||
1765 | QTextCodec *QSettings::iniCodec() const | - | ||||||||||||||||||
1766 | { | - | ||||||||||||||||||
1767 | const QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1768 | return d->iniCodec; | - | ||||||||||||||||||
1769 | } | - | ||||||||||||||||||
1770 | QSettings::Status QSettings::status() const | - | ||||||||||||||||||
1771 | { | - | ||||||||||||||||||
1772 | const QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1773 | return d->status; | - | ||||||||||||||||||
1774 | } | - | ||||||||||||||||||
1775 | void QSettings::beginGroup(const QString &prefix) | - | ||||||||||||||||||
1776 | { | - | ||||||||||||||||||
1777 | QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1778 | d->beginGroupOrArray(QSettingsGroup(d->normalizedKey(prefix))); | - | ||||||||||||||||||
1779 | } | - | ||||||||||||||||||
1780 | void QSettings::endGroup() | - | ||||||||||||||||||
1781 | { | - | ||||||||||||||||||
1782 | QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1783 | if (d->groupStack.isEmpty()) { | - | ||||||||||||||||||
1784 | QMessageLogger(__FILE__, 29382911, __PRETTY_FUNCTION__).warning("QSettings::endGroup: No matching beginGroup()"); | - | ||||||||||||||||||
1785 | return; | - | ||||||||||||||||||
1786 | } | - | ||||||||||||||||||
1787 | - | |||||||||||||||||||
1788 | QSettingsGroup group = d->groupStack.pop(); | - | ||||||||||||||||||
1789 | int len = group.toString().size(); | - | ||||||||||||||||||
1790 | if (len > 0) | - | ||||||||||||||||||
1791 | d->groupPrefix.truncate(d->groupPrefix.size() - (len + 1)); | - | ||||||||||||||||||
1792 | - | |||||||||||||||||||
1793 | if (group.isArray()) | - | ||||||||||||||||||
1794 | QMessageLogger(__FILE__, 29482921, __PRETTY_FUNCTION__).warning("QSettings::endGroup: Expected endArray() instead"); | - | ||||||||||||||||||
1795 | } | - | ||||||||||||||||||
1796 | - | |||||||||||||||||||
1797 | - | |||||||||||||||||||
1798 | - | |||||||||||||||||||
1799 | - | |||||||||||||||||||
1800 | - | |||||||||||||||||||
1801 | - | |||||||||||||||||||
1802 | QString QSettings::group() const | - | ||||||||||||||||||
1803 | { | - | ||||||||||||||||||
1804 | const QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1805 | return d->groupPrefix.left(d->groupPrefix.size() - 1); | - | ||||||||||||||||||
1806 | } | - | ||||||||||||||||||
1807 | int QSettings::beginReadArray(const QString &prefix) | - | ||||||||||||||||||
1808 | { | - | ||||||||||||||||||
1809 | QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1810 | d->beginGroupOrArray(QSettingsGroup(d->normalizedKey(prefix), false)); | - | ||||||||||||||||||
1811 | return value(QLatin1String("size")).toInt(); | - | ||||||||||||||||||
1812 | } | - | ||||||||||||||||||
1813 | void QSettings::beginWriteArray(const QString &prefix, int size) | - | ||||||||||||||||||
1814 | { | - | ||||||||||||||||||
1815 | QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1816 | d->beginGroupOrArray(QSettingsGroup(d->normalizedKey(prefix), size < 0)); | - | ||||||||||||||||||
1817 | - | |||||||||||||||||||
1818 | if (size < 0) | - | ||||||||||||||||||
1819 | remove(QLatin1String("size")); | - | ||||||||||||||||||
1820 | else | - | ||||||||||||||||||
1821 | setValue(QLatin1String("size"), size); | - | ||||||||||||||||||
1822 | } | - | ||||||||||||||||||
1823 | - | |||||||||||||||||||
1824 | - | |||||||||||||||||||
1825 | - | |||||||||||||||||||
1826 | - | |||||||||||||||||||
1827 | - | |||||||||||||||||||
1828 | - | |||||||||||||||||||
1829 | - | |||||||||||||||||||
1830 | void QSettings::endArray() | - | ||||||||||||||||||
1831 | { | - | ||||||||||||||||||
1832 | QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1833 | if (d->groupStack.isEmpty()) { | - | ||||||||||||||||||
1834 | QMessageLogger(__FILE__, 30313004, __PRETTY_FUNCTION__).warning("QSettings::endArray: No matching beginArray()"); | - | ||||||||||||||||||
1835 | return; | - | ||||||||||||||||||
1836 | } | - | ||||||||||||||||||
1837 | - | |||||||||||||||||||
1838 | QSettingsGroup group = d->groupStack.top(); | - | ||||||||||||||||||
1839 | int len = group.toString().size(); | - | ||||||||||||||||||
1840 | d->groupStack.pop(); | - | ||||||||||||||||||
1841 | if (len > 0) | - | ||||||||||||||||||
1842 | d->groupPrefix.truncate(d->groupPrefix.size() - (len + 1)); | - | ||||||||||||||||||
1843 | - | |||||||||||||||||||
1844 | if (group.arraySizeGuess() != -1) | - | ||||||||||||||||||
1845 | setValue(group.name() + QLatin1String("/size"), group.arraySizeGuess()); | - | ||||||||||||||||||
1846 | - | |||||||||||||||||||
1847 | if (!group.isArray()) | - | ||||||||||||||||||
1848 | QMessageLogger(__FILE__, 30453018, __PRETTY_FUNCTION__).warning("QSettings::endArray: Expected endGroup() instead"); | - | ||||||||||||||||||
1849 | } | - | ||||||||||||||||||
1850 | void QSettings::setArrayIndex(int i) | - | ||||||||||||||||||
1851 | { | - | ||||||||||||||||||
1852 | QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1853 | if (d->groupStack.isEmpty() || !d->groupStack.top().isArray()) { | - | ||||||||||||||||||
1854 | QMessageLogger(__FILE__, 30603033, __PRETTY_FUNCTION__).warning("QSettings::setArrayIndex: Missing beginArray()"); | - | ||||||||||||||||||
1855 | return; | - | ||||||||||||||||||
1856 | } | - | ||||||||||||||||||
1857 | - | |||||||||||||||||||
1858 | QSettingsGroup &top = d->groupStack.top(); | - | ||||||||||||||||||
1859 | int len = top.toString().size(); | - | ||||||||||||||||||
1860 | top.setArrayIndex(qMax(i, 0)); | - | ||||||||||||||||||
1861 | d->groupPrefix.replace(d->groupPrefix.size() - len - 1, len, top.toString()); | - | ||||||||||||||||||
1862 | } | - | ||||||||||||||||||
1863 | QStringList QSettings::allKeys() const | - | ||||||||||||||||||
1864 | { | - | ||||||||||||||||||
1865 | const QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1866 | return d->children(d->groupPrefix, QSettingsPrivate::AllKeys); | - | ||||||||||||||||||
1867 | } | - | ||||||||||||||||||
1868 | QStringList QSettings::childKeys() const | - | ||||||||||||||||||
1869 | { | - | ||||||||||||||||||
1870 | const QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1871 | return d->children(d->groupPrefix, QSettingsPrivate::ChildKeys); | - | ||||||||||||||||||
1872 | } | - | ||||||||||||||||||
1873 | QStringList QSettings::childGroups() const | - | ||||||||||||||||||
1874 | { | - | ||||||||||||||||||
1875 | const QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1876 | return d->children(d->groupPrefix, QSettingsPrivate::ChildGroups); | - | ||||||||||||||||||
1877 | } | - | ||||||||||||||||||
1878 | bool QSettings::isWritable() const | - | ||||||||||||||||||
1879 | { | - | ||||||||||||||||||
1880 | const QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1881 | return d->isWritable(); | - | ||||||||||||||||||
1882 | } | - | ||||||||||||||||||
1883 | void QSettings::setValue(const QString &key, const QVariant &value) | - | ||||||||||||||||||
1884 | { | - | ||||||||||||||||||
1885 | QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1886 | if (key.isEmpty()) { | - | ||||||||||||||||||
1887 | QMessageLogger(__FILE__, 31773150, __PRETTY_FUNCTION__).warning("QSettings::setValue: Empty key passed"); | - | ||||||||||||||||||
1888 | return; | - | ||||||||||||||||||
1889 | } | - | ||||||||||||||||||
1890 | QString k = d->actualKey(key); | - | ||||||||||||||||||
1891 | d->set(k, value); | - | ||||||||||||||||||
1892 | d->requestUpdate(); | - | ||||||||||||||||||
1893 | } | - | ||||||||||||||||||
1894 | void QSettings::remove(const QString &key) | - | ||||||||||||||||||
1895 | { | - | ||||||||||||||||||
1896 | QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1897 | - | |||||||||||||||||||
1898 | - | |||||||||||||||||||
1899 | - | |||||||||||||||||||
1900 | - | |||||||||||||||||||
1901 | QString theKey = d->normalizedKey(key); | - | ||||||||||||||||||
1902 | if (theKey.isEmpty()) | - | ||||||||||||||||||
1903 | theKey = group(); | - | ||||||||||||||||||
1904 | else | - | ||||||||||||||||||
1905 | theKey.prepend(d->groupPrefix); | - | ||||||||||||||||||
1906 | - | |||||||||||||||||||
1907 | if (theKey.isEmpty()) { | - | ||||||||||||||||||
1908 | d->clear(); | - | ||||||||||||||||||
1909 | } else { | - | ||||||||||||||||||
1910 | d->remove(theKey); | - | ||||||||||||||||||
1911 | } | - | ||||||||||||||||||
1912 | d->requestUpdate(); | - | ||||||||||||||||||
1913 | } | - | ||||||||||||||||||
1914 | bool QSettings::contains(const QString &key) const | - | ||||||||||||||||||
1915 | { | - | ||||||||||||||||||
1916 | const QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1917 | QString k = d->actualKey(key); | - | ||||||||||||||||||
1918 | return d->get(k, 0); | - | ||||||||||||||||||
1919 | } | - | ||||||||||||||||||
1920 | void QSettings::setFallbacksEnabled(bool b) | - | ||||||||||||||||||
1921 | { | - | ||||||||||||||||||
1922 | QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1923 | d->fallbacks = !!b; | - | ||||||||||||||||||
1924 | } | - | ||||||||||||||||||
1925 | bool QSettings::fallbacksEnabled() const | - | ||||||||||||||||||
1926 | { | - | ||||||||||||||||||
1927 | const QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1928 | return d->fallbacks; | - | ||||||||||||||||||
1929 | } | - | ||||||||||||||||||
1930 | - | |||||||||||||||||||
1931 | - | |||||||||||||||||||
1932 | - | |||||||||||||||||||
1933 | - | |||||||||||||||||||
1934 | - | |||||||||||||||||||
1935 | bool QSettings::event(QEvent *event) | - | ||||||||||||||||||
1936 | { | - | ||||||||||||||||||
1937 | QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1938 | if (event->type() == QEvent::UpdateRequest) { | - | ||||||||||||||||||
1939 | d->update(); | - | ||||||||||||||||||
1940 | return true; | - | ||||||||||||||||||
1941 | } | - | ||||||||||||||||||
1942 | return QObject::event(event); | - | ||||||||||||||||||
1943 | } | - | ||||||||||||||||||
1944 | QVariant QSettings::value(const QString &key, const QVariant &defaultValue) const | - | ||||||||||||||||||
1945 | { | - | ||||||||||||||||||
1946 | const QSettingsPrivate * const d = d_func(); | - | ||||||||||||||||||
1947 | if (key.isEmpty()) { | - | ||||||||||||||||||
1948 | QMessageLogger(__FILE__, 33133286, __PRETTY_FUNCTION__).warning("QSettings::value: Empty key passed"); | - | ||||||||||||||||||
1949 | return QVariant(); | - | ||||||||||||||||||
1950 | } | - | ||||||||||||||||||
1951 | QVariant result = defaultValue; | - | ||||||||||||||||||
1952 | QString k = d->actualKey(key); | - | ||||||||||||||||||
1953 | d->get(k, &result); | - | ||||||||||||||||||
1954 | return result; | - | ||||||||||||||||||
1955 | } | - | ||||||||||||||||||
1956 | void QSettings::setDefaultFormat(Format format) | - | ||||||||||||||||||
1957 | { | - | ||||||||||||||||||
1958 | globalDefaultFormat = format; | - | ||||||||||||||||||
1959 | } | - | ||||||||||||||||||
1960 | QSettings::Format QSettings::defaultFormat() | - | ||||||||||||||||||
1961 | { | - | ||||||||||||||||||
1962 | return globalDefaultFormat; | - | ||||||||||||||||||
1963 | } | - | ||||||||||||||||||
1964 | void QSettings::setSystemIniPath(const QString &dir) | - | ||||||||||||||||||
1965 | { | - | ||||||||||||||||||
1966 | setPath(IniFormat, SystemScope, dir); | - | ||||||||||||||||||
1967 | - | |||||||||||||||||||
1968 | setPath(NativeFormat, SystemScope, dir); | - | ||||||||||||||||||
1969 | - | |||||||||||||||||||
1970 | } | - | ||||||||||||||||||
1971 | - | |||||||||||||||||||
1972 | - | |||||||||||||||||||
1973 | - | |||||||||||||||||||
1974 | - | |||||||||||||||||||
1975 | - | |||||||||||||||||||
1976 | - | |||||||||||||||||||
1977 | - | |||||||||||||||||||
1978 | void QSettings::setUserIniPath(const QString &dir) | - | ||||||||||||||||||
1979 | { | - | ||||||||||||||||||
1980 | setPath(IniFormat, UserScope, dir); | - | ||||||||||||||||||
1981 | - | |||||||||||||||||||
1982 | setPath(NativeFormat, UserScope, dir); | - | ||||||||||||||||||
1983 | - | |||||||||||||||||||
1984 | } | - | ||||||||||||||||||
1985 | void QSettings::setPath(Format format, Scope scope, const QString &path) | - | ||||||||||||||||||
1986 | { | - | ||||||||||||||||||
1987 | QMutexLocker locker(&settingsGlobalMutex); | - | ||||||||||||||||||
1988 | PathHash *pathHash = pathHashFunc(); | - | ||||||||||||||||||
1989 | if (pathHash->isEmpty()) | - | ||||||||||||||||||
1990 | initDefaultPaths(&locker); | - | ||||||||||||||||||
1991 | pathHash->insert(pathHashKey(format, scope), path + QDir::separator()); | - | ||||||||||||||||||
1992 | } | - | ||||||||||||||||||
1993 | QSettings::Format QSettings::registerFormat(const QString &extension, ReadFunc readFunc, | - | ||||||||||||||||||
1994 | WriteFunc writeFunc, | - | ||||||||||||||||||
1995 | Qt::CaseSensitivity caseSensitivity) | - | ||||||||||||||||||
1996 | { | - | ||||||||||||||||||
1997 | - | |||||||||||||||||||
1998 | ((!(caseSensitivity == Qt::CaseSensitive)) ? qt_assert("caseSensitivity == Qt::CaseSensitive",__FILE__,35023475) : qt_noop()); | - | ||||||||||||||||||
1999 | - | |||||||||||||||||||
2000 | - | |||||||||||||||||||
2001 | QMutexLocker locker(&settingsGlobalMutex); | - | ||||||||||||||||||
2002 | CustomFormatVector *customFormatVector = customFormatVectorFunc(); | - | ||||||||||||||||||
2003 | int index = customFormatVector->size(); | - | ||||||||||||||||||
2004 | if (index == 16
| 0-3 | ||||||||||||||||||
2005 | return never executed: QSettings::InvalidFormat;return QSettings::InvalidFormat; never executed: return QSettings::InvalidFormat; | 0 | ||||||||||||||||||
2006 | - | |||||||||||||||||||
2007 | QConfFileCustomFormat info; | - | ||||||||||||||||||
2008 | info.extension = QLatin1Char('.'); | - | ||||||||||||||||||
info.extension +=) + extension; | ||||||||||||||||||||
2009 | info.readFunc = readFunc; | - | ||||||||||||||||||
2010 | info.writeFunc = writeFunc; | - | ||||||||||||||||||
2011 | info.caseSensitivity = caseSensitivity; | - | ||||||||||||||||||
2012 | customFormatVector->append(info); | - | ||||||||||||||||||
2013 | - | |||||||||||||||||||
2014 | return executed 3 times by 1 test: QSettings::Format((int)QSettings::CustomFormat1 + index);return QSettings::Format((int)QSettings::CustomFormat1 + index); Executed by:
executed 3 times by 1 test: return QSettings::Format((int)QSettings::CustomFormat1 + index); Executed by:
| 3 | ||||||||||||||||||
2015 | } | - | ||||||||||||||||||
2016 | - | |||||||||||||||||||
2017 | - | |||||||||||||||||||
Switch to Source code | Preprocessed file |