+#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; i<INT_MAX; ++i)
+ {
+ found = FALSE;
+
+ for (j=0; j<tw->terms->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)
+{
+ 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");
+ gint index = gtk_notebook_prepend_page (GTK_NOTEBOOK(tw->notebook), tt->hbox, label);
+ gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK(tw->notebook), tt->hbox, TRUE, TRUE, GTK_PACK_END);
+ //gtk_notebook_set_current_page (GTK_NOTEBOOK(tw->notebook), index);
+
+ if (gtk_notebook_get_n_pages (GTK_NOTEBOOK(tw->notebook)) > 1)
+ gtk_notebook_set_show_tabs (GTK_NOTEBOOK(tw->notebook), TRUE);
+
+ return TRUE;
+}
+
+static gboolean
+tilda_window_remove_term (TildaWindow *tw, int number)
+{
+ int i;
+
+ for (i=0; i<tw->terms->len; ++i)
+ {
+ 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
+ ******************************************************************************/