comparison finch/gntdebug.c @ 17226:618a3748ff64

merge of '6a857845ed772173ecc2083603f0d661eb52c68a' and 'f806da14ec2d87cd6650b921eaeed3c6d6587598'
author Richard Laager <rlaager@wiktel.com>
date Mon, 21 May 2007 20:58:23 +0000
parents 47a9ba4f4373
children d8b9bea550bc 2d4df5ef0090
comparison
equal deleted inserted replaced
16948:e42309469a4a 17226:618a3748ff64
22 * along with this program; if not, write to the Free Software 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 23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
24 */ 24 */
25 #include <gnt.h> 25 #include <gnt.h>
26 #include <gntbox.h> 26 #include <gntbox.h>
27 #include <gnttextview.h>
28 #include <gntbutton.h> 27 #include <gntbutton.h>
29 #include <gntcheckbox.h> 28 #include <gntcheckbox.h>
29 #include <gntentry.h>
30 #include <gntlabel.h>
30 #include <gntline.h> 31 #include <gntline.h>
32 #include <gnttextview.h>
31 33
32 #include "gntdebug.h" 34 #include "gntdebug.h"
33 #include "finch.h" 35 #include "finch.h"
34 #include "util.h" 36 #include "util.h"
35 37
40 42
41 static struct 43 static struct
42 { 44 {
43 GntWidget *window; 45 GntWidget *window;
44 GntWidget *tview; 46 GntWidget *tview;
47 GntWidget *search;
45 gboolean paused; 48 gboolean paused;
46 gboolean timestamps;
47 } debug; 49 } debug;
50
51 static gboolean
52 match_string(const char *category, const char *args)
53 {
54 const char *str = gnt_entry_get_text(GNT_ENTRY(debug.search));
55 if (!str || !*str)
56 return TRUE;
57 if (g_strrstr(category, str) != NULL)
58 return TRUE;
59 if (g_strrstr(args, str) != NULL)
60 return TRUE;
61 return FALSE;
62 }
48 63
49 static void 64 static void
50 finch_debug_print(PurpleDebugLevel level, const char *category, 65 finch_debug_print(PurpleDebugLevel level, const char *category,
51 const char *args) 66 const char *args)
52 { 67 {
53 if (debug.window && !debug.paused) 68 if (debug.window && !debug.paused && match_string(category, args))
54 { 69 {
55 int pos = gnt_text_view_get_lines_below(GNT_TEXT_VIEW(debug.tview)); 70 int pos = gnt_text_view_get_lines_below(GNT_TEXT_VIEW(debug.tview));
56 GntTextFormatFlags flag = GNT_TEXT_FLAG_NORMAL; 71 GntTextFormatFlags flag = GNT_TEXT_FLAG_NORMAL;
57 72 const char *mdate;
58 if (debug.timestamps) { 73 time_t mtime = time(NULL);
59 const char *mdate; 74 mdate = purple_utf8_strftime("%H:%M:%S ", localtime(&mtime));
60 time_t mtime = time(NULL); 75 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview),
61 mdate = purple_utf8_strftime("%H:%M:%S ", localtime(&mtime)); 76 mdate, flag);
62 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview),
63 mdate, flag);
64 }
65 77
66 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview), 78 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview),
67 category, GNT_TEXT_FLAG_BOLD); 79 category, GNT_TEXT_FLAG_BOLD);
68 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview), 80 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview),
69 ": ", GNT_TEXT_FLAG_BOLD); 81 ": ", GNT_TEXT_FLAG_BOLD);
110 } 122 }
111 123
112 static void 124 static void
113 reset_debug_win(GntWidget *w, gpointer null) 125 reset_debug_win(GntWidget *w, gpointer null)
114 { 126 {
115 debug.window = debug.tview = NULL; 127 debug.window = debug.tview = debug.search = NULL;
116 } 128 }
117 129
118 static void 130 static void
119 clear_debug_win(GntWidget *w, GntTextView *tv) 131 clear_debug_win(GntWidget *w, GntTextView *tv)
120 { 132 {
133 145
134 static void 146 static void
135 toggle_pause(GntWidget *w, gpointer n) 147 toggle_pause(GntWidget *w, gpointer n)
136 { 148 {
137 debug.paused = !debug.paused; 149 debug.paused = !debug.paused;
138 }
139
140 static void
141 toggle_timestamps(GntWidget *w, gpointer n)
142 {
143 debug.timestamps = !debug.timestamps;
144 purple_prefs_set_bool("/purple/debug/timestamps", debug.timestamps);
145 } 150 }
146 151
147 /* Xerox */ 152 /* Xerox */
148 static void 153 static void
149 purple_glib_log_handler(const gchar *domain, GLogLevelFlags flags, 154 purple_glib_log_handler(const gchar *domain, GLogLevelFlags flags,
197 gnt_widget_get_size(widget, &w, &h); 202 gnt_widget_get_size(widget, &w, &h);
198 purple_prefs_set_int(PREF_ROOT "/size/width", w); 203 purple_prefs_set_int(PREF_ROOT "/size/width", w);
199 purple_prefs_set_int(PREF_ROOT "/size/height", h); 204 purple_prefs_set_int(PREF_ROOT "/size/height", h);
200 } 205 }
201 206
207 static gboolean
208 for_real(gpointer entry)
209 {
210 purple_prefs_set_string(PREF_ROOT "/filter", gnt_entry_get_text(entry));
211 return FALSE;
212 }
213
214 static void
215 update_filter_string(GntEntry *entry, gpointer null)
216 {
217 int id = g_timeout_add(1000, for_real, entry);
218 g_object_set_data_full(G_OBJECT(entry), "update-filter", GINT_TO_POINTER(id),
219 (GDestroyNotify)g_source_remove);
220 }
221
202 void finch_debug_window_show() 222 void finch_debug_window_show()
203 { 223 {
204 debug.paused = FALSE; 224 debug.paused = FALSE;
205 debug.timestamps = purple_prefs_get_bool("/purple/debug/timestamps");
206 if (debug.window == NULL) 225 if (debug.window == NULL)
207 { 226 {
208 GntWidget *wid, *box; 227 GntWidget *wid, *box;
209 debug.window = gnt_vbox_new(FALSE); 228 debug.window = gnt_vbox_new(FALSE);
210 gnt_box_set_toplevel(GNT_BOX(debug.window), TRUE); 229 gnt_box_set_toplevel(GNT_BOX(debug.window), TRUE);
232 wid = gnt_button_new(_("Clear")); 251 wid = gnt_button_new(_("Clear"));
233 g_signal_connect(G_OBJECT(wid), "activate", G_CALLBACK(clear_debug_win), debug.tview); 252 g_signal_connect(G_OBJECT(wid), "activate", G_CALLBACK(clear_debug_win), debug.tview);
234 GNT_WIDGET_SET_FLAGS(wid, GNT_WIDGET_GROW_Y); 253 GNT_WIDGET_SET_FLAGS(wid, GNT_WIDGET_GROW_Y);
235 gnt_box_add_widget(GNT_BOX(box), wid); 254 gnt_box_add_widget(GNT_BOX(box), wid);
236 255
256 debug.search = gnt_entry_new(purple_prefs_get_string(PREF_ROOT "/filter"));
257 gnt_box_add_widget(GNT_BOX(box), gnt_label_new(_("Filter: ")));
258 gnt_box_add_widget(GNT_BOX(box), debug.search);
259 g_signal_connect(G_OBJECT(debug.search), "text_changed", G_CALLBACK(update_filter_string), NULL);
260
237 wid = gnt_check_box_new(_("Pause")); 261 wid = gnt_check_box_new(_("Pause"));
238 g_signal_connect(G_OBJECT(wid), "toggled", G_CALLBACK(toggle_pause), NULL); 262 g_signal_connect(G_OBJECT(wid), "toggled", G_CALLBACK(toggle_pause), NULL);
239 GNT_WIDGET_SET_FLAGS(wid, GNT_WIDGET_GROW_Y);
240 gnt_box_add_widget(GNT_BOX(box), wid);
241
242 wid = gnt_check_box_new(_("Timestamps"));
243 gnt_check_box_set_checked(GNT_CHECK_BOX(wid), debug.timestamps);
244 g_signal_connect(G_OBJECT(wid), "toggled", G_CALLBACK(toggle_timestamps), NULL);
245 GNT_WIDGET_SET_FLAGS(wid, GNT_WIDGET_GROW_Y); 263 GNT_WIDGET_SET_FLAGS(wid, GNT_WIDGET_GROW_Y);
246 gnt_box_add_widget(GNT_BOX(box), wid); 264 gnt_box_add_widget(GNT_BOX(box), wid);
247 265
248 gnt_box_add_widget(GNT_BOX(debug.window), box); 266 gnt_box_add_widget(GNT_BOX(debug.window), box);
249 GNT_WIDGET_SET_FLAGS(box, GNT_WIDGET_GROW_Y); 267 GNT_WIDGET_SET_FLAGS(box, GNT_WIDGET_GROW_Y);
281 299
282 g_set_print_handler(print_stderr); /* Redirect the debug messages to stderr */ 300 g_set_print_handler(print_stderr); /* Redirect the debug messages to stderr */
283 g_set_printerr_handler(suppress_error_messages); 301 g_set_printerr_handler(suppress_error_messages);
284 302
285 purple_prefs_add_none(PREF_ROOT); 303 purple_prefs_add_none(PREF_ROOT);
304 purple_prefs_add_string(PREF_ROOT "/filter", "");
286 purple_prefs_add_none(PREF_ROOT "/size"); 305 purple_prefs_add_none(PREF_ROOT "/size");
287 purple_prefs_add_int(PREF_ROOT "/size/width", 60); 306 purple_prefs_add_int(PREF_ROOT "/size/width", 60);
288 purple_prefs_add_int(PREF_ROOT "/size/height", 15); 307 purple_prefs_add_int(PREF_ROOT "/size/height", 15);
289 308
290 if (purple_debug_is_enabled()) 309 if (purple_debug_is_enabled())