diff options
author | Jonathan Ketchker <iontankatchker@gmail.com> | 2023-08-27 12:45:04 +0300 |
---|---|---|
committer | Jonathan Ketchker <iontankatchker@gmail.com> | 2023-09-07 01:17:13 +0300 |
commit | 55f0738f1638356137e6bd60459dc186ceaaabd8 (patch) | |
tree | 6d60bde37dab7ce24e32fb81145254d09e6c65a1 /src/corelib/io/qstandardpaths_unix.cpp | |
parent | 505ed52cd4dcef081d9868424057451bd1dce497 (diff) |
Add StateLocation & GenericStateLocation to StandardLocation
The latest XDG spec (0.8) defines XDG_STATE_HOME that does not exist
in QStandardPaths::StandardLocation.
Some Linux distributions clean XDG_CACHE_HOME on restart which makes
XDG_STATE_HOME useful as a path for saving application state.
This commit adds StateLocation and GenericStateLocation to serve as a
StandardLocation for XDG_STATE_HOME for all platforms.
This commit also updates docs and tests to fit the new changes.
[ChangeLog][QStandardPaths] Added StateLocation &
GenericStateLocation to StandardLocation
Change-Id: I470602466c37f085062cc64d15ea243711728fa5
Reviewed-by: David Faure <david.faure@kdab.com>
Reviewed-by: Qt CI Bot <qt_ci_bot@qt-project.org>
Reviewed-by: Thiago Macieira <thiago.macieira@intel.com>
Diffstat (limited to 'src/corelib/io/qstandardpaths_unix.cpp')
-rw-r--r-- | src/corelib/io/qstandardpaths_unix.cpp | 19 |
1 files changed, 19 insertions, 0 deletions
diff --git a/src/corelib/io/qstandardpaths_unix.cpp b/src/corelib/io/qstandardpaths_unix.cpp index 64d8a3fa49..e38f670895 100644 --- a/src/corelib/io/qstandardpaths_unix.cpp +++ b/src/corelib/io/qstandardpaths_unix.cpp @@ -196,6 +196,25 @@ QString QStandardPaths::writableLocation(StandardLocation type) 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: |