From c88a95f8b527d670084f3e3b40b51dbcd9867a6a Mon Sep 17 00:00:00 2001 From: Akira Ohgaki <akiraohgaki@gmail.com> Date: Thu, 27 Oct 2016 04:36:53 +0900 Subject: [PATCH] Update library --- src/libs/utils/file.cpp | 36 ++++++++++-------------------------- src/libs/utils/file.h | 6 +++--- 2 files changed, 13 insertions(+), 29 deletions(-) diff --git a/src/libs/utils/file.cpp b/src/libs/utils/file.cpp index 04195c3..459292a 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 01cf4d6..0ec6548 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); -- GitLab