# HG changeset patch # User Guido Berhoerster # Date 1398633126 -7200 # Node ID 0907cc7064d4c1c8db44b2e6d74e71f2f19181ef # Parent 52694b49dcc4095e46a393d286076fdff171a418 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. diff -r 52694b49dcc4 -r 0907cc7064d4 main.c --- 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 + * Copyright (C) 2014 Guido Berhoerster * * 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"); diff -r 52694b49dcc4 -r 0907cc7064d4 xwrited-debug.c --- 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 + * Copyright (C) 2014 Guido Berhoerster * * 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) */ }