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 <thiago.macieira@intel.com> Reviewed-by: David Faure <david.faure@kdab.com>
This commit is contained in:
parent
16a26931d4
commit
2fac63c76d
@ -177,8 +177,8 @@ QT_BEGIN_NAMESPACE
|
||||
\li "~"
|
||||
\li "C:/Users/<USER>"
|
||||
\row \li DataLocation
|
||||
\li "~/Library/Application Support/<APPNAME>", "/Library/Application Support/<APPNAME>"
|
||||
\li "C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>"
|
||||
\li "~/Library/Application Support/<APPNAME>", "/Library/Application Support/<APPNAME>". "<APPDIR>/../Resources"
|
||||
\li "C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>", "<APPDIR>", "<APPDIR>/data"
|
||||
\row \li CacheLocation
|
||||
\li "~/Library/Caches/<APPNAME>", "/Library/Caches/<APPNAME>"
|
||||
\li "C:/Users/<USER>/AppData/Local/<APPNAME>/cache"
|
||||
@ -232,7 +232,7 @@ QT_BEGIN_NAMESPACE
|
||||
\li "<APPROOT>/data"
|
||||
\li "~"
|
||||
\row \li DataLocation
|
||||
\li "<APPROOT>/data"
|
||||
\li "<APPROOT>/data", "<APPROOT>/app/native/assets"
|
||||
\li "~/.local/share/<APPNAME>", "/usr/local/share/<APPNAME>", "/usr/share/<APPNAME>"
|
||||
\row \li CacheLocation
|
||||
\li "<APPROOT>/data/Cache"
|
||||
@ -260,7 +260,8 @@ QT_BEGIN_NAMESPACE
|
||||
In the table above, \c <APPNAME> is usually the organization name, the
|
||||
application name, or both, or a unique name generated at packaging.
|
||||
Similarly, <APPROOT> is the location where this application is installed
|
||||
(often a sandbox).
|
||||
(often a sandbox). <APPDIR> is the directory containing the application
|
||||
executable.
|
||||
|
||||
The paths above should not be relied upon, as they may change according to
|
||||
OS configuration, locale, or they may change in future Qt versions.
|
||||
|
@ -103,10 +103,17 @@ QString QStandardPaths::writableLocation(StandardLocation type)
|
||||
|
||||
QStringList QStandardPaths::standardLocations(StandardLocation type)
|
||||
{
|
||||
QStringList dirs;
|
||||
|
||||
if (type == FontsLocation)
|
||||
return QStringList(QLatin1String("/base/usr/fonts"));
|
||||
|
||||
return QStringList(writableLocation(type));
|
||||
if (type == DataLocation)
|
||||
dirs.append(QDir::homePath() + testModeInsert() + QLatin1String("native/assets"));
|
||||
|
||||
const QString localDir = writableLocation(type);
|
||||
dirs.prepend(localDir);
|
||||
return dirs;
|
||||
}
|
||||
|
||||
QT_END_NAMESPACE
|
||||
|
@ -47,6 +47,7 @@
|
||||
#include <qcoreapplication.h>
|
||||
#endif
|
||||
|
||||
#include <CoreFoundation/CoreFoundation.h>
|
||||
#include <ApplicationServices/ApplicationServices.h>
|
||||
|
||||
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;
|
||||
|
@ -204,6 +204,12 @@ QStringList QStandardPaths::standardLocations(StandardLocation type)
|
||||
#endif
|
||||
}
|
||||
dirs.append(result);
|
||||
#ifndef QT_BOOTSTRAPPED
|
||||
if (type != GenericDataLocation) {
|
||||
dirs.append(QCoreApplication::applicationDirPath());
|
||||
dirs.append(QCoreApplication::applicationDirPath() + QLatin1String("/data"));
|
||||
}
|
||||
#endif
|
||||
}
|
||||
break;
|
||||
default:
|
||||
|
Loading…
Reference in New Issue
Block a user