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

source code of qtbase/src/corelib/io/qstandardpaths.cpp