Back to index

gcompris  8.2.2
Classes | Functions
properties.h File Reference
#include "profile.h"
This graph shows which files directly or indirectly include this file:

Go to the source code of this file.

Classes

struct  GcomprisProperties

Functions

GcomprisPropertiesgc_prop_get (void)
GcomprisPropertiesgc_prop_new (void)
void gc_prop_destroy (GcomprisProperties *props)
void gc_prop_save (GcomprisProperties *props)
gchar * gc_prop_default_database_name_get (gchar *shared_dir)
int gc_setenv (const char *name, const char *value)
gchar * gc_prop_user_dirname_get (GcomprisUser *user)
gchar * gc_prop_current_user_dirname_get ()
gchar * gc_prop_board_dirname_get (GcomprisBoard *board)
gchar * gc_prop_current_board_dirname_get ()

Class Documentation

struct GcomprisProperties

Definition at line 27 of file properties.h.

Collaboration diagram for GcomprisProperties:
Class Members
gint administration
gchar * cache_dir
GtkIMContext * context
gchar * database
gchar * default_context
gint defaultcursor
gint difficulty_filter
gint difficulty_max
gint disable_config
gint disable_quit
gint display_resource
gint experimental
gint filter_style
gint fullscreen
gint fx
gchar * key
gchar * local_directory
gchar * locale
GcomprisUser * logged_user
GcomprisBoard * menu_board
gchar * menu_position
gint music
gint noxf86vm
gchar * package_data_dir
gchar * package_locale_dir
gchar * package_plugin_dir
gchar * package_python_plugin_dir
GcomprisProfile * profile
gint reread_menu
gchar * root_menu
gint screensize
gchar * server
gchar * shared_dir
gchar * skin
gchar * system_icon_dir
gint timer
gchar * user_data_dir
gchar * users_dir

Function Documentation

gchar* gc_prop_board_dirname_get ( GcomprisBoard *  board)

Definition at line 392 of file properties.c.

{
  GcomprisProperties *properties = gc_prop_get ();

  gchar *board_main = g_strconcat (properties->shared_dir, "/boards", NULL);
  gc_util_create_rootdir(board_main);

  gchar *board_dirname = g_strconcat (board_main, "/", board->name, NULL);
  gc_util_create_rootdir(board_dirname);

  g_free(board_main);
  return board_dirname;
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 407 of file properties.c.

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 386 of file properties.c.

Here is the call graph for this function:

Here is the caller graph for this function:

gchar* gc_prop_default_database_name_get ( gchar *  shared_dir)

Definition at line 113 of file properties.c.

{
  gchar *dir_base = g_strconcat( shared_dir, "/",  PROFILES_ROOT, NULL);
  gc_util_create_rootdir(dir_base);
  g_free(dir_base);
  return g_strconcat( shared_dir, "/",  PROFILES_ROOT, "/",  DEFAULT_DATABASE, NULL);

}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 317 of file properties.c.

{
  if(!props)
    return;
  g_free(props->user_data_dir);
  g_free(props->package_data_dir);
  g_free(props->package_locale_dir);
  g_free(props->package_plugin_dir);
  g_free(props->package_python_plugin_dir);
  g_free(props->system_icon_dir);
  g_free(props->cache_dir);
  g_free(props->locale);
  g_free(props->skin);
  g_free(props->key);
  gc_profile_destroy(props->profile);
  gc_user_destroy(props->logged_user);
  g_free(props->database);
  g_free(props->shared_dir);
  g_free(props->users_dir);
  g_free(props->menu_position);
  g_free(props->server);
  g_free (props);
  g_warning("properties free");
}

Here is the call graph for this function:

Here is the caller graph for this function:

Definition at line 1136 of file gcompris.c.

{
  return (properties);
}

Definition at line 123 of file properties.c.

{
  GcomprisProperties *tmp;
  char          *config_file = gc_prop_config_file_get();
  GScanner      *scanner;
  gchar              *content;
  gsize              length;
  gchar         *full_rootdir;
  const gchar   *locale;
  gchar         *user_dir;

  tmp = (GcomprisProperties *) malloc (sizeof (GcomprisProperties));
  tmp->music          = 1;
  tmp->fx             = 1;
  tmp->screensize     = 1;
  tmp->fullscreen     = 1;
  tmp->noxf86vm              = FALSE;
  tmp->timer          = 1;
  tmp->skin           = g_strdup("babytoy");
  tmp->key            = g_strdup("default");
  tmp->locale            = NULL;
  tmp->difficulty_max    = 0;
  tmp->filter_style      = GCOMPRIS_FILTER_NONE; /* No difficulty filter by default */
  tmp->difficulty_filter = 1;                           /* No difficulty filter by default */
  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->display_resource  = 0;
  tmp->root_menu         = "/";
  tmp->local_directory   = NULL;
  tmp->profile           = NULL;
  tmp->logged_user       = NULL;

  tmp->administration    = FALSE;
  tmp->reread_menu       = FALSE;
  tmp->experimental      = FALSE;
  tmp->menu_position     = NULL;

  tmp->server            = NULL;

  tmp->package_data_dir           = NULL;
  tmp->package_locale_dir         = NULL;
  tmp->package_plugin_dir         = NULL;
  tmp->package_python_plugin_dir  = NULL;
  tmp->system_icon_dir            = NULL;
  tmp->cache_dir                  = NULL;

  user_dir = gc_prop_user_root_directory_get() ;
  gc_util_create_rootdir( user_dir );

  tmp->shared_dir        = g_strconcat(user_dir, "/shared", NULL);
  gc_util_create_rootdir( tmp->shared_dir );

  tmp->users_dir        = g_strconcat(user_dir, "/users", NULL);
  gc_util_create_rootdir( tmp->users_dir );

  tmp->user_data_dir = g_strconcat(user_dir, "/Plugins/boards", NULL);
  gc_util_create_rootdir( tmp->user_data_dir );

  /* Needs to be set after command line parsing */
  tmp->database          = NULL;

  full_rootdir = g_strconcat(user_dir, "/user_data", NULL);
  gc_util_create_rootdir(full_rootdir);
  g_free(full_rootdir);

  full_rootdir = g_strconcat(user_dir, "/user_data/images", NULL);
  gc_util_create_rootdir(full_rootdir);
  g_free(full_rootdir);

  full_rootdir = g_strconcat(user_dir, "/", PROFILES_ROOT, NULL);
  gc_util_create_rootdir(full_rootdir);
  g_free(full_rootdir);

  g_free(user_dir);

  g_warning("config_file %s", config_file);

  if(g_file_get_contents(config_file,
                      &content,
                      &length,
                      NULL)) {

    /* create a new scanner */
    scanner = g_scanner_new(NULL);

    /* set up the scanner to read from the file */
    g_scanner_input_text(scanner, content, length);

    /* while the next token is something else other than end of file */
    while(g_scanner_peek_next_token(scanner) != G_TOKEN_EOF) {

      /* get the next token */
      GTokenType tokent = g_scanner_get_next_token(scanner);
      switch(tokent) {
      case G_TOKEN_IDENTIFIER: {
       gchar *token;
       /* if we have a symbol, check it's ours */
       GTokenValue value = g_scanner_cur_value(scanner);
       token = g_strdup(value.v_identifier);

       if(!strcmp(value.v_identifier, "music")) {
         if(!scan_get_int(scanner, &tmp->music))
           g_warning("Config file parsing error on token %s", token);
       } else if(!strcmp(value.v_identifier, "fx")) {
         if(!scan_get_int(scanner, &tmp->fx))
           g_warning("Config file parsing error on token %s", token);
       } else if(!strcmp(value.v_identifier, "screensize")) {
         if(!scan_get_int(scanner, &tmp->screensize))
           g_warning("Config file parsing error on token %s", token);
       } else if(!strcmp(value.v_identifier, "fullscreen")) {
         if(!scan_get_int(scanner, &tmp->fullscreen))
           g_warning("Config file parsing error on token %s", token);
       } else if(!strcmp(value.v_identifier, "noxf86vm")) {
         if(!scan_get_int(scanner, &tmp->noxf86vm))
           g_warning("Config file parsing error on token %s", token);
       } else if(!strcmp(value.v_identifier, "timer")) {
         if(!scan_get_int(scanner, &tmp->timer))
           g_warning("Config file parsing error on token %s", token);
       } else if(!strcmp(value.v_identifier, "difficulty_filter")) {
         if(!scan_get_int(scanner, &tmp->difficulty_filter))
           g_warning("Config file parsing error on token %s", token);
       } else if(!strcmp(value.v_identifier, "disable_quit")) {
         if(!scan_get_int(scanner, &tmp->disable_quit))
           g_warning("Config file parsing error on token %s", token);
       } else if(!strcmp(value.v_identifier, "disable_config")) {
         if(!scan_get_int(scanner, &tmp->disable_config))
           g_warning("Config file parsing error on token %s", token);
       } else if(!strcmp(value.v_identifier, "filter_style")) {
         if(!scan_get_int(scanner, &tmp->filter_style))
           g_warning("Config file parsing error on token %s", token);
       } else if(!strcmp(value.v_identifier, "skin")) {
        g_free(tmp->skin);
         tmp->skin = scan_get_string(scanner);
         if(!tmp->skin)
           g_warning("Config file parsing error on token %s", token);
       } else if(!strcmp(value.v_identifier, "locale")) {
         tmp->locale = scan_get_string(scanner);
         if(!tmp->locale)
           g_warning("Config file parsing error on token %s", token);
       } else if(!strcmp(value.v_identifier, "key")) {
      g_free(tmp->key);
         tmp->key = scan_get_string(scanner);
         if(!tmp->key)
           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)
           g_warning("Config file parsing error on token %s", token);
       }
       g_free(token);
       break;
      }
      default:
       break;
      }
    }

    /* destroy the scanner */
    g_scanner_destroy(scanner);
    g_free(content);
  }

  /*
   * Warning, gcompris need a proper locale prefix to find suitable dataset
   * Some system use LOCALE 'C' for english. We have to set it explicitly
   */
  if(!tmp->locale) {

#if defined WIN32
    tmp->locale = g_win32_getlocale();
#else
    locale = g_getenv("LC_ALL");
    if(locale == NULL)
      locale = g_getenv("LC_MESSAGES");
    if(locale == NULL)
      locale = g_getenv("LANG");

    if (locale != NULL && !strcmp(locale, "C"))
      {
       tmp->locale          = "en_US.UTF-8";
      }
#endif
  }

  if(!tmp->locale) {
    /* No user specified locale = '' */
    tmp->locale             = strdup("");
  }

  return (tmp);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gc_prop_save ( GcomprisProperties props)

Definition at line 343 of file properties.c.

{
  char *config_file = gc_prop_config_file_get();
  FILE *filefd;

  filefd = g_fopen(config_file, "w+");

  if(!filefd) {
      g_warning("cannot open '%s', configuration file not saved\n",(char *) config_file);
      return;
    }

  fprintf(filefd, "%s=%d\n", "music",                   props->music);
  fprintf(filefd, "%s=%d\n", "fx",               props->fx);
  fprintf(filefd, "%s=%d\n", "screensize",              props->screensize);
  fprintf(filefd, "%s=%d\n", "fullscreen",              props->fullscreen);
  fprintf(filefd, "%s=%d\n", "timer",                   props->timer);

  fprintf(filefd, "%s=\"%s\"\n", "skin",         props->skin);
  fprintf(filefd, "%s=\"%s\"\n", "locale",              props->locale);
  fprintf(filefd, "%s=\"%s\"\n", "key",                 props->key);

  fprintf(filefd, "%s=\"%s\"\n", "database",            props->database);

  fclose(filefd);
}

Here is the call graph for this function:

Here is the caller graph for this function:

gchar* gc_prop_user_dirname_get ( GcomprisUser *  user)

Definition at line 371 of file properties.c.

{
  GcomprisProperties *properties = gc_prop_get ();

  gchar *user_dirname = g_strconcat (properties->users_dir,
                                 "/",
                                 user->login,
                                 NULL);

  gc_util_create_rootdir(user_dirname);

  return user_dirname;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gc_setenv ( const char *  name,
const char *  value 
)

Definition at line 414 of file properties.c.

                                                  {
#if defined WIN32
  size_t namelen = strlen(name);
  size_t valuelen = (value==NULL ? 0 : strlen(value));
  /* On Woe32, each process has two copies of the environment variables,
     one managed by the OS and one managed by the C library. We set
     the value in both locations, so that other software that looks in
     one place or the other is guaranteed to see the value. Even if it's
     a bit slow. See also
     <http://article.gmane.org/gmane.comp.gnu.mingw.user/8272>
     <http://article.gmane.org/gmane.comp.gnu.mingw.user/8273>
     <http://www.cygwin.com/ml/cygwin/1999-04/msg00478.html> */
  if (!SetEnvironmentVariableA(name,value))
    return -1;
  //#endif
  //#if defined(HAVE_PUTENV)
  char* buffer = (char*)malloc(namelen+1+valuelen+1);
  if (!buffer)
    return -1; /* no need to set errno = ENOMEM */
  memcpy(buffer,name,namelen);
  if (value != NULL) {
    buffer[namelen] = '=';
    memcpy(buffer+namelen+1,value,valuelen);
    buffer[namelen+1+valuelen] = 0;
  } else
    buffer[namelen] = 0;
  return putenv(buffer);
#elif defined(HAVE_SETENV)
  return setenv(name,value,1);
#else
  /* Uh oh, neither putenv() nor setenv() ... */
  return -1;
#endif
}

Here is the caller graph for this function: