| 49 |
49 |
| 50 static void |
50 static void |
| 51 purple_debug_vargs(PurpleDebugLevel level, const char *category, |
51 purple_debug_vargs(PurpleDebugLevel level, const char *category, |
| 52 const char *format, va_list args) |
52 const char *format, va_list args) |
| 53 { |
53 { |
| 54 PurpleDebugUiOps *ops; |
54 PurpleDebugUi *ops; |
| |
55 PurpleDebugUiInterface *iface; |
| 55 char *arg_s = NULL; |
56 char *arg_s = NULL; |
| 56 |
57 |
| 57 g_return_if_fail(level != PURPLE_DEBUG_ALL); |
58 g_return_if_fail(level != PURPLE_DEBUG_ALL); |
| 58 g_return_if_fail(format != NULL); |
59 g_return_if_fail(format != NULL); |
| 59 |
60 |
| 60 ops = purple_debug_get_ui_ops(); |
61 ops = purple_debug_get_ui(); |
| 61 |
62 if (!ops) |
| 62 if (!debug_enabled && ((ops == NULL) || (ops->print == NULL) || |
63 return; |
| 63 (ops->is_enabled && !ops->is_enabled(level, category)))) |
64 iface = PURPLE_DEBUG_UI_GET_IFACE(ops); |
| |
65 if (!iface) |
| |
66 return; |
| |
67 |
| |
68 if (!debug_enabled && ((iface == NULL) || (iface->print == NULL) || |
| |
69 (iface->is_enabled && !iface->is_enabled(ops, level, category)))) |
| 64 return; |
70 return; |
| 65 |
71 |
| 66 arg_s = g_strdup_vprintf(format, args); |
72 arg_s = g_strdup_vprintf(format, args); |
| 67 g_strchomp(arg_s); /* strip trailing linefeeds */ |
73 g_strchomp(arg_s); /* strip trailing linefeeds */ |
| 68 |
74 |
| 100 g_print("%s%s%s: %s%s\n", format_pre, ts_s, category, arg_s, format_post); |
106 g_print("%s%s%s: %s%s\n", format_pre, ts_s, category, arg_s, format_post); |
| 101 |
107 |
| 102 g_free(ts_s); |
108 g_free(ts_s); |
| 103 } |
109 } |
| 104 |
110 |
| 105 if (ops != NULL && ops->print != NULL) |
111 if (iface != NULL && iface->print != NULL) |
| 106 ops->print(level, category, arg_s); |
112 iface->print(ops, level, category, arg_s); |
| 107 |
113 |
| 108 g_free(arg_s); |
114 g_free(arg_s); |
| 109 } |
115 } |
| 110 |
116 |
| 111 void |
117 void |
| 192 purple_debug_is_enabled() |
198 purple_debug_is_enabled() |
| 193 { |
199 { |
| 194 return debug_enabled; |
200 return debug_enabled; |
| 195 } |
201 } |
| 196 |
202 |
| 197 static PurpleDebugUiOps * |
203 void |
| 198 purple_debug_ui_ops_copy(PurpleDebugUiOps *ops) |
204 purple_debug_set_ui(PurpleDebugUi *ops) |
| 199 { |
205 { |
| 200 PurpleDebugUiOps *ops_new; |
206 g_set_object(&debug_ui, ops); |
| 201 |
|
| 202 g_return_val_if_fail(ops != NULL, NULL); |
|
| 203 |
|
| 204 ops_new = g_new(PurpleDebugUiOps, 1); |
|
| 205 *ops_new = *ops; |
|
| 206 |
|
| 207 return ops_new; |
|
| 208 } |
|
| 209 |
|
| 210 GType |
|
| 211 purple_debug_ui_ops_get_type(void) |
|
| 212 { |
|
| 213 static GType type = 0; |
|
| 214 |
|
| 215 if (type == 0) { |
|
| 216 type = g_boxed_type_register_static("PurpleDebugUiOps", |
|
| 217 (GBoxedCopyFunc)purple_debug_ui_ops_copy, |
|
| 218 (GBoxedFreeFunc)g_free); |
|
| 219 } |
|
| 220 |
|
| 221 return type; |
|
| 222 } |
|
| 223 |
|
| 224 void |
|
| 225 purple_debug_set_ui_ops(PurpleDebugUiOps *ops) |
|
| 226 { |
|
| 227 debug_ui_ops = ops; |
|
| 228 } |
207 } |
| 229 |
208 |
| 230 gboolean |
209 gboolean |
| 231 purple_debug_is_verbose() |
210 purple_debug_is_verbose() |
| 232 { |
211 { |
| 255 purple_debug_set_colored(gboolean colored) |
234 purple_debug_set_colored(gboolean colored) |
| 256 { |
235 { |
| 257 debug_colored = colored; |
236 debug_colored = colored; |
| 258 } |
237 } |
| 259 |
238 |
| 260 PurpleDebugUiOps * |
239 PurpleDebugUi * |
| 261 purple_debug_get_ui_ops(void) |
240 purple_debug_get_ui(void) |
| 262 { |
241 { |
| 263 return debug_ui_ops; |
242 return debug_ui; |
| |
243 } |
| |
244 |
| |
245 G_DEFINE_INTERFACE(PurpleDebugUi, purple_debug_ui, G_TYPE_OBJECT); |
| |
246 |
| |
247 static void |
| |
248 purple_debug_ui_default_init(PurpleDebugUiInterface *iface) |
| |
249 { |
| |
250 /* add properties and signals to the interface here */ |
| 264 } |
251 } |
| 265 |
252 |
| 266 void |
253 void |
| 267 purple_debug_init(void) |
254 purple_debug_init(void) |
| 268 { |
255 { |