[gtk/portal-chooser-fail] portal file chooser: Handle errors



commit 245851a6bb8825cffe2aeb3813548d16d8914b35
Author: Matthias Clasen <mclasen redhat com>
Date:   Sat Mar 21 13:06:10 2020 -0400

    portal file chooser: Handle errors
    
    Fall back to showing a local file chooser
    if we get DBus errors from the portal.
    
    Closes: #2527

 gtk/gtkfilechoosernative.c        |  9 ++++++++-
 gtk/gtkfilechoosernativeportal.c  | 24 ++++++++++++++----------
 gtk/gtkfilechoosernativeprivate.h |  4 +++-
 3 files changed, 25 insertions(+), 12 deletions(-)
---
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


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]