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
130 The following table gives examples of paths on different operating systems.
131 The first path is the writable path (unless noted). Other, additional
132 paths, if any, represent non-writable locations.
133
134 \table
135 \header \li Path type \li \macos \li Windows
136 \row \li DesktopLocation
137 \li "~/Desktop"
138 \li "C:/Users/<USER>/Desktop"
139 \row \li DocumentsLocation
140 \li "~/Documents"
141 \li "C:/Users/<USER>/Documents"
142 \row \li FontsLocation
143 \li "/System/Library/Fonts" (not writable)
144 \li "C:/Windows/Fonts" (not writable)
145 \row \li ApplicationsLocation
146 \li "/Applications" (not writable)
147 \li "C:/Users/<USER>/AppData/Roaming/Microsoft/Windows/Start Menu/Programs"
148 \row \li MusicLocation
149 \li "~/Music"
150 \li "C:/Users/<USER>/Music"
151 \row \li MoviesLocation
152 \li "~/Movies"
153 \li "C:/Users/<USER>/Videos"
154 \row \li PicturesLocation
155 \li "~/Pictures"
156 \li "C:/Users/<USER>/Pictures"
157 \row \li TempLocation
158 \li randomly generated by the OS
159 \li "C:/Users/<USER>/AppData/Local/Temp"
160 \row \li HomeLocation
161 \li "~"
162 \li "C:/Users/<USER>"
163 \row \li AppLocalDataLocation
164 \li "~/Library/Application Support/<APPNAME>", "/Library/Application Support/<APPNAME>". "<APPDIR>/../Resources"
165 \li "C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>", "<APPDIR>", "<APPDIR>/data", "<APPDIR>/data/<APPNAME>"
166 \row \li CacheLocation
167 \li "~/Library/Caches/<APPNAME>", "/Library/Caches/<APPNAME>"
168 \li "C:/Users/<USER>/AppData/Local/<APPNAME>/cache"
169 \row \li GenericDataLocation
170 \li "~/Library/Application Support", "/Library/Application Support"
171 \li "C:/Users/<USER>/AppData/Local", "C:/ProgramData", "<APPDIR>", "<APPDIR>/data"
172 \row \li RuntimeLocation
173 \li "~/Library/Application Support"
174 \li "C:/Users/<USER>"
175 \row \li ConfigLocation
176 \li "~/Library/Preferences"
177 \li "C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>"
178 \row \li GenericConfigLocation
179 \li "~/Library/Preferences"
180 \li "C:/Users/<USER>/AppData/Local", "C:/ProgramData"
181 \row \li DownloadLocation
182 \li "~/Downloads"
183 \li "C:/Users/<USER>/Downloads"
184 \row \li GenericCacheLocation
185 \li "~/Library/Caches", "/Library/Caches"
186 \li "C:/Users/<USER>/AppData/Local/cache"
187 \row \li AppDataLocation
188 \li "~/Library/Application Support/<APPNAME>", "/Library/Application Support/<APPNAME>". "<APPDIR>/../Resources"
189 \li "C:/Users/<USER>/AppData/Roaming/<APPNAME>", "C:/ProgramData/<APPNAME>", "<APPDIR>", "<APPDIR>/data", "<APPDIR>/data/<APPNAME>"
190 \row \li AppConfigLocation
191 \li "~/Library/Preferences/<APPNAME>"
192 \li "C:/Users/<USER>/AppData/Local/<APPNAME>", "C:/ProgramData/<APPNAME>"
193 \row \li PublicShareLocation
194 \li "~/Public"
195 \li "C:/Users/Public"
196 \row \li TemplatesLocation
197 \li "~/Templates"
198 \li "C:/Users/<USER>/AppData/Roaming/Microsoft/Windows/Templates"
199 \endtable
200
201 \table
202 \header \li Path type \li Linux and other UNIX operating systems
203 \row \li DesktopLocation
204 \li "~/Desktop"
205 \row \li DocumentsLocation
206 \li "~/Documents"
207 \row \li FontsLocation
208 \li "~/.fonts", "~/.local/share/fonts", "/usr/local/share/fonts", "/usr/share/fonts"
209 \row \li ApplicationsLocation
210 \li "~/.local/share/applications", "/usr/local/share/applications", "/usr/share/applications"
211 \row \li MusicLocation
212 \li "~/Music"
213 \row \li MoviesLocation
214 \li "~/Videos"
215 \row \li PicturesLocation
216 \li "~/Pictures"
217 \row \li TempLocation
218 \li "/tmp"
219 \row \li HomeLocation
220 \li "~"
221 \row \li AppLocalDataLocation
222 \li "~/.local/share/<APPNAME>", "/usr/local/share/<APPNAME>", "/usr/share/<APPNAME>"
223 \row \li CacheLocation
224 \li "~/.cache/<APPNAME>"
225 \row \li GenericDataLocation
226 \li "~/.local/share", "/usr/local/share", "/usr/share"
227 \row \li RuntimeLocation
228 \li "/run/user/<USER>"
229 \row \li ConfigLocation
230 \li "~/.config", "/etc/xdg"
231 \row \li GenericConfigLocation
232 \li "~/.config", "/etc/xdg"
233 \row \li DownloadLocation
234 \li "~/Downloads"
235 \row \li GenericCacheLocation
236 \li "~/.cache"
237 \row \li AppDataLocation
238 \li "~/.local/share/<APPNAME>", "/usr/local/share/<APPNAME>", "/usr/share/<APPNAME>"
239 \row \li AppConfigLocation
240 \li "~/.config/<APPNAME>", "/etc/xdg/<APPNAME>"
241 \row \li PublicShareLocation
242 \li "~/Public"
243 \row \li TemplatesLocation
244 \li "~/Templates"
245 \endtable
246
247 \table
248 \header \li Path type \li Android \li iOS
249 \row \li DesktopLocation
250 \li "<APPROOT>/files"
251 \li "<APPROOT>/Documents/Desktop"
252 \row \li DocumentsLocation
253 \li "<USER>/Documents" [*], "<USER>/<APPNAME>/Documents"
254 \li "<APPROOT>/Documents"
255 \row \li FontsLocation
256 \li "/system/fonts" (not writable)
257 \li "<APPROOT>/Library/Fonts"
258 \row \li ApplicationsLocation
259 \li not supported (directory not readable)
260 \li not supported
261 \row \li MusicLocation
262 \li "<USER>/Music" [*], "<USER>/<APPNAME>/Music"
263 \li "<APPROOT>/Documents/Music"
264 \row \li MoviesLocation
265 \li "<USER>/Movies" [*], "<USER>/<APPNAME>/Movies"
266 \li "<APPROOT>/Documents/Movies"
267 \row \li PicturesLocation
268 \li "<USER>/Pictures" [*], "<USER>/<APPNAME>/Pictures"
269 \li "<APPROOT>/Documents/Pictures", "assets-library://"
270 \row \li TempLocation
271 \li "<APPROOT>/cache"
272 \li "<APPROOT>/tmp"
273 \row \li HomeLocation
274 \li "<APPROOT>/files"
275 \li system defined
276 \row \li AppLocalDataLocation
277 \li "<APPROOT>/files", "<USER>/<APPNAME>/files"
278 \li "<APPROOT>/Library/Application Support"
279 \row \li CacheLocation
280 \li "<APPROOT>/cache", "<USER>/<APPNAME>/cache"
281 \li "<APPROOT>/Library/Caches"
282 \row \li GenericDataLocation
283 \li "<USER>" [*] or "<USER>/<APPNAME>/files"
284 \li "<APPROOT>/Library/Application Support"
285 \row \li RuntimeLocation
286 \li "<APPROOT>/cache"
287 \li not supported
288 \row \li ConfigLocation
289 \li "<APPROOT>/files/settings"
290 \li "<APPROOT>/Library/Preferences"
291 \row \li GenericConfigLocation
292 \li "<APPROOT>/files/settings" (there is no shared settings)
293 \li "<APPROOT>/Library/Preferences"
294 \row \li DownloadLocation
295 \li "<USER>/Downloads" [*], "<USER>/<APPNAME>/Downloads"
296 \li "<APPROOT>/Documents/Downloads"
297 \row \li GenericCacheLocation
298 \li "<APPROOT>/cache" (there is no shared cache)
299 \li "<APPROOT>/Library/Caches"
300 \row \li AppDataLocation
301 \li "<APPROOT>/files", "<USER>/<APPNAME>/files"
302 \li "<APPROOT>/Library/Application Support"
303 \row \li AppConfigLocation
304 \li "<APPROOT>/files/settings"
305 \li "<APPROOT>/Library/Preferences/<APPNAME>"
306 \row \li PublicShareLocation
307 \li not supported
308 \li not supported
309 \row \li TemplatesLocation
310 \li not supported
311 \li not supported
312 \endtable
313
314 In the table above, \c <APPNAME> is usually the organization name, the
315 application name, or both, or a unique name generated at packaging.
316 Similarly, <APPROOT> is the location where this application is installed
317 (often a sandbox). <APPDIR> is the directory containing the application
318 executable.
319
320 The paths above should not be relied upon, as they may change according to
321 OS configuration, locale, or they may change in future Qt versions.
322
323 \note On Android, applications with open files on the external storage (<USER> locations),
324 will be killed if the external storage is unmounted.
325
326 \note On Android 6.0 (API 23) or higher, the "WRITE_EXTERNAL_STORAGE" permission must be
327 requested at runtime when using QStandardPaths::writableLocation or QStandardPaths::standardLocations.
328
329 \note On Android, reading/writing to GenericDataLocation needs the READ_EXTERNAL_STORAGE/WRITE_EXTERNAL_STORAGE permission granted.
330
331 \note [*] On Android 11 and above, public directories are no longer directly accessible
332 in scoped storage mode. Thus, paths of the form \c "<USER>/DirName" are not returned.
333 Instead, you can use \l QFileDialog which uses the Storage Access Framework (SAF)
334 to access such directories.
335
336 \note On iOS, if you do pass \c {QStandardPaths::standardLocations(QStandardPaths::PicturesLocation).last()}
337 as argument to \l{QFileDialog::setDirectory()},
338 a native image picker dialog will be used for accessing the user's photo album.
339 The filename returned can be loaded using QFile and related APIs.
340 This feature was added in Qt 5.5.
341
342 \sa writableLocation(), standardLocations(), displayName(), locate(), locateAll()
343*/
344
345/*!
346 \fn QString QStandardPaths::writableLocation(StandardLocation type)
347
348 \include standardpath/functiondocs.qdocinc writableLocation
349*/
350
351
352/*!
353 \fn QStringList QStandardPaths::standardLocations(StandardLocation type)
354
355 \include standardpath/functiondocs.qdocinc standardLocations
356
357 \sa writableLocation()
358 */
359
360/*!
361 \enum QStandardPaths::LocateOption
362
363 This enum describes the different flags that can be used for
364 controlling the behavior of QStandardPaths::locate and
365 QStandardPaths::locateAll.
366
367 \value LocateFile return only files
368 \value LocateDirectory return only directories
369*/
370
371static bool existsAsSpecified(const QString &path, QStandardPaths::LocateOptions options)
372{
373 if (options & QStandardPaths::LocateDirectory)
374 return QDir(path).exists();
375 return QFileInfo(path).isFile();
376}
377
378/*!
379 \include standardpath/functiondocs.qdocinc locate
380 */
381QString QStandardPaths::locate(StandardLocation type, const QString &fileName, LocateOptions options)
382{
383 const QStringList &dirs = standardLocations(type);
384 for (QStringList::const_iterator dir = dirs.constBegin(); dir != dirs.constEnd(); ++dir) {
385 const QString path = *dir + u'/' + fileName;
386 if (existsAsSpecified(path, options))
387 return path;
388 }
389 return QString();
390}
391
392/*!
393 \include standardpath/functiondocs.qdocinc locateAll
394 */
395QStringList QStandardPaths::locateAll(StandardLocation type, const QString &fileName, LocateOptions options)
396{
397 const QStringList &dirs = standardLocations(type);
398 QStringList result;
399 for (QStringList::const_iterator dir = dirs.constBegin(); dir != dirs.constEnd(); ++dir) {
400 const QString path = *dir + u'/' + fileName;
401 if (existsAsSpecified(path, options))
402 result.append(t: path);
403 }
404 return result;
405}
406
407#ifdef Q_OS_WIN
408static QStringList executableExtensions()
409{
410 // If %PATHEXT% does not contain .exe, it is either empty, malformed, or distorted in ways that we cannot support, anyway.
411 const QStringList pathExt = QString::fromLocal8Bit(qgetenv("PATHEXT")).toLower().split(u';');
412 return pathExt.contains(".exe"_L1, Qt::CaseInsensitive) ?
413 pathExt : QStringList{".exe"_L1, ".com"_L1, ".bat"_L1, ".cmd"_L1};
414}
415#endif
416
417static QString checkExecutable(const QString &path)
418{
419 const QFileInfo info(path);
420 if (info.isBundle())
421 return info.bundleName();
422 if (info.isFile() && info.isExecutable())
423 return QDir::cleanPath(path);
424 return QString();
425}
426
427static inline QString searchExecutable(const QStringList &searchPaths,
428 const QString &executableName)
429{
430 const QDir currentDir = QDir::current();
431 for (const QString &searchPath : searchPaths) {
432 const QString candidate = currentDir.absoluteFilePath(fileName: searchPath + u'/' + executableName);
433 const QString absPath = checkExecutable(path: candidate);
434 if (!absPath.isEmpty())
435 return absPath;
436 }
437 return QString();
438}
439
440#ifdef Q_OS_WIN
441
442// Find executable appending candidate suffixes, used for suffix-less executables
443// on Windows.
444static inline QString
445 searchExecutableAppendSuffix(const QStringList &searchPaths,
446 const QString &executableName,
447 const QStringList &suffixes)
448{
449 const QDir currentDir = QDir::current();
450 for (const QString &searchPath : searchPaths) {
451 const QString candidateRoot = currentDir.absoluteFilePath(searchPath + u'/' + executableName);
452 for (const QString &suffix : suffixes) {
453 const QString absPath = checkExecutable(candidateRoot + suffix);
454 if (!absPath.isEmpty())
455 return absPath;
456 }
457 }
458 return QString();
459}
460
461#endif // Q_OS_WIN
462
463/*!
464 \include standardpath/functiondocs.qdocinc findExecutable
465 */
466QString QStandardPaths::findExecutable(const QString &executableName, const QStringList &paths)
467{
468 if (QFileInfo(executableName).isAbsolute())
469 return checkExecutable(path: executableName);
470
471 QStringList searchPaths = paths;
472 if (paths.isEmpty()) {
473 QByteArray pEnv = qgetenv(varName: "PATH");
474 if (Q_UNLIKELY(pEnv.isNull())) {
475 // Get a default path. POSIX.1 does not actually require this, but
476 // most Unix libc fall back to confstr(_CS_PATH) if the PATH
477 // environment variable isn't set. Let's try to do the same.
478#if defined(_PATH_DEFPATH)
479 // BSD API.
480 pEnv = _PATH_DEFPATH;
481#elif defined(_CS_PATH)
482 // POSIX API.
483 size_t n = confstr(_CS_PATH, nullptr, 0);
484 if (n) {
485 pEnv.resize(n);
486 // size()+1 is ok because QByteArray always has an extra NUL-terminator
487 confstr(_CS_PATH, pEnv.data(), pEnv.size() + 1);
488 }
489#else
490 // Windows SDK's execvpe() does not have a fallback, so we won't
491 // apply one either.
492#endif
493 }
494
495 // Remove trailing slashes, which occur on Windows.
496 const QStringList rawPaths = QString::fromLocal8Bit(ba: pEnv.constData()).split(
497 sep: QDir::listSeparator(), behavior: Qt::SkipEmptyParts);
498 searchPaths.reserve(asize: rawPaths.size());
499 for (const QString &rawPath : rawPaths) {
500 QString cleanPath = QDir::cleanPath(path: rawPath);
501 if (cleanPath.size() > 1 && cleanPath.endsWith(c: u'/'))
502 cleanPath.truncate(pos: cleanPath.size() - 1);
503 searchPaths.push_back(t: cleanPath);
504 }
505 }
506
507#ifdef Q_OS_WIN
508 // On Windows, if the name does not have a suffix or a suffix not
509 // in PATHEXT ("xx.foo"), append suffixes from PATHEXT.
510 static const QStringList executable_extensions = executableExtensions();
511 if (executableName.contains(u'.')) {
512 const QString suffix = QFileInfo(executableName).suffix();
513 if (suffix.isEmpty() || !executable_extensions.contains(u'.' + suffix, Qt::CaseInsensitive))
514 return searchExecutableAppendSuffix(searchPaths, executableName, executable_extensions);
515 } else {
516 return searchExecutableAppendSuffix(searchPaths, executableName, executable_extensions);
517 }
518#endif
519 return searchExecutable(searchPaths, executableName);
520}
521
522/*!
523 \include standardpath/functiondocs.qdocinc displayName
524*/
525
526#if !defined(Q_OS_DARWIN) && !defined(QT_BOOTSTRAPPED)
527QString QStandardPaths::displayName(StandardLocation type)
528{
529 switch (type) {
530 case DesktopLocation:
531 return QCoreApplication::translate(context: "QStandardPaths", key: "Desktop");
532 case DocumentsLocation:
533 return QCoreApplication::translate(context: "QStandardPaths", key: "Documents");
534 case FontsLocation:
535 return QCoreApplication::translate(context: "QStandardPaths", key: "Fonts");
536 case ApplicationsLocation:
537 return QCoreApplication::translate(context: "QStandardPaths", key: "Applications");
538 case MusicLocation:
539 return QCoreApplication::translate(context: "QStandardPaths", key: "Music");
540 case MoviesLocation:
541 return QCoreApplication::translate(context: "QStandardPaths", key: "Movies");
542 case PicturesLocation:
543 return QCoreApplication::translate(context: "QStandardPaths", key: "Pictures");
544 case TempLocation:
545 return QCoreApplication::translate(context: "QStandardPaths", key: "Temporary Directory");
546 case HomeLocation:
547 return QCoreApplication::translate(context: "QStandardPaths", key: "Home");
548 case AppLocalDataLocation:
549 return QCoreApplication::translate(context: "QStandardPaths", key: "Application Data");
550 case CacheLocation:
551 return QCoreApplication::translate(context: "QStandardPaths", key: "Cache");
552 case GenericDataLocation:
553 return QCoreApplication::translate(context: "QStandardPaths", key: "Shared Data");
554 case RuntimeLocation:
555 return QCoreApplication::translate(context: "QStandardPaths", key: "Runtime");
556 case ConfigLocation:
557 return QCoreApplication::translate(context: "QStandardPaths", key: "Configuration");
558 case GenericConfigLocation:
559 return QCoreApplication::translate(context: "QStandardPaths", key: "Shared Configuration");
560 case GenericCacheLocation:
561 return QCoreApplication::translate(context: "QStandardPaths", key: "Shared Cache");
562 case DownloadLocation:
563 return QCoreApplication::translate(context: "QStandardPaths", key: "Download");
564 case AppDataLocation:
565 case AppConfigLocation:
566 return QCoreApplication::translate(context: "QStandardPaths", key: "Application Configuration");
567 case PublicShareLocation:
568 return QCoreApplication::translate(context: "QStandardPaths", key: "Public");
569 case TemplatesLocation:
570 return QCoreApplication::translate(context: "QStandardPaths", key: "Templates");
571 }
572 // not reached
573 return QString();
574}
575#endif
576
577/*!
578 \fn void QStandardPaths::setTestModeEnabled(bool testMode)
579
580 \include standardpath/functiondocs.qdocinc setTestModeEnabled
581*/
582
583Q_CONSTINIT static bool qsp_testMode = false;
584
585void QStandardPaths::setTestModeEnabled(bool testMode)
586{
587 qsp_testMode = testMode;
588}
589
590/*!
591 \fn void QStandardPaths::isTestModeEnabled()
592
593 \internal
594
595 Returns \c true if test mode is enabled in QStandardPaths; otherwise returns \c false.
596*/
597
598bool QStandardPaths::isTestModeEnabled()
599{
600 return qsp_testMode;
601}
602
603
604QT_END_NAMESPACE
605
606#ifndef QT_NO_QOBJECT
607#include "moc_qstandardpaths.cpp"
608#endif
609
610#endif // QT_NO_STANDARDPATHS
611

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