X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;ds=sidebyside;f=tilda-controller.c;h=7d53aa6396340efa64490db1a4bba9fc9b9d7e93;hb=d7889f80f7846c3f6d3051e5b575cf8dd9c02ccd;hp=613bedbbd59acb1f6775153bd1197c13cbddc031;hpb=f63eddf4af4399505f330140cb63986b417b1fde;p=tilda-gobject.git diff --git a/tilda-controller.c b/tilda-controller.c index 613bedb..7d53aa6 100644 --- a/tilda-controller.c +++ b/tilda-controller.c @@ -1,4 +1,5 @@ #include "tilda.h" +#include "tilda-config.h" #include "tilda-controller.h" #include "tilda-controller-dbus-glue.h" #include "tilda-window.h" @@ -14,6 +15,10 @@ tilda_controller_dbus_register_object (TildaController *self) static const gchar object_path[] = "/net/sourceforge/Tilda"; + /* If DBus is not running, leave */ + if (!dbus_connection) + return; + dbus_g_connection_register_g_object (dbus_connection, object_path, G_OBJECT(self)); } @@ -68,7 +73,7 @@ tilda_controller_add_window (TildaController *self) g_ptr_array_add (self->windows, ret); - debug_printf ("Adding window: 0x%x (number %d of %d)\n", ret, ret->number, self->windows->len); + debug_printf ("Adding window: 0x%p (number %d of %d)\n", ret, ret->number, self->windows->len); return TRUE; } @@ -88,7 +93,7 @@ tilda_controller_remove_window (TildaController *self, gint window_number) if (win->number == window_number) { - debug_printf ("Deleting TildaWindow 0x%x (number %d of %d)\n", + debug_printf ("Deleting TildaWindow 0x%p (number %d of %d)\n", win, win->number, self->windows->len); g_ptr_array_remove_index (self->windows, i); g_object_unref (G_OBJECT(win)); @@ -158,6 +163,10 @@ tilda_controller_quit (TildaController *self, GError **error) static GObjectClass *parent_class = NULL; +enum tilda_controller_properties { + TILDA_CONTROLLER_INITIAL_WINDOWS = 1, +}; + static void tilda_controller_instance_init (GTypeInstance *instance, gpointer g_class) @@ -168,6 +177,7 @@ tilda_controller_instance_init (GTypeInstance *instance, self->dispose_has_run = FALSE; self->windows = g_ptr_array_new (); + self->initial_windows = 1; } static void @@ -176,10 +186,17 @@ tilda_controller_set_property (GObject *object, const GValue *value, GParamSpec *pspec) { - TildaController *self = (TildaController *) self; + debug_enter (); + + TildaController *self = (TildaController *) object; switch (property_id) { + case TILDA_CONTROLLER_INITIAL_WINDOWS: + self->initial_windows = g_value_get_int (value); + debug_printf ("tilda controller initial windows: %d\n", self->initial_windows); + break; + default: /* We don't have any other properties */ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -193,10 +210,16 @@ tilda_controller_get_property (GObject *object, GValue *value, GParamSpec *pspec) { + debug_enter (); + TildaController *self = (TildaController *) object; switch (property_id) { + case TILDA_CONTROLLER_INITIAL_WINDOWS: + g_value_set_int (value, self->initial_windows); + break; + default: /* We don't have any other properties */ G_OBJECT_WARN_INVALID_PROPERTY_ID (object, property_id, pspec); @@ -212,10 +235,11 @@ tilda_controller_constructor (GType type, debug_enter (); GObject *obj; - TildaControllerClass *klass; TildaController *self; + gint i; /* Invoke the parent constructor */ + TildaControllerClass *klass; klass = TILDA_CONTROLLER_CLASS (g_type_class_peek (TILDA_TYPE_CONTROLLER)); obj = parent_class->constructor (type, n_construct_properties, @@ -225,12 +249,16 @@ tilda_controller_constructor (GType type, * Have fun! */ self = TILDA_CONTROLLER(obj); + /* Set all of the properties from the config */ + tilda_controller_set_property_from_config (self, "initial-windows"); + + /* Add initial windows */ + for (i=0; iinitial_windows; ++i) + tilda_controller_add_window (self); + /* Register this object with DBus */ tilda_controller_dbus_register_object (self); - /* Add a window -- FIXME: the number should be configurable */ - tilda_controller_add_window (self); - return obj; } @@ -278,7 +306,7 @@ tilda_controller_finalize (GObject *obj) static void tilda_controller_class_init (gpointer g_class, - gpointer g_class_data) + gpointer g_class_data) { debug_enter (); @@ -295,6 +323,17 @@ tilda_controller_class_init (gpointer g_class, parent_class = g_type_class_peek_parent (klass); /* Add properties here */ + pspec = g_param_spec_int ("initial-windows", + _("The number of windows that will be opened on startup"), + NULL, + 1, + 100, /* Sane Limit */ + 1, + G_PARAM_READWRITE); + + g_object_class_install_property (gobject_class, + TILDA_CONTROLLER_INITIAL_WINDOWS, + pspec); /* Hook the TildaController type into DBus */ dbus_g_object_type_install_info (tilda_controller_get_type(),