gedit r6511 - in branches/new_plugins: . gedit gedit/dbus plugin-loaders/python/bindings



Author: jessevdk
Date: Sun Sep  7 22:29:23 2008
New Revision: 6511
URL: http://svn.gnome.org/viewvc/gedit?rev=6511&view=rev

Log:
Added dbus bindings for the message bus. Both sending and receiving should now work
transparently through both busses
Fixed small problems in the message bus python bindings
Added first actual message on the message bus, commands.open. Supports opening uris
with optional arguments to allow for opening in new window, and on specific 
workspace/viewports like we do currently with bacon. This means that with a few changes, we
can remove bacon, and move to dbus!


Added:
   branches/new_plugins/gedit/dbus/
   branches/new_plugins/gedit/dbus/Makefile.am
   branches/new_plugins/gedit/dbus/gedit-dbus-message.c
   branches/new_plugins/gedit/dbus/gedit-dbus-message.h
   branches/new_plugins/gedit/dbus/gedit-dbus-message.xml
   branches/new_plugins/gedit/dbus/gedit-dbus.c
   branches/new_plugins/gedit/dbus/gedit-dbus.h
   branches/new_plugins/gedit/dbus/gedit-dbus.xml
   branches/new_plugins/gedit/gedit-commands-messages.c
Modified:
   branches/new_plugins/configure.ac
   branches/new_plugins/gedit/Makefile.am
   branches/new_plugins/gedit/gedit-commands.h
   branches/new_plugins/gedit/gedit.c
   branches/new_plugins/plugin-loaders/python/bindings/gedit.defs
   branches/new_plugins/plugin-loaders/python/bindings/geditmessage.override

Modified: branches/new_plugins/configure.ac
==============================================================================
--- branches/new_plugins/configure.ac	(original)
+++ branches/new_plugins/configure.ac	Sun Sep  7 22:29:23 2008
@@ -176,6 +176,24 @@
 AC_SUBST(GEDIT_LIBS)
 AC_SUBST(GEDIT_CFLAGS)
 
+AC_ARG_ENABLE([spell],
+	AS_HELP_STRING([--disable-dbus],[Disable dbus support (default: enabled)]),
+	[enable_dbus=$enableval],
+	[enable_dbus=yes])
+
+if test "x$enable_dbus" = "xyes" ; then
+	PKG_CHECK_MODULES(DBUS, [
+		dbus-glib-1 >= 0.74
+	])
+	
+	DBUS_LIBS="${DBUS_LIBS}"
+	AC_SUBST(DBUS_LIBS)
+	AC_SUBST(DBUS_CFLAGS)
+	
+	AC_DEFINE([ENABLE_DBUS],[1],[Define to compile with dbus support])
+fi
+
+AM_CONDITIONAL([ENABLE_DBUS],[test "x$enable_dbus" = "xyes"])
 
 dnl ================================================================
 dnl GConf related settings
@@ -361,6 +379,7 @@
 docs/reference/Makefile
 gedit/dialogs/Makefile
 gedit/smclient/Makefile
+gedit/dbus/Makefile
 gedit/Makefile
 help/Makefile
 help/eu/Makefile
@@ -404,6 +423,7 @@
 	Libattr enabled:	$have_attr
 	Python Plugins Support: $enable_python
 	Spell Plugin enabled:	$enable_enchant
+	DBus Support:		$enable_dbus
 "
 
 dnl uncomment this in developement releases

Modified: branches/new_plugins/gedit/Makefile.am
==============================================================================
--- branches/new_plugins/gedit/Makefile.am	(original)
+++ branches/new_plugins/gedit/Makefile.am	Sun Sep  7 22:29:23 2008
@@ -1,6 +1,10 @@
 ## Process this file with automake to produce Makefile.in
 SUBDIRS = dialogs smclient
 
+if ENABLE_DBUS
+SUBDIRS += dbus
+endif
+
 bin_PROGRAMS = gedit
 
 noinst_LTLIBRARIES = libgedit.la
@@ -20,14 +24,6 @@
 	-DGEDIT_LOADERDIR=\""$(libdir)/gedit-2/plugin-loaders"\"	\
 	-DGEDIT_ICONDIR=\""$(datadir)/gedit-2/icons"\"
 
-if ENABLE_PYTHON
-INCLUDES += \
-	$(NO_STRICT_ALIASING_CFLAGS)	\
-	$(PYGTK_CFLAGS)			\
-	$(PYTHON_CFLAGS)		\
-	$(AM_CFLAGS)
-endif
-
 gedit_SOURCES = \
 	gedit.c			\
 	gedit-message-bus.c	\
@@ -35,6 +31,10 @@
 
 gedit_LDADD = libgedit.la smclient/libeggsmclient.la $(GEDIT_LIBS)
 
+if ENABLE_DBUS
+gedit_LDADD += dbus/libdbus.la
+endif
+
 gedit_LDFLAGS = -export-dynamic -no-undefined -export-symbols-regex "^[[^_]].*"
 
 libgedit_la_LDFLAGS = -export-dynamic -no-undefined -export-symbols-regex "^[[^_]].*"
@@ -119,6 +119,7 @@
 	gedit-commands-help.c		\
 	gedit-commands-search.c		\
 	gedit-commands-view.c		\
+	gedit-commands-messages.c	\
 	gedit-convert.c			\
 	gedit-debug.c			\
 	gedit-document.c 		\

Added: branches/new_plugins/gedit/dbus/Makefile.am
==============================================================================
--- (empty file)
+++ branches/new_plugins/gedit/dbus/Makefile.am	Sun Sep  7 22:29:23 2008
@@ -0,0 +1,29 @@
+INCLUDES =							\
+	-I$(top_srcdir)						\
+	-I$(top_builddir)					\
+	-I$(top_srcdir)/gedit 					\
+	-I$(top_builddir)/gedit					\
+	$(GEDIT_CFLAGS) 					\
+	$(DBUS_CFLAGS)						\
+	$(WARN_CFLAGS)						\
+	$(DISABLE_DEPRECATED_CFLAGS)
+
+noinst_LTLIBRARIES = libdbus.la
+
+libdbus_la_SOURCES = 			\
+	gedit-dbus.c			\
+	gedit-dbus.h			\
+	gedit-dbus-message.c		\
+	gedit-dbus-message.h
+
+BUILT_SOURCES = gedit-dbus-message-glue.h gedit-dbus-glue.h
+
+gedit-dbus-message-glue.h: gedit-dbus-message.xml
+	$(LIBTOOL) --mode=execute dbus-binding-tool --prefix=gedit_dbus_message --mode=glib-server --output=gedit-dbus-message-glue.h $(srcdir)/gedit-dbus-message.xml
+
+gedit-dbus-glue.h: gedit-dbus.xml
+	$(LIBTOOL) --mode=execute dbus-binding-tool --prefix=gedit_dbus --mode=glib-server --output=gedit-dbus-glue.h $(srcdir)/gedit-dbus.xml
+
+CLEANFILES = $(BUILT_SOURCES)
+
+EXTRA_DIST = gedit-dbus-message.xml gedit-dbus.xml

Added: branches/new_plugins/gedit/dbus/gedit-dbus-message.c
==============================================================================
--- (empty file)
+++ branches/new_plugins/gedit/dbus/gedit-dbus-message.c	Sun Sep  7 22:29:23 2008
@@ -0,0 +1,65 @@
+#include "gedit-dbus-message.h"
+
+#include <dbus/dbus-glib.h>
+#include "gedit-dbus-message-glue.h"
+
+#define GEDIT_DBUS_MESSAGE_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GEDIT_TYPE_DBUS_MESSAGE, GeditDBusMessagePrivate))
+
+/*struct _GeditDBusMessagePrivate
+{
+};*/
+
+/* signals */
+enum
+{
+	MESSAGE,
+	LAST_SIGNAL
+};
+
+static guint signals[LAST_SIGNAL] = { 0 };
+
+G_DEFINE_TYPE (GeditDBusMessage, gedit_dbus_message, G_TYPE_OBJECT)
+
+static void
+gedit_dbus_message_finalize (GObject *object)
+{
+	G_OBJECT_CLASS (gedit_dbus_message_parent_class)->finalize (object);
+}
+
+static void
+gedit_dbus_message_class_init (GeditDBusMessageClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	
+	object_class->finalize = gedit_dbus_message_finalize;
+
+	signals[MESSAGE] =
+		g_signal_new ("message",
+			      G_OBJECT_CLASS_TYPE (klass),
+			      G_SIGNAL_RUN_LAST,
+			      0,
+			      NULL, NULL,
+			      g_cclosure_marshal_VOID__POINTER,
+			      G_TYPE_NONE, 1, 
+			      dbus_g_type_get_map ("GHashTable", 
+			      			   G_TYPE_STRING, 
+			      			   G_TYPE_VALUE));
+
+	dbus_g_object_type_install_info (GEDIT_TYPE_DBUS_MESSAGE, 
+					 &dbus_glib_gedit_dbus_message_object_info);
+
+	//g_type_class_add_private (object_class, sizeof (GeditDBusMessagePrivate));
+}
+
+static void
+gedit_dbus_message_init (GeditDBusMessage *self)
+{
+	//self->priv = GEDIT_DBUS_MESSAGE_GET_PRIVATE(self);
+}
+
+void
+gedit_dbus_message_emit (GeditDBusMessage *dbusmessage,
+			 GeditMessage     *message)
+{
+	g_signal_emit (dbusmessage, signals[MESSAGE], 0, gedit_message_get_hash (message));
+}

Added: branches/new_plugins/gedit/dbus/gedit-dbus-message.h
==============================================================================
--- (empty file)
+++ branches/new_plugins/gedit/dbus/gedit-dbus-message.h	Sun Sep  7 22:29:23 2008
@@ -0,0 +1,38 @@
+#ifndef __GEDIT_DBUS_MESSAGE_H__
+#define __GEDIT_DBUS_MESSAGE_H__
+
+#include <glib-object.h>
+#include <gedit/gedit-message.h>
+
+G_BEGIN_DECLS
+
+#define GEDIT_TYPE_DBUS_MESSAGE			(gedit_dbus_message_get_type ())
+#define GEDIT_DBUS_MESSAGE(obj)			(G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_DBUS_MESSAGE, GeditDBusMessage))
+#define GEDIT_DBUS_MESSAGE_CONST(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_DBUS_MESSAGE, GeditDBusMessage const))
+#define GEDIT_DBUS_MESSAGE_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST ((klass), GEDIT_TYPE_DBUS_MESSAGE, GeditDBusMessageClass))
+#define GEDIT_IS_DBUS_MESSAGE(obj)		(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_DBUS_MESSAGE))
+#define GEDIT_IS_DBUS_MESSAGE_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_DBUS_MESSAGE))
+#define GEDIT_DBUS_MESSAGE_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS ((obj), GEDIT_TYPE_DBUS_MESSAGE, GeditDBusMessageClass))
+
+typedef struct _GeditDBusMessage	GeditDBusMessage;
+typedef struct _GeditDBusMessageClass	GeditDBusMessageClass;
+typedef struct _GeditDBusMessagePrivate	GeditDBusMessagePrivate;
+
+struct _GeditDBusMessage {
+	GObject parent;
+	
+	GeditDBusMessagePrivate *priv;
+};
+
+struct _GeditDBusMessageClass {
+	GObjectClass parent_class;
+};
+
+GType gedit_dbus_message_get_type (void) G_GNUC_CONST;
+
+void  gedit_dbus_message_emit (GeditDBusMessage *dbusmessage,
+			       GeditMessage *message);
+
+G_END_DECLS
+
+#endif /* __GEDIT_DBUS_MESSAGE_H__ */

Added: branches/new_plugins/gedit/dbus/gedit-dbus-message.xml
==============================================================================
--- (empty file)
+++ branches/new_plugins/gedit/dbus/gedit-dbus-message.xml	Sun Sep  7 22:29:23 2008
@@ -0,0 +1,8 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<node name="/org/gnome/gedit">
+  <interface name="org.gnome.gedit.Message">
+    <signal name="Message"/>
+  </interface>
+</node>
+

Added: branches/new_plugins/gedit/dbus/gedit-dbus.c
==============================================================================
--- (empty file)
+++ branches/new_plugins/gedit/dbus/gedit-dbus.c	Sun Sep  7 22:29:23 2008
@@ -0,0 +1,148 @@
+#include "gedit-dbus.h"
+
+#include <gedit/gedit-message-bus.h>
+
+#include "gedit-dbus-message.h"
+#include "gedit-dbus-glue.h"
+
+#define GEDIT_DBUS_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE((object), GEDIT_TYPE_DBUS, GeditDBusPrivate))
+
+/*struct _GeditDBusPrivate
+{
+};*/
+
+G_DEFINE_TYPE (GeditDBus, gedit_dbus, G_TYPE_OBJECT)
+
+static void
+gedit_dbus_finalize (GObject *object)
+{
+	G_OBJECT_CLASS (gedit_dbus_parent_class)->finalize (object);
+}
+
+static void
+gedit_dbus_class_init (GeditDBusClass *klass)
+{
+	GObjectClass *object_class = G_OBJECT_CLASS (klass);
+	
+	object_class->finalize = gedit_dbus_finalize;
+
+	dbus_g_object_type_install_info (GEDIT_TYPE_DBUS, 
+					 &dbus_glib_gedit_dbus_object_info);
+	
+	//g_type_class_add_private (object_class, sizeof(GeditDBusPrivate));
+}
+
+static void
+gedit_dbus_init (GeditDBus *self)
+{
+	//self->priv = GEDIT_DBUS_GET_PRIVATE (self);
+}
+
+static void
+on_dispatch_message (GeditMessageBus *bus,
+		     GeditMessage    *message,
+		     DBusGConnection *gbus)
+{
+	/* register new object on dbus */
+	GObject *msg = g_object_new (GEDIT_TYPE_DBUS_MESSAGE, NULL);
+	gchar *path;
+	
+	path = g_strdup_printf ("/org/gnome/gedit/message/%s/%s", 
+				gedit_message_get_domain (message),
+				gedit_message_get_name (message));
+
+	dbus_g_connection_register_g_object (gbus, path, msg);
+	gedit_dbus_message_emit (GEDIT_DBUS_MESSAGE (msg), message);
+	
+	g_object_unref (msg);
+}
+
+gboolean
+gedit_dbus_send (GeditDBus    *bus,
+		 const gchar  *domain,
+		 const gchar  *name,
+		 GHashTable   *message,
+		 GError	     **error)
+{
+	/* propagate the message over the internal bus */
+	GeditMessage *msg;
+	
+	msg = gedit_message_new_hash (domain, name, message);
+	gedit_message_bus_send_message (gedit_message_bus_get_default(),
+					msg);
+
+	g_object_unref (msg);
+
+	return TRUE;
+}
+
+gboolean
+gedit_dbus_send_sync (GeditDBus             *bus,
+		      const gchar           *domain,
+		      const gchar           *name,
+		      GHashTable            *message,
+		      DBusGMethodInvocation *invocation)
+{
+	/* propagate the message over the internal bus */
+	GeditMessage *msg;
+	
+	msg = gedit_message_new_hash (domain, name, message);
+	gedit_message_bus_send_message_sync (gedit_message_bus_get_default(),
+					     msg);
+
+	/* return message */
+	dbus_g_method_return (invocation, gedit_message_get_hash (msg));
+	g_object_unref (msg);
+
+	return TRUE;
+}
+
+gboolean
+gedit_dbus_initialize ()
+{
+	GError *error = NULL;
+	DBusGProxy *bus_proxy;
+	DBusGConnection *gbus;
+	guint request_name_result;
+	GeditMessageBus *bus;
+	
+	gbus = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+	
+	if (!gbus)
+	{
+		g_warning ("Could not connect to session bus: %s", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+
+	/* Register unique name */
+	bus_proxy = dbus_g_proxy_new_for_name (gbus, 
+					       "org.freedesktop.DBus",
+					       "/org/freedesktop/DBus",
+					       "org.freedesktop.DBus");
+	
+	if (!dbus_g_proxy_call (bus_proxy, "RequestName", &error,
+			  G_TYPE_STRING, "org.gnome.gedit",
+			  G_TYPE_UINT, 0,
+			  G_TYPE_INVALID,
+			  G_TYPE_UINT, &request_name_result,
+			  G_TYPE_INVALID))
+	{
+		g_warning ("Failed to get name for connection: %s:", error->message);
+		g_error_free (error);
+		return FALSE;
+	}
+	
+	/* FIXME: check return value and do something when we are queued etc */
+	
+	dbus_g_connection_register_g_object (gbus, "/org/gnome/gedit", g_object_new (GEDIT_TYPE_DBUS, NULL));
+		
+	/* CHECK: maybe add a reference to the bus? */
+	bus = gedit_message_bus_get_default ();
+	g_signal_connect (bus, "dispatch", G_CALLBACK (on_dispatch_message), gbus);
+	
+	/* TODO: disconnect/reconnect signal when we maybe lose ownership, or
+	   bus goes down? */
+	
+	return TRUE;
+}

Added: branches/new_plugins/gedit/dbus/gedit-dbus.h
==============================================================================
--- (empty file)
+++ branches/new_plugins/gedit/dbus/gedit-dbus.h	Sun Sep  7 22:29:23 2008
@@ -0,0 +1,50 @@
+#ifndef __GEDIT_DBUS_H__
+#define __GEDIT_DBUS_H__
+
+#include <glib-object.h>
+#include <dbus/dbus-glib.h>
+
+G_BEGIN_DECLS
+
+#define GEDIT_TYPE_DBUS			(gedit_dbus_get_type ())
+#define GEDIT_DBUS(obj)			(G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_DBUS, GeditDBus))
+#define GEDIT_DBUS_CONST(obj)		(G_TYPE_CHECK_INSTANCE_CAST ((obj), GEDIT_TYPE_DBUS, GeditDBus const))
+#define GEDIT_DBUS_CLASS(klass)		(G_TYPE_CHECK_CLASS_CAST ((klass), GEDIT_TYPE_DBUS, GeditDBusClass))
+#define GEDIT_IS_DBUS(obj)		(G_TYPE_CHECK_INSTANCE_TYPE ((obj), GEDIT_TYPE_DBUS))
+#define GEDIT_IS_DBUS_CLASS(klass)	(G_TYPE_CHECK_CLASS_TYPE ((klass), GEDIT_TYPE_DBUS))
+#define GEDIT_DBUS_GET_CLASS(obj)	(G_TYPE_INSTANCE_GET_CLASS ((obj), GEDIT_TYPE_DBUS, GeditDBusClass))
+
+typedef struct _GeditDBus		GeditDBus;
+typedef struct _GeditDBusClass		GeditDBusClass;
+typedef struct _GeditDBusPrivate	GeditDBusPrivate;
+
+struct _GeditDBus {
+	GObject parent;
+	
+	GeditDBusPrivate *priv;
+};
+
+struct _GeditDBusClass {
+	GObjectClass parent_class;
+};
+
+GType gedit_dbus_get_type (void) G_GNUC_CONST;
+GeditDBus *gedit_dbus_new(void);
+
+gboolean gedit_dbus_send (GeditDBus    *bus,
+			  const gchar  *domain,
+			  const gchar  *name,
+			  GHashTable   *message,
+			  GError      **error);
+
+gboolean gedit_dbus_send_sync (GeditDBus             *bus,
+			       const gchar           *domain,
+			       const gchar           *name,
+			       GHashTable            *message,
+			       DBusGMethodInvocation *invocation);
+
+gboolean gedit_dbus_initialize (void);
+
+G_END_DECLS
+
+#endif /* __GEDIT_DBUS_H__ */

Added: branches/new_plugins/gedit/dbus/gedit-dbus.xml
==============================================================================
--- (empty file)
+++ branches/new_plugins/gedit/dbus/gedit-dbus.xml	Sun Sep  7 22:29:23 2008
@@ -0,0 +1,19 @@
+<?xml version="1.0" encoding="UTF-8" ?>
+
+<node name="/org/gnome/gedit">
+  <interface name="org.gnome.gedit.MessageBus">
+    <method name="Send">
+      <arg type="s" name="domain" direction="in"/>
+      <arg type="s" name="name" direction="in"/>
+      <arg type="a{sv}" name="message" direction="in"/>
+    </method>
+    <method name="SendSync">
+      <annotation name="org.freedesktop.DBus.GLib.Async" value=""/>
+      <arg type="s" name="domain" direction="in"/>
+      <arg type="s" name="name" direction="in"/>
+      <arg type="a{sv}" name="message" direction="in"/>
+      <arg type="a{sv}" name="result" direction="out"/>
+    </method>
+  </interface>
+</node>
+

Added: branches/new_plugins/gedit/gedit-commands-messages.c
==============================================================================
--- (empty file)
+++ branches/new_plugins/gedit/gedit-commands-messages.c	Sun Sep  7 22:29:23 2008
@@ -0,0 +1,173 @@
+/*
+ * gedit-commands-messages.c
+ * This file is part of gedit
+ *
+ * Copyright (C) 2008  Jesse van den Kieboom  <jesse icecrew nl>
+ *
+ * This program is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by
+ * the Free Software Foundation; either version 2 of the License, or
+ * (at your option) any later version.
+ *
+ * This program is distributed in the hope that it will be useful,
+ * but WITHOUT ANY WARRANTY; without even the implied warranty of
+ * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ * GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with this program; if not, write to the Free Software
+ * Foundation, Inc., 59 Temple Place, Suite 330,
+ * Boston, MA 02111-1307, USA.
+ */
+
+#include "gedit-commands.h"
+
+#include "gedit-app.h"
+#include "gedit-window.h"
+#include "gedit-encodings.h"
+#include "gedit-message-bus.h"
+
+#include <gdk/gdkx.h>
+#include <string.h>
+
+#define BUS_CONNECT(domain, name, callback) gedit_message_bus_connect (bus, domain, name, callback, NULL, NULL)
+
+static GdkDisplay *
+display_open_if_needed (const gchar *name)
+{
+	GSList *displays;
+	GSList *l;
+	GdkDisplay *display = NULL;
+
+	displays = gdk_display_manager_list_displays (gdk_display_manager_get ());
+
+	for (l = displays; l != NULL; l = l->next)
+	{
+		if (strcmp (gdk_display_get_name ((GdkDisplay *) l->data), name) == 0)
+		{
+			display = l->data;
+			break;
+		}
+	}
+
+	g_slist_free (displays);
+
+	return display != NULL ? display : gdk_display_open (name);
+}
+
+static void
+on_message_commands_open (GeditMessageBus *bus, 
+			  GeditMessage    *message,
+			  gpointer         userdata)
+{
+	GStrv uris = NULL;
+	gchar *encoding_charset = NULL;
+	gint line_position = 0;
+	gboolean new_window = FALSE;
+	const GeditEncoding *encoding = NULL;
+	GeditWindow *window;
+	GeditApp *app;
+	GSList *uri_list = NULL;
+	GStrv ptr;
+	guint32 startup_timestamp = 0;
+	
+	/* optional parameters, used to specify correct workspace/viewport */
+	GdkScreen *screen = NULL;
+	gint screen_number = -1;
+	gint workspace = -1;
+	gint viewport_x = -1;
+	gint viewport_y = -1;
+	gchar *display_name = NULL;
+
+	gedit_message_get (message,
+			   "uris", &uris,
+			   "encoding", &encoding_charset,
+			   "line_position", &line_position,
+			   "new_window", &new_window,
+			   "screen_number", &screen_number,
+			   "workspace", &workspace,
+			   "viewport_x", &viewport_x,
+			   "viewport_y", &viewport_y,
+			   "display_name", &display_name,
+			   "startup_timestamp", &startup_timestamp,
+			   NULL);
+
+	if (uris == NULL)
+		return;
+	
+	if (*uris == NULL)
+	{
+		g_strfreev (uris);
+		return;
+	}
+
+	if (encoding_charset != NULL)
+		encoding = gedit_encoding_get_from_charset (encoding_charset);
+
+	app = gedit_app_get_default ();
+	
+	/* get correct screen using the display_name and screen_number */
+	if (display_name != NULL)
+	{
+		GdkDisplay *display;
+		
+		display = display_open_if_needed (display_name);
+		screen = gdk_display_get_screen (display, screen_number == -1 ? 0 : screen_number);
+	}
+	
+	if (new_window)
+		window = gedit_app_create_window (app, screen);
+	else if (screen != NULL)
+		window = _gedit_app_get_window_in_viewport (app,
+							    screen,
+							    workspace == -1 ? 0 : workspace,
+							    viewport_x == -1 ? 0 : viewport_x,
+							    viewport_y == -1 ? 0 : viewport_y);
+	else
+		window = gedit_app_get_active_window (app);
+
+	ptr = uris;
+	
+	while (*ptr)
+	{
+		g_message ("Adding: %s", *ptr);
+		uri_list = g_slist_prepend (uri_list, *ptr);
+		ptr++;
+	}
+	
+	uri_list = g_slist_reverse (uri_list);
+	
+	_gedit_cmd_load_files_from_prompt (window, uri_list, encoding, line_position);
+	
+	/* set the proper interaction time on the window.
+	 * Fall back to roundtripping to the X server when we
+	 * don't have the timestamp, e.g. when launched from
+	 * terminal. We also need to make sure that the window
+	 * has been realized otherwise it will not work. lame.
+	 */
+	if (!GTK_WIDGET_REALIZED (window))
+		gtk_widget_realize (GTK_WIDGET (window));
+
+	if (startup_timestamp <= 0)
+		startup_timestamp = gdk_x11_get_server_time (GTK_WIDGET (window)->window);
+
+	gdk_x11_window_set_user_time (GTK_WIDGET (window)->window,
+				      startup_timestamp);
+
+	gtk_window_present (GTK_WINDOW (window));
+
+	g_strfreev (uris);
+	g_free (encoding_charset);
+	g_slist_free (uri_list);
+}
+
+void
+_gedit_commands_messages_register ()
+{
+	GeditMessageBus *bus;
+	
+	/* register message handlers on the message bus */
+	bus = gedit_message_bus_get_default ();
+	
+	BUS_CONNECT ("commands", "open", on_message_commands_open);
+}

Modified: branches/new_plugins/gedit/gedit-commands.h
==============================================================================
--- branches/new_plugins/gedit/gedit-commands.h	(original)
+++ branches/new_plugins/gedit/gedit-commands.h	Sun Sep  7 22:29:23 2008
@@ -151,6 +151,8 @@
 void		_gedit_cmd_file_save_documents_list	(GeditWindow *window,
 							 GList       *docs);
 
+void		_gedit_commands_messages_register	(void);
+
 G_END_DECLS
 
 #endif /* __GEDIT_COMMANDS_H__ */ 

Modified: branches/new_plugins/gedit/gedit.c
==============================================================================
--- branches/new_plugins/gedit/gedit.c	(original)
+++ branches/new_plugins/gedit/gedit.c	Sun Sep  7 22:29:23 2008
@@ -54,6 +54,11 @@
 
 #include "bacon-message-connection.h"
 #include "eggsmclient.h"
+#include "gedit-message-bus.h"
+
+#ifdef ENABLE_DBUS
+#include "dbus/gedit-dbus.h"
+#endif
 
 static guint32 startup_timestamp = 0;
 static BaconMessageConnection *connection;
@@ -517,6 +522,13 @@
 		g_warning ("Cannot create the 'gedit' connection.");
 	}
 
+	/* register command messages on the message bus */
+	_gedit_commands_messages_register ();
+	
+#ifdef ENABLE_DBUS
+	gedit_dbus_initialize ();
+#endif
+
 	gedit_debug_message (DEBUG_APP, "Set icon");
 	
 	gtk_icon_theme_append_search_path (gtk_icon_theme_get_default (),

Modified: branches/new_plugins/plugin-loaders/python/bindings/gedit.defs
==============================================================================
--- branches/new_plugins/plugin-loaders/python/bindings/gedit.defs	(original)
+++ branches/new_plugins/plugin-loaders/python/bindings/gedit.defs	Sun Sep  7 22:29:23 2008
@@ -1253,6 +1253,23 @@
   )
 )
 
+(define-method has_key
+  (of-object "GeditMessage")
+  (c-name "gedit_message_has_key")
+  (return-type "gboolean")
+  (parameters
+    '("const-gchar*" "key")
+  )
+)
+
+(define-method get_keys
+  (of-object "GeditMessage")
+  (c-name "gedit_message_get_keys")
+  (return-type "gchar**")
+  (parameters
+  )
+)
+
 ;; From ../../gedit/gedit-debug.h
 
 (define-function debug

Modified: branches/new_plugins/plugin-loaders/python/bindings/geditmessage.override
==============================================================================
--- branches/new_plugins/plugin-loaders/python/bindings/geditmessage.override	(original)
+++ branches/new_plugins/plugin-loaders/python/bindings/geditmessage.override	Sun Sep  7 22:29:23 2008
@@ -4,8 +4,36 @@
 #include <gedit/gedit-message-bus.h>
 #include <gedit/gedit-message.h>
 
+static GType
+_helper_wrap_get_gtype_from_pytype (PyObject *pytype)
+{
+    PyTypeObject *type = (PyTypeObject *)pytype;
+    
+    if (type == &PyList_Type || type == &PyTuple_Type)
+    	return G_TYPE_STRV;
+
+    return pyg_type_from_object (pytype);
+}
+
+static gchar *
+_helper_wrap_get_string (PyObject *obj)
+{
+	PyObject *str;
+	gchar *result;
+	
+	str = PyObject_Str (obj);
+	
+	if (!str)
+		return NULL;
+	
+	result = g_strdup (PyString_AsString (str));
+	Py_DECREF (str);
+	
+	return result;
+}
+
 static int
-_helper_wrap_message_types(PyObject *args, const gchar ***keys, GType **types, gint *num, gboolean direct)
+_helper_wrap_message_types(PyObject *args, gchar ***keys, GType **types, gint *num, gboolean direct)
 {
     guint len, i, pos;
     
@@ -19,25 +47,23 @@
     	PyObject *value;
 
     	*num = PyDict_Size(dict);
-    	*types = g_new(GType, *num);
-        *keys = g_new(const gchar *, *num);
+    	*types = g_new0(GType, *num);
+        *keys = g_new0(gchar *, *num + 1);
         pos = 0;
         i = 0;
         
         while (PyDict_Next(dict, &pos, &key, &value)) {
-            *keys[i] = PyString_AsString(key);
+            (*keys)[i] = _helper_wrap_get_string (key);
             
             if (direct) {
-                *types[i] = pyg_type_from_object(value);
+                (*types)[i] = _helper_wrap_get_gtype_from_pytype(value);
             } else {
-                PyObject *pytype = PyObject_Type(value);
-                *types[i] = pytype ? pyg_type_from_object(pytype) : 0;
-                Py_DECREF(pytype);
+                (*types)[i] = _helper_wrap_get_gtype_from_pytype((PyObject *)value->ob_type);
             }
             
-            if (*types[i] == 0 || *keys[i] == NULL) {
+            if ((*types)[i] == 0 || (*keys)[i] == NULL) {
                 g_free(*types);
-                g_free(*keys);
+                g_strfreev(*keys);
                 return 0;
             }
             
@@ -54,25 +80,23 @@
 
         *num = len / 2;
         *types = g_new(GType, *num);
-        *keys = g_new(const gchar *, *num);
+        *keys = g_new0(gchar *, *num + 1);
 
         for (i = 0; i < *num; i++) {
             PyObject *key = PyTuple_GetItem(args, i * 2);
             PyObject *value = PyTuple_GetItem(args, i * 2 + 1);
     
-            *keys[i] = PyString_AsString(key);
+            (*keys)[i] = _helper_wrap_get_string (key);
             
             if (direct) {
-                *types[i] = pyg_type_from_object(value);
+                (*types)[i] = _helper_wrap_get_gtype_from_pytype(value);
             } else {
-                PyObject *pytype = PyObject_Type(value);
-                *types[i] = pytype ? pyg_type_from_object(pytype) : 0;
-                Py_DECREF(pytype);
+                (*types)[i] = _helper_wrap_get_gtype_from_pytype((PyObject *)value->ob_type);
             }
 
-            if (*types[i] == 0 || *keys[i] == NULL) {
+            if ((*types)[i] == 0 || (*keys)[i] == NULL) {
                 g_free(*types);
-                g_free(*keys);
+                g_strfreev(*keys);
                 return 0;
             }
         }
@@ -82,13 +106,49 @@
 }
 
 static int
+_helper_wrap_list_to_gvalue (GValue *gvalue, PyObject *pyvalue)
+{
+	int num;
+	gchar **lst;
+	gint i;
+	
+	num = PySequence_Size (pyvalue);
+	lst = g_new0 (gchar *, num + 1);
+	
+	for (i = 0; i < num; i++)
+	{
+		lst[i] = _helper_wrap_get_string (PySequence_GetItem (pyvalue, i));
+		
+		if (lst[i] == NULL)
+		{
+			g_strfreev (lst);
+			return 1;
+		}
+	}
+	
+	g_value_set_boxed (gvalue, lst);
+	g_strfreev (lst);
+	
+	return 0;
+}
+
+static int
+_helper_wrap_get_gvalue_from_pyobject (GValue *gvalue, PyObject *pyvalue)
+{
+	if (pyvalue->ob_type == &PyList_Type || pyvalue->ob_type == &PyTuple_Type)
+		return _helper_wrap_list_to_gvalue (gvalue, pyvalue);
+
+	return pyg_value_from_pyobject(gvalue, pyvalue);
+}
+
+static int
 _helper_wrap_message_set_value(GeditMessage *message, PyObject *pykey, PyObject *pyvalue)
 {
-    const gchar *key;
+    gchar *key;
     GType gtype;
     GValue value = {0,};
 
-    key = PyString_AsString(pykey);
+    key = _helper_wrap_get_string(pykey);
     
     if (key == NULL)
         return 0;
@@ -97,19 +157,22 @@
     
     if (gtype == 0) {
         PyErr_SetString(PyExc_TypeError, "invalid key");
+        g_free (key);
         return 0;
     }
 
     g_value_init(&value, gtype);
     
-    if (pyg_value_from_pyobject(&value, pyvalue)) {
+    if (_helper_wrap_get_gvalue_from_pyobject (&value, pyvalue)) {
         PyErr_SetString(PyExc_TypeError,
                         "value is of the wrong type for this key");
+        g_free (key);
         return 0;
     }
 
     gedit_message_set_value(message, key, &value);
     g_value_unset(&value);
+    g_free (key);
     
     return 1;
 }
@@ -156,10 +219,10 @@
 _helper_wrap_create_message(PyObject *args)
 {
     guint len, num;
-    const gchar *domain;
-    const gchar *name;
+    gchar *domain;
+    gchar *name;
     GType *types;
-    const gchar **keys;
+    gchar **keys;
     PyObject *slice;
     GeditMessage *message;
 
@@ -171,12 +234,14 @@
         return NULL;
     }
     
-    domain = PyString_AsString(PyTuple_GetItem(args, 0));
-    name = PyString_AsString(PyTuple_GetItem(args, 1));
+    domain = _helper_wrap_get_string(PyTuple_GetItem(args, 0));
+    name = _helper_wrap_get_string(PyTuple_GetItem(args, 1));
     
     if (!domain || !name) {
         PyErr_SetString(PyExc_TypeError,
                         "First two arguments need to be strings");
+        g_free (domain);
+        g_free (name);
         return NULL;
     }
     
@@ -188,10 +253,12 @@
     }
 
     message = g_object_new(GEDIT_TYPE_MESSAGE, "domain", domain, "name", name, NULL);
-    gedit_message_set_types (message, keys, types, num);
+    gedit_message_set_types (message, (const gchar **)keys, types, num);
 
     g_free(types);
-    g_free(keys);
+    g_strfreev(keys);
+    g_free (name);
+    g_free (domain);
     
     _helper_wrap_message_set_values(message, slice);
     Py_DECREF(slice);
@@ -251,16 +318,16 @@
 {
     guint num;
     GType *types;
-    const gchar **keys;
+    gchar **keys;
 
     if (!_helper_wrap_message_types (args, &keys, &types, &num, TRUE)) {
     	return NULL;
     }
  
-    gedit_message_set_types (GEDIT_MESSAGE(self->obj), keys, types, num);
+    gedit_message_set_types (GEDIT_MESSAGE(self->obj), (const gchar **)keys, types, num);
 
     g_free(types);
-    g_free(keys);
+    g_strfreev(keys);
 
     Py_INCREF (Py_None);
     return Py_None;
@@ -346,6 +413,32 @@
     return Py_None;
 }
 %%
+override gedit_message_get_keys args
+static PyObject *
+_wrap_gedit_message_get_keys (PyGObject *self, PyObject *args) {
+    PyObject *py_list;
+    gchar **keys;
+    gchar **ptr;
+    
+    if ((py_list = PyList_New(0)) == NULL) {
+        Py_INCREF(Py_None);
+        return Py_None;
+    }
+    
+    keys = gedit_message_get_keys (GEDIT_MESSAGE (self->obj));
+    ptr = keys;
+    
+    if (!keys)
+    	return py_list;
+    
+    while (*ptr)
+    	PyList_Append(py_list, PyString_FromString (*ptr));
+
+    g_strfreev (keys);
+    return py_list;
+}
+
+%%
 override gedit_message_bus_connect kwargs
 static void
 pygedit_message_bus_connect_cb(GeditMessageBus *bus, GeditMessage *message, gpointer data)



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