[nautilus] dbus-manager: add a skeleton of NautilusDBusManager
- From: Cosimo Cecchi <cosimoc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [nautilus] dbus-manager: add a skeleton of NautilusDBusManager
- Date: Thu, 2 Dec 2010 01:35:01 +0000 (UTC)
commit b238be002e446e102e056b8484666f21feb6b6f2
Author: Cosimo Cecchi <cosimoc gnome org>
Date: Wed Dec 1 19:39:31 2010 +0100
dbus-manager: add a skeleton of NautilusDBusManager
libnautilus-private/Makefile.am | 2 +
libnautilus-private/nautilus-dbus-manager.c | 171 +++++++++++++++++++++++++++
libnautilus-private/nautilus-dbus-manager.h | 10 ++
src/nautilus-application.c | 5 +
4 files changed, 188 insertions(+), 0 deletions(-)
---
diff --git a/libnautilus-private/Makefile.am b/libnautilus-private/Makefile.am
index 0acf9d9..610541b 100644
--- a/libnautilus-private/Makefile.am
+++ b/libnautilus-private/Makefile.am
@@ -57,6 +57,8 @@ libnautilus_private_la_SOURCES = \
nautilus-column-chooser.h \
nautilus-column-utilities.c \
nautilus-column-utilities.h \
+ nautilus-dbus-manager.c \
+ nautilus-dbus-manager.h \
nautilus-debug-log.c \
nautilus-debug-log.h \
nautilus-default-file-icon.c \
diff --git a/libnautilus-private/nautilus-dbus-manager.c b/libnautilus-private/nautilus-dbus-manager.c
new file mode 100644
index 0000000..302d469
--- /dev/null
+++ b/libnautilus-private/nautilus-dbus-manager.c
@@ -0,0 +1,171 @@
+#include <config.h>
+
+#include "nautilus-dbus-manager.h"
+
+#include <gio/gio.h>
+
+static const gchar introspection_xml[] =
+ "<node>"
+ " <interface name='org.gnome.nautilus.FileOperations'>"
+ " <method name='CopyURIs'>"
+ " <arg type='as' name='URIList' direction='in'/>"
+ " <arg type='s' name='Destination' direction='in'/>"
+ " </method>"
+ " </interface>"
+ "</node>";
+
+typedef struct _NautilusDBusManager NautilusDBusManager;
+typedef struct _NautilusDBusManagerClass NautilusDBusManagerClass;
+
+struct _NautilusDBusManager {
+ GObject parent;
+
+ GDBusConnection *connection;
+
+ guint owner_id;
+ guint registration_id;
+};
+
+struct _NautilusDBusManagerClass {
+ GObjectClass parent_class;
+};
+
+static GType nautilus_dbus_manager_get_type (void) G_GNUC_CONST;
+G_DEFINE_TYPE (NautilusDBusManager, nautilus_dbus_manager, G_TYPE_OBJECT);
+
+static NautilusDBusManager *singleton = NULL;
+
+static void
+nautilus_dbus_manager_dispose (GObject *object)
+{
+ NautilusDBusManager *self = (NautilusDBusManager *) object;
+
+ if (self->registration_id != 0)
+ {
+ g_dbus_connection_unregister_object (self->connection, self->registration_id);
+ self->registration_id = 0;
+ }
+
+ if (self->owner_id != 0)
+ {
+ g_bus_unown_name (self->owner_id);
+ self->owner_id = 0;
+ }
+
+ g_clear_object (&self->connection);
+
+ G_OBJECT_CLASS (nautilus_dbus_manager_parent_class)->dispose (object);
+}
+
+static void
+nautilus_dbus_manager_class_init (NautilusDBusManagerClass *klass)
+{
+ GObjectClass *oclass = G_OBJECT_CLASS (klass);
+
+ oclass->dispose = nautilus_dbus_manager_dispose;
+}
+
+static void
+handle_method_call (GDBusConnection *connection,
+ const gchar *sender,
+ const gchar *object_path,
+ const gchar *interface_name,
+ const gchar *method_name,
+ GVariant *parameters,
+ GDBusMethodInvocation *invocation,
+ gpointer user_data)
+{
+ const gchar **uris = NULL;
+ const gchar *destination_uri = NULL;
+
+ if (g_strcmp0 (method_name, "CopyURIs") == 0)
+ {
+ g_variant_get (parameters, "(^a&s&s)", &uris, &destination_uri);
+
+ g_print ("Called CopyURIs with dest %s and uri %s\n", destination_uri, uris[0]);
+ }
+
+ g_dbus_method_invocation_return_value (invocation, NULL);
+}
+
+static const GDBusInterfaceVTable interface_vtable =
+{
+ handle_method_call,
+ NULL,
+ NULL,
+};
+
+static void
+name_acquired_cb (GDBusConnection *conn,
+ const gchar *name,
+ gpointer user_data)
+{
+ NautilusDBusManager *self = user_data;
+ GDBusNodeInfo *introspection_data;
+ GError *error = NULL;
+
+ self->connection = g_object_ref (conn);
+ introspection_data = g_dbus_node_info_new_for_xml (introspection_xml, &error);
+
+ if (error != NULL)
+ {
+ g_warning ("Error parsing the FileOperations XML interface: %s", error->message);
+ g_error_free (error);
+
+ g_bus_unown_name (self->owner_id);
+ self->owner_id = 0;
+
+ return;
+ }
+
+ self->registration_id = g_dbus_connection_register_object (conn,
+ "/org/gnome/nautilus",
+ introspection_data->interfaces[0],
+ &interface_vtable,
+ self,
+ NULL, &error);
+
+ if (error != NULL)
+ {
+ g_warning ("Error registering the FileOperations proxy on the bus: %s", error->message);
+ g_error_free (error);
+
+ g_bus_unown_name (self->owner_id);
+
+ return;
+ }
+}
+
+static void
+name_lost_cb (GDBusConnection *conn,
+ const gchar *name,
+ gpointer user_data)
+{
+
+}
+
+static void
+nautilus_dbus_manager_init (NautilusDBusManager *self)
+{
+ self->owner_id = g_bus_own_name (G_BUS_TYPE_SESSION,
+ "org.gnome.nautilus",
+ G_BUS_NAME_OWNER_FLAGS_NONE,
+ NULL,
+ name_acquired_cb,
+ name_lost_cb,
+ self,
+ NULL);
+}
+
+void
+nautilus_dbus_manager_start (void)
+{
+ singleton = g_object_new (nautilus_dbus_manager_get_type (),
+ NULL);
+}
+
+void
+nautilus_dbus_manager_stop (void)
+{
+ g_clear_object (&singleton);
+}
diff --git a/libnautilus-private/nautilus-dbus-manager.h b/libnautilus-private/nautilus-dbus-manager.h
new file mode 100644
index 0000000..dd2d8b7
--- /dev/null
+++ b/libnautilus-private/nautilus-dbus-manager.h
@@ -0,0 +1,10 @@
+
+#ifndef __NAUTILUS_DBUS_MANAGER_H__
+#define __NAUTILUS_DBUS_MANAGER_H__
+
+#include <glib-object.h>
+
+void nautilus_dbus_manager_start (void);
+void nautilus_dbus_manager_stop (void);
+
+#endif /* __NAUTILUS_DBUS_MANAGER_H__ */
diff --git a/src/nautilus-application.c b/src/nautilus-application.c
index f32ef09..9eecbd6 100644
--- a/src/nautilus-application.c
+++ b/src/nautilus-application.c
@@ -53,6 +53,7 @@
#include "nautilus-window-private.h"
#include "nautilus-window-slot.h"
+#include <libnautilus-private/nautilus-dbus-manager.h>
#include <libnautilus-private/nautilus-debug-log.h>
#include <libnautilus-private/nautilus-desktop-link-monitor.h>
#include <libnautilus-private/nautilus-directory-private.h>
@@ -1266,6 +1267,8 @@ nautilus_application_finalize (GObject *object)
application->proxy = NULL;
}
+ nautilus_dbus_manager_stop ();
+
G_OBJECT_CLASS (nautilus_application_parent_class)->finalize (object);
}
@@ -1545,6 +1548,8 @@ nautilus_application_startup (GApplication *app)
/* initialize search path for custom icons */
gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),
NAUTILUS_DATADIR G_DIR_SEPARATOR_S "icons");
+
+ nautilus_dbus_manager_start ();
}
static void
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]