Warning: That file was not part of the compilation database. It may have many parsing errors.

1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Contact: https://www.qt.io/licensing/
5**
6** This file is part of the QtCore module of the Qt Toolkit.
7**
8** $QT_BEGIN_LICENSE:LGPL$
9** Commercial License Usage
10** Licensees holding valid commercial Qt licenses may use this file in
11** accordance with the commercial license agreement provided with the
12** Software or, alternatively, in accordance with the terms contained in
13** a written agreement between you and The Qt Company. For licensing terms
14** and conditions see https://www.qt.io/terms-conditions. For further
15** information use the contact form at https://www.qt.io/contact-us.
16**
17** GNU Lesser General Public License Usage
18** Alternatively, this file may be used under the terms of the GNU Lesser
19** General Public License version 3 as published by the Free Software
20** Foundation and appearing in the file LICENSE.LGPL3 included in the
21** packaging of this file. Please review the following information to
22** ensure the GNU Lesser General Public License version 3 requirements
23** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
24**
25** GNU General Public License Usage
26** Alternatively, this file may be used under the terms of the GNU
27** General Public License version 2.0 or (at your option) the GNU General
28** Public license version 3 or any later version approved by the KDE Free
29** Qt Foundation. The licenses are as published by the Free Software
30** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
31** included in the packaging of this file. Please review the following
32** information to ensure the GNU General Public License requirements will
33** be met: https://www.gnu.org/licenses/gpl-2.0.html and
34** https://www.gnu.org/licenses/gpl-3.0.html.
35**
36** $QT_END_LICENSE$
37**
38****************************************************************************/
39
40#include "qsettings.h"
41
42#include "qsettings_p.h"
43#include "qdatetime.h"
44#include "qdir.h"
45#include "qvarlengtharray.h"
46#include "private/qcore_mac_p.h"
47#ifndef QT_NO_QOBJECT
48#include "qcoreapplication.h"
49#endif // QT_NO_QOBJECT
50
51QT_BEGIN_NAMESPACE
52
53static const CFStringRef hostNames[2] = { kCFPreferencesCurrentHost, kCFPreferencesAnyHost };
54static const int numHostNames = 2;
55
56/*
57 On the Mac, it is more natural to use '.' as the key separator
58 than '/'. Therefore, it makes sense to replace '/' with '.' in
59 keys. Then we replace '.' with middle dots (which we can't show
60 here) and middle dots with '/'. A key like "4.0/BrowserCommand"
61 becomes "4<middot>0.BrowserCommand".
62*/
63
64enum RotateShift { Macify = 1, Qtify = 2 };
65
66static QString rotateSlashesDotsAndMiddots(const QString &key, int shift)
67{
68 static const int NumKnights = 3;
69 static const char knightsOfTheRoundTable[NumKnights] = { '/', '.', '\xb7' };
70 QString result = key;
71
72 for (int i = 0; i < result.size(); ++i) {
73 for (int j = 0; j < NumKnights; ++j) {
74 if (result.at(i) == QLatin1Char(knightsOfTheRoundTable[j])) {
75 result[i] = QLatin1Char(knightsOfTheRoundTable[(j + shift) % NumKnights]).unicode();
76 break;
77 }
78 }
79 }
80 return result;
81}
82
83static QCFType<CFStringRef> macKey(const QString &key)
84{
85 return rotateSlashesDotsAndMiddots(key, Macify).toCFString();
86}
87
88static QString qtKey(CFStringRef cfkey)
89{
90 return rotateSlashesDotsAndMiddots(QString::fromCFString(cfkey), Qtify);
91}
92
93static QCFType<CFPropertyListRef> macValue(const QVariant &value);
94
95static CFArrayRef macList(const QList<QVariant> &list)
96{
97 int n = list.size();
98 QVarLengthArray<QCFType<CFPropertyListRef> > cfvalues(n);
99 for (int i = 0; i < n; ++i)
100 cfvalues[i] = macValue(list.at(i));
101 return CFArrayCreate(kCFAllocatorDefault, reinterpret_cast<const void **>(cfvalues.data()),
102 CFIndex(n), &kCFTypeArrayCallBacks);
103}
104
105static QCFType<CFPropertyListRef> macValue(const QVariant &value)
106{
107 CFPropertyListRef result = 0;
108
109 switch (value.type()) {
110 case QVariant::ByteArray:
111 {
112 QByteArray ba = value.toByteArray();
113 result = CFDataCreate(kCFAllocatorDefault, reinterpret_cast<const UInt8 *>(ba.data()),
114 CFIndex(ba.size()));
115 }
116 break;
117 // should be same as below (look for LIST)
118 case QVariant::List:
119 case QVariant::StringList:
120 case QVariant::Polygon:
121 result = macList(value.toList());
122 break;
123 case QVariant::Map:
124 {
125 /*
126 QMap<QString, QVariant> is potentially a multimap,
127 whereas CFDictionary is a single-valued map. To allow
128 for multiple values with the same key, we store
129 multiple values in a CFArray. To avoid ambiguities,
130 we also wrap lists in a CFArray singleton.
131 */
132 QMap<QString, QVariant> map = value.toMap();
133 QMap<QString, QVariant>::const_iterator i = map.constBegin();
134
135 int maxUniqueKeys = map.size();
136 int numUniqueKeys = 0;
137 QVarLengthArray<QCFType<CFPropertyListRef> > cfkeys(maxUniqueKeys);
138 QVarLengthArray<QCFType<CFPropertyListRef> > cfvalues(maxUniqueKeys);
139
140 while (i != map.constEnd()) {
141 const QString &key = i.key();
142 QList<QVariant> values;
143
144 do {
145 values << i.value();
146 ++i;
147 } while (i != map.constEnd() && i.key() == key);
148
149 bool singleton = (values.count() == 1);
150 if (singleton) {
151 switch (values.constFirst().type()) {
152 // should be same as above (look for LIST)
153 case QVariant::List:
154 case QVariant::StringList:
155 case QVariant::Polygon:
156 singleton = false;
157 default:
158 ;
159 }
160 }
161
162 cfkeys[numUniqueKeys] = key.toCFString();
163 cfvalues[numUniqueKeys] = singleton ? macValue(values.constFirst()) : macList(values);
164 ++numUniqueKeys;
165 }
166
167 result = CFDictionaryCreate(kCFAllocatorDefault,
168 reinterpret_cast<const void **>(cfkeys.data()),
169 reinterpret_cast<const void **>(cfvalues.data()),
170 CFIndex(numUniqueKeys),
171 &kCFTypeDictionaryKeyCallBacks,
172 &kCFTypeDictionaryValueCallBacks);
173 }
174 break;
175 case QVariant::DateTime:
176 {
177 QDateTime dateTime = value.toDateTime();
178 // CFDate, unlike QDateTime, doesn't store timezone information
179 if (dateTime.timeSpec() == Qt::LocalTime)
180 result = dateTime.toCFDate();
181 else
182 goto string_case;
183 }
184 break;
185 case QVariant::Bool:
186 result = value.toBool() ? kCFBooleanTrue : kCFBooleanFalse;
187 break;
188 case QVariant::Int:
189 case QVariant::UInt:
190 {
191 int n = value.toInt();
192 result = CFNumberCreate(kCFAllocatorDefault, kCFNumberIntType, &n);
193 }
194 break;
195 case QVariant::Double:
196 {
197 double n = value.toDouble();
198 result = CFNumberCreate(kCFAllocatorDefault, kCFNumberDoubleType, &n);
199 }
200 break;
201 case QVariant::LongLong:
202 case QVariant::ULongLong:
203 {
204 qint64 n = value.toLongLong();
205 result = CFNumberCreate(0, kCFNumberLongLongType, &n);
206 }
207 break;
208 case QVariant::String:
209 string_case:
210 default:
211 QString string = QSettingsPrivate::variantToString(value);
212 if (string.contains(QChar::Null))
213 result = std::move(string).toUtf8().toCFData();
214 else
215 result = string.toCFString();
216 }
217 return result;
218}
219
220static QVariant qtValue(CFPropertyListRef cfvalue)
221{
222 if (!cfvalue)
223 return QVariant();
224
225 CFTypeID typeId = CFGetTypeID(cfvalue);
226
227 /*
228 Sorted grossly from most to least frequent type.
229 */
230 if (typeId == CFStringGetTypeID()) {
231 return QSettingsPrivate::stringToVariant(QString::fromCFString(static_cast<CFStringRef>(cfvalue)));
232 } else if (typeId == CFNumberGetTypeID()) {
233 CFNumberRef cfnumber = static_cast<CFNumberRef>(cfvalue);
234 if (CFNumberIsFloatType(cfnumber)) {
235 double d;
236 CFNumberGetValue(cfnumber, kCFNumberDoubleType, &d);
237 return d;
238 } else {
239 int i;
240 qint64 ll;
241
242 if (CFNumberGetType(cfnumber) == kCFNumberIntType) {
243 CFNumberGetValue(cfnumber, kCFNumberIntType, &i);
244 return i;
245 }
246 CFNumberGetValue(cfnumber, kCFNumberLongLongType, &ll);
247 return ll;
248 }
249 } else if (typeId == CFArrayGetTypeID()) {
250 CFArrayRef cfarray = static_cast<CFArrayRef>(cfvalue);
251 QList<QVariant> list;
252 CFIndex size = CFArrayGetCount(cfarray);
253 bool metNonString = false;
254 for (CFIndex i = 0; i < size; ++i) {
255 QVariant value = qtValue(CFArrayGetValueAtIndex(cfarray, i));
256 if (value.type() != QVariant::String)
257 metNonString = true;
258 list << value;
259 }
260 if (metNonString)
261 return list;
262 else
263 return QVariant(list).toStringList();
264 } else if (typeId == CFBooleanGetTypeID()) {
265 return (bool)CFBooleanGetValue(static_cast<CFBooleanRef>(cfvalue));
266 } else if (typeId == CFDataGetTypeID()) {
267 QByteArray byteArray = QByteArray::fromRawCFData(static_cast<CFDataRef>(cfvalue));
268
269 // Fast-path for QByteArray, so that we don't have to go
270 // though the expensive and lossy conversion via UTF-8.
271 if (!byteArray.startsWith('@')) {
272 byteArray.detach();
273 return byteArray;
274 }
275
276 const QString str = QString::fromUtf8(byteArray.constData(), byteArray.size());
277 return QSettingsPrivate::stringToVariant(str);
278 } else if (typeId == CFDictionaryGetTypeID()) {
279 CFDictionaryRef cfdict = static_cast<CFDictionaryRef>(cfvalue);
280 CFTypeID arrayTypeId = CFArrayGetTypeID();
281 int size = (int)CFDictionaryGetCount(cfdict);
282 QVarLengthArray<CFPropertyListRef> keys(size);
283 QVarLengthArray<CFPropertyListRef> values(size);
284 CFDictionaryGetKeysAndValues(cfdict, keys.data(), values.data());
285
286 QMultiMap<QString, QVariant> map;
287 for (int i = 0; i < size; ++i) {
288 QString key = QString::fromCFString(static_cast<CFStringRef>(keys[i]));
289
290 if (CFGetTypeID(values[i]) == arrayTypeId) {
291 CFArrayRef cfarray = static_cast<CFArrayRef>(values[i]);
292 CFIndex arraySize = CFArrayGetCount(cfarray);
293 for (CFIndex j = arraySize - 1; j >= 0; --j)
294 map.insert(key, qtValue(CFArrayGetValueAtIndex(cfarray, j)));
295 } else {
296 map.insert(key, qtValue(values[i]));
297 }
298 }
299 return map;
300 } else if (typeId == CFDateGetTypeID()) {
301 return QDateTime::fromCFDate(static_cast<CFDateRef>(cfvalue));
302 }
303 return QVariant();
304}
305
306static QString comify(const QString &organization)
307{
308 for (int i = organization.size() - 1; i >= 0; --i) {
309 QChar ch = organization.at(i);
310 if (ch == QLatin1Char('.') || ch == QChar(0x3002) || ch == QChar(0xff0e)
311 || ch == QChar(0xff61)) {
312 QString suffix = organization.mid(i + 1).toLower();
313 if (suffix.size() == 2 || suffix == QLatin1String("com")
314 || suffix == QLatin1String("org") || suffix == QLatin1String("net")
315 || suffix == QLatin1String("edu") || suffix == QLatin1String("gov")
316 || suffix == QLatin1String("mil") || suffix == QLatin1String("biz")
317 || suffix == QLatin1String("info") || suffix == QLatin1String("name")
318 || suffix == QLatin1String("pro") || suffix == QLatin1String("aero")
319 || suffix == QLatin1String("coop") || suffix == QLatin1String("museum")) {
320 QString result = organization;
321 result.replace(QLatin1Char('/'), QLatin1Char(' '));
322 return result;
323 }
324 break;
325 }
326 int uc = ch.unicode();
327 if ((uc < 'a' || uc > 'z') && (uc < 'A' || uc > 'Z'))
328 break;
329 }
330
331 QString domain;
332 for (int i = 0; i < organization.size(); ++i) {
333 QChar ch = organization.at(i);
334 int uc = ch.unicode();
335 if ((uc >= 'a' && uc <= 'z') || (uc >= '0' && uc <= '9')) {
336 domain += ch;
337 } else if (uc >= 'A' && uc <= 'Z') {
338 domain += ch.toLower();
339 } else {
340 domain += QLatin1Char(' ');
341 }
342 }
343 domain = domain.simplified();
344 domain.replace(QLatin1Char(' '), QLatin1Char('-'));
345 if (!domain.isEmpty())
346 domain.append(QLatin1String(".com"));
347 return domain;
348}
349
350class QMacSettingsPrivate : public QSettingsPrivate
351{
352public:
353 QMacSettingsPrivate(QSettings::Scope scope, const QString &organization,
354 const QString &application);
355 ~QMacSettingsPrivate();
356
357 void remove(const QString &key) override;
358 void set(const QString &key, const QVariant &value) override;
359 bool get(const QString &key, QVariant *value) const override;
360 QStringList children(const QString &prefix, ChildSpec spec) const override;
361 void clear() override;
362 void sync() override;
363 void flush() override;
364 bool isWritable() const override;
365 QString fileName() const override;
366
367private:
368 struct SearchDomain
369 {
370 CFStringRef userName;
371 CFStringRef applicationOrSuiteId;
372 };
373
374 QCFString applicationId;
375 QCFString suiteId;
376 QCFString hostName;
377 SearchDomain domains[6];
378 int numDomains;
379};
380
381QMacSettingsPrivate::QMacSettingsPrivate(QSettings::Scope scope, const QString &organization,
382 const QString &application)
383 : QSettingsPrivate(QSettings::NativeFormat, scope, organization, application)
384{
385 QString javaPackageName;
386 int curPos = 0;
387 int nextDot;
388
389 // attempt to use the organization parameter
390 QString domainName = comify(organization);
391 // if not found, attempt to use the bundle identifier.
392 if (domainName.isEmpty()) {
393 CFBundleRef main_bundle = CFBundleGetMainBundle();
394 if (main_bundle != NULL) {
395 CFStringRef main_bundle_identifier = CFBundleGetIdentifier(main_bundle);
396 if (main_bundle_identifier != NULL) {
397 QString bundle_identifier(qtKey(main_bundle_identifier));
398 // CFBundleGetIdentifier returns identifier separated by slashes rather than periods.
399 QStringList bundle_identifier_components = bundle_identifier.split(QLatin1Char('/'));
400 // pre-reverse them so that when they get reversed again below, they are in the com.company.product format.
401 QStringList bundle_identifier_components_reversed;
402 for (int i=0; i<bundle_identifier_components.size(); ++i) {
403 const QString &bundle_identifier_component = bundle_identifier_components.at(i);
404 bundle_identifier_components_reversed.push_front(bundle_identifier_component);
405 }
406 domainName = bundle_identifier_components_reversed.join(QLatin1Char('.'));
407 }
408 }
409 }
410 // if no bundle identifier yet. use a hard coded string.
411 if (domainName.isEmpty()) {
412 domainName = QLatin1String("unknown-organization.trolltech.com");
413 }
414
415 while ((nextDot = domainName.indexOf(QLatin1Char('.'), curPos)) != -1) {
416 javaPackageName.prepend(domainName.midRef(curPos, nextDot - curPos));
417 javaPackageName.prepend(QLatin1Char('.'));
418 curPos = nextDot + 1;
419 }
420 javaPackageName.prepend(domainName.midRef(curPos));
421 javaPackageName = std::move(javaPackageName).toLower();
422 if (curPos == 0)
423 javaPackageName.prepend(QLatin1String("com."));
424 suiteId = javaPackageName;
425
426 if (!application.isEmpty()) {
427 javaPackageName += QLatin1Char('.') + application;
428 applicationId = javaPackageName;
429 }
430
431 numDomains = 0;
432 for (int i = (scope == QSettings::SystemScope) ? 1 : 0; i < 2; ++i) {
433 for (int j = (application.isEmpty()) ? 1 : 0; j < 3; ++j) {
434 SearchDomain &domain = domains[numDomains++];
435 domain.userName = (i == 0) ? kCFPreferencesCurrentUser : kCFPreferencesAnyUser;
436 if (j == 0)
437 domain.applicationOrSuiteId = applicationId;
438 else if (j == 1)
439 domain.applicationOrSuiteId = suiteId;
440 else
441 domain.applicationOrSuiteId = kCFPreferencesAnyApplication;
442 }
443 }
444
445 hostName = (scope == QSettings::SystemScope) ? kCFPreferencesCurrentHost : kCFPreferencesAnyHost;
446 sync();
447}
448
449QMacSettingsPrivate::~QMacSettingsPrivate()
450{
451}
452
453void QMacSettingsPrivate::remove(const QString &key)
454{
455 QStringList keys = children(key + QLatin1Char('/'), AllKeys);
456
457 // If i == -1, then delete "key" itself.
458 for (int i = -1; i < keys.size(); ++i) {
459 QString subKey = key;
460 if (i >= 0) {
461 subKey += QLatin1Char('/');
462 subKey += keys.at(i);
463 }
464 CFPreferencesSetValue(macKey(subKey), 0, domains[0].applicationOrSuiteId,
465 domains[0].userName, hostName);
466 }
467}
468
469void QMacSettingsPrivate::set(const QString &key, const QVariant &value)
470{
471 CFPreferencesSetValue(macKey(key), macValue(value), domains[0].applicationOrSuiteId,
472 domains[0].userName, hostName);
473}
474
475bool QMacSettingsPrivate::get(const QString &key, QVariant *value) const
476{
477 QCFString k = macKey(key);
478 for (int i = 0; i < numDomains; ++i) {
479 for (int j = 0; j < numHostNames; ++j) {
480 QCFType<CFPropertyListRef> ret =
481 CFPreferencesCopyValue(k, domains[i].applicationOrSuiteId, domains[i].userName,
482 hostNames[j]);
483 if (ret) {
484 if (value)
485 *value = qtValue(ret);
486 return true;
487 }
488 }
489
490 if (!fallbacks)
491 break;
492 }
493 return false;
494}
495
496QStringList QMacSettingsPrivate::children(const QString &prefix, ChildSpec spec) const
497{
498 QStringList result;
499 int startPos = prefix.size();
500
501 for (int i = 0; i < numDomains; ++i) {
502 for (int j = 0; j < numHostNames; ++j) {
503 QCFType<CFArrayRef> cfarray = CFPreferencesCopyKeyList(domains[i].applicationOrSuiteId,
504 domains[i].userName,
505 hostNames[j]);
506 if (cfarray) {
507 CFIndex size = CFArrayGetCount(cfarray);
508 for (CFIndex k = 0; k < size; ++k) {
509 QString currentKey =
510 qtKey(static_cast<CFStringRef>(CFArrayGetValueAtIndex(cfarray, k)));
511 if (currentKey.startsWith(prefix))
512 processChild(currentKey.midRef(startPos), spec, result);
513 }
514 }
515 }
516
517 if (!fallbacks)
518 break;
519 }
520 std::sort(result.begin(), result.end());
521 result.erase(std::unique(result.begin(), result.end()),
522 result.end());
523 return result;
524}
525
526void QMacSettingsPrivate::clear()
527{
528 QCFType<CFArrayRef> cfarray = CFPreferencesCopyKeyList(domains[0].applicationOrSuiteId,
529 domains[0].userName, hostName);
530 CFPreferencesSetMultiple(0, cfarray, domains[0].applicationOrSuiteId, domains[0].userName,
531 hostName);
532}
533
534void QMacSettingsPrivate::sync()
535{
536 for (int i = 0; i < numDomains; ++i) {
537 for (int j = 0; j < numHostNames; ++j) {
538 Boolean ok = CFPreferencesSynchronize(domains[i].applicationOrSuiteId,
539 domains[i].userName, hostNames[j]);
540 // only report failures for the primary file (the one we write to)
541 if (!ok && i == 0 && hostNames[j] == hostName && status == QSettings::NoError) {
542 setStatus(QSettings::AccessError);
543 }
544 }
545 }
546}
547
548void QMacSettingsPrivate::flush()
549{
550 sync();
551}
552
553bool QMacSettingsPrivate::isWritable() const
554{
555 QMacSettingsPrivate *that = const_cast<QMacSettingsPrivate *>(this);
556 QString impossibleKey(QLatin1String("qt_internal/"));
557
558 QSettings::Status oldStatus = that->status;
559 that->status = QSettings::NoError;
560
561 that->set(impossibleKey, QVariant());
562 that->sync();
563 bool writable = (status == QSettings::NoError) && that->get(impossibleKey, 0);
564 that->remove(impossibleKey);
565 that->sync();
566
567 that->status = oldStatus;
568 return writable;
569}
570
571QString QMacSettingsPrivate::fileName() const
572{
573 QString result;
574 if (scope == QSettings::UserScope)
575 result = QDir::homePath();
576 result += QLatin1String("/Library/Preferences/");
577 result += QString::fromCFString(domains[0].applicationOrSuiteId);
578 result += QLatin1String(".plist");
579 return result;
580}
581
582QSettingsPrivate *QSettingsPrivate::create(QSettings::Format format,
583 QSettings::Scope scope,
584 const QString &organization,
585 const QString &application)
586{
587#ifndef QT_BOOTSTRAPPED
588 if (organization == QLatin1String("Qt"))
589 {
590 QString organizationDomain = QCoreApplication::organizationDomain();
591 QString applicationName = QCoreApplication::applicationName();
592
593 QSettingsPrivate *newSettings;
594 if (format == QSettings::NativeFormat) {
595 newSettings = new QMacSettingsPrivate(scope, organizationDomain, applicationName);
596 } else {
597 newSettings = new QConfFileSettingsPrivate(format, scope, organizationDomain, applicationName);
598 }
599
600 newSettings->beginGroupOrArray(QSettingsGroup(normalizedKey(organization)));
601 if (!application.isEmpty())
602 newSettings->beginGroupOrArray(QSettingsGroup(normalizedKey(application)));
603
604 return newSettings;
605 }
606#endif
607 if (format == QSettings::NativeFormat) {
608 return new QMacSettingsPrivate(scope, organization, application);
609 } else {
610 return new QConfFileSettingsPrivate(format, scope, organization, application);
611 }
612}
613
614bool QConfFileSettingsPrivate::readPlistFile(const QByteArray &data, ParsedSettingsMap *map) const
615{
616 QCFType<CFDataRef> cfData = data.toRawCFData();
617 QCFType<CFPropertyListRef> propertyList =
618 CFPropertyListCreateWithData(kCFAllocatorDefault, cfData, kCFPropertyListImmutable, nullptr, nullptr);
619
620 if (!propertyList)
621 return true;
622 if (CFGetTypeID(propertyList) != CFDictionaryGetTypeID())
623 return false;
624
625 CFDictionaryRef cfdict =
626 static_cast<CFDictionaryRef>(static_cast<CFPropertyListRef>(propertyList));
627 int size = (int)CFDictionaryGetCount(cfdict);
628 QVarLengthArray<CFPropertyListRef> keys(size);
629 QVarLengthArray<CFPropertyListRef> values(size);
630 CFDictionaryGetKeysAndValues(cfdict, keys.data(), values.data());
631
632 for (int i = 0; i < size; ++i) {
633 QString key = qtKey(static_cast<CFStringRef>(keys[i]));
634 map->insert(QSettingsKey(key, Qt::CaseSensitive), qtValue(values[i]));
635 }
636 return true;
637}
638
639bool QConfFileSettingsPrivate::writePlistFile(QIODevice &file, const ParsedSettingsMap &map) const
640{
641 QVarLengthArray<QCFType<CFStringRef> > cfkeys(map.size());
642 QVarLengthArray<QCFType<CFPropertyListRef> > cfvalues(map.size());
643 int i = 0;
644 ParsedSettingsMap::const_iterator j;
645 for (j = map.constBegin(); j != map.constEnd(); ++j) {
646 cfkeys[i] = macKey(j.key());
647 cfvalues[i] = macValue(j.value());
648 ++i;
649 }
650
651 QCFType<CFDictionaryRef> propertyList =
652 CFDictionaryCreate(kCFAllocatorDefault,
653 reinterpret_cast<const void **>(cfkeys.data()),
654 reinterpret_cast<const void **>(cfvalues.data()),
655 CFIndex(map.size()),
656 &kCFTypeDictionaryKeyCallBacks,
657 &kCFTypeDictionaryValueCallBacks);
658
659 QCFType<CFDataRef> xmlData = CFPropertyListCreateData(
660 kCFAllocatorDefault, propertyList, kCFPropertyListXMLFormat_v1_0, 0, 0);
661
662 return file.write(QByteArray::fromRawCFData(xmlData)) == CFDataGetLength(xmlData);
663}
664
665QT_END_NAMESPACE
666

Warning: That file was not part of the compilation database. It may have many parsing errors.