[gcompris/gcomprixogoo] Added a message in GCompris itself when we fail to load the skin.



commit a2e86c2d0f762bf2b4b50a65644ec32a9160418b
Author: Bruno Coudoin <bruno coudoin free fr>
Date:   Sun Dec 5 18:53:21 2010 +0100

    Added a message in GCompris itself when we fail to load the skin.
    
    Before, when the skin file was not found, which means GCompris is not
    properly installed or configured, there was an assert and nothing
    was explained to the user. Now there is a message in the GCompris
    windows.

 src/gcompris/board.c    |    9 +++++++++
 src/gcompris/gcompris.c |   18 ++++++++++++++++--
 src/gcompris/menu.c     |    6 ++----
 src/gcompris/skin.c     |   35 +++++++++++++++++++++++------------
 src/gcompris/skin.h     |    2 +-
 src/gcompris/status.c   |   14 ++++++++++++--
 src/gcompris/status.h   |    2 +-
 7 files changed, 64 insertions(+), 22 deletions(-)
---
diff --git a/src/gcompris/board.c b/src/gcompris/board.c
index 975b415..f4579db 100644
--- a/src/gcompris/board.c
+++ b/src/gcompris/board.c
@@ -174,6 +174,9 @@ void gc_board_init(void)
 
 BoardPlugin *gc_board_get_current_board_plugin(void)
 {
+  if (! bp_data)
+    return NULL;
+
   if(bp_data->current_gcompris_board)
     return bp_data->current_gcompris_board->plugin;
 
@@ -182,6 +185,9 @@ BoardPlugin *gc_board_get_current_board_plugin(void)
 
 GcomprisBoard *gc_board_get_current(void)
 {
+  if (! bp_data)
+    return NULL;
+
   return bp_data->current_gcompris_board;
 }
 
@@ -361,6 +367,9 @@ gc_board_pause(int pause)
 void
 gc_board_stop(void)
 {
+  if (! bp_data)
+    return;
+
   if (bp_data->playing && gc_board_get_current_board_plugin())
     {
       bp_data->playing = FALSE;
diff --git a/src/gcompris/gcompris.c b/src/gcompris/gcompris.c
index 0ff8b9d..fe5319e 100644
--- a/src/gcompris/gcompris.c
+++ b/src/gcompris/gcompris.c
@@ -1212,11 +1212,27 @@ static void map_cb (GtkWidget *widget, gpointer data)
       is_mapped = TRUE;
       GcomprisBoard *board_to_start;
 
+      if (! gc_skin_load(properties->skin) )
+	{
+	  gc_status_init("");
+	  gchar *filename = \
+	    g_strdup_printf("%s/%s/skin.xml",
+			    properties->package_skin_dir,
+			    properties->skin);
+
+	  gc_status_set_msg(_("Failed to load the skin '%s'"
+			      " (Check the file exists and is readable)"),
+			    filename);
+	  g_free(filename);
+	  return;
+	}
+
       gc_set_default_background (goo_canvas_get_root_item (GOO_CANVAS(canvas)));
 
       gc_fullscreen_set(properties->fullscreen);
 
       gc_status_init("");
+
       gc_board_init();
       /* Load all the menu once */
       gc_menu_load();
@@ -1932,8 +1948,6 @@ main (int argc, char *argv[])
   gc_net_init();
   gc_cache_init();
 
-  gc_skin_load(properties->skin);
-
   gc_sound_build_music_list();
 
   if(properties->music || properties->fx)
diff --git a/src/gcompris/menu.c b/src/gcompris/menu.c
index c4e2bbc..a1a364b 100644
--- a/src/gcompris/menu.c
+++ b/src/gcompris/menu.c
@@ -580,10 +580,8 @@ void gc_menu_load_dir(char *dirname, gboolean db){
 	      }
 	  }
 	  if (board_read) {
-	    gchar *msg = g_strdup_printf(_("Loading activity from file:\n%s"),
-					 gettext(board_read->title));
-	    gc_status_set_msg(msg);
-	    g_free(msg);
+	    gc_status_set_msg( _("Loading activity from file:\n%s"),
+			       gettext(board_read->title) );
 	  }
 	}
     else
diff --git a/src/gcompris/skin.c b/src/gcompris/skin.c
index d3523dc..005da63 100644
--- a/src/gcompris/skin.c
+++ b/src/gcompris/skin.c
@@ -302,8 +302,9 @@ gboolean gc_skin_str_to_color(gchar* data, guint32* color){
 /*
  * Parse a skin.xml file located in the skin directory
  * and load the skin properties into memory
+ * @return TRUE if load suceeded
  */
-static void
+static gboolean
 skin_xml_load (gchar* skin)
 {
   gchar* xmlfilename;
@@ -314,7 +315,7 @@ skin_xml_load (gchar* skin)
   gchar* data;
   guint32 color;
 
-  g_return_if_fail(skin!=NULL);
+  g_return_val_if_fail(skin!=NULL, FALSE);
 
   xmlfilename = \
     gc_file_find_absolute("%s/skin.xml",
@@ -325,14 +326,17 @@ skin_xml_load (gchar* skin)
   if(!xmlfilename)
     {
       g_warning("Couldn't find skin file %s !", skin);
-      return;
+      return FALSE;
     }
 
   xmldoc = xmlParseFile(xmlfilename);
   g_free(xmlfilename);
 
   if(!xmldoc)
-    return;
+    {
+      g_warning("Parsing of skin file failed '%s' !", skin);
+      return FALSE;
+    }
 
   if(/* if there is no root element */
      !xmldoc->children ||
@@ -340,9 +344,10 @@ skin_xml_load (gchar* skin)
      !xmldoc->children->name ||
      /* if it isn't a GCompris node */
      g_strcasecmp((gchar *)xmldoc->children->name, "GCompris")!=0) {
-    g_warning("No Gcompris node");
     xmlFreeDoc(xmldoc);
-    return;
+    g_warning("Skin file is not properly formatted (no GCompris node) '%s' !",
+	      skin);
+    return FALSE;
   }
 
   skinNode = xmldoc->children->children;
@@ -351,9 +356,10 @@ skin_xml_load (gchar* skin)
 
   if((skinNode==NULL)||
      g_strcasecmp((gchar *)skinNode->name, "Skin")!=0) {
-    g_warning("No Skin node %s", xmldoc->children->children->name);
+    g_warning("In skin file '%s' there are no Skin node %s", skin,
+	      xmldoc->children->children->name);
     xmlFreeDoc(xmldoc);
-    return;
+    return FALSE;
   }
 
   node = skinNode->children;
@@ -397,18 +403,20 @@ skin_xml_load (gchar* skin)
     }
 
   xmlFreeDoc(xmldoc);
+  return TRUE;
 }
 
 /*
  * Parse the default skin.xml file and the one located in the skin
  * directory then load all skins properties into memory
+ * @return TRUE if load suceeded
  */
-void
+gboolean
 gc_skin_load (gchar* skin)
 {
 
   if(skin==NULL)
-    return;
+    return FALSE;
 
   gc_skin_free();
 
@@ -421,11 +429,14 @@ gc_skin_load (gchar* skin)
   gc_skin_numbers = g_hash_table_new_full(g_str_hash, g_str_equal,
 					      gc_skin_free_string,
 					      NULL);
-  skin_xml_load(DEFAULT_SKIN);
+  if (! skin_xml_load(DEFAULT_SKIN) )
+    return FALSE;
   if(strcmp(skin,DEFAULT_SKIN)!=0)
-    skin_xml_load(skin);
+    if (! skin_xml_load(skin) )
+      return FALSE;
 
   gc_skin_setup_vars();
+  return TRUE;
 }
 
 /*
diff --git a/src/gcompris/skin.h b/src/gcompris/skin.h
index 8e4116e..8602367 100644
--- a/src/gcompris/skin.h
+++ b/src/gcompris/skin.h
@@ -50,7 +50,7 @@ GdkPixbuf	*gc_skin_pixmap_load(char *pixmapfile);
 RsvgHandle	*gc_skin_rsvg_get();
 RsvgHandle	*gc_skin_rsvg_load(char *pixmapfile);
 
-void            gc_skin_load (gchar* skin);
+gboolean        gc_skin_load (gchar* skin);
 void            gc_skin_free (void);
 
 guint32         gc_skin_get_color_default(gchar* id, guint32 def);
diff --git a/src/gcompris/status.c b/src/gcompris/status.c
index 078b3dd..eb17960 100644
--- a/src/gcompris/status.c
+++ b/src/gcompris/status.c
@@ -95,17 +95,27 @@ void gc_status_init(gchar *msg)
 
 /*
  * Update the message in the status box
+ * \param format: printf formating.
+ * \param ...:    additional params for the format (printf like)
  */
-void gc_status_set_msg(gchar *msg)
+void gc_status_set_msg(const gchar *format, ...)
 {
+  va_list args;
+  gchar *msg;
+
   // No status bar means we are still at command line level.
-  if (!itemStatusMsg)
+  if (!itemStatusMsg || !format)
     return;
   g_assert(rootStatusItem);
 
+  va_start (args, format);
+  msg = g_strdup_vprintf (format, args);
+  va_end (args);
+
   g_object_set (itemStatusMsg,
 		"text", msg,
 		NULL);
+  g_free(msg);
   while (gtk_events_pending())
     gtk_main_iteration();
 }
diff --git a/src/gcompris/status.h b/src/gcompris/status.h
index cac01c5..9b01f6e 100644
--- a/src/gcompris/status.h
+++ b/src/gcompris/status.h
@@ -24,7 +24,7 @@
 /* Status box */
 void		 gc_status_init(gchar *str);
 void		 gc_status_close();
-void		 gc_status_set_msg(gchar *str);
+void		 gc_status_set_msg(const gchar *format, ...);
 
 
 #endif



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