diff --git a/src/libs/utils/file.cpp b/src/libs/utils/file.cpp index 04195c367cf1b2e5d43fa7b23303de121621473a..459292abf14210ace0df70dde873e9e71612f6ca 100644 --- a/src/libs/utils/file.cpp +++ b/src/libs/utils/file.cpp @@ -12,6 +12,7 @@ #include "file.h" #include <QIODevice> +#include <QStandardPaths> #include <QDir> #include <QFile> #include <QFileInfo> @@ -19,14 +20,6 @@ namespace utils { -/** - * XDG Base Directory Specification - * http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html - * - * KDE System Administration/Environment Variables - * https://userbase.kde.org/KDE_System_Administration/Environment_Variables - */ - File::File(QObject *parent) : QObject(parent) {} @@ -45,35 +38,26 @@ QString File::homePath() return QDir::homePath(); } -QString File::xdgDataHomePath() +QString File::genericDataPath() { - QString path = QString::fromLocal8Bit(qgetenv("XDG_DATA_HOME").constData()); - if (path.isEmpty()) { - path = homePath() + "/.local/share"; - } - return path; + return QStandardPaths::writableLocation(QStandardPaths::GenericDataLocation); } -QString File::xdgConfigHomePath() +QString File::genericConfigPath() { - QString path = QString::fromLocal8Bit(qgetenv("XDG_CONFIG_HOME").constData()); - if (path.isEmpty()) { - path = homePath() + "/.config"; - } - return path; + return QStandardPaths::writableLocation(QStandardPaths::GenericConfigLocation); } -QString File::xdgCacheHomePath() +QString File::genericCachePath() { - QString path = QString::fromLocal8Bit(qgetenv("XDG_CACHE_HOME").constData()); - if (path.isEmpty()) { - path = homePath() + "/.cache"; - } - return path; + return QStandardPaths::writableLocation(QStandardPaths::GenericCacheLocation); } QString File::kdehomePath() { + // KDE System Administration/Environment Variables + // https://userbase.kde.org/KDE_System_Administration/Environment_Variables + // KDE 4 maybe uses $KDEHOME QString path = QString::fromLocal8Bit(qgetenv("KDEHOME").constData()); if (path.isEmpty()) { diff --git a/src/libs/utils/file.h b/src/libs/utils/file.h index 01cf4d6b21764f6666a9cdcbfa5710e77c662447..0ec6548a0c14fb4efe3d616e31fa80c57666ef90 100644 --- a/src/libs/utils/file.h +++ b/src/libs/utils/file.h @@ -28,9 +28,9 @@ public: static QString rootPath(); static QString tempPath(); static QString homePath(); - static QString xdgDataHomePath(); - static QString xdgConfigHomePath(); - static QString xdgCacheHomePath(); + static QString genericDataPath(); + static QString genericConfigPath(); + static QString genericCachePath(); static QString kdehomePath(); static QFileInfoList readDir(const QString &path); static bool makeDir(const QString &path);