[gcompris/gcomprixogoo] Added support for demo field in the menus and the database.



commit 75e116776409bec85bfb6b02e36c2365bc4f0760
Author: Bruno Coudoin <bruno ordinateur-de-bruno-coudoin local>
Date:   Fri Apr 2 00:13:27 2010 +0200

    Added support for demo field in the menus and the database.

 src/gcompris/gcompris-board.h |    4 ++--
 src/gcompris/gcompris_db.c    |   20 ++++++++++++--------
 src/gcompris/gcompris_db.h    |    3 ++-
 src/gcompris/menu.c           |    8 +++++++-
 4 files changed, 23 insertions(+), 12 deletions(-)
---
diff --git a/src/gcompris/gcompris-board.h b/src/gcompris/gcompris-board.h
index 3b58cd4..fece57f 100644
--- a/src/gcompris/gcompris-board.h
+++ b/src/gcompris/gcompris-board.h
@@ -84,8 +84,8 @@ struct _GcomprisBoard
   /* IM_context control */
   gboolean             disable_im_context;
 
-  /* This activity is available only in the demo version */
-  gboolean	       demo_only;
+  /* This activity is a demo one */
+  gboolean	       demo;
 };
 
 
diff --git a/src/gcompris/gcompris_db.c b/src/gcompris/gcompris_db.c
index e88a771..1afd576 100644
--- a/src/gcompris/gcompris_db.c
+++ b/src/gcompris/gcompris_db.c
@@ -50,7 +50,7 @@ static sqlite3 *gcompris_db=NULL;
 #define CREATE_TABLE_BOARDS_PROFILES_CONF				\
   "CREATE TABLE board_profile_conf (profile_id INT, board_id INT, conf_key TEXT, conf_value TEXT ); "
 #define CREATE_TABLE_BOARDS						\
-  "CREATE TABLE boards (board_id INT UNIQUE, name TEXT, section_id INT, section TEXT, author TEXT, type TEXT, mode TEXT, difficulty INT, icon TEXT, boarddir TEXT, mandatory_sound_file TEXT, mandatory_sound_dataset TEXT, filename TEXT, title TEXT, description TEXT, prerequisite TEXT, goal TEXT, manual TEXT, credit TEXT, demo_only INT);"
+  "CREATE TABLE boards (board_id INT UNIQUE, name TEXT, section_id INT, section TEXT, author TEXT, type TEXT, mode TEXT, difficulty INT, icon TEXT, boarddir TEXT, mandatory_sound_file TEXT, mandatory_sound_dataset TEXT, filename TEXT, title TEXT, description TEXT, prerequisite TEXT, goal TEXT, manual TEXT, credit TEXT, demo INT);"
 #define CREATE_TABLE_LOGS						\
   "CREATE TABLE logs (date TEXT, duration INT, user_id INT, board_id INT, level INT, sublevel INT, status INT, comment TEXT);"
 
@@ -386,6 +386,10 @@ gboolean gc_db_init(gboolean disable_database_)
     if(version <= 17)
       {
 	g_message("Upgrading from <17 schema version\n");
+	rc = sqlite3_exec(gcompris_db,"DROP TABLE boards;", NULL,  0, &zErrMsg);
+	if( rc!=SQLITE_OK ) {
+	  g_error("SQL error: %s\n", zErrMsg);
+	}
 	rc = sqlite3_exec(gcompris_db,CREATE_TABLE_BOARDS, NULL,  0, &zErrMsg);
 	if( rc!=SQLITE_OK ) {
 	  g_error("SQL error: %s\n", zErrMsg);
@@ -514,7 +518,7 @@ gboolean gc_db_check_boards()
 
 
 #define GC_BOARD_INSERT							\
-  "INSERT OR REPLACE INTO boards VALUES (%d, %Q, %d, %Q, %Q, %Q, %Q, %d, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q);"
+  "INSERT OR REPLACE INTO boards VALUES (%d, %Q, %d, %Q, %Q, %Q, %Q, %d, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %d);"
 
 #define MAX_GC_BOARD_ID				\
   "SELECT MAX(board_id) FROM boards;"
@@ -549,7 +553,7 @@ gc_db_board_update(guint *board_id,
 		   gchar *goal,
 		   gchar *manual,
 		   gchar *credit,
-		   int demo_only
+		   int demo
 		   )
 {
   SUPPORT_OR_RETURN(FALSE);
@@ -680,7 +684,7 @@ gc_db_board_update(guint *board_id,
 			     goal,
 			     manual,
 			     credit,
-			     demo_only
+			     demo
 			     );
 
   rc = sqlite3_get_table(gcompris_db,
@@ -705,7 +709,7 @@ gc_db_board_update(guint *board_id,
 
 
 #define BOARDS_READ							\
-  "SELECT board_id ,name, section_id, section, author, type, mode, difficulty, icon, boarddir, mandatory_sound_file, mandatory_sound_dataset, filename, title, description, prerequisite, goal, manual, credit, demo_only FROM boards;"
+  "SELECT board_id ,name, section_id, section, author, type, mode, difficulty, icon, boarddir, mandatory_sound_file, mandatory_sound_dataset, filename, title, description, prerequisite, goal, manual, credit, demo FROM boards;"
 
 GList *gc_menu_load_db(GList *boards_list)
 {
@@ -774,7 +778,7 @@ GList *gc_menu_load_db(GList *boards_list)
     gcomprisBoard->goal = reactivate_newline(gettext(result[i++]));
     gcomprisBoard->manual = reactivate_newline(gettext(result[i++]));
     gcomprisBoard->credit = reactivate_newline(gettext(result[i++]));
-    gcomprisBoard->demo_only = atoi(result[i++]);
+    gcomprisBoard->demo = atoi(result[i++]);
 
     boards = g_list_append(boards, gcomprisBoard);
   }
@@ -1752,7 +1756,7 @@ GList *gc_db_get_groups_list()
 
 
 #define BOARDS_READ_FROM_ID(n)						\
-  "SELECT name, section_id, section, author, type, mode, difficulty, icon, boarddir, mandatory_sound_file, mandatory_sound_dataset, filename, title, description, prerequisite, goal, manual, credit FROM boards WHERE board_id=%d;",n
+  "SELECT name, section_id, section, author, type, mode, difficulty, icon, boarddir, mandatory_sound_file, mandatory_sound_dataset, filename, title, description, prerequisite, goal, manual, credit, demo FROM boards WHERE board_id=%d;",n
 
 GcomprisBoard *gc_db_get_board_from_id(int board_id)
 {
@@ -1824,7 +1828,7 @@ GcomprisBoard *gc_db_get_board_from_id(int board_id)
   gcomprisBoard->goal = reactivate_newline(gettext(result[i++]));
   gcomprisBoard->manual = reactivate_newline(gettext(result[i++]));
   gcomprisBoard->credit = reactivate_newline(gettext(result[i++]));
-  gcomprisBoard->demo_only = atoi(result[i++]);
+  gcomprisBoard->demo = atoi(result[i++]);
 
   sqlite3_free_table(result);
 
diff --git a/src/gcompris/gcompris_db.h b/src/gcompris/gcompris_db.h
index bdaf648..31fe97b 100644
--- a/src/gcompris/gcompris_db.h
+++ b/src/gcompris/gcompris_db.h
@@ -52,7 +52,8 @@ gboolean gc_db_board_update(guint *board_id,
 			      gchar *prerequisite,
 			      gchar *goal,
 			      gchar *manual,
-			      gchar *credit
+			      gchar *credit,
+			      int demo
 			      );
 
 gboolean gc_db_save_user(int *user_id,
diff --git a/src/gcompris/menu.c b/src/gcompris/menu.c
index 495c371..0c8859b 100644
--- a/src/gcompris/menu.c
+++ b/src/gcompris/menu.c
@@ -99,6 +99,11 @@ _add_xml_to_data(xmlDocPtr doc, xmlNodePtr xmlnode, GNode * child,
   if(gcomprisBoard->difficulty == NULL)
     gcomprisBoard->difficulty		= g_strdup("0");
 
+  gcomprisBoard->demo = FALSE;
+  char *demo		= (char *)xmlGetProp(xmlnode, BAD_CAST "demo");
+  if(demo && strcmp(demo, "1"))
+    gcomprisBoard->demo = TRUE;
+
   /* Update the difficulty max */
   if(properties->difficulty_max < atoi(gcomprisBoard->difficulty))
     properties->difficulty_max = atoi(gcomprisBoard->difficulty);
@@ -206,7 +211,8 @@ _add_xml_to_data(xmlDocPtr doc, xmlNodePtr xmlnode, GNode * child,
 			prerequisite,
 			goal,
 			manual,
-			credit
+			credit,
+			gcomprisBoard->demo
 			);
 
     g_message("db board written %d in %d  %s/%s",



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