Skip to content

Commit 3f3f8d1

Browse files
committed
XDG_CACHE_HOME support
1 parent ba03872 commit 3f3f8d1

File tree

3 files changed

+18
-2
lines changed

3 files changed

+18
-2
lines changed

qxdg/qxdgstandardpath.cpp

Lines changed: 14 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -30,13 +30,25 @@
3030
static QString xdgConfigHomeDir()
3131
{
3232
QString xdgConfigHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME"));
33+
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-0.8.html
3334
if (xdgConfigHome.isEmpty()) {
3435
xdgConfigHome = QDir::homePath() + QLatin1String("/.config");
3536
}
3637

3738
return xdgConfigHome;
3839
}
3940

41+
static QString xdgCacheHomeDir()
42+
{
43+
QString xdgCacheHome = QFile::decodeName(qgetenv("XDG_CACHE_HOME"));
44+
// https://specifications.freedesktop.org/basedir-spec/basedir-spec-0.8.html
45+
if (xdgCacheHome.isEmpty()) {
46+
xdgCacheHome = QDir::homePath() + QLatin1String("/.cache");
47+
}
48+
49+
return xdgCacheHome;
50+
}
51+
4052
static QStringList xdgConfigDirs()
4153
{
4254
QStringList dirs;
@@ -276,6 +288,8 @@ QStringList QXdgStandardPath::standardLocations(QXdgStandardPath::StandardLocati
276288
return xdgDataDirs();
277289
case XdgDataHomeLocation:
278290
return {xdgDataHomeDir()};
291+
case XdgCacheHomeLocation:
292+
return {xdgCacheHomeDir()};
279293
// xdg-user-dirs:
280294
case DesktopLocation:
281295
case DownloadLocation:

qxdg/qxdgstandardpath.h

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -48,6 +48,7 @@ class QXDGSHARED_EXPORT QXdgStandardPath
4848
XdgConfigDirsLocation,
4949
XdgDataDirsLocation,
5050
XdgDataHomeLocation,
51+
XdgCacheHomeLocation,
5152
// KDE Framework paths
5253
Kf5ServicesLocation,
5354
Kf5SoundLocation,

utils/main.cpp

Lines changed: 3 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -18,15 +18,16 @@ const QMap<QString, QPair<QXdgStandardPath::StandardLocation, QString>> pathType
1818
{"XDG_CONFIG_HOME", {QXdgStandardPath::XdgConfigHomeLocation, "Single base directory relative to which user-specific configuration files should be written, defined by basedir-spec."}},
1919
{"XDG_CONFIG_DIRS", {QXdgStandardPath::XdgConfigDirsLocation, "Set of preference ordered base directories relative to which configuration files should be searched, defined by basedir-spec."}},
2020
{"XDG_DATA_DIRS", {QXdgStandardPath::XdgDataDirsLocation, "set of preference ordered base directories relative to which data files should be searched, defined by basedir-spec."}},
21-
{"XDG_DATA_HOME", {QXdgStandardPath::XdgDataHomeLocation, "Single base directory relative to which user-specific data files should be written., defined by basedir-spec."}},
21+
{"XDG_DATA_HOME", {QXdgStandardPath::XdgDataHomeLocation, "Single base directory relative to which user-specific data files should be written, defined by basedir-spec."}},
22+
{"XDG_CACHE_HOME", {QXdgStandardPath::XdgCacheHomeLocation, "Defines the base directory relative to which user specific non-essential data files should be stored, defined by basedir-spec."}},
2223
{"KF5_SERVICES", {QXdgStandardPath::Kf5ServicesLocation, "(*) KDE Framework 5 services. (kf5-config --path services)"}}, // not part of XDG or FreeDesktop standard
2324
{"KF5_SOUND", {QXdgStandardPath::Kf5SoundLocation, "(*) KDE Framework 5 application sounds. (kf5-config --path sound)"}},
2425
{"KF5_TEMPLATES", {QXdgStandardPath::Kf5TemplatesLocation, "(*) KDE Framework 5 templates. (kf5-config --path templates)"}}
2526
};
2627

2728
const QStringList typesList = {
2829
"DESKTOP", "DOWNLOAD", "TEMPLATES", "PUBLICSHARE", "DOCUMENTS", "MUSIC", "PICTURES", "VIDEOS",
29-
"XDG_CONFIG_HOME", "XDG_CONFIG_DIRS", "XDG_DATA_DIRS", "XDG_DATA_HOME",
30+
"XDG_CONFIG_HOME", "XDG_CONFIG_DIRS", "XDG_DATA_DIRS", "XDG_DATA_HOME", "XDG_CACHE_HOME",
3031
"KF5_SERVICES", "KF5_SOUND", "KF5_TEMPLATES"
3132
};
3233

0 commit comments

Comments
 (0)