diff options
author | Chris Meyer <cmeyer1969@gmail.com> | 2011-11-09 10:44:32 -0800 |
---|---|---|
committer | Qt by Nokia <qt-info@nokia.com> | 2011-11-11 10:58:10 +0100 |
commit | 9a8a70d8e42f7e8fee8398affa5680adb2ba24d6 (patch) | |
tree | 2b6faa6876a78f8326a55c0d5edbbf325eea38ae /src/corelib/io/qsettings_mac.cpp | |
parent | 12ebdd9f9e1b27e322259afc058621b39c17c485 (diff) |
Prefer organizationDomain or CFBundleIdentifier for settings file
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 <morten.sorvig@nokia.com>
Diffstat (limited to 'src/corelib/io/qsettings_mac.cpp')
-rw-r--r-- | src/corelib/io/qsettings_mac.cpp | 44 |
1 files changed, 44 insertions, 0 deletions
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; i<bundle_identifier_components.size(); ++i) { + const QString &bundle_identifier_component = bundle_identifier_components.at(i); + bundle_identifier_components_reversed.push_front(bundle_identifier_component); + } + domainName = bundle_identifier_components_reversed.join(QLatin1String(".")); + } + } + } + // if no bundle identifier yet. use a hard coded string. if (domainName.isEmpty()) { setStatus(QSettings::AccessError); domainName = QLatin1String("unknown-organization.trolltech.com"); @@ -579,6 +603,26 @@ QSettingsPrivate *QSettingsPrivate::create(QSettings::Format format, const QString &organization, const QString &application) { +#ifndef QT_BOOTSTRAPPED + if (organization == QLatin1String("Trolltech")) + { + QString organizationDomain = QCoreApplication::organizationDomain(); + QString applicationName = QCoreApplication::applicationName(); + + QSettingsPrivate *newSettings; + if (format == QSettings::NativeFormat) { + newSettings = new QMacSettingsPrivate(scope, organizationDomain, applicationName); + } else { + newSettings = new QConfFileSettingsPrivate(format, scope, organizationDomain, applicationName); + } + + newSettings->beginGroupOrArray(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 { |