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