From 9879e5b90b1babcf38236d2c46c187eacf613711 Mon Sep 17 00:00:00 2001 From: David Faure Date: Wed, 9 Jul 2014 11:24:16 +0200 Subject: [PATCH 1/4] QFileDialog: emit urlsSelected+urlSelected in accept(). Not just filesSelected+fileSelected (which only happens for local files). Change-Id: Ife592c3c921231356f96cbc2871b6d724a15d2c8 Reviewed-by: Friedemann Kleint (cherry picked from commit da088c5ace607904ec817033d2d48c689ff4816a) --- src/widgets/dialogs/qfiledialog.cpp | 21 +++++++++++++-------- src/widgets/dialogs/qfiledialog.h | 4 ++-- src/widgets/dialogs/qfiledialog_p.h | 4 ++-- 3 files changed, 17 insertions(+), 12 deletions(-) diff --git a/src/widgets/dialogs/qfiledialog.cpp b/src/widgets/dialogs/qfiledialog.cpp index 9219757..037964b 100644 --- a/src/widgets/dialogs/qfiledialog.cpp +++ b/src/widgets/dialogs/qfiledialog.cpp @@ -577,8 +577,8 @@ QFileDialogPrivate::~QFileDialogPrivate() void QFileDialogPrivate::initHelper(QPlatformDialogHelper *h) { QFileDialog *d = q_func(); - QObject::connect(h, SIGNAL(fileSelected(QUrl)), d, SLOT(_q_nativeFileSelected(QUrl))); - QObject::connect(h, SIGNAL(filesSelected(QList)), d, SLOT(_q_nativeFilesSelected(QList))); + QObject::connect(h, SIGNAL(fileSelected(QUrl)), d, SLOT(_q_emitUrlSelected(QUrl))); + QObject::connect(h, SIGNAL(filesSelected(QList)), d, SLOT(_q_emitUrlsSelected(QList))); QObject::connect(h, SIGNAL(currentChanged(QUrl)), d, SLOT(_q_nativeCurrentChanged(QUrl))); QObject::connect(h, SIGNAL(directoryEntered(QUrl)), d, SLOT(_q_nativeEnterDirectory(QUrl))); QObject::connect(h, SIGNAL(filterSelected(QString)), d, SIGNAL(filterSelected(QString))); @@ -2607,15 +2607,20 @@ void QFileDialog::done(int result) void QFileDialog::accept() { Q_D(QFileDialog); - QStringList files = selectedFiles(); - if (files.isEmpty()) - return; if (!d->usingWidgets()) { - d->emitFilesSelected(files); + const QList urls = selectedUrls(); + if (urls.isEmpty()) + return; + d->_q_emitUrlsSelected(urls); + if (urls.count() == 1) + d->_q_emitUrlSelected(urls.first()); QDialog::accept(); return; } + QStringList files = selectedFiles(); + if (files.isEmpty()) + return; QString lineEditText = d->lineEdit()->text(); // "hidden feature" type .. and then enter, and it will move up a dir // special case for ".." @@ -3646,7 +3651,7 @@ void QFileDialogPrivate::_q_fileRenamed(const QString &path, const QString oldNa } } -void QFileDialogPrivate::_q_nativeFileSelected(const QUrl &file) +void QFileDialogPrivate::_q_emitUrlSelected(const QUrl &file) { Q_Q(QFileDialog); emit q->urlSelected(file); @@ -3654,7 +3659,7 @@ void QFileDialogPrivate::_q_nativeFileSelected(const QUrl &file) emit q->fileSelected(file.toLocalFile()); } -void QFileDialogPrivate::_q_nativeFilesSelected(const QList &files) +void QFileDialogPrivate::_q_emitUrlsSelected(const QList &files) { Q_Q(QFileDialog); emit q->urlsSelected(files); diff --git a/src/widgets/dialogs/qfiledialog.h b/src/widgets/dialogs/qfiledialog.h index 404e16c..184e072 100644 --- a/src/widgets/dialogs/qfiledialog.h +++ b/src/widgets/dialogs/qfiledialog.h @@ -287,8 +287,8 @@ private: Q_PRIVATE_SLOT(d_func(), void _q_updateOkButton()) Q_PRIVATE_SLOT(d_func(), void _q_currentChanged(const QModelIndex &index)) Q_PRIVATE_SLOT(d_func(), void _q_enterDirectory(const QModelIndex &index)) - Q_PRIVATE_SLOT(d_func(), void _q_nativeFileSelected(const QUrl &)) - Q_PRIVATE_SLOT(d_func(), void _q_nativeFilesSelected(const QList &)) + Q_PRIVATE_SLOT(d_func(), void _q_emitUrlSelected(const QUrl &)) + Q_PRIVATE_SLOT(d_func(), void _q_emitUrlsSelected(const QList &)) Q_PRIVATE_SLOT(d_func(), void _q_nativeCurrentChanged(const QUrl &)) Q_PRIVATE_SLOT(d_func(), void _q_nativeEnterDirectory(const QUrl&)) Q_PRIVATE_SLOT(d_func(), void _q_goToDirectory(const QString &path)) diff --git a/src/widgets/dialogs/qfiledialog_p.h b/src/widgets/dialogs/qfiledialog_p.h index 632bbca..9e1c23b 100644 --- a/src/widgets/dialogs/qfiledialog_p.h +++ b/src/widgets/dialogs/qfiledialog_p.h @@ -210,8 +210,8 @@ public: void _q_updateOkButton(); void _q_currentChanged(const QModelIndex &index); void _q_enterDirectory(const QModelIndex &index); - void _q_nativeFileSelected(const QUrl &file); - void _q_nativeFilesSelected(const QList &files); + void _q_emitUrlSelected(const QUrl &file); + void _q_emitUrlsSelected(const QList &files); void _q_nativeCurrentChanged(const QUrl &file); void _q_nativeEnterDirectory(const QUrl &directory); void _q_goToDirectory(const QString &); -- 2.1.1