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