summaryrefslogtreecommitdiffstats
path: root/src/corelib
diff options
context:
space:
mode:
authorDavid Faure <faure@kde.org>2012-03-15 12:05:58 +0100
committerQt by Nokia <qt-info@nokia.com>2012-03-22 13:29:27 +0100
commit5ec5ce354904d35c013512a1d38c24502e298657 (patch)
treef71e43042a41f808f0dc6b17d5910a679aa40398 /src/corelib
parent8445c5ede7f5b48f5074d2754abcc14b85196f39 (diff)
Return all expected paths in QStandardPaths::standardLocations
ApplicationsLocation and DataLocation were returning only the local path, rather than system paths + local path. Change-Id: I653d14e5bbe1e08c5fa1ecd5a6106336d1cd0369 Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib')
-rw-r--r--src/corelib/io/qstandardpaths_unix.cpp71
1 files changed, 49 insertions, 22 deletions
diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp
index 5499751751..b27b19eac9 100644
--- a/src/corelib/io/qstandardpaths_unix.cpp
+++ b/src/corelib/io/qstandardpaths_unix.cpp
@@ -53,6 +53,16 @@
QT_BEGIN_NAMESPACE
+static void appendOrganizationAndApp(QString &path)
+{
+ const QString org = QCoreApplication::organizationName();
+ if (!org.isEmpty())
+ path += QLatin1Char('/') + org;
+ const QString appName = QCoreApplication::applicationName();
+ if (!appName.isEmpty())
+ path += QLatin1Char('/') + appName;
+}
+
QString QStandardPaths::writableLocation(StandardLocation type)
{
switch (type) {
@@ -67,12 +77,8 @@ QString QStandardPaths::writableLocation(StandardLocation type)
QString xdgCacheHome = QFile::decodeName(qgetenv("XDG_CACHE_HOME"));
if (xdgCacheHome.isEmpty())
xdgCacheHome = QDir::homePath() + QLatin1String("/.cache");
- if (type == QStandardPaths::CacheLocation) {
- if (!QCoreApplication::organizationName().isEmpty())
- xdgCacheHome += QLatin1Char('/') + QCoreApplication::organizationName();
- if (!QCoreApplication::applicationName().isEmpty())
- xdgCacheHome += QLatin1Char('/') + QCoreApplication::applicationName();
- }
+ if (type == QStandardPaths::CacheLocation)
+ appendOrganizationAndApp(xdgCacheHome);
return xdgCacheHome;
}
case DataLocation:
@@ -81,12 +87,8 @@ QString QStandardPaths::writableLocation(StandardLocation type)
QString xdgDataHome = QFile::decodeName(qgetenv("XDG_DATA_HOME"));
if (xdgDataHome.isEmpty())
xdgDataHome = QDir::homePath() + QLatin1String("/.local/share");
- if (type == QStandardPaths::DataLocation) {
- if (!QCoreApplication::organizationName().isEmpty())
- xdgDataHome += QLatin1Char('/') + QCoreApplication::organizationName();
- if (!QCoreApplication::applicationName().isEmpty())
- xdgDataHome += QLatin1Char('/') + QCoreApplication::applicationName();
- }
+ if (type == QStandardPaths::DataLocation)
+ appendOrganizationAndApp(xdgDataHome);
return xdgDataHome;
}
case ConfigLocation:
@@ -229,24 +231,49 @@ QString QStandardPaths::writableLocation(StandardLocation type)
return path;
}
+static QStringList xdgDataDirs()
+{
+ QStringList dirs;
+ // http://standards.freedesktop.org/basedir-spec/latest/
+ QString xdgDataDirsEnv = QFile::decodeName(qgetenv("XDG_DATA_DIRS"));
+ if (xdgDataDirsEnv.isEmpty()) {
+ dirs.append(QString::fromLatin1("/usr/local/share"));
+ dirs.append(QString::fromLatin1("/usr/share"));
+ } else {
+ dirs = xdgDataDirsEnv.split(QLatin1Char(':'));
+ }
+ return dirs;
+}
+
QStringList QStandardPaths::standardLocations(StandardLocation type)
{
QStringList dirs;
- if (type == ConfigLocation) {
+ switch (type) {
+ case ConfigLocation:
+ {
// http://standards.freedesktop.org/basedir-spec/latest/
- QString xdgConfigDirs = QFile::decodeName(qgetenv("XDG_CONFIG_DIRS"));
+ const QString xdgConfigDirs = QFile::decodeName(qgetenv("XDG_CONFIG_DIRS"));
if (xdgConfigDirs.isEmpty())
dirs.append(QString::fromLatin1("/etc/xdg"));
else
dirs = xdgConfigDirs.split(QLatin1Char(':'));
- } else if (type == GenericDataLocation) {
- // http://standards.freedesktop.org/basedir-spec/latest/
- QString xdgConfigDirs = QFile::decodeName(qgetenv("XDG_DATA_DIRS"));
- if (xdgConfigDirs.isEmpty()) {
- dirs.append(QString::fromLatin1("/usr/local/share"));
- dirs.append(QString::fromLatin1("/usr/share"));
- } else
- dirs = xdgConfigDirs.split(QLatin1Char(':'));
+ }
+ break;
+ case GenericDataLocation:
+ dirs = xdgDataDirs();
+ break;
+ case ApplicationsLocation:
+ dirs = xdgDataDirs();
+ for (int i = 0; i < dirs.count(); ++i)
+ dirs[i].append(QLatin1String("/applications"));
+ break;
+ case DataLocation:
+ dirs = xdgDataDirs();
+ for (int i = 0; i < dirs.count(); ++i)
+ appendOrganizationAndApp(dirs[i]);
+ break;
+ default:
+ break;
}
const QString localDir = writableLocation(type);
dirs.prepend(localDir);