Commit dd313fd5 authored by Christian Persch's avatar Christian Persch Committed by Christian Persch

Fix error handling when failing to load the game file.

2007-07-21  Christian Persch  <chpe@gnome.org>

	* game.c: (cscmi_eval_installed_file),
	(aisleriot_game_error_quark), (aisleriot_game_load_game):
	* game.h:
	* window.c: (load_idle_cb): Fix error handling when failing to load
	the game file.

svn path=/trunk/; revision=6542
parent 11875fdf
2007-07-21 Christian Persch <chpe@gnome.org>
* game.c: (cscmi_eval_installed_file),
(aisleriot_game_error_quark), (aisleriot_game_load_game):
* game.h:
* window.c: (load_idle_cb): Fix error handling when failing to load
the game file.
2007-06-26 Christian Persch <chpe@gnome.org>
* board.c:
......
......@@ -46,8 +46,6 @@
#define DELAYED_CALLBACK_DELAY (50)
#define ERROR_QUARK (g_quark_from_static_string ("AisleRiot"))
struct _AisleriotGame
{
GObject parent_instance;
......@@ -1099,7 +1097,7 @@ cscmi_eval_installed_file (const char *filename,
/* FIXMEchpe: install exception handlers and set error if an exception occurs while loading the file? */
if (!g_str_has_suffix (filename, ".scm")) {
g_set_error (error, ERROR_QUARK, GAME_ERROR_GENERIC,
g_set_error (error, AISLERIOT_GAME_ERROR, GAME_ERROR_GENERIC,
"%s is not a scheme file", filename);
return FALSE;
}
......@@ -1112,7 +1110,7 @@ cscmi_eval_installed_file (const char *filename,
return TRUE;
}
g_set_error (error, ERROR_QUARK, GAME_ERROR_GENERIC,
g_set_error (error, AISLERIOT_GAME_ERROR, GAME_ERROR_GENERIC,
_("Aisleriot cannot load the file \"%s\". "
"Please check your Aisleriot installation."),
path);
......@@ -1318,6 +1316,23 @@ aisleriot_game_class_init (AisleriotGameClass *klass)
/* public API */
/**
* aisleriot_game_error_quark:
*
* Returns: the #GQuark used for errors
*/
GQuark
aisleriot_game_error_quark (void)
{
static GQuark quark = 0;
if (G_UNLIKELY (quark == 0)) {
quark = g_quark_from_static_string ("AisleRiotGameError");
}
return quark;
}
/**
* aisleriot_game_new:
*
......@@ -1492,7 +1507,7 @@ aisleriot_game_load_game (AisleriotGame *game,
* as a key, we also require it to be valid UTF-8 !
*/
if (!g_utf8_validate (game_file, -1, NULL)) {
g_set_error (error, ERROR_QUARK, GAME_ERROR_GENERIC,
g_set_error (error, AISLERIOT_GAME_ERROR, GAME_ERROR_GENERIC,
"Invalid UTF-8");
return FALSE;
}
......@@ -1528,7 +1543,7 @@ aisleriot_game_load_game (AisleriotGame *game,
} else {
g_error_free (err);
g_set_error (error, ERROR_QUARK, GAME_ERROR_FALLBACK,
g_set_error (error, AISLERIOT_GAME_ERROR, GAME_ERROR_FALLBACK,
"%s %s",
_("Aisleriot cannot find the last game you played."),
_("This usually occurs when you run an older version of Aisleriot "
......
......@@ -80,6 +80,8 @@ typedef struct {
#define DEFAULT_VARIATION "klondike.scm"
#define FREECELL_VARIATION "freecell.scm"
#define AISLERIOT_GAME_ERROR (aisleriot_game_error_quark ())
typedef struct _AisleriotGame AisleriotGame;
typedef GObjectClass AisleriotGameClass;
......@@ -105,6 +107,8 @@ typedef enum {
LAST_GAME_STATE
} AisleriotGameState;
GQuark aisleriot_game_error_quark (void);
GType aisleriot_game_get_type (void);
AisleriotGame *aisleriot_game_new (void);
......
......@@ -2536,21 +2536,22 @@ load_idle_cb (LoadIdleData *data)
name);
g_free (name);
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
"%s", error->message);
g_error_free (error);
if (priv->freecell_mode ||
(error->domain == g_quark_from_static_string ("AisleRiot") &&
error->code == GAME_ERROR_FALLBACK)) {
/* Loading the fallback game failed; all we can do is exit */
error->domain != AISLERIOT_GAME_ERROR ||
error->code != GAME_ERROR_FALLBACK) {
/* Loading freecell/the fallback game failed; all we can do is exit */
g_signal_connect_swapped (dialog, "response",
G_CALLBACK (gtk_widget_destroy), data->window);
} else {
gtk_message_dialog_format_secondary_text (GTK_MESSAGE_DIALOG (dialog),
"%s", error->message);
g_signal_connect (dialog, "response",
G_CALLBACK (load_error_response_cb), data->window);
}
g_error_free (error);
gtk_window_present (GTK_WINDOW (dialog));
return FALSE;
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment