summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--src/core/file_picker_controller.cpp36
-rw-r--r--tests/auto/quick/qmltests/data/tst_filePicker.qml52
2 files changed, 39 insertions, 49 deletions
diff --git a/src/core/file_picker_controller.cpp b/src/core/file_picker_controller.cpp
index 3e64afd20..28ededf37 100644
--- a/src/core/file_picker_controller.cpp
+++ b/src/core/file_picker_controller.cpp
@@ -64,12 +64,19 @@ FilePickerController::~FilePickerController() = default;
void FilePickerController::accepted(const QStringList &files)
{
QStringList stringList;
-
- for (const QString &file : files) {
- if (QDir(file).isAbsolute())
- stringList.append(file);
- else
- qWarning("Ignore invalid item in FilePickerController::accepted(QStringList): %s", qPrintable(file));
+ stringList.reserve(files.count());
+
+ for (const QString &urlString : files) {
+ // We accept strings on both absolute-path and file-URL form:
+ if (QDir::isAbsolutePath(urlString)) {
+ stringList.append(QDir::fromNativeSeparators(urlString));
+ } else {
+ QUrl url(urlString, QUrl::StrictMode);
+ if (url.isLocalFile() && QDir::isAbsolutePath(url.toLocalFile()))
+ stringList.append(url.toLocalFile());
+ else
+ qWarning("Ignoring invalid item in FilePickerController::accepted(QStringList): %s", qPrintable(urlString));
+ }
}
FilePickerController::filesSelectedInChooser(stringList);
@@ -77,21 +84,10 @@ void FilePickerController::accepted(const QStringList &files)
void FilePickerController::accepted(const QVariant &files)
{
- QStringList stringList;
- QList<QUrl> urlList = QUrl::fromStringList(files.toStringList());
-
- if (urlList.isEmpty()) {
- FilePickerController::accepted(stringList);
- } else {
- for (const QUrl &url : qAsConst(urlList)) {
- if (url.isValid() && url.scheme() == "file" && !url.path().isEmpty())
- stringList.append(url.path());
- else
- qWarning("Ignore invalid item in FilePickerController::accepted(QVariant): %s", qPrintable(url.toString()));
- }
+ if (!files.canConvert(QVariant::StringList))
+ qWarning("An unhandled type '%s' was provided in FilePickerController::accepted(QVariant)", files.typeName());
- FilePickerController::accepted(stringList);
- }
+ accepted(files.toStringList());
}
void FilePickerController::rejected()
diff --git a/tests/auto/quick/qmltests/data/tst_filePicker.qml b/tests/auto/quick/qmltests/data/tst_filePicker.qml
index 2f813b966..d2815e3a8 100644
--- a/tests/auto/quick/qmltests/data/tst_filePicker.qml
+++ b/tests/auto/quick/qmltests/data/tst_filePicker.qml
@@ -72,27 +72,25 @@ TestWebEngineView {
function test_acceptSingleFileSelection_data() {
return [
- { tag: "/test.txt)", input: "/test.txt", passDefaultDialog: false, passCustomDialog: true },
- { tag: "/tést.txt", input: "/tést.txt", passDefaultDialog: false, passCustomDialog: true },
- { tag: "file:///test.txt", input: "file:///test.txt", passDefaultDialog: true, passCustomDialog: false },
- { tag: "file:///tést.txt", input: "file:///tést.txt", passDefaultDialog: true, passCustomDialog: false },
- { tag: "file:///t%C3%A9st.txt", input: "file:///t%C3%A9st.txt", passDefaultDialog: true, passCustomDialog: false },
- { tag: "file://test.txt", input: "file://test.txt", passDefaultDialog: false, passCustomDialog: false },
- { tag: "file:/test.txt", input: "file:/test.txt", passDefaultDialog: true, passCustomDialog: false },
- { tag: "file:test//test.txt", input: "file:test//test.txt", passDefaultDialog: false, passCustomDialog: false },
- { tag: "http://test.txt", input: "http://test.txt", passDefaultDialog: false, passCustomDialog: false },
- { tag: "qrc:/test.txt", input: "qrc:/test.txt", passDefaultDialog: false, passCustomDialog: false },
+ { tag: "/test.txt", input: "/test.txt", expected: "test.txt" },
+ { tag: "test.txt", input: "test.txt", expected: "Failed to Upload" },
+ { tag: "/tést.txt", input: "/tést.txt", expected: "tést.txt" },
+ { tag: "/t%65st.txt", input: "/t%65st.txt", expected: "t%65st.txt" },
+ { tag: "file:///test.txt", input: "file:///test.txt", expected: "test.txt" },
+ { tag: "file:///tést.txt", input: "file:///tést.txt", expected: "tést.txt" },
+ { tag: "file:///t%65st.txt", input: "file:///t%65st.txt", expected: "test.txt" },
+ { tag: "file://test.txt", input: "file://test.txt", expected: "test.txt" },
+ { tag: "file:/test.txt", input: "file:/test.txt", expected: "test.txt"},
+ { tag: "file:test//test.txt", input: "file:test//test.txt", expected: "Failed to Upload" },
+ { tag: "http://test.txt", input: "http://test.txt", expected: "Failed to Upload" },
+ { tag: "qrc:/test.txt", input: "qrc:/test.txt", expected: "Failed to Upload" },
];
}
function test_acceptSingleFileSelection(row) {
var expectedFileName;
- // Default dialog (expects URL).
- expectedFileName = "Failed to Upload";
- if (row.passDefaultDialog)
- expectedFileName = row.input.slice(row.input.lastIndexOf('/') + 1);
-
+ // Default dialog
webEngineView.url = Qt.resolvedUrl("singlefileupload.html");
verify(webEngineView.waitForLoadSucceeded());
@@ -101,16 +99,12 @@ TestWebEngineView {
keyClick(Qt.Key_Enter); // Focus is on the button. Open FileDialog.
tryCompare(FilePickerParams, "filePickerOpened", true);
- tryCompare(webEngineView, "title", decodeURIComponent(expectedFileName));
+ tryCompare(webEngineView, "title", row.expected);
- // Custom dialog (expects absolute path).
+ // Custom dialog
var finished = false;
- expectedFileName = "Failed to Upload";
- if (row.passCustomDialog)
- expectedFileName = row.input.slice(row.input.lastIndexOf('/') + 1);
-
function acceptedFileHandler(request) {
request.accepted = true;
request.dialogAccept(row.input);
@@ -123,7 +117,7 @@ TestWebEngineView {
keyClick(Qt.Key_Enter); // Focus is on the button. Open FileDialog.
tryVerify(function() { return finished; });
- tryCompare(webEngineView, "title", expectedFileName);
+ tryCompare(webEngineView, "title", row.expected);
webEngineView.fileDialogRequested.disconnect(acceptedFileHandler);
}
@@ -165,14 +159,14 @@ TestWebEngineView {
function test_acceptMultipleFilesWithCustomDialog_data() {
return [
- { tag: "path", input: ["/test1.txt", "/test2.txt"], expectedValueForDefaultDialog: "Failed to Upload", expectedValueForCustomDialog: "test1.txt,test2.txt" },
- { tag: "file", input: ["file:///test1.txt", "file:///test2.txt"], expectedValueForDefaultDialog: "test1.txt,test2.txt", expectedValueForCustomDialog: "Failed to Upload" },
- { tag: "mixed", input: ["file:///test1.txt", "/test2.txt"], expectedValueForDefaultDialog: "test1.txt", expectedValueForCustomDialog: "test2.txt" },
+ { tag: "path", input: ["/test1.txt", "/test2.txt"], expectedValue: "test1.txt,test2.txt" },
+ { tag: "file", input: ["file:///test1.txt", "file:/test2.txt"], expectedValue: "test1.txt,test2.txt" },
+ { tag: "mixed", input: ["file:///test1.txt", "/test2.txt"], expectedValue: "test1.txt,test2.txt" },
];
}
function test_acceptMultipleFilesWithCustomDialog(row) {
- // Default dialog (expects URL).
+ // Default dialog
webEngineView.url = Qt.resolvedUrl("multifileupload.html");
verify(webEngineView.waitForLoadSucceeded());
@@ -181,10 +175,10 @@ TestWebEngineView {
keyClick(Qt.Key_Enter); // Focus is on the button. Open FileDialog.
tryCompare(FilePickerParams, "filePickerOpened", true);
- tryCompare(webEngineView, "title", row.expectedValueForDefaultDialog);
+ tryCompare(webEngineView, "title", row.expectedValue);
- // Custom dialog (expects absolute path).
+ // Custom dialog
var finished = false;
function acceptedFileHandler(request) {
@@ -199,7 +193,7 @@ TestWebEngineView {
keyClick(Qt.Key_Enter); // Focus is on the button. Open FileDialog.
tryVerify(function() { return finished; });
- tryCompare(webEngineView, "title", row.expectedValueForCustomDialog);
+ tryCompare(webEngineView, "title", row.expectedValue);
webEngineView.fileDialogRequested.disconnect(acceptedFileHandler);
}
}