X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;f=tilda-window.c;h=0a55adfe4e7291d6ef06313b60890b3e4c8df084;hb=968c54c805b094821c66af7d172d0fa1677a6fd8;hp=a9a2a794f7b469532891735d55ee5d94fbdb9ed9;hpb=087f41d0249ab8bb5c2fb122af1204e7183d3d7f;p=tilda-gobject.git diff --git a/tilda-window.c b/tilda-window.c index a9a2a79..0a55adf 100644 --- a/tilda-window.c +++ b/tilda-window.c @@ -1,11 +1,47 @@ +#include "tilda.h" #include "tilda-window.h" +#include "tilda-window-dbus-glue.h" + +static gint +tilda_window_find_next_free_terminal_number (TildaWindow *tw) +{ + gint i, j; + gboolean found; + + for (i=0; iterms->len; ++j) + { + TildaTerminal *tt = g_ptr_array_index (tw->terms, j); + + if (tt->number == i) + { + found = TRUE; + break; + } + } + + if (!found) + return i; + } + + return 0; +} static gboolean tilda_window_add_term (TildaWindow *tw) { - // FIXME: this is totally bad, but it's a good hack for feasability - static gint mynumber = 0; - TildaTerminal *tt = g_object_new (TILDA_TYPE_TERMINAL, "number", mynumber++, NULL); + gint number; + TildaTerminal *tt; + + number = tilda_window_find_next_free_terminal_number (tw); + tt = g_object_new (TILDA_TYPE_TERMINAL, + "number", number, + "window-number", tw->number, + "parent-window", tw, + NULL); g_ptr_array_add (tw->terms, tt); GtkWidget *label = gtk_label_new ("Tilda"); @@ -29,12 +65,27 @@ tilda_window_remove_term (TildaWindow *tw, int number) TildaTerminal *tt = g_ptr_array_index (tw->terms, i); if (tt->number == number) + { + // FIXME: Find it in the notebook. Remove that notebook page. + // FIXME: Check if we need to exit. Etc. g_print ("Need to remove window %d terminal %d\n", tw->number, tt->number); + } } return TRUE; } +static void +tilda_window_dbus_register_object (TildaWindow *tw) +{ + gchar *object_path; + + // Register this object with DBus + object_path = g_strdup_printf ("/net/sourceforge/Tilda/Window%d", tw->number); + dbus_g_connection_register_g_object (dbus_connection, object_path, G_OBJECT(tw)); + g_free (object_path); +} + /******************************************************************************* * ALL GOBJECT STUFF BELOW PLEASE ******************************************************************************/ @@ -125,9 +176,13 @@ tilda_window_constructor (GType type, * TODO: This is the place to do DBus-init */ self = TILDA_WINDOW(obj); + /* Register this object with DBus */ + tilda_window_dbus_register_object (self); + gtk_container_add (GTK_CONTAINER(self->window), self->notebook); gtk_widget_show (self->notebook); + tilda_window_add_term (self); tilda_window_add_term (self); gtk_widget_show_all (self->window); @@ -213,6 +268,9 @@ tilda_window_class_init (gpointer g_class, pspec); /* TODO: more properties */ + + /* Hook the TildaWindow type into DBus */ + dbus_g_object_type_install_info (tilda_window_get_type(), &dbus_glib_tilda_window_object_info); } GType