gnome-games r8464 - in trunk: aisleriot libgames-support



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

Log:
Fix loading the initial theme from pref.

Modified:
   trunk/aisleriot/window.c
   trunk/libgames-support/games-card-theme.c

Modified: trunk/aisleriot/window.c
==============================================================================
--- trunk/aisleriot/window.c	(original)
+++ trunk/aisleriot/window.c	Tue Jan  6 18:19:27 2009
@@ -2329,7 +2329,8 @@
   GtkWidget *main_vbox;
   GtkAccelGroup *accel_group;
   GtkAction *action;
-//FIXMEchpe  char *theme;
+  char *theme_name;
+  GamesCardTheme *theme;
   guint i;
 #ifdef HAVE_HILDON
   GtkToolItem *tool_item;
@@ -2380,27 +2381,17 @@
 
   aisleriot_board_set_pixbuf_drawing (priv->board, priv->use_pixbuf_drawing);
 
-#if 0
-  // FIXMEchpe
-  theme = games_conf_get_string (NULL, aisleriot_conf_get_key (CONF_THEME), NULL);
-  if (!theme || !theme[0]) {
-    g_free (theme);
-    theme = g_strdup (GAMES_CARD_THEME_DEFAULT);
-  }
-#ifdef HAVE_GNOME
-  /* Compatibility with old settings */
-  if (g_str_has_suffix (theme, ".svg")) {
-    *g_strrstr (theme, ".svg") = '\0';
-  } else if (g_str_has_suffix (theme, ".png")) {
-    *g_strrstr (theme, ".png") = '\0';
+  theme_name = games_conf_get_string (NULL, aisleriot_conf_get_key (CONF_THEME), NULL);
+  theme = games_card_theme_get_by_name (theme_name);
+  g_free (theme_name);
+  if (!theme) {
+    theme = games_card_theme_get_any ();
+  }
+  if (theme) {
+    aisleriot_window_take_card_theme (window, theme /* adopts */);
+  } else {
+    /* FIXMEchpe: FUCK, what now? Panic! */
   }
-#endif
-
-  aisleriot_board_set_card_theme (priv->board, theme);
-  g_free (theme);
-#endif
-
-  aisleriot_window_take_card_theme (window, games_card_theme_get_any ());
 
   priv->action_group = gtk_action_group_new ("MenuActions");
   gtk_action_group_set_translation_domain (priv->action_group, GETTEXT_PACKAGE);

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:19:27 2009
@@ -46,45 +46,8 @@
 };
 
 static guint signals[LAST_SIGNAL];
-
 static GList *theme_infos;
 
-#if 0
-static GType
-get_default_theme_type (void)
-{
-  GType type;
-  const char *env;
-
-#if defined(HAVE_RSVG) && !defined(HAVE_HILDON)
-  /* Default to scalable */
-  type = GAMES_TYPE_CARD_THEME_SVG;
-#else
-  /* Default to non-scalable */
-  type = GAMES_TYPE_CARD_THEME_FIXED;
-#endif
-
-#ifndef HAVE_HILDON
-  env = g_getenv ("GAMES_CARD_THEME_FORMAT");
-  if (env) {
-#ifdef HAVE_RSVG
-    if (strcmp (env, "svg") == 0)
-      type = GAMES_TYPE_CARD_THEME_SVG;
-    else if (strcmp (env, "kde") == 0)
-      type = GAMES_TYPE_CARD_THEME_KDE;
-    else
-#endif
-    if (strcmp (env, "sliced") == 0)
-      type = GAMES_TYPE_CARD_THEME_SLICED;
-    else if (strcmp (env, "fixed") == 0)
-      type = GAMES_TYPE_CARD_THEME_FIXED;
-  }
-#endif /* !HAVE_HILDON */
-
-  return type;
-}
-#endif
-
 static void
 _games_card_theme_ensure_theme_infos (void)
 {
@@ -128,6 +91,27 @@
   theme_infos = g_list_reverse (theme_infos);
 }
 
+static GamesCardThemeInfo *
+_games_card_theme_get_info_by_type_and_name (GType type,
+                                             const char *filename)
+{
+  GList *l;
+  GamesCardThemeInfo *theme_info = NULL;
+
+  for (l = theme_infos; l != NULL; l = l->next) {
+    GamesCardThemeInfo *info = (GamesCardThemeInfo *) l->data;
+
+    if (info->type != type ||
+        strcmp (info->filename, filename) != 0)
+      continue;
+
+    theme_info = info;
+    break;
+  }
+
+  return theme_info;
+}
+
 #if 0
 static gboolean
 games_card_theme_load_theme_with_fallback (GamesCardTheme *theme,
@@ -561,48 +545,116 @@
 GamesCardTheme *
 games_card_theme_get_by_name (const char *theme_name)
 {
-  GList *l;
+  char *colon, *free_me = NULL;
+  const char *filename;
+  gsize type_str_len;
+  GType type = G_TYPE_INVALID;
+  GamesCardThemeInfo *theme_info = NULL;
 
-  //XXX FIXMEchpe .svg / .png suffix stripping
-  g_return_val_if_fail (theme_name != NULL, NULL);
+  if (!theme_name)
+    goto default_fallback;
 
   _games_card_theme_ensure_theme_infos ();
 
-  for (l = theme_infos; l != NULL; l = l->next) {
-    GamesCardThemeInfo *info = (GamesCardThemeInfo *) l->data;
+  colon = strchr (theme_name, ':');
+  if (colon) {
+    type_str_len = colon - theme_name;
+
+    filename = colon + 1;
+
+#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
+#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;
+    else
+#endif
+    if (strncmp (theme_name, "fixed", type_str_len) == 0)
+      type = GAMES_TYPE_CARD_THEME_FIXED;
+  } 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
+#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
+    }
+  }
+  if (type == G_TYPE_INVALID)
+    return NULL;
+
+  theme_info = _games_card_theme_get_info_by_type_and_name (type, filename);
+  g_free (free_me);
+
+default_fallback:
 
-    // FIXMEchpe
-    if (g_str_has_prefix (theme_name, info->filename))
-      return games_card_theme_get (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);
+#else
+    type = GAMES_TYPE_CARD_THEME_SVG;
+    filename = free_me = g_strconcat (GAMES_CARD_THEME_DEFAULT, ".svg", NULL);
+#endif
+    theme_info = _games_card_theme_get_info_by_type_and_name (type, filename);
+    g_free (free_me);
   }
 
+  if (theme_info)
+    return games_card_theme_get (theme_info);
+
   return NULL;
 }
 
 /**
  * games_card_theme_get_any:
  *
- * FIXMEchpe
- * Loads the card theme @theme_name. If the card theme cannot be loaded,
- * it falls back to the default card theme, if present.
- * After changing the theme, the card size will be undefined; you need
- * to call games_card_theme_set_size() to set it before getting a
- * card from @theme again.
- * 
+ * Loads all card themes until loading one succeeds, and returns it; or
+ * %NULL if all card themes fail to load.
+ *
  * Returns:
  */
 GamesCardTheme *
 games_card_theme_get_any (void)
 {
+  GList *l;
   _games_card_theme_ensure_theme_infos ();
 
   if (!theme_infos)
     return NULL;
 
-  // FIXMEchpe obviously
-  return games_card_theme_get ((GamesCardThemeInfo *) theme_infos->data);
-  return games_card_theme_get_by_name (GAMES_CARD_THEME_DEFAULT);
-  // FIXMEchpe put the fallback in here
+  for (l = theme_infos; l != NULL; l = l->next) {
+    GamesCardThemeInfo *info = (GamesCardThemeInfo *) l->data;
+    GamesCardTheme *theme;
+
+    theme = games_card_theme_get (info);
+    if (theme)
+      return theme;
+  }
+
   return NULL;
 }
 



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