1 #include "tilda-terminal.h"
3 static GObjectClass *parent_class = NULL;
8 * All GObject stuff is below. You probably don't need to change this...
11 enum tilda_terminal_properties {
12 TILDA_TERMINAL_NUMBER = 1,
13 // TODO: All properties
17 tilda_terminal_instance_init (GTypeInstance *instance,
20 TildaTerminal *self = (TildaTerminal *) instance;
22 /* Initialize instance members and allocate any necessary memory here.
23 * NOTE: any constructor-time values will be set later. */
24 self->dispose_has_run = FALSE;
29 tilda_terminal_set_property (GObject *object,
34 TildaTerminal *self = (TildaTerminal *) object;
36 switch (property_id) {
38 case TILDA_TERMINAL_NUMBER:
39 self->number = g_value_get_int (value);
40 g_print ("terminal number: %d\n", self->number);
44 /* We don't have this property... */
45 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
51 tilda_terminal_get_property (GObject *object,
56 TildaTerminal *self = (TildaTerminal *) object;
58 switch (property_id) {
60 case TILDA_TERMINAL_NUMBER:
61 g_value_set_int (value, self->number);
65 /* We don't have this property... */
66 G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec);
72 tilda_terminal_constructor (GType type,
73 guint n_construct_properties,
74 GObjectConstructParam *construct_properties)
78 /* Invoke parent constructor */
79 TildaTerminalClass *klass;
80 klass = TILDA_TERMINAL_CLASS (g_type_class_peek (TILDA_TYPE_TERMINAL));
81 obj = parent_class->constructor (type,
82 n_construct_properties,
83 construct_properties);
85 /* Do other stuff here. The object is ready to go now, and all
86 * ctor properties have been set.
88 * TODO: This is the place to do DBus-init */
95 tilda_terminal_dispose (GObject *obj)
97 TildaTerminal *self = (TildaTerminal *) obj;
99 /* We don't want to run dispose twice, so just return immediately */
100 if (self->dispose_has_run)
103 self->dispose_has_run = TRUE;
106 * In dispose, you are supposed to free all types referenced from this
107 * object which might themselves hold a reference to self. Generally,
108 * the most simple solution is to unref all members on which you own a
112 /* Chain up to the parent class */
113 G_OBJECT_CLASS (parent_class)->dispose (obj);
117 tilda_terminal_finalize (GObject *obj)
119 TildaTerminal *self = (TildaTerminal *) obj;
122 * Here, complete object destruction.
123 * You might not need to do much...
126 // TODO: g_free() any primitives here
129 /* Chain up to the parent class */
130 G_OBJECT_CLASS (parent_class)->finalize (obj);
134 tilda_terminal_class_init (gpointer g_class,
135 gpointer g_class_data)
137 GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
138 TildaTerminalClass *klass = TILDA_TERMINAL_CLASS (g_class);
141 /* Hook our functions to this type */
142 gobject_class->set_property = tilda_terminal_set_property;
143 gobject_class->get_property = tilda_terminal_get_property;
144 gobject_class->dispose = tilda_terminal_dispose;
145 gobject_class->finalize = tilda_terminal_finalize;
146 gobject_class->constructor = tilda_terminal_constructor;
148 parent_class = g_type_class_peek_parent (klass);
150 /* Install all of the properties */
151 pspec = g_param_spec_int ("number",
153 "Set terminal's number",
155 INT_MAX, // max value
157 G_PARAM_CONSTRUCT_ONLY | G_PARAM_READWRITE);
159 g_object_class_install_property (gobject_class,
160 TILDA_TERMINAL_NUMBER,
165 tilda_terminal_get_type (void)
167 static GType type = 0;
171 static const GTypeInfo info = {
172 sizeof (TildaTerminalClass),
173 NULL, /* base_init */
174 NULL, /* base_finalize */
175 tilda_terminal_class_init, /* class_init */
176 NULL, /* class_finalize */
177 NULL, /* class_data */
178 sizeof (TildaTerminal),
180 tilda_terminal_instance_init, /* instance_init */
183 type = g_type_register_static (G_TYPE_OBJECT,
192 int main (int argc, char *argv[])
195 gint test_number = INT_MIN;
197 /* Initialize the GObject type system */
200 tt = g_object_new (TILDA_TYPE_TERMINAL, "number", 10, NULL);
201 g_object_get (G_OBJECT (tt), "number", &test_number, NULL);
202 g_assert (test_number == 10);
204 g_object_unref (G_OBJECT (tt));
206 tt = g_object_new (TILDA_TYPE_TERMINAL, "number", 22, NULL);
207 g_object_get (G_OBJECT (tt), "number", &test_number, NULL);
208 g_assert (test_number == 22);
210 g_object_unref (G_OBJECT (tt));
215 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */