Commit 1ab43485 authored by Bruno Coudoin's avatar Bruno Coudoin

Implemented two new options from the command line:

	gcompris -p or --profile name => run gcompris under the profile 'name'
	gcompris --profile-list => display on stdout the available profiles
parent e1e13e07
2005-07-25 Bruno coudoin <bruno.coudoin@free.fr>
Implemented two new options from the command line:
gcompris -p or --profile name => run gcompris under the profile 'name'
gcompris --profile-list => display on stdout the available profiles
* src/boards/python/tuxpaint.py: Removed old config code per Yves request.
* src/gcompris/gcompris.c: (gcompris_init):
* src/gcompris/gcompris_db.c: (gcompris_get_profile_from_name):
* src/gcompris/gcompris_db.h:
* src/gcompris/images_selector.c: (gcompris_images_selector_start),
(parseImage):
* src/gcompris/profile.c: (gcompris_get_current_profile),
(gcompris_set_current_user), (gcompris_get_current_user):
* src/gcompris/properties.c: (gcompris_properties_new),
(gcompris_properties_save):
* src/gcompris/properties.h:
2005-07-24 Yves Combe <yves@ycombe.net>
pass binding of gcomrpis_window like child_spawn.
......
......@@ -167,18 +167,6 @@ class Gcompris_tuxpaint:
gcompris.boolean_box('Disable stamps', 'disable_stamps', self.configuration('disable_stamps'))
gcompris.boolean_box('Disable stamps control', 'disable_stamps_control', self.configuration('disable_stamps_control'))
def boolean_box(self, label, value):
button = gtk.CheckButton(label)
button.connect("toggled", self.boolean_callback, value)
button.show()
self.configure_main_box.pack_start(button, False, False, 0)
if self.actual_config.has_key(value):
button.set_active(eval(self.actual_config[value]))
def boolean_callback(self, widget, value):
self.config_values[value] = str(widget.get_active())
def apply_callback(self,table):
for key,value in table.iteritems():
......
/* gcompris - gcompris.c
*
* Time-stamp: <2005/07/10 23:38:14 bruno>
* Time-stamp: <2005/07/25 00:32:32 bruno>
*
* Copyright (C) 2000-2003 Bruno Coudoin
*
......@@ -91,6 +91,8 @@ static char *popt_database = NULL;
static char *popt_logs_database = NULL;
static int popt_create_db = FALSE;
static int popt_reread_xml = FALSE;
static char *popt_profile = NULL;
static int *popt_profile_list = FALSE;
GTimer *chronometer;
......@@ -122,13 +124,17 @@ static struct poptOption options[] = {
{"administration", 'e', POPT_ARG_NONE, &popt_administration, 0,
N_("Run gcompris with administration and users management mode"), NULL},
{"database", 'b', POPT_ARG_STRING, &popt_database, 0,
N_("Use alternate database for profils"), NULL},
N_("Use alternate database for profiles"), NULL},
{"logs", 'j', POPT_ARG_STRING, &popt_logs_database, 0,
N_("Use alternate database for logs"), NULL},
{"create-db",'\0', POPT_ARG_NONE, &popt_create_db, 0,
N_("Create the alternate database for profils"), NULL},
N_("Create the alternate database for profiles"), NULL},
{"reread-xml",'\0', POPT_ARG_NONE, &popt_reread_xml, 0,
N_("Re-read XML Menus and store them in the database"), NULL},
{"profile",'p', POPT_ARG_STRING, &popt_profile, 0,
N_("Set the profile to use. Use 'gcompris -e' to create profiles"), NULL},
{"profile-list",'\0', POPT_ARG_NONE, &popt_profile_list, 0,
N_("List all availaible profiles. Use 'gcompris -e' to create profiles"), NULL},
#ifndef WIN32 /* Not supported on windows */
POPT_AUTOHELP
#endif
......@@ -1057,12 +1063,50 @@ gcompris_init (int argc, char *argv[])
properties->reread_xml = TRUE;
}
poptFreeContext(pctx);
/*------------------------------------------------------------*/
/* init MUST BE after properties */
/*
* Database nit MUST BE after properties
* And after a possible alternate database as been provided
*
*/
gcompris_db_init();
/* An alternate profile is requested, check it does exists */
if (popt_profile){
GList * profile_list;
properties->profile = gcompris_get_profile_from_name(popt_profile);
if(properties->profile == NULL)
{
printf("ERROR: Profile '%s' is not found. Run 'gcompris --profile-list' to list available ones\n",
popt_profile);
exit(1);
}
}
/* List all available profiles */
if (popt_profile_list){
GList * profile_list;
int i;
profile_list = gcompris_get_profiles_list();
printf(_("List of available profiles are:\n"));
for(i=0; i< g_list_length(profile_list); i++)
{
GcomprisProfile *profile = g_list_nth_data(profile_list, i);
printf(" %s\n", profile->name);
}
g_list_free(profile_list);
exit(0);
}
poptFreeContext(pctx);
/*------------------------------------------------------------*/
if(properties->music || properties->fx)
initSound();
......
/* gcompris - gcompris_db.c
*
* Time-stamp: <2005/07/23 16:12:09 yves>
* Time-stamp: <2005/07/25 00:29:30 bruno>
*
* Copyright (C) 2000 Bruno Coudoin
*
......@@ -683,6 +683,9 @@ void gcompris_db_remove_board(int board_id)
#define GET_PROFILE(n) \
"SELECT name, profile_directory, description FROM profiles WHERE profile_id=%d;",n
#define GET_PROFILE_FROM_NAME(n) \
"SELECT profile_id, profile_directory, description FROM profiles WHERE name='%s';",n
#define GET_GROUPS_IN_PROFILE(n) \
"SELECT group_id FROM list_groups_in_profiles WHERE profile_id=%d;",n
......@@ -801,6 +804,62 @@ GcomprisProfile *gcompris_get_profile_from_id(gint profile_id)
#endif
}
/** \brief Given a profile name, return a GcomprisProfile struct
*
* \param profile_name: the profile to retrieve.
*
* \return *GcomprisProfile
*/
GcomprisProfile *
gcompris_get_profile_from_name(gchar *profile_name)
{
#ifdef USE_SQLITE
GcomprisProfile *profile = NULL;
char *zErrMsg;
char **result;
int rc;
int nrow;
int ncolumn;
gchar *request;
/* get section_id */
request = g_strdup_printf(GET_PROFILE_FROM_NAME(profile_name));
printf("request = %s\n", request);
rc = sqlite3_get_table(gcompris_db,
request,
&result,
&nrow,
&ncolumn,
&zErrMsg
);
if( rc!=SQLITE_OK ){
g_error("SQL error: %s\n", zErrMsg);
}
if (nrow != 0){
gint profile_id;
profile_id = atoi(result[3]);
printf("profile_id = %d\n", profile_id);
g_free(request);
profile = gcompris_get_profile_from_id(profile_id);
}
return profile;
#else
return NULL;
#endif
}
#define GET_ACTIVE_PROFILE_ID \
"SELECT profile_id FROM informations;"
......
/* gcompris - gcompris_db.h
*
* Time-stamp: <2005/07/23 15:39:41 yves>
* Time-stamp: <2005/07/24 23:59:17 bruno>
*
* Copyright (C) 2005 Bruno Coudoin
*
......@@ -27,8 +27,8 @@
#include <sqlite3.h>
#endif
/* Database management */
int gcompris_db_init();
void gcompris_db_exit();
gboolean gcompris_db_check_boards();
......@@ -71,10 +71,16 @@ GList *gcompris_db_get_board_id(GList *list);
void gcompris_db_remove_board(int board_id);
GcomprisProfile *gcompris_get_profile_from_id(gint profile_id);
/* Profile management */
GcomprisProfile *gcompris_get_profile_from_id(gint profile_id);
GcomprisProfile *gcompris_get_profile_from_name(gchar *profile_name);
GList *gcompris_get_profiles_list();
/* Classes management */
GcomprisClass *gcompris_get_class_from_id(gint class_id);
GList *gcompris_get_classes_list();
......
/* gcompris - images_selector.c
*
* Time-stamp: <2005/04/10 16:44:29 bruno>
* Time-stamp: <2005/07/25 00:17:41 bruno>
*
* Copyright (C) 2000 Bruno Coudoin
*
......@@ -286,8 +286,6 @@ void gcompris_images_selector_start (GcomprisBoard *gcomprisBoard, gchar *datase
-> if dataset is a directory, read all xml file in it.
*/
g_return_val_if_fail(dataset!=NULL,FALSE);
/* if the file doesn't exist */
if(g_file_test ((dataset), G_FILE_TEST_IS_DIR) )
{
......@@ -691,12 +689,13 @@ parseImage (xmlDocPtr doc, xmlNodePtr cur) {
return;
}
imageset_directory = g_dir_open (pathname, 0, error);
while (filename = g_dir_read_name(imageset_directory)){
const gchar * onefile;
while (onefile = g_dir_read_name(imageset_directory)){
if ((g_ascii_strcasecmp (type,"lsdir") != 0) &&
(!g_str_has_suffix (filename,type))){
(!g_str_has_suffix (onefile, type))){
continue;
}
filename = g_strdup_printf("%s/%s",pathname,filename);
filename = g_strdup_printf("%s/%s", pathname, onefile);
if (!g_file_test ((filename), G_FILE_TEST_EXISTS)){
continue;
}
......
/* gcompris - profile.c
*
* Time-stamp: <2005/07/11 13:18:11 yves>
* Time-stamp: <2005/07/25 00:10:07 bruno>
*
* Copyright (C) 2005 Bruno Coudoin
*
......@@ -21,9 +21,7 @@
#include <stdio.h>
#include "gcompris.h"
/* Active profile */
static GcomprisProfile *gcompris_profile = NULL;
#include "properties.h"
/* logged user */
static GcomprisUser *gcompris_logged_user = NULL;
......@@ -31,26 +29,29 @@ static GcomprisUser *gcompris_logged_user = NULL;
GcomprisProfile *gcompris_get_current_profile()
{
GcomprisProperties *properties = gcompris_get_properties();
if (gcompris_profile)
return gcompris_profile;
if (properties->profile)
return properties->profile;
gcompris_profile = gcompris_db_get_profile();
properties->profile = gcompris_db_get_profile();
return gcompris_profile;
return properties->profile;
}
void *gcompris_set_current_user(GcomprisUser *user)
{
gcompris_logged_user = user;
GcomprisProperties *properties = gcompris_get_properties();
properties->logged_user = user;
}
GcomprisUser *gcompris_get_current_user()
{
return gcompris_logged_user;
GcomprisProperties *properties = gcompris_get_properties();
return properties->logged_user;
}
......
/* gcompris - properties.c
*
* Time-stamp: <2005/06/22 10:36:03 yves>
* Time-stamp: <2005/07/24 23:49:10 bruno>
*
* Copyright (C) 2000,2003 Bruno Coudoin
*
......@@ -152,7 +152,8 @@ GcomprisProperties *gcompris_properties_new ()
tmp->root_menu = "/";
tmp->local_directory = NULL;
tmp->package_data_dir = PACKAGE_DATA_DIR;
tmp->profil = "default";
tmp->profile = NULL;
tmp->logged_user = NULL;
tmp->database = get_default_database_name();
tmp->administration = FALSE;
tmp->reread_xml = FALSE;
......@@ -235,11 +236,6 @@ GcomprisProperties *gcompris_properties_new ()
if(!tmp->key)
g_warning("Config file parsing error on token %s", token);
}
else if(!strcmp(value.v_identifier, "profil")) {
tmp->profil = scan_get_string(scanner);
if(!tmp->profil)
g_warning("Config file parsing error on token %s", token);
}
else if(!strcmp(value.v_identifier, "database")) {
tmp->database = scan_get_string(scanner);
if(!tmp->database)
......@@ -328,7 +324,6 @@ void gcompris_properties_save (GcomprisProperties *props)
fprintf(filefd, "%s=\"%s\"\n", "locale", props->locale);
fprintf(filefd, "%s=\"%s\"\n", "key", props->key);
fprintf(filefd, "%s=\"%s\"\n", "profil", props->profil);
fprintf(filefd, "%s=\"%s\"\n", "database", props->database);
fclose(filefd);
......
/* gcompris - properties.h
*
* Time-stamp: <2005/06/29 10:55:12 yves>
* Time-stamp: <2005/07/24 23:48:52 bruno>
*
* Copyright (C) 2000 Bruno Coudoin
*
......@@ -22,6 +22,8 @@
#ifndef _PROPERTIES_H_
#define _PROPERTIES_H_
#include "profile.h"
typedef struct {
gint music;
gint fx;
......@@ -40,8 +42,9 @@ typedef struct {
gchar *locale;
gchar *skin;
gchar *key;
gchar *profil;
gchar *database;
GcomprisProfile *profile;
GcomprisUser *logged_user;
gchar *database;
gint administration;
gint reread_xml;
} GcomprisProperties;
......
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