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,
14 g_ptr_array_add (tw->terms, tt);
16 GtkWidget *label = gtk_label_new ("Tilda");
17 gint index = gtk_notebook_prepend_page (GTK_NOTEBOOK(tw->notebook), tt->hbox, label);
18 gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK(tw->notebook), tt->hbox, TRUE, TRUE, GTK_PACK_END);
19 //gtk_notebook_set_current_page (GTK_NOTEBOOK(tw->notebook), index);
21 if (gtk_notebook_get_n_pages (GTK_NOTEBOOK(tw->notebook)) > 1)
22 gtk_notebook_set_show_tabs (GTK_NOTEBOOK(tw->notebook), TRUE);
28 tilda_window_remove_term (TildaWindow *tw, int number)
32 for (i=0; i<tw->terms->len; ++i)
34 TildaTerminal *tt = g_ptr_array_index (tw->terms, i);
36 if (tt->number == number)
37 g_print ("Need to remove window %d terminal %d\n", tw->number, tt->number);
44 tilda_window_dbus_register_object (TildaWindow *tw)
48 // Register this object with DBus
49 object_path = g_strdup_printf ("/net/sourceforge/Tilda/Window%d", tw->number);
50 dbus_g_connection_register_g_object (dbus_connection, object_path, G_OBJECT(tw));
54 /*******************************************************************************
55 * ALL GOBJECT STUFF BELOW PLEASE
56 ******************************************************************************/
58 static GObjectClass *parent_class = NULL;
60 enum tilda_window_properties {
61 TILDA_WINDOW_NUMBER = 1,
65 tilda_window_instance_init (GTypeInstance *instance,
68 TildaWindow *self = (TildaWindow *) instance;
69 self->dispose_has_run = FALSE;
71 /* Initialize all properties */
72 self->window = gtk_window_new (GTK_WINDOW_TOPLEVEL);
73 self->notebook = gtk_notebook_new ();
74 self->terms = g_ptr_array_new ();
76 /* Somewhat of a "poison" value, incase we don't set this */
77 self->number = 0xdeadbeef;
81 tilda_window_set_property (GObject *object,
86 TildaWindow *self = (TildaWindow *) object;
88 switch (property_id) {
90 case TILDA_WINDOW_NUMBER:
91 self->number = g_value_get_int (value);
92 g_print ("window number: %d\n", self->number);
96 /* We don't have this property */
97 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
103 tilda_window_get_property (GObject *object,
108 TildaWindow *self = (TildaWindow *) object;
110 switch (property_id) {
112 case TILDA_WINDOW_NUMBER:
113 g_value_set_int (value, self->number);
117 /* We don't have this property */
118 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
124 tilda_window_constructor (GType type,
125 guint n_construct_properties,
126 GObjectConstructParam *construct_properties)
131 /* Invoke parent constructor */
132 TildaWindowClass *klass;
133 klass = TILDA_WINDOW_CLASS (g_type_class_peek (TILDA_TYPE_WINDOW));
134 obj = parent_class->constructor (type,
135 n_construct_properties,
136 construct_properties);
138 /* Do other stuff here. The object is ready to go now, and all
139 * ctor properties have been set.
141 * TODO: This is the place to do DBus-init */
142 self = TILDA_WINDOW(obj);
144 /* Register this object with DBus */
145 tilda_window_dbus_register_object (self);
147 gtk_container_add (GTK_CONTAINER(self->window), self->notebook);
148 gtk_widget_show (self->notebook);
150 tilda_window_add_term (self);
151 gtk_widget_show_all (self->window);
157 my_unref (gpointer data, gpointer user_data)
159 g_object_unref (G_OBJECT(data));
163 tilda_window_dispose (GObject *obj)
165 TildaWindow *self = (TildaWindow *) obj;
167 /* We don't want to run dispose twice, so just return immediately */
168 if (self->dispose_has_run)
172 * In dispose, you are supposed to free all types referenced from this
173 * object which might themselves hold a reference to self. Generally,
174 * the most simple solution is to unref all members on which you own a
177 * NOTE: See the following for how to deal with GtkObject-derived things:
178 * http://library.gnome.org/devel/gtk/unstable/GtkObject.html
180 g_ptr_array_foreach (self->terms, my_unref, NULL);
181 gtk_widget_destroy (self->window);
183 /* Chain up to the parent class */
184 G_OBJECT_CLASS (parent_class)->dispose (obj);
188 tilda_window_finalize (GObject *obj)
190 TildaWindow *self = (TildaWindow *) obj;
193 * Here, complete the object's destruction.
194 * You might not need to do much...
196 // TODO: g_free() any primitives here
197 g_ptr_array_free (self->terms, TRUE);
200 /* Chain up to the parent class */
201 G_OBJECT_CLASS (parent_class)->finalize (obj);
205 tilda_window_class_init (gpointer g_class,
206 gpointer g_class_data)
208 GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
209 TildaWindowClass *klass = TILDA_WINDOW_CLASS (g_class);
212 /* Hook our functions to this type */
213 gobject_class->set_property = tilda_window_set_property;
214 gobject_class->get_property = tilda_window_get_property;
215 gobject_class->dispose = tilda_window_dispose;
216 gobject_class->finalize = tilda_window_finalize;
217 gobject_class->constructor = tilda_window_constructor;
219 parent_class = g_type_class_peek_parent (klass);
221 /* Install all of the properties */
222 pspec = g_param_spec_int ("number",
224 "Set window's number",
226 INT_MAX, // max value
228 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
230 g_object_class_install_property (gobject_class,
234 /* TODO: more properties */
236 /* Hook the TildaWindow type into DBus */
237 dbus_g_object_type_install_info (tilda_window_get_type(), &dbus_glib_tilda_window_object_info);
241 tilda_window_get_type (void)
243 static GType type = 0;
247 static const GTypeInfo info = {
248 sizeof (TildaWindowClass),
249 NULL, /* base_init */
250 NULL, /* base_finalize */
251 tilda_window_class_init, /* class_init */
252 NULL, /* class_finalize */
253 NULL, /* class_data */
254 sizeof (TildaWindow),
256 tilda_window_instance_init, /* instance_init */
259 type = g_type_register_static (G_TYPE_OBJECT,
270 int main (int argc, char *argv[])
273 gint test_number = INT_MIN;
275 /* Initialize the GObject type system */
277 gtk_init (&argc, &argv);
279 tw = g_object_new (TILDA_TYPE_WINDOW, "number", 10, NULL);
280 g_object_get (G_OBJECT (tw), "number", &test_number, NULL);
281 g_assert (test_number == 10);
283 g_object_unref (G_OBJECT (tw));
285 tw = g_object_new (TILDA_TYPE_WINDOW, "number", 22, NULL);
286 g_object_get (G_OBJECT (tw), "number", &test_number, NULL);
287 g_assert (test_number == 22);
291 g_object_unref (G_OBJECT (tw));
298 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */