Commit 1263adde authored by Yves Combe's avatar Yves Combe
Browse files

add several functions for directory management.

create user from system data if no user to log (system encoding?).
parent 0a0e4f57
2005-08-26 Yves Combe,,, <yves@ycombe.net>
add several functions for directory management.
create user from system data if no user to log (system encoding?).
* src/boards/py-gcompris-user.c: (pyGcomprisUserType_getattr):
* src/boards/py-mod-gcompris.c: (pyGcomprisTextCallback),
(py_gcompris_get_user_dirname), (py_gcompris_get_board_dirname),
(py_gcompris_get_current_user_dirname),
(py_gcompris_get_current_board_dirname):
* src/boards/python/pythontest.py:
* src/gcompris/Makefile.am:
* src/gcompris/gcompris.c: (setup_window):
* src/gcompris/gcompris.h:
* src/gcompris/gcompris_files.c: (gcompris_get_user_dirname),
(gcompris_get_current_user_dirname), (gcompris_get_board_dirname),
(gcompris_get_current_board_dirname):
* src/gcompris/gcompris_files.h:
* src/gcompris/profile.c: (gcompris_set_current_user):
* src/gcompris/profile.h:
* src/gcompris/properties.c:
* src/gcompris/properties.h:
2005-08-25 bruno coudoin
* boards/sudoku.xml.in: typos (thanks to Gabor Kelemen)
......
......@@ -53,6 +53,8 @@ pyGcomprisUserType_getattr(pyGcomprisUserObject *self, char *name)
if(strcmp(name,"firstname")==0) return Py_BuildValue("s", self->cdata->firstname);
/* str */
if(strcmp(name,"birthdate")==0) return Py_BuildValue("s", self->cdata->birthdate);
/* u int */
if(strcmp(name,"session_id")==0) return Py_BuildValue("i", self->cdata->session_id);
return Py_FindMethod(pyGcomprisUserType_methods, (PyObject *)self, name);
}
......
......@@ -1447,7 +1447,7 @@ py_gcompris_reset_locale(PyObject* self, PyObject* args)
/* How can i free that ? */
static GHashTable *text_callbacks = NULL;
static GcomprisTextCallback pyGcomprisTextCallback(gchar *key, gchar *text, GtkLabel *label){
static gboolean pyGcomprisTextCallback(gchar *key, gchar *text, GtkLabel *label){
PyObject* args;
PyObject* result;
gboolean validate;
......@@ -1524,6 +1524,71 @@ py_gcompris_textview(PyObject* self, PyObject* args){
}
static PyObject*
py_gcompris_get_user_dirname (PyObject* self, PyObject* args)
{
PyObject* pyUser;
pyGcomprisUserObject* pyGcomprisUser;
GcomprisUser* cGcomprisUser;
/* Parse arguments */
if(!PyArg_ParseTuple(args, "O:gcompris.get_user_dirname", &pyUser))
return NULL;
pyGcomprisUser = (pyGcomprisUserObject *) pyUser;
cGcomprisUser = pyGcomprisUser->cdata;
/* Call the corresponding C function */
return PyString_FromString(gcompris_get_user_dirname(cGcomprisUser));
}
static PyObject*
py_gcompris_get_board_dirname (PyObject* self, PyObject* args)
{
PyObject* pyBoard;
pyGcomprisBoardObject* pyGcomprisBoard;
GcomprisBoard* cGcomprisBoard;
/* Parse arguments */
if(!PyArg_ParseTuple(args, "O:gcompris.get_board_dirname", &pyBoard))
return NULL;
pyGcomprisBoard = (pyGcomprisBoardObject *) pyBoard;
cGcomprisBoard = pyGcomprisBoard->cdata;
/* Call the corresponding C function */
return PyString_FromString(gcompris_get_board_dirname(cGcomprisBoard));
}
static PyObject*
py_gcompris_get_current_user_dirname (PyObject* self, PyObject* args)
{
/* Parse arguments */
if(!PyArg_ParseTuple(args, ":gcompris.get_current_user_dirname"))
return NULL;
/* Call the corresponding C function */
return PyString_FromString(gcompris_get_current_user_dirname());
}
static PyObject*
py_gcompris_get_current_board_dirname (PyObject* self, PyObject* args)
{
/* Parse arguments */
if(!PyArg_ParseTuple(args, ":gcompris.get_current_board_dirname"))
return NULL;
/* Call the corresponding C function */
return PyString_FromString(gcompris_get_current_board_dirname());
}
/****************************************************/
......@@ -1581,6 +1646,11 @@ static PyMethodDef PythonGcomprisModule[] = {
{ "combo_locales_asset", py_gcompris_combo_locales_asset, METH_VARARGS, "gcompris_combo_locales_asset" },
{ "get_locales_asset_list", py_gcompris_get_locales_asset_list, METH_VARARGS, "gcompris_get_locales_asset_list" },
{ "textview", py_gcompris_textview, METH_VARARGS, "gcompris_textview" },
{ "get_user_dirname", py_gcompris_get_user_dirname, METH_VARARGS, "gcompris_get_user_dirname" },
{ "get_current_user_dirname", py_gcompris_get_current_user_dirname, METH_VARARGS, "gcompris_get_current_user_dirname" },
{ "get_board_dirname", py_gcompris_get_board_dirname, METH_VARARGS, "gcompris_get_board_dirname" },
{ "get_current_board_dirname", py_gcompris_get_current_board_dirname, METH_VARARGS, "gcompris_get_current_board_dirname" },
{ NULL, NULL, 0, NULL}
};
......
......@@ -40,6 +40,9 @@ class Gcompris_pythontest:
def start(self):
logged = gcompris.admin.get_current_user()
print gcompris.get_current_user_dirname()
print gcompris.get_current_board_dirname()
if logged:
print "User Logged in:"
print " ", logged.login, logged.firstname, logged.lastname
......
......@@ -94,6 +94,8 @@ libgcomprisinclude_HEADERS = \
gcompris_config.h \
gcompris_db.c \
gcompris_db.h \
gcompris_files.c \
gcompris_files.h \
pixbuf_util.h \
plugin.h \
profile.c \
......
......@@ -660,10 +660,15 @@ static void setup_window ()
/* No profile start normally */
if (found)
board_to_start = gcompris_get_board_from_section("/login/login");
else
else {
board_to_start = gcompris_get_board_from_section(properties->root_menu);
/* this will set user information to system one */
gcompris_set_current_user(NULL);
}
}
else
/* this will set user information to system one */
gcompris_set_current_user(NULL);
}
if(!board_to_start) {
......
/* gcompris - gcompris.h
*
* Time-stamp: <2005/07/04 12:51:36 yves>
* Time-stamp: <2005/08/25 23:17:42 yves>
*
* Copyright (C) 2000,2001,2002 Bruno Coudoin
*
......@@ -50,6 +50,7 @@
#include "profile.h"
#include "gcompris_db.h"
#include "gcompris_files.h"
#ifdef USE_CAIRO
#include "gcompris-cairo.h"
......
/* gcompris - gcompris-files.c
*
* Time-stamp: <2005/08/25 23:33:24 yves>
*
* Copyright (C) 2000 Bruno Coudoin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#include "gcompris_files.h"
gchar *gcompris_get_user_dirname(GcomprisUser *user)
{
GcomprisProperties *properties = gcompris_get_properties ();
gchar *user_dirname = g_strconcat (properties->users_dir,
"/",
user->login,
NULL);
create_rootdir(user_dirname);
return user_dirname;
}
gchar *gcompris_get_current_user_dirname()
{
return gcompris_get_user_dirname(gcompris_get_current_user());
}
gchar *gcompris_get_board_dirname(GcomprisBoard *board)
{
GcomprisProperties *properties = gcompris_get_properties ();
gchar *board_main = g_strconcat (properties->shared_dir, "/boards", NULL);
create_rootdir(board_main);
gchar *board_dirname = g_strconcat (board_main, "/", board->name, NULL);
create_rootdir(board_dirname);
g_free(board_main);
return board_dirname;
}
gchar *gcompris_get_current_board_dirname()
{
return gcompris_get_board_dirname(get_current_gcompris_board());
}
/* Local Variables: */
/* mode:c */
/* eval:(load-library "time-stamp") */
/* eval:(make-local-variable 'write-file-hooks) */
/* eval:(add-hook 'write-file-hooks 'time-stamp) */
/* eval:(setq time-stamp-format '(time-stamp-yyyy/mm/dd time-stamp-hh:mm:ss user-login-name)) */
/* End: */
/* gcompris - gcompris-files.h
*
* Time-stamp: <2005/08/25 23:31:06 yves>
*
* Copyright (C) 2000 Bruno Coudoin
*
* This program is free software; you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation; either version 2 of the License, or
* (at your option) any later version.
*
* This program is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with this program; if not, write to the Free Software
* Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA.
*/
#ifndef _GOMPRIS_FILES_H_
#define _GOMPRIS_FILES_H_
#include "gcompris.h"
gchar *gcompris_get_user_dirname(GcomprisUser *user);
gchar *gcompris_get_current_user_dirname();
gchar *gcompris_get_board_dirname(GcomprisBoard *board);
gchar *gcompris_get_current_board_dirname();
#endif
/* Local Variables: */
/* mode:c */
/* eval:(load-library "time-stamp") */
/* eval:(make-local-variable 'write-file-hooks) */
/* eval:(add-hook 'write-file-hooks 'time-stamp) */
/* eval:(setq time-stamp-format '(time-stamp-yyyy/mm/dd time-stamp-hh:mm:ss user-login-name)) */
/* End: */
/* gcompris - profile.c
*
* Time-stamp: <2005/07/25 00:10:07 bruno>
* Time-stamp: <2005/08/26 01:02:32 yves>
*
* Copyright (C) 2005 Bruno Coudoin
*
......@@ -23,10 +23,6 @@
#include "gcompris.h"
#include "properties.h"
/* logged user */
static GcomprisUser *gcompris_logged_user = NULL;
GcomprisProfile *gcompris_get_current_profile()
{
GcomprisProperties *properties = gcompris_get_properties();
......@@ -44,7 +40,28 @@ GcomprisProfile *gcompris_get_current_profile()
void *gcompris_set_current_user(GcomprisUser *user)
{
GcomprisProperties *properties = gcompris_get_properties();
properties->logged_user = user;
if (user)
properties->logged_user = user;
else {
g_warning("No user, getting one from system.");
GcomprisUser *sys_user = g_malloc0(sizeof(GcomprisUser));
sys_user->login = g_strdup(g_get_user_name ());
sys_user->lastname = g_strdup(g_get_real_name ());
sys_user->firstname = g_strdup("Unknown");
sys_user->birthdate = g_strdup("");
properties->logged_user = sys_user;
}
GTimeVal now;
g_get_current_time (&now);
gchar *session_id_str = g_strdup_printf("%s%ld%ld", (properties->logged_user)->login, now.tv_sec, now.tv_usec);
(properties->logged_user)->session_id = g_str_hash((gconstpointer) session_id_str);
}
......
/* gcompris - profile.h
*
* Time-stamp: <2005/08/13 14:34:54 brunoa>
* Time-stamp: <2005/08/26 00:35:48 yves>
*
* Copyright (C) 2005 Bruno Coudoin
*
......@@ -107,6 +107,8 @@ struct _GcomprisUser {
/* Birth day */
gchar *birthdate;
/* Unique Session ID */
guint session_id;
};
typedef struct _GcomprisUser GcomprisUser;
......
/* gcompris - properties.c
*
* Time-stamp: <2005/08/25 12:47:50 yves>
* Time-stamp: <2005/08/25 22:58:04 yves>
*
* Copyright (C) 2000,2003 Bruno Coudoin
*
......@@ -74,7 +74,7 @@ gchar *scan_get_string(GScanner *scanner) {
*
* return 0 if OK, -1 if ERROR
*/
static int
int
create_rootdir (gchar *rootdir)
{
......
/* gcompris - properties.h
*
* Time-stamp: <2005/08/25 07:55:12 yves>
* Time-stamp: <2005/08/25 22:58:31 yves>
*
* Copyright (C) 2000 Bruno Coudoin
*
......@@ -58,6 +58,7 @@ void gcompris_properties_destroy (GcomprisProperties *props);
void gcompris_properties_save (GcomprisProperties *props);
gchar *get_default_database_name (gchar *shared_dir);
int create_rootdir (gchar *rootdir);
#endif
......
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