Back to index

gcompris  8.2.2
Functions
main.c File Reference
#include <signal.h>
#include "gcompris.h"

Go to the source code of this file.

Functions

int gc_init (int argc, char *argv[])
int main (int argc, char *argv[])

Function Documentation

int gc_init ( int  argc,
char *  argv[] 
)

Definition at line 1384 of file gcompris.c.

{
  poptContext pctx;
  int popt_option;

  /* First, Remove the gnome crash dialog because it locks the user when in full screen */
  signal(SIGSEGV, gc_terminate);
  signal(SIGINT, gc_terminate);

  load_properties();

  gc_skin_load(properties->skin);

  bindtextdomain (GETTEXT_PACKAGE, properties->package_locale_dir);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);

  /* To have some real random behaviour */
  srand (time (NULL));

  /* Default difficulty filter: non specified */
  popt_difficulty_filter = -1;

  gtk_init (&argc, &argv);

  pctx = poptGetContext (PACKAGE, argc, (const char **)argv, options, 0);

  /* Argument parsing */
  popt_option = poptGetNextOpt (pctx);

  // Set the default gcompris cursor
  properties->defaultcursor = GCOMPRIS_DEFAULT_CURSOR;

  /* Save the default locale */
#if defined WIN32
  gc_user_default_locale = g_win32_getlocale();
  // Set the user's choice locale
  if(properties->locale[0]=='\0') {
    gc_locale_set(gc_user_default_locale);
  } else {
    gc_locale_set(properties->locale);
  }
#else
  gc_user_default_locale = g_strdup(setlocale(LC_MESSAGES, NULL));
  // Set the user's choice locale
  gc_locale_set(properties->locale);
#endif

  /* Set the default message handler, it avoids message with option -D */
  g_log_set_handler (NULL, G_LOG_LEVEL_MESSAGE | G_LOG_LEVEL_WARNING | G_LOG_LEVEL_DEBUG | G_LOG_FLAG_FATAL
                   | G_LOG_FLAG_RECURSION, gc_log_handler, NULL);

  /*------------------------------------------------------------*/
  if (popt_version)
    {
      printf (_("GCompris\nVersion: %s\nLicence: GPL\n"
              "More info at http://gcompris.net\n"),
             VERSION);
      exit (0);
    }

  if (popt_debug)
    {
      gc_debug = TRUE;
    }

  if (popt_fullscreen)
    {
      properties->fullscreen = TRUE;
    }

  if (popt_noxf86vm)
    {
      properties->noxf86vm = TRUE;
    }

  if (popt_window)
    {
      properties->fullscreen = FALSE;
    }

  if (popt_mute)
    {
      g_warning("Sound disabled");
      properties->music = FALSE;
      properties->fx = FALSE;
    }

  if (popt_sound)
    {
      g_warning("Sound enabled");
      properties->music = TRUE;
      properties->fx = TRUE;
    }

  if (popt_cursor)
    {
      g_warning("Default gnome cursor enabled");
      properties->defaultcursor = GDK_LEFT_PTR;
    }
#ifdef WIN32
  properties->defaultcursor = GDK_LEFT_PTR;
#endif

  if (popt_aalias)
    {
      g_warning("Slower Antialiased canvas used");
      antialiased = TRUE;
    }

  if (popt_experimental)
    {
      g_warning("Experimental boards allowed");
      properties->experimental  = TRUE;
    }

  if (popt_no_quit)
    {
      g_warning("Disable quit button");
      properties->disable_quit = TRUE;
    }

  if (popt_no_config)
    {
      g_warning("Disable config button");
      properties->disable_config = TRUE;
    }

  if (popt_difficulty_filter>=0)
    {
      /* This option provide less capacity than the GUI since we cannot set the filter_style */
      g_warning("Display only activities of level %d", popt_difficulty_filter);
      properties->difficulty_filter = popt_difficulty_filter;
      properties->filter_style      = GCOMPRIS_FILTER_EQUAL;
    }

  if (popt_local_activity){
    g_warning("Adding local activies from %s.", popt_local_activity);
    properties->local_directory = g_strdup(popt_local_activity);
  }

  if (popt_root_menu){
    if (strcmp(popt_root_menu,"list")==0){
      /* check the list of possible values for -l, then exit */
      printf(_("Use -l to access an activity directly.\n"));
      printf(_("The list of available activities is :\n"));
      properties->root_menu = "/";

      gc_db_init();

      gc_menu_load();

      GList *list = NULL;
      GList *menulist = NULL;
      GList *menu_todo = NULL;
      int board_count = 0;

      menu_todo = g_list_append(menu_todo,g_strdup("/"));

      while ( menu_todo != NULL) {
       menulist = gc_menu_getlist(menu_todo->data);
       g_free(menu_todo->data);
       menu_todo = menu_todo->next;

       for(list = menulist; list != NULL; list = list->next) {
         GcomprisBoard *board = list->data;

         if (board){
           if (strcmp(board->type,"menu")==0)
             menu_todo = g_list_prepend(menu_todo, g_strdup_printf("%s/%s",board->section, board->name));
           else
             board_count++;

           printf("%s/%s : %s (%s) \n", board->section, board->name, board->title, board->description );
         }
       }
      }
      /* FIXME: Need to translate */
      printf("Number of activities: %d\n", board_count);

      exit(0);
    }
    else {
    g_warning("Using menu %s as root.", popt_root_menu);
    properties->root_menu = g_strdup(popt_root_menu);
    properties->menu_position = g_strdup(popt_root_menu);
    }
  }

  if (popt_users_dir){
    if ((!g_file_test(popt_users_dir, G_FILE_TEST_IS_DIR)) ||
       (access(popt_users_dir, popt_administration? R_OK : W_OK ) == -1)){
       g_warning("%s does not exists or is not %s ", popt_users_dir,
                popt_administration? "readable" : "writable");
       exit(0);
    } else {
      g_warning("Using %s as users directory.", popt_users_dir);
      properties->users_dir = g_strdup(popt_users_dir);
    }
  }

  if (popt_shared_dir){
    if ((!g_file_test(popt_shared_dir, G_FILE_TEST_IS_DIR)) ||
       (access(popt_shared_dir, popt_administration? W_OK : R_OK ) == -1)){
      g_warning("%s does not exists or is not %s", popt_shared_dir,
              popt_administration? "writable" : "readable"     );
      exit(0);
    }
    else {
      g_warning("Using %s as shared directory.", popt_shared_dir);
      properties->shared_dir = g_strdup(popt_shared_dir);
    }
  }

  /* shared_dir initialised, now we can set the default */
  g_free(properties->database);
  properties->database = gc_prop_default_database_name_get ( properties->shared_dir );
  g_warning( "Infos:\n   Shared dir '%s'\n   Users dir '%s'\n   Database '%s'\n",
            properties->shared_dir,
            properties->users_dir,
            properties->database);

  if (popt_database)
    {
      properties->database = g_strdup(popt_database);

      if (g_file_test(properties->database, G_FILE_TEST_EXISTS))
       {
         if (access(properties->database, R_OK)==-1)
           {
             g_warning("%s exists but is not readable or writable", properties->database);
             exit(0);
           }
         else
           {
             g_warning("Using %s as database", properties->database);
           }
       }
    }

  if (popt_create_db)
    {
      gchar *dirname = g_path_get_dirname (properties->database);
      if (access(dirname, W_OK)==-1)
       {
         g_warning("Cannot create %s : %s is not writable !", properties->database, dirname);
         exit (0);
       }
      /* We really want to recreate it, erase the old one */
      g_warning("Removing %s database.", properties->database);
      unlink(properties->database);
    }

  if (popt_administration){
    if (popt_database){
      if (access(popt_database,R_OK|W_OK)==-1){
       g_warning("%s exists but is not writable", popt_database);
       exit(0);
      }
    }
    g_warning("Running in administration mode");
    properties->administration = TRUE;
    g_warning("Background music disabled");
    properties->music = FALSE;
    g_warning("Fullscreen is disabled");
    properties->fullscreen = FALSE;
  }

  if (popt_reread_menu){
    g_warning("Rebuild db from xml files");
    if (access(properties->database, W_OK)==-1)
      g_warning("Cannot reread menu when database is read-only !");
    else
      properties->reread_menu = TRUE;
  }

  if (popt_server){
#ifdef USE_GNET
      properties->server = g_strdup(popt_server);
#else
      printf("The --server option cannot be used because GCompris has been compiled without network support!");
      exit(1);
#endif
  }

  if(popt_web_only) {
    g_free(properties->package_data_dir);
    properties->package_data_dir = g_strdup("");

    g_free(properties->system_icon_dir);
    properties->system_icon_dir = g_strdup("");
  }

  if (popt_server){
      properties->cache_dir = g_strdup(popt_cache_dir);
  }

  /*
   * Database init MUST BE after properties
   * And after a possible alternate database as been provided
   *
   */
  gc_db_init();

  /* An alternate profile is requested, check it does exists */
  if (popt_profile){
    properties->profile = gc_db_profile_from_name_get(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 = gc_db_profiles_list_get();

    printf(_("The list of available profiles is:\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);
  }

  /* An alternate profile is requested, check it does exists */
  if (popt_display_resource){
    properties->display_resource = TRUE;
    properties->reread_menu = TRUE;
    printf("Resources for selected activities (as selected by gcompris --administration):\n");
    gc_menu_load();
    exit(0);
  }

  poptFreeContext(pctx);
  /*------------------------------------------------------------*/

  if(properties->music || properties->fx)
    gc_sound_init();

  /* Gdk-Pixbuf */
  gdk_rgb_init();

  /* Cache init */
  gc_cache_init(-1);

  /* networking init */
  gc_net_init();

  setup_window ();

  gtk_widget_show_all (window);

  if (properties->music)
    gc_sound_play_ogg("music/intro.ogg", "sounds/$LOCALE/misc/welcome.ogg", NULL);
  else
    gc_sound_play_ogg("sounds/$LOCALE/misc/welcome.ogg", NULL);

  gtk_main ();
  return 0;
}

Here is the call graph for this function:

Here is the caller graph for this function:

int main ( int  argc,
char *  argv[] 
)

Definition at line 30 of file main.c.

{
  gc_init(argc, argv);

  return(0);
}

Here is the call graph for this function: