[epiphany/gdbus: 3/3] ephy-dbus: half-port to gdbus



commit 8aa468b6dbe2f7429abf4c8ef1037a514c3bff1a
Author: Diego Escalante Urrelo <descalante igalia com>
Date:   Sat May 7 18:37:25 2011 -0500

    ephy-dbus: half-port to gdbus

 configure.ac          |   13 +-
 src/Makefile.am       |   34 +++---
 src/ephy-activation.c |  102 -----------------
 src/ephy-activation.h |   49 --------
 src/ephy-dbus.c       |  293 ++++++++++++++++++++++++++++++++-----------------
 src/ephy-dbus.h       |    5 +-
 src/ephy-main.c       |   69 +++++++-----
 7 files changed, 255 insertions(+), 310 deletions(-)
---
diff --git a/configure.ac b/configure.ac
index cfc0df3..cf9e1ff 100644
--- a/configure.ac
+++ b/configure.ac
@@ -83,7 +83,7 @@ if test "$enable_maintainer_mode" = "yes"; then
 	DEPRECATION_FLAGS="-DG_DISABLE_DEPRECATED -DGDK_DISABLE_DEPRECATED -DGDK_PIXBUF_DISABLE_DEPRECATED -DPANGO_DISABLE_DEPRECATED -DGNOME_DISABLE_DEPRECATED -DGTK_DISABLE_DEPRECATED -DGSEAL_ENABLE"
 fi
 
-GLIB_REQUIRED=2.25.13
+GLIB_REQUIRED=2.29.5
 GTK_REQUIRED=3.0.2
 LIBXML_REQUIRED=2.6.12
 LIBXSLT_REQUIRED=1.1.7
@@ -121,18 +121,17 @@ PKG_CHECK_MODULES([DEPENDENCIES], [
 		  libsoup-gnome-2.4 >= $LIBSOUP_GNOME_REQUIRED
 		  gnome-keyring-1 >= $GNOME_KEYRING_REQUIRED
                   gsettings-desktop-schemas >= $GSETTINGS_DESKTOP_SCHEMAS_REQUIRED
+		  dbus-glib-1 >= $DBUS_GLIB_REQUIRED
 		  ])
 
 # ****
-# DBUS
+# GDBUS
 # ****
 
-PKG_CHECK_MODULES([DBUS],[dbus-glib-1 >= $DBUS_GLIB_REQUIRED])
+AC_PATH_PROG([GDBUS_BINDING_TOOL],[gdbus-codegen],[no])
 
-AC_PATH_PROG([DBUS_BINDING_TOOL],[dbus-binding-tool],[no])
-
-if test "$DBUS_BINDING_TOOL" = "no"; then
-	AC_MSG_ERROR([dbus-binding-tool not found])
+if test "$GDBUS_BINDING_TOOL" = "no"; then
+	AC_MSG_ERROR([gdbus-codegen not found])
 fi
 
 # ******************
diff --git a/src/Makefile.am b/src/Makefile.am
index f399505..1042ab7 100644
--- a/src/Makefile.am
+++ b/src/Makefile.am
@@ -15,7 +15,6 @@ header_DATA = \
 
 NOINST_H_FILES = \
 	ephy-action-helper.h			\
-	ephy-activation.h			\
 	ephy-encoding-dialog.h			\
 	ephy-encoding-menu.h			\
 	ephy-find-toolbar.h			\
@@ -53,7 +52,6 @@ INST_H_FILES = \
 	$(NULL)
 
 libephymain_la_SOURCES = \
-	ephy-activation.c			\
 	ephy-action-helper.c			\
 	ephy-completion-model.c			\
 	ephy-completion-model.h			\
@@ -65,6 +63,8 @@ libephymain_la_SOURCES = \
 	ephy-extensions-manager.c		\
 	ephy-find-toolbar.c			\
 	ephy-fullscreen-popup.c			\
+	ephy-gdbus-bindings.c			\
+	ephy-gdbus-bindings.h			\
 	ephy-go-action.c			\
 	ephy-home-action.c			\
 	ephy-history-window.c			\
@@ -186,8 +186,8 @@ endif
 
 BUILT_SOURCES =	\
 	$(TYPES_SOURCE)			\
-	ephy-dbus-client-bindings.h	\
-	ephy-dbus-server-bindings.h
+	ephy-gdbus-bindings.c		\
+	ephy-gdbus-bindings.h
 
 
 TYPES_SOURCE = \
@@ -197,8 +197,8 @@ TYPES_SOURCE = \
 stamp_files = \
 	stamp-ephy-type-builtins.c	\
 	stamp-ephy-type-builtins.h	\
-	stamp-ephy-dbus-server-bindings.h	\
-	stamp-ephy-dbus-client-bindings.h
+	stamp-ephy-gdbus-bindings.c	\
+	stamp-ephy-gdbus-bindings.h
 
 ephy-type-builtins.c: stamp-ephy-type-builtins.c Makefile
 	@true
@@ -242,20 +242,16 @@ stamp-ephy-type-builtins.h: Makefile $(INST_H_FILES) $(NOINST_H_FILES)
 	&& rm -f xgen-$(@F) \
 	&& echo timestamp > $(@F)
 
-ephy-dbus-server-bindings.h: stamp-ephy-dbus-server-bindings.h
+ephy-gdbus-bindings.c:
+ephy-gdbus-bindings.h: stamp-ephy-gdbus-bindings
 	@true
-stamp-ephy-dbus-server-bindings.h: $(top_srcdir)/data/epiphany-service.xml Makefile
-	$(AM_V_GEN) $(DBUS_BINDING_TOOL) --prefix=ephy_activation --mode=glib-server $< > xgen-$(@F) \
-	&& ( cmp -s xgen-$(@F) $(@F:stamp-%=%) || cp xgen-$(@F) $(@F:stamp-%=%) ) \
-	&& rm -f xgen-$(@F) \
-	&& echo timestamp > $(@F)
-
-ephy-dbus-client-bindings.h: stamp-ephy-dbus-client-bindings.h
-	@true
-stamp-ephy-dbus-client-bindings.h: $(top_srcdir)/data/epiphany-service.xml Makefile
-	$(AM_V_GEN) $(DBUS_BINDING_TOOL) --prefix=ephy_activation --mode=glib-client $< > xgen-$(@F) \
-	&& ( cmp -s xgen-$(@F) $(@F:stamp-%=%) || cp xgen-$(@F) $(@F:stamp-%=%) ) \
-	&& rm -f xgen-$(@F) \
+stamp-ephy-gdbus-bindings: $(top_srcdir)/data/epiphany-service.xml Makefile
+	$(AM_V_GEN) $(GDBUS_BINDING_TOOL) \
+		--interface-prefix org.gnome.Epiphany. \
+		--generate-c-code ephy-gdbus-bindings \
+		--c-namespace Epiphany \
+		--c-generate-object-manager \
+		$(top_srcdir)/data/epiphany-service.xml \
 	&& echo timestamp > $(@F)
 
 CLEANFILES = $(stamp_files) $(BUILT_SOURCES)
diff --git a/src/ephy-dbus.c b/src/ephy-dbus.c
index a00c81d..e4cbe40 100644
--- a/src/ephy-dbus.c
+++ b/src/ephy-dbus.c
@@ -24,10 +24,13 @@
 #include "ephy-type-builtins.h"
 #include "ephy-marshal.h"
 #include "ephy-debug.h"
-#include "ephy-activation.h"
-#include "ephy-dbus-server-bindings.h"
+#include "ephy-session.h"
+#include "ephy-shell.h"
+#include "ephy-settings.h"
+#include "ephy-gdbus-bindings.h"
 
 #include <string.h>
+#include <gio/gio.h>
 #include <dbus/dbus-glib-bindings.h>
 
 /* dbus 0.6 API change */
@@ -51,12 +54,18 @@
 
 struct _EphyDbusPrivate
 {
-	DBusGConnection *session_bus;
-	DBusGConnection *system_bus;
+	GDBusConnection *session_bus;
+	GDBusConnection *system_bus;
 	guint session_reconnect_timeout_id;
 	guint system_reconnect_timeout_id;
 	guint is_session_service_owner : 1;
 	guint register_name : 1;
+
+	guint owner_id;
+	guint session_bus_filter_id;
+	guint system_bus_filter_id;
+
+	GDBusObjectManagerServer *manager;
 };
 
 enum
@@ -77,15 +86,6 @@ static EphyDbus *ephy_dbus_instance;
 static guint signals[LAST_SIGNAL];
 GQuark ephy_dbus_error_quark;
 
-/* Filter signals form session bus */
-static DBusHandlerResult session_filter_func (DBusConnection *connection,
-				              DBusMessage *message,
-				              void *user_data);
-/* Filter signals from system bus */
-static DBusHandlerResult system_filter_func (DBusConnection *connection,
-				             DBusMessage *message,
-				             void *user_data);
-
 /* Both  connect to their respective bus */
 static gboolean ephy_dbus_connect_to_session_bus (EphyDbus*, GError**);
 static gboolean ephy_dbus_connect_to_system_bus  (EphyDbus*, GError**);
@@ -97,6 +97,7 @@ ephy_dbus_connect_to_session_bus_cb (gpointer user_data)
 {
 	EphyDbus *dbus = EPHY_DBUS (user_data);
 
+	LOG ("connect to ss bus cb");
 	if (!ephy_dbus_connect_to_session_bus (dbus, NULL))
 	{
 		/* try again */
@@ -126,23 +127,20 @@ ephy_dbus_connect_to_system_bus_cb (gpointer user_data)
 	return FALSE;
 }
 
-static DBusHandlerResult
-session_filter_func (DBusConnection *connection,
-	     	     DBusMessage *message,
-	     	     void *user_data)
+static GDBusMessage*
+session_filter_func (GDBusConnection *connection,
+	     	     GDBusMessage *message,
+		     gboolean incoming,
+	     	     gpointer user_data)
 {
 	EphyDbus *ephy_dbus = EPHY_DBUS (user_data);
 	EphyDbusPrivate *priv = ephy_dbus->priv;
 
-	if (dbus_message_is_signal (message,
-				    DBUS_INTERFACE_LOCAL,
-				    "Disconnected"))
+	if (g_dbus_message_get_message_type (message) == G_DBUS_MESSAGE_TYPE_SIGNAL &&
+	    g_strcmp0 (g_dbus_message_get_member (message), "Disconnected"))
 	{
 		LOG ("EphyDbus disconnected from session bus");
 
-		dbus_g_connection_unref (priv->session_bus);
-		priv->session_bus = NULL;
-
 		g_signal_emit (ephy_dbus, signals[DISCONNECTED], 0, EPHY_DBUS_SESSION);
 
 		/* try to reconnect later ... */
@@ -151,29 +149,31 @@ session_filter_func (DBusConnection *connection,
 				       (GSourceFunc) ephy_dbus_connect_to_session_bus_cb,
 				       ephy_dbus);
 
-		return DBUS_HANDLER_RESULT_HANDLED;
+		g_object_unref (message);
+		message = NULL;
+		return message;
 	}
 
-	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+	return message;
 }
 
-static DBusHandlerResult
-system_filter_func (DBusConnection *connection,
-	     	    DBusMessage *message,
-	     	    void *user_data)
+static GDBusMessage*
+system_filter_func (GDBusConnection *connection,
+	     	    GDBusMessage *message,
+		    gboolean incoming,
+	     	    gpointer user_data)
 {
 	EphyDbus *ephy_dbus = EPHY_DBUS (user_data);
 	EphyDbusPrivate *priv = ephy_dbus->priv;
 
 	LOG ("EphyDbus filtering message from system bus");
 
-	if (dbus_message_is_signal (message,
-				    DBUS_INTERFACE_LOCAL,
-				    "Disconnected"))
+	if (g_dbus_message_get_message_type (message) == G_DBUS_MESSAGE_TYPE_SIGNAL &&
+	    g_strcmp0 (g_dbus_message_get_member (message), "Disconnected"))
 	{
 		LOG ("EphyDbus disconnected from system bus");
 
-		dbus_g_connection_unref (priv->system_bus);
+		g_object_unref (priv->system_bus);
 		priv->system_bus = NULL;
 
 		g_signal_emit (ephy_dbus, signals[DISCONNECTED], 0, EPHY_DBUS_SYSTEM);
@@ -184,10 +184,12 @@ system_filter_func (DBusConnection *connection,
 				       (GSourceFunc) ephy_dbus_connect_to_system_bus_cb,
 				       ephy_dbus);
 
-		return DBUS_HANDLER_RESULT_HANDLED;
+		g_object_unref (message);
+		message = NULL;
+		return message;
 	}
 
-	return DBUS_HANDLER_RESULT_NOT_YET_HANDLED;
+	return message;
 }
 
 static gboolean
@@ -198,93 +200,176 @@ ephy_dbus_connect_to_system_bus (EphyDbus *ephy_dbus,
 
 	LOG ("EphyDbus connecting to system DBUS");
 
-	priv->system_bus = dbus_g_bus_get (DBUS_BUS_SYSTEM, error);
+	priv->system_bus = g_bus_get_sync (G_BUS_TYPE_SYSTEM, NULL, error);
 	if (priv->system_bus == NULL)
 	{
 		g_warning ("Unable to connect to system bus: %s", error ? (*error)->message : "");
 		return FALSE;
 	}
 
-	if (dbus_g_connection_get_connection (priv->system_bus) == NULL)
-	{
-		g_warning ("DBus connection is null");
-		g_set_error (error,
-			     EPHY_DBUS_ERROR_QUARK,
-			     0,
-			     "DBus connection is NULL");
-		return FALSE;
-	}
-
+#if 0
 	dbus_connection_set_exit_on_disconnect 
 		(dbus_g_connection_get_connection (priv->system_bus),
 		 FALSE);
+#endif
 
-	dbus_connection_add_filter
-		(dbus_g_connection_get_connection (priv->system_bus),
-		 system_filter_func, ephy_dbus, NULL);
+	priv->system_bus_filter_id = g_dbus_connection_add_filter
+		(priv->system_bus, system_filter_func, ephy_dbus, NULL);
 
 	g_signal_emit (ephy_dbus, signals[CONNECTED], 0, EPHY_DBUS_SYSTEM);
 
 	return TRUE;
 }
 
+
+static gboolean
+session_queue_command (EphySessionCommand command,
+		       char *arg,
+		       char **args,
+		       guint startup_id)
+{
+	EphyShell *shell;
+	EphySession *session;
+
+	shell = ephy_shell_get_default ();
+	if (shell == NULL)
+	{
+		LOG ("Error activating remote method: shutting down");
+		return FALSE;
+	}
+
+	session = EPHY_SESSION (ephy_shell_get_session (ephy_shell_get_default()));
+	g_assert (session != NULL);
+
+	ephy_session_queue_command (session, command, arg, args,
+				    (guint32) startup_id, TRUE);
+
+	return TRUE;
+}
+
+static gboolean
+load_urilist_cb (EpiphanyOrgGnomeEpiphany *object,
+		 GDBusMethodInvocation *invocation,
+		 char **uris,
+		 char *options,
+		 guint startup_id)
+{
+	char *new_options;
+	gboolean ret;
+
+	LOG ("handle load urilist");
+
+	new_options = g_strconcat (options, "external,", NULL);
+	ret = session_queue_command (EPHY_SESSION_CMD_OPEN_URIS,
+				     new_options, uris, startup_id);
+	g_free (new_options);
+
+	return ret;
+}
+
+static gboolean
+load_session_cb (EpiphanyOrgGnomeEpiphany *object,
+		 GDBusMethodInvocation *invocation,
+		 char *session_name,
+		 guint startup_id)
+{
+	LOG ("handle load session");
+	return session_queue_command (EPHY_SESSION_CMD_LOAD_SESSION,
+				      session_name, NULL, startup_id);
+}
+
+static gboolean
+open_bookmarks_editor_cb (EpiphanyOrgGnomeEpiphany *object,
+			  GDBusMethodInvocation *invocation,
+			  guint startup_id)
+{
+	LOG ("handle open bookmarks editor");
+	if (g_settings_get_boolean (EPHY_SETTINGS_LOCKDOWN,
+				    EPHY_PREFS_LOCKDOWN_BOOKMARK_EDITING))
+	{
+		LOG ("Bookmarks editing is locked down.");
+		return FALSE;
+	}
+
+	return session_queue_command (EPHY_SESSION_CMD_OPEN_BOOKMARKS_EDITOR,
+				      NULL, NULL, startup_id);
+}
+
 static gboolean
 ephy_dbus_connect_to_session_bus (EphyDbus *ephy_dbus,
 				  GError **error)
 {
 	EphyDbusPrivate *priv = ephy_dbus->priv;
-	DBusGProxy *proxy;
+	GDBusProxy *proxy;
+	GVariant *ret;
 	guint request_ret;
 	
 	LOG ("EphyDbus connecting to session DBUS");
 
 	/* Init the DBus connection */
-	priv->session_bus = dbus_g_bus_get (DBUS_BUS_SESSION, error);
+	priv->session_bus = g_bus_get_sync (G_BUS_TYPE_SESSION, NULL, error);
 	if (priv->session_bus == NULL)
 	{
 		g_warning("Unable to connect to session bus: %s", error && *error ? (*error)->message : "");
 		return FALSE;
 	}
-
-	dbus_connection_set_exit_on_disconnect 
-		(dbus_g_connection_get_connection (priv->session_bus),
-		 FALSE);
-
-	dbus_connection_add_filter
-		(dbus_g_connection_get_connection (priv->session_bus),
-		 session_filter_func, ephy_dbus, NULL);
-
+#if 0
+	priv->session_bus_filter_id = g_dbus_connection_add_filter
+		(priv->session_bus, session_filter_func, ephy_dbus, NULL);
+#endif
 	if (priv->register_name == FALSE) return TRUE;
 
-	dbus_g_object_type_install_info (EPHY_TYPE_DBUS,
-					 &dbus_glib_ephy_activation_object_info);
-
-	/* Register DBUS path */
-	dbus_g_connection_register_g_object (priv->session_bus,
-					     DBUS_EPHY_PATH,
-					     G_OBJECT (ephy_dbus));
-
-	/* Register the service name, the constant here are defined in dbus-glib-bindings.h */
-	proxy = dbus_g_proxy_new_for_name (priv->session_bus,
-					   DBUS_SERVICE_DBUS,
-					   DBUS_PATH_DBUS,
-					   DBUS_INTERFACE_DBUS);
-
-	if (!org_freedesktop_DBus_request_name (proxy,
-						DBUS_EPHY_SERVICE,
-						DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT |
-						DBUS_NAME_FLAG_DO_NOT_QUEUE,
-						&request_ret, error))
-	{
-		/* We have a BIG problem! */
-		g_warning ("RequestName failed: %s\n", error ? (*error)->message : "");
-		return FALSE;
-	}
+	/* Register the service name, the constant here are defined in
+	 * dbus-glib-bindings.h */
+	proxy = g_dbus_proxy_new_for_bus_sync
+				(G_BUS_TYPE_SESSION,
+				 G_DBUS_PROXY_FLAGS_NONE,
+				 NULL,
+				 DBUS_SERVICE_DBUS,
+				 DBUS_PATH_DBUS,
+				 DBUS_INTERFACE_DBUS,
+				 NULL, NULL);
+
+	ret = g_dbus_proxy_call_sync
+			  (proxy,
+			   "RequestName",
+			   g_variant_new ("(su)",
+				   	  DBUS_EPHY_SERVICE,
+					  DBUS_NAME_FLAG_PROHIBIT_REPLACEMENT),
+			   G_DBUS_CALL_FLAGS_NONE, -1, NULL,
+			   NULL);
+
+	g_variant_get (ret, "(u)", &request_ret);
+	g_variant_unref (ret);
+	g_object_unref (proxy);
 
 	if (request_ret == DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER ||
 	    request_ret == DBUS_REQUEST_NAME_REPLY_ALREADY_OWNER)
 	{
+		EpiphanyOrgGnomeEpiphany *eobj;
+
+		LOG ("registering object");
+
+		if (priv->manager != NULL) return FALSE;
+
 		priv->is_session_service_owner = TRUE;
+		priv->manager = g_dbus_object_manager_server_new
+						("/org/gnome/Epiphany");
+		eobj = epiphany_org_gnome_epiphany_skeleton_new ();
+
+		g_signal_connect (eobj, "handle-open-bookmarks-editor",
+				  G_CALLBACK (open_bookmarks_editor_cb), NULL);
+		g_signal_connect (eobj, "handle-load-session",
+				  G_CALLBACK (load_session_cb), NULL);
+		g_signal_connect (eobj, "handle-load-urilist",
+				  G_CALLBACK (load_urilist_cb), NULL);
+
+		g_dbus_interface_skeleton_export
+			(G_DBUS_INTERFACE_SKELETON (eobj),
+			 priv->session_bus, "/org/gnome/Epiphany", NULL);
+
+		g_dbus_object_manager_server_set_connection
+			(priv->manager, priv->session_bus);
 	}
 	else if (request_ret == DBUS_REQUEST_NAME_REPLY_EXISTS ||
 		 request_ret == DBUS_REQUEST_NAME_REPLY_IN_QUEUE)
@@ -292,9 +377,8 @@ ephy_dbus_connect_to_session_bus (EphyDbus *ephy_dbus,
 		priv->is_session_service_owner = FALSE;
 	}
 
-	LOG ("Instance is %ssession bus owner.", priv->is_session_service_owner ? "" : "NOT ");
-
-	g_object_unref (proxy);
+	LOG ("Instance is %ssession bus owner.",
+	     priv->is_session_service_owner ? "" : "NOT ");
 
 	return TRUE;
 }
@@ -322,19 +406,17 @@ ephy_dbus_shutdown (EphyDbus *dbus)
 
 	if (priv->session_bus)
 	{
-		dbus_connection_remove_filter
-			(dbus_g_connection_get_connection (priv->session_bus),
-			 session_filter_func, dbus);
-		dbus_g_connection_unref (priv->session_bus);
+		g_dbus_connection_remove_filter
+			(priv->session_bus, priv->session_bus_filter_id);
+		g_object_unref (priv->session_bus);
 		priv->session_bus = NULL;
 	}
 
         if (priv->system_bus)
 	{
-		dbus_connection_remove_filter
-			(dbus_g_connection_get_connection (priv->system_bus),
-			 system_filter_func, dbus);
-		dbus_g_connection_unref (priv->system_bus);
+		g_dbus_connection_remove_filter
+			(priv->system_bus, priv->system_bus_filter_id);
+		g_object_unref (priv->system_bus);
 		priv->system_bus = NULL;
 	}
 }
@@ -452,12 +534,12 @@ ephy_dbus_get_default (void)
  * Returns: the #DBusGConnection for the @kind DBUS, or %NULL
  * if a connection could not be established.
  */
-DBusGConnection *
+GDBusConnection *
 ephy_dbus_get_bus (EphyDbus *dbus,
 		   EphyDbusBus kind)
 {
 	EphyDbusPrivate *priv = dbus->priv;
-	DBusGConnection *bus = NULL;
+	GDBusConnection *bus = NULL;
 
 	g_return_val_if_fail (EPHY_IS_DBUS (dbus), NULL);
 
@@ -475,6 +557,7 @@ ephy_dbus_get_bus (EphyDbus *dbus,
 	{
 		if (priv->session_bus == NULL)
 		{
+			LOG ("get_bus");
 			ephy_dbus_connect_to_session_bus (dbus, NULL);
 		}
 
@@ -488,11 +571,11 @@ ephy_dbus_get_bus (EphyDbus *dbus,
 	return bus;
 }
 
-DBusGProxy *
+GDBusProxy *
 ephy_dbus_get_proxy (EphyDbus *dbus,
 		     EphyDbusBus kind)
 {
-	DBusGConnection *bus = NULL;
+	GDBusConnection *bus = NULL;
 
 	g_return_val_if_fail (EPHY_IS_DBUS (dbus), NULL);
 	
@@ -505,10 +588,13 @@ ephy_dbus_get_proxy (EphyDbus *dbus,
 		return NULL;
 	}
 
-	return dbus_g_proxy_new_for_name (bus,
-					  DBUS_EPHY_SERVICE,
-					  DBUS_EPHY_PATH,
-					  DBUS_EPHY_INTERFACE);
+	return g_dbus_proxy_new_sync (bus,
+				      G_DBUS_PROXY_FLAGS_NONE,
+				      NULL,
+				      DBUS_EPHY_SERVICE,
+				      DBUS_EPHY_PATH,
+				      DBUS_EPHY_INTERFACE,
+				      NULL, NULL);
 }
 
 /* private API */
@@ -528,6 +614,7 @@ _ephy_dbus_startup (gboolean connect_and_register_name,
 	if (!connect_and_register_name) return TRUE;
 
 	/* We only connect to the session bus on startup*/
+	LOG ("startup");
 	return ephy_dbus_connect_to_session_bus (ephy_dbus_instance, error);
 }
 
diff --git a/src/ephy-dbus.h b/src/ephy-dbus.h
index c24544a..68b13a9 100644
--- a/src/ephy-dbus.h
+++ b/src/ephy-dbus.h
@@ -28,6 +28,7 @@
 
 /* Yes, we know that DBUS API isn't stable yet */
 #define DBUS_API_SUBJECT_TO_CHANGE
+#include <gio/gio.h>
 #include <dbus/dbus-glib.h>
 #include <dbus/dbus-glib-lowlevel.h>
 
@@ -76,10 +77,10 @@ GType		ephy_dbus_get_type	(void);
 
 EphyDbus       *ephy_dbus_get_default	(void);
 
-DBusGConnection *ephy_dbus_get_bus	(EphyDbus *dbus,
+GDBusConnection *ephy_dbus_get_bus	(EphyDbus *dbus,
 					 EphyDbusBus kind);
 
-DBusGProxy	*ephy_dbus_get_proxy	(EphyDbus *dbus,
+GDBusProxy	*ephy_dbus_get_proxy	(EphyDbus *dbus,
 					 EphyDbusBus kind);
 
 /* private */
diff --git a/src/ephy-main.c b/src/ephy-main.c
index 17ebb8f..321795e 100644
--- a/src/ephy-main.c
+++ b/src/ephy-main.c
@@ -20,6 +20,7 @@
 
 #include "config.h"
 
+#include "ephy-dbus.h"
 #include "ephy-settings.h"
 #include "ephy-shell.h"
 #include "ephy-file-helpers.h"
@@ -27,8 +28,7 @@
 #include "ephy-state.h"
 #include "ephy-debug.h"
 #include "ephy-stock-icons.h"
-#include "ephy-dbus-client-bindings.h"
-#include "ephy-activation.h"
+#include "ephy-gdbus-bindings.h"
 #include "ephy-session.h"
 #include "ephy-shell.h"
 #include "ephy-prefs.h"
@@ -199,16 +199,11 @@ slowly_and_stupidly_obtain_timestamp (Display *xdisplay)
 }
 
 static void
-unref_proxy_reply_cb (DBusGProxy *proxy,
-		      GError *error,
+unref_proxy_reply_cb (GObject *proxy,
+		      GAsyncResult *res,
 		      gpointer user_data)
 {
-	if (error != NULL)
-	{
-		g_warning ("An error occurred while calling remote method: %s", error->message);
-		g_error_free (error);
-	}
-
+	LOG ("unref proxy cb");
 	g_object_unref (proxy);
 
 	if (gtk_main_level ())
@@ -218,7 +213,7 @@ unref_proxy_reply_cb (DBusGProxy *proxy,
 }
 
 static gboolean
-open_urls (DBusGProxy *proxy,
+open_urls (EpiphanyOrgGnomeEpiphany *proxy,
 	   guint32 user_time,
 	   GError **error)
 {
@@ -246,9 +241,10 @@ open_urls (DBusGProxy *proxy,
 		uris = (char **) arguments;
 	}
 
-	org_gnome_Epiphany_load_ur_ilist_async
-		(proxy, (const char **) uris, options->str, user_time,
-		 unref_proxy_reply_cb, NULL);
+	epiphany_org_gnome_epiphany_call_load_urilist
+		(proxy,
+		 (const char **) uris, options->str, user_time,
+		 NULL, unref_proxy_reply_cb, NULL);
 	
 	if (arguments != NULL)
 	{
@@ -262,26 +258,27 @@ open_urls (DBusGProxy *proxy,
 }
 
 static gboolean
-call_dbus_proxy (DBusGProxy *proxy,
+call_dbus_proxy (EpiphanyOrgGnomeEpiphany *proxy,
 		 guint32 user_time,
 		 GError **error)
 {
-	EphyShell *shell;
 	gboolean retval = TRUE;
 
-	shell = ephy_shell_get_default ();
+	LOG ("call_dbus");
 
 	if (open_as_bookmarks_editor)
 	{
-		org_gnome_Epiphany_open_bookmarks_editor_async
-			(proxy, user_time,
-			 unref_proxy_reply_cb, shell);
+		epiphany_org_gnome_epiphany_call_open_bookmarks_editor
+			(proxy,
+			 user_time,
+			 NULL, unref_proxy_reply_cb, NULL);
 	}
 	else if (session_filename != NULL)
 	{
-		org_gnome_Epiphany_load_session_async
-			(proxy, session_filename, user_time,
-			 unref_proxy_reply_cb, shell);
+		epiphany_org_gnome_epiphany_call_load_session
+			(proxy,
+			 session_filename, user_time,
+			 NULL, unref_proxy_reply_cb, NULL);
 
 		g_free (session_filename);
 		session_filename = NULL;
@@ -291,8 +288,12 @@ call_dbus_proxy (DBusGProxy *proxy,
 		retval = open_urls (proxy, user_time, error);
 	}
 
-	/* FIXME why? */
-	dbus_g_connection_flush (ephy_dbus_get_bus (ephy_dbus_get_default (), EPHY_DBUS_SESSION));
+#if 0
+	/* Ensure this messages are processed, instead of (possibly) being
+	 * queued. */
+	g_dbus_connection_flush_sync (g_dbus_proxy_get_connection (proxy),
+				      NULL, NULL);
+#endif
 
 	return retval;
 }
@@ -394,7 +395,7 @@ main (int argc,
 {
 	GOptionContext *option_context;
 	GOptionGroup *option_group;
-	DBusGProxy *proxy;
+	EpiphanyOrgGnomeEpiphany *proxy;
 	GError *error = NULL;
 	guint32 user_time;
 	gboolean arbitrary_url;
@@ -408,7 +409,6 @@ main (int argc,
 
 	/* Threads have to be initialised before calling ANY glib function */
 	g_thread_init (NULL);
-	dbus_g_thread_init ();
 
 	/* check libxml2 API version epiphany was compiled with against the
 	 * version we're running with.
@@ -629,13 +629,26 @@ main (int argc,
 	if (!private_instance &&
 	    !_ephy_dbus_is_name_owner ())
 	{
+		GError *error = NULL;
 		/* Create DBUS proxy */
+#if 0
 		proxy = ephy_dbus_get_proxy (ephy_dbus_get_default (), EPHY_DBUS_SESSION);
-		if (proxy == NULL)
+#endif
+
+		proxy = epiphany_org_gnome_epiphany_proxy_new_for_bus_sync
+					(G_BUS_TYPE_SESSION,
+					 G_DBUS_PROXY_FLAGS_NONE,
+					 "org.gnome.Epiphany",
+					 "/org/gnome/Epiphany",
+					 NULL, &error);
+
+		if (error != NULL)
 		{
+#if 0
 			error = g_error_new (STARTUP_ERROR_QUARK,
 					     0,
 					     "Unable to get DBus proxy; aborting activation."); /* FIXME i18n */
+#endif
 
 			_ephy_dbus_release ();
 



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