[nautilus] previewer: switch to using GDBusProxy for remote calls



commit fd9591fc810f721e8c80a6577539b306b63f41c2
Author: Cosimo Cecchi <cosimoc gnome org>
Date:   Sat Jul 6 22:48:19 2019 -0700

    previewer: switch to using GDBusProxy for remote calls
    
    Instead of using the connection directly. This allows us to easily
    inspect a property in a future commit.

 src/nautilus-previewer.c | 90 ++++++++++++++++++++++++++++++------------------
 1 file changed, 57 insertions(+), 33 deletions(-)
---
diff --git a/src/nautilus-previewer.c b/src/nautilus-previewer.c
index e2ac3e885..7f8867afe 100644
--- a/src/nautilus-previewer.c
+++ b/src/nautilus-previewer.c
@@ -37,15 +37,44 @@
 #define PREVIEWER2_DBUS_IFACE "org.gnome.NautilusPreviewer2"
 #define PREVIEWER_DBUS_PATH "/org/gnome/NautilusPreviewer"
 
+static GDBusProxy *previewer_v2_proxy = NULL;
+
+static gboolean
+ensure_previewer_v2_proxy (void)
+{
+    if (previewer_v2_proxy == NULL)
+    {
+        g_autoptr(GError) error = NULL;
+        GDBusConnection *connection = g_application_get_dbus_connection (g_application_get_default ());
+
+        previewer_v2_proxy = g_dbus_proxy_new_sync (connection,
+                                                    G_DBUS_PROXY_FLAGS_DO_NOT_AUTO_START,
+                                                    NULL,
+                                                    PREVIEWER_DBUS_NAME,
+                                                    PREVIEWER_DBUS_PATH,
+                                                    PREVIEWER2_DBUS_IFACE,
+                                                    NULL,
+                                                    &error);
+
+        if (error != NULL)
+        {
+            DEBUG ("Unable to create NautilusPreviewer2 proxy: %s", error->message);
+            return FALSE;
+        }
+    }
+
+    return TRUE;
+}
+
 static void
 previewer2_method_ready_cb (GObject      *source,
                             GAsyncResult *res,
                             gpointer      user_data)
 {
-    GDBusConnection *connection = G_DBUS_CONNECTION (source);
+    GDBusProxy *proxy = G_DBUS_PROXY (source);
     g_autoptr(GError) error = NULL;
 
-    g_dbus_connection_call_finish (connection, res, &error);
+    g_dbus_proxy_call_finish (proxy, res, &error);
 
     if (error != NULL)
     {
@@ -59,44 +88,39 @@ nautilus_previewer_call_show_file (const gchar *uri,
                                    guint        xid,
                                    gboolean     close_if_already_visible)
 {
-    GDBusConnection *connection = g_application_get_dbus_connection (g_application_get_default ());
-    GVariant *variant;
-
-    variant = g_variant_new ("(ssb)",
-                             uri, window_handle, close_if_already_visible);
-
-    g_dbus_connection_call (connection,
-                            PREVIEWER_DBUS_NAME,
-                            PREVIEWER_DBUS_PATH,
-                            PREVIEWER2_DBUS_IFACE,
-                            "ShowFile",
-                            variant,
-                            NULL,
-                            G_DBUS_CALL_FLAGS_NONE,
-                            -1,
-                            NULL,
-                            previewer2_method_ready_cb,
-                            NULL);
+    if (!ensure_previewer_v2_proxy ())
+    {
+        return;
+    }
+
+    g_dbus_proxy_call (previewer_v2_proxy,
+                       "ShowFile",
+                       g_variant_new ("(ssb)",
+                                      uri, window_handle, close_if_already_visible),
+                       G_DBUS_CALL_FLAGS_NONE,
+                       -1,
+                       NULL,
+                       previewer2_method_ready_cb,
+                       NULL);
 }
 
 void
 nautilus_previewer_call_close (void)
 {
-    GDBusConnection *connection = g_application_get_dbus_connection (g_application_get_default ());
+    if (!ensure_previewer_v2_proxy ())
+    {
+        return;
+    }
 
     /* don't autostart the previewer if it's not running */
-    g_dbus_connection_call (connection,
-                            PREVIEWER_DBUS_NAME,
-                            PREVIEWER_DBUS_PATH,
-                            PREVIEWER2_DBUS_IFACE,
-                            "Close",
-                            NULL,
-                            NULL,
-                            G_DBUS_CALL_FLAGS_NO_AUTO_START,
-                            -1,
-                            NULL,
-                            previewer2_method_ready_cb,
-                            NULL);
+    g_dbus_proxy_call (previewer_v2_proxy,
+                       "Close",
+                       NULL,
+                       G_DBUS_CALL_FLAGS_NO_AUTO_START,
+                       -1,
+                       NULL,
+                       previewer2_method_ready_cb,
+                       NULL);
 }
 
 static void


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