Mercurial > pidgin.yaz
annotate src/gtkdebug.c @ 5276:b353c171fd3c
[gaim-migrate @ 5648]
compile fix for some folk
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Thu, 01 May 2003 17:53:38 +0000 |
parents | 6afeab1955b2 |
children | 1f901484599d |
rev | line source |
---|---|
5212 | 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 | |
82 gtk_container_add(GTK_CONTAINER(sw), win->entry); | |
83 gtk_container_add(GTK_CONTAINER(win->window), sw); | |
84 gtk_widget_show_all(win->window); | |
85 | |
86 return win; | |
87 } | |
88 | |
89 void | |
90 gaim_gtk_debug_window_show(void) | |
91 { | |
92 if (debug_win == NULL) | |
93 debug_win = debug_window_new(); | |
94 | |
95 gtk_widget_show(debug_win->window); | |
96 } | |
97 | |
98 void | |
99 gaim_gtk_debug_window_hide(void) | |
100 { | |
101 if (debug_win != NULL) { | |
102 gtk_widget_destroy(debug_win->window); | |
103 debug_window_destroy(NULL, NULL, NULL); | |
104 } | |
105 } | |
106 | |
107 static void | |
108 gaim_gtk_debug_print(GaimDebugLevel level, const char *category, | |
109 const char *format, va_list args) | |
110 { | |
111 va_list ap; | |
112 gchar *esc_s, *arg_s, *cat_s, *s; | |
113 | |
114 arg_s = g_strdup_vprintf(format, args); | |
115 | |
116 if ((misc_options & OPT_MISC_DEBUG) && debug_win != NULL) { | |
117 if (category == NULL) | |
118 cat_s = g_strdup(""); | |
119 else | |
120 cat_s = g_strdup_printf("<b>%s:</b> ", category); | |
121 | |
122 esc_s = g_markup_escape_text(arg_s, -1); | |
123 | |
124 s = g_strdup_printf("<font color=\"%s\">%s%s</font>", | |
125 debug_fg_colors[level], cat_s, esc_s); | |
126 | |
127 g_free(esc_s); | |
128 | |
129 if (level == GAIM_DEBUG_FATAL) { | |
130 gchar *temp = s; | |
131 | |
132 s = g_strdup_printf("<b>%s</b>", temp); | |
133 g_free(temp); | |
134 } | |
135 | |
136 g_free(cat_s); | |
137 | |
138 gtk_imhtml_append_text(GTK_IMHTML(debug_win->entry), s, -1, 0); | |
139 | |
140 g_free(s); | |
141 } | |
142 | |
5214
7ea282e1f615
[gaim-migrate @ 5584]
Christian Hammond <chipx86@chipx86.com>
parents:
5212
diff
changeset
|
143 if (opt_debug) { |
7ea282e1f615
[gaim-migrate @ 5584]
Christian Hammond <chipx86@chipx86.com>
parents:
5212
diff
changeset
|
144 if (category == NULL) |
7ea282e1f615
[gaim-migrate @ 5584]
Christian Hammond <chipx86@chipx86.com>
parents:
5212
diff
changeset
|
145 g_print("%s", arg_s); |
7ea282e1f615
[gaim-migrate @ 5584]
Christian Hammond <chipx86@chipx86.com>
parents:
5212
diff
changeset
|
146 else |
5217
6afeab1955b2
[gaim-migrate @ 5587]
Christian Hammond <chipx86@chipx86.com>
parents:
5215
diff
changeset
|
147 g_print("%s: %s", category, arg_s); |
5214
7ea282e1f615
[gaim-migrate @ 5584]
Christian Hammond <chipx86@chipx86.com>
parents:
5212
diff
changeset
|
148 } |
5212 | 149 |
150 g_free(arg_s); | |
151 } | |
152 | |
153 static GaimDebugUiOps ops = | |
154 { | |
155 gaim_gtk_debug_print | |
156 }; | |
157 | |
158 GaimDebugUiOps * | |
159 gaim_get_gtk_debug_ui_ops(void) | |
160 { | |
161 return &ops; | |
162 } | |
163 |