Merge branch 'portal-chooser-fail' into 'master'

portal file chooser: Handle errors

Closes #2527

See merge request GNOME/gtk!1551
This commit is contained in:
Matthias Clasen 2020-03-21 18:34:07 +00:00
commit bf988f8d07
3 changed files with 25 additions and 12 deletions

View File

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

View File

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

View File

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