[Terminal] Mark all translatable strings
[tilda-gobject.git] / tilda-window.c
index be5067d..579ee1f 100644 (file)
@@ -1,6 +1,9 @@
+#include <string.h>
+
 #include "tilda.h"
 #include "tilda-window.h"
 #include "tilda-window-dbus-glue.h"
+#include "tomboykeybinder.h"
 
 /**
  * Find the TildaTerminal corresponding to the currently selected
@@ -10,6 +13,9 @@
 static TildaTerminal *
 tilda_window_find_current_terminal (TildaWindow *self)
 {
+       debug_enter();
+       debug_assert (TILDA_IS_WINDOW(self));
+
        gint i;
        TildaTerminal *ret;
        gint current_page = gtk_notebook_get_current_page (GTK_NOTEBOOK(self->notebook));
@@ -23,13 +29,16 @@ tilda_window_find_current_terminal (TildaWindow *self)
                        return ret;
        }
 
-       g_printerr ("FIXME: unable to find current terminal!\n");
+       debug_printf ("ERROR: unable to find current terminal!\n");
        return NULL;
 }
 
 static gint
 tilda_window_find_next_free_terminal_number (TildaWindow *tw)
 {
+       debug_enter ();
+       debug_assert (TILDA_IS_WINDOW(tw));
+
        gint i, j;
        gboolean found;
 
@@ -58,13 +67,15 @@ tilda_window_find_next_free_terminal_number (TildaWindow *tw)
 static gboolean
 tilda_window_add_term (TildaWindow *tw)
 {
+       debug_enter ();
+       debug_assert (TILDA_IS_WINDOW(tw));
+
        gint number;
        TildaTerminal *tt;
 
        number = tilda_window_find_next_free_terminal_number (tw);
        tt = g_object_new (TILDA_TYPE_TERMINAL,
                                           "number", number,
-                                          "window-number", tw->number,
                                           "parent-window", tw,
                                           NULL);
        g_ptr_array_add (tw->terms, tt);
@@ -72,7 +83,7 @@ tilda_window_add_term (TildaWindow *tw)
        GtkWidget *label = gtk_label_new ("Tilda");
        gint index = gtk_notebook_prepend_page (GTK_NOTEBOOK(tw->notebook), tt->hbox, label);
        gtk_notebook_set_tab_label_packing (GTK_NOTEBOOK(tw->notebook), tt->hbox, TRUE, TRUE, GTK_PACK_END);
-       //gtk_notebook_set_current_page (GTK_NOTEBOOK(tw->notebook), index);
+       gtk_notebook_set_current_page (GTK_NOTEBOOK(tw->notebook), index);
 
        if (gtk_notebook_get_n_pages (GTK_NOTEBOOK(tw->notebook)) > 1)
                gtk_notebook_set_show_tabs (GTK_NOTEBOOK(tw->notebook), TRUE);
@@ -89,6 +100,10 @@ tilda_window_add_term (TildaWindow *tw)
 gboolean
 tilda_window_remove_term (TildaWindow *tw, gint terminal_number)
 {
+       debug_enter  ();
+       debug_assert (TILDA_IS_WINDOW(tw));
+       debug_assert (terminal_number >= 0);
+
        gint i;
 
        for (i=0; i<tw->terms->len; ++i)
@@ -102,7 +117,7 @@ tilda_window_remove_term (TildaWindow *tw, gint terminal_number)
                        /* Make sure the index was valid */
                        if (notebook_index == -1)
                        {
-                               g_printerr ("DEBUG ERROR: Bad Notebook Tab\n");
+                               debug_printf ("ERROR: Bad Notebook Tab\n");
                                return FALSE;
                        }
 
@@ -113,17 +128,17 @@ tilda_window_remove_term (TildaWindow *tw, gint terminal_number)
                        if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (tw->notebook)) == 1)
                                gtk_notebook_set_show_tabs (GTK_NOTEBOOK (tw->notebook), FALSE);
 
-#if 0
-                       // FIXME FIXME FIXME: need to actually do the stuff below
-                       /* With no pages left, it's time to leave the program */
-                       if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (tw->notebook)) < 1)
-                               gtk_main_quit ();
-#endif
-
                        /* Remove the term from our lists, then free it */
                        g_ptr_array_remove_fast (tw->terms, tt);
                        g_object_unref (G_OBJECT(tt));
 
+                       /* With no pages left, it's time to remove this window */
+                       if (gtk_notebook_get_n_pages (GTK_NOTEBOOK (tw->notebook)) < 1)
+                       {
+                               debug_printf ("no terminals left, closing window %d\n", tw->number);
+                               tilda_del_window (tw->number);
+                       }
+
                        /* Leave the loop, we're done */
                        break;
                }
@@ -138,6 +153,9 @@ tilda_window_remove_term (TildaWindow *tw, gint terminal_number)
 static void
 tilda_window_setup_real_transparency (TildaWindow *self)
 {
+       debug_enter  ();
+       debug_assert (TILDA_IS_WINDOW(self));
+
        GdkScreen *screen;
        GdkColormap *colormap;
 
@@ -156,12 +174,42 @@ tilda_window_setup_real_transparency (TildaWindow *self)
        self->have_real_transparency = FALSE;
 }
 
+/* Center the given TildaWindow in the horizontal axis */
+static void
+tilda_window_center_horizontally (TildaWindow *self)
+{
+       debug_enter  ();
+       debug_assert (TILDA_IS_WINDOW(self));
+
+       const gint screen_center = gdk_screen_width() / 2;
+       const gint tilda_center  = self->width / 2;
+       const gint center_coord  = screen_center - tilda_center;
+
+       g_object_set (G_OBJECT(self), "x-position", center_coord, NULL);
+}
+
+/* Center the given TildaWindow in the vertical axis */
+static void
+tilda_window_center_vertically (TildaWindow *self)
+{
+       debug_enter  ();
+       debug_assert (TILDA_IS_WINDOW(self));
+
+       const gint screen_center = gdk_screen_height() / 2;
+       const gint tilda_center  = self->height / 2;
+       const gint center_coord  = screen_center - tilda_center;
+
+       g_object_set (G_OBJECT(self), "y-position", center_coord, NULL);
+}
+
 static void
 tilda_window_keybinding_cb (const gchar *keystr, gpointer data)
 {
+       debug_enter  ();
+       debug_assert (TILDA_IS_WINDOW(data));
+
        TildaWindow *self = TILDA_WINDOW(data);
        TildaTerminal *tt;
-       g_print ("tilda_window_keybinding_cb() called! -- window %d\n", self->number);
 
        // FIXME: this doesn't handle animation!
 
@@ -200,7 +248,7 @@ tilda_window_keybinding_cb (const gchar *keystr, gpointer data)
                        break;
 
                default:
-                       g_printerr ("FIXME: the window is in a bad state!\n");
+                       debug_printf ("ERROR: Window is in a bad state!\n");
 
                        /* Pretend we're down, for good measure.... */
                        self->state = WINDOW_DOWN;
@@ -216,6 +264,9 @@ tilda_window_keybinding_cb (const gchar *keystr, gpointer data)
 static gboolean
 tilda_window_try_to_bind_key (TildaWindow *self, const gchar *new_key)
 {
+       debug_enter  ();
+       debug_assert (TILDA_IS_WINDOW(self));
+
        gboolean ret = FALSE;
 
        /* Make sure the new key is not null in any way */
@@ -224,7 +275,7 @@ tilda_window_try_to_bind_key (TildaWindow *self, const gchar *new_key)
 
        /* Unbind if we were set */
        if (self->key)
-               tomboy_keybinder_unbind (self->key, tilda_window_keybinding_cb, self);
+               tomboy_keybinder_unbind (self->key, tilda_window_keybinding_cb);
 
        ret = tomboy_keybinder_bind (new_key, tilda_window_keybinding_cb, self);
 
@@ -236,7 +287,7 @@ tilda_window_try_to_bind_key (TildaWindow *self, const gchar *new_key)
                return TRUE;
        }
 
-       g_printerr ("Keybinding unsuccessful. Reverting to original key\n");
+       g_printerr (_("Bind key '%s' failed. Reverting to original keybinding\n"), self->key);
 
        /* Not successful, so rebind the old key, and return FALSE */
        if (self->key != NULL && strcmp("",self->key) != 0)
@@ -245,10 +296,10 @@ tilda_window_try_to_bind_key (TildaWindow *self, const gchar *new_key)
 
                /* Check that it went ok */
                if (!ret)
-                       g_printerr ("Unable to bind original key as well! Oh shit...\n");
+                       g_printerr (_("Unable to re-bind original key '%s'. Oh shit...\n"), self->key);
        }
        else
-               g_printerr ("No original key to revert to!\n");
+               g_printerr (_("No original key to revert to!\n"));
 
        return FALSE;
 }
@@ -256,6 +307,9 @@ tilda_window_try_to_bind_key (TildaWindow *self, const gchar *new_key)
 static void
 tilda_window_dbus_register_object (TildaWindow *tw)
 {
+       debug_enter  ();
+       debug_assert (TILDA_IS_WINDOW(tw));
+
        gchar *object_path;
 
        // Register this object with DBus
@@ -298,6 +352,8 @@ static void
 tilda_window_instance_init (GTypeInstance *instance,
                                                        gpointer       g_class)
 {
+       debug_enter ();
+
        TildaWindow *self = (TildaWindow *) instance;
        self->dispose_has_run = FALSE;
 
@@ -324,66 +380,66 @@ tilda_window_set_property (GObject      *object,
 
                case TILDA_WINDOW_NUMBER:
                        self->number = g_value_get_int (value);
-                       g_print ("window number: %d\n", self->number);
+                       debug_printf ("window number: %d\n", self->number);
                        break;
 
                case TILDA_WINDOW_KEY:
                        tilda_window_try_to_bind_key (self, g_value_get_string (value));
-                       g_print ("window key: %s\n", self->key);
+                       debug_printf ("window key %s\n", self->key);
                        break;
 
                case TILDA_WINDOW_HEIGHT:
                        self->height = g_value_get_int (value);
                        gtk_widget_set_size_request (self->window, self->width, self->height);
                        gtk_window_resize (GTK_WINDOW(self->window), self->width, self->height);
-                       g_print ("window height: %d\n", self->height);
+                       debug_printf ("window height: %d\n", self->height);
                        break;
 
                case TILDA_WINDOW_WIDTH:
                        self->width = g_value_get_int (value);
                        gtk_widget_set_size_request (self->window, self->width, self->height);
                        gtk_window_resize (GTK_WINDOW(self->window), self->width, self->height);
-                       g_print ("window width: %d\n", self->width);
+                       debug_printf ("window width: %d\n", self->width);
                        break;
 
                case TILDA_WINDOW_X_POSITION:
                        self->x_position = g_value_get_int (value);
                        gtk_window_move (GTK_WINDOW(self->window), self->x_position, self->y_position);
-                       g_print ("window x position: %d\n", self->x_position);
+                       debug_printf ("window x position: %d\n", self->x_position);
                        break;
 
                case TILDA_WINDOW_Y_POSITION:
                        self->y_position = g_value_get_int (value);
                        gtk_window_move (GTK_WINDOW(self->window), self->x_position, self->y_position);
-                       g_print ("window y position: %d\n", self->y_position);
+                       debug_printf ("window y position: %d\n", self->y_position);
                        break;
 
                case TILDA_WINDOW_TAB_POSITION:
                        self->tab_position = g_value_get_int (value);
                        gtk_notebook_set_tab_pos (GTK_NOTEBOOK(self->notebook), self->tab_position);
-                       g_print ("window tab position: %d\n", self->tab_position);
+                       debug_printf ("window tab position: %d\n", self->tab_position);
                        break;
 
                case TILDA_WINDOW_ANIMATION_ORIENTATION:
                        self->animation_orientation = g_value_get_int (value);
-                       g_print ("window animation orientation: %d\n", self->animation_orientation);
+                       debug_printf ("window animation orientation: %d\n", self->animation_orientation);
                        break;
 
                case TILDA_WINDOW_ANIMATION_DELAY:
                        self->animation_delay = g_value_get_int (value);
-                       g_print ("window animation delay: %d\n", self->animation_delay);
+                       debug_printf ("window animation delay: %d\n", self->animation_delay);
                        break;
 
                case TILDA_WINDOW_KEEP_ABOVE:
                        self->keep_above = g_value_get_boolean (value);
                        gtk_window_set_keep_above (GTK_WINDOW(self->window), self->keep_above);
-                       g_print ("window keep above: %d\n", self->keep_above);
+                       debug_printf ("window keep above: %d\n", self->keep_above);
                        break;
 
                case TILDA_WINDOW_SKIP_TASKBAR_HINT:
                        self->skip_taskbar_hint = g_value_get_boolean (value);
                        gtk_window_set_skip_taskbar_hint (GTK_WINDOW(self->window), self->skip_taskbar_hint);
-                       g_print ("window skip taskbar hint: %d\n", self->skip_taskbar_hint);
+                       debug_printf ("window skip taskbar hint: %d\n", self->skip_taskbar_hint);
                        break;
 
                case TILDA_WINDOW_STICK:
@@ -392,27 +448,31 @@ tilda_window_set_property (GObject      *object,
                        /* This is moderately ugly, but GTK+ does it this way... */
                        self->stick ? gtk_window_stick (GTK_WINDOW(self->window))
                                                : gtk_window_unstick (GTK_WINDOW(self->window));
-                       g_print ("window stick: %d\n", self->stick);
+                       debug_printf ("window stick: %d\n", self->stick);
                        break;
 
                case TILDA_WINDOW_HIDDEN_AT_START:
                        self->hidden_at_start = g_value_get_boolean (value);
-                       g_print ("window hidden at start: %d\n", self->hidden_at_start);
+                       debug_printf ("window hidden at start: %d\n", self->hidden_at_start);
                        break;
 
                case TILDA_WINDOW_CENTERED_HORIZONTALLY:
                        self->centered_horizontally = g_value_get_boolean (value);
-                       g_print ("window centered horizontally: %d\n", self->centered_horizontally);
+                       if (self->centered_horizontally)
+                               tilda_window_center_horizontally (self);
+                       debug_printf ("window centered horizontally: %d\n", self->centered_horizontally);
                        break;
 
                case TILDA_WINDOW_CENTERED_VERTICALLY:
                        self->centered_vertically = g_value_get_boolean (value);
-                       g_print ("window centered vertically: %d\n", self->centered_vertically);
+                       if (self->centered_vertically)
+                               tilda_window_center_vertically (self);
+                       debug_printf ("window centered vertically: %d\n", self->centered_vertically);
                        break;
 
                case TILDA_WINDOW_HAVE_REAL_TRANSPARENCY:
                        self->have_real_transparency = g_value_get_boolean (value);
-                       g_print ("window have real transp: %d\n", self->have_real_transparency);
+                       debug_printf ("window have real transp: %d\n", self->have_real_transparency);
                        break;
 
                default:
@@ -508,6 +568,8 @@ tilda_window_constructor (GType                  type,
                                                  guint                  n_construct_properties,
                                                  GObjectConstructParam *construct_properties)
 {
+       debug_enter ();
+
        GObject *obj;
        TildaWindow *self;
 
@@ -520,8 +582,7 @@ tilda_window_constructor (GType                  type,
 
        /* Do other stuff here. The object is ready to go now, and all
         * ctor properties have been set.
-        *
-        * TODO: This is the place to do DBus-init */
+        */
        self = TILDA_WINDOW(obj);
 
        /* Register this object with DBus */
@@ -537,6 +598,8 @@ tilda_window_constructor (GType                  type,
        g_object_set (G_OBJECT(self), "key", "F2", NULL);
        g_object_set (G_OBJECT(self), "x-position", 0, "y-position", 0, NULL);
        g_object_set (G_OBJECT(self), "height", 400, "width", 1680, NULL);
+       g_object_set (G_OBJECT(self), "keep-above", TRUE, "stick", TRUE, NULL);
+       g_object_set (G_OBJECT(self), "hidden-at-start", FALSE, NULL);
 
        gtk_window_set_decorated (GTK_WINDOW(self->window), FALSE);
 
@@ -560,12 +623,17 @@ tilda_window_constructor (GType                  type,
 static void
 my_unref (gpointer data, gpointer user_data)
 {
+       debug_enter ();
+
+       // FIXME: This function should probably be eliminated. It /is/ rather ugly
        g_object_unref (G_OBJECT(data));
 }
 
 static void
 tilda_window_dispose (GObject *obj)
 {
+       debug_enter ();
+
        TildaWindow *self = (TildaWindow *) obj;
 
        /* We don't want to run dispose twice, so just return immediately */
@@ -591,6 +659,8 @@ tilda_window_dispose (GObject *obj)
 static void
 tilda_window_finalize (GObject *obj)
 {
+       debug_enter ();
+
        TildaWindow *self = (TildaWindow *) obj;
 
        /*
@@ -609,6 +679,8 @@ static void
 tilda_window_class_init (gpointer g_class,
                                                 gpointer g_class_data)
 {
+       debug_enter ();
+
        GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
        TildaWindowClass *klass = TILDA_WINDOW_CLASS (g_class);
        GParamSpec *pspec;
@@ -624,8 +696,8 @@ tilda_window_class_init (gpointer g_class,
 
        /* Install all of the properties */
        pspec = g_param_spec_int ("number",
-                                                         "Window number",
-                                                         "Set window's number",
+                                                         _("Window number"),
+                                                         NULL,
                                                          0,            // min value
                                                          INT_MAX,      // max value
                                                          0,            // def value
@@ -636,7 +708,7 @@ tilda_window_class_init (gpointer g_class,
                                                                         pspec);
 
        pspec = g_param_spec_string ("key",
-                                                                "Window's drop-down keybinding",
+                                                                _("Window's drop-down keybinding"),
                                                                 NULL,
                                                                 NULL,
                                                                 G_PARAM_READWRITE);
@@ -646,7 +718,7 @@ tilda_window_class_init (gpointer g_class,
                                                                         pspec);
 
        pspec = g_param_spec_int ("height",
-                                                         "Window's height",
+                                                         _("Window's height"),
                                                          NULL,
                                                          0,
                                                          INT_MAX,
@@ -658,7 +730,7 @@ tilda_window_class_init (gpointer g_class,
                                                                         pspec);
 
        pspec = g_param_spec_int ("width",
-                                                         "Window's width",
+                                                         _("Window's width"),
                                                          NULL,
                                                          0,
                                                          INT_MAX,
@@ -670,7 +742,7 @@ tilda_window_class_init (gpointer g_class,
                                                                         pspec);
 
        pspec = g_param_spec_int ("x-position",
-                                                         "Window's x position",
+                                                         _("Window's x position"),
                                                          NULL,
                                                          0,
                                                          INT_MAX,
@@ -682,7 +754,7 @@ tilda_window_class_init (gpointer g_class,
                                                                         pspec);
 
        pspec = g_param_spec_int ("y-position",
-                                                         "Window's y position",
+                                                         _("Window's y position"),
                                                          NULL,
                                                          0,
                                                          INT_MAX,
@@ -694,7 +766,7 @@ tilda_window_class_init (gpointer g_class,
                                                                         pspec);
 
        pspec = g_param_spec_int ("tab-position",
-                                                         "Window's tab position",
+                                                         _("Position of window's tab bar"),
                                                          NULL,
                                                          0,
                                                          INT_MAX,
@@ -706,7 +778,7 @@ tilda_window_class_init (gpointer g_class,
                                                                         pspec);
 
        pspec = g_param_spec_int ("animation-orientation",
-                                                         "Window's animation orientation",
+                                                         _("Window's animation orientation"),
                                                          NULL,
                                                          0,
                                                          INT_MAX,
@@ -718,7 +790,7 @@ tilda_window_class_init (gpointer g_class,
                                                                         pspec);
 
        pspec = g_param_spec_int ("animation-delay",
-                                                         "Amount of time in milliseconds between animation intervals",
+                                                         _("Amount of time in milliseconds between animation intervals"),
                                                          NULL,
                                                          0,
                                                          INT_MAX,
@@ -730,7 +802,7 @@ tilda_window_class_init (gpointer g_class,
                                                                         pspec);
 
        pspec = g_param_spec_boolean ("keep-above",
-                                                                 "Keep this window above all others",
+                                                                 _("Keep this window above all others"),
                                                                  NULL,
                                                                  FALSE,
                                                                  G_PARAM_READWRITE);
@@ -740,7 +812,7 @@ tilda_window_class_init (gpointer g_class,
                                                                         pspec);
 
        pspec = g_param_spec_boolean ("skip-taskbar-hint",
-                                                                 "Hide this window in the taskbar if TRUE",
+                                                                 _("Hide this window in the taskbar if TRUE"),
                                                                  NULL,
                                                                  FALSE,
                                                                  G_PARAM_READWRITE);
@@ -750,7 +822,7 @@ tilda_window_class_init (gpointer g_class,
                                                                         pspec);
 
        pspec = g_param_spec_boolean ("stick",
-                                                                 "Display this window on all workspaces",
+                                                                 _("Display this window on all workspaces"),
                                                                  NULL,
                                                                  FALSE,
                                                                  G_PARAM_READWRITE);
@@ -760,7 +832,7 @@ tilda_window_class_init (gpointer g_class,
                                                                         pspec);
 
        pspec = g_param_spec_boolean ("hidden-at-start",
-                                                                 "Hide the window when it is first created",
+                                                                 _("Hide the window when it is first created"),
                                                                  NULL,
                                                                  FALSE,
                                                                  G_PARAM_READWRITE);
@@ -770,7 +842,7 @@ tilda_window_class_init (gpointer g_class,
                                                                         pspec);
 
        pspec = g_param_spec_boolean ("centered-horizontally",
-                                                                 "Center the window horizontally",
+                                                                 _("Center the window horizontally"),
                                                                  NULL,
                                                                  FALSE,
                                                                  G_PARAM_READWRITE);
@@ -780,7 +852,7 @@ tilda_window_class_init (gpointer g_class,
                                                                         pspec);
 
        pspec = g_param_spec_boolean ("centered-vertically",
-                                                                 "Center the window vertically",
+                                                                 _("Center the window vertically"),
                                                                  NULL,
                                                                  FALSE,
                                                                  G_PARAM_READWRITE);
@@ -796,8 +868,6 @@ tilda_window_class_init (gpointer g_class,
                                                                         TILDA_WINDOW_HAVE_REAL_TRANSPARENCY,
                                                                         pspec);
 
-       /* TODO: more properties */
-
        /* Hook the TildaWindow type into DBus */
        dbus_g_object_type_install_info (tilda_window_get_type(), &dbus_glib_tilda_window_object_info);
 }
@@ -830,34 +900,4 @@ tilda_window_get_type (void)
        return type;
 }
 
-#if 0
-
-int main (int argc, char *argv[])
-{
-       GObject *tw;
-       gint test_number = INT_MIN;
-
-       /* Initialize the GObject type system */
-       g_type_init ();
-       gtk_init (&argc, &argv);
-
-       tw = g_object_new (TILDA_TYPE_WINDOW, "number", 10, NULL);
-       g_object_get (G_OBJECT (tw), "number", &test_number, NULL);
-       g_assert (test_number == 10);
-
-       g_object_unref (G_OBJECT (tw));
-
-       tw = g_object_new (TILDA_TYPE_WINDOW, "number", 22, NULL);
-       g_object_get (G_OBJECT (tw), "number", &test_number, NULL);
-       g_assert (test_number == 22);
-
-       gtk_main ();
-
-       g_object_unref (G_OBJECT (tw));
-
-       return 0;
-}
-
-#endif
-
 /* vim: set ts=4 sts=4 sw=4 noet tw=112: */