Mercurial > pidgin
comparison console/gntdebug.c @ 14693:ae0136b0a3ae
[gaim-migrate @ 17445]
Patch #1569730 from Richard Nelson (wabz):
"This patch adds a "Clear" button, timestamp and pause
options, and stops it scrolling down if it's scrolled up."
and
"Also gives the debug window a name, so window managers
can more easily have their way with it."
These changes make the debug window a whole lot more usable.
committer: Tailor Script <tailor@pidgin.im>
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sun, 08 Oct 2006 03:56:06 +0000 |
parents | 81650a27f253 |
children | 3b5c732458ec |
comparison
equal
deleted
inserted
replaced
14692:dd0c43d42394 | 14693:ae0136b0a3ae |
---|---|
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> | 27 #include <gnttextview.h> |
28 #include <gntbutton.h> | |
29 #include <gntcheckbox.h> | |
30 #include <gntline.h> | |
28 | 31 |
29 #include "gntdebug.h" | 32 #include "gntdebug.h" |
30 #include "gntgaim.h" | 33 #include "gntgaim.h" |
34 #include "util.h" | |
31 | 35 |
32 #include <stdio.h> | 36 #include <stdio.h> |
33 #include <string.h> | 37 #include <string.h> |
34 | 38 |
35 static struct | 39 static struct |
36 { | 40 { |
37 GntWidget *window; | 41 GntWidget *window; |
38 GntWidget *tview; | 42 GntWidget *tview; |
43 gboolean paused; | |
44 gboolean timestamps; | |
39 } debug; | 45 } debug; |
40 | 46 |
41 static gboolean | 47 static gboolean |
42 debug_window_kpress_cb(GntWidget *wid, const char *key, GntTextView *view) | 48 debug_window_kpress_cb(GntWidget *wid, const char *key, GntTextView *view) |
43 { | 49 { |
60 | 66 |
61 static void | 67 static void |
62 gg_debug_print(GaimDebugLevel level, const char *category, | 68 gg_debug_print(GaimDebugLevel level, const char *category, |
63 const char *args) | 69 const char *args) |
64 { | 70 { |
65 if (debug.window) | 71 if (debug.window && !debug.paused) |
66 { | 72 { |
73 int pos = gnt_text_view_get_lines_below(GNT_TEXT_VIEW(debug.tview)); | |
67 GntTextFormatFlags flag = GNT_TEXT_FLAG_NORMAL; | 74 GntTextFormatFlags flag = GNT_TEXT_FLAG_NORMAL; |
75 | |
76 if (debug.timestamps) { | |
77 const char *mdate; | |
78 time_t mtime = time(NULL); | |
79 mdate = gaim_utf8_strftime("%H:%M:%S ", localtime(&mtime)); | |
80 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview), | |
81 mdate, flag); | |
82 } | |
68 | 83 |
69 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview), | 84 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview), |
70 category, GNT_TEXT_FLAG_BOLD); | 85 category, GNT_TEXT_FLAG_BOLD); |
71 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview), | 86 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview), |
72 ": ", GNT_TEXT_FLAG_BOLD); | 87 ": ", GNT_TEXT_FLAG_BOLD); |
73 | 88 |
74 switch (level) | 89 switch (level) |
75 { | 90 { |
76 case GAIM_DEBUG_WARNING: | 91 case GAIM_DEBUG_WARNING: |
77 flag |= GNT_TEXT_FLAG_UNDERLINE; | 92 flag |= GNT_TEXT_FLAG_UNDERLINE; |
78 case GAIM_DEBUG_ERROR: | 93 case GAIM_DEBUG_ERROR: |
80 flag |= GNT_TEXT_FLAG_BOLD; | 95 flag |= GNT_TEXT_FLAG_BOLD; |
81 break; | 96 break; |
82 default: | 97 default: |
83 break; | 98 break; |
84 } | 99 } |
85 | 100 |
86 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview), args, flag); | 101 gnt_text_view_append_text_with_flags(GNT_TEXT_VIEW(debug.tview), args, flag); |
87 gnt_text_view_scroll(GNT_TEXT_VIEW(debug.tview), 0); | 102 if (pos <= 1) |
103 gnt_text_view_scroll(GNT_TEXT_VIEW(debug.tview), 0); | |
88 } | 104 } |
89 } | 105 } |
90 | 106 |
91 static GaimDebugUiOps uiops = | 107 static GaimDebugUiOps uiops = |
92 { | 108 { |
93 gg_debug_print, | 109 gg_debug_print, |
94 }; | 110 }; |
95 | 111 |
96 GaimDebugUiOps *gg_debug_get_ui_ops() | 112 GaimDebugUiOps *gg_debug_get_ui_ops() |
103 { | 119 { |
104 debug.window = debug.tview = NULL; | 120 debug.window = debug.tview = NULL; |
105 } | 121 } |
106 | 122 |
107 static void | 123 static void |
124 clear_debug_win(GntWidget *w, GntTextView *tv) | |
125 { | |
126 gnt_text_view_clear(tv); | |
127 } | |
128 | |
129 static void | |
108 print_stderr(const char *string) | 130 print_stderr(const char *string) |
109 { | 131 { |
110 g_printerr("%s", string); | 132 g_printerr("%s", string); |
111 } | 133 } |
112 | 134 |
135 static void | |
136 toggle_pause(GntWidget *w, gpointer n) | |
137 { | |
138 debug.paused = !debug.paused; | |
139 } | |
140 | |
141 static void | |
142 toggle_timestamps(GntWidget *w, gpointer n) | |
143 { | |
144 debug.timestamps = !debug.timestamps; | |
145 gaim_prefs_set_bool("/core/debug/timestamps", debug.timestamps); | |
146 } | |
147 | |
113 void gg_debug_window_show() | 148 void gg_debug_window_show() |
114 { | 149 { |
150 debug.paused = false; | |
151 debug.timestamps = gaim_prefs_get_bool("/core/debug/timestamps"); | |
115 if (debug.window == NULL) | 152 if (debug.window == NULL) |
116 { | 153 { |
154 GntWidget *wid, *box; | |
117 debug.window = gnt_vbox_new(FALSE); | 155 debug.window = gnt_vbox_new(FALSE); |
118 gnt_box_set_toplevel(GNT_BOX(debug.window), TRUE); | 156 gnt_box_set_toplevel(GNT_BOX(debug.window), TRUE); |
119 gnt_box_set_title(GNT_BOX(debug.window), _("Debug Window")); | 157 gnt_box_set_title(GNT_BOX(debug.window), _("Debug Window")); |
158 gnt_box_set_pad(GNT_BOX(debug.window), 0); | |
159 gnt_box_set_alignment(GNT_BOX(debug.window), GNT_ALIGN_MID); | |
120 | 160 |
121 debug.tview = gnt_text_view_new(); | 161 debug.tview = gnt_text_view_new(); |
122 gnt_box_add_widget(GNT_BOX(debug.window), debug.tview); | 162 gnt_box_add_widget(GNT_BOX(debug.window), debug.tview); |
123 | 163 |
124 /* XXX: Add checkboxes/buttons for Clear, Pause, Timestamps */ | 164 gnt_box_add_widget(GNT_BOX(debug.window), gnt_line_new(FALSE)); |
165 | |
166 box = gnt_hbox_new(FALSE); | |
167 gnt_box_set_alignment(GNT_BOX(box), GNT_ALIGN_MID); | |
168 | |
169 /* XXX: Setting the GROW_Y for the following widgets don't make sense. But right now | |
170 * it's necessary to make the width of the debug window resizable ... like I said, | |
171 * it doesn't make sense. The bug is likely in the packing in gntbox.c. | |
172 */ | |
173 wid = gnt_button_new(_("Clear")); | |
174 g_signal_connect(G_OBJECT(wid), "activate", G_CALLBACK(clear_debug_win), debug.tview); | |
175 GNT_WIDGET_SET_FLAGS(wid, GNT_WIDGET_GROW_Y); | |
176 gnt_box_add_widget(GNT_BOX(box), wid); | |
177 | |
178 wid = gnt_check_box_new(_("Pause")); | |
179 g_signal_connect(G_OBJECT(wid), "toggled", G_CALLBACK(toggle_pause), NULL); | |
180 GNT_WIDGET_SET_FLAGS(wid, GNT_WIDGET_GROW_Y); | |
181 gnt_box_add_widget(GNT_BOX(box), wid); | |
182 | |
183 wid = gnt_check_box_new(_("Timestamps")); | |
184 gnt_check_box_set_checked(GNT_CHECK_BOX(wid), debug.timestamps); | |
185 g_signal_connect(G_OBJECT(wid), "toggled", G_CALLBACK(toggle_timestamps), NULL); | |
186 GNT_WIDGET_SET_FLAGS(wid, GNT_WIDGET_GROW_Y); | |
187 gnt_box_add_widget(GNT_BOX(box), wid); | |
188 | |
189 gnt_box_add_widget(GNT_BOX(debug.window), box); | |
190 GNT_WIDGET_SET_FLAGS(box, GNT_WIDGET_GROW_Y); | |
191 | |
192 gnt_widget_set_name(debug.window, "debug-window"); | |
125 | 193 |
126 g_signal_connect(G_OBJECT(debug.window), "destroy", G_CALLBACK(reset_debug_win), NULL); | 194 g_signal_connect(G_OBJECT(debug.window), "destroy", G_CALLBACK(reset_debug_win), NULL); |
127 g_signal_connect(G_OBJECT(debug.window), "key_pressed", G_CALLBACK(debug_window_kpress_cb), debug.tview); | 195 g_signal_connect(G_OBJECT(debug.window), "key_pressed", G_CALLBACK(debug_window_kpress_cb), debug.tview); |
128 } | 196 } |
129 | 197 |