[gcompris] Added support for remembering last passed level
- From: Bruno Coudoin <bcoudoin src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gcompris] Added support for remembering last passed level
- Date: Mon, 1 Apr 2013 17:20:30 +0000 (UTC)
commit 2fe7005d8affdcd7aedaa429cdac674c9b23a88f
Author: Roopesh Shenoy <shenoy roopesh gmail com>
Date: Mon Apr 1 19:15:58 2013 +0200
Added support for remembering last passed level
When in user mode, the children will be proposed the last level
she completed for each activity.
This mode can also be activated in -r, --rememberlevel and from
the configuration dialog box.
src/gcompris/board.c | 30 +++++++++++++++++++++++++++++-
src/gcompris/config.c | 38 ++++++++++++++++++++++++++++++++++++--
src/gcompris/gcompris.c | 19 ++++++++++++++-----
src/gcompris/gcompris_db.c | 39 +++++++++++++++++++++++++++++++++++++++
src/gcompris/gcompris_db.h | 3 +++
src/gcompris/properties.c | 10 +++++++++-
src/gcompris/properties.h | 2 ++
7 files changed, 132 insertions(+), 9 deletions(-)
---
diff --git a/src/gcompris/board.c b/src/gcompris/board.c
index 8355840..e5a77c5 100644
--- a/src/gcompris/board.c
+++ b/src/gcompris/board.c
@@ -21,7 +21,7 @@
#include "gcompris.h"
#include "gc_core.h"
-
+#include "profile.h"
static struct BoardPluginData *bp_data;
@@ -324,6 +324,34 @@ gc_board_play(GcomprisBoard *gcomprisBoard)
gc_activity_intro_play(gcomprisBoard);
bp->start_board(gcomprisBoard);
+
+ /*also set the level to the last played level if the plugin exposes
+ a method for that*/
+ if(bp->set_level)
+ {
+ GcomprisUser *gcomprisUser = gc_profile_get_current_user();
+ int user_id = -1;
+
+ if (gcomprisUser) {
+ user_id = gcomprisUser->user_id;
+ }
+
+ GcomprisProperties *properties = gc_prop_get();
+
+ /* For all signed in users or if --rememberlevel flag is used or if
+ rememberlevel configuration is set to true */
+ if(user_id != -1 || properties->rememberlevel)
+ {
+ int level_id = get_last_played_level(user_id
+ , gcomprisBoard->board_id);
+
+ if(level_id > 0)
+ {
+ bp->set_level(level_id);
+ }
+ }
+ }
+
bp_data->playing = TRUE;
/* Force the bar to go on top of the activities canvas items */
diff --git a/src/gcompris/config.c b/src/gcompris/config.c
index 2863066..6cd32df 100644
--- a/src/gcompris/config.c
+++ b/src/gcompris/config.c
@@ -45,7 +45,7 @@ static GooCanvasGroup *stars_group = NULL;
static double stars_group_x;
static double stars_group_y;
-#define Y_GAP 45
+#define Y_GAP 38
static gboolean is_displayed = FALSE;
static gint x_flag_start;
@@ -278,10 +278,36 @@ gc_config_start ()
(gdouble) y_start,
-1,
GTK_ANCHOR_WEST,
- "font", gc_skin_font_subtitle,
+ "font", gc_skin_font_content,
+ "fill-color-rgba", gc_skin_color_content,
+ NULL);
+
+ // Rememberlevel
+ y_start += Y_GAP;
+
+ item = goo_canvas_svg_new (rootitem,
+ gc_skin_rsvg_get(),
+ "svg-id", (properties->rememberlevel ? pixmap_checked : pixmap_unchecked),
+ NULL);
+ SET_ITEM_LOCATION(item, x_start, y_start - pixmap_width/2);
+
+ g_signal_connect(item, "button_press_event",
+ (GCallback) item_event_ok,
+ "rememberlevel");
+ gc_item_focus_init(item, NULL);
+
+
+ goo_canvas_text_new (rootitem,
+ _("Remember level for default user"),
+ (gdouble) x_text_start,
+ (gdouble) y_start,
+ -1,
+ GTK_ANCHOR_WEST,
+ "font", gc_skin_font_content,
"fill-color-rgba", gc_skin_color_content,
NULL);
+
// Music
y_start += Y_GAP;
@@ -777,6 +803,14 @@ item_event_ok(GooCanvasItem *item,
}
gc_prop_save(properties);
}
+ else if(!strcmp((char *)data, "rememberlevel"))
+ {
+ properties->rememberlevel = (properties->rememberlevel ? 0 : 1);
+ g_object_set(item,
+ "svg-id", (properties->rememberlevel ? pixmap_checked : pixmap_unchecked),
+ NULL);
+ gc_item_focus_init(item, NULL);
+ }
else if(!strcmp((char *)data, "fullscreen"))
{
properties->fullscreen = (properties->fullscreen ? 0 : 1);
diff --git a/src/gcompris/gcompris.c b/src/gcompris/gcompris.c
index 05cc891..36c0303 100644
--- a/src/gcompris/gcompris.c
+++ b/src/gcompris/gcompris.c
@@ -115,6 +115,7 @@ static gboolean gc_debug = FALSE;
/*** gcompris-popttable */
static gint popt_fullscreen = FALSE;
static gint popt_window = FALSE;
+static gint popt_rememberlevel = FALSE;
static gint popt_sound = FALSE;
static gint popt_mute = FALSE;
static gint popt_cursor = FALSE;
@@ -171,11 +172,8 @@ static GOptionEntry options[] = {
{"difficulty", 'd', 0, G_OPTION_ARG_INT, &popt_difficulty_filter,
N_("display only activities with this difficulty level."), NULL},
- {"debug", 'D', 0, G_OPTION_ARG_NONE, &popt_debug,
- N_("display debug informations on the console."), NULL},
-
- {"version", 'v', 0, G_OPTION_ARG_NONE, &popt_version,
- N_("Print the version of " PACKAGE), NULL},
+ {"rememberlevel", 'r', '0', G_OPTION_ARG_NONE, &popt_rememberlevel,
+ N_("Return to last passed level even when no user is selected"), NULL},
{"root-menu", 'l', 0, G_OPTION_ARG_STRING, &popt_root_menu,
N_("Run GCompris with local menu"
@@ -257,6 +255,12 @@ static GOptionEntry options[] = {
{"test",'\0', 0, G_OPTION_ARG_NONE, &popt_test,
N_("For test purpose, run in a loop all the activities"), NULL},
+ {"debug", 'D', 0, G_OPTION_ARG_NONE, &popt_debug,
+ N_("display debug informations on the console."), NULL},
+
+ {"version", 'v', 0, G_OPTION_ARG_NONE, &popt_version,
+ N_("Print the version of " PACKAGE), NULL},
+
{ NULL }
};
@@ -1710,6 +1714,11 @@ main (int argc, char *argv[])
properties->fullscreen = FALSE;
}
+ if(popt_rememberlevel)
+ {
+ properties->rememberlevel = TRUE;
+ }
+
if (popt_mute)
{
g_message("Sound disabled");
diff --git a/src/gcompris/gcompris_db.c b/src/gcompris/gcompris_db.c
index 2788a3d..84c6a08 100644
--- a/src/gcompris/gcompris_db.c
+++ b/src/gcompris/gcompris_db.c
@@ -2197,3 +2197,42 @@ escape_quote(const char *input)
return result;
}
#endif
+
+
+#define GET_LAST_PLAYED_LEVEL \
+ "select level from logs louter where user_id = %d and board_id = %d and not exists (select 1 from
logs linner where linner.user_id = louter.user_id and linner.board_id = louter.board_id and linner.date >
louter.date) ;"
+
+int get_last_played_level(int user_id, int board_id)
+{
+ char **result;
+ int nrow;
+ int ncolumn;
+ char *zErrMsg;
+ int rc;
+ gchar *request;
+
+ request = sqlite3_mprintf( GET_LAST_PLAYED_LEVEL,
+ user_id,
+ board_id
+ );
+
+ rc = sqlite3_get_table(gcompris_db,
+ request,
+ &result,
+ &nrow,
+ &ncolumn,
+ &zErrMsg
+ );
+
+ if(nrow == 0)
+ {
+ sqlite3_free_table(result);
+ return -1;
+ }
+
+ int level = atoi(result[1]); //expect only one row and one column
+
+ sqlite3_free_table(result);
+
+ return level;
+}
diff --git a/src/gcompris/gcompris_db.h b/src/gcompris/gcompris_db.h
index 31fe97b..9464d75 100644
--- a/src/gcompris/gcompris_db.h
+++ b/src/gcompris/gcompris_db.h
@@ -123,4 +123,7 @@ gboolean gc_db_log(gchar *date, int duration,
int level, int sublevel,
int status, gchar *comment);
+/*Use mainly for getting last played level for a particular board and user*/
+int get_last_played_level(int user_id, int board_id);
+
#endif
diff --git a/src/gcompris/properties.c b/src/gcompris/properties.c
index 3f553a3..03bc7f4 100644
--- a/src/gcompris/properties.c
+++ b/src/gcompris/properties.c
@@ -161,7 +161,11 @@ gc_prop_new ()
tmp->disable_quit = 0; /* Used to remove the quit button from the bar. Use
it for kiosk mode */
tmp->disable_config = 0; /* Used to remove the config button from the bar. Use
it for kiosk mode */
tmp->disable_level = 0; /* Used to remove the level button from the bar */
- tmp->display_resource = 0;
+ tmp->display_resource = 0; /* Used to check whether
+ rememberlevel should be
+ enabled for non-signed
+ in user*/
+ tmp->rememberlevel = 0;
tmp->root_menu = g_strdup("/");
tmp->profile = NULL;
tmp->logged_user = NULL;
@@ -387,6 +391,9 @@ gc_prop_load (GcomprisProperties *props, GCPropSourceConf source_conf)
} else if(!strcmp(value.v_identifier, "fx")) {
if(!scan_get_int(scanner, &props->fx))
g_warning("Config file parsing error on token %s", token);
+ } else if(!strcmp(value.v_identifier, "rememberlevel")) {
+ if(!scan_get_int(scanner, &props->rememberlevel))
+ g_warning("Config file parsing error on token %s", token);
} else if(!strcmp(value.v_identifier, "fullscreen")) {
if(!scan_get_int(scanner, &props->fullscreen))
g_warning("Config file parsing error on token %s", token);
@@ -566,6 +573,7 @@ gc_prop_save (GcomprisProperties *props)
fprintf(filefd, "%s=\"%s\"\n", "key", props->key);
fprintf(filefd, "%s=%d\n", "zoom", props->zoom);
+ fprintf(filefd, "%s=%d\n", "rememberlevel", props->rememberlevel);
fclose(filefd);
diff --git a/src/gcompris/properties.h b/src/gcompris/properties.h
index facb8f5..86c6ff5 100644
--- a/src/gcompris/properties.h
+++ b/src/gcompris/properties.h
@@ -41,6 +41,8 @@ typedef struct {
gint disable_config;
gint disable_level;
gint display_resource;
+ gint rememberlevel; /* Should we remember the last level for the
+ non-signed-in user as well (-1) */
gchar *root_menu;
gchar *package_data_dir;
gchar *package_skin_dir;
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]