Mercurial > pidgin
annotate src/gtkdebug.c @ 10924:7a82d86ab44a
[gaim-migrate @ 12695]
Don't try to use a NULL value in printf. Also eliminate an outdated win32 GTK+ bug workaround hack.
committer: Tailor Script <tailor@pidgin.im>
author | Daniel Atallah <daniel.atallah@gmail.com> |
---|---|
date | Mon, 16 May 2005 18:24:30 +0000 |
parents | 42dbc4ba1325 |
children | 50224ac8184d |
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 */ | |
9791 | 25 #include "internal.h" |
26 #include "gtkgaim.h" | |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5818
diff
changeset
|
27 |
9480 | 28 #include "notify.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5818
diff
changeset
|
29 #include "prefs.h" |
8953 | 30 #include "request.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5818
diff
changeset
|
31 #include "util.h" |
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5818
diff
changeset
|
32 |
5212 | 33 #include "gtkdebug.h" |
9709 | 34 #include "gtkdialogs.h" |
5212 | 35 #include "gtkimhtml.h" |
8953 | 36 #include "gtkutils.h" |
10297
ec140184437b
[gaim-migrate @ 11480]
Luke Schierer <lschiere@pidgin.im>
parents:
10175
diff
changeset
|
37 #include "gtkstock.h" |
5872
059d95c67cda
[gaim-migrate @ 6304]
Christian Hammond <chipx86@chipx86.com>
parents:
5818
diff
changeset
|
38 |
5212 | 39 typedef struct |
40 { | |
41 GtkWidget *window; | |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
42 GtkWidget *text; |
8953 | 43 GtkWidget *find; |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
44 |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
45 gboolean timestamps; |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
46 gboolean paused; |
5212 | 47 |
48 } DebugWindow; | |
49 | |
50 static char debug_fg_colors[][8] = { | |
51 "#000000", /**< All debug levels. */ | |
7150 | 52 "#666666", /**< Misc. */ |
5212 | 53 "#000000", /**< Information. */ |
54 "#660000", /**< Warnings. */ | |
55 "#FF0000", /**< Errors. */ | |
56 "#FF0000", /**< Fatal errors. */ | |
57 }; | |
58 | |
59 static DebugWindow *debug_win = NULL; | |
60 | |
8953 | 61 struct _find { |
62 DebugWindow *window; | |
63 GtkWidget *entry; | |
64 }; | |
65 | |
5212 | 66 static gint |
67 debug_window_destroy(GtkWidget *w, GdkEvent *event, void *unused) | |
68 { | |
10087 | 69 gaim_prefs_disconnect_by_handle(gaim_gtk_debug_get_handle()); |
9502 | 70 |
71 /* If the "Save Log" dialog is open then close it */ | |
72 gaim_request_close_with_handle(debug_win); | |
5704
aa8dbb7e0a4d
[gaim-migrate @ 6125]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
73 |
5212 | 74 g_free(debug_win); |
75 debug_win = NULL; | |
76 | |
9480 | 77 gaim_prefs_set_bool("/gaim/gtk/debug/enabled", FALSE); |
78 | |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
79 return FALSE; |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
80 } |
5212 | 81 |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
82 static gboolean |
5794
5e93fc46d1af
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5738
diff
changeset
|
83 configure_cb(GtkWidget *w, GdkEventConfigure *event, DebugWindow *win) |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
84 { |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
85 if (GTK_WIDGET_VISIBLE(w)) { |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
86 gaim_prefs_set_int("/gaim/gtk/debug/width", event->width); |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
87 gaim_prefs_set_int("/gaim/gtk/debug/height", event->height); |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
88 } |
5212 | 89 |
90 return FALSE; | |
91 } | |
92 | |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
93 static void |
9482 | 94 do_find_cb(GtkWidget *widget, gint response, struct _find *f) |
8953 | 95 { |
9482 | 96 switch (response) { |
8953 | 97 case GTK_RESPONSE_OK: |
98 gtk_imhtml_search_find(GTK_IMHTML(f->window->text), | |
99 gtk_entry_get_text(GTK_ENTRY(f->entry))); | |
100 break; | |
101 | |
102 case GTK_RESPONSE_DELETE_EVENT: | |
103 case GTK_RESPONSE_CLOSE: | |
104 gtk_imhtml_search_clear(GTK_IMHTML(f->window->text)); | |
105 gtk_widget_destroy(f->window->find); | |
106 f->window->find = NULL; | |
107 g_free(f); | |
108 break; | |
109 } | |
110 } | |
111 | |
112 static void | |
113 find_cb(GtkWidget *w, DebugWindow *win) | |
114 { | |
115 GtkWidget *hbox, *img, *label; | |
116 struct _find *f; | |
117 | |
118 if(win->find) | |
119 { | |
120 gtk_window_present(GTK_WINDOW(win->find)); | |
121 return; | |
122 } | |
123 | |
124 f = g_malloc(sizeof(struct _find)); | |
125 f->window = win; | |
126 win->find = gtk_dialog_new_with_buttons(_("Find"), | |
127 GTK_WINDOW(win->window), GTK_DIALOG_DESTROY_WITH_PARENT, | |
128 GTK_STOCK_CLOSE, GTK_RESPONSE_CLOSE, | |
129 GTK_STOCK_FIND, GTK_RESPONSE_OK, NULL); | |
130 gtk_dialog_set_default_response(GTK_DIALOG(win->find), | |
131 GTK_RESPONSE_OK); | |
132 g_signal_connect(G_OBJECT(win->find), "response", | |
133 G_CALLBACK(do_find_cb), f); | |
134 | |
135 gtk_container_set_border_width(GTK_CONTAINER(win->find), 6); | |
136 gtk_window_set_resizable(GTK_WINDOW(win->find), FALSE); | |
137 gtk_dialog_set_has_separator(GTK_DIALOG(win->find), FALSE); | |
138 gtk_box_set_spacing(GTK_BOX(GTK_DIALOG(win->find)->vbox), 12); | |
139 gtk_container_set_border_width( | |
140 GTK_CONTAINER(GTK_DIALOG(win->find)->vbox), 6); | |
141 | |
142 hbox = gtk_hbox_new(FALSE, 12); | |
143 gtk_container_add(GTK_CONTAINER(GTK_DIALOG(win->find)->vbox), | |
144 hbox); | |
145 img = gtk_image_new_from_stock(GAIM_STOCK_DIALOG_QUESTION, | |
146 GTK_ICON_SIZE_DIALOG); | |
147 gtk_box_pack_start(GTK_BOX(hbox), img, FALSE, FALSE, 0); | |
148 | |
149 gtk_misc_set_alignment(GTK_MISC(img), 0, 0); | |
150 gtk_dialog_set_response_sensitive(GTK_DIALOG(win->find), | |
151 GTK_RESPONSE_OK, FALSE); | |
152 | |
153 label = gtk_label_new(NULL); | |
154 gtk_label_set_markup_with_mnemonic(GTK_LABEL(label), _("_Search for:")); | |
155 gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 0); | |
156 | |
157 f->entry = gtk_entry_new(); | |
158 gtk_entry_set_activates_default(GTK_ENTRY(f->entry), TRUE); | |
159 gtk_label_set_mnemonic_widget(GTK_LABEL(label), GTK_WIDGET(f->entry)); | |
160 g_signal_connect(G_OBJECT(f->entry), "changed", | |
161 G_CALLBACK(gaim_gtk_set_sensitive_if_input), | |
162 win->find); | |
163 gtk_box_pack_start(GTK_BOX(hbox), f->entry, FALSE, FALSE, 0); | |
164 | |
165 gtk_widget_show_all(win->find); | |
166 gtk_widget_grab_focus(f->entry); | |
167 } | |
168 | |
169 static void | |
9502 | 170 save_writefile_cb(void *user_data, const char *filename) |
8953 | 171 { |
9502 | 172 DebugWindow *win = (DebugWindow *)user_data; |
9489 | 173 FILE *fp; |
8953 | 174 char *tmp; |
175 | |
10589
0f7452b1f777
[gaim-migrate @ 11994]
Daniel Atallah <daniel.atallah@gmail.com>
parents:
10448
diff
changeset
|
176 if ((fp = g_fopen(filename, "w+")) == NULL) { |
9502 | 177 gaim_notify_error(win, NULL, _("Unable to open file."), NULL); |
8953 | 178 return; |
9480 | 179 } |
8953 | 180 |
9489 | 181 tmp = gtk_imhtml_get_text(GTK_IMHTML(win->text), NULL, NULL); |
8953 | 182 fprintf(fp, "Gaim Debug log : %s\n", gaim_date_full()); |
183 fprintf(fp, "%s", tmp); | |
184 g_free(tmp); | |
185 | |
186 fclose(fp); | |
187 } | |
188 | |
189 static void | |
190 save_cb(GtkWidget *w, DebugWindow *win) | |
191 { | |
9502 | 192 gaim_request_file(win, _("Save Debug Log"), "gaim-debug.log", TRUE, |
193 G_CALLBACK(save_writefile_cb), NULL, win); | |
8953 | 194 } |
195 | |
196 static void | |
5794
5e93fc46d1af
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5738
diff
changeset
|
197 clear_cb(GtkWidget *w, DebugWindow *win) |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
198 { |
6280
d330afe3ccf0
[gaim-migrate @ 6779]
Christian Hammond <chipx86@chipx86.com>
parents:
6094
diff
changeset
|
199 gtk_imhtml_clear(GTK_IMHTML(win->text)); |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
200 } |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
201 |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
202 static void |
5794
5e93fc46d1af
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5738
diff
changeset
|
203 pause_cb(GtkWidget *w, DebugWindow *win) |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
204 { |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
205 win->paused = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)); |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
206 } |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
207 |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
208 static void |
5794
5e93fc46d1af
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5738
diff
changeset
|
209 timestamps_cb(GtkWidget *w, DebugWindow *win) |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
210 { |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
211 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
|
212 |
10307 | 213 gaim_prefs_set_bool("/core/debug/timestamps", win->timestamps); |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
214 } |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
215 |
5704
aa8dbb7e0a4d
[gaim-migrate @ 6125]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
216 static void |
aa8dbb7e0a4d
[gaim-migrate @ 6125]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
217 timestamps_pref_cb(const char *name, GaimPrefType type, gpointer value, |
aa8dbb7e0a4d
[gaim-migrate @ 6125]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
218 gpointer data) |
aa8dbb7e0a4d
[gaim-migrate @ 6125]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
219 { |
6478
338147ea6896
[gaim-migrate @ 6991]
Christian Hammond <chipx86@chipx86.com>
parents:
6371
diff
changeset
|
220 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
|
221 } |
aa8dbb7e0a4d
[gaim-migrate @ 6125]
Christian Hammond <chipx86@chipx86.com>
parents:
5684
diff
changeset
|
222 |
5212 | 223 static DebugWindow * |
224 debug_window_new(void) | |
225 { | |
226 DebugWindow *win; | |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
227 GtkWidget *vbox; |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
228 GtkWidget *toolbar; |
10175 | 229 GtkWidget *frame; |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
230 GtkWidget *button; |
6094
538c522e36e1
[gaim-migrate @ 6553]
Christian Hammond <chipx86@chipx86.com>
parents:
6009
diff
changeset
|
231 GtkWidget *image; |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
232 int width, height; |
5212 | 233 |
234 win = g_new0(DebugWindow, 1); | |
235 | |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
236 width = gaim_prefs_get_int("/gaim/gtk/debug/width"); |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
237 height = gaim_prefs_get_int("/gaim/gtk/debug/height"); |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
238 |
5212 | 239 GAIM_DIALOG(win->window); |
10309 | 240 gaim_debug_info("gtkdebug", "Setting dimensions to %d, %d\n", |
5642
1693a3027dc8
[gaim-migrate @ 6056]
Christian Hammond <chipx86@chipx86.com>
parents:
5636
diff
changeset
|
241 width, height); |
1693a3027dc8
[gaim-migrate @ 6056]
Christian Hammond <chipx86@chipx86.com>
parents:
5636
diff
changeset
|
242 |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
243 gtk_window_set_default_size(GTK_WINDOW(win->window), width, height); |
5212 | 244 gtk_window_set_role(GTK_WINDOW(win->window), "debug"); |
245 gtk_window_set_title(GTK_WINDOW(win->window), _("Debug Window")); | |
246 | |
247 g_signal_connect(G_OBJECT(win->window), "delete_event", | |
248 G_CALLBACK(debug_window_destroy), NULL); | |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
249 g_signal_connect(G_OBJECT(win->window), "configure_event", |
5794
5e93fc46d1af
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5738
diff
changeset
|
250 G_CALLBACK(configure_cb), win); |
5212 | 251 |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
252 /* Setup the vbox */ |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
253 vbox = gtk_vbox_new(FALSE, 0); |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
254 gtk_container_add(GTK_CONTAINER(win->window), vbox); |
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
255 |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
256 if (gaim_prefs_get_bool("/gaim/gtk/debug/toolbar")) { |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
257 /* Setup our top button bar thingie. */ |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
258 toolbar = gtk_toolbar_new(); |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
259 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH_HORIZ); |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
260 gtk_toolbar_set_icon_size(GTK_TOOLBAR(toolbar), |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
261 GTK_ICON_SIZE_SMALL_TOOLBAR); |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
262 |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
263 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
|
264 |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
265 /* Find button */ |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
266 gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_FIND, |
8953 | 267 NULL, NULL, G_CALLBACK(find_cb), win, -1); |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
268 |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
269 /* Save */ |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
270 gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_SAVE, |
8953 | 271 NULL, NULL, G_CALLBACK(save_cb), win, -1); |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
272 |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
273 /* Clear button */ |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
274 gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_CLEAR, |
5794
5e93fc46d1af
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5738
diff
changeset
|
275 NULL, NULL, G_CALLBACK(clear_cb), win, -1); |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
276 |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
277 gtk_toolbar_insert_space(GTK_TOOLBAR(toolbar), -1); |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
278 |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
279 /* Pause */ |
6094
538c522e36e1
[gaim-migrate @ 6553]
Christian Hammond <chipx86@chipx86.com>
parents:
6009
diff
changeset
|
280 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
|
281 button = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar), |
538c522e36e1
[gaim-migrate @ 6553]
Christian Hammond <chipx86@chipx86.com>
parents:
6009
diff
changeset
|
282 GTK_TOOLBAR_CHILD_TOGGLEBUTTON, |
538c522e36e1
[gaim-migrate @ 6553]
Christian Hammond <chipx86@chipx86.com>
parents:
6009
diff
changeset
|
283 NULL, _("Pause"), NULL, NULL, |
538c522e36e1
[gaim-migrate @ 6553]
Christian Hammond <chipx86@chipx86.com>
parents:
6009
diff
changeset
|
284 image, G_CALLBACK(pause_cb), win); |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
285 |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
286 /* Timestamps */ |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
287 button = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar), |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
288 GTK_TOOLBAR_CHILD_TOGGLEBUTTON, |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
289 NULL, _("Timestamps"), NULL, NULL, |
5794
5e93fc46d1af
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5738
diff
changeset
|
290 NULL, G_CALLBACK(timestamps_cb), |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
291 win); |
8953 | 292 |
293 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), | |
10307 | 294 gaim_prefs_get_bool("/core/debug/timestamps")); |
8953 | 295 |
10307 | 296 gaim_prefs_connect_callback(gaim_gtk_debug_get_handle(), "/core/debug/timestamps", |
10087 | 297 timestamps_pref_cb, button); |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
298 } |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
299 |
10175 | 300 /* Add the gtkimhtml */ |
301 frame = gaim_gtk_create_imhtml(FALSE, &win->text, NULL); | |
10739 | 302 gtk_imhtml_set_format_functions(GTK_IMHTML(win->text), |
303 GTK_IMHTML_ALL ^ GTK_IMHTML_SMILEY ^ GTK_IMHTML_IMAGE); | |
10175 | 304 gtk_box_pack_start(GTK_BOX(vbox), frame, TRUE, TRUE, 0); |
305 gtk_widget_show(frame); | |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
306 |
5212 | 307 gtk_widget_show_all(win->window); |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
308 |
5212 | 309 return win; |
310 } | |
311 | |
5625
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
312 static void |
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
313 debug_enabled_cb(const char *name, GaimPrefType type, gpointer value, |
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
314 gpointer data) |
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
315 { |
5636 | 316 if (value) |
5625
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
317 gaim_gtk_debug_window_show(); |
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
318 else |
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
319 gaim_gtk_debug_window_hide(); |
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
320 } |
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
321 |
7150 | 322 static void |
323 gaim_glib_log_handler(const gchar *domain, GLogLevelFlags flags, | |
324 const gchar *msg, gpointer user_data) | |
325 { | |
326 GaimDebugLevel level; | |
327 char *new_msg = NULL; | |
328 char *new_domain = NULL; | |
329 | |
7152
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
330 if ((flags & G_LOG_LEVEL_ERROR) == G_LOG_LEVEL_ERROR) |
7150 | 331 level = GAIM_DEBUG_ERROR; |
7152
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
332 else if ((flags & G_LOG_LEVEL_CRITICAL) == G_LOG_LEVEL_CRITICAL) |
7150 | 333 level = GAIM_DEBUG_FATAL; |
7152
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
334 else if ((flags & G_LOG_LEVEL_WARNING) == G_LOG_LEVEL_WARNING) |
7150 | 335 level = GAIM_DEBUG_WARNING; |
7152
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
336 else if ((flags & G_LOG_LEVEL_MESSAGE) == G_LOG_LEVEL_MESSAGE) |
7150 | 337 level = GAIM_DEBUG_INFO; |
7152
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
338 else if ((flags & G_LOG_LEVEL_INFO) == G_LOG_LEVEL_INFO) |
7150 | 339 level = GAIM_DEBUG_INFO; |
7152
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
340 else if ((flags & G_LOG_LEVEL_DEBUG) == G_LOG_LEVEL_DEBUG) |
7150 | 341 level = GAIM_DEBUG_MISC; |
7152
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
342 else |
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
343 { |
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
344 gaim_debug_warning("gtkdebug", |
7150 | 345 "Unknown glib logging level in %d\n", flags); |
346 | |
347 level = GAIM_DEBUG_MISC; /* This will never happen. */ | |
348 } | |
349 | |
350 if (msg != NULL) | |
351 new_msg = gaim_utf8_try_convert(msg); | |
352 | |
353 if (domain != NULL) | |
354 new_domain = gaim_utf8_try_convert(domain); | |
355 | |
7152
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
356 if (new_msg != NULL) |
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
357 { |
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
358 gaim_debug(level, (new_domain != NULL ? new_domain : "g_log"), |
cada5ddc21f5
[gaim-migrate @ 7719]
Christian Hammond <chipx86@chipx86.com>
parents:
7150
diff
changeset
|
359 "%s\n", new_msg); |
7150 | 360 |
361 g_free(new_msg); | |
362 } | |
363 | |
364 if (new_domain != NULL) | |
365 g_free(new_domain); | |
366 } | |
367 | |
368 #ifdef _WIN32 | |
369 static void | |
370 gaim_glib_dummy_print_handler(const gchar *string) | |
371 { | |
372 } | |
373 #endif | |
374 | |
5625
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
375 void |
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
376 gaim_gtk_debug_init(void) |
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
377 { |
5684 | 378 /* Debug window preferences. */ |
379 /* | |
380 * NOTE: This must be set before prefs are loaded, and the callbacks | |
381 * set after they are loaded, since prefs sets the enabled | |
382 * preference here and that loads the window, which calls the | |
8735
92cbf9713795
[gaim-migrate @ 9490]
Christian Hammond <chipx86@chipx86.com>
parents:
8046
diff
changeset
|
383 * configure event, which overrides the width and height! :P |
5684 | 384 */ |
385 | |
386 gaim_prefs_add_none("/gaim/gtk/debug"); | |
10307 | 387 |
388 /* Controls printing to the debug window */ | |
5684 | 389 gaim_prefs_add_bool("/gaim/gtk/debug/enabled", FALSE); |
10307 | 390 |
5684 | 391 gaim_prefs_add_bool("/gaim/gtk/debug/toolbar", TRUE); |
392 gaim_prefs_add_int("/gaim/gtk/debug/width", 450); | |
393 gaim_prefs_add_int("/gaim/gtk/debug/height", 250); | |
394 | |
10087 | 395 gaim_prefs_connect_callback(NULL, "/gaim/gtk/debug/enabled", |
5794
5e93fc46d1af
[gaim-migrate @ 6219]
Christian Hammond <chipx86@chipx86.com>
parents:
5738
diff
changeset
|
396 debug_enabled_cb, NULL); |
7150 | 397 |
398 #define REGISTER_G_LOG_HANDLER(name) \ | |
399 g_log_set_handler((name), G_LOG_LEVEL_MASK | G_LOG_FLAG_FATAL \ | |
400 | G_LOG_FLAG_RECURSION, \ | |
401 gaim_glib_log_handler, NULL) | |
402 | |
403 /* Register the glib/gtk log handlers. */ | |
404 REGISTER_G_LOG_HANDLER(NULL); | |
405 REGISTER_G_LOG_HANDLER("Gdk"); | |
406 REGISTER_G_LOG_HANDLER("Gtk"); | |
7229
26fe5055e0b0
[gaim-migrate @ 7799]
Herman Bloggs <hermanator12002@yahoo.com>
parents:
7152
diff
changeset
|
407 REGISTER_G_LOG_HANDLER("GdkPixbuf"); |
7150 | 408 REGISTER_G_LOG_HANDLER("GLib"); |
409 REGISTER_G_LOG_HANDLER("GModule"); | |
410 REGISTER_G_LOG_HANDLER("GLib-GObject"); | |
411 REGISTER_G_LOG_HANDLER("GThread"); | |
412 | |
413 #ifdef _WIN32 | |
10314 | 414 if (!gaim_debug_is_enabled()) |
7150 | 415 g_set_print_handler(gaim_glib_dummy_print_handler); |
416 #endif | |
5625
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
417 } |
73c9dc20e41a
[gaim-migrate @ 6032]
Christian Hammond <chipx86@chipx86.com>
parents:
5535
diff
changeset
|
418 |
5212 | 419 void |
420 gaim_gtk_debug_window_show(void) | |
421 { | |
422 if (debug_win == NULL) | |
423 debug_win = debug_window_new(); | |
424 | |
425 gtk_widget_show(debug_win->window); | |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
426 |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
427 gaim_prefs_set_bool("/gaim/gtk/debug/enabled", TRUE); |
5212 | 428 } |
429 | |
430 void | |
431 gaim_gtk_debug_window_hide(void) | |
432 { | |
433 if (debug_win != NULL) { | |
434 gtk_widget_destroy(debug_win->window); | |
435 debug_window_destroy(NULL, NULL, NULL); | |
436 } | |
437 } | |
438 | |
439 static void | |
440 gaim_gtk_debug_print(GaimDebugLevel level, const char *category, | |
441 const char *format, va_list args) | |
442 { | |
10307 | 443 gboolean timestamps; |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
444 gchar *arg_s, *ts_s; |
10307 | 445 gchar *esc_s, *cat_s, *tmp, *s; |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
446 |
10307 | 447 if (!gaim_prefs_get_bool("/gaim/gtk/debug/enabled") || |
448 (debug_win == NULL) || debug_win->paused) { | |
449 return; | |
450 } | |
451 | |
452 timestamps = gaim_prefs_get_bool("/core/debug/timestamps"); | |
5212 | 453 |
454 arg_s = g_strdup_vprintf(format, args); | |
455 | |
10307 | 456 /* |
457 * For some reason we only print the timestamp if category is | |
458 * not NULL. Why the hell do we do that? --Mark | |
459 */ | |
460 if ((category != NULL) && (timestamps)) { | |
461 gchar mdate[64]; | |
462 | |
463 time_t mtime = time(NULL); | |
464 strftime(mdate, sizeof(mdate), "%H:%M:%S", localtime(&mtime)); | |
465 ts_s = g_strdup_printf("(%s) ", mdate); | |
466 } else { | |
5530
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
467 ts_s = g_strdup(""); |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
468 } |
2c4c975620f0
[gaim-migrate @ 5930]
Christian Hammond <chipx86@chipx86.com>
parents:
5430
diff
changeset
|
469 |
10307 | 470 if (category == NULL) |
471 cat_s = g_strdup(""); | |
472 else | |
473 cat_s = g_strdup_printf("<b>%s:</b> ", category); | |
5212 | 474 |
10307 | 475 esc_s = g_markup_escape_text(arg_s, -1); |
5428
96bde36bb76b
[gaim-migrate @ 5808]
Christian Hammond <chipx86@chipx86.com>
parents:
5314
diff
changeset
|
476 |
10307 | 477 g_free(arg_s); |
5212 | 478 |
10307 | 479 s = g_strdup_printf("<font color=\"%s\">%s%s%s</font>", |
480 debug_fg_colors[level], ts_s, cat_s, esc_s); | |
5212 | 481 |
10307 | 482 g_free(ts_s); |
483 g_free(cat_s); | |
484 g_free(esc_s); | |
5212 | 485 |
10307 | 486 tmp = gaim_utf8_try_convert(s); |
487 g_free(s); | |
488 s = tmp; | |
5212 | 489 |
10307 | 490 if (level == GAIM_DEBUG_FATAL) { |
491 tmp = g_strdup_printf("<b>%s</b>", s); | |
5212 | 492 g_free(s); |
10307 | 493 s = tmp; |
5212 | 494 } |
495 | |
10307 | 496 gtk_imhtml_append_text(GTK_IMHTML(debug_win->text), s, 0); |
5212 | 497 |
10307 | 498 g_free(s); |
5212 | 499 } |
500 | |
501 static GaimDebugUiOps ops = | |
502 { | |
503 gaim_gtk_debug_print | |
504 }; | |
505 | |
506 GaimDebugUiOps * | |
7035
feb3d21a7794
[gaim-migrate @ 7598]
Christian Hammond <chipx86@chipx86.com>
parents:
6982
diff
changeset
|
507 gaim_gtk_debug_get_ui_ops(void) |
5212 | 508 { |
509 return &ops; | |
510 } | |
10087 | 511 |
512 void * | |
513 gaim_gtk_debug_get_handle() { | |
514 static int handle; | |
515 | |
516 return &handle; | |
517 } |