diff --git a/gtk/gtkfilechoosernative.c b/gtk/gtkfilechoosernative.c index 4db1a2743a..9c6828aaae 100644 --- a/gtk/gtkfilechoosernative.c +++ b/gtk/gtkfilechoosernative.c @@ -682,6 +682,13 @@ gtk_file_chooser_native_get_files (GtkFileChooser *chooser) } } +static void +portal_error_handler (GtkFileChooserNative *self) +{ + self->mode = MODE_FALLBACK; + show_dialog (self); +} + static void gtk_file_chooser_native_show (GtkNativeDialog *native) { @@ -700,7 +707,7 @@ gtk_file_chooser_native_show (GtkNativeDialog *native) #endif if (self->mode == MODE_FALLBACK && - gtk_file_chooser_native_portal_show (self)) + gtk_file_chooser_native_portal_show (self, portal_error_handler)) self->mode = MODE_PORTAL; if (self->mode == MODE_FALLBACK) diff --git a/gtk/gtkfilechoosernativeportal.c b/gtk/gtkfilechoosernativeportal.c index 3fa5145f7c..6ee6f276b6 100644 --- a/gtk/gtkfilechoosernativeportal.c +++ b/gtk/gtkfilechoosernativeportal.c @@ -43,6 +43,7 @@ #include "gtkfilefilterprivate.h" #include "gtkwindowprivate.h" + typedef struct { GtkFileChooserNative *self; @@ -58,6 +59,7 @@ typedef struct { const char *method_name; GtkWindow *exported_window; + PortalErrorHandler error_handler; } FilechooserPortalData; @@ -188,12 +190,13 @@ open_file_msg_cb (GObject *source_object, if (reply == NULL) { - if (!data->hidden) - _gtk_native_dialog_emit_response (GTK_NATIVE_DIALOG (self), GTK_RESPONSE_DELETE_EVENT); - g_warning ("Can't open portal file chooser: %s", error->message); + if (!data->hidden && data->error_handler) + { + data->error_handler (self); + filechooser_portal_data_free (data); + self->mode_data = NULL; + } g_error_free (error); - filechooser_portal_data_free (data); - self->mode_data = NULL; return; } @@ -398,7 +401,8 @@ window_handle_exported (GtkWindow *window, } gboolean -gtk_file_chooser_native_portal_show (GtkFileChooserNative *self) +gtk_file_chooser_native_portal_show (GtkFileChooserNative *self, + PortalErrorHandler error_handler) { FilechooserPortalData *data; GtkWindow *transient_for; @@ -428,6 +432,7 @@ gtk_file_chooser_native_portal_show (GtkFileChooserNative *self) data = g_new0 (FilechooserPortalData, 1); data->self = g_object_ref (self); data->connection = connection; + data->error_handler = error_handler; data->method_name = method_name; @@ -470,10 +475,9 @@ gtk_file_chooser_native_portal_hide (GtkFileChooserNative *self) data->hidden = TRUE; if (data->portal_handle) - { - send_close (data); - filechooser_portal_data_free (data); - } + send_close (data); + + filechooser_portal_data_free (data); self->mode_data = NULL; } diff --git a/gtk/gtkfilechoosernativeprivate.h b/gtk/gtkfilechoosernativeprivate.h index 5749e663dc..e8630238f6 100644 --- a/gtk/gtkfilechoosernativeprivate.h +++ b/gtk/gtkfilechoosernativeprivate.h @@ -61,7 +61,9 @@ void gtk_file_chooser_native_win32_hide (GtkFileChooserNative *self); gboolean gtk_file_chooser_native_quartz_show (GtkFileChooserNative *self); void gtk_file_chooser_native_quartz_hide (GtkFileChooserNative *self); -gboolean gtk_file_chooser_native_portal_show (GtkFileChooserNative *self); +typedef void (* PortalErrorHandler) (GtkFileChooserNative *self); +gboolean gtk_file_chooser_native_portal_show (GtkFileChooserNative *self, + PortalErrorHandler error_handler); void gtk_file_chooser_native_portal_hide (GtkFileChooserNative *self); G_END_DECLS