pidgin/pidgin

Move debug command-line option to the UIs

2021-10-19, Elliott Sales de Andrade
cd297cfc56f3
Parents fed868e592ca
Children 445f5cc52e1a
Move debug command-line option to the UIs

This is not really a core option, and even has a different meaning in Finch.

Testing Done:
Run `finch3 -d` and see debug window open by default; run `pidgin3` and see debug output printed.

Reviewed at https://reviews.imfreedom.org/r/1080/
--- a/ChangeLog.API Tue Oct 19 02:57:01 2021 -0500
+++ b/ChangeLog.API Tue Oct 19 03:00:48 2021 -0500
@@ -390,6 +390,9 @@
* 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.
--- a/finch/gntdebug.c Tue Oct 19 02:57:01 2021 -0500
+++ b/finch/gntdebug.c Tue Oct 19 03:00:48 2021 -0500
@@ -317,13 +317,6 @@
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 @@
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
--- a/finch/libfinch.c Tue Oct 19 02:57:01 2021 -0500
+++ b/finch/libfinch.c Tue Oct 19 03:00:48 2021 -0500
@@ -65,14 +65,21 @@
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 @@
{"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 @@
/* 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());
--- a/libpurple/debug.c Tue Oct 19 02:57:01 2021 -0500
+++ b/libpurple/debug.c Tue Oct 19 03:00:48 2021 -0500
@@ -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_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 @@
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 @@
}
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")) {
--- a/libpurple/debug.h Tue Oct 19 02:57:01 2021 -0500
+++ b/libpurple/debug.h Tue Oct 19 03:00:48 2021 -0500
@@ -151,23 +151,6 @@
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 @@
*/
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
*****************************************************************************/
--- a/libpurple/purpleoptions.c Tue Oct 19 02:57:01 2021 -0500
+++ b/libpurple/purpleoptions.c Tue Oct 19 03:00:48 2021 -0500
@@ -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 @@
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"),
--- a/libpurple/tests/test_ui.c Tue Oct 19 02:57:01 2021 -0500
+++ b/libpurple/tests/test_ui.c Tue Oct 19 03:00:48 2021 -0500
@@ -106,9 +106,6 @@
/* 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.
--- a/pidgin/libpidgin.c Tue Oct 19 02:57:01 2021 -0500
+++ b/pidgin/libpidgin.c Tue Oct 19 03:00:48 2021 -0500
@@ -432,10 +432,6 @@
GApplication *app;
int ret;
-#ifdef DEBUG
- purple_debug_set_enabled(TRUE);
-#endif
-
bindtextdomain(PACKAGE, PURPLE_LOCALEDIR);
bind_textdomain_codeset(PACKAGE, "UTF-8");
textdomain(PACKAGE);
--- a/pidgin/pidginapplication.c Tue Oct 19 02:57:01 2021 -0500
+++ b/pidgin/pidginapplication.c Tue Oct 19 03:00:48 2021 -0500
@@ -55,6 +55,20 @@
/******************************************************************************
* 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 @@
"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_debug_init_handler();
+#ifdef DEBUG
+ pidgin_debug_set_print_enabled(TRUE);
+#endif
provider = gtk_css_provider_new();
--- a/pidgin/pidgindebug.c Tue Oct 19 02:57:01 2021 -0500
+++ b/pidgin/pidgindebug.c Tue Oct 19 03:00:48 2021 -0500
@@ -69,6 +69,7 @@
GRegex *regex;
};
+static gboolean debug_print_enabled = FALSE;
static PidginDebugWindow *debug_win = NULL;
static guint debug_enabled_timer = 0;
@@ -696,7 +697,11 @@
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 @@
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 @@
}
void
+pidgin_debug_set_print_enabled(gboolean enable)
+{
+ debug_print_enabled = enable;
+}
+
+void
pidgin_debug_init(void)
{
/* Debug window preferences. */
--- a/pidgin/pidgindebug.h Tue Oct 19 02:57:01 2021 -0500
+++ b/pidgin/pidgindebug.h Tue Oct 19 03:00:48 2021 -0500
@@ -46,6 +46,17 @@
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.