1 #include "tilda-window.h"
3 static GObjectClass *parent_class = NULL;
5 enum tilda_window_properties {
6 TILDA_WINDOW_NUMBER = 1,
10 tilda_window_instance_init (GTypeInstance *instance,
13 TildaWindow *self = (TildaWindow *) instance;
14 self->dispose_has_run = FALSE;
16 /* Initialize all properties */
21 tilda_window_set_property (GObject *object,
26 TildaWindow *self = (TildaWindow *) object;
28 switch (property_id) {
30 case TILDA_WINDOW_NUMBER:
31 self->number = g_value_get_int (value);
32 g_print ("window number: %d\n", self->number);
36 /* We don't have this property */
37 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
43 tilda_window_get_property (GObject *object,
48 TildaWindow *self = (TildaWindow *) object;
50 switch (property_id) {
52 case TILDA_WINDOW_NUMBER:
53 g_value_set_int (value, self->number);
57 /* We don't have this property */
58 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
64 tilda_window_constructor (GType type,
65 guint n_construct_properties,
66 GObjectConstructParam *construct_properties)
70 /* Invoke parent constructor */
71 TildaWindowClass *klass;
72 klass = TILDA_WINDOW_CLASS (g_type_class_peek (TILDA_TYPE_WINDOW));
73 obj = parent_class->constructor (type,
74 n_construct_properties,
75 construct_properties);
77 /* Do other stuff here. The object is ready to go now, and all
78 * ctor properties have been set.
80 * TODO: This is the place to do DBus-init */
86 tilda_window_dispose (GObject *obj)
88 TildaWindow *self = (TildaWindow *) obj;
90 /* We don't want to run dispose twice, so just return immediately */
91 if (self->dispose_has_run)
95 * In dispose, you are supposed to free all types referenced from this
96 * object which might themselves hold a reference to self. Generally,
97 * the most simple solution is to unref all members on which you own a
101 /* Chain up to the parent class */
102 G_OBJECT_CLASS (parent_class)->dispose (obj);
106 tilda_window_finalize (GObject *obj)
108 TildaWindow *self = (TildaWindow *) obj;
111 * Here, complete the object's destruction.
112 * You might not need to do much...
114 // TODO: g_free() any primitives here
117 /* Chain up to the parent class */
118 G_OBJECT_CLASS (parent_class)->finalize (obj);
122 tilda_window_class_init (gpointer g_class,
123 gpointer g_class_data)
125 GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
126 TildaWindowClass *klass = TILDA_WINDOW_CLASS (g_class);
129 /* Hook our functions to this type */
130 gobject_class->set_property = tilda_window_set_property;
131 gobject_class->get_property = tilda_window_get_property;
132 gobject_class->dispose = tilda_window_dispose;
133 gobject_class->finalize = tilda_window_finalize;
134 gobject_class->constructor = tilda_window_constructor;
136 parent_class = g_type_class_peek_parent (klass);
138 /* Install all of the properties */
139 pspec = g_param_spec_int ("number",
141 "Set window's number",
143 INT_MAX, // max value
145 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
147 g_object_class_install_property (gobject_class,
151 /* TODO: more properties */
155 tilda_window_get_type (void)
157 static GType type = 0;
161 static const GTypeInfo info = {
162 sizeof (TildaWindowClass),
163 NULL, /* base_init */
164 NULL, /* base_finalize */
165 tilda_window_class_init, /* class_init */
166 NULL, /* class_finalize */
167 NULL, /* class_data */
168 sizeof (TildaWindow),
170 tilda_window_instance_init, /* instance_init */
173 type = g_type_register_static (G_TYPE_OBJECT,
183 int main (int argc, char *argv[])
186 gint test_number = INT_MIN;
188 /* Initialize the GObject type system */
191 tw = g_object_new (TILDA_TYPE_WINDOW, "number", 10, NULL);
192 g_object_get (G_OBJECT (tw), "number", &test_number, NULL);
193 g_assert (test_number == 10);
195 g_object_unref (G_OBJECT (tw));
197 tw = g_object_new (TILDA_TYPE_WINDOW, "number", 22, NULL);
198 g_object_get (G_OBJECT (tw), "number", &test_number, NULL);
199 g_assert (test_number == 22);
201 g_object_unref (G_OBJECT (tw));
206 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */