changeset 5428:96bde36bb76b

[gaim-migrate @ 5808] Let's see what the others think about this. I made some modifications to the debug window. There are now Clear, Pause, and Timestamp buttons. I have Find and Save #if 0'd out in the code, because I haven't written them, and I'm not sure when I will. For now, I like this. Oh, and the Jabber stuff no longer makes the window really wide. This was my fault. Fixed! :D Resize to your heart's content. Timestamps don't save. I won't implement this until we get new prefs ;) committer: Tailor Script <tailor@pidgin.im>
author Christian Hammond <chipx86@chipx86.com>
date Sun, 18 May 2003 09:08:42 +0000
parents 04e1e40b99b0
children 7d1a44cbd347
files src/gtkdebug.c
diffstat 1 files changed, 95 insertions(+), 11 deletions(-) [+]
line wrap: on
line diff
--- a/src/gtkdebug.c	Sun May 18 07:54:54 2003 +0000
+++ b/src/gtkdebug.c	Sun May 18 09:08:42 2003 +0000
@@ -28,7 +28,10 @@
 typedef struct
 {
 	GtkWidget *window;
-	GtkWidget *entry;
+	GtkWidget *text;
+
+	gboolean timestamps;
+	gboolean paused;
 
 } DebugWindow;
 
@@ -57,10 +60,30 @@
 	return FALSE;
 }
 
+static void
+__clear_cb(GtkWidget *w, DebugWindow *win)
+{
+	gtk_imhtml_clear(GTK_IMHTML(win->text));
+}
+
+static void
+__pause_cb(GtkWidget *w, DebugWindow *win)
+{
+	win->paused = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
+}
+
+static void
+__timestamps_cb(GtkWidget *w, DebugWindow *win)
+{
+	win->timestamps = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
+}
+
 static DebugWindow *
 debug_window_new(void)
 {
 	DebugWindow *win;
+	GtkWidget *vbox;
+	GtkWidget *toolbar;
 	GtkWidget *sw;
 
 	win = g_new0(DebugWindow, 1);
@@ -73,16 +96,61 @@
 	g_signal_connect(G_OBJECT(win->window), "delete_event",
 					 G_CALLBACK(debug_window_destroy), NULL);
 
+	/* Setup the vbox */
+	vbox = gtk_vbox_new(FALSE, 0);
+	gtk_container_add(GTK_CONTAINER(win->window), vbox);
+
+	/* Setup our top button bar thingie. */
+	toolbar = gtk_toolbar_new();
+	gtk_toolbar_set_style(GTK_TOOLBAR(toolbar), GTK_TOOLBAR_TEXT);
+
+	gtk_box_pack_start(GTK_BOX(vbox), toolbar, FALSE, FALSE, 0);
+
+#if 0
+	/* Find button */
+	gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_FIND,
+							 NULL, NULL, NULL, NULL, -1);
+
+	/* Save */
+	gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_SAVE,
+							 NULL, NULL, NULL, NULL, -1);
+#endif
+
+	/* Clear button */
+	gtk_toolbar_insert_stock(GTK_TOOLBAR(toolbar), GTK_STOCK_CLEAR,
+							 NULL, NULL, G_CALLBACK(__clear_cb), win, -1);
+
+	gtk_toolbar_insert_space(GTK_TOOLBAR(toolbar), -1);
+
+	/* Pause */
+	gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
+							   GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
+							   _("Pause"), NULL, NULL,
+							   NULL, G_CALLBACK(__pause_cb), win);
+
+	/* Timestamps */
+	gtk_toolbar_append_element(GTK_TOOLBAR(toolbar),
+							   GTK_TOOLBAR_CHILD_TOGGLEBUTTON, NULL,
+							   _("Timestamps"), NULL, NULL,
+							   NULL, G_CALLBACK(__timestamps_cb), win);
+
+	/* Now our scrolled window... */
 	sw = gtk_scrolled_window_new(NULL, NULL);
 	gtk_scrolled_window_set_policy(GTK_SCROLLED_WINDOW(sw),
-								   GTK_POLICY_NEVER, GTK_POLICY_ALWAYS);
+								   GTK_POLICY_AUTOMATIC, GTK_POLICY_ALWAYS);
+	gtk_scrolled_window_set_shadow_type(GTK_SCROLLED_WINDOW(sw),
+										GTK_SHADOW_IN);
 
-	win->entry = gtk_imhtml_new(NULL, NULL);
+	/* ... which has a gtkimhtml in it. */
+	win->text = gtk_imhtml_new(NULL, NULL);
 
-	gtk_container_add(GTK_CONTAINER(sw), win->entry);
-	gtk_container_add(GTK_CONTAINER(win->window), sw);
+	gtk_container_add(GTK_CONTAINER(sw), win->text);
+
+	/* Pack it in... Not like that, sicko. */
+	gtk_box_pack_start(GTK_BOX(vbox), sw, TRUE, TRUE, 0);
+
 	gtk_widget_show_all(win->window);
-	
+
 	return win;
 }
 
@@ -108,21 +176,37 @@
 gaim_gtk_debug_print(GaimDebugLevel level, const char *category,
 					 const char *format, va_list args)
 {
-	gchar *esc_s, *arg_s, *cat_s, *s;
+	gchar *arg_s;
 
 	arg_s = g_strdup_vprintf(format, args);
 
-	if ((misc_options & OPT_MISC_DEBUG) && debug_win != NULL) {
+	if ((misc_options & OPT_MISC_DEBUG) &&
+		debug_win != NULL && !debug_win->paused) {
+
+		gchar *esc_s, *cat_s, *ts_s, *s;
+
 		if (category == NULL)
 			cat_s = g_strdup("");
 		else
 			cat_s = g_strdup_printf("<b>%s:</b> ", category);
 
+		if (debug_win->timestamps) {
+			gchar mdate[64];
+			time_t mtime = time(NULL);
+
+			strftime(mdate, sizeof(mdate), "%H:%M:%S", localtime(&mtime));
+
+			ts_s = g_strdup_printf("(%s) ", mdate);
+		}
+		else
+			ts_s = g_strdup("");
+
 		esc_s = g_markup_escape_text(arg_s, -1);
 
-		s = g_strdup_printf("<font color=\"%s\">%s%s</font>",
-							debug_fg_colors[level], cat_s, esc_s);
+		s = g_strdup_printf("<font color=\"%s\">%s%s%s</font>",
+							debug_fg_colors[level], ts_s, cat_s, esc_s);
 
+		g_free(ts_s);
 		g_free(esc_s);
 
 		if (level == GAIM_DEBUG_FATAL) {
@@ -134,7 +218,7 @@
 
 		g_free(cat_s);
 
-		gtk_imhtml_append_text(GTK_IMHTML(debug_win->entry), s, -1, 0);
+		gtk_imhtml_append_text(GTK_IMHTML(debug_win->text), s, -1, 0);
 
 		g_free(s);
 	}