From b844ee29ddc1e3f1f9daec6d145becca293f950b Mon Sep 17 00:00:00 2001 From: Ivan Solovev Date: Tue, 15 Mar 2022 11:55:33 +0100 Subject: FileDialog: do not add default suffix when content scheme is used On Android when a file is selected using the default file manager, the selected file is reported using the url with "content" scheme. This url does not use file suffixes. Before this patch, if the FileDialog had a defaultSuffix specified, that suffix was added to the returned content url, and as a result the file could not be found. This problem exists FileDialog from both QtQuick.Dialogs and Qt.labs.platforms, so this patch implements the similar fix in both of them. Fixes: QTBUG-94391 Change-Id: Ic6ba95e301857d9b72ee6f5ddb819b9aae9e66e3 Reviewed-by: Assam Boudjelthia Reviewed-by: Mitch Curtis (cherry picked from commit d10d1f97d0aadb1f26e99db1ef2c1c3d53458a38) Reviewed-by: Qt Cherry-pick Bot --- src/labs/platform/qquicklabsplatformfiledialog.cpp | 7 ++++++- src/quickdialogs2/quickdialogs2/qquickfiledialog.cpp | 7 ++++++- 2 files changed, 12 insertions(+), 2 deletions(-) (limited to 'src') diff --git a/src/labs/platform/qquicklabsplatformfiledialog.cpp b/src/labs/platform/qquicklabsplatformfiledialog.cpp index 1650d043ec..d16f8f7f92 100644 --- a/src/labs/platform/qquicklabsplatformfiledialog.cpp +++ b/src/labs/platform/qquicklabsplatformfiledialog.cpp @@ -554,8 +554,13 @@ QUrl QQuickLabsPlatformFileDialog::addDefaultSuffix(const QUrl &file) const QUrl url = file; const QString path = url.path(); const QString suffix = m_options->defaultSuffix(); - if (!suffix.isEmpty() && !path.endsWith(QLatin1Char('/')) && path.lastIndexOf(QLatin1Char('.')) == -1) + // Urls with "content" scheme do not require suffixes. Such schemes are + // used on Android. + const bool isContentScheme = url.scheme() == u"content"_qs; + if (!isContentScheme && !suffix.isEmpty() && !path.endsWith(QLatin1Char('/')) + && path.lastIndexOf(QLatin1Char('.')) == -1) { url.setPath(path + QLatin1Char('.') + suffix); + } return url; } diff --git a/src/quickdialogs2/quickdialogs2/qquickfiledialog.cpp b/src/quickdialogs2/quickdialogs2/qquickfiledialog.cpp index da899140b7..5d4023a8cf 100644 --- a/src/quickdialogs2/quickdialogs2/qquickfiledialog.cpp +++ b/src/quickdialogs2/quickdialogs2/qquickfiledialog.cpp @@ -576,8 +576,13 @@ QUrl QQuickFileDialog::addDefaultSuffix(const QUrl &file) const QUrl url = file; const QString path = url.path(); const QString suffix = m_options->defaultSuffix(); - if (!suffix.isEmpty() && !path.endsWith(QLatin1Char('/')) && path.lastIndexOf(QLatin1Char('.')) == -1) + // Urls with "content" scheme do not require suffixes. Such schemes are + // used on Android. + const bool isContentScheme = url.scheme() == u"content"_qs; + if (!isContentScheme && !suffix.isEmpty() && !path.endsWith(QLatin1Char('/')) + && path.lastIndexOf(QLatin1Char('.')) == -1) { url.setPath(path + QLatin1Char('.') + suffix); + } return url; } -- cgit v1.2.3