Add debugging macros + use them
[tilda-gobject.git] / tilda-terminal.c
index f31e797..38a353f 100644 (file)
@@ -14,6 +14,9 @@
 static void
 tilda_terminal_dbus_register_object (TildaTerminal *tt)
 {
+       debug_enter  ();
+       debug_assert (TILDA_IS_TERMINAL(tt));
+
        gchar *object_path;
 
        // Register this object with DBus
@@ -32,6 +35,9 @@ tilda_terminal_dbus_register_object (TildaTerminal *tt)
 static gboolean
 tilda_terminal_start_shell (TildaTerminal *tt)
 {
+       debug_enter  ();
+       debug_assert (TILDA_IS_TERMINAL(tt));
+
        gint ret;
        gint argc;
        gchar **argv;
@@ -102,6 +108,10 @@ launch_default_shell:
 static void
 tilda_terminal_child_exited_cb (GtkWidget *widget, gpointer data)
 {
+       debug_enter  ();
+       debug_assert (GTK_IS_WIDGET(widget));
+       debug_assert (TILDA_IS_TERMINAL(data));
+
        TildaTerminal *self = TILDA_TERMINAL(data);
 
        /* These can stay here. They don't need to go into a header because
@@ -133,6 +143,10 @@ tilda_terminal_child_exited_cb (GtkWidget *widget, gpointer data)
 static void
 tilda_terminal_window_title_changed_cb (GtkWidget *widget, gpointer data)
 {
+       debug_enter  ();
+       debug_assert (GTK_IS_WIDGET(widget));
+       debug_assert (TILDA_IS_TERMINAL(data));
+
        TildaTerminal *self = TILDA_TERMINAL(data);
        TildaWindow *parent_window = TILDA_WINDOW(self->parent_window);
        GtkWidget *label;
@@ -168,9 +182,9 @@ tilda_terminal_window_title_changed_cb (GtkWidget *widget, gpointer data)
                        new_title = g_strdup_printf ("%s - %s", self->title, vte_title);
                        break;
 
-               case NOT_DISPLAYED:
                default:
-                       g_printerr (_("FIXME: Bad value of self->dynamic_title\n"));
+                       debug_printf ("ERROR: Bad value of self->dynamic_title\n");
+               case NOT_DISPLAYED:
                        new_title = g_strdup(self->title);
                        break;
        }
@@ -188,6 +202,11 @@ tilda_terminal_button_press_cb (GtkWidget      *widget,
                                                                GdkEventButton *event,
                                                                gpointer        data)
 {
+       debug_enter  ();
+       debug_assert (GTK_IS_WIDGET(widget));
+       debug_assert (TILDA_IS_TERMINAL(data));
+       debug_printf ("event->button = %d\n", event->button);
+
        GError *error = NULL;
        TildaTerminal *self = TILDA_TERMINAL(data);
        VteTerminal *terminal = VTE_TERMINAL(self->vte_term);
@@ -216,14 +235,12 @@ tilda_terminal_button_press_cb (GtkWidget      *widget,
                        /* Check if we can launch a web browser, and do so if possible */
                        if ((event->state & GDK_CONTROL_MASK) && match != NULL)
                        {
-#if DEBUG
-                               g_print ("Got a Ctrl+Left Click -- Matched: `%s' (%d)\n", match, tag);
-#endif
                                web_browser_cmd = g_strescape (self->web_browser, NULL);
                                cmd = g_strdup_printf ("%s %s", web_browser_cmd, match);
-#if DEBUG
-                               g_print ("Launching command: `%s'\n", cmd);
-#endif
+
+                               debug_printf ("Got a Ctrl+Left-Click -- match: '%s' tag: %d\n", match, tag);
+                               debug_printf ("Launching command: '%s'\n", cmd);
+
                                ret = g_spawn_command_line_async(cmd, &error);
 
                                /* Check that the command launched */
@@ -255,6 +272,9 @@ tilda_terminal_button_press_cb (GtkWidget      *widget,
 static void
 tilda_terminal_set_transparent (TildaTerminal *self)
 {
+       debug_enter  ();
+       debug_assert (TILDA_IS_TERMINAL(self));
+
        TildaWindow *parent_window = TILDA_WINDOW(self->parent_window);
        gdouble temp;
 
@@ -285,6 +305,9 @@ tilda_terminal_set_transparent (TildaTerminal *self)
 static void
 tilda_terminal_set_scrollbar_position (TildaTerminal *self)
 {
+       debug_enter  ();
+       debug_assert (TILDA_IS_TERMINAL(self));
+
        enum scrollbar_positions { DISABLED, LEFT, RIGHT };
        switch (self->scrollbar_position)
        {
@@ -298,8 +321,9 @@ tilda_terminal_set_scrollbar_position (TildaTerminal *self)
                        gtk_widget_show (self->scrollbar);
                        break;
 
-               case DISABLED:
                default:
+                       debug_printf ("ERROR: Bad scrollbar position\n");
+               case DISABLED:
                        gtk_widget_hide (self->scrollbar);
                        break;
        }
@@ -349,6 +373,8 @@ static void
 tilda_terminal_instance_init (GTypeInstance *instance,
                                                          gpointer       g_class)
 {
+       debug_enter ();
+
        TildaTerminal *self = (TildaTerminal *) instance;
 
        /* Initialize instance members and allocate any necessary memory here.
@@ -373,32 +399,31 @@ tilda_terminal_set_property (GObject      *object,
 
                case TILDA_TERMINAL_NUMBER:
                        self->number = g_value_get_int (value);
-                       g_print ("terminal number: %d\n", self->number);
+                       debug_printf ("terminal number: %d\n", self->number);
                        break;
 
                case TILDA_TERMINAL_WINDOW_NUMBER:
                        self->window_number = g_value_get_int (value);
-                       g_print ("terminal parent window number: %d\n", self->window_number);
+                       debug_printf ("terminal parent window number: %d\n", self->window_number);
                        break;
 
                case TILDA_TERMINAL_TW:
                        self->parent_window = g_value_get_pointer (value);
-                       g_print ("terminal parent window: 0x%x\n", self->parent_window);
-                       g_print ("terminal parent window number (direct): %d\n", TILDA_WINDOW(self->parent_window)->number);
+                       debug_printf ("terminal parent window: 0x%x\n", self->parent_window);
                        break;
 
                case TILDA_TERMINAL_BACKGROUND_IMAGE:
                        g_free (self->background_image);
                        self->background_image = g_value_dup_string (value);
                        vte_terminal_set_background_image_file (VTE_TERMINAL(self->vte_term), self->background_image);
-                       g_print ("terminal back img: %s\n", self->background_image);
+                       debug_printf ("terminal back img: %s\n", self->background_image);
                        break;
 
                case TILDA_TERMINAL_SHELL:
                        g_free (self->shell);
                        self->shell = g_value_dup_string (value);
                        tilda_terminal_start_shell (self);
-                       g_print ("terminal shell: %s\n", self->shell);
+                       debug_printf ("terminal shell: %s\n", self->shell);
                        break;
 
                case TILDA_TERMINAL_FONT:
@@ -407,83 +432,83 @@ tilda_terminal_set_property (GObject      *object,
                        vte_terminal_set_font_from_string_full (VTE_TERMINAL(self->vte_term),
                                                                                                        self->font,
                                                                                                        self->antialiased);
-                       g_print ("terminal font: %s\n", self->font);
+                       debug_printf ("terminal font: %s\n", self->font);
                        break;
 
                case TILDA_TERMINAL_TITLE:
                        g_free (self->title);
                        self->title = g_value_dup_string (value);
-                       g_print ("terminal title: %s\n", self->title);
+                       debug_printf ("terminal title: %s\n", self->title);
                        break;
 
                case TILDA_TERMINAL_WORKING_DIRECTORY:
                        g_free (self->working_directory);
                        self->working_directory = g_value_dup_string (value);
-                       g_print ("terminal wrk dir: %s\n", self->working_directory);
+                       debug_printf ("terminal wrk dir: %s\n", self->working_directory);
                        break;
 
                case TILDA_TERMINAL_WEB_BROWSER:
                        g_free (self->web_browser);
                        self->web_browser = g_value_dup_string (value);
-                       g_print ("terminal web browser: %s\n", self->web_browser);
+                       debug_printf ("terminal web browser: %s\n", self->web_browser);
                        break;
 
                case TILDA_TERMINAL_SCROLLBACK_LINES:
                        self->scrollback_lines = g_value_get_int (value);
                        vte_terminal_set_scrollback_lines (VTE_TERMINAL(self->vte_term), self->scrollback_lines);
-                       g_print ("terminal scrollback lines: %d\n", self->scrollback_lines);
+                       debug_printf ("terminal scrollback lines: %d\n", self->scrollback_lines);
                        break;
 
                case TILDA_TERMINAL_TRANSPARENCY_PERCENT:
                        self->transparency_percent = g_value_get_int (value);
                        tilda_terminal_set_transparent (self);
-                       g_print ("terminal transp percent: %d\n", self->transparency_percent);
+                       debug_printf ("terminal transp percent: %d\n", self->transparency_percent);
                        break;
 
                case TILDA_TERMINAL_BACKSPACE_BINDING:
                        self->backspace_binding = g_value_get_int (value);
                        vte_terminal_set_backspace_binding (VTE_TERMINAL(self->vte_term), self->backspace_binding);
-                       g_print ("terminal backspace key: %d\n", self->backspace_binding);
+                       debug_printf ("terminal backspace key: %d\n", self->backspace_binding);
                        break;
 
                case TILDA_TERMINAL_DELETE_BINDING:
                        self->delete_binding = g_value_get_int (value);
                        vte_terminal_set_delete_binding (VTE_TERMINAL(self->vte_term), self->delete_binding);
-                       g_print ("terminal delete key: %d\n", self->delete_binding);
+                       debug_printf ("terminal delete key: %d\n", self->delete_binding);
                        break;
 
                case TILDA_TERMINAL_DYNAMIC_TITLE:
                        self->dynamic_title = g_value_get_int (value);
-                       g_print ("terminal dynamic title: %d\n", self->dynamic_title);
+                       debug_printf ("terminal dynamic title: %d\n", self->dynamic_title);
                        break;
 
                case TILDA_TERMINAL_EXIT_ACTION:
                        self->exit_action = g_value_get_int (value);
-                       g_print ("terminal exit action: %d\n", self->exit_action);
+                       debug_printf ("terminal exit action: %d\n", self->exit_action);
                        break;
 
                case TILDA_TERMINAL_SCROLLBAR_POSITION:
                        self->scrollbar_position = g_value_get_int (value);
                        tilda_terminal_set_scrollbar_position (self);
-                       g_print ("terminal scrollbar position: %d\n", self->scrollbar_position);
+                       debug_printf ("terminal scrollbar position: %d\n", self->scrollbar_position);
                        break;
 
                case TILDA_TERMINAL_SCROLL_BACKGROUND:
                        self->scroll_background = g_value_get_boolean (value);
                        vte_terminal_set_scroll_background (VTE_TERMINAL(self->vte_term), self->scroll_background);
-                       g_print ("terminal scroll background: %d\n", self->scroll_background);
+                       debug_printf ("terminal scroll background: %d\n", self->scroll_background);
                        break;
 
                case TILDA_TERMINAL_SCROLL_ON_OUTPUT:
                        self->scroll_on_output = g_value_get_boolean (value);
                        vte_terminal_set_scroll_on_output (VTE_TERMINAL(self->vte_term), self->scroll_on_output);
-                       g_print ("terminal scroll on output: %d\n", self->scroll_on_output);
+                       debug_printf ("terminal scroll on output: %d\n", self->scroll_on_output);
                        break;
 
                case TILDA_TERMINAL_SCROLL_ON_KEYSTROKE:
                        self->scroll_on_keystroke = g_value_get_boolean (value);
                        vte_terminal_set_scroll_on_keystroke (VTE_TERMINAL(self->vte_term), self->scroll_on_keystroke);
-                       g_print ("terminal scroll on keystroke: %d\n", self->scroll_on_keystroke);
+                       debug_printf ("terminal scroll on keystroke: %d\n", self->scroll_on_keystroke);
                        break;
 
                case TILDA_TERMINAL_ANTIALIASED:
@@ -491,43 +516,43 @@ tilda_terminal_set_property (GObject      *object,
                        vte_terminal_set_font_from_string_full (VTE_TERMINAL(self->vte_term),
                                                                                                        self->font,
                                                                                                        self->antialiased);
-                       g_print ("terminal antialiased: %d\n", self->antialiased);
+                       debug_printf ("terminal antialiased: %d\n", self->antialiased);
                        break;
 
                case TILDA_TERMINAL_ALLOW_BOLD_TEXT:
                        self->allow_bold_text = g_value_get_boolean (value);
                        vte_terminal_set_allow_bold (VTE_TERMINAL(self->vte_term), self->allow_bold_text);
-                       g_print ("terminal allow bold text: %d\n", self->allow_bold_text);
+                       debug_printf ("terminal allow bold text: %d\n", self->allow_bold_text);
                        break;
 
                case TILDA_TERMINAL_CURSOR_BLINKS:
                        self->cursor_blinks = g_value_get_boolean (value);
                        vte_terminal_set_cursor_blinks (VTE_TERMINAL(self->vte_term), self->cursor_blinks);
-                       g_print ("terminal cursor blinks: %d\n", self->cursor_blinks);
+                       debug_printf ("terminal cursor blinks: %d\n", self->cursor_blinks);
                        break;
 
                case TILDA_TERMINAL_AUDIBLE_BELL:
                        self->audible_bell = g_value_get_boolean (value);
                        vte_terminal_set_audible_bell (VTE_TERMINAL(self->vte_term), self->audible_bell);
-                       g_print ("terminal audible bell: %d\n", self->audible_bell);
+                       debug_printf ("terminal audible bell: %d\n", self->audible_bell);
                        break;
 
                case TILDA_TERMINAL_VISIBLE_BELL:
                        self->visible_bell = g_value_get_boolean (value);
                        vte_terminal_set_visible_bell (VTE_TERMINAL(self->vte_term), self->visible_bell);
-                       g_print ("terminal visible bell: %d\n", self->visible_bell);
+                       debug_printf ("terminal visible bell: %d\n", self->visible_bell);
                        break;
 
                case TILDA_TERMINAL_DOUBLE_BUFFERED:
                        self->double_buffered = g_value_get_boolean (value);
                        gtk_widget_set_double_buffered (GTK_WIDGET(self->vte_term), self->double_buffered);
-                       g_print ("terminal double buffered: %d\n", self->double_buffered);
+                       debug_printf ("terminal double buffered: %d\n", self->double_buffered);
                        break;
 
                case TILDA_TERMINAL_MOUSE_AUTOHIDE:
                        self->mouse_autohide = g_value_get_boolean (value);
                        vte_terminal_set_mouse_autohide (VTE_TERMINAL(self->vte_term), self->mouse_autohide);
-                       g_print ("terminal mouse autohide: %d\n", self->mouse_autohide);
+                       debug_printf ("terminal mouse autohide: %d\n", self->mouse_autohide);
                        break;
 
                default:
@@ -662,6 +687,8 @@ tilda_terminal_constructor (GType                  type,
                                                        guint                  n_construct_properties,
                                                        GObjectConstructParam *construct_properties)
 {
+       debug_enter ();
+
        GObject *obj;
        TildaTerminal *self;
        gint ret;
@@ -711,6 +738,8 @@ tilda_terminal_constructor (GType                  type,
 static void
 tilda_terminal_dispose (GObject *obj)
 {
+       debug_enter ();
+
        TildaTerminal *self = (TildaTerminal *) obj;
 
        /* We don't want to run dispose twice, so just return immediately */
@@ -733,6 +762,8 @@ tilda_terminal_dispose (GObject *obj)
 static void
 tilda_terminal_finalize (GObject *obj)
 {
+       debug_enter ();
+
        TildaTerminal *self = (TildaTerminal *) obj;
 
        /*
@@ -756,6 +787,8 @@ static void
 tilda_terminal_class_init (gpointer g_class,
                                                   gpointer g_class_data)
 {
+       debug_enter ();
+
        GObjectClass *gobject_class = G_OBJECT_CLASS (g_class);
        TildaTerminalClass *klass = TILDA_TERMINAL_CLASS (g_class);
        GParamSpec *pspec;