DtkCore
DTK Core module
载入中...
搜索中...
未找到
dstandardpaths.h
浏览该文件的文档.
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
12DCORE_BEGIN_NAMESPACE
13
14class DStandardPathsPrivate;
15class LIBDTKCORESHARED_EXPORT DStandardPaths
16{
17public:
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
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
77private:
80 Q_DISABLE_COPY(DStandardPaths)
81};
82
83DCORE_END_NAMESPACE
84
85#endif // DTK_CORE_FILESYSTEM_DSTANDARDPATHS_H
Definition dstandardpaths.h:16
static QString findExecutable(const QString &executableName, const QStringList &paths=QStringList())
同QStandardPaths::findExecutable, 查找可执行文件
static QString homePath(const uint uid)
用uid返回家目录
static QString homePath()
返回家目录
static QString writableLocation(QStandardPaths::StandardLocation type)
DStandardPaths提供兼容Snap/Dtk标准的路径模式。DStandardPaths实现了Qt的QStandardPaths主要接口。此处返回可写路径
static void setMode(Mode mode)
同QStandardPaths::setTestModeEnabled, 设置是否是测试模式
static QStringList standardLocations(QStandardPaths::StandardLocation type)
DStandardPaths提供兼容Snap/Dtk标准的路径模式。DStandardPaths实现了Qt的QStandardPaths主要接口。此处返回所有Standardpath
static QString locate(QStandardPaths::StandardLocation type, const QString &fileName, QStandardPaths::LocateOptions options=QStandardPaths::LocateFile)
在 type 的标准位置查找名为 fileName 的文件或目录。选项标志允许您指定是否查找文件或目录。默认情况下,此标志设置为 LocateFile。返回找到的第一个文件或目录的绝对路径,否则返回空字...
static QStringList paths(DSG type)
返回所有DSG下所有目录
static QStringList locateAll(QStandardPaths::StandardLocation type, const QString &fileName, QStandardPaths::LocateOptions options=QStandardPaths::LocateFile)
在类型的标准位置中按名称 fileName 查找所有文件或目录。选项标志允许您指定是否查找文件或目录。默认情况下,此标志设置为 LocateFile。返回找到的所有文件的列表。
XDG
About XDG dir, view it in https://gitlab.freedesktop.org/xdg/xdg-specs/
Definition dstandardpaths.h:35