| 1 |
// SPDX-FileCopyrightText: 2017 - 2022 UnionTech Software Technology Co., Ltd. |
| 2 |
// |
| 3 |
// SPDX-License-Identifier: LGPL-3.0-or-later |
| 4 |
|
| 5 |
#ifndef DTK_CORE_FILESYSTEM_DSTANDARDPATHS_H |
| 6 |
#define DTK_CORE_FILESYSTEM_DSTANDARDPATHS_H |
| 7 |
|
| 8 |
#include <QStandardPaths> |
| 9 |
|
| 10 |
#include "dtkcore_global.h" |
| 11 |
|
| 12 |
DCORE_BEGIN_NAMESPACE |
| 13 |
|
| 14 |
class DStandardPathsPrivate; |
| 15 |
class LIBDTKCORESHARED_EXPORT DStandardPaths |
| 16 |
{ |
| 17 |
public: |
| 18 |
enum Mode { |
| 19 |
Auto, |
| 20 |
Snap, |
| 21 |
Test, |
| 22 |
}; |
| 23 |
|
| 24 |
static QString writableLocation(QStandardPaths::StandardLocation type); |
| 25 |
static QStringList standardLocations(QStandardPaths::StandardLocation type); |
| 26 |
|
| 27 |
static QString locate(QStandardPaths::StandardLocation type, const QString &fileName, QStandardPaths::LocateOptions options = QStandardPaths::LocateFile); |
| 28 |
static QStringList locateAll(QStandardPaths::StandardLocation type, const QString &fileName, QStandardPaths::LocateOptions options = QStandardPaths::LocateFile); |
| 29 |
static QString findExecutable(const QString &executableName, const QStringList &paths = QStringList()); |
| 30 |
static void setMode(Mode mode); |
| 31 |
|
| 32 |
/** |
| 33 |
* @brief About XDG dir, view it in https://gitlab.freedesktop.org/xdg/xdg-specs/ |
| 34 |
*/ |
| 35 |
enum class XDG { |
| 36 |
/* |
| 37 |
* @brief DataHome, usually is ~/.local/share, also can be defined by ${XDG_DATA_HOME}, where stores the data of applications |
| 38 |
*/ |
| 39 |
DataHome, |
| 40 |
/* |
| 41 |
* @brief ConfigHome, usually is ~/.config, can be defined by ${XDG_CONFIG_HOME}, where stores the config of applications |
| 42 |
*/ |
| 43 |
ConfigHome, |
| 44 |
/* |
| 45 |
* @brief CacheHome, usually is ~/.cache, can be defined by ${XDG_CACHE_HOME}, where stores caches, can be always cleared |
| 46 |
*/ |
| 47 |
CacheHome, |
| 48 |
/* |
| 49 |
* @brief Where temp files or sock files always be put in, like sddm.sock. It is unique per session. It is /run/user/${uid} or ${XDG_RUNTIME_DIR}, |
| 50 |
*/ |
| 51 |
RuntimeDir, |
| 52 |
#if DTK_VERSION < DTK_VERSION_CHECK(6, 0, 0, 0) |
| 53 |
RuntimeTime [[deprecated("Use RuntimeDir Instead")]] = RuntimeDir, |
| 54 |
#endif |
| 55 |
/* |
| 56 |
* @brief where history file and state file should be. It is induced because users do not want to mix their config files and state files. It is always ~/.local/state, or defined by ${XDG_STATE_HOME} |
| 57 |
*/ |
| 58 |
StateHome |
| 59 |
}; |
| 60 |
|
| 61 |
enum class DSG { |
| 62 |
AppData, |
| 63 |
DataDir |
| 64 |
}; |
| 65 |
|
| 66 |
static QString homePath(); |
| 67 |
static QString homePath(const uint uid); |
| 68 |
/* |
| 69 |
* @brief Get the XDG dir path by XDG type |
| 70 |
*/ |
| 71 |
static QString path(XDG type); |
| 72 |
static QString path(DSG type); |
| 73 |
static QStringList paths(DSG type); |
| 74 |
static QString filePath(XDG type, QString fileName); |
| 75 |
static QString filePath(DSG type, QString fileName); |
| 76 |
|
| 77 |
private: |
| 78 |
DStandardPaths(); |
| 79 |
~DStandardPaths(); |
| 80 |
Q_DISABLE_COPY(DStandardPaths) |
| 81 |
}; |
| 82 |
|
| 83 |
DCORE_END_NAMESPACE |
| 84 |
|
| 85 |
#endif // DTK_CORE_FILESYSTEM_DSTANDARDPATHS_H |