2 #include "tilda-window.h"
3 #include "tilda-window-dbus-glue.h"
6 tilda_window_add_term (TildaWindow *tw)
8 // FIXME: this is totally bad, but it's a good hack for feasability
9 static gint mynumber = 0;
10 TildaTerminal *tt = g_object_new (TILDA_TYPE_TERMINAL,
12 "window-number", tw->number,
15 g_ptr_array_add (tw->terms, tt);
17 GtkWidget *label = gtk_label_new ("Tilda");
18 gint index = gtk_notebook_prepend_page (GTK_NOTEBOOK(tw->notebook), tt->hbox, label);
19 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK(tw->notebook), tt->hbox, TRUE, TRUE, GTK_PACK_END);
20 //gtk_notebook_set_current_page (GTK_NOTEBOOK(tw->notebook), index);
22 if (gtk_notebook_get_n_pages (GTK_NOTEBOOK(tw->notebook)) > 1)
23 gtk_notebook_set_show_tabs (GTK_NOTEBOOK(tw->notebook), TRUE);
29 tilda_window_remove_term (TildaWindow *tw, int number)
33 for (i=0; i<tw->terms->len; ++i)
35 TildaTerminal *tt = g_ptr_array_index (tw->terms, i);
37 if (tt->number == number)
38 g_print ("Need to remove window %d terminal %d\n", tw->number, tt->number);
45 tilda_window_dbus_register_object (TildaWindow *tw)
49 // Register this object with DBus
50 object_path = g_strdup_printf ("/net/sourceforge/Tilda/Window%d", tw->number);
51 dbus_g_connection_register_g_object (dbus_connection, object_path, G_OBJECT(tw));
55 /*******************************************************************************
56 * ALL GOBJECT STUFF BELOW PLEASE
57 ******************************************************************************/
59 static GObjectClass *parent_class = NULL;
61 enum tilda_window_properties {
62 TILDA_WINDOW_NUMBER = 1,
66 tilda_window_instance_init (GTypeInstance *instance,
69 TildaWindow *self = (TildaWindow *) instance;
70 self->dispose_has_run = FALSE;
72 /* Initialize all properties */
73 self->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
74 self->notebook = gtk_notebook_new ();
75 self->terms = g_ptr_array_new ();
77 /* Somewhat of a "poison" value, incase we don't set this */
78 self->number = 0xdeadbeef;
82 tilda_window_set_property (GObject *object,
87 TildaWindow *self = (TildaWindow *) object;
89 switch (property_id) {
91 case TILDA_WINDOW_NUMBER:
92 self->number = g_value_get_int (value);
93 g_print ("window number: %d\n", self->number);
97 /* We don't have this property */
98 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
104 tilda_window_get_property (GObject *object,
109 TildaWindow *self = (TildaWindow *) object;
111 switch (property_id) {
113 case TILDA_WINDOW_NUMBER:
114 g_value_set_int (value, self->number);
118 /* We don't have this property */
119 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
125 tilda_window_constructor (GType type,
126 guint n_construct_properties,
127 GObjectConstructParam *construct_properties)
132 /* Invoke parent constructor */
133 TildaWindowClass *klass;
134 klass = TILDA_WINDOW_CLASS (g_type_class_peek (TILDA_TYPE_WINDOW));
135 obj = parent_class->constructor (type,
136 n_construct_properties,
137 construct_properties);
139 /* Do other stuff here. The object is ready to go now, and all
140 * ctor properties have been set.
142 * TODO: This is the place to do DBus-init */
143 self = TILDA_WINDOW(obj);
145 /* Register this object with DBus */
146 tilda_window_dbus_register_object (self);
148 gtk_container_add (GTK_CONTAINER(self->window), self->notebook);
149 gtk_widget_show (self->notebook);
151 tilda_window_add_term (self);
152 gtk_widget_show_all (self->window);
158 my_unref (gpointer data, gpointer user_data)
160 g_object_unref (G_OBJECT(data));
164 tilda_window_dispose (GObject *obj)
166 TildaWindow *self = (TildaWindow *) obj;
168 /* We don't want to run dispose twice, so just return immediately */
169 if (self->dispose_has_run)
173 * In dispose, you are supposed to free all types referenced from this
174 * object which might themselves hold a reference to self. Generally,
175 * the most simple solution is to unref all members on which you own a
178 * NOTE: See the following for how to deal with GtkObject-derived things:
179 * http://library.gnome.org/devel/gtk/unstable/GtkObject.html
181 g_ptr_array_foreach (self->terms, my_unref, NULL);
182 gtk_widget_destroy (self->window);
184 /* Chain up to the parent class */
185 G_OBJECT_CLASS (parent_class)->dispose (obj);
189 tilda_window_finalize (GObject *obj)
191 TildaWindow *self = (TildaWindow *) obj;
194 * Here, complete the object's destruction.
195 * You might not need to do much...
197 // TODO: g_free() any primitives here
198 g_ptr_array_free (self->terms, TRUE);
201 /* Chain up to the parent class */
202 G_OBJECT_CLASS (parent_class)->finalize (obj);
206 tilda_window_class_init (gpointer g_class,
207 gpointer g_class_data)
209 GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
210 TildaWindowClass *klass = TILDA_WINDOW_CLASS (g_class);
213 /* Hook our functions to this type */
214 gobject_class->set_property = tilda_window_set_property;
215 gobject_class->get_property = tilda_window_get_property;
216 gobject_class->dispose = tilda_window_dispose;
217 gobject_class->finalize = tilda_window_finalize;
218 gobject_class->constructor = tilda_window_constructor;
220 parent_class = g_type_class_peek_parent (klass);
222 /* Install all of the properties */
223 pspec = g_param_spec_int ("number",
225 "Set window's number",
227 INT_MAX, // max value
229 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
231 g_object_class_install_property (gobject_class,
235 /* TODO: more properties */
237 /* Hook the TildaWindow type into DBus */
238 dbus_g_object_type_install_info (tilda_window_get_type(), &dbus_glib_tilda_window_object_info);
242 tilda_window_get_type (void)
244 static GType type = 0;
248 static const GTypeInfo info = {
249 sizeof (TildaWindowClass),
250 NULL, /* base_init */
251 NULL, /* base_finalize */
252 tilda_window_class_init, /* class_init */
253 NULL, /* class_finalize */
254 NULL, /* class_data */
255 sizeof (TildaWindow),
257 tilda_window_instance_init, /* instance_init */
260 type = g_type_register_static (G_TYPE_OBJECT,
271 int main (int argc, char *argv[])
274 gint test_number = INT_MIN;
276 /* Initialize the GObject type system */
278 gtk_init (&argc, &argv);
280 tw = g_object_new (TILDA_TYPE_WINDOW, "number", 10, NULL);
281 g_object_get (G_OBJECT (tw), "number", &test_number, NULL);
282 g_assert (test_number == 10);
284 g_object_unref (G_OBJECT (tw));
286 tw = g_object_new (TILDA_TYPE_WINDOW, "number", 22, NULL);
287 g_object_get (G_OBJECT (tw), "number", &test_number, NULL);
288 g_assert (test_number == 22);
292 g_object_unref (G_OBJECT (tw));
299 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */