[nautilus/wip/csoriano/destktop-split2: 2/3] desktop-application: use dbus for opening files
- From: Carlos Soriano Sánchez <csoriano src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus/wip/csoriano/destktop-split2: 2/3] desktop-application: use dbus for opening files
- Date: Wed, 16 Mar 2016 17:22:08 +0000 (UTC)
commit da82e57d3d9c391455847ea053bc581ccd25517e
Author: Carlos Soriano <csoriano gnome org>
Date: Wed Mar 16 17:50:51 2016 +0100
desktop-application: use dbus for opening files
src/nautilus-desktop-application.c | 104 +++++++++++++++++++++++++++++++++---
1 files changed, 97 insertions(+), 7 deletions(-)
---
diff --git a/src/nautilus-desktop-application.c b/src/nautilus-desktop-application.c
index 7be01d7..ba7d3b5 100644
--- a/src/nautilus-desktop-application.c
+++ b/src/nautilus-desktop-application.c
@@ -21,30 +21,91 @@
#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
+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 *self,
+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;
- g_print ("open location full %s\n", g_file_get_uri (location));
uri = g_file_get_uri (location);
+ g_print ("open location full %s\n", g_file_get_uri (location));
if (eel_uri_is_desktop (uri) && target_window &&
NAUTILUS_IS_DESKTOP_WINDOW (target_window))
{
@@ -53,7 +114,16 @@ open_location_full (NautilusApplication *self,
else
{
g_print ("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);
}
@@ -65,14 +135,15 @@ nautilus_application_set_desktop_visible (NautilusDesktopApplication *self,
if (visible)
{
- g_print ("set desktop visible\n");
- nautilus_desktop_window_ensure ();
+ g_print ("set desktop visible\n");
+ nautilus_desktop_window_ensure ();
}
else
{
- desktop_window = nautilus_desktop_window_get ();
- if (desktop_window != NULL) {
- gtk_widget_destroy (desktop_window);
+ desktop_window = nautilus_desktop_window_get ();
+ if (desktop_window != NULL)
+ {
+ gtk_widget_destroy (desktop_window);
}
}
}
@@ -123,14 +194,31 @@ nautilus_desktop_application_startup (GApplication *app)
g_print ("startup desktop\n");
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);
g_print ("desktop application class init\n");
@@ -139,6 +227,8 @@ nautilus_desktop_application_class_init (NautilusDesktopApplicationClass *klass)
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]