gnome-games r8487 - in trunk: aisleriot blackjack/src libgames-support
- From: chpe svn gnome org
- To: svn-commits-list gnome org
- Subject: gnome-games r8487 - in trunk: aisleriot blackjack/src libgames-support
- Date: Tue, 6 Jan 2009 18:20:11 +0000 (UTC)
Author: chpe
Date: Tue Jan 6 18:20:10 2009
New Revision: 8487
URL: http://svn.gnome.org/viewvc/gnome-games?rev=8487&view=rev
Log:
Split card theme management into its own class.
Added:
trunk/libgames-support/games-card-themes.c
trunk/libgames-support/games-card-themes.h
Modified:
trunk/aisleriot/window.c
trunk/blackjack/src/card.cpp
trunk/libgames-support/Makefile.am
trunk/libgames-support/games-card-selector.c
trunk/libgames-support/games-card-selector.h
trunk/libgames-support/games-card-theme.c
trunk/libgames-support/games-card-theme.h
trunk/libgames-support/render-cards.c
Modified: trunk/aisleriot/window.c
==============================================================================
--- trunk/aisleriot/window.c (original)
+++ trunk/aisleriot/window.c Tue Jan 6 18:20:10 2009
@@ -39,6 +39,7 @@
#endif /* HAVE_HILDON */
#include <libgames-support/games-card-theme.h>
+#include <libgames-support/games-card-themes.h>
#include <libgames-support/games-clock.h>
#include <libgames-support/games-files.h>
#include <libgames-support/games-stock.h>
@@ -96,6 +97,8 @@
{
AisleriotGame *game;
AisleriotBoard *board;
+
+ GamesCardThemes *theme_manager;
GamesCardTheme *theme;
#ifdef HAVE_HILDON
@@ -1480,7 +1483,7 @@
if (new_theme_info == current_theme_info)
return;
- theme = games_card_theme_get (new_theme_info);
+ theme = games_card_themes_get_theme (priv->theme_manager, new_theme_info);
if (!theme) {
GSList *group, *l;
@@ -1540,7 +1543,7 @@
/* See gtk bug #424448 */
gtk_ui_manager_ensure_update (priv->ui_manager);
- list = games_card_theme_get_all ();
+ list = games_card_themes_get_theme_all (priv->theme_manager);
/* No need to install the menu when there's only one theme available anyway */
if (list == NULL || list->next == NULL) {
@@ -2397,15 +2400,17 @@
#endif /* HAVE_MAEMO */
+ priv->theme_manager = games_card_themes_new ();
+
priv->board = AISLERIOT_BOARD (aisleriot_board_new (priv->game));
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_theme_get_by_name (theme_name);
+ theme = games_card_themes_get_theme_by_name (priv->theme_manager, theme_name);
g_free (theme_name);
if (!theme) {
- theme = games_card_theme_get_any ();
+ theme = games_card_themes_get_theme_any (priv->theme_manager);
}
if (theme) {
aisleriot_window_take_card_theme (window, theme /* adopts */);
@@ -2664,6 +2669,8 @@
g_object_unref (priv->theme);
}
+ g_object_unref (priv->theme_manager);
+
g_signal_handlers_disconnect_matched (priv->game,
G_SIGNAL_MATCH_DATA,
0, 0, NULL, NULL, window);
Modified: trunk/blackjack/src/card.cpp
==============================================================================
--- trunk/blackjack/src/card.cpp (original)
+++ trunk/blackjack/src/card.cpp Tue Jan 6 18:20:10 2009
@@ -40,6 +40,7 @@
GdkBitmap *mask;
+GamesCardThemes *theme_manager = NULL;
GamesCardTheme *theme = NULL;
GamesCardImages *images = NULL;
@@ -119,14 +120,17 @@
{
CardSize card_size;
+ if (!theme_manager) {
+ theme_manager = games_card_themes_new ();
+ }
if (!theme) {
char *card_theme;
card_theme = bj_get_card_style ();
- theme = games_card_theme_get_by_name (card_theme);
+ theme = games_card_themes_get_theme_by_name (theme_manager, card_theme);
if (!theme) {
g_warning ("Failed to load theme %s!", card_theme);
- theme = games_card_theme_get_any ();
+ theme = games_card_themes_get_theme_any (theme_manager);
}
if (!theme) {
g_warning ("Failed to load any theme !");
@@ -157,9 +161,10 @@
{
GamesCardTheme *new_theme;
+ g_assert (theme_manager != NULL);
g_assert (theme != NULL);
- new_theme = games_card_theme_get_by_name (card_theme);
+ new_theme = games_card_themes_get_theme_by_name (theme_manager, card_theme);
if (!new_theme) {
g_warning ("Failed to load theme %s\n", card_theme);
return;
@@ -187,10 +192,10 @@
{
GtkWidget *selector;
- if (!theme)
+ if (!theme_manager || !theme)
return NULL;
- selector = games_card_selector_new (games_card_theme_get_theme_info (theme));
+ selector = games_card_selector_new (theme_manager, games_card_theme_get_theme_info (theme));
g_signal_connect (selector, "changed",
G_CALLBACK (card_deck_options_changed), NULL);
Modified: trunk/libgames-support/Makefile.am
==============================================================================
--- trunk/libgames-support/Makefile.am (original)
+++ trunk/libgames-support/Makefile.am Tue Jan 6 18:20:10 2009
@@ -33,6 +33,8 @@
games-card-theme.h \
games-card-theme-private.h \
games-card-theme-fixed.c \
+ games-card-themes.c \
+ games-card-themes.h \
games-conf.c \
games-conf.h \
games-debug.c \
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:10 2009
@@ -67,7 +67,8 @@
}
static GtkWidget *
-create_combo_box (GamesCardThemeInfo *selected_info)
+create_combo_box (GamesCardThemes *theme_manager,
+ GamesCardThemeInfo *selected_info)
{
GtkListStore *store;
GtkTreeIter iter, selection_iter;
@@ -78,7 +79,8 @@
store = gtk_list_store_new (N_COLUMNS, GAMES_TYPE_CARD_THEME_INFO, G_TYPE_STRING);
- themes = games_card_theme_get_all ();
+ themes = games_card_themes_get_theme_all (theme_manager);
+
for (l = themes; l != NULL; l = l->next) {
GamesCardThemeInfo *info = l->data;
@@ -109,7 +111,8 @@
}
GtkWidget *
-games_card_selector_new (GamesCardThemeInfo *selected_info)
+games_card_selector_new (GamesCardThemes *theme_manager,
+ GamesCardThemeInfo *selected_info)
{
GamesCardSelector *selector;
@@ -117,7 +120,7 @@
games_frame_set_label (GAMES_FRAME (selector), _("Card Style"));
- selector->combobox = create_combo_box (selected_info);
+ selector->combobox = create_combo_box (theme_manager, selected_info);
g_signal_connect (selector->combobox, "changed",
G_CALLBACK (combo_changed_cb), selector);
Modified: trunk/libgames-support/games-card-selector.h
==============================================================================
--- trunk/libgames-support/games-card-selector.h (original)
+++ trunk/libgames-support/games-card-selector.h Tue Jan 6 18:20:10 2009
@@ -26,6 +26,7 @@
#include "games-frame.h"
#include "games-card-theme.h"
+#include "games-card-themes.h"
G_BEGIN_DECLS
@@ -51,7 +52,8 @@
GType games_card_selector_get_type (void);
-GtkWidget *games_card_selector_new (GamesCardThemeInfo *selected_info);
+GtkWidget *games_card_selector_new (GamesCardThemes *theme_manager,
+ GamesCardThemeInfo *selected_info);
G_END_DECLS
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:10 2009
@@ -26,7 +26,6 @@
#include <gtk/gtk.h>
#include "games-debug.h"
-#include "games-preimage.h"
#include "games-profile.h"
#include "games-runtime.h"
@@ -44,125 +43,6 @@
};
static guint signals[LAST_SIGNAL];
-static GHashTable *theme_infos;
-
-static gboolean
-_games_card_theme_class_get_theme_info_foreach (GamesCardThemeClass *klass,
- const char *path,
- gpointer data)
-{
- GHashTable *hash_table = (GHashTable *) data;
- GDir *iter;
- const char *filename;
-
- _games_profile_start ("looking for %s card themes in %s", G_OBJECT_CLASS_NAME (klass), path);
-
- iter = g_dir_open (path, 0, NULL);
- if (!iter)
- goto out;
-
- while ((filename = g_dir_read_name (iter)) != NULL) {
- GamesCardThemeInfo *info;
-
- _games_profile_start ("checking for %ss card theme in file %s", G_OBJECT_CLASS_NAME (klass), filename);
- info = _games_card_theme_class_get_theme_info (klass, path, filename);
- _games_profile_end ("checking for %ss card theme in file %s", G_OBJECT_CLASS_NAME (klass), filename);
-
- if (info)
- g_hash_table_insert (hash_table, info->pref_name, info);
- }
-
- g_dir_close (iter);
-
-out:
- _games_profile_end ("looking for %s card themes in %s", G_OBJECT_CLASS_NAME (klass), path);
-
- return TRUE;
-}
-
-static void
-_games_card_theme_ensure_theme_infos (void)
-{
- /* 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_infos)
- return;
-
- /* Hash table: pref name => theme info */
- 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);
-
- _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,
- _games_card_theme_class_get_theme_info_foreach,
- theme_infos);
- _games_profile_end ("looking for %s card themes", G_OBJECT_CLASS_NAME (klass));
-
- g_type_class_unref (klass);
- }
-
- _games_profile_end ("looking for card themes");
-}
-
-typedef struct {
- GType type;
- const char *filename;
- GamesCardThemeInfo *theme_info;
-} FindData;
-
-static void
-find_by_type_and_name (gpointer key,
- GamesCardThemeInfo *info,
- FindData *data)
-{
- if (info->type != data->type ||
- strcmp (info->filename, data->filename) != 0)
- return;
-
- data->theme_info = info;
-}
-
-static GamesCardThemeInfo *
-_games_card_theme_get_info_by_type_and_name (GType type,
- const char *filename)
-{
- FindData data = { type, filename, NULL };
-
- g_assert (theme_infos != NULL);
- g_hash_table_foreach (theme_infos, (GHFunc) find_by_type_and_name, &data);
-
- return data.theme_info;
-}
-
-static void
-foreach_add_to_list (gpointer key,
- gpointer data,
- GList **list)
-{
- *list = g_list_prepend (*list, data);
-}
/* Class implementation */
@@ -447,191 +327,6 @@
return pixbuf;
}
-/**
- * games_card_theme_get:
- * @info: a #GamesCardThemeInfo
- *
- * Returns: a new #GamesCardTheme for @info, or %NULL if there was an
- * error while loading the theme.
- */
-GamesCardTheme *
-games_card_theme_get (GamesCardThemeInfo *info)
-{
- GamesCardTheme *theme;
- GError *error = NULL;
-
- g_return_val_if_fail (info != NULL, NULL);
-
- if (info->type == G_TYPE_INVALID)
- return NULL;
-
- _games_profile_start ("loading %s card theme %s", g_type_name (info->type), info->display_name);
-
- theme = g_object_new (info->type, "theme-info", info, NULL);
- if (!theme->klass->load (theme, &error)) {
- _games_debug_print (GAMES_DEBUG_CARD_THEME,
- "Failed to load card theme %s: %s\n",
- info->display_name, error ? error->message : "(no error information)");
-
- g_clear_error (&error);
- g_object_unref (theme);
- theme = NULL;
- } else {
- _games_debug_print (GAMES_DEBUG_CARD_THEME,
- "Successfully loaded card theme %s\n",
- info->display_name);
- }
-
- _games_profile_end ("loading %s card theme %s", g_type_name (info->type), info->display_name);
-
- return theme;
-}
-
-/**
- * games_card_theme_get_by_name:
- * @theme_name: a theme name
- *
- * This function exists only for backward compatibility with
- * older aisleriot versions' preferences.
- *
- * Returns: a new #GamesCardTheme for @name, or %NULL if there was an
- * error while loading the theme.
- */
-GamesCardTheme *
-games_card_theme_get_by_name (const char *theme_name)
-{
- char *colon, *free_me = NULL;
- const char *filename;
- gsize type_str_len;
- GType type = G_TYPE_INVALID;
- GamesCardThemeInfo *theme_info = NULL;
-
- if (!theme_name || !theme_name[0])
- goto default_fallback;
-
- _games_card_theme_ensure_theme_infos ();
-
- 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;
- 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 {
-#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:
-
- 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:
- *
- * 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;
-
- 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;
-}
-
-/**
- * games_card_theme_get_all:
- *
- * Returns:
- */
-GList *
-games_card_theme_get_all (void)
-{
- GList *list = NULL;
-
- _games_card_theme_ensure_theme_infos ();
-
- g_hash_table_foreach (theme_infos, (GHFunc) foreach_add_to_list, &list);
-
- return g_list_sort (list, (GCompareFunc) _games_card_theme_info_collate);
-}
-
/* GamesCardThemeInfo impl */
static int
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:10 2009
@@ -91,16 +91,6 @@
GdkPixbuf *games_card_theme_get_card_pixbuf (GamesCardTheme * theme,
int cardid);
-/* Utility functions */
-
-GamesCardTheme *games_card_theme_get (GamesCardThemeInfo *info);
-
-GamesCardTheme *games_card_theme_get_by_name (const char *theme_name);
-
-GamesCardTheme *games_card_theme_get_any (void);
-
-GList *games_card_theme_get_all (void);
-
G_END_DECLS
#endif /* GAMES_CARD_THEME_H */
Added: trunk/libgames-support/games-card-themes.c
==============================================================================
--- (empty file)
+++ trunk/libgames-support/games-card-themes.c Tue Jan 6 18:20:10 2009
@@ -0,0 +1,440 @@
+/*
+ Copyright  2004 Callum McKenzie
+ Copyright  2007, 2008 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
+ by the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+/* Authors: Callum McKenzie <callum physics otago ac nz> */
+
+#include <config.h>
+
+#include <string.h>
+#include <glib.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gtk/gtk.h>
+
+#include "games-debug.h"
+#include "games-profile.h"
+#include "games-runtime.h"
+
+#include "games-card-themes.h"
+#include "games-card-theme-private.h"
+
+struct _GamesCardThemesClass {
+ GObjectClass parent_class;
+};
+
+struct _GamesCardThemes {
+ GObject parent;
+
+ GHashTable *theme_infos;
+ gboolean theme_infos_update_needed;
+};
+
+enum {
+ PROP_0
+};
+
+enum {
+ CHANGED,
+ LAST_SIGNAL
+};
+
+/*static guint signals[LAST_SIGNAL];*/
+
+static gboolean
+_games_card_themes_get_theme_info_foreach (GamesCardThemeClass *klass,
+ const char *path,
+ GamesCardThemes *theme_manager)
+{
+ GDir *iter;
+ const char *filename;
+
+ _games_profile_start ("looking for %s card themes in %s", G_OBJECT_CLASS_NAME (klass), path);
+
+ iter = g_dir_open (path, 0, NULL);
+ if (!iter)
+ goto out;
+
+ while ((filename = g_dir_read_name (iter)) != NULL) {
+ GamesCardThemeInfo *info;
+
+ _games_profile_start ("checking for %s card theme in file %s", G_OBJECT_CLASS_NAME (klass), filename);
+ info = _games_card_theme_class_get_theme_info (klass, path, filename);
+ _games_profile_end ("checking for %s card theme in file %s", G_OBJECT_CLASS_NAME (klass), filename);
+
+ if (info)
+ g_hash_table_insert (theme_manager->theme_infos, info->pref_name, info);
+ }
+
+ g_dir_close (iter);
+
+out:
+ _games_profile_end ("looking for %s card themes in %s", G_OBJECT_CLASS_NAME (klass), path);
+
+ return TRUE;
+}
+
+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_profile_end ("looking for card themes");
+}
+
+typedef struct {
+ GType type;
+ const char *filename;
+ GamesCardThemeInfo *theme_info;
+} FindData;
+
+static void
+find_by_type_and_name (gpointer key,
+ GamesCardThemeInfo *info,
+ FindData *data)
+{
+ if (info->type != data->type ||
+ strcmp (info->filename, data->filename) != 0)
+ return;
+
+ data->theme_info = info;
+}
+
+static GamesCardThemeInfo *
+_games_card_themes_get_info_by_type_and_name (GamesCardThemes *theme_manager,
+ GType type,
+ const char *filename)
+{
+ FindData data = { type, filename, NULL };
+
+ g_hash_table_foreach (theme_manager->theme_infos, (GHFunc) find_by_type_and_name, &data);
+
+ 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);
+
+static void
+games_card_themes_init (GamesCardThemes *theme_manager)
+{
+ /* 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;
+}
+
+static void
+games_card_themes_finalize (GObject *object)
+{
+ GamesCardThemes *theme_manager = GAMES_CARD_THEMES (object);
+
+ g_hash_table_destroy (theme_manager->theme_infos);
+
+ 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
+ *
+ * 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.
+ */
+ signals[CHANGED] =
+ g_signal_newv ("changed",
+ G_TYPE_FROM_CLASS (klass),
+ (GSignalFlags) (G_SIGNAL_RUN_LAST),
+ NULL,
+ NULL, NULL,
+ g_cclosure_marshal_VOID__VOID,
+ G_TYPE_NONE,
+ 0, NULL);
+#endif
+}
+
+/* private API */
+
+/* public API */
+
+/**
+ * games_card_themes_new:
+ *
+ * Returns: a new #GamesCardThemes object
+ */
+GamesCardThemes *
+games_card_themes_new (void)
+{
+ return g_object_new (GAMES_TYPE_CARD_THEMES, NULL);
+}
+
+/**
+ * games_card_themes_get_theme:
+ * @theme_manager:
+ * @info: a #GamesCardThemeInfo
+ *
+ * Returns: a new #GamesCardTheme for @info, or %NULL if there was an
+ * error while loading the theme.
+ */
+GamesCardTheme *
+games_card_themes_get_theme (GamesCardThemes *theme_manager,
+ GamesCardThemeInfo *info)
+{
+ GamesCardTheme *theme;
+ GError *error = NULL;
+
+ g_return_val_if_fail (info != NULL, NULL);
+
+ if (info->type == G_TYPE_INVALID)
+ return NULL;
+
+ _games_profile_start ("loading %s card theme %s", g_type_name (info->type), info->display_name);
+
+ theme = g_object_new (info->type, "theme-info", info, NULL);
+ if (!theme->klass->load (theme, &error)) {
+ _games_debug_print (GAMES_DEBUG_CARD_THEME,
+ "Failed to load card theme %s: %s\n",
+ info->display_name, error ? error->message : "(no error information)");
+
+ g_clear_error (&error);
+ g_object_unref (theme);
+ theme = NULL;
+ } else {
+ _games_debug_print (GAMES_DEBUG_CARD_THEME,
+ "Successfully loaded card theme %s\n",
+ info->display_name);
+ }
+
+ _games_profile_end ("loading %s card theme %s", g_type_name (info->type), info->display_name);
+
+ return theme;
+}
+
+/**
+ * games_card_themes_get_theme_by_name:
+ * @theme_name: a theme name
+ *
+ * This function exists only for backward compatibility with
+ * older aisleriot versions' preferences.
+ *
+ * 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)
+{
+ char *colon, *free_me = NULL;
+ const char *filename;
+ gsize type_str_len;
+ GType type = G_TYPE_INVALID;
+ GamesCardThemeInfo *theme_info = NULL;
+
+ if (!theme_name || !theme_name[0])
+ goto default_fallback;
+
+ _games_card_theme_ensure_theme_infos (theme_manager);
+
+ 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;
+ 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 {
+#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_themes_get_info_by_type_and_name (theme_manager, type, filename);
+ g_free (free_me);
+
+default_fallback:
+
+ 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_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);
+
+ return NULL;
+}
+
+/**
+ * games_card_themes_get_theme_any:
+ *
+ * Loads all card themes until loading one succeeds, and returns it; or
+ * %NULL if all card themes fail to load.
+ *
+ * Returns:
+ */
+GamesCardTheme *
+games_card_themes_get_theme_any (GamesCardThemes *theme_manager)
+{
+// GList *l;
+
+ _games_card_theme_ensure_theme_infos (theme_manager);
+
+/* if (!theme_infos)
+ return NULL;
+
+ 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;
+}
+
+/**
+ * games_card_themes_get_theme_all:
+ *
+ * Returns:
+ */
+GList *
+games_card_themes_get_theme_all (GamesCardThemes *theme_manager)
+{
+ GList *list = NULL;
+
+ _games_card_theme_ensure_theme_infos (theme_manager);
+
+ g_hash_table_foreach (theme_manager->theme_infos, (GHFunc) foreach_add_to_list, &list);
+
+ return g_list_sort (list, (GCompareFunc) _games_card_theme_info_collate);
+}
Added: trunk/libgames-support/games-card-themes.h
==============================================================================
--- (empty file)
+++ trunk/libgames-support/games-card-themes.h Tue Jan 6 18:20:10 2009
@@ -0,0 +1,58 @@
+/*
+ Copyright  2004 Callum McKenzie
+ Copyright  2007, 2008 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
+ by the Free Software Foundation; either version 2, or (at your option)
+ any later version.
+
+ This library is distributed in the hope that it will be useful,
+ but WITHOUT ANY WARRANTY; without even the implied warranty of
+ MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
+ GNU Library General Public License for more details.
+
+ You should have received a copy of the GNU Library General Public License
+ along with this library; if not, write to the Free Software
+ Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. */
+
+/* Authors: Callum McKenzie <callum physics otago ac nz> */
+
+#ifndef GAMES_CARD_THEMES_H
+#define GAMES_CARD_THEMES_H
+
+#include <glib.h>
+#include <gdk-pixbuf/gdk-pixbuf.h>
+#include <gtk/gtk.h>
+
+#include "games-card-theme.h"
+
+G_BEGIN_DECLS
+
+#define GAMES_TYPE_CARD_THEMES (games_card_themes_get_type ())
+#define GAMES_CARD_THEMES(obj) (G_TYPE_CHECK_INSTANCE_CAST ((obj), GAMES_TYPE_CARD_THEMES, GamesCardThemes))
+#define GAMES_CARD_THEMES_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST ((klass), GAMES_TYPE_CARD_THEMES, GamesCardThemesClass))
+#define GAMES_IS_CARD_THEMES(obj) (G_TYPE_CHECK_INSTANCE_TYPE ((obj), GAMES_TYPE_CARD_THEMES))
+#define GAMES_IS_CARD_THEMES_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((klass), GAMES_TYPE_CARD_THEMES))
+#define GAMES_CARD_THEMES_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS ((obj), GAMES_TYPE_CARD_THEMES, GamesCardThemesClass))
+
+typedef struct _GamesCardThemesClass GamesCardThemesClass;
+typedef struct _GamesCardThemes GamesCardThemes;
+
+GType games_card_themes_get_type (void);
+
+GamesCardThemes *games_card_themes_new (void);
+
+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);
+
+G_END_DECLS
+
+#endif /* GAMES_CARD_THEMES_H */
Modified: trunk/libgames-support/render-cards.c
==============================================================================
--- trunk/libgames-support/render-cards.c (original)
+++ trunk/libgames-support/render-cards.c Tue Jan 6 18:20:10 2009
@@ -28,6 +28,7 @@
#include "games-runtime.h"
#include "games-card-theme.h"
+#include "games-card-themes.h"
#include "games-card-theme-private.h"
int
@@ -36,6 +37,7 @@
GError *err = NULL;
char *basepath = NULL, *kfname, *kfpath;
GamesCardThemeInfo *theme_info = NULL;
+ GamesCardThemes *theme_manager = NULL;
GamesCardTheme *theme = NULL;
GKeyFile *key_file = NULL;
int i;
@@ -134,7 +136,8 @@
theme_name,
NULL,
NULL, NULL);
- theme = games_card_theme_get (theme_info);
+ theme_manager = games_card_themes_new ();
+ theme = games_card_themes_get_theme (theme_manager, theme_info);
if (!theme) {
/* FIXMEchpe print real error */
g_warning ("Failed to load theme '%s'\n", theme_name);
@@ -259,6 +262,8 @@
g_object_unref (theme);
if (theme_info)
games_card_theme_info_unref (theme_info);
+ if (theme_manager)
+ g_object_unref (theme_manager);
if (key_file)
g_key_file_free (key_file);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]