#include "tilda.h"
+#include "tilda-config.h"
#include "tilda-controller.h"
#include "tilda-controller-dbus-glue.h"
#include "tilda-window.h"
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));
}
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;
}
gboolean
-tilda_controller_delete_window (TildaController *self, gint window_number)
+tilda_controller_remove_window (TildaController *self, gint window_number)
{
debug_enter ();
debug_assert (TILDA_IS_CONTROLLER(self));
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));
gtk_main_quit ();
}
- /* We were able to delete the window */
+ /* We were able to remove the window */
return TRUE;
}
}
- /* There must have been no window to delete */
+ /* There must have been no window to remove */
+ 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; i<self->windows->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;
}
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)
self->dispose_has_run = FALSE;
self->windows = g_ptr_array_new ();
+ self->initial_windows = 1;
}
static void
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);
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);
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,
* 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; i<self->initial_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;
}
static void
tilda_controller_class_init (gpointer g_class,
- gpointer g_class_data)
+ gpointer g_class_data)
{
debug_enter ();
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(),