diff options
Diffstat (limited to 'src')
-rw-r--r-- | src/gui/kernel/qplatformdialoghelper.cpp | 13 | ||||
-rw-r--r-- | src/gui/kernel/qplatformdialoghelper.h | 3 | ||||
-rw-r--r-- | src/widgets/dialogs/qfiledialog.cpp | 36 | ||||
-rw-r--r-- | src/widgets/dialogs/qfiledialog.h | 4 |
4 files changed, 48 insertions, 8 deletions
diff --git a/src/gui/kernel/qplatformdialoghelper.cpp b/src/gui/kernel/qplatformdialoghelper.cpp index 2d0458f705..25894fd504 100644 --- a/src/gui/kernel/qplatformdialoghelper.cpp +++ b/src/gui/kernel/qplatformdialoghelper.cpp @@ -422,6 +422,7 @@ public: QUrl initialDirectory; QString initiallySelectedNameFilter; QList<QUrl> initiallySelectedFiles; + QStringList supportedSchemes; }; QFileDialogOptions::QFileDialogOptions() : d(new QFileDialogOptionsPrivate) @@ -613,6 +614,18 @@ void QFileDialogOptions::setInitiallySelectedFiles(const QList<QUrl> &files) d->initiallySelectedFiles = files; } +// Schemes supported by the application +void QFileDialogOptions::setSupportedSchemes(const QStringList &schemes) +{ + d->supportedSchemes = schemes; +} + +QStringList QFileDialogOptions::supportedSchemes() const +{ + return d->supportedSchemes; +} + +// Return true if the URL is supported by the filedialog implementation *and* by the application. bool QPlatformFileDialogHelper::isSupportedUrl(const QUrl &url) const { return url.isLocalFile(); diff --git a/src/gui/kernel/qplatformdialoghelper.h b/src/gui/kernel/qplatformdialoghelper.h index 8b2b9881b7..ec88770862 100644 --- a/src/gui/kernel/qplatformdialoghelper.h +++ b/src/gui/kernel/qplatformdialoghelper.h @@ -348,6 +348,9 @@ public: QList<QUrl> initiallySelectedFiles() const; void setInitiallySelectedFiles(const QList<QUrl> &); + void setSupportedSchemes(const QStringList &schemes); + QStringList supportedSchemes() const; + private: QSharedDataPointer<QFileDialogOptionsPrivate> d; }; diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index 45f41bb0d2..86ca64d82a 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -1700,6 +1700,30 @@ void QFileDialog::setAcceptMode(QFileDialog::AcceptMode mode) d->retranslateWindowTitle(); } +/*! + \property QFileDialog::supportedSchemes + \brief the URL schemes that the file dialog should allow navigating to. + \since 5.6 + + Setting this property allows to restrict the type of URLs the + user will be able to select. It is a way for the application to declare + the protocols it will support to fetch the file content. An empty list + means that no restriction is applied (the default). + Supported for local files ("file" scheme) is implicit and always enabled; + it is not necessary to include it in the restriction. +*/ + +void QFileDialog::setSupportedSchemes(const QStringList &schemes) +{ + Q_D(QFileDialog); + d->options->setSupportedSchemes(schemes); +} + +QStringList QFileDialog::supportedSchemes() const +{ + return d_func()->options->supportedSchemes(); +} + /* Returns the file system model index that is the root index in the views @@ -2114,8 +2138,6 @@ QUrl QFileDialog::getOpenFileUrl(QWidget *parent, Options options, const QStringList &supportedSchemes) { - Q_UNUSED(supportedSchemes); // TODO - QFileDialogArgs args; args.parent = parent; args.caption = caption; @@ -2126,6 +2148,7 @@ QUrl QFileDialog::getOpenFileUrl(QWidget *parent, args.options = options; QFileDialog dialog(args); + dialog.setSupportedSchemes(supportedSchemes); if (selectedFilter && !selectedFilter->isEmpty()) dialog.selectNameFilter(*selectedFilter); if (dialog.exec() == QDialog::Accepted) { @@ -2237,8 +2260,6 @@ QList<QUrl> QFileDialog::getOpenFileUrls(QWidget *parent, Options options, const QStringList &supportedSchemes) { - Q_UNUSED(supportedSchemes); - QFileDialogArgs args; args.parent = parent; args.caption = caption; @@ -2249,6 +2270,7 @@ QList<QUrl> QFileDialog::getOpenFileUrls(QWidget *parent, args.options = options; QFileDialog dialog(args); + dialog.setSupportedSchemes(supportedSchemes); if (selectedFilter && !selectedFilter->isEmpty()) dialog.selectNameFilter(*selectedFilter); if (dialog.exec() == QDialog::Accepted) { @@ -2356,8 +2378,6 @@ QUrl QFileDialog::getSaveFileUrl(QWidget *parent, Options options, const QStringList &supportedSchemes) { - Q_UNUSED(supportedSchemes); - QFileDialogArgs args; args.parent = parent; args.caption = caption; @@ -2368,6 +2388,7 @@ QUrl QFileDialog::getSaveFileUrl(QWidget *parent, args.options = options; QFileDialog dialog(args); + dialog.setSupportedSchemes(supportedSchemes); dialog.setAcceptMode(AcceptSave); if (selectedFilter && !selectedFilter->isEmpty()) dialog.selectNameFilter(*selectedFilter); @@ -2461,8 +2482,6 @@ QUrl QFileDialog::getExistingDirectoryUrl(QWidget *parent, Options options, const QStringList &supportedSchemes) { - Q_UNUSED(supportedSchemes); - QFileDialogArgs args; args.parent = parent; args.caption = caption; @@ -2471,6 +2490,7 @@ QUrl QFileDialog::getExistingDirectoryUrl(QWidget *parent, args.options = options; QFileDialog dialog(args); + dialog.setSupportedSchemes(supportedSchemes); if (dialog.exec() == QDialog::Accepted) return dialog.selectedUrls().value(0); return QUrl(); diff --git a/src/widgets/dialogs/qfiledialog.h b/src/widgets/dialogs/qfiledialog.h index 6bbeb3817a..bba8c5f3c7 100644 --- a/src/widgets/dialogs/qfiledialog.h +++ b/src/widgets/dialogs/qfiledialog.h @@ -66,6 +66,7 @@ class Q_WIDGETS_EXPORT QFileDialog : public QDialog Q_PROPERTY(bool nameFilterDetailsVisible READ isNameFilterDetailsVisible WRITE setNameFilterDetailsVisible DESIGNABLE false) Q_PROPERTY(Options options READ options WRITE setOptions) + Q_PROPERTY(QStringList supportedSchemes READ supportedSchemes WRITE setSupportedSchemes) public: enum ViewMode { Detail, List }; @@ -167,6 +168,9 @@ public: void setLabelText(DialogLabel label, const QString &text); QString labelText(DialogLabel label) const; + void setSupportedSchemes(const QStringList &schemes); + QStringList supportedSchemes() const; + #ifndef QT_NO_PROXYMODEL void setProxyModel(QAbstractProxyModel *model); QAbstractProxyModel *proxyModel() const; |