From 9a8a70d8e42f7e8fee8398affa5680adb2ba24d6 Mon Sep 17 00:00:00 2001 From: Chris Meyer Date: Wed, 9 Nov 2011 10:44:32 -0800 Subject: Prefer organizationDomain or CFBundleIdentifier for settings file MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit Watch for attempts to write to "Trolltech" preferences and use QCoreApplication::organizationDomain() instead. If that doesn't exist, then fall back to CFBundleIdentifier if possible. If that doesn't exist, then follow the old code path and use the hardcoded string. This change eliminates extra files being created which helps Mac app store acceptance. Change-Id: I1ba3984b46cf3888f371d87f6ad8ea6c2f26d2ec Reviewed-by: Morten Johan Sørvig --- src/corelib/io/qsettings_mac.cpp | 44 ++++++++++++++++++++++++++++++++++++++++ 1 file changed, 44 insertions(+) diff --git a/src/corelib/io/qsettings_mac.cpp b/src/corelib/io/qsettings_mac.cpp index 416e256640..11e0c3c103 100644 --- a/src/corelib/io/qsettings_mac.cpp +++ b/src/corelib/io/qsettings_mac.cpp @@ -45,6 +45,9 @@ #include "qdir.h" #include "qvarlengtharray.h" #include "private/qcore_mac_p.h" +#ifndef QT_NO_QOBJECT +#include "qcoreapplication.h" +#endif // QT_NO_QOBJECT QT_BEGIN_NAMESPACE @@ -377,7 +380,28 @@ QMacSettingsPrivate::QMacSettingsPrivate(QSettings::Scope scope, const QString & int curPos = 0; int nextDot; + // attempt to use the organization parameter QString domainName = comify(organization); + // if not found, attempt to use the bundle identifier. + if (domainName.isEmpty()) { + CFBundleRef main_bundle = CFBundleGetMainBundle(); + if (main_bundle != NULL) { + CFStringRef main_bundle_identifier = CFBundleGetIdentifier(main_bundle); + if (main_bundle_identifier != NULL) { + QString bundle_identifier(qtKey(main_bundle_identifier)); + // CFBundleGetIdentifier returns identifier separated by slashes rather than periods. + QStringList bundle_identifier_components = bundle_identifier.split(QLatin1String("/")); + // pre-reverse them so that when they get reversed again below, they are in the com.company.product format. + QStringList bundle_identifier_components_reversed; + for (int i=0; ibeginGroupOrArray(QSettingsGroup(normalizedKey(organization))); + if (!application.isEmpty()) + newSettings->beginGroupOrArray(QSettingsGroup(normalizedKey(application))); + + return newSettings; + } +#endif if (format == QSettings::NativeFormat) { return new QMacSettingsPrivate(scope, organization, application); } else { -- cgit v1.2.3