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