Absolute File Name: | /home/qt/qt5_coco/qt5/qtbase/src/corelib/io/qstandardpaths_unix.cpp |
Source code | Switch to Preprocessed file |
Line | Source | Count | ||||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|---|---|
1 | /**************************************************************************** | - | ||||||||||||
2 | ** | - | ||||||||||||
3 | ** Copyright (C) 2016 The Qt Company Ltd. | - | ||||||||||||
4 | ** Contact: https://www.qt.io/licensing/ | - | ||||||||||||
5 | ** | - | ||||||||||||
6 | ** This file is part of the QtCore module of the Qt Toolkit. | - | ||||||||||||
7 | ** | - | ||||||||||||
8 | ** $QT_BEGIN_LICENSE:LGPL$ | - | ||||||||||||
9 | ** Commercial License Usage | - | ||||||||||||
10 | ** Licensees holding valid commercial Qt licenses may use this file in | - | ||||||||||||
11 | ** accordance with the commercial license agreement provided with the | - | ||||||||||||
12 | ** Software or, alternatively, in accordance with the terms contained in | - | ||||||||||||
13 | ** a written agreement between you and The Qt Company. For licensing terms | - | ||||||||||||
14 | ** and conditions see https://www.qt.io/terms-conditions. For further | - | ||||||||||||
15 | ** information use the contact form at https://www.qt.io/contact-us. | - | ||||||||||||
16 | ** | - | ||||||||||||
17 | ** GNU Lesser General Public License Usage | - | ||||||||||||
18 | ** Alternatively, this file may be used under the terms of the GNU Lesser | - | ||||||||||||
19 | ** General Public License version 3 as published by the Free Software | - | ||||||||||||
20 | ** Foundation and appearing in the file LICENSE.LGPL3 included in the | - | ||||||||||||
21 | ** packaging of this file. Please review the following information to | - | ||||||||||||
22 | ** ensure the GNU Lesser General Public License version 3 requirements | - | ||||||||||||
23 | ** will be met: https://www.gnu.org/licenses/lgpl-3.0.html. | - | ||||||||||||
24 | ** | - | ||||||||||||
25 | ** GNU General Public License Usage | - | ||||||||||||
26 | ** Alternatively, this file may be used under the terms of the GNU | - | ||||||||||||
27 | ** General Public License version 2.0 or (at your option) the GNU General | - | ||||||||||||
28 | ** Public license version 3 or any later version approved by the KDE Free | - | ||||||||||||
29 | ** Qt Foundation. The licenses are as published by the Free Software | - | ||||||||||||
30 | ** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3 | - | ||||||||||||
31 | ** included in the packaging of this file. Please review the following | - | ||||||||||||
32 | ** information to ensure the GNU General Public License requirements will | - | ||||||||||||
33 | ** be met: https://www.gnu.org/licenses/gpl-2.0.html and | - | ||||||||||||
34 | ** https://www.gnu.org/licenses/gpl-3.0.html. | - | ||||||||||||
35 | ** | - | ||||||||||||
36 | ** $QT_END_LICENSE$ | - | ||||||||||||
37 | ** | - | ||||||||||||
38 | ****************************************************************************/ | - | ||||||||||||
39 | - | |||||||||||||
40 | #include "qstandardpaths.h" | - | ||||||||||||
41 | #include <qdir.h> | - | ||||||||||||
42 | #include <qfile.h> | - | ||||||||||||
43 | #include <qhash.h> | - | ||||||||||||
44 | #include <qtextstream.h> | - | ||||||||||||
45 | #include <private/qfilesystemengine_p.h> | - | ||||||||||||
46 | #include <errno.h> | - | ||||||||||||
47 | #include <stdlib.h> | - | ||||||||||||
48 | - | |||||||||||||
49 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||
50 | #include <qcoreapplication.h> | - | ||||||||||||
51 | #endif | - | ||||||||||||
52 | - | |||||||||||||
53 | #ifndef QT_NO_STANDARDPATHS | - | ||||||||||||
54 | - | |||||||||||||
55 | QT_BEGIN_NAMESPACE | - | ||||||||||||
56 | - | |||||||||||||
57 | static void appendOrganizationAndApp(QString &path) | - | ||||||||||||
58 | { | - | ||||||||||||
59 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||
60 | const QString org = QCoreApplication::organizationName(); | - | ||||||||||||
61 | if (!org.isEmpty())
| 8-30 | ||||||||||||
62 | path += QLatin1Char('/') + org; executed 8 times by 1 test: path += QLatin1Char('/') + org; Executed by:
| 8 | ||||||||||||
63 | const QString appName = QCoreApplication::applicationName(); | - | ||||||||||||
64 | if (!appName.isEmpty())
| 0-38 | ||||||||||||
65 | path += QLatin1Char('/') + appName; executed 38 times by 1 test: path += QLatin1Char('/') + appName; Executed by:
| 38 | ||||||||||||
66 | #else | - | ||||||||||||
67 | Q_UNUSED(path); | - | ||||||||||||
68 | #endif | - | ||||||||||||
69 | } executed 38 times by 1 test: end of block Executed by:
| 38 | ||||||||||||
70 | - | |||||||||||||
71 | QString QStandardPaths::writableLocation(StandardLocation type) | - | ||||||||||||
72 | { | - | ||||||||||||
73 | switch (type) { | - | ||||||||||||
74 | case HomeLocation: executed 5 times by 1 test: case HomeLocation: Executed by:
| 5 | ||||||||||||
75 | return QDir::homePath(); executed 5 times by 1 test: return QDir::homePath(); Executed by:
| 5 | ||||||||||||
76 | case TempLocation: executed 5 times by 1 test: case TempLocation: Executed by:
| 5 | ||||||||||||
77 | return QDir::tempPath(); executed 5 times by 1 test: return QDir::tempPath(); Executed by:
| 5 | ||||||||||||
78 | case CacheLocation: executed 6 times by 1 test: case CacheLocation: Executed by:
| 6 | ||||||||||||
79 | case GenericCacheLocation: executed 8 times by 1 test: case GenericCacheLocation: Executed by:
| 8 | ||||||||||||
80 | { | - | ||||||||||||
81 | // http://standards.freedesktop.org/basedir-spec/basedir-spec-0.6.html | - | ||||||||||||
82 | QString xdgCacheHome = QFile::decodeName(qgetenv("XDG_CACHE_HOME")); | - | ||||||||||||
83 | if (isTestModeEnabled())
| 4-10 | ||||||||||||
84 | xdgCacheHome = QDir::homePath() + QLatin1String("/.qttest/cache"); executed 4 times by 1 test: xdgCacheHome = QDir::homePath() + QLatin1String("/.qttest/cache"); Executed by:
| 4 | ||||||||||||
85 | if (xdgCacheHome.isEmpty())
| 4-10 | ||||||||||||
86 | xdgCacheHome = QDir::homePath() + QLatin1String("/.cache"); executed 10 times by 1 test: xdgCacheHome = QDir::homePath() + QLatin1String("/.cache"); Executed by:
| 10 | ||||||||||||
87 | if (type == QStandardPaths::CacheLocation)
| 6-8 | ||||||||||||
88 | appendOrganizationAndApp(xdgCacheHome); executed 6 times by 1 test: appendOrganizationAndApp(xdgCacheHome); Executed by:
| 6 | ||||||||||||
89 | return xdgCacheHome; executed 14 times by 1 test: return xdgCacheHome; Executed by:
| 14 | ||||||||||||
90 | } | - | ||||||||||||
91 | case AppDataLocation: executed 5 times by 1 test: case AppDataLocation: Executed by:
| 5 | ||||||||||||
92 | case AppLocalDataLocation: executed 13 times by 1 test: case AppLocalDataLocation: Executed by:
| 13 | ||||||||||||
93 | case GenericDataLocation: executed 2676 times by 26 tests: case GenericDataLocation: Executed by:
| 2676 | ||||||||||||
94 | { | - | ||||||||||||
95 | QString xdgDataHome = QFile::decodeName(qgetenv("XDG_DATA_HOME")); | - | ||||||||||||
96 | if (isTestModeEnabled())
| 631-2063 | ||||||||||||
97 | xdgDataHome = QDir::homePath() + QLatin1String("/.qttest/share"); executed 2063 times by 4 tests: xdgDataHome = QDir::homePath() + QLatin1String("/.qttest/share"); Executed by:
| 2063 | ||||||||||||
98 | if (xdgDataHome.isEmpty())
| 620-2074 | ||||||||||||
99 | xdgDataHome = QDir::homePath() + QLatin1String("/.local/share"); executed 620 times by 23 tests: xdgDataHome = QDir::homePath() + QLatin1String("/.local/share"); Executed by:
| 620 | ||||||||||||
100 | if (type == AppDataLocation || type == AppLocalDataLocation)
| 5-2689 | ||||||||||||
101 | appendOrganizationAndApp(xdgDataHome); executed 18 times by 1 test: appendOrganizationAndApp(xdgDataHome); Executed by:
| 18 | ||||||||||||
102 | return xdgDataHome; executed 2694 times by 26 tests: return xdgDataHome; Executed by:
| 2694 | ||||||||||||
103 | } | - | ||||||||||||
104 | case ConfigLocation: executed 16 times by 1 test: case ConfigLocation: Executed by:
| 16 | ||||||||||||
105 | case GenericConfigLocation: executed 1098 times by 32 tests: case GenericConfigLocation: Executed by:
| 1098 | ||||||||||||
106 | case AppConfigLocation: executed 5 times by 1 test: case AppConfigLocation: Executed by:
| 5 | ||||||||||||
107 | { | - | ||||||||||||
108 | // http://standards.freedesktop.org/basedir-spec/latest/ | - | ||||||||||||
109 | QString xdgConfigHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME")); | - | ||||||||||||
110 | if (isTestModeEnabled())
| 12-1107 | ||||||||||||
111 | xdgConfigHome = QDir::homePath() + QLatin1String("/.qttest/config"); executed 12 times by 5 tests: xdgConfigHome = QDir::homePath() + QLatin1String("/.qttest/config"); Executed by:
| 12 | ||||||||||||
112 | if (xdgConfigHome.isEmpty())
| 21-1098 | ||||||||||||
113 | xdgConfigHome = QDir::homePath() + QLatin1String("/.config"); executed 1098 times by 28 tests: xdgConfigHome = QDir::homePath() + QLatin1String("/.config"); Executed by:
| 1098 | ||||||||||||
114 | if (type == AppConfigLocation)
| 5-1114 | ||||||||||||
115 | appendOrganizationAndApp(xdgConfigHome); executed 5 times by 1 test: appendOrganizationAndApp(xdgConfigHome); Executed by:
| 5 | ||||||||||||
116 | return xdgConfigHome; executed 1119 times by 32 tests: return xdgConfigHome; Executed by:
| 1119 | ||||||||||||
117 | } | - | ||||||||||||
118 | case RuntimeLocation: executed 8 times by 1 test: case RuntimeLocation: Executed by:
| 8 | ||||||||||||
119 | { | - | ||||||||||||
120 | const uid_t myUid = geteuid(); | - | ||||||||||||
121 | // http://standards.freedesktop.org/basedir-spec/latest/ | - | ||||||||||||
122 | QFileInfo fileInfo; | - | ||||||||||||
123 | QString xdgRuntimeDir = QFile::decodeName(qgetenv("XDG_RUNTIME_DIR")); | - | ||||||||||||
124 | if (xdgRuntimeDir.isEmpty()) {
| 0-8 | ||||||||||||
125 | const QString userName = QFileSystemEngine::resolveUserName(myUid); | - | ||||||||||||
126 | xdgRuntimeDir = QDir::tempPath() + QLatin1String("/runtime-") + userName; | - | ||||||||||||
127 | fileInfo.setFile(xdgRuntimeDir); | - | ||||||||||||
128 | if (!fileInfo.isDir()) {
| 0 | ||||||||||||
129 | if (!QDir().mkdir(xdgRuntimeDir)) {
| 0 | ||||||||||||
130 | qWarning("QStandardPaths: error creating runtime directory %s: %s", qPrintable(xdgRuntimeDir), qPrintable(qt_error_string(errno))); | - | ||||||||||||
131 | return QString(); never executed: return QString(); | 0 | ||||||||||||
132 | } | - | ||||||||||||
133 | } never executed: end of block | 0 | ||||||||||||
134 | qWarning("QStandardPaths: XDG_RUNTIME_DIR not set, defaulting to '%s'", qPrintable(xdgRuntimeDir)); | - | ||||||||||||
135 | } else { never executed: end of block | 0 | ||||||||||||
136 | fileInfo.setFile(xdgRuntimeDir); | - | ||||||||||||
137 | if (!fileInfo.exists()) {
| 1-7 | ||||||||||||
138 | qWarning("QStandardPaths: XDG_RUNTIME_DIR points to non-existing path '%s', " | - | ||||||||||||
139 | "please create it with 0700 permissions.", qPrintable(xdgRuntimeDir)); | - | ||||||||||||
140 | return QString(); executed 1 time by 1 test: return QString(); Executed by:
| 1 | ||||||||||||
141 | } | - | ||||||||||||
142 | if (!fileInfo.isDir()) {
| 1-6 | ||||||||||||
143 | qWarning("QStandardPaths: XDG_RUNTIME_DIR points to '%s' which is not a directory", | - | ||||||||||||
144 | qPrintable(xdgRuntimeDir)); | - | ||||||||||||
145 | return QString(); executed 1 time by 1 test: return QString(); Executed by:
| 1 | ||||||||||||
146 | } | - | ||||||||||||
147 | } executed 6 times by 1 test: end of block Executed by:
| 6 | ||||||||||||
148 | // "The directory MUST be owned by the user" | - | ||||||||||||
149 | if (fileInfo.ownerId() != myUid) {
| 1-5 | ||||||||||||
150 | qWarning("QStandardPaths: wrong ownership on runtime directory %s, %d instead of %d", qPrintable(xdgRuntimeDir), | - | ||||||||||||
151 | fileInfo.ownerId(), myUid); | - | ||||||||||||
152 | return QString(); executed 1 time by 1 test: return QString(); Executed by:
| 1 | ||||||||||||
153 | } | - | ||||||||||||
154 | // "and he MUST be the only one having read and write access to it. Its Unix access mode MUST be 0700." | - | ||||||||||||
155 | // since the current user is the owner, set both xxxUser and xxxOwner | - | ||||||||||||
156 | const QFile::Permissions wantedPerms = QFile::ReadUser | QFile::WriteUser | QFile::ExeUser | - | ||||||||||||
157 | | QFile::ReadOwner | QFile::WriteOwner | QFile::ExeOwner; | - | ||||||||||||
158 | if (fileInfo.permissions() != wantedPerms) {
| 1-4 | ||||||||||||
159 | QFile file(xdgRuntimeDir); | - | ||||||||||||
160 | if (!file.setPermissions(wantedPerms)) {
| 0-1 | ||||||||||||
161 | qWarning("QStandardPaths: could not set correct permissions on runtime directory %s: %s", | - | ||||||||||||
162 | qPrintable(xdgRuntimeDir), qPrintable(file.errorString())); | - | ||||||||||||
163 | return QString(); never executed: return QString(); | 0 | ||||||||||||
164 | } | - | ||||||||||||
165 | } executed 1 time by 1 test: end of block Executed by:
| 1 | ||||||||||||
166 | return xdgRuntimeDir; executed 5 times by 1 test: return xdgRuntimeDir; Executed by:
| 5 | ||||||||||||
167 | } | - | ||||||||||||
168 | default: executed 45 times by 3 tests: default: Executed by:
| 45 | ||||||||||||
169 | break; executed 45 times by 3 tests: break; Executed by:
| 45 | ||||||||||||
170 | } | - | ||||||||||||
171 | - | |||||||||||||
172 | #ifndef QT_BOOTSTRAPPED | - | ||||||||||||
173 | // http://www.freedesktop.org/wiki/Software/xdg-user-dirs | - | ||||||||||||
174 | QString xdgConfigHome = QFile::decodeName(qgetenv("XDG_CONFIG_HOME")); | - | ||||||||||||
175 | if (xdgConfigHome.isEmpty())
| 2-43 | ||||||||||||
176 | xdgConfigHome = QDir::homePath() + QLatin1String("/.config"); executed 43 times by 3 tests: xdgConfigHome = QDir::homePath() + QLatin1String("/.config"); Executed by:
| 43 | ||||||||||||
177 | QFile file(xdgConfigHome + QLatin1String("/user-dirs.dirs")); | - | ||||||||||||
178 | if (!isTestModeEnabled() && file.open(QIODevice::ReadOnly)) {
| 0-45 | ||||||||||||
179 | QHash<QString, QString> lines; | - | ||||||||||||
180 | QTextStream stream(&file); | - | ||||||||||||
181 | // Only look for lines like: XDG_DESKTOP_DIR="$HOME/Desktop" | - | ||||||||||||
182 | QRegExp exp(QLatin1String("^XDG_(.*)_DIR=(.*)$")); | - | ||||||||||||
183 | while (!stream.atEnd()) {
| 43-645 | ||||||||||||
184 | const QString &line = stream.readLine(); | - | ||||||||||||
185 | if (exp.indexIn(line) != -1) {
| 301-344 | ||||||||||||
186 | const QStringList lst = exp.capturedTexts(); | - | ||||||||||||
187 | const QString key = lst.at(1); | - | ||||||||||||
188 | QString value = lst.at(2); | - | ||||||||||||
189 | if (value.length() > 2
| 0-344 | ||||||||||||
190 | && value.startsWith(QLatin1Char('\"'))
| 0-344 | ||||||||||||
191 | && value.endsWith(QLatin1Char('\"')))
| 0-344 | ||||||||||||
192 | value = value.mid(1, value.length() - 2); executed 344 times by 3 tests: value = value.mid(1, value.length() - 2); Executed by:
| 344 | ||||||||||||
193 | // Store the key and value: "DESKTOP", "$HOME/Desktop" | - | ||||||||||||
194 | lines[key] = value; | - | ||||||||||||
195 | } executed 344 times by 3 tests: end of block Executed by:
| 344 | ||||||||||||
196 | } executed 645 times by 3 tests: end of block Executed by:
| 645 | ||||||||||||
197 | - | |||||||||||||
198 | QString key; | - | ||||||||||||
199 | switch (type) { | - | ||||||||||||
200 | case DesktopLocation: executed 5 times by 1 test: case DesktopLocation: Executed by:
| 5 | ||||||||||||
201 | key = QLatin1String("DESKTOP"); | - | ||||||||||||
202 | break; executed 5 times by 1 test: break; Executed by:
| 5 | ||||||||||||
203 | case DocumentsLocation: executed 7 times by 2 tests: case DocumentsLocation: Executed by:
| 7 | ||||||||||||
204 | key = QLatin1String("DOCUMENTS"); | - | ||||||||||||
205 | break; executed 7 times by 2 tests: break; Executed by:
| 7 | ||||||||||||
206 | case PicturesLocation: executed 5 times by 1 test: case PicturesLocation: Executed by:
| 5 | ||||||||||||
207 | key = QLatin1String("PICTURES"); | - | ||||||||||||
208 | break; executed 5 times by 1 test: break; Executed by:
| 5 | ||||||||||||
209 | case MusicLocation: executed 5 times by 1 test: case MusicLocation: Executed by:
| 5 | ||||||||||||
210 | key = QLatin1String("MUSIC"); | - | ||||||||||||
211 | break; executed 5 times by 1 test: break; Executed by:
| 5 | ||||||||||||
212 | case MoviesLocation: executed 5 times by 1 test: case MoviesLocation: Executed by:
| 5 | ||||||||||||
213 | key = QLatin1String("VIDEOS"); | - | ||||||||||||
214 | break; executed 5 times by 1 test: break; Executed by:
| 5 | ||||||||||||
215 | case DownloadLocation: executed 6 times by 2 tests: case DownloadLocation: Executed by:
| 6 | ||||||||||||
216 | key = QLatin1String("DOWNLOAD"); | - | ||||||||||||
217 | break; executed 6 times by 2 tests: break; Executed by:
| 6 | ||||||||||||
218 | default: executed 10 times by 1 test: default: Executed by:
| 10 | ||||||||||||
219 | break; executed 10 times by 1 test: break; Executed by:
| 10 | ||||||||||||
220 | } | - | ||||||||||||
221 | if (!key.isEmpty()) {
| 10-33 | ||||||||||||
222 | QString value = lines.value(key); | - | ||||||||||||
223 | if (!value.isEmpty()) {
| 0-33 | ||||||||||||
224 | // value can start with $HOME | - | ||||||||||||
225 | if (value.startsWith(QLatin1String("$HOME")))
| 0-33 | ||||||||||||
226 | value = QDir::homePath() + value.mid(5); executed 33 times by 3 tests: value = QDir::homePath() + value.mid(5); Executed by:
| 33 | ||||||||||||
227 | if (value.length() > 1 && value.endsWith(QLatin1Char('/')))
| 0-33 | ||||||||||||
228 | value.chop(1); never executed: value.chop(1); | 0 | ||||||||||||
229 | return value; executed 33 times by 3 tests: return value; Executed by:
| 33 | ||||||||||||
230 | } | - | ||||||||||||
231 | } never executed: end of block | 0 | ||||||||||||
232 | } executed 10 times by 1 test: end of block Executed by:
| 10 | ||||||||||||
233 | #endif | - | ||||||||||||
234 | - | |||||||||||||
235 | QString path; | - | ||||||||||||
236 | switch (type) { | - | ||||||||||||
237 | case DesktopLocation: never executed: case DesktopLocation: | 0 | ||||||||||||
238 | path = QDir::homePath() + QLatin1String("/Desktop"); | - | ||||||||||||
239 | break; never executed: break; | 0 | ||||||||||||
240 | case DocumentsLocation: never executed: case DocumentsLocation: | 0 | ||||||||||||
241 | path = QDir::homePath() + QLatin1String("/Documents"); | - | ||||||||||||
242 | break; never executed: break; | 0 | ||||||||||||
243 | case PicturesLocation: never executed: case PicturesLocation: | 0 | ||||||||||||
244 | path = QDir::homePath() + QLatin1String("/Pictures"); | - | ||||||||||||
245 | break; never executed: break; | 0 | ||||||||||||
246 | - | |||||||||||||
247 | case FontsLocation: executed 5 times by 1 test: case FontsLocation: Executed by:
| 5 | ||||||||||||
248 | path = QDir::homePath() + QLatin1String("/.fonts"); | - | ||||||||||||
249 | break; executed 5 times by 1 test: break; Executed by:
| 5 | ||||||||||||
250 | - | |||||||||||||
251 | case MusicLocation: never executed: case MusicLocation: | 0 | ||||||||||||
252 | path = QDir::homePath() + QLatin1String("/Music"); | - | ||||||||||||
253 | break; never executed: break; | 0 | ||||||||||||
254 | - | |||||||||||||
255 | case MoviesLocation: never executed: case MoviesLocation: | 0 | ||||||||||||
256 | path = QDir::homePath() + QLatin1String("/Videos"); | - | ||||||||||||
257 | break; never executed: break; | 0 | ||||||||||||
258 | case DownloadLocation: never executed: case DownloadLocation: | 0 | ||||||||||||
259 | path = QDir::homePath() + QLatin1String("/Downloads"); | - | ||||||||||||
260 | break; never executed: break; | 0 | ||||||||||||
261 | case ApplicationsLocation: executed 7 times by 1 test: case ApplicationsLocation: Executed by:
| 7 | ||||||||||||
262 | path = writableLocation(GenericDataLocation) + QLatin1String("/applications"); | - | ||||||||||||
263 | break; executed 7 times by 1 test: break; Executed by:
| 7 | ||||||||||||
264 | - | |||||||||||||
265 | default: never executed: default: | 0 | ||||||||||||
266 | break; never executed: break; | 0 | ||||||||||||
267 | } | - | ||||||||||||
268 | - | |||||||||||||
269 | return path; executed 12 times by 1 test: return path; Executed by:
| 12 | ||||||||||||
270 | } | - | ||||||||||||
271 | - | |||||||||||||
272 | static QStringList xdgDataDirs() | - | ||||||||||||
273 | { | - | ||||||||||||
274 | QStringList dirs; | - | ||||||||||||
275 | // http://standards.freedesktop.org/basedir-spec/latest/ | - | ||||||||||||
276 | QString xdgDataDirsEnv = QFile::decodeName(qgetenv("XDG_DATA_DIRS")); | - | ||||||||||||
277 | if (xdgDataDirsEnv.isEmpty()) {
| 141-2501 | ||||||||||||
278 | dirs.append(QString::fromLatin1("/usr/local/share")); | - | ||||||||||||
279 | dirs.append(QString::fromLatin1("/usr/share")); | - | ||||||||||||
280 | } else { executed 2501 times by 23 tests: end of block Executed by:
| 2501 | ||||||||||||
281 | dirs = xdgDataDirsEnv.split(QLatin1Char(':'), QString::SkipEmptyParts); | - | ||||||||||||
282 | - | |||||||||||||
283 | // Normalize paths, skip relative paths | - | ||||||||||||
284 | QMutableListIterator<QString> it(dirs); | - | ||||||||||||
285 | while (it.hasNext()) {
| 141-142 | ||||||||||||
286 | const QString dir = it.next(); | - | ||||||||||||
287 | if (!dir.startsWith(QLatin1Char('/')))
| 2-140 | ||||||||||||
288 | it.remove(); executed 2 times by 2 tests: it.remove(); Executed by:
| 2 | ||||||||||||
289 | else | - | ||||||||||||
290 | it.setValue(QDir::cleanPath(dir)); executed 140 times by 2 tests: it.setValue(QDir::cleanPath(dir)); Executed by:
| 140 | ||||||||||||
291 | } | - | ||||||||||||
292 | - | |||||||||||||
293 | // Remove duplicates from the list, there's no use for duplicated | - | ||||||||||||
294 | // paths in XDG_DATA_DIRS - if it's not found in the given | - | ||||||||||||
295 | // directory the first time, it won't be there the second time. | - | ||||||||||||
296 | // Plus duplicate paths causes problems for example for mimetypes, | - | ||||||||||||
297 | // where duplicate paths here lead to duplicated mime types returned | - | ||||||||||||
298 | // for a file, eg "text/plain,text/plain" instead of "text/plain" | - | ||||||||||||
299 | dirs.removeDuplicates(); | - | ||||||||||||
300 | } executed 141 times by 3 tests: end of block Executed by:
| 141 | ||||||||||||
301 | return dirs; executed 2642 times by 25 tests: return dirs; Executed by:
| 2642 | ||||||||||||
302 | } | - | ||||||||||||
303 | - | |||||||||||||
304 | static QStringList xdgConfigDirs() | - | ||||||||||||
305 | { | - | ||||||||||||
306 | QStringList dirs; | - | ||||||||||||
307 | // http://standards.freedesktop.org/basedir-spec/latest/ | - | ||||||||||||
308 | const QString xdgConfigDirs = QFile::decodeName(qgetenv("XDG_CONFIG_DIRS")); | - | ||||||||||||
309 | if (xdgConfigDirs.isEmpty())
| 6-1086 | ||||||||||||
310 | dirs.append(QString::fromLatin1("/etc/xdg")); executed 1086 times by 25 tests: dirs.append(QString::fromLatin1("/etc/xdg")); Executed by:
| 1086 | ||||||||||||
311 | else | - | ||||||||||||
312 | dirs = xdgConfigDirs.split(QLatin1Char(':')); executed 6 times by 1 test: dirs = xdgConfigDirs.split(QLatin1Char(':')); Executed by:
| 6 | ||||||||||||
313 | return dirs; executed 1092 times by 25 tests: return dirs; Executed by:
| 1092 | ||||||||||||
314 | } | - | ||||||||||||
315 | - | |||||||||||||
316 | QStringList QStandardPaths::standardLocations(StandardLocation type) | - | ||||||||||||
317 | { | - | ||||||||||||
318 | QStringList dirs; | - | ||||||||||||
319 | switch (type) { | - | ||||||||||||
320 | case ConfigLocation: executed 9 times by 1 test: case ConfigLocation: Executed by:
| 9 | ||||||||||||
321 | case GenericConfigLocation: executed 1082 times by 25 tests: case GenericConfigLocation: Executed by:
| 1082 | ||||||||||||
322 | dirs = xdgConfigDirs(); | - | ||||||||||||
323 | break; executed 1091 times by 25 tests: break; Executed by:
| 1091 | ||||||||||||
324 | case AppConfigLocation: executed 1 time by 1 test: case AppConfigLocation: Executed by:
| 1 | ||||||||||||
325 | dirs = xdgConfigDirs(); | - | ||||||||||||
326 | for (int i = 0; i < dirs.count(); ++i)
| 1 | ||||||||||||
327 | appendOrganizationAndApp(dirs[i]); executed 1 time by 1 test: appendOrganizationAndApp(dirs[i]); Executed by:
| 1 | ||||||||||||
328 | break; executed 1 time by 1 test: break; Executed by:
| 1 | ||||||||||||
329 | case GenericDataLocation: executed 2634 times by 25 tests: case GenericDataLocation: Executed by:
| 2634 | ||||||||||||
330 | dirs = xdgDataDirs(); | - | ||||||||||||
331 | break; executed 2634 times by 25 tests: break; Executed by:
| 2634 | ||||||||||||
332 | case ApplicationsLocation: executed 4 times by 1 test: case ApplicationsLocation: Executed by:
| 4 | ||||||||||||
333 | dirs = xdgDataDirs(); | - | ||||||||||||
334 | for (int i = 0; i < dirs.count(); ++i)
| 4-6 | ||||||||||||
335 | dirs[i].append(QLatin1String("/applications")); executed 6 times by 1 test: dirs[i].append(QLatin1String("/applications")); Executed by:
| 6 | ||||||||||||
336 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||
337 | case AppDataLocation: executed 1 time by 1 test: case AppDataLocation: Executed by:
| 1 | ||||||||||||
338 | case AppLocalDataLocation: executed 3 times by 1 test: case AppLocalDataLocation: Executed by:
| 3 | ||||||||||||
339 | dirs = xdgDataDirs(); | - | ||||||||||||
340 | for (int i = 0; i < dirs.count(); ++i)
| 4-8 | ||||||||||||
341 | appendOrganizationAndApp(dirs[i]); executed 8 times by 1 test: appendOrganizationAndApp(dirs[i]); Executed by:
| 8 | ||||||||||||
342 | break; executed 4 times by 1 test: break; Executed by:
| 4 | ||||||||||||
343 | default: executed 27 times by 2 tests: default: Executed by:
| 27 | ||||||||||||
344 | break; executed 27 times by 2 tests: break; Executed by:
| 27 | ||||||||||||
345 | } | - | ||||||||||||
346 | const QString localDir = writableLocation(type); | - | ||||||||||||
347 | dirs.prepend(localDir); | - | ||||||||||||
348 | return dirs; executed 3761 times by 48 tests: return dirs; Executed by:
| 3761 | ||||||||||||
349 | } | - | ||||||||||||
350 | - | |||||||||||||
351 | QT_END_NAMESPACE | - | ||||||||||||
352 | - | |||||||||||||
353 | #endif // QT_NO_STANDARDPATHS | - | ||||||||||||
Source code | Switch to Preprocessed file |