pidgin/pidgin

Initialize Pidgin GLib logging handler earlier

2021-10-18, Elliott Sales de Andrade
6dc7e403f8f2
Parents dff0811ff40c
Children bd2767810a18
Initialize Pidgin GLib logging handler earlier

This ensures that output at startup is captured, which is mostly just the error about finding the `theme.css` file.

Testing Done:
Opened/closed the Debug Window, and checked that there were no log messages on the terminal.

Reviewed at https://reviews.imfreedom.org/r/1071/
--- a/pidgin/libpidgin.c Mon Oct 18 21:21:38 2021 -0500
+++ b/pidgin/libpidgin.c Mon Oct 18 22:41:34 2021 -0500
@@ -232,6 +232,8 @@
GError *error = NULL;
gchar *path;
+ pidgin_debug_init();
+
theme = gtk_icon_theme_get_default();
path = g_build_filename(PURPLE_DATADIR, "pidgin", "icons", NULL);
@@ -305,6 +307,7 @@
ui = purple_debug_get_ui();
purple_debug_set_ui(NULL);
g_object_unref(ui);
+ pidgin_debug_uninit();
/* and end it all... */
g_application_quit(g_application_get_default());
--- a/pidgin/pidginapplication.c Mon Oct 18 21:21:38 2021 -0500
+++ b/pidgin/pidginapplication.c Mon Oct 18 22:41:34 2021 -0500
@@ -481,6 +481,8 @@
}
}
+ pidgin_debug_init_handler();
+
provider = gtk_css_provider_new();
search_path = g_build_filename(purple_config_dir(), "gtk-3.0.css", NULL);
--- a/pidgin/pidgindebug.c Mon Oct 18 21:21:38 2021 -0500
+++ b/pidgin/pidgindebug.c Mon Oct 18 22:41:34 2021 -0500
@@ -70,6 +70,7 @@
};
static PidginDebugWindow *debug_win = NULL;
+static guint debug_enabled_timer = 0;
struct _PidginDebugUi
{
@@ -79,7 +80,6 @@
guint debug_enabled_timer;
};
-static void pidgin_debug_ui_finalize(GObject *gobject);
static void pidgin_debug_ui_interface_init(PurpleDebugUiInterface *iface);
G_DEFINE_TYPE_WITH_CODE(PidginDebugUi, pidgin_debug_ui, G_TYPE_OBJECT,
@@ -671,37 +671,27 @@
static gboolean
debug_enabled_timeout_cb(gpointer data)
{
- PidginDebugUi *ui = PIDGIN_DEBUG_UI(data);
-
- ui->debug_enabled_timer = 0;
+ gboolean enabled = GPOINTER_TO_INT(data);
- pidgin_debug_window_show();
-
- return FALSE;
-}
+ debug_enabled_timer = 0;
-static gboolean
-debug_disabled_timeout_cb(gpointer data)
-{
- PidginDebugUi *ui = PIDGIN_DEBUG_UI(data);
-
- ui->debug_enabled_timer = 0;
-
- pidgin_debug_window_hide();
+ if (enabled) {
+ pidgin_debug_window_show();
+ } else {
+ pidgin_debug_window_hide();
+ }
return FALSE;
}
static void
-debug_enabled_cb(const char *name, PurplePrefType type,
- gconstpointer value, gpointer data)
+debug_enabled_cb(G_GNUC_UNUSED const gchar *name,
+ G_GNUC_UNUSED PurplePrefType type,
+ gconstpointer value,
+ gpointer data)
{
- PidginDebugUi *ui = PIDGIN_DEBUG_UI(data);
-
- if (GPOINTER_TO_INT(value))
- ui->debug_enabled_timer = g_timeout_add(0, debug_enabled_timeout_cb, data);
- else
- ui->debug_enabled_timer = g_timeout_add(0, debug_disabled_timeout_cb, data);
+ debug_enabled_timer = g_timeout_add(0, debug_enabled_timeout_cb,
+ (gpointer)value);
}
static GLogWriterOutput
@@ -824,47 +814,6 @@
static void
pidgin_debug_ui_init(PidginDebugUi *self)
{
- /* Debug window preferences. */
- /*
- * NOTE: This must be set before prefs are loaded, and the callbacks
- * set after they are loaded, since prefs sets the enabled
- * preference here and that loads the window, which calls the
- * configure event, which overrides the width and height! :P
- */
-
- purple_prefs_add_none(PIDGIN_PREFS_ROOT "/debug");
-
- /* Controls printing to the debug window */
- purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/debug/enabled", FALSE);
- purple_prefs_add_int(PIDGIN_PREFS_ROOT "/debug/filterlevel", PURPLE_DEBUG_ALL);
- purple_prefs_add_int(PIDGIN_PREFS_ROOT "/debug/style", GTK_TOOLBAR_BOTH_HORIZ);
-
- purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/debug/toolbar", TRUE);
- purple_prefs_add_int(PIDGIN_PREFS_ROOT "/debug/width", 450);
- purple_prefs_add_int(PIDGIN_PREFS_ROOT "/debug/height", 250);
-
- purple_prefs_add_string(PIDGIN_PREFS_ROOT "/debug/regex", "");
- purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/debug/filter", FALSE);
- purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/debug/invert", FALSE);
- purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/debug/case_insensitive", FALSE);
- purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/debug/highlight", FALSE);
-
- purple_prefs_connect_callback(NULL, PIDGIN_PREFS_ROOT "/debug/enabled",
- debug_enabled_cb, self);
-
- g_log_set_writer_func(pidgin_debug_g_log_handler, NULL, NULL);
-}
-
-static void
-pidgin_debug_ui_finalize(GObject *gobject)
-{
- PidginDebugUi *self = PIDGIN_DEBUG_UI(gobject);
-
- if (self->debug_enabled_timer != 0)
- g_source_remove(self->debug_enabled_timer);
- self->debug_enabled_timer = 0;
-
- G_OBJECT_CLASS(pidgin_debug_ui_parent_class)->finalize(gobject);
}
void
@@ -996,9 +945,6 @@
static void
pidgin_debug_ui_class_init(PidginDebugUiClass *klass)
{
- GObjectClass *object_class = G_OBJECT_CLASS(klass);
-
- object_class->finalize = pidgin_debug_ui_finalize;
}
PidginDebugUi *
@@ -1007,6 +953,55 @@
return g_object_new(PIDGIN_TYPE_DEBUG_UI, NULL);
}
+void
+pidgin_debug_init_handler(void)
+{
+ g_log_set_writer_func(pidgin_debug_g_log_handler, NULL, NULL);
+}
+
+void
+pidgin_debug_init(void)
+{
+ /* Debug window preferences. */
+ /*
+ * NOTE: This must be set before prefs are loaded, and the callbacks
+ * set after they are loaded, since prefs sets the enabled
+ * preference here and that loads the window, which calls the
+ * configure event, which overrides the width and height! :P
+ */
+
+ purple_prefs_add_none(PIDGIN_PREFS_ROOT "/debug");
+
+ /* Controls printing to the debug window */
+ purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/debug/enabled", FALSE);
+ purple_prefs_add_int(PIDGIN_PREFS_ROOT "/debug/filterlevel",
+ PURPLE_DEBUG_ALL);
+ purple_prefs_add_int(PIDGIN_PREFS_ROOT "/debug/style",
+ GTK_TOOLBAR_BOTH_HORIZ);
+
+ purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/debug/toolbar", TRUE);
+ purple_prefs_add_int(PIDGIN_PREFS_ROOT "/debug/width", 450);
+ purple_prefs_add_int(PIDGIN_PREFS_ROOT "/debug/height", 250);
+
+ purple_prefs_add_string(PIDGIN_PREFS_ROOT "/debug/regex", "");
+ purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/debug/filter", FALSE);
+ purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/debug/invert", FALSE);
+ purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/debug/case_insensitive", FALSE);
+ purple_prefs_add_bool(PIDGIN_PREFS_ROOT "/debug/highlight", FALSE);
+
+ purple_prefs_connect_callback(NULL, PIDGIN_PREFS_ROOT "/debug/enabled",
+ debug_enabled_cb, NULL);
+}
+
+void
+pidgin_debug_uninit(void)
+{
+ if (debug_enabled_timer != 0) {
+ g_source_remove(debug_enabled_timer);
+ }
+ debug_enabled_timer = 0;
+}
+
void *
pidgin_debug_get_handle() {
static int handle;
--- a/pidgin/pidgindebug.h Mon Oct 18 21:21:38 2021 -0500
+++ b/pidgin/pidgindebug.h Mon Oct 18 22:41:34 2021 -0500
@@ -42,6 +42,36 @@
G_DECLARE_FINAL_TYPE(PidginDebugWindow, pidgin_debug_window, PIDGIN, DEBUG_WINDOW, GtkWindow)
/**
+ * pidgin_debug_init_handler:
+ *
+ * Initialize handler for GLib logging system.
+ *
+ * This must be called early if you want to capture logs at startup, and avoid
+ * printing them out.
+ *
+ * Since: 3.0.0
+ */
+void pidgin_debug_init_handler(void);
+
+/**
+ * pidgin_debug_init:
+ *
+ * Perform necessary initializations.
+ *
+ * Since: 3.0.0
+ */
+void pidgin_debug_init(void);
+
+/**
+ * pidgin_debug_uninit:
+ *
+ * Perform necessary uninitializations.
+ *
+ * Since: 3.0.0
+ */
+void pidgin_debug_uninit(void);
+
+/**
* pidgin_debug_ui_new:
*
* Initializes the GTK debug system.