Gnome-terminal gets on the bus



hi

Not really sure who to send this to: does gnome-terminal even have a
maintainer these days?

First there was Bonobo, and it was good for certain things, and sucked
fairly majorly for others, but it was not cross-desktop and all that
stuff that people like, so the good bits of it were replaced by DBus.

Occasionally programs used Bonobo to implement unique program
instances. gnome-terminal was one of them. In the spirit of using DBus
pervasivly throughout the desktop I have ported gnome-terminal to use
this new system

The patch is here:
http://www.openedhand.com/~iain/gnome-terminal-gets-on-the-bus.patch
and is also attached.

lots of love
iain
Index: ChangeLog
===================================================================
RCS file: /cvs/gnome/gnome-terminal/ChangeLog,v
retrieving revision 1.555
diff -U2 -r1.555 ChangeLog
--- ChangeLog	17 May 2006 22:10:04 -0000	1.555
+++ ChangeLog	2 Jun 2006 23:19:22 -0000
@@ -1,2 +1,12 @@
+2006-06-02  Iain Holmes  <iain gnome org>
+
+	* src/Makefile.am: Generate DBus stuff
+
+	* src/terminal.c: Replace Bonobo factory with DBus.
+
+	* src/terminal-service.xml: Definition of org.gnome.TerminalInterface
+
+	* configure.in: Check for DBus
+
 2006-05-17  Behdad Esfahbod  <behdad gnome org>
 
Index: configure.in
===================================================================
RCS file: /cvs/gnome/gnome-terminal/configure.in,v
retrieving revision 1.155
diff -U2 -r1.155 configure.in
--- configure.in	17 May 2006 22:10:04 -0000	1.155
+++ configure.in	2 Jun 2006 23:19:23 -0000
@@ -55,4 +55,5 @@
  gtk+-2.0 >= $GTK_REQUIRED dnl
  gconf-2.0 >= $GCONF_REQUIRED dnl
+ dbus-glib-1 >= 0.6 dnl
  libglade-2.0 dnl
  libgnomeui-2.0 dnl
Index: src/Makefile.am
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/Makefile.am,v
retrieving revision 1.43
diff -U2 -r1.43 Makefile.am
--- src/Makefile.am	12 Jan 2006 16:46:59 -0000	1.43
+++ src/Makefile.am	2 Jun 2006 23:19:23 -0000
@@ -14,5 +14,6 @@
 	-DTERM_PKGDATADIR=\"$(pkgdatadir)\" \
 	-DGDK_DISABLE_DEPRECATED -DG_DISABLE_DEPRECATED	\
-	-DSN_API_NOT_YET_FROZEN
+	-DSN_API_NOT_YET_FROZEN \
+	-DDBUS_API_SUBJECT_TO_CHANGE
 #	-DGTK_DISABLE_DEPRECATED 
 #	-DGNOME_DISABLE_DEPRECATED 
@@ -26,6 +27,17 @@
 	eggcellrendererkeys.c
 
+DBUS_GENERATED_H = terminal-service-bindings.h terminal-service-glue.h
+
+terminal-service-glue.h:
+	dbus-binding-tool --mode=glib-server --output=terminal-service-glue.h --prefix=terminal_service terminal-service.xml
+
+terminal-service-bindings.h:
+	dbus-binding-tool --mode=glib-client --output=terminal-service-bindings.h terminal-service.xml
+
+BUILT_SOURCES = $(DBUS_GENERATED_H)
+
 ## Terminal
-gnome_terminal_SOURCES=				\
+gnome_terminal_SOURCES =			\
+	$(DBUS_GENERATED_H)			\
 	encoding.c				\
 	encoding.h				\
@@ -65,5 +77,5 @@
 icon_DATA = gnome-terminal.png
 
-CLEANFILES = gnome-terminal.schemas
+CLEANFILES = $(DBUS_GENERATED_H) gnome-terminal.schemas
 
 EXTRA_DIST =				\
@@ -74,4 +86,5 @@
 	$(server_DATA)			\
 	update-from-egg.sh		\
+	terminal-service.xml		\
 	terminal-widget-vte.c
 
Index: src/terminal-service.xml
===================================================================
RCS file: src/terminal-service.xml
diff -N src/terminal-service.xml
--- /dev/null	1 Jan 1970 00:00:00 -0000
+++ src/terminal-service.xml	2 Jun 2006 23:19:23 -0000
@@ -0,0 +1,7 @@
+<node name="/">
+	<interface name="org.gnome.TerminalInterface">
+		<method name="NewTerminal">
+			<arg type="as"/>
+		</method>
+	</interface>
+</node>
Index: src/terminal.c
===================================================================
RCS file: /cvs/gnome/gnome-terminal/src/terminal.c,v
retrieving revision 1.96
diff -U2 -r1.96 terminal.c
--- src/terminal.c	2 Apr 2006 12:21:12 -0000	1.96
+++ src/terminal.c	2 Jun 2006 23:19:23 -0000
@@ -31,8 +31,9 @@
 #include "encoding.h"
 #include <gconf/gconf-client.h>
-#include <bonobo-activation/bonobo-activation-activate.h>
-#include <bonobo-activation/bonobo-activation-register.h>
-#include <bonobo/bonobo-exception.h>
-#include <bonobo/bonobo-listener.h>
+
+#include <dbus/dbus-protocol.h>
+#include <dbus/dbus-glib.h>
+#include <dbus/dbus-glib-bindings.h>
+
 #include <libgnome/gnome-program.h>
 #include <libgnome/gnome-help.h>
@@ -45,4 +46,19 @@
 #include <gdk/gdkx.h>
 
+#define TERMINAL_FACTORY_TYPE (terminal_factory_get_type ())
+
+typedef struct _TerminalFactory {
+  GObject object;
+} TerminalFactory;
+
+typedef struct _TerminalFactoryClass {
+  GObjectClass object_class;
+} TerminalFactoryClass;
+
+static gboolean terminal_service_new_terminal (TerminalFactory *factory,
+                                               const char **IN_args,
+                                               GError **error);
+#include "terminal-service-glue.h"
+#include "terminal-service-bindings.h"
 
 /* Settings storage works as follows:
@@ -3749,12 +3765,9 @@
  * given arguments.
  */
-static void
-terminal_new_event (BonoboListener    *listener,
-		    const char        *event_name, 
-		    const CORBA_any   *any,
-		    CORBA_Environment *ev,
-		    gpointer           user_data)
+static gboolean
+terminal_service_new_terminal (TerminalFactory *factory,
+                               const char **IN_args,
+                               GError **error)
 {
-  CORBA_sequence_CORBA_string *args;
   char **tmp_argv;
   int tmp_argc;
@@ -3762,20 +3775,16 @@
   NewTerminalEvent *event;
   
-  if (strcmp (event_name, "new_terminal"))
-    {
-      g_warning ("Unknown event '%s' on terminal",
-		 event_name);
-      return;
-    }
+  tmp_argc = 0;
+  while (IN_args[tmp_argc]) {
+    tmp_argc++;
+  }
+
+  tmp_argv = g_new0 (char *, tmp_argc + 1);
 
-  args = any->_value;
-  
-  tmp_argv = g_new0 (char*, args->_length + 1);
   i = 0;
-  while (i < args->_length)
-    {
-      tmp_argv[i] = g_strdup (((const char**)args->_buffer)[i]);
-      ++i;
-    }
+  while (IN_args[i]) {
+    tmp_argv[i] = g_strdup (IN_args [i]);
+    ++i;
+  }
   tmp_argv[i] = NULL;
   tmp_argc = i;
@@ -3790,29 +3799,66 @@
   if (initialization_complete)
     handle_new_terminal_events ();
+
+  return TRUE;
+}
+
+static void
+terminal_factory_class_init (TerminalFactoryClass *factory_class)
+{
+  dbus_g_object_type_install_info (G_TYPE_FROM_CLASS (factory_class),
+                                   &dbus_glib_terminal_service_object_info);
+}
+
+static void
+terminal_factory_init (TerminalFactory *factory)
+{
 }
 
-#define ACT_IID "OAFIID:GNOME_Terminal_Factory"
+G_DEFINE_TYPE(TerminalFactory, terminal_factory, G_TYPE_OBJECT);
 
-static Bonobo_RegistrationResult
+#define TERMINAL_FACTORY_NAME "org.gnome.TerminalFactory"
+static gboolean
 terminal_register_as_factory (void)
 {
-  char *per_display_iid;
-  BonoboListener *listener;
-  Bonobo_RegistrationResult result;
+  DBusGConnection *connection;
+  DBusGProxy *proxy;
+  GError *error = NULL;
+  TerminalFactory *factory;
+  guint32 request_name_ret;
+  
+  connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+  if (connection == NULL) {
+    return FALSE;
+  }
 
-  listener = bonobo_listener_new (terminal_new_event, NULL);
+  proxy = dbus_g_proxy_new_for_name (connection,
+                                     DBUS_SERVICE_DBUS,
+                                     DBUS_PATH_DBUS,
+                                     DBUS_INTERFACE_DBUS);
 
-  per_display_iid = bonobo_activation_make_registration_id (
-    ACT_IID, DisplayString (gdk_display));
+#if 0
+  dbus_g_proxy_add_signal (proxy, "NameOwnerChanged",
+                           G_TYPE_STRING, G_TYPE_STRING, G_TYPE_STRING,
+                           G_TYPE_INVALID);
+  dbus_g_proxy_connect_signal (proxy, "NameOwnerChanged", 
+                               G_CALLBACK (name_owner_changed), factory, NULL);
+#endif
 
-  result = bonobo_activation_active_server_register (
-    per_display_iid, BONOBO_OBJREF (listener));
+  if (!org_freedesktop_DBus_request_name (proxy, TERMINAL_FACTORY_NAME,
+                                          DBUS_NAME_FLAG_DO_NOT_QUEUE, 
+                                          &request_name_ret, &error)) {
+    return FALSE;
+  }
 
-  if (result != Bonobo_ACTIVATION_REG_SUCCESS)
-    bonobo_object_unref (BONOBO_OBJECT (listener));
+  if (request_name_ret != DBUS_REQUEST_NAME_REPLY_PRIMARY_OWNER) {
+    return FALSE;
+  }
 
-  g_free (per_display_iid);
+  factory = g_object_new (TERMINAL_FACTORY_TYPE, NULL);
+  dbus_g_connection_register_g_object (connection,
+                                       "/Terminal",
+                                       G_OBJECT (factory));
 
-  return result;
+  return TRUE;
 }
 
@@ -3820,54 +3866,43 @@
 terminal_invoke_factory (int argc, char **argv)
 {
-  Bonobo_Listener listener;
-
-  switch (terminal_register_as_factory ())
-    {
-      case Bonobo_ACTIVATION_REG_SUCCESS:
-	/* we were the first terminal to register */
-	return FALSE;
-      case Bonobo_ACTIVATION_REG_NOT_LISTED:
-	g_printerr (_("It appears that you do not have gnome-terminal.server installed in a valid location. Factory mode disabled.\n"));
-        return FALSE;
-      case Bonobo_ACTIVATION_REG_ERROR:
-        g_printerr (_("Error registering terminal with the activation service; factory mode disabled.\n"));
-        return FALSE;
-      case Bonobo_ACTIVATION_REG_ALREADY_ACTIVE:
-        /* lets use it then */
-        break;
-    }
-
-  listener = bonobo_activation_activate_from_id (
-    ACT_IID, Bonobo_ACTIVATION_FLAG_EXISTING_ONLY, NULL, NULL);
-
-  if (listener != CORBA_OBJECT_NIL)
-    {
-      int i;
-      CORBA_any any;
-      CORBA_sequence_CORBA_string args;
-      CORBA_Environment ev;
-
-      CORBA_exception_init (&ev);
+  DBusGConnection *connection;
+  GError *error;
+  DBusGProxy *proxy;
+  char **args;
+  int i;
 
-      any._type = TC_CORBA_sequence_CORBA_string;
-      any._value = &args;
+  if (terminal_register_as_factory ()) {
+    /* we were the first terminal to register */
+    return FALSE;
+  }
 
-      args._length = argc;
-      args._buffer = g_newa (CORBA_char *, args._length);
+  error = NULL;
+  connection = dbus_g_bus_get (DBUS_BUS_SESSION, &error);
+  if (connection == NULL) {
+    g_printerr ("Failed to open connection to bus: %s\n", error->message);
+    g_error_free (error);
+    return FALSE;
+  }
 
-      for (i = 0; i < args._length; i++)
-        args._buffer [i] = argv [i];
-      
-      Bonobo_Listener_event (listener, "new_terminal", &any, &ev);
-      CORBA_Object_release (listener, &ev);
-      if (!BONOBO_EX (&ev))
-        return TRUE;
+  /* Need to NULL terminate our argv */
+  args = g_new (char *, argc + 1);
+  for (i = 0; i < argc; i++) {
+    args[i] = argv[i];
+  }
+  args[argc] = NULL;
 
-      CORBA_exception_free (&ev);
-    }
-  else
-    g_printerr (_("Failed to retrieve terminal server from activation server\n"));
+  proxy = dbus_g_proxy_new_for_name (connection, "org.gnome.TerminalFactory",
+                                     "/Terminal",
+                                     "org.gnome.TerminalInterface");
+  if (org_gnome_TerminalInterface_new_terminal (proxy, (const char **) args, 
+                                                &error) == FALSE){
+    g_free (args);
+    g_printerr ("Failed to start new terminal: %s\n", error->message);
+    g_error_free (error);
+    return FALSE;
+  }
 
-  return FALSE;
+  g_free (args);
+  return TRUE;
 }
 


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