1/****************************************************************************
2**
3** Copyright (C) 2016 The Qt Company Ltd.
4** Copyright (C) 2016 Intel Corporation.
5** Contact: https://www.qt.io/licensing/
6**
7** This file is part of the QtCore module of the Qt Toolkit.
8**
9** $QT_BEGIN_LICENSE:LGPL$
10** Commercial License Usage
11** Licensees holding valid commercial Qt licenses may use this file in
12** accordance with the commercial license agreement provided with the
13** Software or, alternatively, in accordance with the terms contained in
14** a written agreement between you and The Qt Company. For licensing terms
15** and conditions see https://www.qt.io/terms-conditions. For further
16** information use the contact form at https://www.qt.io/contact-us.
17**
18** GNU Lesser General Public License Usage
19** Alternatively, this file may be used under the terms of the GNU Lesser
20** General Public License version 3 as published by the Free Software
21** Foundation and appearing in the file LICENSE.LGPL3 included in the
22** packaging of this file. Please review the following information to
23** ensure the GNU Lesser General Public License version 3 requirements
24** will be met: https://www.gnu.org/licenses/lgpl-3.0.html.
25**
26** GNU General Public License Usage
27** Alternatively, this file may be used under the terms of the GNU
28** General Public License version 2.0 or (at your option) the GNU General
29** Public license version 3 or any later version approved by the KDE Free
30** Qt Foundation. The licenses are as published by the Free Software
31** Foundation and appearing in the file LICENSE.GPL2 and LICENSE.GPL3
32** included in the packaging of this file. Please review the following
33** information to ensure the GNU General Public License requirements will
34** be met: https://www.gnu.org/licenses/gpl-2.0.html and
35** https://www.gnu.org/licenses/gpl-3.0.html.
36**
37** $QT_END_LICENSE$
38**
39****************************************************************************/
40
41#include "qstandardpaths.h"
42
43#include <qdir.h>
44#include <qfileinfo.h>
45
46#ifndef QT_BOOTSTRAPPED
47#include <qobject.h>
48#include <qcoreapplication.h>
49#endif
50
51#if QT_HAS_INCLUDE(<paths.h>)
52#include <paths.h>
53#endif
54
55#ifdef Q_OS_UNIX
56#include <unistd.h>
57#endif
58
59#ifndef QT_NO_STANDARDPATHS
60
61QT_BEGIN_NAMESPACE
62
63/*!
64 \class QStandardPaths
65 \inmodule QtCore
66 \brief The QStandardPaths class provides methods for accessing standard paths.
67 \since 5.0
68
69 This class contains functions to query standard locations on the local
70 filesystem, for common tasks such as user-specific directories or system-wide
71 configuration directories.
72*/
73
74/*!
75 \enum QStandardPaths::StandardLocation
76
77 This enum describes the different locations that can be queried using
78 methods such as QStandardPaths::writableLocation, QStandardPaths::standardLocations,
79 and QStandardPaths::displayName.
80
81 Some of the values in this enum represent a user configuration. Such enum
82 values will return the same paths in different applications, so they could
83 be used to share data with other applications. Other values are specific to
84 this application. Each enum value in the table below describes whether it's
85 application-specific or generic.
86
87 Application-specific directories should be assumed to be unreachable by
88 other applications. Therefore, files placed there might not be readable by
89 other applications, even if run by the same user. On the other hand, generic
90 directories should be assumed to be accessible by all applications run by
91 this user, but should still be assumed to be unreachable by applications by
92 other users.
93
94 Data interchange with other users is out of the scope of QStandardPaths.
95
96 \value DesktopLocation Returns the user's desktop directory. This is a generic value.
97 On systems with no concept of a desktop, this is the same as
98 QStandardPaths::HomeLocation.
99 \value DocumentsLocation Returns the directory containing user document files.
100 This is a generic value. The returned path is never empty.
101 \value FontsLocation Returns the directory containing user's fonts. This is a generic value.
102 Note that installing fonts may require additional, platform-specific operations.
103 \value ApplicationsLocation Returns the directory containing the user applications
104 (either executables, application bundles, or shortcuts to them). This is a generic value.
105 Note that installing applications may require additional, platform-specific operations.
106 Files, folders or shortcuts in this directory are platform-specific.
107 \value MusicLocation Returns the directory containing the user's music or other audio files.
108 This is a generic value. If no directory specific for music files exists, a sensible
109 fallback for storing user documents is returned.
110 \value MoviesLocation Returns the directory containing the user's movies and videos.
111 This is a generic value. If no directory specific for movie files exists, a sensible
112 fallback for storing user documents is returned.
113 \value PicturesLocation Returns the directory containing the user's pictures or photos.
114 This is a generic value. If no directory specific for picture files exists, a sensible
115 fallback for storing user documents is returned.
116 \value TempLocation Returns a directory where temporary files can be stored. The returned value
117 might be application-specific, shared among other applications for this user, or even
118 system-wide. The returned path is never empty.
119 \value HomeLocation Returns the user's home directory (the same as QDir::homePath()). On Unix
120 systems, this is equal to the HOME environment variable. This value might be
121 generic or application-specific, but the returned path is never empty.
122 \value DataLocation Returns the same value as AppLocalDataLocation. This enumeration value
123 is deprecated. Using AppDataLocation is preferable since on Windows, the roaming path is
124 recommended.
125 \value CacheLocation Returns a directory location where user-specific
126 non-essential (cached) data should be written. This is an application-specific directory.
127 The returned path is never empty.
128 \value GenericCacheLocation Returns a directory location where user-specific non-essential
129 (cached) data, shared across applications, should be written. This is a generic value.
130 Note that the returned path may be empty if the system has no concept of shared cache.
131 \value GenericDataLocation Returns a directory location where persistent
132 data shared across applications can be stored. This is a generic value. The returned
133 path is never empty.
134 \value RuntimeLocation Returns a directory location where runtime communication
135 files should be written, like Unix local sockets. This is a generic value.
136 The returned path may be empty on some systems.
137 \value ConfigLocation Returns a directory location where user-specific
138 configuration files should be written. This may be either a generic value
139 or application-specific, and the returned path is never empty.
140 \value DownloadLocation Returns a directory for user's downloaded files. This is a generic value.
141 If no directory specific for downloads exists, a sensible fallback for storing user
142 documents is returned.
143 \value GenericConfigLocation Returns a directory location where user-specific
144 configuration files shared between multiple applications should be written.
145 This is a generic value and the returned path is never empty.
146 \value AppDataLocation Returns a directory location where persistent
147 application data can be stored. This is an application-specific directory.
148 To obtain a path to store data to be shared with other applications, use
149 QStandardPaths::GenericDataLocation. The returned path is never empty.
150 On the Windows operating system, this returns the roaming path.
151 This enum value was added in Qt 5.4.
152 \value AppLocalDataLocation Returns the local settings path on the Windows operating
153 system. On all other platforms, it returns the same value as AppDataLocation.
154 This enum value was added in Qt 5.4.
155 \value AppConfigLocation Returns a directory location where user-specific
156 configuration files should be written. This is an application-specific directory,
157 and the returned path is never empty.
158 This enum value was added in Qt 5.5.
159
160 The following table gives examples of paths on different operating systems.
161 The first path is the writable path (unless noted). Other, additional
162 paths, if any, represent non-writable locations.
163
164 \table
165 \header \li Path type \li \macos \li Windows
166 \row \li DesktopLocation
167 \li "~/Desktop"
168 \li "C:/Users/<USER>/Desktop"
169 \row \li DocumentsLocation
170 \li "~/Documents"
171 \li "C:/Users/<USER>/Documents"
172 \row \li FontsLocation
173 \li "/System/Library/Fonts" (not writable)
174 \li "C:/Windows/Fonts" (not writable)
175 \row \li ApplicationsLocation
176 \li "/Applications" (not writable)
177 \li "C:/Users/<USER>/AppData/Roaming/Microsoft/Windows/Start Menu/Programs"
178 \row \li MusicLocation
179 \li "~/Music"
180 \li "C:/Users/<USER>/Music"
181 \row \li MoviesLocation
182 \li "~/Movies"
183 \li "C:/Users/<USER>/Videos"
184 \row \li PicturesLocation
185 \li "~/Pictures"
186 \li "C:/Users/<USER>/Pictures"
187 \row \li TempLocation
188 \li randomly generated by the OS
189 \li "C:/Users/<USER>/AppData/Local/Temp"
190 \row \li HomeLocation
191 \li "~"
192 \li "C:/Users/<USER>"
193 \row \li DataLocation
194 \li "~/Library/Application Support/<APPNAME>", "/Library/Application Support/<APPNAME>". "<APPDIR>/../Resources"
195 \li "C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>", "<APPDIR>", "<APPDIR>/data", "<APPDIR>/data/<APPNAME>"
196 \row \li CacheLocation
197 \li "~/Library/Caches/<APPNAME>", "/Library/Caches/<APPNAME>"
198 \li "C:/Users/<USER>/AppData/Local/<APPNAME>/cache"
199 \row \li GenericDataLocation
200 \li "~/Library/Application Support", "/Library/Application Support"
201 \li "C:/Users/<USER>/AppData/Local", "C:/ProgramData", "<APPDIR>", "<APPDIR>/data"
202 \row \li RuntimeLocation
203 \li "~/Library/Application Support"
204 \li "C:/Users/<USER>"
205 \row \li ConfigLocation
206 \li "~/Library/Preferences"
207 \li "C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>"
208 \row \li GenericConfigLocation
209 \li "~/Library/Preferences"
210 \li "C:/Users/<USER>/AppData/Local", "C:/ProgramData"
211 \row \li DownloadLocation
212 \li "~/Downloads"
213 \li "C:/Users/<USER>/Documents"
214 \row \li GenericCacheLocation
215 \li "~/Library/Caches", "/Library/Caches"
216 \li "C:/Users/<USER>/AppData/Local/cache"
217 \row \li AppDataLocation
218 \li "~/Library/Application Support/<APPNAME>", "/Library/Application Support/<APPNAME>". "<APPDIR>/../Resources"
219 \li "C:/Users/<USER>/AppData/Roaming/<APPNAME>", "C:/ProgramData/<APPNAME>", "<APPDIR>", "<APPDIR>/data", "<APPDIR>/data/<APPNAME>"
220 \row \li AppLocalDataLocation
221 \li "~/Library/Application Support/<APPNAME>", "/Library/Application Support/<APPNAME>". "<APPDIR>/../Resources"
222 \li "C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>", "<APPDIR>", "<APPDIR>/data", "<APPDIR>/data/<APPNAME>"
223 \row \li AppConfigLocation
224 \li "~/Library/Preferences/<APPNAME>"
225 \li "C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>"
226 \endtable
227
228 \table
229 \header \li Path type \li Linux
230 \row \li DesktopLocation
231 \li "~/Desktop"
232 \row \li DocumentsLocation
233 \li "~/Documents"
234 \row \li FontsLocation
235 \li "~/.fonts"
236 \row \li ApplicationsLocation
237 \li "~/.local/share/applications", "/usr/local/share/applications", "/usr/share/applications"
238 \row \li MusicLocation
239 \li "~/Music"
240 \row \li MoviesLocation
241 \li "~/Videos"
242 \row \li PicturesLocation
243 \li "~/Pictures"
244 \row \li TempLocation
245 \li "/tmp"
246 \row \li HomeLocation
247 \li "~"
248 \row \li DataLocation
249 \li "~/.local/share/<APPNAME>", "/usr/local/share/<APPNAME>", "/usr/share/<APPNAME>"
250 \row \li CacheLocation
251 \li "~/.cache/<APPNAME>"
252 \row \li GenericDataLocation
253 \li "~/.local/share", "/usr/local/share", "/usr/share"
254 \row \li RuntimeLocation
255 \li "/run/user/<USER>"
256 \row \li ConfigLocation
257 \li "~/.config", "/etc/xdg"
258 \row \li GenericConfigLocation
259 \li "~/.config", "/etc/xdg"
260 \row \li DownloadLocation
261 \li "~/Downloads"
262 \row \li GenericCacheLocation
263 \li "~/.cache"
264 \row \li AppDataLocation
265 \li "~/.local/share/<APPNAME>", "/usr/local/share/<APPNAME>", "/usr/share/<APPNAME>"
266 \row \li AppLocalDataLocation
267 \li "~/.local/share/<APPNAME>", "/usr/local/share/<APPNAME>", "/usr/share/<APPNAME>"
268 \row \li AppConfigLocation
269 \li "~/.config/<APPNAME>", "/etc/xdg/<APPNAME>"
270 \endtable
271
272 \table
273 \header \li Path type \li Android \li iOS
274 \row \li DesktopLocation
275 \li "<APPROOT>/files"
276 \li "<APPROOT>/Documents/Desktop"
277 \row \li DocumentsLocation
278 \li "<USER>/Documents", "<USER>/<APPNAME>/Documents"
279 \li "<APPROOT>/Documents"
280 \row \li FontsLocation
281 \li "/system/fonts" (not writable)
282 \li "<APPROOT>/Library/Fonts"
283 \row \li ApplicationsLocation
284 \li not supported (directory not readable)
285 \li not supported
286 \row \li MusicLocation
287 \li "<USER>/Music", "<USER>/<APPNAME>/Music"
288 \li "<APPROOT>/Documents/Music"
289 \row \li MoviesLocation
290 \li "<USER>/Movies", "<USER>/<APPNAME>/Movies"
291 \li "<APPROOT>/Documents/Movies"
292 \row \li PicturesLocation
293 \li "<USER>/Pictures", "<USER>/<APPNAME>/Pictures"
294 \li "<APPROOT>/Documents/Pictures", "assets-library://"
295 \row \li TempLocation
296 \li "<APPROOT>/cache"
297 \li "<APPROOT>/tmp"
298 \row \li HomeLocation
299 \li "<APPROOT>/files"
300 \li system defined
301 \row \li DataLocation
302 \li "<APPROOT>/files", "<USER>/<APPNAME>/files"
303 \li "<APPROOT>/Library/Application Support"
304 \row \li CacheLocation
305 \li "<APPROOT>/cache", "<USER>/<APPNAME>/cache"
306 \li "<APPROOT>/Library/Caches"
307 \row \li GenericDataLocation
308 \li "<USER>"
309 \li "<APPROOT>/Documents"
310 \row \li RuntimeLocation
311 \li "<APPROOT>/cache"
312 \li not supported
313 \row \li ConfigLocation
314 \li "<APPROOT>/files/settings"
315 \li "<APPROOT>/Library/Preferences"
316 \row \li GenericConfigLocation
317 \li "<APPROOT>/files/settings" (there is no shared settings)
318 \li "<APPROOT>/Library/Preferences"
319 \row \li DownloadLocation
320 \li "<USER>/Downloads", "<USER>/<APPNAME>/Downloads"
321 \li "<APPROOT>/Documents/Downloads"
322 \row \li GenericCacheLocation
323 \li "<APPROOT>/cache" (there is no shared cache)
324 \li "<APPROOT>/Library/Caches"
325 \row \li AppDataLocation
326 \li "<APPROOT>/files", "<USER>/<APPNAME>/files"
327 \li "<APPROOT>/Library/Application Support"
328 \row \li AppConfigLocation
329 \li "<APPROOT>/files/settings"
330 \li "<APPROOT>/Library/Preferences/<APPNAME>"
331 \row \li AppLocalDataLocation
332 \li "<APPROOT>/files", "<USER>/<APPNAME>/files"
333 \li "<APPROOT>/Library/Application Support"
334 \endtable
335
336 In the table above, \c <APPNAME> is usually the organization name, the
337 application name, or both, or a unique name generated at packaging.
338 Similarly, <APPROOT> is the location where this application is installed
339 (often a sandbox). <APPDIR> is the directory containing the application
340 executable.
341
342 The paths above should not be relied upon, as they may change according to
343 OS configuration, locale, or they may change in future Qt versions.
344
345 \note On Android, applications with open files on the external storage (<USER> locations),
346 will be killed if the external storage is unmounted.
347
348 \note On iOS, if you do pass \c {QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).last()}
349 as argument to \l{QFileDialog::setDirectory()},
350 a native image picker dialog will be used for accessing the user's photo album.
351 The filename returned can be loaded using QFile and related APIs.
352 This feature was added in Qt 5.5.
353
354 \sa writableLocation(), standardLocations(), displayName(), locate(), locateAll()
355*/
356
357/*!
358 \fn QString QStandardPaths::writableLocation(StandardLocation type)
359
360 Returns the directory where files of \a type should be written to, or an empty string
361 if the location cannot be determined.
362
363 \note The storage location returned can be a directory that does not exist; i.e., it
364 may need to be created by the system or the user.
365*/
366
367
368/*!
369 \fn QStringList QStandardPaths::standardLocations(StandardLocation type)
370
371 Returns all the directories where files of \a type belong.
372
373 The list of directories is sorted from high to low priority, starting with
374 writableLocation() if it can be determined. This list is empty if no locations
375 for \a type are defined.
376
377 \sa writableLocation()
378 */
379
380/*!
381 \enum QStandardPaths::LocateOption
382
383 This enum describes the different flags that can be used for
384 controlling the behavior of QStandardPaths::locate and
385 QStandardPaths::locateAll.
386
387 \value LocateFile return only files
388 \value LocateDirectory return only directories
389*/
390
391static bool existsAsSpecified(const QString &path, QStandardPaths::LocateOptions options)
392{
393 if (options & QStandardPaths::LocateDirectory)
394 return QDir(path).exists();
395 return QFileInfo(path).isFile();
396}
397
398/*!
399 Tries to find a file or directory called \a fileName in the standard locations
400 for \a type.
401
402 The full path to the first file or directory (depending on \a options) found is returned.
403 If no such file or directory can be found, an empty string is returned.
404 */
405QString QStandardPaths::locate(StandardLocation type, const QString &fileName, LocateOptions options)
406{
407 const QStringList &dirs = standardLocations(type);
408 for (QStringList::const_iterator dir = dirs.constBegin(); dir != dirs.constEnd(); ++dir) {
409 const QString path = *dir + QLatin1Char('/') + fileName;
410 if (existsAsSpecified(path, options))
411 return path;
412 }
413 return QString();
414}
415
416/*!
417 Tries to find all files or directories called \a fileName in the standard locations
418 for \a type.
419
420 The \a options flag allows to specify whether to look for files or directories.
421
422 Returns the list of all the files that were found.
423 */
424QStringList QStandardPaths::locateAll(StandardLocation type, const QString &fileName, LocateOptions options)
425{
426 const QStringList &dirs = standardLocations(type);
427 QStringList result;
428 for (QStringList::const_iterator dir = dirs.constBegin(); dir != dirs.constEnd(); ++dir) {
429 const QString path = *dir + QLatin1Char('/') + fileName;
430 if (existsAsSpecified(path, options))
431 result.append(path);
432 }
433 return result;
434}
435
436#ifdef Q_OS_WIN
437static QStringList executableExtensions()
438{
439 // If %PATHEXT% does not contain .exe, it is either empty, malformed, or distorted in ways that we cannot support, anyway.
440 const QStringList pathExt = QString::fromLocal8Bit(qgetenv("PATHEXT")).toLower().split(QLatin1Char(';'));
441 return pathExt.contains(QLatin1String(".exe"), Qt::CaseInsensitive) ?
442 pathExt :
443 QStringList() << QLatin1String(".exe") << QLatin1String(".com")
444 << QLatin1String(".bat") << QLatin1String(".cmd");
445}
446#endif
447
448static QString checkExecutable(const QString &path)
449{
450 const QFileInfo info(path);
451 if (info.isBundle())
452 return info.bundleName();
453 if (info.isFile() && info.isExecutable())
454 return QDir::cleanPath(path);
455 return QString();
456}
457
458static inline QString searchExecutable(const QStringList &searchPaths,
459 const QString &executableName)
460{
461 const QDir currentDir = QDir::current();
462 for (const QString &searchPath : searchPaths) {
463 const QString candidate = currentDir.absoluteFilePath(searchPath + QLatin1Char('/') + executableName);
464 const QString absPath = checkExecutable(candidate);
465 if (!absPath.isEmpty())
466 return absPath;
467 }
468 return QString();
469}
470
471#ifdef Q_OS_WIN
472
473// Find executable appending candidate suffixes, used for suffix-less executables
474// on Windows.
475static inline QString
476 searchExecutableAppendSuffix(const QStringList &searchPaths,
477 const QString &executableName,
478 const QStringList &suffixes)
479{
480 const QDir currentDir = QDir::current();
481 for (const QString &searchPath : searchPaths) {
482 const QString candidateRoot = currentDir.absoluteFilePath(searchPath + QLatin1Char('/') + executableName);
483 for (const QString &suffix : suffixes) {
484 const QString absPath = checkExecutable(candidateRoot + suffix);
485 if (!absPath.isEmpty())
486 return absPath;
487 }
488 }
489 return QString();
490}
491
492#endif // Q_OS_WIN
493
494/*!
495 Finds the executable named \a executableName in the paths specified by \a paths,
496 or the system paths if \a paths is empty.
497
498 On most operating systems the system path is determined by the PATH environment variable.
499
500 The directories where to search for the executable can be set in the \a paths argument.
501 To search in both your own paths and the system paths, call findExecutable twice, once with
502 \a paths set and once with \a paths empty.
503
504 Symlinks are not resolved, in order to preserve behavior for the case of executables
505 whose behavior depends on the name they are invoked with.
506
507 \note On Windows, the usual executable extensions (from the PATHEXT environment variable)
508 are automatically appended, so that for instance findExecutable("foo") will find foo.exe
509 or foo.bat if present.
510
511 Returns the absolute file path to the executable, or an empty string if not found.
512 */
513QString QStandardPaths::findExecutable(const QString &executableName, const QStringList &paths)
514{
515 if (QFileInfo(executableName).isAbsolute())
516 return checkExecutable(executableName);
517
518 QStringList searchPaths = paths;
519 if (paths.isEmpty()) {
520 QByteArray pEnv = qgetenv("PATH");
521 if (Q_UNLIKELY(pEnv.isNull())) {
522 // Get a default path. POSIX.1 does not actually require this, but
523 // most Unix libc fall back to confstr(_CS_PATH) if the PATH
524 // environment variable isn't set. Let's try to do the same.
525#if defined(_PATH_DEFPATH)
526 // BSD API.
527 pEnv = _PATH_DEFPATH;
528#elif defined(_CS_PATH)
529 // POSIX API.
530 size_t n = confstr(_CS_PATH, nullptr, 0);
531 if (n) {
532 pEnv.resize(n);
533 // size()+1 is ok because QByteArray always has an extra NUL-terminator
534 confstr(_CS_PATH, pEnv.data(), pEnv.size() + 1);
535 }
536#else
537 // Windows SDK's execvpe() does not have a fallback, so we won't
538 // apply one either.
539#endif
540 }
541
542 // Remove trailing slashes, which occur on Windows.
543 const QStringList rawPaths = QString::fromLocal8Bit(pEnv.constData()).split(QDir::listSeparator(), QString::SkipEmptyParts);
544 searchPaths.reserve(rawPaths.size());
545 for (const QString &rawPath : rawPaths) {
546 QString cleanPath = QDir::cleanPath(rawPath);
547 if (cleanPath.size() > 1 && cleanPath.endsWith(QLatin1Char('/')))
548 cleanPath.truncate(cleanPath.size() - 1);
549 searchPaths.push_back(cleanPath);
550 }
551 }
552
553#ifdef Q_OS_WIN
554 // On Windows, if the name does not have a suffix or a suffix not
555 // in PATHEXT ("xx.foo"), append suffixes from PATHEXT.
556 static const QStringList executable_extensions = executableExtensions();
557 if (executableName.contains(QLatin1Char('.'))) {
558 const QString suffix = QFileInfo(executableName).suffix();
559 if (suffix.isEmpty() || !executable_extensions.contains(QLatin1Char('.') + suffix, Qt::CaseInsensitive))
560 return searchExecutableAppendSuffix(searchPaths, executableName, executable_extensions);
561 } else {
562 return searchExecutableAppendSuffix(searchPaths, executableName, executable_extensions);
563 }
564#endif
565 return searchExecutable(searchPaths, executableName);
566}
567
568/*!
569 \fn QString QStandardPaths::displayName(StandardLocation type)
570
571 Returns a localized display name for the given location \a type or
572 an empty QString if no relevant location can be found.
573*/
574
575#if !defined(Q_OS_MAC) && !defined(QT_BOOTSTRAPPED)
576QString QStandardPaths::displayName(StandardLocation type)
577{
578 switch (type) {
579 case DesktopLocation:
580 return QCoreApplication::translate("QStandardPaths", "Desktop");
581 case DocumentsLocation:
582 return QCoreApplication::translate("QStandardPaths", "Documents");
583 case FontsLocation:
584 return QCoreApplication::translate("QStandardPaths", "Fonts");
585 case ApplicationsLocation:
586 return QCoreApplication::translate("QStandardPaths", "Applications");
587 case MusicLocation:
588 return QCoreApplication::translate("QStandardPaths", "Music");
589 case MoviesLocation:
590 return QCoreApplication::translate("QStandardPaths", "Movies");
591 case PicturesLocation:
592 return QCoreApplication::translate("QStandardPaths", "Pictures");
593 case TempLocation:
594 return QCoreApplication::translate("QStandardPaths", "Temporary Directory");
595 case HomeLocation:
596 return QCoreApplication::translate("QStandardPaths", "Home");
597 case CacheLocation:
598 return QCoreApplication::translate("QStandardPaths", "Cache");
599 case GenericDataLocation:
600 return QCoreApplication::translate("QStandardPaths", "Shared Data");
601 case RuntimeLocation:
602 return QCoreApplication::translate("QStandardPaths", "Runtime");
603 case ConfigLocation:
604 return QCoreApplication::translate("QStandardPaths", "Configuration");
605 case GenericConfigLocation:
606 return QCoreApplication::translate("QStandardPaths", "Shared Configuration");
607 case GenericCacheLocation:
608 return QCoreApplication::translate("QStandardPaths", "Shared Cache");
609 case DownloadLocation:
610 return QCoreApplication::translate("QStandardPaths", "Download");
611 case AppDataLocation:
612 case AppLocalDataLocation:
613 return QCoreApplication::translate("QStandardPaths", "Application Data");
614 case AppConfigLocation:
615 return QCoreApplication::translate("QStandardPaths", "Application Configuration");
616 }
617 // not reached
618 return QString();
619}
620#endif
621
622/*!
623 \fn void QStandardPaths::enableTestMode(bool testMode)
624 \obsolete Use QStandardPaths::setTestModeEnabled
625 */
626/*!
627 \fn void QStandardPaths::setTestModeEnabled(bool testMode)
628
629 If \a testMode is true, this enables a special "test mode" in
630 QStandardPaths, which changes writable locations
631 to point to test directories, in order to prevent auto tests from reading from
632 or writing to the current user's configuration.
633
634 This affects the locations into which test programs might write files:
635 GenericDataLocation, DataLocation, ConfigLocation, GenericConfigLocation,
636 AppConfigLocation, GenericCacheLocation, CacheLocation.
637 Other locations are not affected.
638
639 On Unix, \c XDG_DATA_HOME is set to \e ~/.qttest/share, \c XDG_CONFIG_HOME is
640 set to \e ~/.qttest/config, and \c XDG_CACHE_HOME is set to \e ~/.qttest/cache.
641
642 On \macos, data goes to \e ~/.qttest/Application Support, cache goes to
643 \e ~/.qttest/Cache, and config goes to \e ~/.qttest/Preferences.
644
645 On Windows, everything goes to a "qttest" directory under Application Data.
646*/
647
648static bool qsp_testMode = false;
649
650#if QT_DEPRECATED_SINCE(5, 2)
651void QStandardPaths::enableTestMode(bool testMode)
652{
653 qsp_testMode = testMode;
654}
655#endif
656
657void QStandardPaths::setTestModeEnabled(bool testMode)
658{
659 qsp_testMode = testMode;
660}
661
662/*!
663 \fn void QStandardPaths::isTestModeEnabled()
664
665 \internal
666
667 Returns \c true if test mode is enabled in QStandardPaths; otherwise returns \c false.
668*/
669
670bool QStandardPaths::isTestModeEnabled()
671{
672 return qsp_testMode;
673}
674
675
676QT_END_NAMESPACE
677
678#ifndef QT_NO_QOBJECT
679#include "moc_qstandardpaths.cpp"
680#endif
681
682#endif // QT_NO_STANDARDPATHS
683