aboutsummaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorIvan Solovev <ivan.solovev@qt.io>2022-03-15 11:55:33 +0100
committerQt Cherry-pick Bot <cherrypick_bot@qt-project.org>2022-03-18 03:53:15 +0000
commitb844ee29ddc1e3f1f9daec6d145becca293f950b (patch)
tree1fe1a953461bf35c80c2c40aed76a966d7a73436 /src
parentf111f419df98ff0a34bf3166c37afc614793bc10 (diff)
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 <assam.boudjelthia@qt.io> Reviewed-by: Mitch Curtis <mitch.curtis@qt.io> (cherry picked from commit d10d1f97d0aadb1f26e99db1ef2c1c3d53458a38) Reviewed-by: Qt Cherry-pick Bot <cherrypick_bot@qt-project.org>
Diffstat (limited to 'src')
-rw-r--r--src/labs/platform/qquicklabsplatformfiledialog.cpp7
-rw-r--r--src/quickdialogs2/quickdialogs2/qquickfiledialog.cpp7
2 files changed, 12 insertions, 2 deletions
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;
}