diff options
author | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2021-05-18 17:27:40 +0300 |
---|---|---|
committer | Assam Boudjelthia <assam.boudjelthia@qt.io> | 2021-06-02 08:19:47 +0000 |
commit | ed431caa27672427d28f8ecde667a3a064ddda7e (patch) | |
tree | 38b816cd447e80d0ff2c34d3f3710af0ce8e4bf3 /src/plugins | |
parent | 2a6e30c9c4b7d367d8be502e3444ee3768ea8db5 (diff) |
Android: fix mimetype/namefilters handling for FileDialog
Android file dialog uses setType() to set the main mimetype for the
dialog if no mimetype or multiple (+1) mimetypes are provided, then
the additional mimetypes can be provided via EXTRA_MIME_TYPES flag.
The problem was that the mimetypes deduction from the namefilters was:
* the namefilter used was empty, now we take the first item
nameFilters(), because mimetypes cannot be changed once the dialog is
open anyway.
* The regex extraction was getting a namefilter ending with an empty
char and that was giving a mimetype of any format thus making it show
all possible files.
Pick-to: 6.1 5.15
Fixes: QTBUG-83089
Change-Id: Ifaef40c2186732ad3a604d28e086409c35dafacf
Reviewed-by: Rami Potinkara <rami.potinkara@qt.io>
Reviewed-by: Andy Shaw <andy.shaw@qt.io>
Diffstat (limited to 'src/plugins')
-rw-r--r-- | src/plugins/platforms/android/qandroidplatformfiledialoghelper.cpp | 17 |
1 files changed, 9 insertions, 8 deletions
diff --git a/src/plugins/platforms/android/qandroidplatformfiledialoghelper.cpp b/src/plugins/platforms/android/qandroidplatformfiledialoghelper.cpp index 0b539d1af3..7741fc755d 100644 --- a/src/plugins/platforms/android/qandroidplatformfiledialoghelper.cpp +++ b/src/plugins/platforms/android/qandroidplatformfiledialoghelper.cpp @@ -148,10 +148,10 @@ QStringList nameFilterExtensions(const QString nameFilters) { QStringList ret; #if QT_CONFIG(regularexpression) - QRegularExpression re("(\\*\\.?\\w*)"); + QRegularExpression re("(\\*\\.[a-z .]+)"); QRegularExpressionMatchIterator i = re.globalMatch(nameFilters); while (i.hasNext()) - ret << i.next().captured(1); + ret << i.next().captured(1).trimmed(); #endif // QT_CONFIG(regularexpression) ret.removeAll("*"); return ret; @@ -160,23 +160,24 @@ QStringList nameFilterExtensions(const QString nameFilters) void QAndroidPlatformFileDialogHelper::setMimeTypes() { QStringList mimeTypes = options()->mimeTypeFilters(); - const QString nameFilter = options()->initiallySelectedNameFilter(); + const QStringList nameFilters = options()->nameFilters(); + const QString nameFilter = nameFilters.isEmpty() ? QString() : nameFilters.first(); - if (mimeTypes.isEmpty() && !nameFilter.isEmpty()) { + if (!nameFilter.isEmpty()) { QMimeDatabase db; for (const QString &filter : nameFilterExtensions(nameFilter)) - mimeTypes.append(db.mimeTypeForFile(filter).name()); + mimeTypes.append(db.mimeTypeForFile(filter, QMimeDatabase::MatchExtension).name()); } - QString type = !mimeTypes.isEmpty() ? mimeTypes.at(0) : QLatin1String("*/*"); + const QString initialType = mimeTypes.size() == 1 ? mimeTypes.at(0) : QLatin1String("*/*"); m_intent.callObjectMethod("setType", "(Ljava/lang/String;)Landroid/content/Intent;", - QJniObject::fromString(type).object()); + QJniObject::fromString(initialType).object()); if (!mimeTypes.isEmpty()) { const QJniObject extraMimeType = QJniObject::getStaticObjectField( JniIntentClass, "EXTRA_MIME_TYPES", "Ljava/lang/String;"); - QJniObject mimeTypesArray = QJniObject::callStaticObjectMethod( + const QJniObject mimeTypesArray = QJniObject::callStaticObjectMethod( "org/qtproject/qt/android/QtNative", "getStringArray", "(Ljava/lang/String;)[Ljava/lang/String;", |