[nautilus] desktop-application: use dbus for opening files



commit 5e6026e034a000d7d19c1b094af3871708d00691
Author: Carlos Soriano <csoriano gnome org>
Date:   Wed Mar 16 17:50:51 2016 +0100

    desktop-application: use dbus for opening files
    
    Since the desktop is in a different binary now, we need a way to comunicate
    the desktop proccess with Nautilus proccess, since we want to avoid
    any Nautilus handling in the desktop proccess.
    
    To do so, use the freedesktop dbus API for accessing the file manager.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=712620

 src/nautilus-desktop-application.c |   93 +++++++++++++++++++++++++++++++++++-
 1 files changed, 91 insertions(+), 2 deletions(-)
---
diff --git a/src/nautilus-desktop-application.c b/src/nautilus-desktop-application.c
index bce6800..53ab6d7 100644
--- a/src/nautilus-desktop-application.c
+++ b/src/nautilus-desktop-application.c
@@ -21,26 +21,87 @@
 #include "nautilus-desktop-application.h"
 #include "nautilus-desktop-window.h"
 
+#include "nautilus-freedesktop-generated.h"
+
 #include <libnautilus-private/nautilus-global-preferences.h>
 #include <eel/eel.h>
 #include <gdk/gdkx.h>
 
+static NautilusFreedesktopFileManager1 *freedesktop_proxy = NULL;
+
 struct _NautilusDesktopApplication
 {
   NautilusApplication parent_instance;
+
+  GCancellable *freedesktop_cancellable;
+  GList *pending_locations;
 };
 
 G_DEFINE_TYPE (NautilusDesktopApplication, nautilus_desktop_application, NAUTILUS_TYPE_APPLICATION)
 
+static void
+on_show_folders (GObject      *source_object,
+                 GAsyncResult *res,
+                 gpointer      user_data)
+{
+  GError *error = NULL;
+
+  nautilus_freedesktop_file_manager1_call_show_items_finish (freedesktop_proxy,
+                                                             res,
+                                                             &error);
+  if (error != NULL)
+    {
+      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+        {
+          g_warning ("Unable to show items with File Manager freedesktop proxy: %s", error->message);
+        }
+      g_error_free (error);
+    }
+}
+
+static void
+open_location_on_dbus (NautilusDesktopApplication *self,
+                       const gchar                *uri)
+{
+  const gchar *uris[] = { uri, NULL };
+
+  nautilus_freedesktop_file_manager1_call_show_folders (freedesktop_proxy,
+                                                        uris,
+                                                        "",
+                                                        self->freedesktop_cancellable,
+                                                        on_show_folders,
+                                                        self);
+}
+
 
 static void
-open_location_full (NautilusApplication     *self,
+on_freedesktop_bus_proxy_created (GObject      *source_object,
+                                  GAsyncResult *res,
+                                  gpointer      user_data)
+{
+  GError *error = NULL;
+
+  freedesktop_proxy = nautilus_freedesktop_file_manager1_proxy_new_for_bus_finish (res, &error);
+
+  if (error != NULL)
+    {
+      if (!g_error_matches (error, G_IO_ERROR, G_IO_ERROR_CANCELLED))
+        {
+          g_warning ("Unable to create File Manager freedesktop proxy: %s", error->message);
+        }
+      g_error_free (error);
+    }
+}
+
+static void
+open_location_full (NautilusApplication     *app,
                     GFile                   *location,
                     NautilusWindowOpenFlags  flags,
                     GList                   *selection,
                     NautilusWindow          *target_window,
                     NautilusWindowSlot      *target_slot)
 {
+  NautilusDesktopApplication *self = NAUTILUS_DESKTOP_APPLICATION (app);
   gchar *uri;
 
   uri = g_file_get_uri (location);
@@ -51,8 +112,16 @@ open_location_full (NautilusApplication     *self,
     }
   else
     {
-      g_warning ("other location, use dbus to communicate with nautilus. This process is only for the 
desktop\n");
+      if (freedesktop_proxy)
+        {
+          open_location_on_dbus (self, uri);
+        }
+      else
+        {
+          g_warning ("cannot open folder on desktop, freedesktop bus not ready\n");
+        }
     }
+
   g_free (uri);
 }
 
@@ -125,19 +194,39 @@ nautilus_desktop_application_startup (GApplication *app)
   NautilusDesktopApplication *self = NAUTILUS_DESKTOP_APPLICATION (app);
 
   nautilus_application_startup_common (NAUTILUS_APPLICATION (app));
+  self->freedesktop_cancellable = g_cancellable_new ();
+  nautilus_freedesktop_file_manager1_proxy_new_for_bus (G_BUS_TYPE_SESSION,
+                                                        G_DBUS_PROXY_FLAGS_NONE,
+                                                        "org.freedesktop.FileManager1",
+                                                        "/org/freedesktop/FileManager1",
+                                                        self->freedesktop_cancellable,
+                                                        on_freedesktop_bus_proxy_created,
+                                                        self);
+
   init_desktop (self);
 }
 
 static void
+nautilus_desktop_application_dispose (GObject *object)
+{
+  NautilusDesktopApplication *self = NAUTILUS_DESKTOP_APPLICATION (object);
+
+  g_clear_object (&self->freedesktop_cancellable);
+}
+
+static void
 nautilus_desktop_application_class_init (NautilusDesktopApplicationClass *klass)
 {
   GApplicationClass *application_class = G_APPLICATION_CLASS (klass);
+  GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
   NautilusApplicationClass *parent_class = NAUTILUS_APPLICATION_CLASS (klass);
 
   parent_class->open_location_full = open_location_full;
 
   application_class->startup = nautilus_desktop_application_startup;
   application_class->activate = nautilus_desktop_application_activate;
+
+  gobject_class->dispose = nautilus_desktop_application_dispose;
 }
 
 static void


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