changeset 1:0907cc7064d4

Add support for newer glib versions Do not call g_type_init() in glib >= 2.35 where it has been deprecated. glib >= 2.32 only shows debug messages if the G_MESSAGES_DEBUG environment variable contains the log domain or "all", so add the log domain to G_MESSAGES_DEBUG if necessary if the "-d" commandline option was specified.
author Guido Berhoerster <guido+xwrited@berhoerster.name>
date Sun, 27 Apr 2014 23:12:06 +0200
parents 52694b49dcc4
children c53bcdabbba7
files main.c xwrited-debug.c
diffstat 2 files changed, 30 insertions(+), 2 deletions(-) [+]
line wrap: on
line diff
--- a/main.c	Sun Apr 27 23:07:51 2014 +0200
+++ b/main.c	Sun Apr 27 23:12:06 2014 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Guido Berhoerster <guido+xwrited@berhoerster.name>
+ * Copyright (C) 2014 Guido Berhoerster <guido+xwrited@berhoerster.name>
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files (the
@@ -288,7 +288,10 @@
 	bind_textdomain_codeset(PACKAGE, "UTF-8");
 	textdomain(PACKAGE);
 
+#if !GLIB_CHECK_VERSION(2, 35, 0)
+	/* deprecated in glib >= 2.35 */
 	g_type_init();
+#endif
 
 	context = g_option_context_new("- display write and wall messages as "
 	    "desktop notifications");
--- a/xwrited-debug.c	Sun Apr 27 23:07:51 2014 +0200
+++ b/xwrited-debug.c	Sun Apr 27 23:12:06 2014 +0200
@@ -1,5 +1,5 @@
 /*
- * Copyright (C) 2011 Guido Berhoerster <guido+xwrited@berhoerster.name>
+ * Copyright (C) 2014 Guido Berhoerster <guido+xwrited@berhoerster.name>
  *
  * Permission is hereby granted, free of charge, to any person obtaining
  * a copy of this software and associated documentation files (the
@@ -29,18 +29,43 @@
 
 #include "xwrited-debug.h"
 
+#if !GLIB_CHECK_VERSION(2, 32, 0)
 static void
 dummy_log_handler(const gchar *log_domain, GLogLevelFlags log_level,
     const gchar *message, gpointer data)
 {
 	/* drop all messages */
 }
+#endif /* !GLIB_CHECK_VERSION (2,32,0) */
 
 void
 xwrited_debug_init(gboolean debug_mode)
 {
+	/*
+	 * glib >= 2.32 only shows debug messages if the G_MESSAGES_DEBUG
+	 * environment variable contains the log domain or "all", earlier glib
+	 * version always show debugging output
+	 */
+#if GLIB_CHECK_VERSION(2, 32, 0)
+	const gchar	*debug_env;
+	gchar		*debug_env_new;
+
+	if (debug_mode) {
+		debug_env = g_getenv("G_MESSAGES_DEBUG");
+
+		if (debug_env == NULL) {
+			g_setenv("G_MESSAGES_DEBUG", G_LOG_DOMAIN, TRUE);
+		} else if (strstr(debug_env, G_LOG_DOMAIN) == NULL) {
+			debug_env_new = g_strdup_printf("%s %s", debug_env,
+			    G_LOG_DOMAIN);
+			g_setenv("G_MESSAGES_DEBUG", debug_env_new, TRUE);
+			g_free(debug_env_new);
+		}
+	}
+#else
 	if (!debug_mode) {
 		g_log_set_handler(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
 		    dummy_log_handler, NULL);
 	}
+#endif /* GLIB_CHECK_VERSION (2,32,0) */
 }