[gtk+/portal] file chooser portal: Port to new Request API



commit 73ae1d667f8e36e7251e36ceb66c68be12ee44e2
Author: Matthias Clasen <mclasen redhat com>
Date:   Sun Jun 26 14:35:12 2016 -0400

    file chooser portal: Port to new Request API
    
    The portal API has changed, we need to adapt.

 gtk/gtkfilechoosernativeportal.c |   50 ++++++++++++++++---------------------
 1 files changed, 22 insertions(+), 28 deletions(-)
---
diff --git a/gtk/gtkfilechoosernativeportal.c b/gtk/gtkfilechoosernativeportal.c
index b8e83fc..cf2e016 100644
--- a/gtk/gtkfilechoosernativeportal.c
+++ b/gtk/gtkfilechoosernativeportal.c
@@ -55,6 +55,7 @@ typedef struct {
   GDBusConnection *connection;
   char *portal_handle;
   guint portal_response_signal_id;
+  GDBusSignalCallback signal_callback;
   gboolean modal;
 
   gboolean hidden;
@@ -240,6 +241,19 @@ open_file_msg_cb (GObject *source_object,
       send_close (data);
       filechooser_portal_data_free (data);
     }
+  else
+    {
+      data->portal_response_signal_id =
+        g_dbus_connection_signal_subscribe (data->connection,
+                                            "org.freedesktop.portal.Desktop",
+                                            "org.freedesktop.portal.Request",
+                                            "Response",
+                                            data->portal_handle,
+                                            NULL,
+                                            G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE,
+                                            data->signal_callback,
+                                            self, NULL);
+    }
 
   g_object_unref (reply);
 }
@@ -275,8 +289,6 @@ gtk_file_chooser_native_portal_show (GtkFileChooserNative *self)
   GtkFileChooserAction action;
   gboolean multiple;
   const char *method_name;
-  const char *signal_name;
-  GDBusSignalCallback signal_callback;
   const char *use_portal;
   gchar *path;
 
@@ -312,23 +324,11 @@ gtk_file_chooser_native_portal_show (GtkFileChooserNative *self)
   multiple = gtk_file_chooser_get_select_multiple (GTK_FILE_CHOOSER (self));
 
   if (action == GTK_FILE_CHOOSER_ACTION_OPEN && !multiple)
-    {
-      method_name = "OpenFile";
-      signal_name = "OpenFileResponse";
-      signal_callback = one_file_response;
-    }
+    method_name = "OpenFile";
   else if (action == GTK_FILE_CHOOSER_ACTION_OPEN && multiple)
-    {
-      method_name = "OpenFiles";
-      signal_name = "OpenFilesResponse";
-      signal_callback = multi_file_response;
-    }
+    method_name = "OpenFiles";
   else if (action == GTK_FILE_CHOOSER_ACTION_SAVE)
-    {
-      method_name = "SaveFile";
-      signal_name = "SaveFileResponse";
-      signal_callback = one_file_response;
-    }
+    method_name = "SaveFile";
   else
     {
       g_warning ("GTK_FILE_CHOOSER_ACTION_%s is not supported by GtkFileChooserNativePortal", action == 
GTK_FILE_CHOOSER_ACTION_SELECT_FOLDER ? "SELECT_FOLDER" : "CREATE_FOLDER");
@@ -339,6 +339,11 @@ gtk_file_chooser_native_portal_show (GtkFileChooserNative *self)
   data->self = g_object_ref (self);
   data->connection = connection;
 
+  if (strcmp (method_name, "OpenFiles") == 0)
+    data->signal_callback = multi_file_response;
+  else
+    data->signal_callback = one_file_response;
+
   message = g_dbus_message_new_method_call ("org.freedesktop.portal.Desktop",
                                             "/org/freedesktop/portal/desktop",
                                             "org.freedesktop.portal.FileChooser",
@@ -403,17 +408,6 @@ gtk_file_chooser_native_portal_show (GtkFileChooserNative *self)
                                           g_variant_builder_end (&opt_builder)));
   g_free (parent_window_str);
 
-  data->portal_response_signal_id =
-    g_dbus_connection_signal_subscribe (data->connection,
-                                        "org.freedesktop.portal.Desktop",
-                                        "org.freedesktop.portal.FileChooser",
-                                        signal_name,
-                                        "/org/freedesktop/portal/desktop",
-                                        NULL,
-                                        G_DBUS_SIGNAL_FLAGS_NO_MATCH_RULE,
-                                        signal_callback,
-                                        self, NULL);
-
   g_dbus_connection_send_message_with_reply (data->connection,
                                              message,
                                              G_DBUS_SEND_MESSAGE_FLAGS_NONE,


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