Commit d71cb6ad authored by Yves Combe's avatar Yves Combe
Browse files

board conf by profile, user/class db access.

parent 88342950
2005-07-10 Yves Combe,,, <yves@ycombe.net>
board conf by profile, user/class db access.
* src/boards/Makefile.am:
* src/boards/py-gcompris-profile.h:
* src/boards/py-mod-gcompris.c: (py_gcompris_get_board_conf):
* src/boards/python/tuxpaint.py:
* src/gcompris/gcompris_db.c: (gcompris_get_users_from_group),
(gcompris_get_user_from_id), (gcompris_get_class_from_id),
(gcompris_get_board_conf):
* src/gcompris/gcompris_db.h:
* src/gcompris/profile.h:
2005-07-10 Yves Combe <yves@ycombe.net>
profile C functions now complete, with missing files
......
......@@ -235,6 +235,8 @@ libpython_la_SOURCES = python.c \
py-gcompris-board.c py-gcompris-board.h \
py-gcompris-properties.c py-gcompris-properties.h \
py-gcompris-profile.c py-gcompris-profile.h \
py-gcompris-class.c py-gcompris-group.c \
py-gcompris-user.cy \
py-mod-gcompris.c py-mod-gcompris.h \
py-mod-utils.c py-mod-utils.h \
py-mod-bonus.c py-mod-bonus.h \
......
......@@ -11,4 +11,26 @@ typedef struct{
GcomprisProfile* cdata;
} pyGcomprisProfileObject;
PyObject* gcompris_new_pyGcomprisClassObject(GcomprisClass* class);
typedef struct{
PyObject_HEAD
GcomprisClass* cdata;
} pyGcomprisClassObject;
PyObject* gcompris_new_pyGcomprisGroupObject(GcomprisGroup* group);
typedef struct{
PyObject_HEAD
GcomprisGroup* cdata;
} pyGcomprisGroupObject;
PyObject* gcompris_new_pyGcomprisUserObject(GcomprisUser* user);
typedef struct{
PyObject_HEAD
GcomprisUser* cdata;
} pyGcomprisUserObject;
#endif
......@@ -965,6 +965,39 @@ py_gcompris_get_boards_list(PyObject* self, PyObject* args)
return pylist;;
}
static PyObject*
py_gcompris_get_board_conf(PyObject* self, PyObject* args)
{
GList *board_conf;
GList *list;
PyObject *pydict;
PyObject *value;
GcomprisConfPair *pair;
/* Parse arguments */
if(!PyArg_ParseTuple(args, ":gcompris.get_boards_list"))
return NULL;
/* Call the corresponding C function */
board_conf = gcompris_get_board_conf();
pydict = PyDict_New();
for (list = board_conf; list != NULL; list = list->next){
pair = (GcomprisConfPair *) list->data;
if (pair->key==NULL)
continue;
if (pair->value==NULL){
Py_INCREF(Py_None);
value = Py_None;
} else
value = PyString_FromString(pair->value);
PyDict_SetItem(pydict, PyString_FromString(pair->key), value);
}
/* Create and return the result */
return pydict;;
}
/*
{ "", py_gcompris_, METH_VARARGS, "gcompris_" },
*/
......@@ -1015,6 +1048,7 @@ static PyMethodDef PythonGcomprisModule[] = {
{ "board_config_stop", py_board_config_stop, METH_VARARGS, "board_config_stop" },
{ "get_boards_list", py_gcompris_get_boards_list, METH_VARARGS, "gcompris_get_boards_list" },
{ "get_profile", py_gcompris_get_profile, METH_VARARGS, "gcompris_get_profile" },
{ "get_board_conf", py_gcompris_get_board_conf, METH_VARARGS, "gcompris_get_board_conf" },
{ NULL, NULL, 0, NULL}
};
......
......@@ -45,6 +45,10 @@ class Gcompris_tuxpaint:
print Prof.profile_id, Prof.name, Prof.description, Prof.group_ids, Prof.activities
dict = gcompris.get_board_conf()
print dict
self.rootitem = self.gcomprisBoard.canvas.root().add(
gnome.canvas.CanvasGroup,
x=0.0,
......
/* gcompris - gcompris_db.c
*
* Time-stamp: <2005/07/09 16:23:47 bruno>
* Time-stamp: <2005/07/10 22:38:11 yves>
*
* Copyright (C) 2000 Bruno Coudoin
*
......@@ -31,7 +31,7 @@ extern GnomeCanvas *canvas;
#define CREATE_TABLE_USERS \
"CREATE TABLE users (user_id INT UNIQUE, login TEXT, lastname TEXT, firstname TEXT, birthdate TEXT, class_id INT ); "
#define CREATE_TABLE_CLASS \
"CREATE TABLE class (class_id INT UNIQUE, name TEXT, teacher TEXT ); "
"CREATE TABLE class (class_id INT UNIQUE, name TEXT, teacher TEXT, wholegroup_id INT ); "
#define CREATE_TABLE_GROUPS \
"CREATE TABLE groups (group_id INT UNIQUE, name TEXT, class_id INT, description TEXT ); "
#define CREATE_TABLE_USERS_IN_GROUPS \
......@@ -800,6 +800,7 @@ GcomprisProfile *gcompris_db_get_profile()
GList *gcompris_get_users_from_group(gint group_id)
{
#ifdef USE_SQLITE
char *zErrMsg;
char **result;
int rc;
......@@ -844,6 +845,155 @@ GList *gcompris_get_users_from_group(gint group_id)
}
return users;
#else
return NULL;
#endif
}
#define USER_FROM_ID(n) \
"SELECT users.login, lastname, firstname, birthdate, class_id FROM users WHERE user_id = %d;",n
GcomprisUser *gcompris_get_user_from_id(gint user_id)
{
#ifdef USE_SQLITE
char *zErrMsg;
char **result;
int rc;
int nrow;
int ncolumn;
gchar *request;
int i;
GList *users = NULL;
GcomprisUser *user = NULL;
request = g_strdup_printf(USER_FROM_ID(user_id));
rc = sqlite3_get_table(gcompris_db,
request,
&result,
&nrow,
&ncolumn,
&zErrMsg
);
if( rc!=SQLITE_OK ){
g_error("SQL error: %s\n", zErrMsg);
}
g_free(request);
if (nrow == 0){
g_warning(_("No user with id %d"), user_id);
return NULL;
} else {
i = ncolumn;
user = g_malloc0(sizeof(GcomprisUser));
user->user_id = user_id;
user->login = g_strdup(result[i++]);
user->lastname = g_strdup(result[i++]);
user->firstname = g_strdup(result[i++]);
user->birthdate = g_strdup(result[i++]);
user->class_id = atoi(result[i++]);
}
return user ;
#else
return NULL;
#endif
}
#define CLASS_FROM_ID(n) \
"SELECT name, teacher, wholegroup_id FROM class WHERE class_id = %d;",n
#define GROUPS_IN_CLASS(n) \
"SELECT group_id FROM groups WHERE class_id = %d;",n
GcomprisClass *gcompris_get_class_from_id(gint class_id)
{
#ifdef USE_SQLITE
char *zErrMsg;
char **result;
int rc;
int nrow;
int ncolumn;
gchar *request;
int i;
GList *users = NULL;
GcomprisClass *class = NULL;
request = g_strdup_printf(CLASS_FROM_ID(class_id));
rc = sqlite3_get_table(gcompris_db,
request,
&result,
&nrow,
&ncolumn,
&zErrMsg
);
if( rc!=SQLITE_OK ){
g_error("SQL error: %s\n", zErrMsg);
}
g_free(request);
if (nrow == 0){
g_warning(_("No class with id %d"), class_id);
return NULL;
return NULL;
} else {
i = ncolumn;
class = g_malloc0(sizeof(GcomprisClass));
class->class_id = class_id;
class->name = g_strdup(result[i++]);
class->description = g_strdup(result[i++]);
class->wholegroup_id = atoi(result[i++]);
}
/* Group _ids */
GList *group_ids = NULL;
request = g_strdup_printf(GROUPS_IN_CLASS(class_id));
rc = sqlite3_get_table(gcompris_db,
request,
&result,
&nrow,
&ncolumn,
&zErrMsg
);
if( rc!=SQLITE_OK ){
g_error("SQL error: %s\n", zErrMsg);
}
g_free(request);
if (nrow == 0){
g_error(_("No groups in for class %s, there must be at least one for whole class (%d)"), class_id, class->wholegroup_id);
class->class_id = NULL;
} else {
i = ncolumn;
while (i < (nrow +1)*ncolumn) {
int *group_id = g_malloc(sizeof(int));
*group_id = atoi(result[i++]);
group_ids = g_list_append(group_ids, group_id);
}
class->group_ids = group_ids;
}
return class ;
#else
return NULL;
#endif
}
......@@ -930,8 +1080,7 @@ void gcompris_set_board_conf(GcomprisProfile *profile,
#define GET_CONF(p, b) \
"SELECT key, value FROM board_profile_conf WHERE profile_id=%d AND board_id=%d;", p, b
GList *gcompris_get_board_conf(GcomprisProfile *profile,
GcomprisBoard *board)
GList *gcompris_get_board_conf()
{
char *zErrMsg;
char **result;
......@@ -943,8 +1092,8 @@ GList *gcompris_get_board_conf(GcomprisProfile *profile,
GList *list_conf = NULL;
request = g_strdup_printf(GET_CONF(profile->profile_id,
board->board_id));
request = g_strdup_printf(GET_CONF(gcompris_get_profile()->profile_id,
get_current_gcompris_board()->board_id));
rc = sqlite3_get_table(gcompris_db,
request,
......
/* gcompris - gcompris_db.h
*
* Time-stamp: <2005/07/09 22:03:02 yves>
* Time-stamp: <2005/07/10 21:38:48 yves>
*
* Copyright (C) 2005 Bruno Coudoin
*
......@@ -76,6 +76,10 @@ GcomprisProfile *gcompris_db_get_profile();
GList *gcompris_get_users_from_group(gint group_id);
GcomprisClass *gcompris_get_class_from_id(gint class_id);
GcomprisUser *gcompris_get_user_from_id(gint user_id);
void gcompris_set_board_conf(GcomprisProfile *profile,
GcomprisBoard *board,
gchar *key,
......@@ -88,8 +92,9 @@ typedef struct {
gchar *value;
} GcomprisConfPair;
GList *gcompris_get_board_conf(GcomprisProfile *profile,
GcomprisBoard *board);
/* get conf for currents profile and board */
GList *gcompris_get_board_conf();
#endif
/* Local Variables: */
......
/* gcompris - profile.h
*
* Time-stamp: <2005/07/09 23:50:28 yves>
* Time-stamp: <2005/07/10 09:28:34 yves>
*
* Copyright (C) 2005 Bruno Coudoin
*
......@@ -36,6 +36,8 @@
/*****************************************************************************/
/* The following structure dsecribes a class, partitionning the users set */
struct _GcomprisClass {
gint class_id;
/* name of class -- must be unique */
gchar *name;
......@@ -43,10 +45,13 @@ struct _GcomprisClass {
gchar *description;
/* Group id for whole class */
struct _GcomprisGroup *all;
gint *wholegroup_id;
/* list of GComprisGroup id */
GList *group_ids;
/* list of GComprisUser id */
GList *user_ids;
};
typedef struct _GcomprisClass GcomprisClass;
......@@ -58,6 +63,8 @@ typedef struct _GcomprisClass GcomprisClass;
/* group data is saved when class is saved */
struct _GcomprisGroup {
gint group_id;
/*name of group -- must be unique */
gchar *name;
......@@ -100,8 +107,6 @@ struct _GcomprisUser {
/* Birth day */
gchar *birthdate;
/* desactived activities for this user */
GList *desactived_activities;
};
typedef struct _GcomprisUser GcomprisUser;
......
Supports Markdown
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