gnome-games r8489 - in trunk: . aisleriot libgames-support



Author: chpe
Date: Tue Jan  6 18:20:14 2009
New Revision: 8489
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8489&view=rev

Log:
Add configure flags to enable the various card theme formats.
Refactor theme info loading code so we don't need to read the whole list
just to get the theme info for the theme saved in the prefs.

Modified:
   trunk/aisleriot/window.c
   trunk/configure.in
   trunk/libgames-support/games-card-selector.c
   trunk/libgames-support/games-card-theme-fixed.c
   trunk/libgames-support/games-card-theme-preimage.c
   trunk/libgames-support/games-card-theme-private.h
   trunk/libgames-support/games-card-theme-pysol.c
   trunk/libgames-support/games-card-theme.c
   trunk/libgames-support/games-card-theme.h
   trunk/libgames-support/games-card-themes.c
   trunk/libgames-support/games-card-themes.h

Modified: trunk/aisleriot/window.c
==============================================================================
--- trunk/aisleriot/window.c	(original)
+++ trunk/aisleriot/window.c	Tue Jan  6 18:20:14 2009
@@ -611,7 +611,7 @@
 			     "AisleRiot is a part of GNOME Games."),
 #endif
                          "copyright", "Copyright  1998-2006 Jonathan Blandford\n"
-                                      "Copyright  2007, 2008 Christian Persch",
+                                      "Copyright  2007, 2008, 2009 Christian Persch",
                          "license", licence,
                          "authors", authors,
                          "artists", artists,
@@ -1542,7 +1542,7 @@
   /* See gtk bug #424448 */
   gtk_ui_manager_ensure_update (priv->ui_manager);
 
-  list = games_card_themes_get_theme_all (priv->theme_manager);
+  list = games_card_themes_get_themes (priv->theme_manager);
 
   /* No need to install the menu when there's only one theme available anyway */
   if (list == NULL || list->next == NULL) {
@@ -2353,6 +2353,7 @@
   GtkAccelGroup *accel_group;
   GtkAction *action;
   char *theme_name;
+  GamesCardThemeInfo *theme_info;
   GamesCardTheme *theme;
   guint i;
 #ifdef HAVE_HILDON
@@ -2391,13 +2392,16 @@
   aisleriot_board_set_pixbuf_drawing (priv->board, priv->use_pixbuf_drawing);
 
   theme_name = games_conf_get_string (NULL, aisleriot_conf_get_key (CONF_THEME), NULL);
-  theme = games_card_themes_get_theme_by_name (priv->theme_manager, theme_name);
+  theme_info = games_card_themes_get_theme_info_by_name (priv->theme_manager, theme_name);
   g_free (theme_name);
-  if (!theme) {
-    theme = games_card_themes_get_theme_any (priv->theme_manager);
+  if (!theme_info) {
+    //XXXtheme = games_card_themes_get_theme_any (priv->theme_manager);
   }
-  if (theme) {
-    aisleriot_window_take_card_theme (window, theme /* adopts */);
+  if (theme_info) {
+    theme = games_card_themes_get_theme (priv->theme_manager, theme_info);
+    if (theme) {
+      aisleriot_window_take_card_theme (window, theme /* adopts */);
+    }
   } else {
     /* FIXMEchpe: FUCK, what now? Panic! */
   }

Modified: trunk/configure.in
==============================================================================
--- trunk/configure.in	(original)
+++ trunk/configure.in	Tue Jan  6 18:20:14 2009
@@ -86,7 +86,6 @@
         esac
      done
    done
-   echo ${omittedgames}
    for game in ${allgames}; do
      case ${omittedgames} in
        *${game}*) ;;
@@ -293,17 +292,6 @@
   [with_sound=sdl_mixer])
 AC_MSG_RESULT([$with_sound])
 
-# Scalable graphics
-
-AC_MSG_CHECKING([whether to enable scalable graphics])
-AC_ARG_ENABLE([scalable],
-  [AS_HELP_STRING([--enable-scalable],[Enable scalable graphics])],
-  [],[case "$with_platform" in
-        gnome|gtk-only) enable_scalable=yes ;;
-        hildon) enable_scalable=no ;;
-      esac])
-AC_MSG_RESULT([$enable_scalable])
-
 # Clutter
   
 AC_MSG_CHECKING([whether to enable clutter support])
@@ -323,6 +311,68 @@
           ;;
 esac
 
+# Card theme formats
+
+AC_MSG_CHECKING([for requested card theme formats])
+AC_ARG_WITH([card-theme-formats],
+  [AS_HELP_STRING([--with-card-theme-formats],[which card theme formats to support (svg, fixed, kde, pysol, defaults, all)])],
+  [],[case "$with_platform" in
+        gnome|gtk-only) with_card_theme_formats="svg" ;;
+        hildon) with_card_theme_formats="fixed" ;;
+      esac])
+
+enable_card_theme_format_svg=no
+enable_card_theme_format_kde=no
+enable_card_theme_format_fixed=no
+enable_card_theme_format_sliced=no
+enable_card_theme_format_pysol=no
+
+IFS="${IFS=	}"; gg_saved_ifs="$IFS"; IFS=","
+for format in "$with_card_theme_formats"; do
+  case "$format" in
+    all) enable_card_theme_format_svg=yes
+         enable_card_theme_format_kde=yes
+         enable_card_theme_format_fixed=yes
+         enable_card_theme_format_sliced=yes
+         enable_card_theme_format_pysol=yes
+         with_card_theme_formats="svg,kde,fixed,sliced,pysol"
+         ;;
+    svg) enable_card_theme_format_svg=yes ;;
+    kde) enable_card_theme_format_kde=yes ;;
+    fixed) enable_card_theme_format_fixed=yes ;;
+    sliced) enable_card_theme_format_svg=yes ;;
+    pysol) enable_card_theme_format_pysol=yes ;;
+    *) AC_MSG_ERROR([unknown card theme format $format]) ;;
+  esac
+done
+IFS="$gg_saved_ifs"
+
+AC_MSG_RESULT([$with_card_theme_formats])
+
+if test "$enable_card_theme_format_svg" = "yes"; then
+  AC_DEFINE([ENABLE_CARD_THEME_FORMAT_SVG],[1],[Define to enable SVG card theme format support])
+  need_rsvg=yes
+fi
+if test "$enable_card_theme_format_kde" = "yes"; then
+  AC_DEFINE([ENABLE_CARD_THEME_FORMAT_KDE],[1],[Define to enable KDE card theme format support])
+  need_rsvg=yes
+fi
+if test "$enable_card_theme_format_fixed" = "yes"; then
+  AC_DEFINE([ENABLE_CARD_THEME_FORMAT_FIXED],[1],[Define to enable prerendered card theme format support])
+fi
+if test "$enable_card_theme_format_sliced" = "yes"; then
+  AC_DEFINE([ENABLE_CARD_THEME_FORMAT_SLICED],[1],[Define to enable pre-2.19 card theme format support])
+fi
+if test "$enable_card_theme_format_pysol" = "yes"; then
+  AC_DEFINE([ENABLE_CARD_THEME_FORMAT_PYSOL],[1],[Define to enable PySol card theme format support])
+fi
+
+AM_CONDITIONAL([ENABLE_CARD_THEME_FORMAT_SVG],[test "$enable_card_theme_format_svg" = "yes"])
+AM_CONDITIONAL([ENABLE_CARD_THEME_FORMAT_KDE],[test "$enable_card_theme_format_kde" = "yes"])
+AM_CONDITIONAL([ENABLE_CARD_THEME_FORMAT_FIXED],[test "$enable_card_theme_format_fixed" = "yes"])
+AM_CONDITIONAL([ENABLE_CARD_THEME_FORMAT_SLICED],[test "$enable_card_theme_format_sliced" = "yes"])
+AM_CONDITIONAL([ENABLE_CARD_THEME_FORMAT_PYSOL],[test "$enable_card_theme_format_pysol" = "yes"])
+
 # Default card theme
 
 AC_MSG_CHECKING([which card theme to use by default])
@@ -336,6 +386,25 @@
 
 AC_DEFINE_UNQUOTED([GAMES_CARD_THEME_DEFAULT],["$with_default_card_theme"],[The default card theme])
 
+AC_MSG_CHECKING([which card theme format to use by default])
+AC_ARG_WITH([default-card-theme-format],
+  [AS_HELP_STRING([--with-default-card-theme-format=NAME],[Which card theme format to use by default (default: platform dependent)])],
+  [],[case "$with_platform" in
+        gnome|gtk-only) with_default_card_theme_format=svg ;;
+        hildon) with_default_card_theme_format=fixed ;;
+      esac])
+AC_MSG_RESULT([$with_default_card_theme_format])
+
+case "$with_default_card_theme_format" in
+  svg) GAMES_CARD_THEME_DEFAULT_FORMAT="GAMES_TYPE_CARD_THEME_SVG" ;;
+  kde) GAMES_CARD_THEME_DEFAULT_FORMAT="GAMES_TYPE_CARD_THEME_KDE" ;;
+  fixed) GAMES_CARD_THEME_DEFAULT_FORMAT="GAMES_TYPE_CARD_THEME_FIXED" ;;
+  sliced) GAMES_CARD_THEME_DEFAULT_FORMAT="GAMES_TYPE_CARD_THEME_SLICED" ;;
+  pysol) GAMES_CARD_THEME_DEFAULT_FORMAT="GAMES_TYPE_CARD_THEME_PYSOL" ;;
+esac
+
+AC_DEFINE_UNQUOTED([GAMES_CARD_THEME_DEFAULT_FORMAT],[$GAMES_CARD_THEME_DEFAULT_FORMAT],[The default card theme format type])
+
 # Checks for libraries.
 PYGTK_REQUIRED=2.10.0
 GNOME_PYTHON_DESKTOP_REQUIRED=2.17.3
@@ -409,36 +478,37 @@
 # Check for librsvg
 
 have_rsvg=no
-if test "$enable_scalable" = "yes"; then
+if test "$need_rsvg" = "yes"; then
+  have_rsvg=yes
+
+  # Errors out if rsvg is not found
   PKG_CHECK_MODULES([RSVG],[
     librsvg-2.0 >= $RSVG_REQUIRED
-    cairo >= $CAIRO_REQUIRED],
-    [have_rsvg=yes],[have_rsvg=no])
-fi
-
-if test "$need_rsvg" = "yes" -a "$have_rsvg" = "no"; then
-  AC_MSG_ERROR([librsvg not found but is required])
-fi
+    cairo >= $CAIRO_REQUIRED])
 
-if test "$have_rsvg" = "yes"; then
   AC_SUBST([RSVG_CFLAGS])
   AC_SUBST([RSVG_LIBS])
 
   AC_DEFINE([HAVE_RSVG],[1],[Refine if librsvg is available])
 
-  # Check whether librsvg was compiled with gnome-vfs support
-  AC_MSG_CHECKING([whether librsvg supports gnome-vfs])
-
-  have_rsvg_gnomevfs=$($PKG_CONFIG --variable=gnome_vfs_supported librsvg-2.0)
-
-  if test -z "$have_rsvg_gnomevfs" -o "$have_rsvg_gnomevfs" = "yes"; then
-    have_rsvg_gnomevfs=yes
+  # This only existed in some pre-gio rsvg versions
+  rsvg_gnomevfs=$($PKG_CONFIG --variable=gnome_vfs_supported librsvg-2.0)
+  if test "$rsvg_gnomevfs" = "yes"; then
     AC_DEFINE([HAVE_RSVG_GNOMEVFS],[1],[Define if librsvg has gnome-vfs support])
-  
+
     need_gthread=yes
   fi
 
-  AC_MSG_RESULT([$have_rsvg_gnomevfs])
+  # These exist only since rsvg 2.22.something, so we check for != false below
+  rsvg_svgz="$($PKG_CONFIG --variable svgz_supported librsvg-2.0)"
+  rsvg_css="$($PKG_CONFIG --variable css_supported librsvg-2.0)"
+
+  if test "$rsvg_svgz" != "false"; then
+    AC_DEFINE([HAVE_RSVG_SVGZ],[1],[Define if rsvg supports gzipped SVG files])
+  fi
+  if test "$rsvg_css" != "false"; then
+    AC_DEFINE([HAVE_RSVG_CSS],[1],[Define if rsvg supports CSS])
+  fi
 fi
 
 AM_CONDITIONAL([HAVE_RSVG],[test "$have_rsvg" = "yes"])
@@ -453,7 +523,7 @@
   CLUTTER_API_VERSION=
   AC_MSG_CHECKING([for clutter API version])
   for API_VERSION in 1.0 0.9 0.8; do
-    PKG_CHECK_EXISTS([clutter-$API_VERSION clutter-gtk-$API_VERSION clutter-cairo-$API_VERSION],
+    PKG_CHECK_EXISTS([clutter-$API_VERSION clutter-cairo-$API_VERSION],
       [CLUTTER_API_VERSION=$API_VERSION; break],[])
   done
   if test -z "$CLUTTER_API_VERSION"; then
@@ -467,10 +537,14 @@
 
   PKG_CHECK_MODULES([CLUTTER],[
      clutter-$CLUTTER_API_VERSION >= $CLUTTER_REQUIRED
-     clutter-gtk-$CLUTTER_API_VERSION  >= $CLUTTER_GTK_REQUIRED
      clutter-cairo-$CLUTTER_API_VERSION >= $CLUTTER_CAIRO_REQUIRED])
   AC_SUBST([CLUTTER_CFLAGS])
   AC_SUBST([CLUTTER_LIBS])
+
+  # PKG_CHECK_MODULES([CLUTTER_GTK],[
+  #   clutter-gtk-$CLUTTER_API_VERSION  >= $CLUTTER_GTK_REQUIRED])
+  # AC_SUBST([CLUTTER_GTK_CFLAGS])
+  # AC_SUBST([CLUTTER_GTK_LIBS])
 fi
 
 AM_CONDITIONAL([HAVE_CLUTTER],[test "$enable_clutter" = "yes"])
@@ -1046,6 +1120,7 @@
     Using SM Client:       ${with_smclient}
     Using RSVG:            ${have_rsvg}
     Using Clutter:         ${enable_clutter}
+    Card theme formats:    ${with_card_theme_formats}
     Sound support:         ${with_sound}
     Use setgid binaries:   ${setgid}
     Scores user:           ${scores_user}

Modified: trunk/libgames-support/games-card-selector.c
==============================================================================
--- trunk/libgames-support/games-card-selector.c	(original)
+++ trunk/libgames-support/games-card-selector.c	Tue Jan  6 18:20:14 2009
@@ -79,7 +79,7 @@
 
   store = gtk_list_store_new (N_COLUMNS, GAMES_TYPE_CARD_THEME_INFO, G_TYPE_STRING);
 
-  themes = games_card_themes_get_theme_all (theme_manager);
+  themes = games_card_themes_get_themes (theme_manager);
 
   for (l = themes; l != NULL; l = l->next) {
     GamesCardThemeInfo *info = l->data;

Modified: trunk/libgames-support/games-card-theme-fixed.c
==============================================================================
--- trunk/libgames-support/games-card-theme-fixed.c	(original)
+++ trunk/libgames-support/games-card-theme-fixed.c	Tue Jan  6 18:20:14 2009
@@ -1,6 +1,6 @@
 /*
    Copyright  2004 Callum McKenzie
-   Copyright  2007, 2008 Christian Persch
+   Copyright  2007, 2008, 2009 Christian Persch
 
    This library is free software; you can redistribute it and'or modify
    it under the terms of the GNU Library General Public License as published 

Modified: trunk/libgames-support/games-card-theme-preimage.c
==============================================================================
--- trunk/libgames-support/games-card-theme-preimage.c	(original)
+++ trunk/libgames-support/games-card-theme-preimage.c	Tue Jan  6 18:20:14 2009
@@ -223,8 +223,11 @@
   GamesCardThemeInfo *info;
   char *display_name;
 
-  if (!g_str_has_suffix (filename, ".svg") &&
-      !g_str_has_suffix (filename, ".svgz"))
+  if (!g_str_has_suffix (filename, ".svg")
+#ifdef HAVE_RSVG_SVGZ
+      && !g_str_has_suffix (filename, ".svgz")
+#endif
+     )
     return NULL;
 
   display_name = games_filename_to_display_name (filename);

Modified: trunk/libgames-support/games-card-theme-private.h
==============================================================================
--- trunk/libgames-support/games-card-theme-private.h	(original)
+++ trunk/libgames-support/games-card-theme-private.h	Tue Jan  6 18:20:14 2009
@@ -1,6 +1,6 @@
 /*
    Copyright  2004 Callum McKenzie
-   Copyright  2007, 2008 Christian Persch
+   Copyright  2007, 2008, 2009 Christian Persch
 
    This library is free software; you can redistribute it and'or modify
    it under the terms of the GNU Library General Public License as published 
@@ -44,13 +44,13 @@
                                                 gpointer data,
                                                 GDestroyNotify destroy_notify);
 
-guint _games_card_theme_info_hash  (GamesCardThemeInfo *a,
-                                    GamesCardThemeInfo *b);
-gboolean _games_card_theme_info_equal (GamesCardThemeInfo *a,
-                                       GamesCardThemeInfo *b);
+guint _games_card_theme_info_hash  (const GamesCardThemeInfo *a);
 
-int _games_card_theme_info_collate (GamesCardThemeInfo *a,
-                                    GamesCardThemeInfo *b);
+gboolean _games_card_theme_info_equal (const GamesCardThemeInfo *a,
+                                       const GamesCardThemeInfo *b);
+
+int _games_card_theme_info_collate (const GamesCardThemeInfo *a,
+                                    const GamesCardThemeInfo *b);
 
 /* GamesCardTheme */
 

Modified: trunk/libgames-support/games-card-theme-pysol.c
==============================================================================
--- trunk/libgames-support/games-card-theme-pysol.c	(original)
+++ trunk/libgames-support/games-card-theme-pysol.c	Tue Jan  6 18:20:14 2009
@@ -1,6 +1,6 @@
 /*
   Copyright  2004 Callum McKenzie
-  Copyright  2007, 2008 Christian Persch
+  Copyright  2007, 2008, 2009 Christian Persch
 
   This programme is free software: you can redistribute it and/or modify
   it under the terms of the GNU General Public License as published by
@@ -359,7 +359,7 @@
     return NULL;
 
   display_name = g_strdup_printf ("%s (PySol)", pysol_data->name);
-  pref_name = g_strdup_printf ("pysol:%s", filename + strlen ("cardset-"));
+  pref_name = g_strdup_printf ("pysol:%s", filename);
   info = _games_card_theme_info_new (G_OBJECT_CLASS_TYPE (klass),
                                      path,
                                      filename,

Modified: trunk/libgames-support/games-card-theme.c
==============================================================================
--- trunk/libgames-support/games-card-theme.c	(original)
+++ trunk/libgames-support/games-card-theme.c	Tue Jan  6 18:20:14 2009
@@ -406,18 +406,16 @@
 }
 
 guint
-_games_card_theme_info_hash (GamesCardThemeInfo *a,
-                             GamesCardThemeInfo *b)
+_games_card_theme_info_hash (const GamesCardThemeInfo *a)
 {
-/*  return g_int_hash (a->type, b->type) ^
-         g_str_hash (a->path, b->path) ^
-         g_str_hash (a->filename, b->filename);*/
-  return 0;
+  return g_int_hash (&a->type) ^
+         g_str_hash (a->path) ^
+         g_str_hash (a->filename);
 }
 
 gboolean
-_games_card_theme_info_equal (GamesCardThemeInfo *a,
-                              GamesCardThemeInfo *b)
+_games_card_theme_info_equal (const GamesCardThemeInfo *a,
+                              const GamesCardThemeInfo *b)
 {
   g_return_val_if_fail (a != NULL && b != NULL, FALSE);
 
@@ -437,8 +435,8 @@
  * %0 if @a and @b are equal.
  */
 int
-_games_card_theme_info_collate (GamesCardThemeInfo *a,
-                                GamesCardThemeInfo *b)
+_games_card_theme_info_collate (const GamesCardThemeInfo *a,
+                                const GamesCardThemeInfo *b)
 {
   g_return_val_if_fail (a != NULL && b != NULL, 0);
 

Modified: trunk/libgames-support/games-card-theme.h
==============================================================================
--- trunk/libgames-support/games-card-theme.h	(original)
+++ trunk/libgames-support/games-card-theme.h	Tue Jan  6 18:20:14 2009
@@ -1,6 +1,6 @@
 /*
   Copyright  2004 Callum McKenzie
-  Copyright  2007, 2008 Christian Persch
+   Copyright  2007, 2008, 2009 Christian Persch
 
   This library is free software; you can redistribute it and'or modify
   it under the terms of the GNU Library General Public License as published

Modified: trunk/libgames-support/games-card-themes.c
==============================================================================
--- trunk/libgames-support/games-card-themes.c	(original)
+++ trunk/libgames-support/games-card-themes.c	Tue Jan  6 18:20:14 2009
@@ -1,6 +1,6 @@
 /*
    Copyright  2004 Callum McKenzie
-   Copyright  2007, 2008 Christian Persch
+   Copyright  2007, 2008, 2009 Christian Persch
 
    This library is free software; you can redistribute it and'or modify
    it under the terms of the GNU Library General Public License as published 
@@ -41,10 +41,13 @@
 
   GHashTable *theme_infos;
   gboolean theme_infos_update_needed;
+
+  GType *theme_types;
+  guint n_theme_types;
 };
 
 enum {
-  PROP_0
+  N_THEME_TYPES = 5
 };
 
 enum {
@@ -52,12 +55,100 @@
   LAST_SIGNAL
 };
 
-/*static guint signals[LAST_SIGNAL];*/
+static guint signals[LAST_SIGNAL];
+
+static GType
+theme_type_from_string (const char *type_str,
+                        gssize type_str_len)
+{
+  const struct {
+    const char name[6];
+    GType type;
+  } type_strings[] = {
+#ifdef HAVE_RSVG
+#ifdef ENABLE_CARD_THEME_FORMAT_SVG
+    { "svg", GAMES_TYPE_CARD_THEME_SVG },
+#endif
+#ifdef ENABLE_CARD_THEME_FORMAT_KDE
+    { "kde", GAMES_TYPE_CARD_THEME_KDE },
+#endif
+#endif /* HAVE_RSVG */
+#ifndef HAVE_HILDON
+#ifdef ENABLE_CARD_THEME_FORMAT_SLICED
+    { "sliced", GAMES_TYPE_CARD_THEME_SLICED },
+#endif
+#ifdef ENABLE_CARD_THEME_FORMAT_PYSOL
+    { "pysol", GAMES_TYPE_CARD_THEME_PYSOL },
+#endif
+#endif /* !HAVE_HILDON */
+#ifdef ENABLE_CARD_THEME_FORMAT_FIXED
+    { "fixed", GAMES_TYPE_CARD_THEME_FIXED },
+#endif
+  };
+  GType type = G_TYPE_INVALID;
+
+  if (type_str_len == 0) {
+    /* Use the default type */
+#ifdef HAVE_HILDON
+    type = GAMES_TYPE_CARD_THEME_FIXED;
+#else
+    type = GAMES_TYPE_CARD_THEME_SVG;
+#endif
+  } else {
+    guint i;
+
+    for (i = 0; i < G_N_ELEMENTS (type_strings); ++i) {
+      if (strncmp (type_str, type_strings[i].name, type_str_len) == 0) {
+        type = type_strings[i].type;
+        break;
+      }
+    }
+  }
+
+  return type;
+}
+
+static gboolean
+games_card_themes_foreach_theme_dir (GType type,
+                                     GamesCardThemeForeachFunc callback,
+                                     gpointer data)
+{
+  GamesCardThemeClass *klass;
+  gboolean retval;
+
+  klass = g_type_class_ref (type);
+  if (!klass)
+    return TRUE;
+
+  _games_profile_start ("foreach %s card themes", G_OBJECT_CLASS_NAME (klass));
+  retval = _games_card_theme_class_foreach_theme_dir (klass, callback, data);
+  _games_profile_end ("foreach %s card themes", G_OBJECT_CLASS_NAME (klass));
+
+  g_type_class_unref (klass);
+  return retval;
+}
+
+static gboolean
+games_card_themes_foreach_theme_type_and_dir (GamesCardThemes *theme_manager,
+                                              GamesCardThemeForeachFunc callback,
+                                              gpointer data)
+{
+  guint i;
+  gboolean retval = TRUE;
+
+  for (i = 0; i < theme_manager->n_theme_types; ++i) {
+    retval = games_card_themes_foreach_theme_dir (theme_manager->theme_types[i], callback, data);
+    if (!retval)
+      break;
+  }
+
+  return retval;
+}
 
 static gboolean
-_games_card_themes_get_theme_info_foreach (GamesCardThemeClass *klass,
-                                           const char *path,
-                                           GamesCardThemes *theme_manager)
+games_card_themes_get_theme_infos_in_dir (GamesCardThemeClass *klass,
+                                          const char *path,
+                                          GamesCardThemes *theme_manager)
 {
   GDir *iter;
   const char *filename;
@@ -87,45 +178,36 @@
   return TRUE;
 }
 
+typedef struct {
+  const char *filename;
+  GamesCardThemeInfo *theme_info;
+} LookupData;
+
+static gboolean
+games_card_themes_try_theme_info_by_filename (GamesCardThemeClass *klass,
+                                              const char *path,
+                                              LookupData *data)
+{
+  /* Try constructing the theme info */
+  data->theme_info = _games_card_theme_class_get_theme_info (klass, path, data->filename);
+
+  /* Continue until found */
+  return data->theme_info == NULL;
+}
+
 static void
 _games_card_theme_ensure_theme_infos (GamesCardThemes *theme_manager)
 {
-  /* FIXME: take env vars and prefs into account on ordering here */
-  GType types[] = {
-#ifdef HAVE_RSVG
-    GAMES_TYPE_CARD_THEME_SVG,
-    GAMES_TYPE_CARD_THEME_KDE,
-#endif
-#ifndef HAVE_HILDON
-    GAMES_TYPE_CARD_THEME_SLICED,
-    GAMES_TYPE_CARD_THEME_PYSOL,
-#endif
-    GAMES_TYPE_CARD_THEME_FIXED
-  };
-  guint i;
-
   if (!theme_manager->theme_infos_update_needed)
     return;
 
   _games_profile_start ("looking for card themes");
-
-  for (i = 0; i < G_N_ELEMENTS (types); ++i) {
-    GamesCardThemeClass *klass;
-
-    klass = g_type_class_ref (types[i]);
-    if (!klass)
-      continue;
-
-    _games_profile_start ("looking for %s card themes", G_OBJECT_CLASS_NAME (klass));
-    _games_card_theme_class_foreach_theme_dir (klass,
-                                               (GamesCardThemeForeachFunc) _games_card_themes_get_theme_info_foreach,
-                                               theme_manager);
-    _games_profile_end ("looking for %s card themes", G_OBJECT_CLASS_NAME (klass));
-
-    g_type_class_unref (klass);
-  }
-
+  games_card_themes_foreach_theme_type_and_dir (theme_manager,
+                                                (GamesCardThemeForeachFunc) games_card_themes_get_theme_infos_in_dir,
+                                                theme_manager);
   _games_profile_end ("looking for card themes");
+
+  g_signal_emit (theme_manager, signals[CHANGED], 0);
 }
 
 typedef struct {
@@ -143,13 +225,22 @@
       strcmp (info->filename, data->filename) != 0)
     return;
 
-  data->theme_info = info;
+  if (data->theme_info == NULL)
+    data->theme_info = info;
+}
+
+static void
+foreach_add_to_list (gpointer key,
+                     gpointer data,
+                     GList **list)
+{
+  *list = g_list_prepend (*list, data);
 }
 
 static GamesCardThemeInfo *
-_games_card_themes_get_info_by_type_and_name (GamesCardThemes *theme_manager,
-                                              GType type,
-                                              const char *filename)
+games_card_themes_get_info_by_type_and_filename (GamesCardThemes *theme_manager,
+                                                 GType type,
+                                                 const char *filename)
 {
   FindData data = { type, filename, NULL };
 
@@ -158,14 +249,6 @@
   return data.theme_info;
 }
 
-static void
-foreach_add_to_list (gpointer key,
-                     gpointer data,
-                     GList **list)
-{
-  *list = g_list_prepend (*list, data);
-}
-
 /* Class implementation */
 
 G_DEFINE_TYPE (GamesCardThemes, games_card_themes, G_TYPE_OBJECT);
@@ -173,12 +256,30 @@
 static void
 games_card_themes_init (GamesCardThemes *theme_manager)
 {
+  GType *types;
+  guint n_types = 0;
+
   /* Hash table: pref name => theme info */
   theme_manager->theme_infos = g_hash_table_new_full (g_str_hash, g_str_equal,
                                                       NULL /* key is owned by data */,
                                                       (GDestroyNotify) games_card_theme_info_unref);
 
   theme_manager->theme_infos_update_needed = TRUE;
+
+  types = theme_manager->theme_types = g_new (GType, N_THEME_TYPES);
+
+  /* List of supported theme types, in order of decreasing precedence */
+#ifdef HAVE_RSVG
+  types[n_types++] = GAMES_TYPE_CARD_THEME_SVG;
+  types[n_types++] = GAMES_TYPE_CARD_THEME_KDE;
+#endif
+#ifndef HAVE_HILDON
+  types[n_types++] = GAMES_TYPE_CARD_THEME_SLICED;
+  types[n_types++] = GAMES_TYPE_CARD_THEME_PYSOL;
+#endif
+  types[n_types++] = GAMES_TYPE_CARD_THEME_FIXED;
+
+  theme_manager->n_theme_types = n_types;
 }
 
 static void
@@ -191,38 +292,18 @@
   G_OBJECT_CLASS (games_card_themes_parent_class)->finalize (object);
 }
 
-#if 0
-static void
-games_card_theme_set_property (GObject * object,
-                               guint prop_id,
-                               const GValue * value, GParamSpec * pspec)
-{
-  GamesCardTheme *theme = GAMES_CARD_THEME (object);
-
-  switch (prop_id) {
-    case PROP_THEME_INFO:
-      theme->theme_info = g_value_dup_boxed (value);
-      break;
-  }
-}
-#endif
-
 static void
 games_card_themes_class_init (GamesCardThemesClass * klass)
 {
   GObjectClass *gobject_class = G_OBJECT_CLASS (klass);
 
-//  gobject_class->set_property = games_card_themes_set_property;
   gobject_class->finalize = games_card_themes_finalize;
 
-#if 0
   /**
-   * GamesCardTheme:changed:
-   * @themes: the object on which the signal is emitted
+   * GamesCardThemes:changed:
    *
-   * The ::changed signal is emitted when the card themes has
-   * changed in any way that makes it necessary to re-render
-   * any displayed or cached images.
+   * The ::changed signal is emitted when the list of card themes has
+   * changed.
    */
   signals[CHANGED] =
     g_signal_newv ("changed",
@@ -233,11 +314,8 @@
                    g_cclosure_marshal_VOID__VOID,
                    G_TYPE_NONE,
                    0, NULL);
-#endif
 }
 
-/* private API */
-
 /* public API */
 
 /**
@@ -266,6 +344,7 @@
   GamesCardTheme *theme;
   GError *error = NULL;
 
+  g_return_val_if_fail (GAMES_IS_CARD_THEMES (theme_manager), NULL);
   g_return_val_if_fail (info != NULL, NULL);
 
   if (info->type == G_TYPE_INVALID)
@@ -294,7 +373,7 @@
 }
 
 /**
- * games_card_themes_get_theme_by_name:
+ * games_card_themes_get_theme_info_by_name:
  * @theme_name: a theme name
  *
  * This function exists only for backward compatibility with
@@ -303,94 +382,102 @@
  * Returns: a new #GamesCardTheme for @name, or %NULL if there was an
  *  error while loading the theme.
  */
-GamesCardTheme *
-games_card_themes_get_theme_by_name (GamesCardThemes *theme_manager,
-                                     const char *theme_name)
+GamesCardThemeInfo *
+games_card_themes_get_theme_info_by_name (GamesCardThemes *theme_manager,
+                                          const char *theme_name)
 {
-  char *colon, *free_me = NULL;
-  const char *filename;
-  gsize type_str_len;
-  GType type = G_TYPE_INVALID;
+  const char *colon, *filename, *dot;
+  char *free_me = NULL;
+  GType type;
+  LookupData data;
   GamesCardThemeInfo *theme_info = NULL;
 
-  if (!theme_name || !theme_name[0])
-    goto default_fallback;
+  g_return_val_if_fail (GAMES_IS_CARD_THEMES (theme_manager), NULL);
 
-  _games_card_theme_ensure_theme_infos (theme_manager);
+  if (!theme_name || !theme_name[0])
+    return NULL;
 
   colon = strchr (theme_name, ':');
+  type = theme_type_from_string (theme_name, colon ? colon - theme_name : 0);
+  if (type == G_TYPE_INVALID)
+    return NULL;
+
   if (colon) {
-    type_str_len = colon - theme_name;
+    /* Get the filename from the theme name */
 
     filename = colon + 1;
+    dot = strrchr (filename, '.');
 
-#ifdef HAVE_RSVG
-    if (strncmp (theme_name, "svg", type_str_len) == 0) {
-      type = GAMES_TYPE_CARD_THEME_SVG;
-    } else if (strncmp (theme_name, "kde", type_str_len) == 0) {
-      type = GAMES_TYPE_CARD_THEME_KDE;
-    } else
+    if (dot == NULL) {
+      /* No dot? Try appending the default, for compatibility with old settings */
+#if defined(HAVE_HILDON)
+      filename = free_me = g_strconcat (filename, ".card-theme", NULL);
+#elif defined(HAVE_RSVG)
+      filename = free_me = g_strconcat (filename, ".svg", NULL);
 #endif
-#ifndef HAVE_HILDON
-    if (strncmp (theme_name, "sliced", type_str_len) == 0) {
-      type = GAMES_TYPE_CARD_THEME_SLICED;
-    } else if (strncmp (theme_name, "pysol", type_str_len) == 0) {
-      type = GAMES_TYPE_CARD_THEME_PYSOL;
-      filename = free_me = g_strdup_printf ("cardset-%s", filename);
-    } else
-#endif
-    if (strncmp (theme_name, "fixed", type_str_len) == 0)
-      type = GAMES_TYPE_CARD_THEME_FIXED;
-  } else {
+    } else {
 #ifdef HAVE_GNOME
-    /* Compatibility with old settings */
-#ifdef HAVE_RSVG
-    if (g_str_has_suffix (theme_name, ".svg")) {
-      type = GAMES_TYPE_CARD_THEME_SVG;
-      filename = theme_name;
-    } else
-#endif
-    if (g_str_has_suffix (theme_name, ".png")) {
-      type = GAMES_TYPE_CARD_THEME_SLICED;
-      filename = theme_name;
-    } else
+      if (g_str_has_suffix (filename, ".png")) {
+        char *base_name;
+
+        /* Very old version; replace .png with .svg */
+        base_name = g_strndup (filename, dot - filename);
+        filename = free_me = g_strconcat (base_name, ".svg", NULL);
+        g_free (base_name);
+      }
 #endif /* HAVE_GNOME */
-    {
-#ifdef HAVE_HILDON
-      type = GAMES_TYPE_CARD_THEME_FIXED;
-      filename = free_me = g_strconcat (theme_name, ".card-theme", NULL);
-#else
-      type = GAMES_TYPE_CARD_THEME_SVG;
-      filename = free_me = g_strconcat (theme_name, ".svg", NULL);
-#endif
     }
+  } else {
+    filename = theme_name;
   }
-  if (type == G_TYPE_INVALID)
-    return NULL;
+  if (!filename[0])
+    goto out;
+
+  /* First try to find the theme in our hash table */
+  theme_info = games_card_themes_get_info_by_type_and_filename (theme_manager,
+                                                                type,
+                                                                filename);
+  if (theme_info)
+    goto out;
+
+  /* Not in our hash table, and the list is uptodate? No such theme! */
+  if (!theme_manager->theme_infos_update_needed)
+    goto out;
 
-  theme_info = _games_card_themes_get_info_by_type_and_name (theme_manager, type, filename);
+  /* Then, try to find it in one of the theme dirs */
+  data.filename = filename;
+  data.theme_info = NULL;
+  games_card_themes_foreach_theme_dir (type, (GamesCardThemeForeachFunc) games_card_themes_try_theme_info_by_filename, &data);
+  theme_info = data.theme_info;
+
+out:
   g_free (free_me);
 
-default_fallback:
+  return theme_info;
+}
+
+#if 0
+static GamesCardThemeInfo *
+games_card_themes_get_default_theme_info (GamesCardThemes *theme_manager)
+{
+  GType type;
+  char *filename;
+  GamesCardThemeInfo *theme_info;
 
-  if (!theme_info) {
-    /* Try falling back to the default */
 #ifdef HAVE_HILDON
-    type = GAMES_TYPE_CARD_THEME_FIXED;
-    filename = free_me = g_strconcat (GAMES_CARD_THEME_DEFAULT, ".card-theme", NULL);
+  type = GAMES_TYPE_CARD_THEME_FIXED;
+  filename = g_strconcat (GAMES_CARD_THEME_DEFAULT, ".card-theme", NULL);
 #else
-    type = GAMES_TYPE_CARD_THEME_SVG;
-    filename = free_me = g_strconcat (GAMES_CARD_THEME_DEFAULT, ".svg", NULL);
+  type = GAMES_TYPE_CARD_THEME_SVG;
+  filename = g_strconcat (GAMES_CARD_THEME_DEFAULT, ".svg", NULL);
 #endif
-    theme_info = _games_card_themes_get_info_by_type_and_name (theme_manager, type, filename);
-    g_free (free_me);
-  }
 
-  if (theme_info)
-    return games_card_themes_get_theme (theme_manager, theme_info);
+  theme_info = games_card_themes_get_info_by_type_and_filename (theme_manager, type, filename);
+  g_free (filename);
 
-  return NULL;
+  return theme_info;
 }
+#endif
 
 /**
  * games_card_themes_get_theme_any:
@@ -405,6 +492,8 @@
 {
 //   GList *l;
 
+  g_return_val_if_fail (GAMES_IS_CARD_THEMES (theme_manager), NULL);
+
   _games_card_theme_ensure_theme_infos (theme_manager);
 
 /*  if (!theme_infos)
@@ -423,15 +512,17 @@
 }
 
 /**
- * games_card_themes_get_theme_all:
+ * games_card_themes_get_themes:
  *
  * Returns:
  */
 GList *
-games_card_themes_get_theme_all (GamesCardThemes *theme_manager)
+games_card_themes_get_themes (GamesCardThemes *theme_manager)
 {
   GList *list = NULL;
 
+  g_return_val_if_fail (GAMES_IS_CARD_THEMES (theme_manager), NULL);
+
   _games_card_theme_ensure_theme_infos (theme_manager);
 
   g_hash_table_foreach (theme_manager->theme_infos, (GHFunc) foreach_add_to_list, &list);

Modified: trunk/libgames-support/games-card-themes.h
==============================================================================
--- trunk/libgames-support/games-card-themes.h	(original)
+++ trunk/libgames-support/games-card-themes.h	Tue Jan  6 18:20:14 2009
@@ -1,6 +1,6 @@
 /*
   Copyright  2004 Callum McKenzie
-  Copyright  2007, 2008 Christian Persch
+   Copyright  2007, 2008, 2009 Christian Persch
 
   This library is free software; you can redistribute it and'or modify
   it under the terms of the GNU Library General Public License as published
@@ -46,12 +46,12 @@
 GamesCardTheme *games_card_themes_get_theme (GamesCardThemes *theme_manager,
                                              GamesCardThemeInfo *info);
 
-GamesCardTheme *games_card_themes_get_theme_by_name (GamesCardThemes *theme_manager,
-                                                     const char *theme_name);
-
 GamesCardTheme *games_card_themes_get_theme_any (GamesCardThemes *theme_manager);
 
-GList *games_card_themes_get_theme_all (GamesCardThemes *theme_manager);
+GamesCardThemeInfo *games_card_themes_get_theme_info_by_name (GamesCardThemes *theme_manager,
+                                                              const char *theme_name);
+
+GList *games_card_themes_get_themes (GamesCardThemes *theme_manager);
 
 G_END_DECLS
 



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