# HG changeset patch
# Node ID 76599c2aed32
# Parent  089c8a3a9ff4
diff --git a/ChangeLog.API b/ChangeLog.API
--- a/ChangeLog.API
+++ b/ChangeLog.API
@@ -390,6 +390,9 @@ version 3.0.0 (??/??/????):
 		* purple_date_format_long, use g_date_time_format instead.
 		* purple_date_format_short, use g_date_time_format instead.
 		* PurpleDebugUiOps
+		* purple_debug_is_enabled
+		* purple_debug_set_colored
+		* purple_debug_set_enabled
 		* purple_dnsquery_a_account
 		* purple_event_loop_{get|set}_ui_ops. Manually drive the GLib
 		  event loop yourself. See GLib Main Event Loop docs.
diff --git a/finch/gntdebug.c b/finch/gntdebug.c
--- a/finch/gntdebug.c
+++ b/finch/gntdebug.c
@@ -317,13 +317,6 @@ void finch_debug_window_show()
 	gnt_widget_show(debug.window);
 }
 
-static gboolean
-start_with_debugwin(gpointer null)
-{
-	finch_debug_window_show();
-	return FALSE;
-}
-
 void
 finch_debug_init_handler(void)
 {
@@ -334,19 +327,13 @@ void
 finch_debug_init(void)
 {
 	g_set_print_handler(print_stderr);   /* Redirect the debug messages to stderr */
-	if (!purple_debug_is_enabled()) {
-		handle_fprintf_stderr(FALSE);
-	}
+	handle_fprintf_stderr(FALSE);
 
 	purple_prefs_add_none(PREF_ROOT);
 	purple_prefs_add_string(PREF_ROOT "/filter", "");
 	purple_prefs_add_none(PREF_ROOT "/size");
 	purple_prefs_add_int(PREF_ROOT "/size/width", 60);
 	purple_prefs_add_int(PREF_ROOT "/size/height", 15);
-
-	if (purple_debug_is_enabled()) {
-		g_timeout_add(0, start_with_debugwin, NULL);
-	}
 }
 
 void
diff --git a/finch/libfinch.c b/finch/libfinch.c
--- a/finch/libfinch.c
+++ b/finch/libfinch.c
@@ -65,14 +65,21 @@ gnt_core_get_ui_ops(void)
 	return &core_ops;
 }
 
+static gboolean
+start_with_debugwin(gpointer null)
+{
+	finch_debug_window_show();
+	return FALSE;
+}
+
 static int
 init_libpurple(int argc, char **argv)
 {
 	char *path;
 	gboolean opt_nologin = FALSE;
 	gboolean opt_version = FALSE;
+	gboolean opt_debug = FALSE;
 	char *opt_config_dir_arg = NULL;
-	gboolean debug_enabled = FALSE;
 	GOptionContext *context;
 	gchar **args;
 	const gchar *plugin_path = NULL;
@@ -82,6 +89,9 @@ init_libpurple(int argc, char **argv)
 		{"config", 'c', 0,
 			G_OPTION_ARG_FILENAME, &opt_config_dir_arg,
 			_("use DIR for config files"), _("DIR")},
+		{"debug", 'd', 0,
+			G_OPTION_ARG_NONE, &opt_debug,
+			_("open debug window on startup"), NULL},
 		{"nologin", 'n', 0,
 			G_OPTION_ARG_NONE, &opt_nologin,
 			_("don't automatically login"), NULL},
@@ -152,7 +162,9 @@ init_libpurple(int argc, char **argv)
 
 	/* We don't want debug-messages to show up and corrupt the display */
 	finch_debug_init_handler();
-	purple_debug_set_enabled(debug_enabled);
+	if (opt_debug) {
+		g_timeout_add(0, start_with_debugwin, NULL);
+	}
 
 	purple_core_set_ui_ops(gnt_core_get_ui_ops());
 	purple_idle_set_ui_ops(finch_idle_get_ui_ops());
diff --git a/libpurple/debug.h b/libpurple/debug.h
--- a/libpurple/debug.h
+++ b/libpurple/debug.h
@@ -151,23 +151,6 @@ void purple_debug_error(const gchar *cat
 void purple_debug_fatal(const gchar *category, const gchar *format, ...) G_GNUC_PRINTF(2, 3);
 
 /**
- * purple_debug_set_enabled:
- * @enabled: %TRUE to enable debug output or %FALSE to disable it.
- *
- * Enable or disable printing debug output to the console.
- */
-void purple_debug_set_enabled(gboolean enabled);
-
-/**
- * purple_debug_is_enabled:
- *
- * Check if console debug output is enabled.
- *
- * Returns: %TRUE if debugging is enabled, %FALSE if it is not.
- */
-gboolean purple_debug_is_enabled(void);
-
-/**
  * purple_debug_set_verbose:
  * @verbose: %TRUE to enable verbose debugging or %FALSE to disable it.
  *
@@ -209,14 +192,6 @@ void purple_debug_set_unsafe(gboolean un
  */
 gboolean purple_debug_is_unsafe(void);
 
-/**
- * purple_debug_set_colored:
- * @colored: %TRUE to enable colored output, %FALSE to disable it.
- *
- * Enable or disable colored output for bash console.
- */
-void purple_debug_set_colored(gboolean colored);
-
 /******************************************************************************
  * Debug Subsystem
  *****************************************************************************/
diff --git a/libpurple/debug.c b/libpurple/debug.c
--- a/libpurple/debug.c
+++ b/libpurple/debug.c
@@ -24,18 +24,6 @@
 #include "prefs.h"
 
 /*
- * This determines whether debug info should be written to the
- * console or not.
- *
- * It doesn't make sense to make this a normal Purple preference
- * because it's a command line option.  This will always be FALSE,
- * unless the user explicitly started the UI with the -d flag.
- * It doesn't matter what this value was the last time Purple was
- * started, so it doesn't make sense to save it in prefs.
- */
-static gboolean debug_enabled = FALSE;
-
-/*
  * These determine whether verbose or unsafe debugging are desired.  I
  * don't want to make these purple preferences because their values should
  * not be remembered across instances of the UI.
@@ -43,8 +31,6 @@ static gboolean debug_enabled = FALSE;
 static gboolean debug_verbose = FALSE;
 static gboolean debug_unsafe = FALSE;
 
-static gboolean debug_colored = FALSE;
-
 static void
 purple_debug_vargs(PurpleDebugLevel level, const gchar *category,
                    const gchar *format, va_list args)
@@ -153,16 +139,6 @@ purple_debug_fatal(const gchar *category
 	va_end(args);
 }
 
-void
-purple_debug_set_enabled(gboolean enabled) {
-	debug_enabled = enabled;
-}
-
-gboolean
-purple_debug_is_enabled() {
-	return debug_enabled;
-}
-
 gboolean
 purple_debug_is_verbose() {
 	return debug_verbose;
@@ -184,11 +160,6 @@ purple_debug_set_unsafe(gboolean unsafe)
 }
 
 void
-purple_debug_set_colored(gboolean colored) {
-	debug_colored = colored;
-}
-
-void
 purple_debug_init(void) {
 	/* Read environment variables once per init */
 	if(g_getenv("PURPLE_UNSAFE_DEBUG")) {
diff --git a/libpurple/purpleoptions.c b/libpurple/purpleoptions.c
--- a/libpurple/purpleoptions.c
+++ b/libpurple/purpleoptions.c
@@ -32,19 +32,6 @@
  * Callbacks
  *****************************************************************************/
 static gboolean
-purple_options_debug_cb(const gchar *option_name, const gchar *value,
-                        gpointer data, GError **error)
-{
-	purple_debug_set_enabled(TRUE);
-
-	if (purple_strequal(value, "colored")) {
-		purple_debug_set_colored(TRUE);
-	}
-
-	return TRUE;
-}
-
-static gboolean
 purple_options_force_online_cb(const gchar *option_name, const gchar *value,
                                gpointer data, GError **error)
 {
@@ -61,11 +48,6 @@ purple_get_option_group(void) {
 	GOptionGroup *group = NULL;
 	GOptionEntry entries[] = {
 		{
-			"debug", 'd', G_OPTION_FLAG_OPTIONAL_ARG,
-			G_OPTION_ARG_CALLBACK, &purple_options_debug_cb,
-			_("print debugging messages to stdout"),
-			_("[colored]")
-		}, {
 			"force-online", 'f', G_OPTION_FLAG_NO_ARG,
 			G_OPTION_ARG_CALLBACK, &purple_options_force_online_cb,
 			_("force online, regardless of network status"),
diff --git a/libpurple/tests/test_ui.c b/libpurple/tests/test_ui.c
--- a/libpurple/tests/test_ui.c
+++ b/libpurple/tests/test_ui.c
@@ -106,9 +106,6 @@ test_ui_purple_init(void) {
 	/* set the magic PURPLE_PLUGINS_SKIP environment variable */
 	g_setenv("PURPLE_PLUGINS_SKIP", "1", TRUE);
 
-	/* We do not want any debugging for now to keep the noise to a minimum. */
-	purple_debug_set_enabled(FALSE);
-
 	/* Set the core-uiops, which is used to
 	 * 	- initialize the ui specific preferences.
 	 * 	- initialize the debug ui.
diff --git a/pidgin/libpidgin.c b/pidgin/libpidgin.c
--- a/pidgin/libpidgin.c
+++ b/pidgin/libpidgin.c
@@ -432,10 +432,6 @@ int pidgin_start(int argc, char *argv[])
 	GApplication *app;
 	int ret;
 
-#ifdef DEBUG
-	purple_debug_set_enabled(TRUE);
-#endif
-
 	bindtextdomain(PACKAGE, PURPLE_LOCALEDIR);
 	bind_textdomain_codeset(PACKAGE, "UTF-8");
 	textdomain(PACKAGE);
diff --git a/pidgin/pidginapplication.c b/pidgin/pidginapplication.c
--- a/pidgin/pidginapplication.c
+++ b/pidgin/pidginapplication.c
@@ -55,6 +55,20 @@ struct _PidginApplication {
 /******************************************************************************
  * Globals
  *****************************************************************************/
+static gboolean
+pidgin_options_debug_cb(G_GNUC_UNUSED const gchar *option_name,
+                        G_GNUC_UNUSED const gchar *value,
+                        G_GNUC_UNUSED gpointer data,
+                        G_GNUC_UNUSED GError **error)
+{
+	pidgin_debug_set_print_enabled(TRUE);
+
+	return TRUE;
+}
+
+/******************************************************************************
+ * Globals
+ *****************************************************************************/
 static gchar *opt_config_dir_arg = NULL;
 static gboolean opt_nologin = FALSE;
 
@@ -63,6 +77,10 @@ static GOptionEntry option_entries[] = {
 		"config", 'c', 0, G_OPTION_ARG_FILENAME, &opt_config_dir_arg,
 		N_("use DIR for config files"), N_("DIR")
 	}, {
+		"debug", 'd', 0, G_OPTION_ARG_CALLBACK,
+		&pidgin_options_debug_cb,
+		N_("print debugging messages to stdout"), NULL
+	}, {
 		"nologin", 'n', 0, G_OPTION_ARG_NONE, &opt_nologin,
 		N_("don't automatically login"), NULL
 	},
@@ -482,6 +500,9 @@ pidgin_application_startup(GApplication 
 	}
 
 	pidgin_debug_init_handler();
+#ifdef DEBUG
+	pidgin_debug_set_print_enabled(TRUE);
+#endif
 
 	provider = gtk_css_provider_new();
 
diff --git a/pidgin/pidgindebug.h b/pidgin/pidgindebug.h
--- a/pidgin/pidgindebug.h
+++ b/pidgin/pidgindebug.h
@@ -52,6 +52,17 @@ G_DECLARE_FINAL_TYPE(PidginDebugWindow, 
 void pidgin_debug_init_handler(void);
 
 /**
+ * pidgin_debug_set_print_enabled:
+ *
+ * Set whether the debug logging messages are sent the default GLib logging handler.
+ *
+ * This will print to the console, if Pidgin is run from there.
+ *
+ * Since: 3.0.0
+ */
+void pidgin_debug_set_print_enabled(gboolean enable);
+
+/**
  * pidgin_debug_init:
  *
  * Perform necessary initializations.
diff --git a/pidgin/pidgindebug.c b/pidgin/pidgindebug.c
--- a/pidgin/pidgindebug.c
+++ b/pidgin/pidgindebug.c
@@ -69,6 +69,7 @@ struct _PidginDebugWindow {
 	GRegex *regex;
 };
 
+static gboolean debug_print_enabled = FALSE;
 static PidginDebugWindow *debug_win = NULL;
 static guint debug_enabled_timer = 0;
 
@@ -696,7 +697,11 @@ pidgin_debug_g_log_handler(GLogLevelFlag
 
 	if (debug_win == NULL ||
 			!purple_prefs_get_bool(PIDGIN_PREFS_ROOT "/debug/enabled")) {
-		return G_LOG_WRITER_UNHANDLED;
+		if (debug_print_enabled) {
+			return g_log_writer_default(log_level, fields, n_fields, user_data);
+		} else {
+			return G_LOG_WRITER_UNHANDLED;
+		}
 	}
 
 	for (i = 0; i < n_fields; i++) {
@@ -795,7 +800,11 @@ pidgin_debug_g_log_handler(GLogLevelFlag
 				debug_win->end_mark, 0, TRUE, 0, 1);
 	}
 
-	return G_LOG_WRITER_HANDLED;
+	if (debug_print_enabled) {
+		return g_log_writer_default(log_level, fields, n_fields, user_data);
+	} else {
+		return G_LOG_WRITER_HANDLED;
+	}
 }
 
 void
@@ -827,6 +836,12 @@ pidgin_debug_init_handler(void)
 }
 
 void
+pidgin_debug_set_print_enabled(gboolean enable)
+{
+	debug_print_enabled = enable;
+}
+
+void
 pidgin_debug_init(void)
 {
 	/* Debug window preferences. */
