X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;f=tilda-window.c;h=0a55adfe4e7291d6ef06313b60890b3e4c8df084;hb=968c54c805b094821c66af7d172d0fa1677a6fd8;hp=2cae5a755fbdeec09fad1d41258ede61b9480647;hpb=b10473197a4e969f9e7e4dbb70d9d5f8a4a1092d;p=tilda-gobject.git diff --git a/tilda-window.c b/tilda-window.c index 2cae5a7..0a55adf 100644 --- a/tilda-window.c +++ b/tilda-window.c @@ -1,4 +1,94 @@ +#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) +{ + 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; iterms->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 + ******************************************************************************/ static GObjectClass *parent_class = NULL; @@ -14,7 +104,12 @@ tilda_window_instance_init (GTypeInstance *instance, self->dispose_has_run = FALSE; /* Initialize all properties */ - self->number = 0; + self->window = gtk_window_new (GTK_WINDOW_TOPLEVEL); + self->notebook = gtk_notebook_new (); + self->terms = g_ptr_array_new (); + + /* Somewhat of a "poison" value, incase we don't set this */ + self->number = 0xdeadbeef; } static void @@ -66,6 +161,7 @@ tilda_window_constructor (GType type, GObjectConstructParam *construct_properties) { GObject *obj; + TildaWindow *self; /* Invoke parent constructor */ TildaWindowClass *klass; @@ -78,10 +174,27 @@ tilda_window_constructor (GType type, * ctor properties have been set. * * 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); return obj; } +static void +my_unref (gpointer data, gpointer user_data) +{ + g_object_unref (G_OBJECT(data)); +} + static void tilda_window_dispose (GObject *obj) { @@ -96,7 +209,12 @@ tilda_window_dispose (GObject *obj) * object which might themselves hold a reference to self. Generally, * the most simple solution is to unref all members on which you own a * reference. + * + * NOTE: See the following for how to deal with GtkObject-derived things: + * http://library.gnome.org/devel/gtk/unstable/GtkObject.html */ + g_ptr_array_foreach (self->terms, my_unref, NULL); + gtk_widget_destroy (self->window); /* Chain up to the parent class */ G_OBJECT_CLASS (parent_class)->dispose (obj); @@ -112,6 +230,7 @@ tilda_window_finalize (GObject *obj) * You might not need to do much... */ // TODO: g_free() any primitives here + g_ptr_array_free (self->terms, TRUE); /* Chain up to the parent class */ @@ -149,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 @@ -179,6 +301,7 @@ tilda_window_get_type (void) return type; } +#if 0 int main (int argc, char *argv[]) { @@ -187,6 +310,7 @@ int main (int argc, char *argv[]) /* Initialize the GObject type system */ g_type_init (); + gtk_init (&argc, &argv); tw = g_object_new (TILDA_TYPE_WINDOW, "number", 10, NULL); g_object_get (G_OBJECT (tw), "number", &test_number, NULL); @@ -198,10 +322,13 @@ int main (int argc, char *argv[]) g_object_get (G_OBJECT (tw), "number", &test_number, NULL); g_assert (test_number == 22); + gtk_main (); + g_object_unref (G_OBJECT (tw)); return 0; } -/* vim: set ts=4 sts=4 sw=4 noet tw=112: */ +#endif +/* vim: set ts=4 sts=4 sw=4 noet tw=112: */