QFileDialog: add setSupportedSchemes and pass it along to the QPA.

This also finishes the implementation of the static methods which
were being passed a supportedSchemes argument but weren't using it.
Now they can pass it along to the QFileDialog instance, which then
passes it to the helper used by the QPA implementation of the file
dialog. The default implementation only supports local files and
can therefore ignore this, but other implementations can use this
argument to restrict the protocols allowed to the user.

[ChangeLog][Widgets][QFileDialog] Add supportedSchemes property.

Change-Id: I5235f70e785da1c06866a8355ef98f571890c4a2
Reviewed-by: Kevin Ottens <kevin.ottens@kdab.com>
Reviewed-by: Friedemann Kleint <Friedemann.Kleint@theqtcompany.com>
bb10
David Faure 2015-05-09 14:12:28 +02:00
parent 4e4b16dc17
commit 5443da6c27
4 changed files with 48 additions and 8 deletions

View File

@ -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();

View File

@ -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;
};

View File

@ -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();

View File

@ -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;