From 78f761318a20f320e04a8439101d429136fe3d0a Mon Sep 17 00:00:00 2001 From: =?UTF-8?q?Michael=20Br=C3=BCning?= Date: Tue, 28 Mar 2017 17:12:44 +0200 Subject: Set the mode for the GTK3 file chooser also in selectFile If the mode is not GTK_FILE_CHOOSER_ACTION_SAVE or GTK_FILE_CHOOSER_ACTION_CREATE_FOLDER , a GTK warning will be generated which makes Qt WebEngine's Glib error handler assert. Doing so only when showing the dialog is too late. This patch moves the actual file selection to a private method that can be called from both selectFile and applyOptions in order to prevent overwriting the file chooser action potentially multiple times. Task-number: QTBUG-59692 Change-Id: Ied939248cdc3a0b4c9e8239ab61ba617a46b8496 Reviewed-by: J-P Nurmi --- .../platformthemes/gtk3/qgtk3dialoghelpers.cpp | 19 ++++++++++++++++--- src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.h | 2 ++ 2 files changed, 18 insertions(+), 3 deletions(-) (limited to 'src/plugins') diff --git a/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp b/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp index 8b6ec31400..b1821ebbd2 100644 --- a/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp +++ b/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.cpp @@ -315,6 +315,12 @@ QUrl QGtk3FileDialogHelper::directory() const } void QGtk3FileDialogHelper::selectFile(const QUrl &filename) +{ + setFileChooserAction(); + selectFileInternal(filename); +} + +void QGtk3FileDialogHelper::selectFileInternal(const QUrl &filename) { GtkDialog *gtkDialog = d->gtkDialog(); if (options()->acceptMode() == QFileDialogOptions::AcceptSave) { @@ -409,6 +415,14 @@ static GtkFileChooserAction gtkFileChooserAction(const QSharedPointergtkDialog(); + + const GtkFileChooserAction action = gtkFileChooserAction(options()); + gtk_file_chooser_set_action(GTK_FILE_CHOOSER(gtkDialog), action); +} + void QGtk3FileDialogHelper::applyOptions() { GtkDialog *gtkDialog = d->gtkDialog(); @@ -417,8 +431,7 @@ void QGtk3FileDialogHelper::applyOptions() gtk_window_set_title(GTK_WINDOW(gtkDialog), opts->windowTitle().toUtf8()); gtk_file_chooser_set_local_only(GTK_FILE_CHOOSER(gtkDialog), true); - const GtkFileChooserAction action = gtkFileChooserAction(opts); - gtk_file_chooser_set_action(GTK_FILE_CHOOSER(gtkDialog), action); + setFileChooserAction(); const bool selectMultiple = opts->fileMode() == QFileDialogOptions::ExistingFiles; gtk_file_chooser_set_select_multiple(GTK_FILE_CHOOSER(gtkDialog), selectMultiple); @@ -437,7 +450,7 @@ void QGtk3FileDialogHelper::applyOptions() setDirectory(opts->initialDirectory()); foreach (const QUrl &filename, opts->initiallySelectedFiles()) - selectFile(filename); + selectFileInternal(filename); const QString initialNameFilter = opts->initiallySelectedNameFilter(); if (!initialNameFilter.isEmpty()) diff --git a/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.h b/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.h index 99add3bda3..ba43046e04 100644 --- a/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.h +++ b/src/plugins/platformthemes/gtk3/qgtk3dialoghelpers.h @@ -110,6 +110,8 @@ private: static void onFilterChanged(QGtk3FileDialogHelper *helper); void applyOptions(); void setNameFilters(const QStringList &filters); + void selectFileInternal(const QUrl &filename); + void setFileChooserAction(); QUrl _dir; QList _selection; -- cgit v1.2.3