# HG changeset patch # User Christian Hammond # Date 1051339619 0 # Node ID 740303e8425bdb07c7c3e24e9b67e47b6121c6f6 # Parent 0241d6b6702db090151cce9d76605bea1e1f3d01 [gaim-migrate @ 5582] And, er, having the actual debugging code in would be just dandy. committer: Tailor Script diff -r 0241d6b6702d -r 740303e8425b src/debug.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/debug.c Sat Apr 26 06:46:59 2003 +0000 @@ -0,0 +1,80 @@ +/** + * @file debug.c Debug API + * @ingroup core + * + * gaim + * + * Copyright (C) 2002-2003, Christian Hammond + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "debug.h" +#include +#include + +static GaimDebugUiOps *debug_ui_ops = NULL; + +void +gaim_debug_vargs(GaimDebugLevel level, const char *category, + const char *format, va_list args) +{ + GaimDebugUiOps *ops; + + g_return_if_fail(level != GAIM_DEBUG_ALL); + g_return_if_fail(format != NULL); + + ops = gaim_get_debug_ui_ops(); + + if (ops != NULL && ops->print != NULL) + ops->print(level, category, format, args); +} + +void +gaim_debug(GaimDebugLevel level, const char *category, + const char *format, ...) +{ + va_list args; + + g_return_if_fail(level != GAIM_DEBUG_ALL); + g_return_if_fail(format != NULL); + + va_start(args, format); + gaim_debug_vargs(level, category, format, args); + va_end(args); +} + +void +debug_printf(const char *format, ...) +{ + va_list args; + + g_return_if_fail(format != NULL); + + va_start(args, format); + gaim_debug_vargs(GAIM_DEBUG_INFO, NULL, format, args); + va_end(args); +} + +void +gaim_set_debug_ui_ops(GaimDebugUiOps *ops) +{ + debug_ui_ops = ops; +} + +GaimDebugUiOps * +gaim_get_debug_ui_ops(void) +{ + return debug_ui_ops; +} diff -r 0241d6b6702d -r 740303e8425b src/debug.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/debug.h Sat Apr 26 06:46:59 2003 +0000 @@ -0,0 +1,105 @@ +/** + * @file debug.h Debug API + * @ingroup core + * + * gaim + * + * Copyright (C) 2002-2003, Christian Hammond + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef _GAIM_DEBUG_H_ +#define _GAIM_DEBUG_H_ + +#include + +/** + * Debug levels. + */ +typedef enum +{ + GAIM_DEBUG_ALL = 0, /**< All debug levels. */ + GAIM_DEBUG_MISC, /**< General chatter. */ + GAIM_DEBUG_INFO, /**< General operation Information. */ + GAIM_DEBUG_WARNING, /**< Warnings. */ + GAIM_DEBUG_ERROR, /**< Errors. */ + GAIM_DEBUG_FATAL /**< Fatal errors. */ + +} GaimDebugLevel; + +/** + * Debug UI operations. + */ +typedef struct +{ + void (*print)(GaimDebugLevel level, const char *category, + const char *format, va_list args); + +} GaimDebugUiOps; + +/** + * Outputs debug information. + * + * This differs from gaim_debug() in that it takes a va_list. + * + * @param level The debug level. + * @param category The category (or @c NULL). + * @param format The format string. + * @param args The format parameters. + * + * @see gaim_debug() + */ +void gaim_debug_vargs(GaimDebugLevel level, const char *category, + const char *format, va_list args); + +/** + * Outputs debug information. + * + * @param level The debug level. + * @param category The category (or @c NULL). + * @param format The format string. + */ +void gaim_debug(GaimDebugLevel level, const char *category, + const char *format, ...); + +/** + * Outputs debug information. + * + * @deprecated This has been replaced with gaim_debug(), and will be + * removed in a future release. + * + * @param fmt The format string. + * + * @see gaim_debug() + */ +void debug_printf(const char *fmt, ...); + +/** + * Sets the UI operations structure to be used when outputting debug + * information. + * + * @param ops The UI operations structure. + */ +void gaim_set_debug_ui_ops(GaimDebugUiOps *ops); + +/** + * Returns the UI operations structure used when outputting debug + * information. + * + * @return The UI operations structure in use. + */ +GaimDebugUiOps *gaim_get_debug_ui_ops(void); + +#endif /* _GAIM_DEBUG_H_ */ diff -r 0241d6b6702d -r 740303e8425b src/gtkdebug.c --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gtkdebug.c Sat Apr 26 06:46:59 2003 +0000 @@ -0,0 +1,186 @@ +/** + * @file gtkdebug.c GTK+ Debug API + * @ingroup gtkui + * + * gaim + * + * Copyright (C) 2002-2003, Christian Hammond + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#include "gtkdebug.h" +#include "gaim.h" +#include "gtkimhtml.h" +#include + +typedef struct +{ + GtkWidget *window; + GtkWidget *entry; + +} DebugWindow; + +static char debug_fg_colors[][8] = { + "#000000", /**< All debug levels. */ + "#666666", /**< Blather. */ + "#000000", /**< Information. */ + "#660000", /**< Warnings. */ + "#FF0000", /**< Errors. */ + "#FF0000", /**< Fatal errors. */ +}; + +static DebugWindow *debug_win = NULL; + +static gint +debug_window_destroy(GtkWidget *w, GdkEvent *event, void *unused) +{ + g_free(debug_win); + debug_win = NULL; + + if (misc_options & OPT_MISC_DEBUG) + misc_options ^= OPT_MISC_DEBUG; + + save_prefs(); + + return FALSE; +} + +static DebugWindow * +debug_window_new(void) +{ + DebugWindow *win; + GtkWidget *sw; + + win = g_new0(DebugWindow, 1); + + GAIM_DIALOG(win->window); + gtk_window_set_default_size(GTK_WINDOW(win->window), 500, 200); + gtk_window_set_role(GTK_WINDOW(win->window), "debug"); + gtk_window_set_title(GTK_WINDOW(win->window), _("Debug Window")); + + g_signal_connect(G_OBJECT(win->window), "delete_event", + G_CALLBACK(debug_window_destroy), NULL); + + sw = gtk_scrolled_window_new(NULL, NULL); + gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), + GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); + + win->entry = gtk_imhtml_new(NULL, NULL); + gaim_setup_imhtml(win->entry); + +#if 0 + win->entry = gtk_text_view_new(); + gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(win->entry), FALSE); + gtk_text_view_set_editable(GTK_TEXT_VIEW(win->entry), FALSE); + gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(win->entry), GTK_WRAP_WORD_CHAR); + + buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(win->entry)); + gtk_text_buffer_get_end_iter(buffer, &end); + gtk_text_buffer_create_mark(buffer, "end", &end, FALSE); +#endif + + gtk_container_add(GTK_CONTAINER(sw), win->entry); + gtk_container_add(GTK_CONTAINER(win->window), sw); + gtk_widget_show_all(win->window); + + return win; +} + +void +gaim_gtk_debug_window_show(void) +{ + if (debug_win == NULL) + debug_win = debug_window_new(); + + gtk_widget_show(debug_win->window); +} + +void +gaim_gtk_debug_window_hide(void) +{ + if (debug_win != NULL) { + gtk_widget_destroy(debug_win->window); + debug_window_destroy(NULL, NULL, NULL); + } +} + +static void +gaim_gtk_debug_print(GaimDebugLevel level, const char *category, + const char *format, va_list args) +{ + va_list ap; + gchar *esc_s, *arg_s, *cat_s, *s; + + arg_s = g_strdup_vprintf(format, args); + + if ((misc_options & OPT_MISC_DEBUG) && debug_win != NULL) { + if (category == NULL) + cat_s = g_strdup(""); + else + cat_s = g_strdup_printf("%s: ", category); + + esc_s = g_markup_escape_text(arg_s, -1); + + s = g_strdup_printf("%s%s", + debug_fg_colors[level], cat_s, esc_s); + + g_free(esc_s); + + if (level == GAIM_DEBUG_FATAL) { + gchar *temp = s; + + s = g_strdup_printf("%s", temp); + g_free(temp); + } + + g_free(cat_s); + + gtk_imhtml_append_text(GTK_IMHTML(debug_win->entry), s, -1, 0); + + g_free(s); + +#if 0 + GtkTextBuffer *buffer; + GtkTextMark *endmark; + GtkTextIter end; + + buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(debug_win->entry)); + endmark = gtk_text_buffer_get_mark(buffer, "end"); + + gtk_text_buffer_get_iter_at_mark(buffer, &end, endmark); + gtk_text_buffer_insert_with_tags(buffer, &end, s, -1); + + gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(debug_win->entry), + endmark); +#endif + } + + if (opt_debug) + g_print("%s", arg_s); + + g_free(arg_s); +} + +static GaimDebugUiOps ops = +{ + gaim_gtk_debug_print +}; + +GaimDebugUiOps * +gaim_get_gtk_debug_ui_ops(void) +{ + return &ops; +} + diff -r 0241d6b6702d -r 740303e8425b src/gtkdebug.h --- /dev/null Thu Jan 01 00:00:00 1970 +0000 +++ b/src/gtkdebug.h Sat Apr 26 06:46:59 2003 +0000 @@ -0,0 +1,45 @@ +/** + * @file gtkdebug.c GTK+ Debug API + * @ingroup gtkui + * + * gaim + * + * Copyright (C) 2002-2003, Christian Hammond + * + * This program is free software; you can redistribute it and/or modify + * it under the terms of the GNU General Public License as published by + * the Free Software Foundation; either version 2 of the License, or + * (at your option) any later version. + * + * This program is distributed in the hope that it will be useful, + * but WITHOUT ANY WARRANTY; without even the implied warranty of + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the + * GNU General Public License for more details. + * + * You should have received a copy of the GNU General Public License + * along with this program; if not, write to the Free Software + * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA + */ +#ifndef _GAIM_GTK_DEBUG_H_ +#define _GAIM_GTK_DEBUG_H_ + +#include "debug.h" + +/** + * Shows the debug window. + */ +void gaim_gtk_debug_window_show(void); + +/** + * Hides the debug window. + */ +void gaim_gtk_debug_window_hide(void); + +/** + * Returns the UI operations structure for GTK debug output. + * + * @return The GTK UI debug operations structure. + */ +GaimDebugUiOps *gaim_get_gtk_debug_ui_ops(void); + +#endif /* _GAIM_GTK_DEBUG_H_ */