Mercurial > pidgin
annotate src/gtkdebug.c @ 9484:4ecff68380ea
[gaim-migrate @ 10309]
[23:55] <SimGuy> s/your/you're/
committer: Tailor Script <tailor@pidgin.im>
author | Tim Ringenbach <marv@pidgin.im> |
---|---|
date | Thu, 08 Jul 2004 05:01:54 +0000 |
parents | b917acdc982f |
children | 59d986a931d4 |
rev | line source |
---|---|
5212 | 1 /** |
2 * @file gtkdebug.c GTK+ Debug API | |
3 * @ingroup gtkui | |
4 * | |
5 * gaim | |
6 * | |
8046 | 7 * Gaim is the legal property of its developers, whose names are too numerous |
8 * to list here. Please refer to the COPYRIGHT file distributed with this | |
9 * source distribution. | |
7152
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
10 * |
5212 | 11 * This program is free software; you can redistribute it and/or modify |
12 * it under the terms of the GNU General Public License as published by | |
13 * the Free Software Foundation; either version 2 of the License, or | |
14 * (at your option) any later version. | |
15 * | |
16 * This program is distributed in the hope that it will be useful, | |
17 * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
18 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
19 * GNU General Public License for more details. | |
20 * | |
21 * You should have received a copy of the GNU General Public License | |
22 * along with this program; if not, write to the Free Software | |
23 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | |
24 */ | |
6371
8f94cce8faa5
[gaim-migrate @ 6876]
Christian Hammond <chipx86@chipx86.com>
parents:
6280
diff
changeset
|
25 #include "gtkinternal.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5818
diff
changeset
|
26 |
9480 | 27 #include "notify.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5818
diff
changeset
|
28 #include "prefs.h" |
8953 | 29 #include "request.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5818
diff
changeset
|
30 #include "util.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5818
diff
changeset
|
31 |
5212 | 32 #include "gtkdebug.h" |
33 #include "gtkimhtml.h" | |
8953 | 34 #include "gtkutils.h" |
6009
5cd7a10c6ade
[gaim-migrate @ 6457]
Christian Hammond <chipx86@chipx86.com>
parents:
5872
diff
changeset
|
35 #include "stock.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5818
diff
changeset
|
36 |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5818
diff
changeset
|
37 #include "ui.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5818
diff
changeset
|
38 |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5818
diff
changeset
|
39 extern int opt_debug; |
5212 | 40 |
41 typedef struct | |
42 { | |
43 GtkWidget *window; | |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
44 GtkWidget *text; |
8953 | 45 GtkWidget *find; |
9480 | 46 GtkWidget *save; |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
47 |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
48 gboolean timestamps; |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
49 gboolean paused; |
5212 | 50 |
5704
aa8dbb7e0a4d
[gaim-migrate @ 6125]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
51 guint timestamps_handle; |
aa8dbb7e0a4d
[gaim-migrate @ 6125]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
52 |
5212 | 53 } DebugWindow; |
54 | |
55 static char debug_fg_colors[][8] = { | |
56 "#000000", /**< All debug levels. */ | |
7150 | 57 "#666666", /**< Misc. */ |
5212 | 58 "#000000", /**< Information. */ |
59 "#660000", /**< Warnings. */ | |
60 "#FF0000", /**< Errors. */ | |
61 "#FF0000", /**< Fatal errors. */ | |
62 }; | |
63 | |
64 static DebugWindow *debug_win = NULL; | |
65 | |
8953 | 66 struct _find { |
67 DebugWindow *window; | |
68 GtkWidget *entry; | |
69 }; | |
70 | |
5212 | 71 static gint |
72 debug_window_destroy(GtkWidget *w, GdkEvent *event, void *unused) | |
73 { | |
5704
aa8dbb7e0a4d
[gaim-migrate @ 6125]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
74 if (debug_win->timestamps_handle != 0) |
aa8dbb7e0a4d
[gaim-migrate @ 6125]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
75 gaim_prefs_disconnect_callback(debug_win->timestamps_handle); |
9480 | 76 if (debug_win->save != NULL) |
77 gtk_widget_destroy(debug_win->save); | |
5704
aa8dbb7e0a4d
[gaim-migrate @ 6125]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
78 |
5212 | 79 g_free(debug_win); |
80 debug_win = NULL; | |
81 | |
9480 | 82 gaim_prefs_set_bool("/gaim/gtk/debug/enabled", FALSE); |
83 | |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
84 return FALSE; |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
85 } |
5212 | 86 |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
87 static gboolean |
5794
5e93fc46d1af
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5738
diff
changeset
|
88 configure_cb(GtkWidget *w, GdkEventConfigure *event, DebugWindow *win) |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
89 { |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
90 if (GTK_WIDGET_VISIBLE(w)) { |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
91 gaim_prefs_set_int("/gaim/gtk/debug/width", event->width); |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
92 gaim_prefs_set_int("/gaim/gtk/debug/height", event->height); |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
93 } |
5212 | 94 |
95 return FALSE; | |
96 } | |
97 | |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
98 static void |
9482 | 99 do_find_cb(GtkWidget *widget, gint response, struct _find *f) |
8953 | 100 { |
9482 | 101 switch (response) { |
8953 | 102 case GTK_RESPONSE_OK: |
103 gtk_imhtml_search_find(GTK_IMHTML(f->window->text), | |
104 gtk_entry_get_text(GTK_ENTRY(f->entry))); | |
105 break; | |
106 | |
107 case GTK_RESPONSE_DELETE_EVENT: | |
108 case GTK_RESPONSE_CLOSE: | |
109 gtk_imhtml_search_clear(GTK_IMHTML(f->window->text)); | |
110 gtk_widget_destroy(f->window->find); | |
111 f->window->find = NULL; | |
112 g_free(f); | |
113 break; | |
114 } | |
115 } | |
116 | |
117 static void | |
118 find_cb(GtkWidget *w, DebugWindow *win) | |
119 { | |
120 GtkWidget *hbox, *img, *label; | |
121 struct _find *f; | |
122 | |
123 if(win->find) | |
124 { | |
125 gtk_window_present(GTK_WINDOW(win->find)); | |
126 return; | |
127 } | |
128 | |
129 f = g_malloc(sizeof(struct _find)); | |
130 f->window = win; | |
131 win->find = gtk_dialog_new_with_buttons(_("Find"), | |
132 GTK_WINDOW(win->window), GTK_DIALOG_DESTROY_WITH_PARENT, | |
133 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, | |
134 GTK_STOCK_FIND, GTK_RESPONSE_OK, NULL); | |
135 gtk_dialog_set_default_response(GTK_DIALOG(win->find), | |
136 GTK_RESPONSE_OK); | |
137 g_signal_connect(G_OBJECT(win->find), "response", | |
138 G_CALLBACK(do_find_cb), f); | |
139 | |
140 gtk_container_set_border_width(GTK_CONTAINER(win->find), 6); | |
141 gtk_window_set_resizable(GTK_WINDOW(win->find), FALSE); | |
142 gtk_dialog_set_has_separator(GTK_DIALOG(win->find), FALSE); | |
143 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(win->find)->vbox), 12); | |
144 gtk_container_set_border_width( | |
145 GTK_CONTAINER(GTK_DIALOG(win->find)->vbox), 6); | |
146 | |
147 hbox = gtk_hbox_new(FALSE, 12); | |
148 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(win->find)->vbox), | |
149 hbox); | |
150 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, | |
151 GTK_ICON_SIZE_DIALOG); | |
152 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); | |
153 | |
154 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | |
155 gtk_dialog_set_response_sensitive(GTK_DIALOG(win->find), | |
156 GTK_RESPONSE_OK, FALSE); | |
157 | |
158 label = gtk_label_new(NULL); | |
159 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Search for:")); | |
160 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
161 | |
162 f->entry = gtk_entry_new(); | |
163 gtk_entry_set_activates_default(GTK_ENTRY(f->entry), TRUE); | |
164 gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(f->entry)); | |
165 g_signal_connect(G_OBJECT(f->entry), "changed", | |
166 G_CALLBACK(gaim_gtk_set_sensitive_if_input), | |
167 win->find); | |
168 gtk_box_pack_start(GTK_BOX(hbox), f->entry, FALSE, FALSE, 0); | |
169 | |
170 gtk_widget_show_all(win->find); | |
171 gtk_widget_grab_focus(f->entry); | |
172 } | |
173 | |
174 static void | |
9482 | 175 save_writefile_cb(GtkWidget *widget) |
8953 | 176 { |
177 const char *filename; | |
178 char *tmp; | |
179 FILE *fp; | |
180 | |
9480 | 181 g_return_if_fail(debug_win != NULL); |
8953 | 182 |
9480 | 183 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
184 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(debug_win->save)); | |
185 #else /* FILECHOOSER */ | |
186 filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(debug_win->save)); | |
187 #endif /* FILECHOOSER */ | |
8953 | 188 |
9482 | 189 gaim_notify_close_with_handle(debug_win->save); |
190 | |
9480 | 191 if (filename == NULL) { |
9482 | 192 gaim_notify_error(debug_win->save, NULL, _("Invalid file name."), NULL); |
8953 | 193 return; |
9480 | 194 } |
8953 | 195 |
9480 | 196 if ((fp = fopen(filename, "w+")) == NULL) { |
9482 | 197 gaim_notify_error(debug_win->save, NULL, _("Unable to open file."), NULL); |
8953 | 198 return; |
9480 | 199 } |
8953 | 200 |
9480 | 201 tmp = gtk_imhtml_get_text(GTK_IMHTML(debug_win->text), NULL, NULL); |
8953 | 202 fprintf(fp, "Gaim Debug log : %s\n", gaim_date_full()); |
203 fprintf(fp, "%s", tmp); | |
204 g_free(tmp); | |
205 | |
206 fclose(fp); | |
9480 | 207 |
208 gtk_widget_destroy(debug_win->save); | |
209 debug_win->save = NULL; | |
8953 | 210 } |
211 | |
9480 | 212 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
8953 | 213 static void |
9482 | 214 save_checkfile_cb(GtkWidget *widget, gint response, DebugWindow *win) |
9480 | 215 { |
216 const char *filename; | |
217 | |
218 if (response != GTK_RESPONSE_ACCEPT) { | |
219 if (response == GTK_RESPONSE_CANCEL) | |
220 gtk_widget_destroy(win->save); | |
221 win->save = NULL; | |
222 return; | |
223 } | |
224 | |
225 filename = gtk_file_chooser_get_filename(GTK_FILE_CHOOSER(win->save)); | |
226 #else /* FILECHOOSER */ | |
227 static void | |
9482 | 228 save_checkfile_cb(GtkWidget *widget, DebugWindow *win) |
8953 | 229 { |
230 const char *filename; | |
231 | |
9480 | 232 filename = gtk_file_selection_get_filename(GTK_FILE_SELECTION(win->save)); |
233 if (gaim_gtk_check_if_dir(filename, GTK_FILE_SELECTION(win->save))) { | |
234 /* Descend into directory? */ | |
8953 | 235 return; |
9480 | 236 } |
237 #endif /* FILECHOOSER */ | |
8953 | 238 |
239 if (g_file_test(filename, G_FILE_TEST_EXISTS)) | |
240 { | |
9482 | 241 gaim_request_close_with_handle(win->save); |
242 gaim_request_yes_no(win->save, NULL, _("That file already exists"), | |
9480 | 243 _("Would you like to overwrite it?"), 1, |
9482 | 244 win->save, G_CALLBACK(save_writefile_cb), NULL); |
8953 | 245 } |
246 else | |
9482 | 247 save_writefile_cb(win->save); |
8953 | 248 } |
249 | |
9480 | 250 #if !GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
251 static void | |
9482 | 252 save_destroy_cb(GtkWidget *widget, DebugWindow *win) |
9480 | 253 { |
254 if (win->save != NULL) | |
255 gtk_widget_destroy(win->save); | |
256 | |
257 win->save = NULL; | |
258 } | |
259 #endif | |
260 | |
8953 | 261 static void |
262 save_cb(GtkWidget *w, DebugWindow *win) | |
263 { | |
9480 | 264 if (win->save != NULL) { |
9482 | 265 gtk_window_present(GTK_WINDOW(win->save)); |
9480 | 266 return; |
267 } | |
8953 | 268 |
9480 | 269 #if GTK_CHECK_VERSION(2,4,0) /* FILECHOOSER */ |
270 win->save = gtk_file_chooser_dialog_new(_("Save Conversation"), | |
271 GTK_WINDOW(win->window), | |
272 GTK_FILE_CHOOSER_ACTION_SAVE, | |
273 GTK_STOCK_CANCEL, GTK_RESPONSE_CANCEL, | |
274 GTK_STOCK_SAVE, GTK_RESPONSE_ACCEPT, | |
275 NULL); | |
276 gtk_dialog_set_default_response(GTK_DIALOG(win->save), GTK_RESPONSE_ACCEPT); | |
277 gtk_file_chooser_set_current_name(GTK_FILE_CHOOSER(win->save), | |
278 "gaim-debug.log"); | |
9482 | 279 g_signal_connect(G_OBJECT(win->save), "response", |
280 G_CALLBACK(save_checkfile_cb), win); | |
9480 | 281 #else /* FILECHOOSER */ |
282 gchar *buf; | |
8953 | 283 |
9480 | 284 win->save = gtk_file_selection_new(_("Save Debug Log")); |
285 buf = g_strdup_printf("%s" G_DIR_SEPARATOR_S "gaim-debug.log", | |
286 gaim_home_dir()); | |
287 gtk_file_selection_set_filename(GTK_FILE_SELECTION(win->save), buf); | |
288 g_free(buf); | |
289 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(win->save)->ok_button), | |
9482 | 290 "clicked", G_CALLBACK(save_checkfile_cb), win); |
9480 | 291 g_signal_connect(G_OBJECT(GTK_FILE_SELECTION(win->save)->cancel_button), |
9482 | 292 "clicked", G_CALLBACK(save_destroy_cb), win); |
9480 | 293 g_signal_connect(G_OBJECT(win->save), |
9482 | 294 "destroy", G_CALLBACK(save_destroy_cb), win); |
9480 | 295 #endif /* FILECHOOSER */ |
296 | |
9482 | 297 gtk_widget_show_all(GTK_WIDGET(win->save)); |
8953 | 298 } |
299 | |
300 static void | |
5794
5e93fc46d1af
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5738
diff
changeset
|
301 clear_cb(GtkWidget *w, DebugWindow *win) |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
302 { |
6280
d330afe3ccf0
[gaim-migrate @ 6779]
Christian Hammond <chipx86@chipx86.com>
parents:
6094
diff
changeset
|
303 gtk_imhtml_clear(GTK_IMHTML(win->text)); |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
304 } |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
305 |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
306 static void |
5794
5e93fc46d1af
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5738
diff
changeset
|
307 pause_cb(GtkWidget *w, DebugWindow *win) |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
308 { |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
309 win->paused = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)); |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
310 } |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
311 |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
312 static void |
5794
5e93fc46d1af
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5738
diff
changeset
|
313 timestamps_cb(GtkWidget *w, DebugWindow *win) |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
314 { |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
315 win->timestamps = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)); |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
316 |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
317 gaim_prefs_set_bool("/gaim/gtk/debug/timestamps", win->timestamps); |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
318 } |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
319 |
5704
aa8dbb7e0a4d
[gaim-migrate @ 6125]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
320 static void |
aa8dbb7e0a4d
[gaim-migrate @ 6125]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
321 timestamps_pref_cb(const char *name, GaimPrefType type, gpointer value, |
aa8dbb7e0a4d
[gaim-migrate @ 6125]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
322 gpointer data) |
aa8dbb7e0a4d
[gaim-migrate @ 6125]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
323 { |
6478
338147ea6896
[gaim-migrate @ 6991]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
324 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(data), GPOINTER_TO_INT(value)); |
5704
aa8dbb7e0a4d
[gaim-migrate @ 6125]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
325 } |
aa8dbb7e0a4d
[gaim-migrate @ 6125]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
326 |
5212 | 327 static DebugWindow * |
328 debug_window_new(void) | |
329 { | |
330 DebugWindow *win; | |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
331 GtkWidget *vbox; |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
332 GtkWidget *toolbar; |
5212 | 333 GtkWidget *sw; |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
334 GtkWidget *button; |
6094
538c522e36e1
[gaim-migrate @ 6553]
Christian Hammond <chipx86@chipx86.com>
parents:
6009
diff
changeset
|
335 GtkWidget *image; |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
336 int width, height; |
5212 | 337 |
338 win = g_new0(DebugWindow, 1); | |
339 | |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
340 width = gaim_prefs_get_int("/gaim/gtk/debug/width"); |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
341 height = gaim_prefs_get_int("/gaim/gtk/debug/height"); |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
342 |
5212 | 343 GAIM_DIALOG(win->window); |
5642
1693a3027dc8
[gaim-migrate @ 6056]
Christian Hammond <chipx86@chipx86.com>
parents:
5636
diff
changeset
|
344 gaim_debug(GAIM_DEBUG_INFO, "gtkdebug", "Setting dimensions to %d, %d\n", |
1693a3027dc8
[gaim-migrate @ 6056]
Christian Hammond <chipx86@chipx86.com>
parents:
5636
diff
changeset
|
345 width, height); |
1693a3027dc8
[gaim-migrate @ 6056]
Christian Hammond <chipx86@chipx86.com>
parents:
5636
diff
changeset
|
346 |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
347 gtk_window_set_default_size(GTK_WINDOW(win->window), width, height); |
5212 | 348 gtk_window_set_role(GTK_WINDOW(win->window), "debug"); |
349 gtk_window_set_title(GTK_WINDOW(win->window), _("Debug Window")); | |
350 | |
351 g_signal_connect(G_OBJECT(win->window), "delete_event", | |
352 G_CALLBACK(debug_window_destroy), NULL); | |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
353 g_signal_connect(G_OBJECT(win->window), "configure_event", |
5794
5e93fc46d1af
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5738
diff
changeset
|
354 G_CALLBACK(configure_cb), win); |
5212 | 355 |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
356 /* Setup the vbox */ |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
357 vbox = gtk_vbox_new(FALSE, 0); |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
358 gtk_container_add(GTK_CONTAINER(win->window), vbox); |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
359 |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
360 if (gaim_prefs_get_bool("/gaim/gtk/debug/toolbar")) { |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
361 /* Setup our top button bar thingie. */ |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
362 toolbar = gtk_toolbar_new(); |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
363 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH_HORIZ); |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
364 gtk_toolbar_set_icon_size(GTK_TOOLBAR(toolbar), |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
365 GTK_ICON_SIZE_SMALL_TOOLBAR); |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
366 |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
367 gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0); |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
368 |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
369 /* Find button */ |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
370 gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_FIND, |
8953 | 371 NULL, NULL, G_CALLBACK(find_cb), win, -1); |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
372 |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
373 /* Save */ |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
374 gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_SAVE, |
8953 | 375 NULL, NULL, G_CALLBACK(save_cb), win, -1); |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
376 |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
377 /* Clear button */ |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
378 gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_CLEAR, |
5794
5e93fc46d1af
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5738
diff
changeset
|
379 NULL, NULL, G_CALLBACK(clear_cb), win, -1); |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
380 |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
381 gtk_toolbar_insert_space(GTK_TOOLBAR(toolbar), -1); |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
382 |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
383 /* Pause */ |
6094
538c522e36e1
[gaim-migrate @ 6553]
Christian Hammond <chipx86@chipx86.com>
parents:
6009
diff
changeset
|
384 image = gtk_image_new_from_stock(GAIM_STOCK_PAUSE, GTK_ICON_SIZE_MENU); |
538c522e36e1
[gaim-migrate @ 6553]
Christian Hammond <chipx86@chipx86.com>
parents:
6009
diff
changeset
|
385 button = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar), |
538c522e36e1
[gaim-migrate @ 6553]
Christian Hammond <chipx86@chipx86.com>
parents:
6009
diff
changeset
|
386 GTK_TOOLBAR_CHILD_TOGGLEBUTTON, |
538c522e36e1
[gaim-migrate @ 6553]
Christian Hammond <chipx86@chipx86.com>
parents:
6009
diff
changeset
|
387 NULL, _("Pause"), NULL, NULL, |
538c522e36e1
[gaim-migrate @ 6553]
Christian Hammond <chipx86@chipx86.com>
parents:
6009
diff
changeset
|
388 image, G_CALLBACK(pause_cb), win); |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
389 |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
390 /* Timestamps */ |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
391 button = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar), |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
392 GTK_TOOLBAR_CHILD_TOGGLEBUTTON, |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
393 NULL, _("Timestamps"), NULL, NULL, |
5794
5e93fc46d1af
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5738
diff
changeset
|
394 NULL, G_CALLBACK(timestamps_cb), |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
395 win); |
8953 | 396 |
397 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), | |
8002
c94f2dad3b73
[gaim-migrate @ 8679]
Christian Hammond <chipx86@chipx86.com>
parents:
7229
diff
changeset
|
398 gaim_prefs_get_bool("/gaim/gtk/debug/timestamps")); |
8953 | 399 |
5704
aa8dbb7e0a4d
[gaim-migrate @ 6125]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
400 win->timestamps_handle = |
aa8dbb7e0a4d
[gaim-migrate @ 6125]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
401 gaim_prefs_connect_callback("/gaim/gtk/debug/timestamps", |
aa8dbb7e0a4d
[gaim-migrate @ 6125]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
402 timestamps_pref_cb, button); |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
403 } |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
404 |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
405 /* Now our scrolled window... */ |
5212 | 406 sw = gtk_scrolled_window_new(NULL, NULL); |
407 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
408 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
409 gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw), |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
410 GTK_SHADOW_IN); |
5212 | 411 |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
412 /* ... which has a gtkimhtml in it. */ |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
413 win->text = gtk_imhtml_new(NULL, NULL); |
5212 | 414 |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
415 gtk_container_add(GTK_CONTAINER(sw), win->text); |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
416 |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
417 /* Pack it in... Not like that, sicko. */ |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
418 gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0); |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
419 |
5212 | 420 gtk_widget_show_all(win->window); |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
421 |
5212 | 422 return win; |
423 } | |
424 | |
5625
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
425 static void |
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
426 debug_enabled_cb(const char *name, GaimPrefType type, gpointer value, |
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
427 gpointer data) |
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
428 { |
5636 | 429 if (value) |
5625
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
430 gaim_gtk_debug_window_show(); |
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
431 else |
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
432 gaim_gtk_debug_window_hide(); |
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
433 } |
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
434 |
7150 | 435 static void |
436 gaim_glib_log_handler(const gchar *domain, GLogLevelFlags flags, | |
437 const gchar *msg, gpointer user_data) | |
438 { | |
439 GaimDebugLevel level; | |
440 char *new_msg = NULL; | |
441 char *new_domain = NULL; | |
442 | |
7152
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
443 if ((flags & G_LOG_LEVEL_ERROR) == G_LOG_LEVEL_ERROR) |
7150 | 444 level = GAIM_DEBUG_ERROR; |
7152
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
445 else if ((flags & G_LOG_LEVEL_CRITICAL) == G_LOG_LEVEL_CRITICAL) |
7150 | 446 level = GAIM_DEBUG_FATAL; |
7152
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
447 else if ((flags & G_LOG_LEVEL_WARNING) == G_LOG_LEVEL_WARNING) |
7150 | 448 level = GAIM_DEBUG_WARNING; |
7152
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
449 else if ((flags & G_LOG_LEVEL_MESSAGE) == G_LOG_LEVEL_MESSAGE) |
7150 | 450 level = GAIM_DEBUG_INFO; |
7152
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
451 else if ((flags & G_LOG_LEVEL_INFO) == G_LOG_LEVEL_INFO) |
7150 | 452 level = GAIM_DEBUG_INFO; |
7152
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
453 else if ((flags & G_LOG_LEVEL_DEBUG) == G_LOG_LEVEL_DEBUG) |
7150 | 454 level = GAIM_DEBUG_MISC; |
7152
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
455 else |
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
456 { |
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
457 gaim_debug_warning("gtkdebug", |
7150 | 458 "Unknown glib logging level in %d\n", flags); |
459 | |
460 level = GAIM_DEBUG_MISC; /* This will never happen. */ | |
461 } | |
462 | |
463 if (msg != NULL) | |
464 new_msg = gaim_utf8_try_convert(msg); | |
465 | |
466 if (domain != NULL) | |
467 new_domain = gaim_utf8_try_convert(domain); | |
468 | |
7152
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
469 if (new_msg != NULL) |
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
470 { |
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
471 gaim_debug(level, (new_domain != NULL ? new_domain : "g_log"), |
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
472 "%s\n", new_msg); |
7150 | 473 |
474 g_free(new_msg); | |
475 } | |
476 | |
477 if (new_domain != NULL) | |
478 g_free(new_domain); | |
479 } | |
480 | |
481 #ifdef _WIN32 | |
482 static void | |
483 gaim_glib_dummy_print_handler(const gchar *string) | |
484 { | |
485 } | |
486 #endif | |
487 | |
5625
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
488 void |
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
489 gaim_gtk_debug_init(void) |
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
490 { |
5684 | 491 /* Debug window preferences. */ |
492 /* | |
493 * NOTE: This must be set before prefs are loaded, and the callbacks | |
494 * set after they are loaded, since prefs sets the enabled | |
495 * preference here and that loads the window, which calls the | |
8735
92cbf9713795
[gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents:
8046
diff
changeset
|
496 * configure event, which overrides the width and height! :P |
5684 | 497 */ |
498 | |
499 gaim_prefs_add_none("/gaim/gtk/debug"); | |
500 gaim_prefs_add_bool("/gaim/gtk/debug/enabled", FALSE); | |
501 gaim_prefs_add_bool("/gaim/gtk/debug/timestamps", FALSE); | |
502 gaim_prefs_add_bool("/gaim/gtk/debug/toolbar", TRUE); | |
503 gaim_prefs_add_int("/gaim/gtk/debug/width", 450); | |
504 gaim_prefs_add_int("/gaim/gtk/debug/height", 250); | |
505 | |
5625
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
506 gaim_prefs_connect_callback("/gaim/gtk/debug/enabled", |
5794
5e93fc46d1af
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5738
diff
changeset
|
507 debug_enabled_cb, NULL); |
7150 | 508 |
509 #define REGISTER_G_LOG_HANDLER(name) \ | |
510 g_log_set_handler((name), G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL \ | |
511 | G_LOG_FLAG_RECURSION, \ | |
512 gaim_glib_log_handler, NULL) | |
513 | |
514 /* Register the glib/gtk log handlers. */ | |
515 REGISTER_G_LOG_HANDLER(NULL); | |
516 REGISTER_G_LOG_HANDLER("Gdk"); | |
517 REGISTER_G_LOG_HANDLER("Gtk"); | |
7229
26fe5055e0b0
[gaim-migrate @ 7799]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7152
diff
changeset
|
518 REGISTER_G_LOG_HANDLER("GdkPixbuf"); |
7150 | 519 REGISTER_G_LOG_HANDLER("GLib"); |
520 REGISTER_G_LOG_HANDLER("GModule"); | |
521 REGISTER_G_LOG_HANDLER("GLib-GObject"); | |
522 REGISTER_G_LOG_HANDLER("GThread"); | |
523 | |
524 #ifdef _WIN32 | |
525 if (!opt_debug) | |
526 g_set_print_handler(gaim_glib_dummy_print_handler); | |
527 #endif | |
5625
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
528 } |
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
529 |
5212 | 530 void |
531 gaim_gtk_debug_window_show(void) | |
532 { | |
533 if (debug_win == NULL) | |
534 debug_win = debug_window_new(); | |
535 | |
536 gtk_widget_show(debug_win->window); | |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
537 |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
538 gaim_prefs_set_bool("/gaim/gtk/debug/enabled", TRUE); |
5212 | 539 } |
540 | |
541 void | |
542 gaim_gtk_debug_window_hide(void) | |
543 { | |
544 if (debug_win != NULL) { | |
545 gtk_widget_destroy(debug_win->window); | |
546 debug_window_destroy(NULL, NULL, NULL); | |
547 } | |
548 } | |
549 | |
550 static void | |
551 gaim_gtk_debug_print(GaimDebugLevel level, const char *category, | |
552 const char *format, va_list args) | |
553 { | |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
554 gchar *arg_s, *ts_s; |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
555 gboolean timestamps; |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
556 |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
557 timestamps = gaim_prefs_get_bool("/gaim/gtk/debug/timestamps"); |
5212 | 558 |
559 arg_s = g_strdup_vprintf(format, args); | |
560 | |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
561 if (category == NULL) { |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
562 ts_s = g_strdup(""); |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
563 } |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
564 else { |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
565 /* |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
566 * If the category is not NULL, then do timestamps. |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
567 * This IS right. :) |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
568 */ |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
569 if (timestamps) { |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
570 gchar mdate[64]; |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
571 time_t mtime = time(NULL); |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
572 |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
573 strftime(mdate, sizeof(mdate), "%H:%M:%S", localtime(&mtime)); |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
574 |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
575 ts_s = g_strdup_printf("(%s) ", mdate); |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
576 } |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
577 else |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
578 ts_s = g_strdup(""); |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
579 } |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
580 |
5535 | 581 if (gaim_prefs_get_bool("/gaim/gtk/debug/enabled") && |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
582 debug_win != NULL && !debug_win->paused) { |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
583 |
5738
ec032cb2f9ec
[gaim-migrate @ 6162]
Christian Hammond <chipx86@chipx86.com>
parents:
5704
diff
changeset
|
584 gchar *esc_s, *cat_s, *utf8_s, *s; |
5212 | 585 |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
586 if (category == NULL) |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
587 cat_s = g_strdup(""); |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
588 else |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
589 cat_s = g_strdup_printf("<b>%s:</b> ", category); |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
590 |
5212 | 591 esc_s = g_markup_escape_text(arg_s, -1); |
592 | |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
593 s = g_strdup_printf("<font color=\"%s\">%s%s%s</font>", |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
594 debug_fg_colors[level], ts_s, cat_s, esc_s); |
5212 | 595 |
596 g_free(esc_s); | |
597 | |
7108
6faeeecab0dc
[gaim-migrate @ 7673]
Christian Hammond <chipx86@chipx86.com>
parents:
7035
diff
changeset
|
598 utf8_s = gaim_utf8_try_convert(s); |
5738
ec032cb2f9ec
[gaim-migrate @ 6162]
Christian Hammond <chipx86@chipx86.com>
parents:
5704
diff
changeset
|
599 g_free(s); |
ec032cb2f9ec
[gaim-migrate @ 6162]
Christian Hammond <chipx86@chipx86.com>
parents:
5704
diff
changeset
|
600 s = utf8_s; |
ec032cb2f9ec
[gaim-migrate @ 6162]
Christian Hammond <chipx86@chipx86.com>
parents:
5704
diff
changeset
|
601 |
5212 | 602 if (level == GAIM_DEBUG_FATAL) { |
603 gchar *temp = s; | |
604 | |
605 s = g_strdup_printf("<b>%s</b>", temp); | |
606 g_free(temp); | |
607 } | |
608 | |
609 g_free(cat_s); | |
610 | |
6982 | 611 gtk_imhtml_append_text(GTK_IMHTML(debug_win->text), s, 0); |
5212 | 612 |
613 g_free(s); | |
614 } | |
615 | |
5214
7ea282e1f615
[gaim-migrate @ 5584]
Christian Hammond <chipx86@chipx86.com>
parents:
5212
diff
changeset
|
616 if (opt_debug) { |
7ea282e1f615
[gaim-migrate @ 5584]
Christian Hammond <chipx86@chipx86.com>
parents:
5212
diff
changeset
|
617 if (category == NULL) |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
618 g_print("%s%s", ts_s, arg_s); |
5214
7ea282e1f615
[gaim-migrate @ 5584]
Christian Hammond <chipx86@chipx86.com>
parents:
5212
diff
changeset
|
619 else |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
620 g_print("%s%s: %s", ts_s, category, arg_s); |
5214
7ea282e1f615
[gaim-migrate @ 5584]
Christian Hammond <chipx86@chipx86.com>
parents:
5212
diff
changeset
|
621 } |
5212 | 622 |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
623 g_free(ts_s); |
5212 | 624 g_free(arg_s); |
625 } | |
626 | |
627 static GaimDebugUiOps ops = | |
628 { | |
629 gaim_gtk_debug_print | |
630 }; | |
631 | |
632 GaimDebugUiOps * | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
633 gaim_gtk_debug_get_ui_ops(void) |
5212 | 634 { |
635 return &ops; | |
636 } |