Mercurial > pidgin.yaz
comparison src/gtkdebug.c @ 10307:2ac21bf20e04
[gaim-migrate @ 11497]
And another one gone, and another one gone, another one bites the dust.
Hopefully I'm committing everything this time.
committer: Tailor Script <tailor@pidgin.im>
author | Mark Doliner <mark@kingant.net> |
---|---|
date | Fri, 03 Dec 2004 02:46:34 +0000 |
parents | ec140184437b |
children | 19974fd2d61d |
comparison
equal
deleted
inserted
replaced
10306:56cc5d49472b | 10307:2ac21bf20e04 |
---|---|
34 #include "gtkdialogs.h" | 34 #include "gtkdialogs.h" |
35 #include "gtkimhtml.h" | 35 #include "gtkimhtml.h" |
36 #include "gtkutils.h" | 36 #include "gtkutils.h" |
37 #include "gtkstock.h" | 37 #include "gtkstock.h" |
38 | 38 |
39 extern int opt_debug; | |
40 | |
41 typedef struct | 39 typedef struct |
42 { | 40 { |
43 GtkWidget *window; | 41 GtkWidget *window; |
44 GtkWidget *text; | 42 GtkWidget *text; |
45 GtkWidget *find; | 43 GtkWidget *find; |
210 static void | 208 static void |
211 timestamps_cb(GtkWidget *w, DebugWindow *win) | 209 timestamps_cb(GtkWidget *w, DebugWindow *win) |
212 { | 210 { |
213 win->timestamps = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)); | 211 win->timestamps = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)); |
214 | 212 |
215 gaim_prefs_set_bool("/gaim/gtk/debug/timestamps", win->timestamps); | 213 gaim_prefs_set_bool("/core/debug/timestamps", win->timestamps); |
216 } | 214 } |
217 | 215 |
218 static void | 216 static void |
219 timestamps_pref_cb(const char *name, GaimPrefType type, gpointer value, | 217 timestamps_pref_cb(const char *name, GaimPrefType type, gpointer value, |
220 gpointer data) | 218 gpointer data) |
291 NULL, _("Timestamps"), NULL, NULL, | 289 NULL, _("Timestamps"), NULL, NULL, |
292 NULL, G_CALLBACK(timestamps_cb), | 290 NULL, G_CALLBACK(timestamps_cb), |
293 win); | 291 win); |
294 | 292 |
295 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), | 293 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), |
296 gaim_prefs_get_bool("/gaim/gtk/debug/timestamps")); | 294 gaim_prefs_get_bool("/core/debug/timestamps")); |
297 | 295 |
298 gaim_prefs_connect_callback(gaim_gtk_debug_get_handle(), "/gaim/gtk/debug/timestamps", | 296 gaim_prefs_connect_callback(gaim_gtk_debug_get_handle(), "/core/debug/timestamps", |
299 timestamps_pref_cb, button); | 297 timestamps_pref_cb, button); |
300 } | 298 } |
301 | 299 |
302 /* Add the gtkimhtml */ | 300 /* Add the gtkimhtml */ |
303 frame = gaim_gtk_create_imhtml(FALSE, &win->text, NULL); | 301 frame = gaim_gtk_create_imhtml(FALSE, &win->text, NULL); |
382 * preference here and that loads the window, which calls the | 380 * preference here and that loads the window, which calls the |
383 * configure event, which overrides the width and height! :P | 381 * configure event, which overrides the width and height! :P |
384 */ | 382 */ |
385 | 383 |
386 gaim_prefs_add_none("/gaim/gtk/debug"); | 384 gaim_prefs_add_none("/gaim/gtk/debug"); |
385 | |
386 /* Controls printing to the debug window */ | |
387 gaim_prefs_add_bool("/gaim/gtk/debug/enabled", FALSE); | 387 gaim_prefs_add_bool("/gaim/gtk/debug/enabled", FALSE); |
388 gaim_prefs_add_bool("/gaim/gtk/debug/timestamps", FALSE); | 388 |
389 gaim_prefs_add_bool("/gaim/gtk/debug/toolbar", TRUE); | 389 gaim_prefs_add_bool("/gaim/gtk/debug/toolbar", TRUE); |
390 gaim_prefs_add_int("/gaim/gtk/debug/width", 450); | 390 gaim_prefs_add_int("/gaim/gtk/debug/width", 450); |
391 gaim_prefs_add_int("/gaim/gtk/debug/height", 250); | 391 gaim_prefs_add_int("/gaim/gtk/debug/height", 250); |
392 | 392 |
393 gaim_prefs_connect_callback(NULL, "/gaim/gtk/debug/enabled", | 393 gaim_prefs_connect_callback(NULL, "/gaim/gtk/debug/enabled", |
436 | 436 |
437 static void | 437 static void |
438 gaim_gtk_debug_print(GaimDebugLevel level, const char *category, | 438 gaim_gtk_debug_print(GaimDebugLevel level, const char *category, |
439 const char *format, va_list args) | 439 const char *format, va_list args) |
440 { | 440 { |
441 gboolean timestamps; | |
441 gchar *arg_s, *ts_s; | 442 gchar *arg_s, *ts_s; |
442 gboolean timestamps; | 443 gchar *esc_s, *cat_s, *tmp, *s; |
443 | 444 |
444 timestamps = gaim_prefs_get_bool("/gaim/gtk/debug/timestamps"); | 445 if (!gaim_prefs_get_bool("/gaim/gtk/debug/enabled") || |
446 (debug_win == NULL) || debug_win->paused) { | |
447 return; | |
448 } | |
449 | |
450 timestamps = gaim_prefs_get_bool("/core/debug/timestamps"); | |
445 | 451 |
446 arg_s = g_strdup_vprintf(format, args); | 452 arg_s = g_strdup_vprintf(format, args); |
447 | 453 |
448 if (category == NULL) { | 454 /* |
455 * For some reason we only print the timestamp if category is | |
456 * not NULL. Why the hell do we do that? --Mark | |
457 */ | |
458 if ((category != NULL) && (timestamps)) { | |
459 gchar mdate[64]; | |
460 | |
461 time_t mtime = time(NULL); | |
462 strftime(mdate, sizeof(mdate), "%H:%M:%S", localtime(&mtime)); | |
463 ts_s = g_strdup_printf("(%s) ", mdate); | |
464 } else { | |
449 ts_s = g_strdup(""); | 465 ts_s = g_strdup(""); |
450 } | 466 } |
451 else { | 467 |
452 /* | 468 if (category == NULL) |
453 * If the category is not NULL, then do timestamps. | 469 cat_s = g_strdup(""); |
454 * This IS right. :) | 470 else |
455 */ | 471 cat_s = g_strdup_printf("<b>%s:</b> ", category); |
456 if (timestamps) { | 472 |
457 gchar mdate[64]; | 473 esc_s = g_markup_escape_text(arg_s, -1); |
458 time_t mtime = time(NULL); | 474 |
459 | 475 g_free(arg_s); |
460 strftime(mdate, sizeof(mdate), "%H:%M:%S", localtime(&mtime)); | 476 |
461 | 477 s = g_strdup_printf("<font color=\"%s\">%s%s%s</font>", |
462 ts_s = g_strdup_printf("(%s) ", mdate); | 478 debug_fg_colors[level], ts_s, cat_s, esc_s); |
463 } | 479 |
464 else | 480 g_free(ts_s); |
465 ts_s = g_strdup(""); | 481 g_free(cat_s); |
466 } | 482 g_free(esc_s); |
467 | 483 |
468 if (gaim_prefs_get_bool("/gaim/gtk/debug/enabled") && | 484 tmp = gaim_utf8_try_convert(s); |
469 debug_win != NULL && !debug_win->paused) { | 485 g_free(s); |
470 | 486 s = tmp; |
471 gchar *esc_s, *cat_s, *utf8_s, *s; | 487 |
472 | 488 if (level == GAIM_DEBUG_FATAL) { |
473 if (category == NULL) | 489 tmp = g_strdup_printf("<b>%s</b>", s); |
474 cat_s = g_strdup(""); | |
475 else | |
476 cat_s = g_strdup_printf("<b>%s:</b> ", category); | |
477 | |
478 esc_s = g_markup_escape_text(arg_s, -1); | |
479 | |
480 s = g_strdup_printf("<font color=\"%s\">%s%s%s</font>", | |
481 debug_fg_colors[level], ts_s, cat_s, esc_s); | |
482 | |
483 g_free(esc_s); | |
484 | |
485 utf8_s = gaim_utf8_try_convert(s); | |
486 g_free(s); | 490 g_free(s); |
487 s = utf8_s; | 491 s = tmp; |
488 | 492 } |
489 if (level == GAIM_DEBUG_FATAL) { | 493 |
490 gchar *temp = s; | 494 gtk_imhtml_append_text(GTK_IMHTML(debug_win->text), s, 0); |
491 | 495 |
492 s = g_strdup_printf("<b>%s</b>", temp); | 496 g_free(s); |
493 g_free(temp); | |
494 } | |
495 | |
496 g_free(cat_s); | |
497 | |
498 gtk_imhtml_append_text(GTK_IMHTML(debug_win->text), s, 0); | |
499 | |
500 g_free(s); | |
501 } | |
502 | |
503 if (opt_debug) { | |
504 if (category == NULL) | |
505 g_print("%s%s", ts_s, arg_s); | |
506 else | |
507 g_print("%s%s: %s", ts_s, category, arg_s); | |
508 } | |
509 | |
510 g_free(ts_s); | |
511 g_free(arg_s); | |
512 } | 497 } |
513 | 498 |
514 static GaimDebugUiOps ops = | 499 static GaimDebugUiOps ops = |
515 { | 500 { |
516 gaim_gtk_debug_print | 501 gaim_gtk_debug_print |