summaryrefslogtreecommitdiffstats
path: root/src/corelib/io/qstandardpaths_unix.cpp
diff options
context:
space:
mode:
Diffstat (limited to 'src/corelib/io/qstandardpaths_unix.cpp')
-rw-r--r--src/corelib/io/qstandardpaths_unix.cpp89
1 files changed, 57 insertions, 32 deletions
diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp
index 55150f9e93..e38f670895 100644
--- a/src/corelib/io/qstandardpaths_unix.cpp
+++ b/src/corelib/io/qstandardpaths_unix.cpp
@@ -180,33 +180,56 @@ QString QStandardPaths::writableLocation(StandardLocation type)
case CacheLocation:
case GenericCacheLocation:
{
- if (isTestModeEnabled())
- return QDir::homePath() + "/.qttest/cache"_L1;
-
- // http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
- QString xdgCacheHome = QFile::decodeName(qgetenv("XDG_CACHE_HOME"));
- if (!xdgCacheHome.startsWith(u'/'))
- xdgCacheHome.clear(); // spec says relative paths should be ignored
-
- if (xdgCacheHome.isEmpty())
- xdgCacheHome = QDir::homePath() + "/.cache"_L1;
+ QString xdgCacheHome;
+ if (isTestModeEnabled()) {
+ xdgCacheHome = QDir::homePath() + "/.qttest/cache"_L1;
+ } else {
+ // http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html
+ xdgCacheHome = QFile::decodeName(qgetenv("XDG_CACHE_HOME"));
+ if (!xdgCacheHome.startsWith(u'/'))
+ xdgCacheHome.clear(); // spec says relative paths should be ignored
+
+ if (xdgCacheHome.isEmpty())
+ xdgCacheHome = QDir::homePath() + "/.cache"_L1;
+ }
if (type == QStandardPaths::CacheLocation)
appendOrganizationAndApp(xdgCacheHome);
return xdgCacheHome;
}
+ case StateLocation:
+ case GenericStateLocation:
+ {
+ QString xdgStateHome;
+ if (isTestModeEnabled()) {
+ xdgStateHome = QDir::homePath() + "/.qttest/state"_L1;
+ } else {
+ // http://standards.freedesktop.org/basedir-spec/basedir-spec-0.8.html
+ xdgStateHome = QFile::decodeName(qgetenv("XDG_STATE_HOME"));
+ if (!xdgStateHome.startsWith(u'/'))
+ xdgStateHome.clear(); // spec says relative paths should be ignored
+
+ if (xdgStateHome.isEmpty())
+ xdgStateHome = QDir::homePath() + "/.local/state"_L1;
+ }
+ if (type == QStandardPaths::StateLocation)
+ appendOrganizationAndApp(xdgStateHome);
+ return xdgStateHome;
+ }
case AppDataLocation:
case AppLocalDataLocation:
case GenericDataLocation:
{
- if (isTestModeEnabled())
- return QDir::homePath() + "/.qttest/share"_L1;
-
- QString xdgDataHome = QFile::decodeName(qgetenv("XDG_DATA_HOME"));
- if (!xdgDataHome.startsWith(u'/'))
- xdgDataHome.clear(); // spec says relative paths should be ignored
-
- if (xdgDataHome.isEmpty())
- xdgDataHome = QDir::homePath() + "/.local/share"_L1;
+ QString xdgDataHome;
+ if (isTestModeEnabled()) {
+ xdgDataHome = QDir::homePath() + "/.qttest/share"_L1;
+ } else {
+ xdgDataHome = QFile::decodeName(qgetenv("XDG_DATA_HOME"));
+ if (!xdgDataHome.startsWith(u'/'))
+ xdgDataHome.clear(); // spec says relative paths should be ignored
+
+ if (xdgDataHome.isEmpty())
+ xdgDataHome = QDir::homePath() + "/.local/share"_L1;
+ }
if (type == AppDataLocation || type == AppLocalDataLocation)
appendOrganizationAndApp(xdgDataHome);
return xdgDataHome;
@@ -215,16 +238,18 @@ QString QStandardPaths::writableLocation(StandardLocation type)
case GenericConfigLocation:
case AppConfigLocation:
{
- if (isTestModeEnabled())
- return QDir::homePath() + "/.qttest/config"_L1;
-
- // http://standards.freedesktop.org/basedir-spec/latest/
- QString xdgConfigHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME"));
- if (!xdgConfigHome.startsWith(u'/'))
- xdgConfigHome.clear(); // spec says relative paths should be ignored
-
- if (xdgConfigHome.isEmpty())
- xdgConfigHome = QDir::homePath() + "/.config"_L1;
+ QString xdgConfigHome;
+ if (isTestModeEnabled()) {
+ xdgConfigHome = QDir::homePath() + "/.qttest/config"_L1;
+ } else {
+ // http://standards.freedesktop.org/basedir-spec/latest/
+ xdgConfigHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME"));
+ if (!xdgConfigHome.startsWith(u'/'))
+ xdgConfigHome.clear(); // spec says relative paths should be ignored
+
+ if (xdgConfigHome.isEmpty())
+ xdgConfigHome = QDir::homePath() + "/.config"_L1;
+ }
if (type == AppConfigLocation)
appendOrganizationAndApp(xdgConfigHome);
return xdgConfigHome;
@@ -351,9 +376,9 @@ static QStringList dirsList(const QString &xdgEnvVar)
if (dir.startsWith(u'/'))
dirs.push_back(QDir::cleanPath(dir.toString()));
- // Remove duplicates from the list, there's no use for duplicated
- // paths in XDG_DATA_DIRS - if it's not found in the given
- // directory the first time, it won't be there the second time.
+ // Remove duplicates from the list, there's no use for duplicated paths
+ // in XDG_* env vars - if whatever is being looked for is not found in
+ // the given directory the first time, it won't be there the second time.
// Plus duplicate paths causes problems for example for mimetypes,
// where duplicate paths here lead to duplicated mime types returned
// for a file, eg "text/plain,text/plain" instead of "text/plain"