| 39 #include <stdio.h> |
39 #include <stdio.h> |
| 40 #include <string.h> |
40 #include <string.h> |
| 41 |
41 |
| 42 #define PREF_ROOT "/finch/debug" |
42 #define PREF_ROOT "/finch/debug" |
| 43 |
43 |
| |
44 struct _FinchDebugUi |
| |
45 { |
| |
46 GObject parent; |
| |
47 |
| |
48 /* Other members, including private data. */ |
| |
49 }; |
| |
50 |
| |
51 static void finch_debug_ui_finalize(GObject *gobject); |
| |
52 static void finch_debug_ui_interface_init(PurpleDebugUiInterface *iface); |
| |
53 |
| |
54 G_DEFINE_TYPE_WITH_CODE(FinchDebugUi, finch_debug_ui, G_TYPE_OBJECT, |
| |
55 G_IMPLEMENT_INTERFACE(PURPLE_TYPE_DEBUG_UI, |
| |
56 finch_debug_ui_interface_init)); |
| |
57 |
| 44 static gboolean |
58 static gboolean |
| 45 handle_fprintf_stderr_cb(GIOChannel *source, GIOCondition cond, gpointer null) |
59 handle_fprintf_stderr_cb(GIOChannel *source, GIOCondition cond, gpointer null) |
| 46 { |
60 { |
| 47 gssize size; |
61 gssize size; |
| 48 char message[1024]; |
62 char message[1024]; |
| 106 return TRUE; |
120 return TRUE; |
| 107 return FALSE; |
121 return FALSE; |
| 108 } |
122 } |
| 109 |
123 |
| 110 static void |
124 static void |
| 111 finch_debug_print(PurpleDebugLevel level, const char *category, |
125 finch_debug_print(PurpleDebugUi *self, |
| 112 const char *args) |
126 PurpleDebugLevel level, const char *category, |
| |
127 const char *args) |
| 113 { |
128 { |
| 114 if (debug.window && !debug.paused && match_string(category, args)) |
129 if (debug.window && !debug.paused && match_string(category, args)) |
| 115 { |
130 { |
| 116 int pos = gnt_text_view_get_lines_below(GNT_TEXT_VIEW(debug.tview)); |
131 int pos = gnt_text_view_get_lines_below(GNT_TEXT_VIEW(debug.tview)); |
| 117 GntTextFormatFlags flag = GNT_TEXT_FLAG_NORMAL; |
132 GntTextFormatFlags flag = GNT_TEXT_FLAG_NORMAL; |
| 145 gnt_text_view_scroll(GNT_TEXT_VIEW(debug.tview), 0); |
160 gnt_text_view_scroll(GNT_TEXT_VIEW(debug.tview), 0); |
| 146 } |
161 } |
| 147 } |
162 } |
| 148 |
163 |
| 149 static gboolean |
164 static gboolean |
| 150 finch_debug_is_enabled(PurpleDebugLevel level, const char *category) |
165 finch_debug_is_enabled(PurpleDebugUi *self, PurpleDebugLevel level, const char *category) |
| 151 { |
166 { |
| 152 return debug.window && !debug.paused; |
167 return debug.window && !debug.paused; |
| 153 } |
168 } |
| 154 |
169 |
| 155 static PurpleDebugUiOps uiops = |
170 static void |
| 156 { |
171 finch_debug_ui_interface_init(PurpleDebugUiInterface *iface) |
| 157 finch_debug_print, |
172 { |
| 158 finch_debug_is_enabled, |
173 iface->print = finch_debug_print; |
| 159 |
174 iface->is_enabled = finch_debug_is_enabled; |
| 160 /* padding */ |
|
| 161 NULL, |
|
| 162 NULL, |
|
| 163 NULL, |
|
| 164 NULL |
|
| 165 }; |
|
| 166 |
|
| 167 PurpleDebugUiOps *finch_debug_get_ui_ops() |
|
| 168 { |
|
| 169 return &uiops; |
|
| 170 } |
175 } |
| 171 |
176 |
| 172 static void |
177 static void |
| 173 reset_debug_win(GntWidget *w, gpointer null) |
178 reset_debug_win(GntWidget *w, gpointer null) |
| 174 { |
179 { |
| 369 { |
374 { |
| 370 finch_debug_window_show(); |
375 finch_debug_window_show(); |
| 371 return FALSE; |
376 return FALSE; |
| 372 } |
377 } |
| 373 |
378 |
| 374 void finch_debug_init() |
379 static void |
| |
380 finch_debug_ui_class_init(FinchDebugUiClass *klass) |
| |
381 { |
| |
382 GObjectClass *object_class = G_OBJECT_CLASS(klass); |
| |
383 |
| |
384 object_class->finalize = finch_debug_ui_finalize; |
| |
385 } |
| |
386 |
| |
387 static void |
| |
388 finch_debug_ui_init(FinchDebugUi *self) |
| 375 { |
389 { |
| 376 /* Xerox */ |
390 /* Xerox */ |
| 377 #define REGISTER_G_LOG_HANDLER(name) \ |
391 #define REGISTER_G_LOG_HANDLER(name) \ |
| 378 g_log_set_handler((name), G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL \ |
392 g_log_set_handler((name), G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL \ |
| 379 | G_LOG_FLAG_RECURSION, \ |
393 | G_LOG_FLAG_RECURSION, \ |
| 403 |
417 |
| 404 if (purple_debug_is_enabled()) |
418 if (purple_debug_is_enabled()) |
| 405 g_timeout_add(0, start_with_debugwin, NULL); |
419 g_timeout_add(0, start_with_debugwin, NULL); |
| 406 } |
420 } |
| 407 |
421 |
| 408 void finch_debug_uninit() |
422 static void |
| |
423 finch_debug_ui_finalize(GObject *gobject) |
| 409 { |
424 { |
| 410 handle_fprintf_stderr(TRUE); |
425 handle_fprintf_stderr(TRUE); |
| 411 } |
426 G_OBJECT_CLASS(finch_debug_ui_parent_class)->finalize(gobject); |
| 412 |
427 } |
| |
428 |
| |
429 FinchDebugUi * |
| |
430 finch_debug_ui_new(void) |
| |
431 { |
| |
432 return g_object_new(FINCH_TYPE_DEBUG_UI, NULL); |
| |
433 } |