285 lines
10 KiB
Diff
285 lines
10 KiB
Diff
|
From 2dcade09fca04dc45848a5a653b160e96aaab1e8 Mon Sep 17 00:00:00 2001
|
||
|
From: David Faure <david.faure@kdab.com>
|
||
|
Date: Wed, 9 Jul 2014 12:01:05 +0200
|
||
|
Subject: [PATCH 4/4] QFileDialog: implement getOpenFileUrl and friends for
|
||
|
real
|
||
|
|
||
|
i.e. make them support remote URLs.
|
||
|
To avoid code duplication, getOpenFileName/getSaveFileName/getExistingDirectory
|
||
|
are now implemented in terms of getOpenFileUrl/getSaveFileUrl/getExistingDirectoryUrl.
|
||
|
|
||
|
Change-Id: If409ac9ab72c2a65f04e2ef1dc28e7d47bbcd73c
|
||
|
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@digia.com>
|
||
|
(cherry picked from commit 1a9701fe81c39450822c0d4b51c11444380a2fe4)
|
||
|
|
||
|
Conflicts:
|
||
|
src/widgets/dialogs/qfiledialog.cpp
|
||
|
---
|
||
|
src/widgets/dialogs/qfiledialog.cpp | 199 +++++++++++++++---------------------
|
||
|
1 file changed, 81 insertions(+), 118 deletions(-)
|
||
|
|
||
|
diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp
|
||
|
index ab0361a..bc4a0a3 100644
|
||
|
--- a/src/widgets/dialogs/qfiledialog.cpp
|
||
|
+++ b/src/widgets/dialogs/qfiledialog.cpp
|
||
|
@@ -2110,35 +2110,9 @@ QString QFileDialog::getOpenFileName(QWidget *parent,
|
||
|
QString *selectedFilter,
|
||
|
Options options)
|
||
|
{
|
||
|
- QFileDialogArgs args;
|
||
|
- args.parent = parent;
|
||
|
- args.caption = caption;
|
||
|
- args.directory = QFileDialogPrivate::workingDirectory(QUrl::fromLocalFile(dir));
|
||
|
- args.selection = QFileDialogPrivate::initialSelection(QUrl::fromLocalFile(dir));
|
||
|
- args.filter = filter;
|
||
|
- args.mode = ExistingFile;
|
||
|
- args.options = options;
|
||
|
-#if defined(Q_WS_WIN)
|
||
|
- if (QGuiApplicationPrivate::platformIntegration()->usePlatformNativeDialog() && !(args.options & DontUseNativeDialog)) {
|
||
|
- return qt_win_get_open_file_name(args, &(args.directory), selectedFilter);
|
||
|
- }
|
||
|
-#endif
|
||
|
-
|
||
|
- // create a qt dialog
|
||
|
- QFileDialog dialog(args);
|
||
|
- if (selectedFilter && !selectedFilter->isEmpty())
|
||
|
- dialog.selectNameFilter(*selectedFilter);
|
||
|
- if (dialog.exec() == QDialog::Accepted) {
|
||
|
- if (selectedFilter)
|
||
|
- *selectedFilter = dialog.selectedNameFilter();
|
||
|
- return dialog.selectedFiles().value(0);
|
||
|
- }
|
||
|
- return QString();
|
||
|
-}
|
||
|
-
|
||
|
-static inline QUrl dialogResultToUrl(const QString &file)
|
||
|
-{
|
||
|
- return file.isEmpty() ? QUrl() : QUrl::fromLocalFile(file);
|
||
|
+ const QStringList schemes = QStringList(QStringLiteral("file"));
|
||
|
+ const QUrl selectedUrl = getOpenFileUrl(parent, caption, QUrl::fromLocalFile(dir), filter, selectedFilter, options, schemes);
|
||
|
+ return selectedUrl.toLocalFile();
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
@@ -2176,10 +2150,26 @@ QUrl QFileDialog::getOpenFileUrl(QWidget *parent,
|
||
|
Options options,
|
||
|
const QStringList &supportedSchemes)
|
||
|
{
|
||
|
- Q_UNUSED(supportedSchemes);
|
||
|
+ Q_UNUSED(supportedSchemes); // TODO
|
||
|
+
|
||
|
+ QFileDialogArgs args;
|
||
|
+ args.parent = parent;
|
||
|
+ args.caption = caption;
|
||
|
+ args.directory = QFileDialogPrivate::workingDirectory(dir);
|
||
|
+ args.selection = QFileDialogPrivate::initialSelection(dir);
|
||
|
+ args.filter = filter;
|
||
|
+ args.mode = ExistingFile;
|
||
|
+ args.options = options;
|
||
|
|
||
|
- // Falls back to local file
|
||
|
- return dialogResultToUrl(getOpenFileName(parent, caption, dir.toLocalFile(), filter, selectedFilter, options));
|
||
|
+ QFileDialog dialog(args);
|
||
|
+ if (selectedFilter && !selectedFilter->isEmpty())
|
||
|
+ dialog.selectNameFilter(*selectedFilter);
|
||
|
+ if (dialog.exec() == QDialog::Accepted) {
|
||
|
+ if (selectedFilter)
|
||
|
+ *selectedFilter = dialog.selectedNameFilter();
|
||
|
+ return dialog.selectedUrls().value(0);
|
||
|
+ }
|
||
|
+ return QUrl();
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
@@ -2238,31 +2228,12 @@ QStringList QFileDialog::getOpenFileNames(QWidget *parent,
|
||
|
QString *selectedFilter,
|
||
|
Options options)
|
||
|
{
|
||
|
- QFileDialogArgs args;
|
||
|
- args.parent = parent;
|
||
|
- args.caption = caption;
|
||
|
- args.directory = QFileDialogPrivate::workingDirectory(QUrl::fromLocalFile(dir));
|
||
|
- args.selection = QFileDialogPrivate::initialSelection(QUrl::fromLocalFile(dir));
|
||
|
- args.filter = filter;
|
||
|
- args.mode = ExistingFiles;
|
||
|
- args.options = options;
|
||
|
-
|
||
|
-#if defined(Q_WS_WIN)
|
||
|
- if (QGuiApplicationPrivate::platformIntegration()->usePlatformNativeDialog() && !(args.options & DontUseNativeDialog)) {
|
||
|
- return qt_win_get_open_file_names(args, &(args.directory), selectedFilter);
|
||
|
- }
|
||
|
-#endif
|
||
|
-
|
||
|
- // create a qt dialog
|
||
|
- QFileDialog dialog(args);
|
||
|
- if (selectedFilter && !selectedFilter->isEmpty())
|
||
|
- dialog.selectNameFilter(*selectedFilter);
|
||
|
- if (dialog.exec() == QDialog::Accepted) {
|
||
|
- if (selectedFilter)
|
||
|
- *selectedFilter = dialog.selectedNameFilter();
|
||
|
- return dialog.selectedFiles();
|
||
|
- }
|
||
|
- return QStringList();
|
||
|
+ const QStringList schemes = QStringList(QStringLiteral("file"));
|
||
|
+ const QList<QUrl> selectedUrls = getOpenFileUrls(parent, caption, QUrl::fromLocalFile(dir), filter, selectedFilter, options, schemes);
|
||
|
+ QStringList fileNames;
|
||
|
+ foreach (const QUrl &url, selectedUrls)
|
||
|
+ fileNames << url.toLocalFile();
|
||
|
+ return fileNames;
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
@@ -2303,14 +2274,24 @@ QList<QUrl> QFileDialog::getOpenFileUrls(QWidget *parent,
|
||
|
{
|
||
|
Q_UNUSED(supportedSchemes);
|
||
|
|
||
|
- // Falls back to local files
|
||
|
- QList<QUrl> urls;
|
||
|
-
|
||
|
- const QStringList fileNames = getOpenFileNames(parent, caption, dir.toLocalFile(), filter, selectedFilter, options);
|
||
|
- foreach (const QString &fileName, fileNames)
|
||
|
- urls << QUrl::fromLocalFile(fileName);
|
||
|
+ QFileDialogArgs args;
|
||
|
+ args.parent = parent;
|
||
|
+ args.caption = caption;
|
||
|
+ args.directory = QFileDialogPrivate::workingDirectory(dir);
|
||
|
+ args.selection = QFileDialogPrivate::initialSelection(dir);
|
||
|
+ args.filter = filter;
|
||
|
+ args.mode = ExistingFiles;
|
||
|
+ args.options = options;
|
||
|
|
||
|
- return urls;
|
||
|
+ QFileDialog dialog(args);
|
||
|
+ if (selectedFilter && !selectedFilter->isEmpty())
|
||
|
+ dialog.selectNameFilter(*selectedFilter);
|
||
|
+ if (dialog.exec() == QDialog::Accepted) {
|
||
|
+ if (selectedFilter)
|
||
|
+ *selectedFilter = dialog.selectedNameFilter();
|
||
|
+ return dialog.selectedUrls();
|
||
|
+ }
|
||
|
+ return QList<QUrl>();
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
@@ -2370,33 +2351,9 @@ QString QFileDialog::getSaveFileName(QWidget *parent,
|
||
|
QString *selectedFilter,
|
||
|
Options options)
|
||
|
{
|
||
|
- QFileDialogArgs args;
|
||
|
- args.parent = parent;
|
||
|
- args.caption = caption;
|
||
|
- args.directory = QFileDialogPrivate::workingDirectory(QUrl::fromLocalFile(dir));
|
||
|
- args.selection = QFileDialogPrivate::initialSelection(QUrl::fromLocalFile(dir));
|
||
|
- args.filter = filter;
|
||
|
- args.mode = AnyFile;
|
||
|
- args.options = options;
|
||
|
-
|
||
|
-#if defined(Q_WS_WIN)
|
||
|
- if (QGuiApplicationPrivate::platformIntegration()->usePlatformNativeDialog() && !(args.options & DontUseNativeDialog)) {
|
||
|
- return qt_win_get_save_file_name(args, &(args.directory), selectedFilter);
|
||
|
- }
|
||
|
-#endif
|
||
|
-
|
||
|
- // create a qt dialog
|
||
|
- QFileDialog dialog(args);
|
||
|
- dialog.setAcceptMode(AcceptSave);
|
||
|
- if (selectedFilter && !selectedFilter->isEmpty())
|
||
|
- dialog.selectNameFilter(*selectedFilter);
|
||
|
- if (dialog.exec() == QDialog::Accepted) {
|
||
|
- if (selectedFilter)
|
||
|
- *selectedFilter = dialog.selectedNameFilter();
|
||
|
- return dialog.selectedFiles().value(0);
|
||
|
- }
|
||
|
-
|
||
|
- return QString();
|
||
|
+ const QStringList schemes = QStringList(QStringLiteral("file"));
|
||
|
+ const QUrl selectedUrl = getSaveFileUrl(parent, caption, QUrl::fromLocalFile(dir), filter, selectedFilter, options, schemes);
|
||
|
+ return selectedUrl.toLocalFile();
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
@@ -2436,8 +2393,25 @@ QUrl QFileDialog::getSaveFileUrl(QWidget *parent,
|
||
|
{
|
||
|
Q_UNUSED(supportedSchemes);
|
||
|
|
||
|
- // Falls back to local file
|
||
|
- return dialogResultToUrl(getSaveFileName(parent, caption, dir.toLocalFile(), filter, selectedFilter, options));
|
||
|
+ QFileDialogArgs args;
|
||
|
+ args.parent = parent;
|
||
|
+ args.caption = caption;
|
||
|
+ args.directory = QFileDialogPrivate::workingDirectory(dir);
|
||
|
+ args.selection = QFileDialogPrivate::initialSelection(dir);
|
||
|
+ args.filter = filter;
|
||
|
+ args.mode = AnyFile;
|
||
|
+ args.options = options;
|
||
|
+
|
||
|
+ QFileDialog dialog(args);
|
||
|
+ dialog.setAcceptMode(AcceptSave);
|
||
|
+ if (selectedFilter && !selectedFilter->isEmpty())
|
||
|
+ dialog.selectNameFilter(*selectedFilter);
|
||
|
+ if (dialog.exec() == QDialog::Accepted) {
|
||
|
+ if (selectedFilter)
|
||
|
+ *selectedFilter = dialog.selectedNameFilter();
|
||
|
+ return dialog.selectedUrls().value(0);
|
||
|
+ }
|
||
|
+ return QUrl();
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
@@ -2484,29 +2458,9 @@ QString QFileDialog::getExistingDirectory(QWidget *parent,
|
||
|
const QString &dir,
|
||
|
Options options)
|
||
|
{
|
||
|
- QFileDialogArgs args;
|
||
|
- args.parent = parent;
|
||
|
- args.caption = caption;
|
||
|
- args.directory = QFileDialogPrivate::workingDirectory(QUrl::fromLocalFile(dir));
|
||
|
- args.mode = (options & ShowDirsOnly ? DirectoryOnly : Directory);
|
||
|
- args.options = options;
|
||
|
-
|
||
|
-#if defined(Q_WS_WIN)
|
||
|
- if (QGuiApplicationPrivate::platformIntegration()->usePlatformNativeDialog() && !(args.options & DontUseNativeDialog) && (options & ShowDirsOnly)
|
||
|
-#if defined(Q_OS_WINCE)
|
||
|
- && qt_priv_ptr_valid
|
||
|
-#endif
|
||
|
- ) {
|
||
|
- return qt_win_get_existing_directory(args);
|
||
|
- }
|
||
|
-#endif
|
||
|
-
|
||
|
- // create a qt dialog
|
||
|
- QFileDialog dialog(args);
|
||
|
- if (dialog.exec() == QDialog::Accepted) {
|
||
|
- return dialog.selectedFiles().value(0);
|
||
|
- }
|
||
|
- return QString();
|
||
|
+ const QStringList schemes = QStringList(QStringLiteral("file"));
|
||
|
+ const QUrl selectedUrl = getExistingDirectoryUrl(parent, caption, QUrl::fromLocalFile(dir), options, schemes);
|
||
|
+ return selectedUrl.toLocalFile();
|
||
|
}
|
||
|
|
||
|
/*!
|
||
|
@@ -2544,8 +2498,17 @@ QUrl QFileDialog::getExistingDirectoryUrl(QWidget *parent,
|
||
|
{
|
||
|
Q_UNUSED(supportedSchemes);
|
||
|
|
||
|
- // Falls back to local file
|
||
|
- return dialogResultToUrl(getExistingDirectory(parent, caption, dir.toLocalFile(), options));
|
||
|
+ QFileDialogArgs args;
|
||
|
+ args.parent = parent;
|
||
|
+ args.caption = caption;
|
||
|
+ args.directory = QFileDialogPrivate::workingDirectory(dir);
|
||
|
+ args.mode = (options & ShowDirsOnly ? DirectoryOnly : Directory);
|
||
|
+ args.options = options;
|
||
|
+
|
||
|
+ QFileDialog dialog(args);
|
||
|
+ if (dialog.exec() == QDialog::Accepted)
|
||
|
+ return dialog.selectedUrls().value(0);
|
||
|
+ return QUrl();
|
||
|
}
|
||
|
|
||
|
inline static QUrl _qt_get_directory(const QUrl &url)
|
||
|
--
|
||
|
2.1.1
|
||
|
|