Mercurial > pidgin.yaz
annotate finch/gntdebug.c @ 16183:8cf53d7a0887
Update the Doxygen signals documentation to match the new struct names.
author | Richard Laager <rlaager@wiktel.com> |
---|---|
date | Mon, 16 Apr 2007 00:50:57 +0000 |
parents | ab3f93232a2d |
children | 0f0832c13fcb |
rev | line source |
---|---|
15818 | 1 /** |
2 * @file gntdebug.c GNT Debug API | |
3 * @ingroup gntui | |
4 * | |
15871
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15823
diff
changeset
|
5 * finch |
15818 | 6 * |
15871
66dff3dfdea6
Re-sed the copyright notices so they don't all talk about Purple.
Richard Laager <rlaager@wiktel.com>
parents:
15823
diff
changeset
|
7 * Finch is the legal property of its developers, whose names are too numerous |
15818 | 8 * to list here. Please refer to the COPYRIGHT file distributed with this |
9 * source distribution. | |
10 * | |
11 * This program is free software; you can redistribute it and/or modify | |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
25 #include <gnt.h> | |
26 #include <gntbox.h> | |
27 #include <gnttextview.h> | |
28 #include <gntbutton.h> | |
29 #include <gntcheckbox.h> | |
30 #include <gntline.h> | |
31 | |
32 #include "gntdebug.h" | |
15823 | 33 #include "finch.h" |
15818 | 34 #include "util.h" |
35 | |
36 #include <stdio.h> | |
37 #include <string.h> | |
38 | |
15823 | 39 #define PREF_ROOT "/purple/gnt/debug" |
15818 | 40 |
41 static struct | |
42 { | |
43 GntWidget *window; | |
44 GntWidget *tview; | |
45 gboolean paused; | |
46 gboolean timestamps; | |
47 } debug; | |
48 | |
49 static void | |
15823 | 50 finch_debug_print(PurpleDebugLevel level, const char *category, |
15818 | 51 const char *args) |
52 { | |
53 if (debug.window && !debug.paused) | |
54 { | |
55 int pos = gnt_text_view_get_lines_below(GNT_TEXT_VIEW(debug.tview)); | |
56 GntTextFormatFlags flag = GNT_TEXT_FLAG_NORMAL; | |
57 | |
58 if (debug.timestamps) { | |
59 const char *mdate; | |
60 time_t mtime = time(NULL); | |
15823 | 61 mdate = purple_utf8_strftime("%H:%M:%S ", localtime(&mtime)); |
15818 | 62 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview), |
63 mdate, flag); | |
64 } | |
65 | |
66 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview), | |
67 category, GNT_TEXT_FLAG_BOLD); | |
68 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview), | |
69 ": ", GNT_TEXT_FLAG_BOLD); | |
70 | |
71 switch (level) | |
72 { | |
15823 | 73 case PURPLE_DEBUG_WARNING: |
15818 | 74 flag |= GNT_TEXT_FLAG_UNDERLINE; |
15823 | 75 case PURPLE_DEBUG_ERROR: |
76 case PURPLE_DEBUG_FATAL: | |
15818 | 77 flag |= GNT_TEXT_FLAG_BOLD; |
78 break; | |
79 default: | |
80 break; | |
81 } | |
82 | |
83 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview), args, flag); | |
84 if (pos <= 1) | |
85 gnt_text_view_scroll(GNT_TEXT_VIEW(debug.tview), 0); | |
86 } | |
87 } | |
88 | |
15985
6dc5dc83a61b
Add a whimpy ui op to the debug API that returns TRUE if debugging
Mark Doliner <mark@kingant.net>
parents:
15871
diff
changeset
|
89 static gboolean |
6dc5dc83a61b
Add a whimpy ui op to the debug API that returns TRUE if debugging
Mark Doliner <mark@kingant.net>
parents:
15871
diff
changeset
|
90 finch_debug_is_enabled(PurpleDebugLevel level, const char *category) |
6dc5dc83a61b
Add a whimpy ui op to the debug API that returns TRUE if debugging
Mark Doliner <mark@kingant.net>
parents:
15871
diff
changeset
|
91 { |
6dc5dc83a61b
Add a whimpy ui op to the debug API that returns TRUE if debugging
Mark Doliner <mark@kingant.net>
parents:
15871
diff
changeset
|
92 return debug.window && !debug.paused; |
6dc5dc83a61b
Add a whimpy ui op to the debug API that returns TRUE if debugging
Mark Doliner <mark@kingant.net>
parents:
15871
diff
changeset
|
93 } |
6dc5dc83a61b
Add a whimpy ui op to the debug API that returns TRUE if debugging
Mark Doliner <mark@kingant.net>
parents:
15871
diff
changeset
|
94 |
15823 | 95 static PurpleDebugUiOps uiops = |
15818 | 96 { |
97 finch_debug_print, | |
15985
6dc5dc83a61b
Add a whimpy ui op to the debug API that returns TRUE if debugging
Mark Doliner <mark@kingant.net>
parents:
15871
diff
changeset
|
98 finch_debug_is_enabled |
15818 | 99 }; |
100 | |
15823 | 101 PurpleDebugUiOps *finch_debug_get_ui_ops() |
15818 | 102 { |
103 return &uiops; | |
104 } | |
105 | |
106 static void | |
107 reset_debug_win(GntWidget *w, gpointer null) | |
108 { | |
109 debug.window = debug.tview = NULL; | |
110 } | |
111 | |
112 static void | |
113 clear_debug_win(GntWidget *w, GntTextView *tv) | |
114 { | |
115 gnt_text_view_clear(tv); | |
116 } | |
117 | |
118 static void | |
119 print_stderr(const char *string) | |
120 { | |
121 g_printerr("%s", string); | |
122 } | |
123 | |
124 static void | |
125 suppress_error_messages(const char *message) | |
126 {} | |
127 | |
128 static void | |
129 toggle_pause(GntWidget *w, gpointer n) | |
130 { | |
131 debug.paused = !debug.paused; | |
132 } | |
133 | |
134 static void | |
135 toggle_timestamps(GntWidget *w, gpointer n) | |
136 { | |
137 debug.timestamps = !debug.timestamps; | |
15823 | 138 purple_prefs_set_bool("/core/debug/timestamps", debug.timestamps); |
15818 | 139 } |
140 | |
141 /* Xerox */ | |
142 static void | |
15823 | 143 purple_glib_log_handler(const gchar *domain, GLogLevelFlags flags, |
15818 | 144 const gchar *msg, gpointer user_data) |
145 { | |
15823 | 146 PurpleDebugLevel level; |
15818 | 147 char *new_msg = NULL; |
148 char *new_domain = NULL; | |
149 | |
150 if ((flags & G_LOG_LEVEL_ERROR) == G_LOG_LEVEL_ERROR) | |
15823 | 151 level = PURPLE_DEBUG_ERROR; |
15818 | 152 else if ((flags & G_LOG_LEVEL_CRITICAL) == G_LOG_LEVEL_CRITICAL) |
15823 | 153 level = PURPLE_DEBUG_FATAL; |
15818 | 154 else if ((flags & G_LOG_LEVEL_WARNING) == G_LOG_LEVEL_WARNING) |
15823 | 155 level = PURPLE_DEBUG_WARNING; |
15818 | 156 else if ((flags & G_LOG_LEVEL_MESSAGE) == G_LOG_LEVEL_MESSAGE) |
15823 | 157 level = PURPLE_DEBUG_INFO; |
15818 | 158 else if ((flags & G_LOG_LEVEL_INFO) == G_LOG_LEVEL_INFO) |
15823 | 159 level = PURPLE_DEBUG_INFO; |
15818 | 160 else if ((flags & G_LOG_LEVEL_DEBUG) == G_LOG_LEVEL_DEBUG) |
15823 | 161 level = PURPLE_DEBUG_MISC; |
15818 | 162 else |
163 { | |
15823 | 164 purple_debug_warning("gntdebug", |
15818 | 165 "Unknown glib logging level in %d\n", flags); |
166 | |
15823 | 167 level = PURPLE_DEBUG_MISC; /* This will never happen. */ |
15818 | 168 } |
169 | |
170 if (msg != NULL) | |
15823 | 171 new_msg = purple_utf8_try_convert(msg); |
15818 | 172 |
173 if (domain != NULL) | |
15823 | 174 new_domain = purple_utf8_try_convert(domain); |
15818 | 175 |
176 if (new_msg != NULL) | |
177 { | |
15823 | 178 purple_debug(level, (new_domain != NULL ? new_domain : "g_log"), |
15818 | 179 "%s\n", new_msg); |
180 | |
181 g_free(new_msg); | |
182 } | |
183 | |
184 g_free(new_domain); | |
185 } | |
186 | |
187 static void | |
188 size_changed_cb(GntWidget *widget, int oldw, int oldh) | |
189 { | |
190 int w, h; | |
191 gnt_widget_get_size(widget, &w, &h); | |
15823 | 192 purple_prefs_set_int(PREF_ROOT "/size/width", w); |
193 purple_prefs_set_int(PREF_ROOT "/size/height", h); | |
15818 | 194 } |
195 | |
196 void finch_debug_window_show() | |
197 { | |
198 debug.paused = FALSE; | |
15823 | 199 debug.timestamps = purple_prefs_get_bool("/core/debug/timestamps"); |
15818 | 200 if (debug.window == NULL) |
201 { | |
202 GntWidget *wid, *box; | |
203 debug.window = gnt_vbox_new(FALSE); | |
204 gnt_box_set_toplevel(GNT_BOX(debug.window), TRUE); | |
205 gnt_box_set_title(GNT_BOX(debug.window), _("Debug Window")); | |
206 gnt_box_set_pad(GNT_BOX(debug.window), 0); | |
207 gnt_box_set_alignment(GNT_BOX(debug.window), GNT_ALIGN_MID); | |
208 | |
209 debug.tview = gnt_text_view_new(); | |
210 gnt_box_add_widget(GNT_BOX(debug.window), debug.tview); | |
211 gnt_widget_set_size(debug.tview, | |
15823 | 212 purple_prefs_get_int(PREF_ROOT "/size/width"), |
213 purple_prefs_get_int(PREF_ROOT "/size/height")); | |
15818 | 214 g_signal_connect(G_OBJECT(debug.tview), "size_changed", G_CALLBACK(size_changed_cb), NULL); |
215 | |
216 gnt_box_add_widget(GNT_BOX(debug.window), gnt_line_new(FALSE)); | |
217 | |
218 box = gnt_hbox_new(FALSE); | |
219 gnt_box_set_alignment(GNT_BOX(box), GNT_ALIGN_MID); | |
220 gnt_box_set_fill(GNT_BOX(box), FALSE); | |
221 | |
222 /* XXX: Setting the GROW_Y for the following widgets don't make sense. But right now | |
223 * it's necessary to make the width of the debug window resizable ... like I said, | |
224 * it doesn't make sense. The bug is likely in the packing in gntbox.c. | |
225 */ | |
226 wid = gnt_button_new(_("Clear")); | |
227 g_signal_connect(G_OBJECT(wid), "activate", G_CALLBACK(clear_debug_win), debug.tview); | |
228 GNT_WIDGET_SET_FLAGS(wid, GNT_WIDGET_GROW_Y); | |
229 gnt_box_add_widget(GNT_BOX(box), wid); | |
230 | |
231 wid = gnt_check_box_new(_("Pause")); | |
232 g_signal_connect(G_OBJECT(wid), "toggled", G_CALLBACK(toggle_pause), NULL); | |
233 GNT_WIDGET_SET_FLAGS(wid, GNT_WIDGET_GROW_Y); | |
234 gnt_box_add_widget(GNT_BOX(box), wid); | |
235 | |
236 wid = gnt_check_box_new(_("Timestamps")); | |
237 gnt_check_box_set_checked(GNT_CHECK_BOX(wid), debug.timestamps); | |
238 g_signal_connect(G_OBJECT(wid), "toggled", G_CALLBACK(toggle_timestamps), NULL); | |
239 GNT_WIDGET_SET_FLAGS(wid, GNT_WIDGET_GROW_Y); | |
240 gnt_box_add_widget(GNT_BOX(box), wid); | |
241 | |
242 gnt_box_add_widget(GNT_BOX(debug.window), box); | |
243 GNT_WIDGET_SET_FLAGS(box, GNT_WIDGET_GROW_Y); | |
244 | |
245 gnt_widget_set_name(debug.window, "debug-window"); | |
246 | |
247 g_signal_connect(G_OBJECT(debug.window), "destroy", G_CALLBACK(reset_debug_win), NULL); | |
16124
ab3f93232a2d
Add a utility function to assist scrolling in a textview.
Sadrul Habib Chowdhury <imadil@gmail.com>
parents:
15985
diff
changeset
|
248 gnt_text_view_attach_scroll_widget(GNT_TEXT_VIEW(debug.tview), debug.window); |
15818 | 249 } |
250 | |
251 gnt_widget_show(debug.window); | |
252 } | |
253 | |
254 static gboolean | |
255 start_with_debugwin(gpointer null) | |
256 { | |
257 finch_debug_window_show(); | |
258 return FALSE; | |
259 } | |
260 | |
261 void finch_debug_init() | |
262 { | |
263 /* Xerox */ | |
264 #define REGISTER_G_LOG_HANDLER(name) \ | |
265 g_log_set_handler((name), G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL \ | |
266 | G_LOG_FLAG_RECURSION, \ | |
15823 | 267 purple_glib_log_handler, NULL) |
15818 | 268 |
269 /* Register the glib log handlers. */ | |
270 REGISTER_G_LOG_HANDLER(NULL); | |
271 REGISTER_G_LOG_HANDLER("GLib"); | |
272 REGISTER_G_LOG_HANDLER("GModule"); | |
273 REGISTER_G_LOG_HANDLER("GLib-GObject"); | |
274 REGISTER_G_LOG_HANDLER("GThread"); | |
275 | |
276 g_set_print_handler(print_stderr); /* Redirect the debug messages to stderr */ | |
277 g_set_printerr_handler(suppress_error_messages); | |
278 | |
15823 | 279 purple_prefs_add_none(PREF_ROOT); |
280 purple_prefs_add_none(PREF_ROOT "/size"); | |
281 purple_prefs_add_int(PREF_ROOT "/size/width", 60); | |
282 purple_prefs_add_int(PREF_ROOT "/size/height", 15); | |
15818 | 283 |
15823 | 284 if (purple_debug_is_enabled()) |
15818 | 285 g_timeout_add(0, start_with_debugwin, NULL); |
286 } | |
287 | |
288 void finch_debug_uninit() | |
289 { | |
290 } | |
291 |