[gnome-games] libgames-support: Add games-glib-compat.h



commit d0579217651b767f776095f7d59974cce220f180
Author: Christian Persch <chpe gnome org>
Date:   Mon Jan 4 19:41:38 2010 +0100

    libgames-support: Add games-glib-compat.h
    
    Add a glib compat header containing definitions for older glib versions.

 libgames-support/Makefile.am         |    1 +
 libgames-support/games-clock.c       |    7 +----
 libgames-support/games-conf.c        |   15 +----------
 libgames-support/games-glib-compat.h |   45 ++++++++++++++++++++++++++++++++++
 4 files changed, 49 insertions(+), 19 deletions(-)
---
diff --git a/libgames-support/Makefile.am b/libgames-support/Makefile.am
index 0d3e987..1ff5352 100644
--- a/libgames-support/Makefile.am
+++ b/libgames-support/Makefile.am
@@ -27,6 +27,7 @@ libgames_support_la_SOURCES =		\
 	games-conf.h			\
 	games-debug.c			\
 	games-debug.h			\
+	games-glib-compat.h		\
 	games-gtk-compat.h		\
 	games-help.c			\
 	games-help.h			\
diff --git a/libgames-support/games-clock.c b/libgames-support/games-clock.c
index b982c79..7eaaeae 100644
--- a/libgames-support/games-clock.c
+++ b/libgames-support/games-clock.c
@@ -11,6 +11,7 @@
 #include <config.h>
 
 #include "games-clock.h"
+#include "games-glib-compat.h"
 
 G_DEFINE_TYPE (GamesClock, games_clock, GTK_TYPE_LABEL)
 
@@ -50,11 +51,7 @@ games_clock_start_timer (GamesClock *clock_widget)
     return;
 
   clock_widget->update_timeout_id =
-#if GLIB_CHECK_VERSION (2, 14, 0)
-    g_timeout_add_seconds (1, (GSourceFunc) games_clock_update, clock_widget);
-#else
-    g_timeout_add (1000, (GSourceFunc) games_clock_update, clock_widget);
-#endif
+    gdk_threads_add_timeout_seconds (1, (GSourceFunc) games_clock_update, clock_widget);
 }
 
 static void
diff --git a/libgames-support/games-conf.c b/libgames-support/games-conf.c
index 89522dc..aa367ed 100644
--- a/libgames-support/games-conf.c
+++ b/libgames-support/games-conf.c
@@ -31,6 +31,7 @@
 #endif
 
 #include "games-debug.h"
+#include "games-glib-compat.h"
 #include "games-gtk-compat.h"
 #include "games-marshal.h"
 
@@ -134,11 +135,7 @@ free_window_state (WindowState *state)
 
   g_free (state->group);
 
-#if GLIB_CHECK_VERSION (2, 10, 0)
   g_slice_free (WindowState, state);
-#else
-  g_free (state);
-#endif
 }
 
 static gboolean
@@ -164,15 +161,9 @@ window_configure_event_cb (GtkWidget *widget,
                       state->window);
 
     if (state->timeout_id == 0) {
-#if GLIB_CHECK_VERSION (2, 14, 0)
       state->timeout_id = g_timeout_add_seconds (WINDOW_STATE_TIMEOUT,
                                                  (GSourceFunc) window_state_timeout_cb,
                                                  state);
-#else
-      state->timeout_id = g_timeout_add (WINDOW_STATE_TIMEOUT * 1000,
-                                         (GSourceFunc) window_state_timeout_cb,
-                                         state);
-#endif
     }
   }
 
@@ -1299,11 +1290,7 @@ games_conf_add_window (GtkWindow *window,
   g_return_if_fail (GTK_IS_WINDOW (window));
   g_return_if_fail (!GTK_WIDGET_REALIZED (window));
 
-#if GLIB_CHECK_VERSION (2, 10, 0)
   state = g_slice_new0 (WindowState);
-#else
-  state = g_new0 (WindowState, 1);
-#endif
 
   state->window = window;
   state->group = g_strdup (group);
diff --git a/libgames-support/games-glib-compat.h b/libgames-support/games-glib-compat.h
new file mode 100644
index 0000000..f8bd1bc
--- /dev/null
+++ b/libgames-support/games-glib-compat.h
@@ -0,0 +1,45 @@
+/*
+ *  Copyright © 2009 Thomas H.P. Andersen <phomes gmail com>
+ *
+ *  This runtime is free software; you can redistribute it and/or modify
+ *  it under the terms of the GNU Lesser General Public License as published by
+ *  the Free Software Foundation; either version 2.1, or (at your option)
+ *  any later version.
+ *
+ *  This runtime is distributed in the hope runtime it will be useful,
+ *  but WITHOUT ANY WARRANTY; without even the implied warranty of
+ *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
+ *  GNU General Public License for more details.
+ *
+ *  You should have received a copy of the GNU Lesser General Public License
+ *  along with this runtime; if not, write to the Free Software
+ *  Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA.
+ */
+
+#ifndef GAMES_GLIB_COMPAT_H
+#define GAMES_GLIB_COMPAT_H
+
+#include <glib.h>
+#include <glib-object.h>
+
+G_BEGIN_DECLS
+
+#if !GLIB_CHECK_VERSION (2, 10, 0)
+
+#define g_slice_new(T) g_new (T, 1)
+#define g_slice_new0(T) g_new0 (T, 1)
+#define g_slice_free(T,ptr) g_free (ptr)
+
+#endif /* GLIB < 2.10 */
+
+#if !GLIB_CHECK_VERSION (2, 14, 0)
+
+#define G_PARAM_STATIC_STRINGS (G_PARAM_STATIC_NAME | G_PARAM_STATIC_NICK | G_PARAM_STATIC_BLURB)
+
+#define g_timeout_add_seconds(timeout,callback,data) g_timeout_add ((timeout)*1000, callback, data)
+#define gdk_threads_add_timeout_seconds(timeout,callback,data) g_timeout_add ((timeout)*1000, callback, data)
+#endif /* GLIB < 2.14 */
+
+G_END_DECLS
+
+#endif /* !GAMES_GLIB_COMPAT_H */



[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]