2 #include "tilda-window.h"
3 #include "tilda-window-dbus-glue.h"
6 tilda_window_find_next_free_terminal_number (TildaWindow *tw)
11 for (i=0; i<INT_MAX; ++i)
15 for (j=0; j<tw->terms->len; ++j)
17 TildaTerminal *tt = g_ptr_array_index (tw->terms, j);
34 tilda_window_add_term (TildaWindow *tw)
39 number = tilda_window_find_next_free_terminal_number (tw);
40 tt = g_object_new (TILDA_TYPE_TERMINAL,
42 "window-number", tw->number,
45 g_ptr_array_add (tw->terms, tt);
47 GtkWidget *label = gtk_label_new ("Tilda");
48 gint index = gtk_notebook_prepend_page (GTK_NOTEBOOK(tw->notebook), tt->hbox, label);
49 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK(tw->notebook), tt->hbox, TRUE, TRUE, GTK_PACK_END);
50 //gtk_notebook_set_current_page (GTK_NOTEBOOK(tw->notebook), index);
52 if (gtk_notebook_get_n_pages (GTK_NOTEBOOK(tw->notebook)) > 1)
53 gtk_notebook_set_show_tabs (GTK_NOTEBOOK(tw->notebook), TRUE);
59 tilda_window_remove_term (TildaWindow *tw, int number)
63 for (i=0; i<tw->terms->len; ++i)
65 TildaTerminal *tt = g_ptr_array_index (tw->terms, i);
67 if (tt->number == number)
69 // FIXME: Find it in the notebook. Remove that notebook page.
70 // FIXME: Check if we need to exit. Etc.
71 g_print ("Need to remove window %d terminal %d\n", tw->number, tt->number);
79 tilda_window_dbus_register_object (TildaWindow *tw)
83 // Register this object with DBus
84 object_path = g_strdup_printf ("/net/sourceforge/Tilda/Window%d", tw->number);
85 dbus_g_connection_register_g_object (dbus_connection, object_path, G_OBJECT(tw));
89 /*******************************************************************************
90 * ALL GOBJECT STUFF BELOW PLEASE
91 ******************************************************************************/
93 static GObjectClass *parent_class = NULL;
95 enum tilda_window_properties {
96 TILDA_WINDOW_NUMBER = 1,
100 tilda_window_instance_init (GTypeInstance *instance,
103 TildaWindow *self = (TildaWindow *) instance;
104 self->dispose_has_run = FALSE;
106 /* Initialize all properties */
107 self->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
108 self->notebook = gtk_notebook_new ();
109 self->terms = g_ptr_array_new ();
111 /* Somewhat of a "poison" value, incase we don't set this */
112 self->number = 0xdeadbeef;
116 tilda_window_set_property (GObject *object,
121 TildaWindow *self = (TildaWindow *) object;
123 switch (property_id) {
125 case TILDA_WINDOW_NUMBER:
126 self->number = g_value_get_int (value);
127 g_print ("window number: %d\n", self->number);
131 /* We don't have this property */
132 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
138 tilda_window_get_property (GObject *object,
143 TildaWindow *self = (TildaWindow *) object;
145 switch (property_id) {
147 case TILDA_WINDOW_NUMBER:
148 g_value_set_int (value, self->number);
152 /* We don't have this property */
153 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
159 tilda_window_constructor (GType type,
160 guint n_construct_properties,
161 GObjectConstructParam *construct_properties)
166 /* Invoke parent constructor */
167 TildaWindowClass *klass;
168 klass = TILDA_WINDOW_CLASS (g_type_class_peek (TILDA_TYPE_WINDOW));
169 obj = parent_class->constructor (type,
170 n_construct_properties,
171 construct_properties);
173 /* Do other stuff here. The object is ready to go now, and all
174 * ctor properties have been set.
176 * TODO: This is the place to do DBus-init */
177 self = TILDA_WINDOW(obj);
179 /* Register this object with DBus */
180 tilda_window_dbus_register_object (self);
182 gtk_container_add (GTK_CONTAINER(self->window), self->notebook);
183 gtk_widget_show (self->notebook);
185 tilda_window_add_term (self);
186 tilda_window_add_term (self);
187 gtk_widget_show_all (self->window);
193 my_unref (gpointer data, gpointer user_data)
195 g_object_unref (G_OBJECT(data));
199 tilda_window_dispose (GObject *obj)
201 TildaWindow *self = (TildaWindow *) obj;
203 /* We don't want to run dispose twice, so just return immediately */
204 if (self->dispose_has_run)
208 * In dispose, you are supposed to free all types referenced from this
209 * object which might themselves hold a reference to self. Generally,
210 * the most simple solution is to unref all members on which you own a
213 * NOTE: See the following for how to deal with GtkObject-derived things:
214 * http://library.gnome.org/devel/gtk/unstable/GtkObject.html
216 g_ptr_array_foreach (self->terms, my_unref, NULL);
217 gtk_widget_destroy (self->window);
219 /* Chain up to the parent class */
220 G_OBJECT_CLASS (parent_class)->dispose (obj);
224 tilda_window_finalize (GObject *obj)
226 TildaWindow *self = (TildaWindow *) obj;
229 * Here, complete the object's destruction.
230 * You might not need to do much...
232 // TODO: g_free() any primitives here
233 g_ptr_array_free (self->terms, TRUE);
236 /* Chain up to the parent class */
237 G_OBJECT_CLASS (parent_class)->finalize (obj);
241 tilda_window_class_init (gpointer g_class,
242 gpointer g_class_data)
244 GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
245 TildaWindowClass *klass = TILDA_WINDOW_CLASS (g_class);
248 /* Hook our functions to this type */
249 gobject_class->set_property = tilda_window_set_property;
250 gobject_class->get_property = tilda_window_get_property;
251 gobject_class->dispose = tilda_window_dispose;
252 gobject_class->finalize = tilda_window_finalize;
253 gobject_class->constructor = tilda_window_constructor;
255 parent_class = g_type_class_peek_parent (klass);
257 /* Install all of the properties */
258 pspec = g_param_spec_int ("number",
260 "Set window's number",
262 INT_MAX, // max value
264 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
266 g_object_class_install_property (gobject_class,
270 /* TODO: more properties */
272 /* Hook the TildaWindow type into DBus */
273 dbus_g_object_type_install_info (tilda_window_get_type(), &dbus_glib_tilda_window_object_info);
277 tilda_window_get_type (void)
279 static GType type = 0;
283 static const GTypeInfo info = {
284 sizeof (TildaWindowClass),
285 NULL, /* base_init */
286 NULL, /* base_finalize */
287 tilda_window_class_init, /* class_init */
288 NULL, /* class_finalize */
289 NULL, /* class_data */
290 sizeof (TildaWindow),
292 tilda_window_instance_init, /* instance_init */
295 type = g_type_register_static (G_TYPE_OBJECT,
306 int main (int argc, char *argv[])
309 gint test_number = INT_MIN;
311 /* Initialize the GObject type system */
313 gtk_init (&argc, &argv);
315 tw = g_object_new (TILDA_TYPE_WINDOW, "number", 10, NULL);
316 g_object_get (G_OBJECT (tw), "number", &test_number, NULL);
317 g_assert (test_number == 10);
319 g_object_unref (G_OBJECT (tw));
321 tw = g_object_new (TILDA_TYPE_WINDOW, "number", 22, NULL);
322 g_object_get (G_OBJECT (tw), "number", &test_number, NULL);
323 g_assert (test_number == 22);
327 g_object_unref (G_OBJECT (tw));
334 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */