forked from lxqt/libqtxdg
-
Notifications
You must be signed in to change notification settings - Fork 1
/
xdgdirs.h
158 lines (134 loc) · 6.04 KB
/
xdgdirs.h
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
/* BEGIN_COMMON_COPYRIGHT_HEADER
* (c)LGPL2+
*
* Razor - a lightweight, Qt based, desktop toolset
* http://razor-qt.org
*
* Copyright: 2010-2011 Razor team
* Authors:
* Alexander Sokoloff <[email protected]>
*
* This program or library is free software; you can redistribute it
* and/or modify it under the terms of the GNU Lesser General Public
* License as published by the Free Software Foundation; either
* version 2.1 of the License, or (at your option) any later version.
*
* This library is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
* Lesser General Public License for more details.
* You should have received a copy of the GNU Lesser General
* Public License along with this library; if not, write to the
* Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor,
* Boston, MA 02110-1301 USA
*
* END_COMMON_COPYRIGHT_HEADER */
#ifndef QTXDG_XDGDIRS_H
#define QTXDG_XDGDIRS_H
#include <QString>
#include <QStringList>
/*! @brief The XdgMenu class implements the "XDG Base Directory Specification" from freedesktop.org.
* This specification defines where these files should be looked for by defining one or more base
* directories relative to which files should be located.
*
* @sa http://standards.freedesktop.org/basedir-spec/basedir-spec-latest.html
*/
static const QString userDirectoryString[8] =
{
"Desktop",
"Download",
"Templates",
"Publicshare",
"Documents",
"Music",
"Pictures",
"Videos"
};
class XdgDirs
{
public:
enum UserDirectory
{
Desktop,
Download,
Templates,
PublicShare,
Documents,
Music,
Pictures,
Videos
};
/*! @brief Returns the path to the user folder passed as parameter dir defined in
* $XDG_CONFIG_HOME/user-dirs.dirs. Returns /tmp if no $HOME defined, $HOME/Desktop if
* dir equals XdgDirs::Desktop or $HOME othewise.
*/
static QString userDir(UserDirectory dir);
/*! @brief Returns true if writting into configuration file $XDG_CONFIG_HOME/user-dirs.dirs
* the path in value for the directory in dir is succesfull. Returns false otherwise. If
* createDir is true, dir will be created if it doesn't exist.
*/
static bool setUserDir(UserDirectory dir, const QString &value, bool createDir);
/*! @brief Returns the path to the directory that corresponds to the $XDG_DATA_HOME.
* If @i createDir is true, the function will create the directory.
*
* $XDG_DATA_HOME defines the base directory relative to which user specific data files
* should be stored. If $XDG_DATA_HOME is either not set or empty, a default equal to
* $HOME/.local/share should be used.
*/
static QString dataHome(bool createDir=true);
/*! @brief Returns the path to the directory that corresponds to the $XDG_CONFIG_HOME.
* If @i createDir is true, the function will create the directory.
*
* $XDG_CONFIG_HOME defines the base directory relative to which user specific configuration
* files should be stored. If $XDG_CONFIG_HOME is either not set or empty, a default equal
* to $HOME/.config should be used.
*/
static QString configHome(bool createDir=true);
/*! @brief Returns a list of all directories that corresponds to the $XDG_DATA_DIRS.
* $XDG_DATA_DIRS defines the preference-ordered set of base directories to search for data
* files in addition to the $XDG_DATA_HOME base directory. If $XDG_DATA_DIRS is either not set
* or empty, a value equal to /usr/local/share/:/usr/share/ should be used.
*
* If the postfix is not empty it will append to end of each returned directory.
*/
static QStringList dataDirs(const QString &postfix = "");
/*! @brief Returns a list of all directories that corresponds to the $XDG_CONFIG_DIRS.
* $XDG_CONFIG_DIRS defines the preference-ordered set of base directories to search for
* configuration files in addition to the $XDG_CONFIG_HOME base directory. If $XDG_CONFIG_DIRS
* is either not set or empty, a value equal to /etc/xdg should be used.
*
* If the postfix is not empty it will append to end of each returned directory.
*/
static QStringList configDirs(const QString &postfix = "");
/*! @brief Returns the path to the directory that corresponds to the $XDG_CACHE_HOME.
* If @i createDir is true, the function will create the directory.
*
* $XDG_CACHE_HOME defines the base directory relative to which user specific non-essential
* data files should be stored. If $XDG_CACHE_HOME is either not set or empty,
* a default equal to $HOME/.cache should be used.
*/
static QString cacheHome(bool createDir=true);
/*! @brief Returns the path to the directory that corresponds to the $XDG_RUNTIME_DIR.
* $XDG_RUNTIME_DIR defines the base directory relative to which user-specific non-essential
* runtime files and other file objects (such as sockets, named pipes, ...) should be stored.
* The directory MUST be owned by the user, and he MUST be the only one having read and write
* access to it. Its Unix access mode MUST be 0700.
*/
static QString runtimeDir();
/*! @brief Returns the path to the directory that corresponds to the $XDG_CONFIG_HOME/autostart
*
* If $XDG_CONFIG_HOME is not set, the Autostart Directory in the user's home directory is
* ~/.config/autostart/
*/
static QString autostartHome(bool createDir=true);
/*! @brief Returns a list of all directories that correspond to $XDG_CONFIG_DIRS/autostart
* If $XDG_CONFIG_DIRS is not set, the system wide Autostart Directory is /etc/xdg/autostart
*
* If the postfix is not empty it will append to end of each returned directory.
*
* Note: this does not include the user's autostart directory
* @sa autostartHome()
*/
static QStringList autostartDirs(const QString &postfix = "");
};
#endif // QTXDG_XDGDIRS_H