Blame SOURCES/application-Export-FileManager1-iface-from-dbus_regi.patch

5bc9b2
From 1fa3039c67671fe53416b2575f3c305029ef4854 Mon Sep 17 00:00:00 2001
5bc9b2
From: Ondrej Holy <oholy@redhat.com>
5bc9b2
Date: Wed, 11 Jan 2023 09:55:41 +0100
5bc9b2
Subject: [PATCH] application: Export FileManager1 iface from dbus_register
5bc9b2
 vfunc
5bc9b2
5bc9b2
The `org/freedesktop/FileManager1` interface is not currently exported
5bc9b2
from the `dbus_register` vfunc. This causes issues for projects (e.g.
5bc9b2
desktop-icons extension) that want to use all the Nautilus intefaces
5bc9b2
over the `org.gnome.Nautilus` connection. Let's use the already established
5bc9b2
connection and export the `FileManager1` interface from the `dbus_register`
5bc9b2
vfunc.
5bc9b2
5bc9b2
https://bugzilla.redhat.com/show_bug.cgi?id=2150894
5bc9b2
---
5bc9b2
 src/nautilus-application.c      |  17 ++--
5bc9b2
 src/nautilus-freedesktop-dbus.c | 150 +++++++++++++++++++++++++-------
5bc9b2
 src/nautilus-freedesktop-dbus.h |   6 +-
5bc9b2
 3 files changed, 136 insertions(+), 37 deletions(-)
5bc9b2
5bc9b2
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
5bc9b2
index 829faa3..3bb3da1 100644
5bc9b2
--- a/src/nautilus-application.c
5bc9b2
+++ b/src/nautilus-application.c
5bc9b2
@@ -608,8 +608,6 @@ nautilus_application_finalize (GObject *object)
5bc9b2
     g_clear_object (&priv->progress_handler);
5bc9b2
     g_clear_object (&priv->bookmark_list);
5bc9b2
 
5bc9b2
-    g_clear_object (&priv->fdb_manager);
5bc9b2
-
5bc9b2
     g_list_free (priv->windows);
5bc9b2
 
5bc9b2
     g_hash_table_destroy (priv->notifications);
5bc9b2
@@ -1270,9 +1268,6 @@ nautilus_application_startup (GApplication *app)
5bc9b2
 
5bc9b2
     setup_theme_extensions ();
5bc9b2
 
5bc9b2
-    /* create DBus manager */
5bc9b2
-    priv->fdb_manager = nautilus_freedesktop_dbus_new ();
5bc9b2
-
5bc9b2
     /* initialize preferences and create the global GSettings objects */
5bc9b2
     nautilus_global_preferences_init ();
5bc9b2
 
5bc9b2
@@ -1315,6 +1310,12 @@ nautilus_application_dbus_register (GApplication     *app,
5bc9b2
         return FALSE;
5bc9b2
     }
5bc9b2
 
5bc9b2
+    priv->fdb_manager = nautilus_freedesktop_dbus_new (connection);
5bc9b2
+    if (!nautilus_freedesktop_dbus_register (priv->fdb_manager, error))
5bc9b2
+    {
5bc9b2
+        return FALSE;
5bc9b2
+    }
5bc9b2
+
5bc9b2
     priv->search_provider = nautilus_shell_search_provider_new ();
5bc9b2
     if (!nautilus_shell_search_provider_register (priv->search_provider, connection, error))
5bc9b2
     {
5bc9b2
@@ -1339,6 +1340,12 @@ nautilus_application_dbus_unregister (GApplication    *app,
5bc9b2
         g_clear_object (&priv->dbus_manager);
5bc9b2
     }
5bc9b2
 
5bc9b2
+    if (priv->fdb_manager)
5bc9b2
+    {
5bc9b2
+        nautilus_freedesktop_dbus_unregister (priv->fdb_manager);
5bc9b2
+        g_clear_object (&priv->fdb_manager);
5bc9b2
+    }
5bc9b2
+
5bc9b2
     if (priv->search_provider)
5bc9b2
     {
5bc9b2
         nautilus_shell_search_provider_unregister (priv->search_provider);
5bc9b2
diff --git a/src/nautilus-freedesktop-dbus.c b/src/nautilus-freedesktop-dbus.c
5bc9b2
index b888099..d013e20 100644
5bc9b2
--- a/src/nautilus-freedesktop-dbus.c
5bc9b2
+++ b/src/nautilus-freedesktop-dbus.c
5bc9b2
@@ -41,6 +41,14 @@ struct _NautilusFreedesktopDBus
5bc9b2
 
5bc9b2
     /* Our DBus implementation skeleton */
5bc9b2
     NautilusFreedesktopFileManager1 *skeleton;
5bc9b2
+
5bc9b2
+    GDBusConnection *connection;
5bc9b2
+};
5bc9b2
+
5bc9b2
+enum
5bc9b2
+{
5bc9b2
+    PROP_0,
5bc9b2
+    PROP_CONNECTION,
5bc9b2
 };
5bc9b2
 
5bc9b2
 struct _NautilusFreedesktopDBusClass
5bc9b2
@@ -149,27 +157,6 @@ skeleton_handle_show_item_properties_cb (NautilusFreedesktopFileManager1 *object
5bc9b2
     return TRUE;
5bc9b2
 }
5bc9b2
 
5bc9b2
-static void
5bc9b2
-bus_acquired_cb (GDBusConnection *conn,
5bc9b2
-                 const gchar     *name,
5bc9b2
-                 gpointer         user_data)
5bc9b2
-{
5bc9b2
-    NautilusFreedesktopDBus *fdb = user_data;
5bc9b2
-
5bc9b2
-    DEBUG ("Bus acquired at %s", name);
5bc9b2
-
5bc9b2
-    fdb->skeleton = nautilus_freedesktop_file_manager1_skeleton_new ();
5bc9b2
-
5bc9b2
-    g_signal_connect (fdb->skeleton, "handle-show-items",
5bc9b2
-                      G_CALLBACK (skeleton_handle_show_items_cb), fdb);
5bc9b2
-    g_signal_connect (fdb->skeleton, "handle-show-folders",
5bc9b2
-                      G_CALLBACK (skeleton_handle_show_folders_cb), fdb);
5bc9b2
-    g_signal_connect (fdb->skeleton, "handle-show-item-properties",
5bc9b2
-                      G_CALLBACK (skeleton_handle_show_item_properties_cb), fdb);
5bc9b2
-
5bc9b2
-    g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (fdb->skeleton), conn, NAUTILUS_FDO_DBUS_PATH, NULL);
5bc9b2
-}
5bc9b2
-
5bc9b2
 static void
5bc9b2
 name_acquired_cb (GDBusConnection *connection,
5bc9b2
                   const gchar     *name,
5bc9b2
@@ -186,6 +173,20 @@ name_lost_cb (GDBusConnection *connection,
5bc9b2
     DEBUG ("Lost (or failed to acquire) the name %s on the session message bus\n", name);
5bc9b2
 }
5bc9b2
 
5bc9b2
+static void
5bc9b2
+nautilus_freedesktop_dbus_constructed (GObject *object)
5bc9b2
+{
5bc9b2
+    NautilusFreedesktopDBus *fdb = NAUTILUS_FREEDESKTOP_DBUS (object);
5bc9b2
+
5bc9b2
+    fdb->owner_id = g_bus_own_name_on_connection (fdb->connection,
5bc9b2
+                                                  NAUTILUS_FDO_DBUS_NAME,
5bc9b2
+                                                  G_BUS_NAME_OWNER_FLAGS_NONE,
5bc9b2
+                                                  name_acquired_cb,
5bc9b2
+                                                  name_lost_cb,
5bc9b2
+                                                  fdb,
5bc9b2
+                                                  NULL);
5bc9b2
+}
5bc9b2
+
5bc9b2
 static void
5bc9b2
 nautilus_freedesktop_dbus_dispose (GObject *object)
5bc9b2
 {
5bc9b2
@@ -199,33 +200,87 @@ nautilus_freedesktop_dbus_dispose (GObject *object)
5bc9b2
 
5bc9b2
     if (fdb->skeleton != NULL)
5bc9b2
     {
5bc9b2
-        g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (fdb->skeleton));
5bc9b2
         g_object_unref (fdb->skeleton);
5bc9b2
         fdb->skeleton = NULL;
5bc9b2
     }
5bc9b2
 
5bc9b2
+    g_clear_object (&fdb->connection);
5bc9b2
+
5bc9b2
     G_OBJECT_CLASS (nautilus_freedesktop_dbus_parent_class)->dispose (object);
5bc9b2
 }
5bc9b2
 
5bc9b2
+static void
5bc9b2
+nautilus_freedesktop_dbus_set_property (GObject      *object,
5bc9b2
+                                        guint         prop_id,
5bc9b2
+                                        const GValue *value,
5bc9b2
+                                        GParamSpec   *pspec)
5bc9b2
+{
5bc9b2
+    NautilusFreedesktopDBus *fdb = NAUTILUS_FREEDESKTOP_DBUS (object);
5bc9b2
+
5bc9b2
+    switch (prop_id)
5bc9b2
+    {
5bc9b2
+        case PROP_CONNECTION:
5bc9b2
+        {
5bc9b2
+            g_set_object (&fdb->connection, g_value_get_object (value));
5bc9b2
+        }
5bc9b2
+        break;
5bc9b2
+
5bc9b2
+        default:
5bc9b2
+        {
5bc9b2
+            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
5bc9b2
+        }
5bc9b2
+        break;
5bc9b2
+    }
5bc9b2
+}
5bc9b2
+
5bc9b2
+static void
5bc9b2
+nautilus_freedesktop_dbus_get_property (GObject    *object,
5bc9b2
+                                        guint       prop_id,
5bc9b2
+                                        GValue     *value,
5bc9b2
+                                        GParamSpec *pspec)
5bc9b2
+{
5bc9b2
+    NautilusFreedesktopDBus *fdb = NAUTILUS_FREEDESKTOP_DBUS (object);
5bc9b2
+
5bc9b2
+    switch (prop_id)
5bc9b2
+    {
5bc9b2
+        case PROP_CONNECTION:
5bc9b2
+        {
5bc9b2
+            g_value_set_object (value, fdb->connection);
5bc9b2
+        }
5bc9b2
+        break;
5bc9b2
+
5bc9b2
+        default:
5bc9b2
+        {
5bc9b2
+            G_OBJECT_WARN_INVALID_PROPERTY_ID (object, prop_id, pspec);
5bc9b2
+        }
5bc9b2
+        break;
5bc9b2
+    }
5bc9b2
+}
5bc9b2
+
5bc9b2
 static void
5bc9b2
 nautilus_freedesktop_dbus_class_init (NautilusFreedesktopDBusClass *klass)
5bc9b2
 {
5bc9b2
     GObjectClass *object_class = G_OBJECT_CLASS (klass);
5bc9b2
 
5bc9b2
     object_class->dispose = nautilus_freedesktop_dbus_dispose;
5bc9b2
+    object_class->constructed = nautilus_freedesktop_dbus_constructed;
5bc9b2
+    object_class->get_property = nautilus_freedesktop_dbus_get_property;
5bc9b2
+    object_class->set_property = nautilus_freedesktop_dbus_set_property;
5bc9b2
+
5bc9b2
+    g_object_class_install_property (object_class,
5bc9b2
+                                     PROP_CONNECTION,
5bc9b2
+                                     g_param_spec_object ("connection",
5bc9b2
+                                                          "Connection",
5bc9b2
+                                                          "GDBus connection property",
5bc9b2
+                                                          G_TYPE_DBUS_CONNECTION,
5bc9b2
+                                                          G_PARAM_CONSTRUCT_ONLY |
5bc9b2
+                                                          G_PARAM_READWRITE));
5bc9b2
 }
5bc9b2
 
5bc9b2
 static void
5bc9b2
 nautilus_freedesktop_dbus_init (NautilusFreedesktopDBus *fdb)
5bc9b2
 {
5bc9b2
-    fdb->owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
5bc9b2
-                                    NAUTILUS_FDO_DBUS_NAME,
5bc9b2
-                                    G_BUS_NAME_OWNER_FLAGS_NONE,
5bc9b2
-                                    bus_acquired_cb,
5bc9b2
-                                    name_acquired_cb,
5bc9b2
-                                    name_lost_cb,
5bc9b2
-                                    fdb,
5bc9b2
-                                    NULL);
5bc9b2
+    fdb->skeleton = nautilus_freedesktop_file_manager1_skeleton_new ();
5bc9b2
 }
5bc9b2
 
5bc9b2
 void
5bc9b2
@@ -239,8 +294,41 @@ nautilus_freedesktop_dbus_set_open_locations (NautilusFreedesktopDBus  *fdb,
5bc9b2
 
5bc9b2
 /* Tries to own the org.freedesktop.FileManager1 service name */
5bc9b2
 NautilusFreedesktopDBus *
5bc9b2
-nautilus_freedesktop_dbus_new (void)
5bc9b2
+nautilus_freedesktop_dbus_new (GDBusConnection *connection)
5bc9b2
 {
5bc9b2
     return g_object_new (nautilus_freedesktop_dbus_get_type (),
5bc9b2
+                         "connection", connection,
5bc9b2
                          NULL);
5bc9b2
 }
5bc9b2
+
5bc9b2
+gboolean
5bc9b2
+nautilus_freedesktop_dbus_register (NautilusFreedesktopDBus  *fdb,
5bc9b2
+                                    GError                  **error)
5bc9b2
+{
5bc9b2
+    gboolean success;
5bc9b2
+
5bc9b2
+    success = g_dbus_interface_skeleton_export (G_DBUS_INTERFACE_SKELETON (fdb->skeleton),
5bc9b2
+                                                fdb->connection,
5bc9b2
+                                                NAUTILUS_FDO_DBUS_PATH,
5bc9b2
+                                                error);
5bc9b2
+
5bc9b2
+    if (success)
5bc9b2
+    {
5bc9b2
+        g_signal_connect (fdb->skeleton, "handle-show-items",
5bc9b2
+                          G_CALLBACK (skeleton_handle_show_items_cb), fdb);
5bc9b2
+        g_signal_connect (fdb->skeleton, "handle-show-folders",
5bc9b2
+                          G_CALLBACK (skeleton_handle_show_folders_cb), fdb);
5bc9b2
+        g_signal_connect (fdb->skeleton, "handle-show-item-properties",
5bc9b2
+                          G_CALLBACK (skeleton_handle_show_item_properties_cb), fdb);
5bc9b2
+    }
5bc9b2
+
5bc9b2
+    return success;
5bc9b2
+}
5bc9b2
+
5bc9b2
+void
5bc9b2
+nautilus_freedesktop_dbus_unregister (NautilusFreedesktopDBus *fdb)
5bc9b2
+{
5bc9b2
+    g_dbus_interface_skeleton_unexport (G_DBUS_INTERFACE_SKELETON (fdb->skeleton));
5bc9b2
+
5bc9b2
+    g_signal_handlers_disconnect_by_data (fdb->skeleton, fdb);
5bc9b2
+}
5bc9b2
diff --git a/src/nautilus-freedesktop-dbus.h b/src/nautilus-freedesktop-dbus.h
5bc9b2
index 410c420..ee2ced5 100644
5bc9b2
--- a/src/nautilus-freedesktop-dbus.h
5bc9b2
+++ b/src/nautilus-freedesktop-dbus.h
5bc9b2
@@ -23,6 +23,7 @@
5bc9b2
 #define __NAUTILUS_FREEDESKTOP_DBUS_H__
5bc9b2
 
5bc9b2
 #include <glib-object.h>
5bc9b2
+#include <gio/gio.h>
5bc9b2
 
5bc9b2
 #define NAUTILUS_FDO_DBUS_IFACE "org.freedesktop.FileManager1"
5bc9b2
 #define NAUTILUS_FDO_DBUS_NAME  "org.freedesktop.FileManager1"
5bc9b2
@@ -44,7 +45,10 @@ typedef struct _NautilusFreedesktopDBus NautilusFreedesktopDBus;
5bc9b2
 typedef struct _NautilusFreedesktopDBusClass NautilusFreedesktopDBusClass;
5bc9b2
 
5bc9b2
 GType nautilus_freedesktop_dbus_get_type (void);
5bc9b2
-NautilusFreedesktopDBus * nautilus_freedesktop_dbus_new (void);
5bc9b2
+NautilusFreedesktopDBus * nautilus_freedesktop_dbus_new (GDBusConnection *connection);
5bc9b2
+
5bc9b2
+gboolean nautilus_freedesktop_dbus_register (NautilusFreedesktopDBus *fdb, GError **error);
5bc9b2
+void nautilus_freedesktop_dbus_unregister (NautilusFreedesktopDBus *fdb);
5bc9b2
 
5bc9b2
 void nautilus_freedesktop_dbus_set_open_locations (NautilusFreedesktopDBus *fdb, const gchar **locations);
5bc9b2
 
5bc9b2
-- 
5bc9b2
2.38.1
5bc9b2