projects/xwrited

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 Apr 27 23:12:06 2014 +0200 (2014-04-27)
parents 52694b49dcc4
children c53bcdabbba7
files main.c xwrited-debug.c
line diff
     1.1 --- a/main.c	Sun Apr 27 23:07:51 2014 +0200
     1.2 +++ b/main.c	Sun Apr 27 23:12:06 2014 +0200
     1.3 @@ -1,5 +1,5 @@
     1.4  /*
     1.5 - * Copyright (C) 2011 Guido Berhoerster <guido+xwrited@berhoerster.name>
     1.6 + * Copyright (C) 2014 Guido Berhoerster <guido+xwrited@berhoerster.name>
     1.7   *
     1.8   * Permission is hereby granted, free of charge, to any person obtaining
     1.9   * a copy of this software and associated documentation files (the
    1.10 @@ -288,7 +288,10 @@
    1.11  	bind_textdomain_codeset(PACKAGE, "UTF-8");
    1.12  	textdomain(PACKAGE);
    1.13  
    1.14 +#if !GLIB_CHECK_VERSION(2, 35, 0)
    1.15 +	/* deprecated in glib >= 2.35 */
    1.16  	g_type_init();
    1.17 +#endif
    1.18  
    1.19  	context = g_option_context_new("- display write and wall messages as "
    1.20  	    "desktop notifications");
     2.1 --- a/xwrited-debug.c	Sun Apr 27 23:07:51 2014 +0200
     2.2 +++ b/xwrited-debug.c	Sun Apr 27 23:12:06 2014 +0200
     2.3 @@ -1,5 +1,5 @@
     2.4  /*
     2.5 - * Copyright (C) 2011 Guido Berhoerster <guido+xwrited@berhoerster.name>
     2.6 + * Copyright (C) 2014 Guido Berhoerster <guido+xwrited@berhoerster.name>
     2.7   *
     2.8   * Permission is hereby granted, free of charge, to any person obtaining
     2.9   * a copy of this software and associated documentation files (the
    2.10 @@ -29,18 +29,43 @@
    2.11  
    2.12  #include "xwrited-debug.h"
    2.13  
    2.14 +#if !GLIB_CHECK_VERSION(2, 32, 0)
    2.15  static void
    2.16  dummy_log_handler(const gchar *log_domain, GLogLevelFlags log_level,
    2.17      const gchar *message, gpointer data)
    2.18  {
    2.19  	/* drop all messages */
    2.20  }
    2.21 +#endif /* !GLIB_CHECK_VERSION (2,32,0) */
    2.22  
    2.23  void
    2.24  xwrited_debug_init(gboolean debug_mode)
    2.25  {
    2.26 +	/*
    2.27 +	 * glib >= 2.32 only shows debug messages if the G_MESSAGES_DEBUG
    2.28 +	 * environment variable contains the log domain or "all", earlier glib
    2.29 +	 * version always show debugging output
    2.30 +	 */
    2.31 +#if GLIB_CHECK_VERSION(2, 32, 0)
    2.32 +	const gchar	*debug_env;
    2.33 +	gchar		*debug_env_new;
    2.34 +
    2.35 +	if (debug_mode) {
    2.36 +		debug_env = g_getenv("G_MESSAGES_DEBUG");
    2.37 +
    2.38 +		if (debug_env == NULL) {
    2.39 +			g_setenv("G_MESSAGES_DEBUG", G_LOG_DOMAIN, TRUE);
    2.40 +		} else if (strstr(debug_env, G_LOG_DOMAIN) == NULL) {
    2.41 +			debug_env_new = g_strdup_printf("%s %s", debug_env,
    2.42 +			    G_LOG_DOMAIN);
    2.43 +			g_setenv("G_MESSAGES_DEBUG", debug_env_new, TRUE);
    2.44 +			g_free(debug_env_new);
    2.45 +		}
    2.46 +	}
    2.47 +#else
    2.48  	if (!debug_mode) {
    2.49  		g_log_set_handler(G_LOG_DOMAIN, G_LOG_LEVEL_DEBUG,
    2.50  		    dummy_log_handler, NULL);
    2.51  	}
    2.52 +#endif /* GLIB_CHECK_VERSION (2,32,0) */
    2.53  }