From 2fac63c76d1527c2ef0bf77355d944efaa59af3d Mon Sep 17 00:00:00 2001 From: Alan Alpert Date: Fri, 23 Aug 2013 16:05:12 -0700 Subject: Add Asset Locations to QStandardPaths::DataLocation The locations of UI assets are deployed to is being added as a read-only location under DataLocation. As such a path is located differently on certain mobile platforms, such as Android and BlackBerry, having an entry in StandardPaths will make it easier to write cross-platform code. Change-Id: I4533c90ed7157725a8604591595b350c7f616723 Reviewed-by: Thiago Macieira Reviewed-by: David Faure --- src/corelib/io/qstandardpaths_mac.cpp | 25 +++++++++++++++++++++++++ 1 file changed, 25 insertions(+) (limited to 'src/corelib/io/qstandardpaths_mac.cpp') diff --git a/src/corelib/io/qstandardpaths_mac.cpp b/src/corelib/io/qstandardpaths_mac.cpp index 0efdfae253..aff9112fb7 100644 --- a/src/corelib/io/qstandardpaths_mac.cpp +++ b/src/corelib/io/qstandardpaths_mac.cpp @@ -47,6 +47,7 @@ #include #endif +#include #include QT_BEGIN_NAMESPACE @@ -184,6 +185,30 @@ QStringList QStandardPaths::standardLocations(StandardLocation type) dirs.append(path); } + if (type == DataLocation) { + CFBundleRef mainBundle = CFBundleGetMainBundle(); + if (mainBundle) { + CFURLRef bundleUrl = CFBundleCopyBundleURL(mainBundle); + CFStringRef cfBundlePath = CFURLCopyPath(bundleUrl); + QString bundlePath = QCFString::toQString(cfBundlePath); + CFRelease(cfBundlePath); + CFRelease(bundleUrl); + + CFURLRef resourcesUrl = CFBundleCopyResourcesDirectoryURL(mainBundle); + CFStringRef cfResourcesPath = CFURLCopyPath(bundleUrl); + QString resourcesPath = QCFString::toQString(cfResourcesPath); + CFRelease(cfResourcesPath); + CFRelease(resourcesUrl); + + // Handle bundled vs unbundled executables. CFBundleGetMainBundle() returns + // a valid bundle in both cases. CFBundleCopyResourcesDirectoryURL() returns + // an absolute path for unbundled executables. + if (resourcesPath.startsWith(QLatin1Char('/'))) + dirs.append(resourcesPath); + else + dirs.append(bundlePath + resourcesPath); + } + } const QString localDir = writableLocation(type); dirs.prepend(localDir); return dirs; -- cgit v1.2.3