diff options
author | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2023-02-14 14:24:46 +0200 |
---|---|---|
committer | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2023-03-02 15:53:27 +0200 |
commit | 90a4d74abcb9d0c1c153c64838cbc3f87922bfe9 (patch) | |
tree | 81318df8a80149ddff2f76e5744ee5fc0bc4bb38 | |
parent | 640769733a030379dd4243ed5278a472b4bfe233 (diff) |
Android: avoid duplicate paths from QStandardPaths::standardLocations()
Don't return duplicate path entries from calling
QStandardPaths::standardLocations() and as a pass by no empty entries
either.
Task-number: QTBUG-104892
Change-Id: If05b20d2c07d75428cb572d9549a39cf21bdef99
Reviewed-by: Ville Voutilainen <ville.voutilainen@qt.io>
(cherry picked from commit 30014ed850bbe62005b4aa789586b01c1281cab4)
-rw-r--r-- | src/corelib/io/qstandardpaths_android.cpp | 86 |
1 files changed, 37 insertions, 49 deletions
diff --git a/src/corelib/io/qstandardpaths_android.cpp b/src/corelib/io/qstandardpaths_android.cpp index c26a5d30ce..efc3661e23 100644 --- a/src/corelib/io/qstandardpaths_android.cpp +++ b/src/corelib/io/qstandardpaths_android.cpp @@ -175,59 +175,47 @@ QString QStandardPaths::writableLocation(StandardLocation type) QStringList QStandardPaths::standardLocations(StandardLocation type) { - if (type == MusicLocation) { - return QStringList() << writableLocation(type) - << getExternalFilesDir("DIRECTORY_MUSIC") - << getExternalFilesDir("DIRECTORY_PODCASTS") - << getExternalFilesDir("DIRECTORY_NOTIFICATIONS") - << getExternalFilesDir("DIRECTORY_ALARMS"); - } - - if (type == MoviesLocation) { - return QStringList() << writableLocation(type) - << getExternalFilesDir("DIRECTORY_MOVIES"); - } - - if (type == PicturesLocation) { - return QStringList() << writableLocation(type) - << getExternalFilesDir("DIRECTORY_PICTURES"); - } - - if (type == DocumentsLocation) { - return QStringList() << writableLocation(type) - << getExternalFilesDir("DIRECTORY_DOCUMENTS"); - } - - if (type == DownloadLocation) { - return QStringList() << writableLocation(type) - << getExternalFilesDir("DIRECTORY_DOWNLOADS"); - } - - if (type == AppDataLocation || type == AppLocalDataLocation) { - return QStringList() << writableLocation(type) - << getExternalFilesDir(); - } - - if (type == CacheLocation) { - return QStringList() << writableLocation(type) - << getExternalCacheDir(); - } + QStringList locations; - if (type == FontsLocation) { + if (type == MusicLocation) { + locations << getExternalFilesDir("DIRECTORY_MUSIC") + << getExternalFilesDir("DIRECTORY_PODCASTS") + << getExternalFilesDir("DIRECTORY_NOTIFICATIONS") + << getExternalFilesDir("DIRECTORY_ALARMS"); + } else if (type == MoviesLocation) { + locations << getExternalFilesDir("DIRECTORY_MOVIES"); + } else if (type == PicturesLocation) { + locations << getExternalFilesDir("DIRECTORY_PICTURES"); + } else if (type == DocumentsLocation) { + locations << getExternalFilesDir("DIRECTORY_DOCUMENTS"); + } else if (type == DownloadLocation) { + locations << getExternalFilesDir("DIRECTORY_DOWNLOADS"); + } else if (type == AppDataLocation || type == AppLocalDataLocation) { + locations << getExternalFilesDir(); + } else if (type == CacheLocation) { + locations << getExternalCacheDir(); + } else if (type == FontsLocation) { QString &fontLocation = (*androidDirCache)[QStringLiteral("FONT_LOCATION")]; - if (!fontLocation.isEmpty()) - return QStringList(fontLocation); - - const QByteArray ba = qgetenv("QT_ANDROID_FONT_LOCATION"); - if (!ba.isEmpty()) - return QStringList((fontLocation = QDir::cleanPath(QString::fromLocal8Bit(ba)))); - - // Don't cache the fallback, as we might just have been called before - // QT_ANDROID_FONT_LOCATION has been set. - return QStringList("/system/fonts"_L1); + if (!fontLocation.isEmpty()) { + locations << fontLocation; + } else { + const QByteArray ba = qgetenv("QT_ANDROID_FONT_LOCATION"); + if (!ba.isEmpty()) { + locations << (fontLocation = QDir::cleanPath(QString::fromLocal8Bit(ba))); + } else { + // Don't cache the fallback, as we might just have been called before + // QT_ANDROID_FONT_LOCATION has been set. + locations << "/system/fonts"_L1; + } + } } - return QStringList(writableLocation(type)); + const QString writable = writableLocation(type); + if (!writable.isEmpty()) + locations.prepend(writable); + + locations.removeDuplicates(); + return locations; } QT_END_NAMESPACE |