Mercurial > pidgin
comparison src/gtkdebug.c @ 5530:2c4c975620f0
[gaim-migrate @ 5930]
Okay, several changes in this commit.
- We now have gtkprefs.h.
- We have a place where we can add UI prefs.
- show_prefs() -> gaim_gtk_prefs_show().
- make_frame() -> gaim_gtk_make_frame().
- The debug window is the first thing to have prefs. You can even
turn off the toolbar if you edit ~/.gaim/prefs.xml.
committer: Tailor Script <tailor@pidgin.im>
| author | Christian Hammond <chipx86@chipx86.com> |
|---|---|
| date | Mon, 26 May 2003 08:30:48 +0000 |
| parents | 908f3d9ee660 |
| children | 933739f789f9 |
comparison
equal
deleted
inserted
replaced
| 5529:e7747cae9710 | 5530:2c4c975620f0 |
|---|---|
| 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA | 21 * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA |
| 22 */ | 22 */ |
| 23 #include "gtkdebug.h" | 23 #include "gtkdebug.h" |
| 24 #include "gaim.h" | 24 #include "gaim.h" |
| 25 #include "gtkimhtml.h" | 25 #include "gtkimhtml.h" |
| 26 #include "prefs.h" | |
| 26 #include <gtk/gtk.h> | 27 #include <gtk/gtk.h> |
| 27 | 28 |
| 28 typedef struct | 29 typedef struct |
| 29 { | 30 { |
| 30 GtkWidget *window; | 31 GtkWidget *window; |
| 50 debug_window_destroy(GtkWidget *w, GdkEvent *event, void *unused) | 51 debug_window_destroy(GtkWidget *w, GdkEvent *event, void *unused) |
| 51 { | 52 { |
| 52 g_free(debug_win); | 53 g_free(debug_win); |
| 53 debug_win = NULL; | 54 debug_win = NULL; |
| 54 | 55 |
| 55 if (misc_options & OPT_MISC_DEBUG) | 56 gaim_prefs_set_bool("/gaim/gtk/debug/enabled", FALSE); |
| 56 misc_options ^= OPT_MISC_DEBUG; | |
| 57 | |
| 58 save_prefs(); | |
| 59 | 57 |
| 60 return FALSE; | 58 return FALSE; |
| 61 } | 59 } |
| 62 | 60 |
| 61 static gboolean | |
| 62 __configure_cb(GtkWidget *w, GdkEventConfigure *event, DebugWindow *win) | |
| 63 { | |
| 64 if (GTK_WIDGET_VISIBLE(w)) { | |
| 65 gaim_prefs_set_int("/gaim/gtk/debug/width", event->width); | |
| 66 gaim_prefs_set_int("/gaim/gtk/debug/height", event->height); | |
| 67 } | |
| 68 | |
| 69 return FALSE; | |
| 70 } | |
| 71 | |
| 63 static void | 72 static void |
| 64 __clear_cb(GtkWidget *w, DebugWindow *win) | 73 __clear_cb(GtkWidget *w, DebugWindow *win) |
| 65 { | 74 { |
| 66 gtk_imhtml_clear(GTK_IMHTML(win->text)); | 75 gtk_imhtml_clear(GTK_IMHTML(win->text)); |
| 67 } | 76 } |
| 74 | 83 |
| 75 static void | 84 static void |
| 76 __timestamps_cb(GtkWidget *w, DebugWindow *win) | 85 __timestamps_cb(GtkWidget *w, DebugWindow *win) |
| 77 { | 86 { |
| 78 win->timestamps = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)); | 87 win->timestamps = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w)); |
| 88 | |
| 89 gaim_prefs_set_bool("/gaim/gtk/debug/timestamps", win->timestamps); | |
| 90 | |
| 79 } | 91 } |
| 80 | 92 |
| 81 static DebugWindow * | 93 static DebugWindow * |
| 82 debug_window_new(void) | 94 debug_window_new(void) |
| 83 { | 95 { |
| 84 DebugWindow *win; | 96 DebugWindow *win; |
| 85 GtkWidget *vbox; | 97 GtkWidget *vbox; |
| 86 GtkWidget *toolbar; | 98 GtkWidget *toolbar; |
| 87 GtkWidget *sw; | 99 GtkWidget *sw; |
| 100 GtkWidget *button; | |
| 101 int width, height; | |
| 88 | 102 |
| 89 win = g_new0(DebugWindow, 1); | 103 win = g_new0(DebugWindow, 1); |
| 90 | 104 |
| 105 width = gaim_prefs_get_int("/gaim/gtk/debug/width"); | |
| 106 height = gaim_prefs_get_int("/gaim/gtk/debug/height"); | |
| 107 | |
| 91 GAIM_DIALOG(win->window); | 108 GAIM_DIALOG(win->window); |
| 92 gtk_window_set_default_size(GTK_WINDOW(win->window), 500, 200); | 109 gtk_window_set_default_size(GTK_WINDOW(win->window), width, height); |
| 93 gtk_window_set_role(GTK_WINDOW(win->window), "debug"); | 110 gtk_window_set_role(GTK_WINDOW(win->window), "debug"); |
| 94 gtk_window_set_title(GTK_WINDOW(win->window), _("Debug Window")); | 111 gtk_window_set_title(GTK_WINDOW(win->window), _("Debug Window")); |
| 95 | 112 |
| 96 g_signal_connect(G_OBJECT(win->window), "delete_event", | 113 g_signal_connect(G_OBJECT(win->window), "delete_event", |
| 97 G_CALLBACK(debug_window_destroy), NULL); | 114 G_CALLBACK(debug_window_destroy), NULL); |
| 115 g_signal_connect(G_OBJECT(win->window), "configure_event", | |
| 116 G_CALLBACK(__configure_cb), win); | |
| 98 | 117 |
| 99 /* Setup the vbox */ | 118 /* Setup the vbox */ |
| 100 vbox = gtk_vbox_new(FALSE, 0); | 119 vbox = gtk_vbox_new(FALSE, 0); |
| 101 gtk_container_add(GTK_CONTAINER(win->window), vbox); | 120 gtk_container_add(GTK_CONTAINER(win->window), vbox); |
| 102 | 121 |
| 103 /* Setup our top button bar thingie. */ | 122 if (gaim_prefs_get_bool("/gaim/gtk/debug/toolbar")) { |
| 104 toolbar = gtk_toolbar_new(); | 123 /* Setup our top button bar thingie. */ |
| 105 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH_HORIZ); | 124 toolbar = gtk_toolbar_new(); |
| 106 gtk_toolbar_set_icon_size(GTK_TOOLBAR(toolbar), | 125 gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_BOTH_HORIZ); |
| 107 GTK_ICON_SIZE_SMALL_TOOLBAR); | 126 gtk_toolbar_set_icon_size(GTK_TOOLBAR(toolbar), |
| 108 | 127 GTK_ICON_SIZE_SMALL_TOOLBAR); |
| 109 gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0); | 128 |
| 129 gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0); | |
| 110 | 130 |
| 111 #if 0 | 131 #if 0 |
| 112 /* Find button */ | 132 /* Find button */ |
| 113 gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_FIND, | 133 gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_FIND, |
| 114 NULL, NULL, NULL, NULL, -1); | 134 NULL, NULL, NULL, NULL, -1); |
| 115 | 135 |
| 116 /* Save */ | 136 /* Save */ |
| 117 gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_SAVE, | 137 gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_SAVE, |
| 118 NULL, NULL, NULL, NULL, -1); | 138 NULL, NULL, NULL, NULL, -1); |
| 119 #endif | 139 #endif |
| 120 | 140 |
| 121 /* Clear button */ | 141 /* Clear button */ |
| 122 gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_CLEAR, | 142 gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_CLEAR, |
| 123 NULL, NULL, G_CALLBACK(__clear_cb), win, -1); | 143 NULL, NULL, G_CALLBACK(__clear_cb), win, -1); |
| 124 | 144 |
| 125 gtk_toolbar_insert_space(GTK_TOOLBAR(toolbar), -1); | 145 gtk_toolbar_insert_space(GTK_TOOLBAR(toolbar), -1); |
| 126 | 146 |
| 127 /* Pause */ | 147 /* Pause */ |
| 128 gtk_toolbar_append_element(GTK_TOOLBAR(toolbar), | 148 gtk_toolbar_append_element(GTK_TOOLBAR(toolbar), |
| 129 GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL, | 149 GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL, |
| 130 _("Pause"), NULL, NULL, | 150 _("Pause"), NULL, NULL, |
| 131 NULL, G_CALLBACK(__pause_cb), win); | 151 NULL, G_CALLBACK(__pause_cb), win); |
| 132 | 152 |
| 133 /* Timestamps */ | 153 /* Timestamps */ |
| 134 gtk_toolbar_append_element(GTK_TOOLBAR(toolbar), | 154 button = gtk_toolbar_append_element(GTK_TOOLBAR(toolbar), |
| 135 GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL, | 155 GTK_TOOLBAR_CHILD_TOGGLEBUTTON, |
| 136 _("Timestamps"), NULL, NULL, | 156 NULL, _("Timestamps"), NULL, NULL, |
| 137 NULL, G_CALLBACK(__timestamps_cb), win); | 157 NULL, G_CALLBACK(__timestamps_cb), |
| 158 win); | |
| 159 | |
| 160 gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button), | |
| 161 gaim_prefs_get_bool("/gaim/gtk/debug/timestamps")); | |
| 162 } | |
| 138 | 163 |
| 139 /* Now our scrolled window... */ | 164 /* Now our scrolled window... */ |
| 140 sw = gtk_scrolled_window_new(NULL, NULL); | 165 sw = gtk_scrolled_window_new(NULL, NULL); |
| 141 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), | 166 gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw), |
| 142 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); | 167 GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS); |
| 161 { | 186 { |
| 162 if (debug_win == NULL) | 187 if (debug_win == NULL) |
| 163 debug_win = debug_window_new(); | 188 debug_win = debug_window_new(); |
| 164 | 189 |
| 165 gtk_widget_show(debug_win->window); | 190 gtk_widget_show(debug_win->window); |
| 191 | |
| 192 gaim_prefs_set_bool("/gaim/gtk/debug/enabled", TRUE); | |
| 166 } | 193 } |
| 167 | 194 |
| 168 void | 195 void |
| 169 gaim_gtk_debug_window_hide(void) | 196 gaim_gtk_debug_window_hide(void) |
| 170 { | 197 { |
| 176 | 203 |
| 177 static void | 204 static void |
| 178 gaim_gtk_debug_print(GaimDebugLevel level, const char *category, | 205 gaim_gtk_debug_print(GaimDebugLevel level, const char *category, |
| 179 const char *format, va_list args) | 206 const char *format, va_list args) |
| 180 { | 207 { |
| 181 gchar *arg_s; | 208 gchar *arg_s, *ts_s; |
| 209 gboolean timestamps; | |
| 210 | |
| 211 timestamps = gaim_prefs_get_bool("/gaim/gtk/debug/timestamps"); | |
| 182 | 212 |
| 183 arg_s = g_strdup_vprintf(format, args); | 213 arg_s = g_strdup_vprintf(format, args); |
| 214 | |
| 215 if (category == NULL) { | |
| 216 ts_s = g_strdup(""); | |
| 217 } | |
| 218 else { | |
| 219 /* | |
| 220 * If the category is not NULL, then do timestamps. | |
| 221 * This IS right. :) | |
| 222 */ | |
| 223 if (timestamps) { | |
| 224 gchar mdate[64]; | |
| 225 time_t mtime = time(NULL); | |
| 226 | |
| 227 strftime(mdate, sizeof(mdate), "%H:%M:%S", localtime(&mtime)); | |
| 228 | |
| 229 ts_s = g_strdup_printf("(%s) ", mdate); | |
| 230 } | |
| 231 else | |
| 232 ts_s = g_strdup(""); | |
| 233 } | |
| 184 | 234 |
| 185 if ((misc_options & OPT_MISC_DEBUG) && | 235 if ((misc_options & OPT_MISC_DEBUG) && |
| 186 debug_win != NULL && !debug_win->paused) { | 236 debug_win != NULL && !debug_win->paused) { |
| 187 | 237 |
| 188 gchar *esc_s, *cat_s, *ts_s, *s; | 238 gchar *esc_s, *cat_s, *s; |
| 189 | 239 |
| 190 if (category == NULL) { | 240 if (category == NULL) |
| 191 cat_s = g_strdup(""); | 241 cat_s = g_strdup(""); |
| 192 ts_s = g_strdup(""); | 242 else |
| 193 } | |
| 194 else { | |
| 195 cat_s = g_strdup_printf("<b>%s:</b> ", category); | 243 cat_s = g_strdup_printf("<b>%s:</b> ", category); |
| 196 | |
| 197 /* | |
| 198 * If the category is not NULL, then do timestamps. | |
| 199 * This IS right. :) | |
| 200 */ | |
| 201 if (debug_win->timestamps) { | |
| 202 gchar mdate[64]; | |
| 203 time_t mtime = time(NULL); | |
| 204 | |
| 205 strftime(mdate, sizeof(mdate), "%H:%M:%S", localtime(&mtime)); | |
| 206 | |
| 207 ts_s = g_strdup_printf("(%s) ", mdate); | |
| 208 } | |
| 209 else | |
| 210 ts_s = g_strdup(""); | |
| 211 } | |
| 212 | 244 |
| 213 esc_s = g_markup_escape_text(arg_s, -1); | 245 esc_s = g_markup_escape_text(arg_s, -1); |
| 214 | 246 |
| 215 s = g_strdup_printf("<font color=\"%s\">%s%s%s</font>", | 247 s = g_strdup_printf("<font color=\"%s\">%s%s%s</font>", |
| 216 debug_fg_colors[level], ts_s, cat_s, esc_s); | 248 debug_fg_colors[level], ts_s, cat_s, esc_s); |
| 217 | 249 |
| 218 g_free(ts_s); | |
| 219 g_free(esc_s); | 250 g_free(esc_s); |
| 220 | 251 |
| 221 if (level == GAIM_DEBUG_FATAL) { | 252 if (level == GAIM_DEBUG_FATAL) { |
| 222 gchar *temp = s; | 253 gchar *temp = s; |
| 223 | 254 |
| 232 g_free(s); | 263 g_free(s); |
| 233 } | 264 } |
| 234 | 265 |
| 235 if (opt_debug) { | 266 if (opt_debug) { |
| 236 if (category == NULL) | 267 if (category == NULL) |
| 237 g_print("%s", arg_s); | 268 g_print("%s%s", ts_s, arg_s); |
| 238 else | 269 else |
| 239 g_print("%s: %s", category, arg_s); | 270 g_print("%s%s: %s", ts_s, category, arg_s); |
| 240 } | 271 } |
| 241 | 272 |
| 273 g_free(ts_s); | |
| 242 g_free(arg_s); | 274 g_free(arg_s); |
| 243 } | 275 } |
| 244 | 276 |
| 245 static GaimDebugUiOps ops = | 277 static GaimDebugUiOps ops = |
| 246 { | 278 { |
