changeset 10307:2ac21bf20e04

[gaim-migrate @ 11497] And another one gone, and another one gone, another one bites the dust. Hopefully I'm committing everything this time. committer: Tailor Script <tailor@pidgin.im>
author Mark Doliner <mark@kingant.net>
date Fri, 03 Dec 2004 02:46:34 +0000
parents 56cc5d49472b
children 52c2303f60dc
files src/debug.c src/debug.h src/gaim.h src/gtkdebug.c src/gtkmain.c src/gtkprefs.c src/proxy.c
diffstat 7 files changed, 153 insertions(+), 74 deletions(-) [+]
line wrap: on
line diff
--- a/src/debug.c	Fri Dec 03 00:57:21 2004 +0000
+++ b/src/debug.c	Fri Dec 03 02:46:34 2004 +0000
@@ -23,12 +23,23 @@
  * Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
  */
 #include "debug.h"
-#include <stdio.h>
-#include <stdlib.h>
-#include <glib.h>
+#include "internal.h"
+#include "prefs.h"
 
 static GaimDebugUiOps *debug_ui_ops = NULL;
 
+/*
+ * This determines whether debug info should be written to the
+ * console or not.
+ *
+ * It doesn't make sense to make this a normal Gaim preference
+ * because it's a command line option.  This will always be FALSE,
+ * unless the user explicitly started Gaim with the -d flag.
+ * It doesn't matter what this value was the last time Gaim was
+ * started, so it doesn't make sense to save it in prefs.
+ */
+static gboolean debug_enabled = FALSE;
+
 void
 gaim_debug_vargs(GaimDebugLevel level, const char *category,
 				 const char *format, va_list args)
@@ -38,6 +49,32 @@
 	g_return_if_fail(level != GAIM_DEBUG_ALL);
 	g_return_if_fail(format != NULL);
 
+	if (debug_enabled) {
+		gchar *arg_s, *ts_s;
+		gboolean timestamps;
+
+		arg_s = g_strdup_vprintf(format, args);
+
+		timestamps = gaim_prefs_get_bool("/core/debug/timestamps");;
+		if ((category != NULL) && (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("");
+		}
+
+		if (category == NULL)
+			g_print("%s%s", ts_s, arg_s);
+		else
+			g_print("%s%s: %s", ts_s, category, arg_s);
+
+		g_free(arg_s);
+		g_free(ts_s);
+	}
+
 	ops = gaim_debug_get_ui_ops();
 
 	if (ops != NULL && ops->print != NULL)
@@ -119,6 +156,18 @@
 }
 
 void
+gaim_debug_set_enabled(gboolean enabled)
+{
+	debug_enabled = enabled;
+}
+
+gboolean
+gaim_debug_is_enabled()
+{
+	return debug_enabled;
+}
+
+void
 gaim_debug_set_ui_ops(GaimDebugUiOps *ops)
 {
 	debug_ui_ops = ops;
@@ -129,3 +178,15 @@
 {
 	return debug_ui_ops;
 }
+
+void
+gaim_debug_init(void)
+{
+	gaim_prefs_add_none("/core/debug");
+
+	/*
+	 * This pref is currently used by both the console
+	 * output and the debug window output.
+	 */
+	gaim_prefs_add_bool("/core/debug/timestamps", FALSE);
+}
--- a/src/debug.h	Fri Dec 03 00:57:21 2004 +0000
+++ b/src/debug.h	Fri Dec 03 02:46:34 2004 +0000
@@ -25,6 +25,7 @@
 #ifndef _GAIM_DEBUG_H_
 #define _GAIM_DEBUG_H_
 
+#include <glib.h>
 #include <stdarg.h>
 
 /**
@@ -148,6 +149,20 @@
  */
 void gaim_debug_fatal(const char *category, const char *format, ...);
 
+/**
+ * Enable or disable printing debug output to the console.
+ *
+ * @param enabled TRUE to enable debug output or FALSE to disable it.
+ */
+void gaim_debug_set_enabled(gboolean enabled);
+
+/**
+ * Check if console debug output is enabled.
+ *
+ * @return TRUE if debuggin is enabled, FALSE if it is not.
+ */
+gboolean gaim_debug_is_enabled();
+
 /*@}*/
 
 /**************************************************************************/
@@ -173,6 +188,18 @@
 
 /*@}*/
 
+/**************************************************************************/
+/** @name Debug Subsystem                                                 */
+/**************************************************************************/
+/*@{*/
+
+/**
+ * Initializes the debug subsystem.
+ */
+void gaim_debug_init(void);
+
+/*@}*/
+
 #ifdef __cplusplus
 }
 #endif
--- a/src/gaim.h	Fri Dec 03 00:57:21 2004 +0000
+++ b/src/gaim.h	Fri Dec 03 02:46:34 2004 +0000
@@ -27,9 +27,6 @@
 
 #include "connection.h"
 
-/* Globals in gtkmain.c */
-extern int opt_debug;
-
 /* Functions in idle.c */
 extern gint check_idle(gpointer);
 
--- a/src/gtkdebug.c	Fri Dec 03 00:57:21 2004 +0000
+++ b/src/gtkdebug.c	Fri Dec 03 02:46:34 2004 +0000
@@ -36,8 +36,6 @@
 #include "gtkutils.h"
 #include "gtkstock.h"
 
-extern int opt_debug;
-
 typedef struct
 {
 	GtkWidget *window;
@@ -212,7 +210,7 @@
 {
 	win->timestamps = gtk_toggle_button_get_active(GTK_TOGGLE_BUTTON(w));
 
-	gaim_prefs_set_bool("/gaim/gtk/debug/timestamps", win->timestamps);
+	gaim_prefs_set_bool("/core/debug/timestamps", win->timestamps);
 }
 
 static void
@@ -293,9 +291,9 @@
 											win);
 
 		gtk_toggle_button_set_active(GTK_TOGGLE_BUTTON(button),
-						gaim_prefs_get_bool("/gaim/gtk/debug/timestamps"));
+						gaim_prefs_get_bool("/core/debug/timestamps"));
 
-		gaim_prefs_connect_callback(gaim_gtk_debug_get_handle(), "/gaim/gtk/debug/timestamps",
+		gaim_prefs_connect_callback(gaim_gtk_debug_get_handle(), "/core/debug/timestamps",
 									timestamps_pref_cb, button);
 	}
 
@@ -384,8 +382,10 @@
 	 */
 
 	gaim_prefs_add_none("/gaim/gtk/debug");
+
+	/* Controls printing to the debug window */
 	gaim_prefs_add_bool("/gaim/gtk/debug/enabled", FALSE);
-	gaim_prefs_add_bool("/gaim/gtk/debug/timestamps", FALSE);
+
 	gaim_prefs_add_bool("/gaim/gtk/debug/toolbar", TRUE);
 	gaim_prefs_add_int("/gaim/gtk/debug/width",  450);
 	gaim_prefs_add_int("/gaim/gtk/debug/height", 250);
@@ -438,77 +438,62 @@
 gaim_gtk_debug_print(GaimDebugLevel level, const char *category,
 					 const char *format, va_list args)
 {
+	gboolean timestamps;
 	gchar *arg_s, *ts_s;
-	gboolean timestamps;
+	gchar *esc_s, *cat_s, *tmp, *s;
 
-	timestamps = gaim_prefs_get_bool("/gaim/gtk/debug/timestamps");
+	if (!gaim_prefs_get_bool("/gaim/gtk/debug/enabled") ||
+					(debug_win == NULL) || debug_win->paused) {
+		return;
+	}
+
+	timestamps = gaim_prefs_get_bool("/core/debug/timestamps");
 
 	arg_s = g_strdup_vprintf(format, args);
 
-	if (category == NULL) {
+	/*
+ 	 * For some reason we only print the timestamp if category is
+ 	 * not NULL.  Why the hell do we do that?  --Mark
+	 */
+	if ((category != NULL) && (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("");
 	}
-	else {
-		/*
-		 * If the category is not NULL, then do timestamps.
-		 * This IS right. :)
-		 */
-		if (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("");
-	}
 
-	if (gaim_prefs_get_bool("/gaim/gtk/debug/enabled") &&
-		debug_win != NULL && !debug_win->paused) {
-
-		gchar *esc_s, *cat_s, *utf8_s, *s;
+	if (category == NULL)
+		cat_s = g_strdup("");
+	else
+		cat_s = g_strdup_printf("<b>%s:</b> ", category);
 
-		if (category == NULL)
-			cat_s = g_strdup("");
-		else
-			cat_s = g_strdup_printf("<b>%s:</b> ", category);
+	esc_s = g_markup_escape_text(arg_s, -1);
 
-		esc_s = g_markup_escape_text(arg_s, -1);
+	g_free(arg_s);
 
-		s = g_strdup_printf("<font color=\"%s\">%s%s%s</font>",
-							debug_fg_colors[level], ts_s, cat_s, esc_s);
-
-		g_free(esc_s);
+	s = g_strdup_printf("<font color=\"%s\">%s%s%s</font>",
+						debug_fg_colors[level], ts_s, cat_s, esc_s);
 
-		utf8_s = gaim_utf8_try_convert(s);
-		g_free(s);
-		s = utf8_s;
-
-		if (level == GAIM_DEBUG_FATAL) {
-			gchar *temp = s;
+	g_free(ts_s);
+	g_free(cat_s);
+	g_free(esc_s);
 
-			s = g_strdup_printf("<b>%s</b>", temp);
-			g_free(temp);
-		}
+	tmp = gaim_utf8_try_convert(s);
+	g_free(s);
+	s = tmp;
 
-		g_free(cat_s);
-
-		gtk_imhtml_append_text(GTK_IMHTML(debug_win->text), s, 0);
-
+	if (level == GAIM_DEBUG_FATAL) {
+		tmp = g_strdup_printf("<b>%s</b>", s);
 		g_free(s);
+		s = tmp;
 	}
 
-	if (opt_debug) {
-		if (category == NULL)
-			g_print("%s%s", ts_s, arg_s);
-		else
-			g_print("%s%s: %s", ts_s, category, arg_s);
-	}
+	gtk_imhtml_append_text(GTK_IMHTML(debug_win->text), s, 0);
 
-	g_free(ts_s);
-	g_free(arg_s);
+	g_free(s);
 }
 
 static GaimDebugUiOps ops =
--- a/src/gtkmain.c	Fri Dec 03 00:57:21 2004 +0000
+++ b/src/gtkmain.c	Fri Dec 03 02:46:34 2004 +0000
@@ -83,7 +83,6 @@
 int opt_away = 0;
 int docklet_count = 0;
 char *opt_away_arg = NULL;
-int opt_debug = 0;
 
 #if HAVE_SIGNAL_H
 /*
@@ -654,6 +653,7 @@
 	int opt, opt_user = 0;
 	int i;
 	gboolean gui_check;
+	gboolean debug_enabled;
 	gchar *gaimrc, *accountsxml;
 
 	struct option long_options[] = {
@@ -671,8 +671,11 @@
 	};
 
 #ifdef DEBUG
-	opt_debug = 1;
+	debug_enabled = TRUE;
+#else
+	debug_enabled = FALSE;
 #endif
+
 #ifndef _WIN32
 	br_set_locate_fallback_func(gaim_find_binary_location, argv[0]);
 #endif
@@ -720,7 +723,7 @@
 		char errmsg[BUFSIZ];
 		snprintf(errmsg, BUFSIZ, "Warning: couldn't unblock signals");
 		perror(errmsg);
-	}		
+	}
 #endif
 
 	for (i = 0; i < argc; i++) {
@@ -801,9 +804,9 @@
 	opterr = 1;
 	while ((opt = getopt_long(argc, argv,
 #ifndef _WIN32
-				  "adhu:c:vns:", 
+				  "adhu:c:vns:",
 #else
-				  "adhu:c:vn", 
+				  "adhu:c:vn",
 #endif
 				  long_options, NULL)) != -1) {
 		switch (opt) {
@@ -815,7 +818,7 @@
 			opt_acct = 1;
 			break;
 		case 'd':	/* debug */
-			opt_debug = 1;
+			debug_enabled = TRUE;
 			break;
 		case 'c':	/* use specified config dir */
 			set_gaim_user_dir(optarg);
@@ -874,6 +877,8 @@
 		abort();
 	}
 
+	gaim_debug_set_enabled(debug_enabled);
+
 	plugin_search_paths[0] = g_strdup(LIBDIR);
 	plugin_search_paths[1] = gaim_user_dir();
 	plugin_search_paths[2] = g_build_filename(gaim_user_dir(), "plugins", NULL);
@@ -903,7 +908,6 @@
 	gaim_blist_load();
 
 	gaim_prefs_load();
-
 	gaim_prefs_update_old();
 	gaim_gtk_prefs_update_old();
 
@@ -922,7 +926,7 @@
 		g_free(opt_session_arg);
 		opt_session_arg = NULL;
 	}
-	
+
 	if (opt_config_dir_arg != NULL) {
 		g_free(opt_config_dir_arg);
 		opt_config_dir_arg = NULL;
--- a/src/gtkprefs.c	Fri Dec 03 00:57:21 2004 +0000
+++ b/src/gtkprefs.c	Fri Dec 03 02:46:34 2004 +0000
@@ -2384,6 +2384,8 @@
 	gaim_prefs_rename("/gaim/gtk/conversations/im/button_type",
 			"/gaim/gtk/conversations/button_type");
 
+	gaim_prefs_rename("/gaim/gtk/debug/timestamps", "/core/debug/timestamps");
+
 	/* Remove some no-longer-used prefs */
 	gaim_prefs_remove("/gaim/gtk/blist/button_style");
 	gaim_prefs_remove("/gaim/gtk/blist/grey_idle_buddies");
--- a/src/proxy.c	Fri Dec 03 00:57:21 2004 +0000
+++ b/src/proxy.c	Fri Dec 03 02:46:34 2004 +0000
@@ -536,6 +536,9 @@
 	pending_dns_request_t *req = NULL;
 	dns_params_t dns_params;
 	gchar *host_temp;
+	gboolean show_debug;
+
+	show_debug = gaim_debug_is_enabled();
 
 	host_temp = g_strstrip(g_strdup(hostname));
 	strncpy(dns_params.hostname, host_temp, sizeof(dns_params.hostname) - 1);
@@ -600,7 +603,7 @@
 			close(child_out[0]);
 			close(child_in[1]);
 
-			gaim_dns_childthread(child_out[1], child_in[0], &dns_params, opt_debug);
+			gaim_dns_childthread(child_out[1], child_in[0], &dns_params, show_debug);
 			/* The thread calls _exit() rather than returning, so we never get here */
 		}