X-Git-Url: https://irasnyder.com/gitweb/?a=blobdiff_plain;f=tilda-controller.c;h=7d53aa6396340efa64490db1a4bba9fc9b9d7e93;hb=d7889f80f7846c3f6d3051e5b575cf8dd9c02ccd;hp=cf0c23cee36b231ca712f0e221149f1df24c061d;hpb=29d12c6484f9be8e5d61e44b5031fb7bb7d1c076;p=tilda-gobject.git diff --git a/tilda-controller.c b/tilda-controller.c index cf0c23c..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)); @@ -110,6 +115,36 @@ tilda_controller_remove_window (TildaController *self, gint window_number) return FALSE; } +/** + * Check if a key is used in one of our windows. + * + * This is needed because the tomboy_keybinder_bind() function allows + * more than one callback to be registered for the same key. + */ +gboolean +tilda_controller_global_key_in_use (const TildaController *self, const gchar *keystr) +{ + gint i; + TildaWindow *tw; + + guint key1, key2; + GdkModifierType mod1, mod2; + + gtk_accelerator_parse (keystr, &key1, &mod1); + + for (i=0; iwindows->len; ++i) + { + tw = g_ptr_array_index (self->windows, i); + gtk_accelerator_parse (tw->key, &key2, &mod2); + + if (key1 == key2 && mod1 == mod2) + return TRUE; + } + + /* No identical keys found, we're ok */ + return FALSE; +} + gboolean tilda_controller_quit (TildaController *self, GError **error) { @@ -128,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) @@ -138,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 @@ -146,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); @@ -163,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); @@ -182,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, @@ -195,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; } @@ -248,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 (); @@ -265,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(),