comparison src/gtkdebug.c @ 5212:740303e8425b

[gaim-migrate @ 5582] And, er, having the actual debugging code in would be just dandy. committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Sat, 26 Apr 2003 06:46:59 +0000
parents
children 7ea282e1f615
comparison
equal deleted inserted replaced
5211:0241d6b6702d 5212:740303e8425b
1 /**
2 * @file gtkdebug.c GTK+ Debug API
3 * @ingroup gtkui
4 *
5 * gaim
6 *
7 * Copyright (C) 2002-2003, Christian Hammond <chipx86@gnupdate.org>
8 *
9 * This program is free software; you can redistribute it and/or modify
10 * it under the terms of the GNU General Public License as published by
11 * the Free Software Foundation; either version 2 of the License, or
12 * (at your option) any later version.
13 *
14 * This program is distributed in the hope that it will be useful,
15 * but WITHOUT ANY WARRANTY; without even the implied warranty of
16 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
17 * GNU General Public License for more details.
18 *
19 * You should have received a copy of the GNU General Public License
20 * along with this program; if not, write to the Free Software
21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
22 */
23 #include "gtkdebug.h"
24 #include "gaim.h"
25 #include "gtkimhtml.h"
26 #include <gtk/gtk.h>
27
28 typedef struct
29 {
30 GtkWidget *window;
31 GtkWidget *entry;
32
33 } DebugWindow;
34
35 static char debug_fg_colors[][8] = {
36 "#000000", /**< All debug levels. */
37 "#666666", /**< Blather. */
38 "#000000", /**< Information. */
39 "#660000", /**< Warnings. */
40 "#FF0000", /**< Errors. */
41 "#FF0000", /**< Fatal errors. */
42 };
43
44 static DebugWindow *debug_win = NULL;
45
46 static gint
47 debug_window_destroy(GtkWidget *w, GdkEvent *event, void *unused)
48 {
49 g_free(debug_win);
50 debug_win = NULL;
51
52 if (misc_options & OPT_MISC_DEBUG)
53 misc_options ^= OPT_MISC_DEBUG;
54
55 save_prefs();
56
57 return FALSE;
58 }
59
60 static DebugWindow *
61 debug_window_new(void)
62 {
63 DebugWindow *win;
64 GtkWidget *sw;
65
66 win = g_new0(DebugWindow, 1);
67
68 GAIM_DIALOG(win->window);
69 gtk_window_set_default_size(GTK_WINDOW(win->window), 500, 200);
70 gtk_window_set_role(GTK_WINDOW(win->window), "debug");
71 gtk_window_set_title(GTK_WINDOW(win->window), _("Debug Window"));
72
73 g_signal_connect(G_OBJECT(win->window), "delete_event",
74 G_CALLBACK(debug_window_destroy), NULL);
75
76 sw = gtk_scrolled_window_new(NULL, NULL);
77 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
78 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
79
80 win->entry = gtk_imhtml_new(NULL, NULL);
81 gaim_setup_imhtml(win->entry);
82
83 #if 0
84 win->entry = gtk_text_view_new();
85 gtk_text_view_set_cursor_visible(GTK_TEXT_VIEW(win->entry), FALSE);
86 gtk_text_view_set_editable(GTK_TEXT_VIEW(win->entry), FALSE);
87 gtk_text_view_set_wrap_mode(GTK_TEXT_VIEW(win->entry), GTK_WRAP_WORD_CHAR);
88
89 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(win->entry));
90 gtk_text_buffer_get_end_iter(buffer, &end);
91 gtk_text_buffer_create_mark(buffer, "end", &end, FALSE);
92 #endif
93
94 gtk_container_add(GTK_CONTAINER(sw), win->entry);
95 gtk_container_add(GTK_CONTAINER(win->window), sw);
96 gtk_widget_show_all(win->window);
97
98 return win;
99 }
100
101 void
102 gaim_gtk_debug_window_show(void)
103 {
104 if (debug_win == NULL)
105 debug_win = debug_window_new();
106
107 gtk_widget_show(debug_win->window);
108 }
109
110 void
111 gaim_gtk_debug_window_hide(void)
112 {
113 if (debug_win != NULL) {
114 gtk_widget_destroy(debug_win->window);
115 debug_window_destroy(NULL, NULL, NULL);
116 }
117 }
118
119 static void
120 gaim_gtk_debug_print(GaimDebugLevel level, const char *category,
121 const char *format, va_list args)
122 {
123 va_list ap;
124 gchar *esc_s, *arg_s, *cat_s, *s;
125
126 arg_s = g_strdup_vprintf(format, args);
127
128 if ((misc_options & OPT_MISC_DEBUG) && debug_win != NULL) {
129 if (category == NULL)
130 cat_s = g_strdup("");
131 else
132 cat_s = g_strdup_printf("<b>%s:</b> ", category);
133
134 esc_s = g_markup_escape_text(arg_s, -1);
135
136 s = g_strdup_printf("<font color=\"%s\">%s%s</font>",
137 debug_fg_colors[level], cat_s, esc_s);
138
139 g_free(esc_s);
140
141 if (level == GAIM_DEBUG_FATAL) {
142 gchar *temp = s;
143
144 s = g_strdup_printf("<b>%s</b>", temp);
145 g_free(temp);
146 }
147
148 g_free(cat_s);
149
150 gtk_imhtml_append_text(GTK_IMHTML(debug_win->entry), s, -1, 0);
151
152 g_free(s);
153
154 #if 0
155 GtkTextBuffer *buffer;
156 GtkTextMark *endmark;
157 GtkTextIter end;
158
159 buffer = gtk_text_view_get_buffer(GTK_TEXT_VIEW(debug_win->entry));
160 endmark = gtk_text_buffer_get_mark(buffer, "end");
161
162 gtk_text_buffer_get_iter_at_mark(buffer, &end, endmark);
163 gtk_text_buffer_insert_with_tags(buffer, &end, s, -1);
164
165 gtk_text_view_scroll_mark_onscreen(GTK_TEXT_VIEW(debug_win->entry),
166 endmark);
167 #endif
168 }
169
170 if (opt_debug)
171 g_print("%s", arg_s);
172
173 g_free(arg_s);
174 }
175
176 static GaimDebugUiOps ops =
177 {
178 gaim_gtk_debug_print
179 };
180
181 GaimDebugUiOps *
182 gaim_get_gtk_debug_ui_ops(void)
183 {
184 return &ops;
185 }
186