Mercurial > pidgin
comparison src/gtkdebug.c @ 5428:96bde36bb76b
[gaim-migrate @ 5808]
Let's see what the others think about this.
I made some modifications to the debug window. There are now Clear, Pause,
and Timestamp buttons. I have Find and Save #if 0'd out in the code,
because I haven't written them, and I'm not sure when I will. For now,
I like this. Oh, and the Jabber stuff no longer makes the window really
wide. This was my fault. Fixed! :D Resize to your heart's content.
Timestamps don't save. I won't implement this until we get new prefs ;)
committer: Tailor Script <tailor@pidgin.im>
| author | Christian Hammond <chipx86@chipx86.com> |
|---|---|
| date | Sun, 18 May 2003 09:08:42 +0000 |
| parents | 1f901484599d |
| children | 7d1a44cbd347 |
comparison
equal
deleted
inserted
replaced
| 5427:04e1e40b99b0 | 5428:96bde36bb76b |
|---|---|
| 26 #include <gtk/gtk.h> | 26 #include <gtk/gtk.h> |
| 27 | 27 |
| 28 typedef struct | 28 typedef struct |
| 29 { | 29 { |
| 30 GtkWidget *window; | 30 GtkWidget *window; |
| 31 GtkWidget *entry; | 31 GtkWidget *text; |
| 32 | |
| 33 gboolean timestamps; | |
| 34 gboolean paused; | |
| 32 | 35 |
| 33 } DebugWindow; | 36 } DebugWindow; |
| 34 | 37 |
| 35 static char debug_fg_colors[][8] = { | 38 static char debug_fg_colors[][8] = { |
| 36 "#000000", /**< All debug levels. */ | 39 "#000000", /**< All debug levels. */ |
| 55 save_prefs(); | 58 save_prefs(); |
| 56 | 59 |
| 57 return FALSE; | 60 return FALSE; |
| 58 } | 61 } |
| 59 | 62 |
| 63 static void | |
| 64 __clear_cb(GtkWidget *w, DebugWindow *win) | |
| 65 { | |
| 66 gtk_imhtml_clear(GTK_IMHTML(win->text)); | |
| 67 } | |
| 68 | |
| 69 static void | |
| 70 __pause_cb(GtkWidget *w, DebugWindow *win) | |
| 71 { | |
| 72 win->paused = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)); | |
| 73 } | |
| 74 | |
| 75 static void | |
| 76 __timestamps_cb(GtkWidget *w, DebugWindow *win) | |
| 77 { | |
| 78 win->timestamps = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)); | |
| 79 } | |
| 80 | |
| 60 static DebugWindow * | 81 static DebugWindow * |
| 61 debug_window_new(void) | 82 debug_window_new(void) |
| 62 { | 83 { |
| 63 DebugWindow *win; | 84 DebugWindow *win; |
| 85 GtkWidget *vbox; | |
| 86 GtkWidget *toolbar; | |
| 64 GtkWidget *sw; | 87 GtkWidget *sw; |
| 65 | 88 |
| 66 win = g_new0(DebugWindow, 1); | 89 win = g_new0(DebugWindow, 1); |
| 67 | 90 |
| 68 GAIM_DIALOG(win->window); | 91 GAIM_DIALOG(win->window); |
| 71 gtk_window_set_title(GTK_WINDOW(win->window), _("Debug Window")); | 94 gtk_window_set_title(GTK_WINDOW(win->window), _("Debug Window")); |
| 72 | 95 |
| 73 g_signal_connect(G_OBJECT(win->window), "delete_event", | 96 g_signal_connect(G_OBJECT(win->window), "delete_event", |
| 74 G_CALLBACK(debug_window_destroy), NULL); | 97 G_CALLBACK(debug_window_destroy), NULL); |
| 75 | 98 |
| 99 /* Setup the vbox */ | |
| 100 vbox = gtk_vbox_new(FALSE, 0); | |
| 101 gtk_container_add(GTK_CONTAINER(win->window), vbox); | |
| 102 | |
| 103 /* Setup our top button bar thingie. */ | |
| 104 toolbar = gtk_toolbar_new(); | |
| 105 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_TEXT); | |
| 106 | |
| 107 gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0); | |
| 108 | |
| 109 #if 0 | |
| 110 /* Find button */ | |
| 111 gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_FIND, | |
| 112 NULL, NULL, NULL, NULL, -1); | |
| 113 | |
| 114 /* Save */ | |
| 115 gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_SAVE, | |
| 116 NULL, NULL, NULL, NULL, -1); | |
| 117 #endif | |
| 118 | |
| 119 /* Clear button */ | |
| 120 gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_CLEAR, | |
| 121 NULL, NULL, G_CALLBACK(__clear_cb), win, -1); | |
| 122 | |
| 123 gtk_toolbar_insert_space(GTK_TOOLBAR(toolbar), -1); | |
| 124 | |
| 125 /* Pause */ | |
| 126 gtk_toolbar_append_element(GTK_TOOLBAR(toolbar), | |
| 127 GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL, | |
| 128 _("Pause"), NULL, NULL, | |
| 129 NULL, G_CALLBACK(__pause_cb), win); | |
| 130 | |
| 131 /* Timestamps */ | |
| 132 gtk_toolbar_append_element(GTK_TOOLBAR(toolbar), | |
| 133 GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL, | |
| 134 _("Timestamps"), NULL, NULL, | |
| 135 NULL, G_CALLBACK(__timestamps_cb), win); | |
| 136 | |
| 137 /* Now our scrolled window... */ | |
| 76 sw = gtk_scrolled_window_new(NULL, NULL); | 138 sw = gtk_scrolled_window_new(NULL, NULL); |
| 77 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | 139 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), |
| 78 GTK_POLICY_NEVER, GTK_POLICY_ALWAYS); | 140 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); |
| 79 | 141 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), |
| 80 win->entry = gtk_imhtml_new(NULL, NULL); | 142 GTK_SHADOW_IN); |
| 81 | 143 |
| 82 gtk_container_add(GTK_CONTAINER(sw), win->entry); | 144 /* ... which has a gtkimhtml in it. */ |
| 83 gtk_container_add(GTK_CONTAINER(win->window), sw); | 145 win->text = gtk_imhtml_new(NULL, NULL); |
| 146 | |
| 147 gtk_container_add(GTK_CONTAINER(sw), win->text); | |
| 148 | |
| 149 /* Pack it in... Not like that, sicko. */ | |
| 150 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); | |
| 151 | |
| 84 gtk_widget_show_all(win->window); | 152 gtk_widget_show_all(win->window); |
| 85 | 153 |
| 86 return win; | 154 return win; |
| 87 } | 155 } |
| 88 | 156 |
| 89 void | 157 void |
| 90 gaim_gtk_debug_window_show(void) | 158 gaim_gtk_debug_window_show(void) |
| 106 | 174 |
| 107 static void | 175 static void |
| 108 gaim_gtk_debug_print(GaimDebugLevel level, const char *category, | 176 gaim_gtk_debug_print(GaimDebugLevel level, const char *category, |
| 109 const char *format, va_list args) | 177 const char *format, va_list args) |
| 110 { | 178 { |
| 111 gchar *esc_s, *arg_s, *cat_s, *s; | 179 gchar *arg_s; |
| 112 | 180 |
| 113 arg_s = g_strdup_vprintf(format, args); | 181 arg_s = g_strdup_vprintf(format, args); |
| 114 | 182 |
| 115 if ((misc_options & OPT_MISC_DEBUG) && debug_win != NULL) { | 183 if ((misc_options & OPT_MISC_DEBUG) && |
| 184 debug_win != NULL && !debug_win->paused) { | |
| 185 | |
| 186 gchar *esc_s, *cat_s, *ts_s, *s; | |
| 187 | |
| 116 if (category == NULL) | 188 if (category == NULL) |
| 117 cat_s = g_strdup(""); | 189 cat_s = g_strdup(""); |
| 118 else | 190 else |
| 119 cat_s = g_strdup_printf("<b>%s:</b> ", category); | 191 cat_s = g_strdup_printf("<b>%s:</b> ", category); |
| 120 | 192 |
| 193 if (debug_win->timestamps) { | |
| 194 gchar mdate[64]; | |
| 195 time_t mtime = time(NULL); | |
| 196 | |
| 197 strftime(mdate, sizeof(mdate), "%H:%M:%S", localtime(&mtime)); | |
| 198 | |
| 199 ts_s = g_strdup_printf("(%s) ", mdate); | |
| 200 } | |
| 201 else | |
| 202 ts_s = g_strdup(""); | |
| 203 | |
| 121 esc_s = g_markup_escape_text(arg_s, -1); | 204 esc_s = g_markup_escape_text(arg_s, -1); |
| 122 | 205 |
| 123 s = g_strdup_printf("<font color=\"%s\">%s%s</font>", | 206 s = g_strdup_printf("<font color=\"%s\">%s%s%s</font>", |
| 124 debug_fg_colors[level], cat_s, esc_s); | 207 debug_fg_colors[level], ts_s, cat_s, esc_s); |
| 125 | 208 |
| 209 g_free(ts_s); | |
| 126 g_free(esc_s); | 210 g_free(esc_s); |
| 127 | 211 |
| 128 if (level == GAIM_DEBUG_FATAL) { | 212 if (level == GAIM_DEBUG_FATAL) { |
| 129 gchar *temp = s; | 213 gchar *temp = s; |
| 130 | 214 |
| 132 g_free(temp); | 216 g_free(temp); |
| 133 } | 217 } |
| 134 | 218 |
| 135 g_free(cat_s); | 219 g_free(cat_s); |
| 136 | 220 |
| 137 gtk_imhtml_append_text(GTK_IMHTML(debug_win->entry), s, -1, 0); | 221 gtk_imhtml_append_text(GTK_IMHTML(debug_win->text), s, -1, 0); |
| 138 | 222 |
| 139 g_free(s); | 223 g_free(s); |
| 140 } | 224 } |
| 141 | 225 |
| 142 if (opt_debug) { | 226 if (opt_debug) { |
