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