Back to index

gcompris  8.2.2
Defines | Functions | Variables
gcompris.c File Reference
#include <signal.h>
#include <popt.h>
#include <sys/types.h>
#include <sys/stat.h>
#include <unistd.h>
#include <time.h>
#include <string.h>
#include "gcompris.h"
#include "gc_core.h"
#include "gcompris_config.h"
#include "about.h"
#include <locale.h>
#include "cursor.h"
#include "binreloc.h"

Go to the source code of this file.

Defines

#define display_activation_dialog()

Functions

static void quit_cb (GtkWidget *widget, gpointer data)
static void map_cb (GtkWidget *widget, gpointer data)
static gint board_widget_key_press_callback (GtkWidget *widget, GdkEventKey *event, gpointer client_data)
void gc_terminate (int signum)
static void gc_close_all_dialog ()
GnomeCanvas * gc_get_canvas ()
 Return the main canvas we run in.
GtkWidget * gc_get_window ()
void gc_ignore_next_focus_out ()
GnomeCanvasItem * gc_set_background (GnomeCanvasGroup *parent, gchar *file)
static void init_background ()
void gc_cursor_set (guint gdk_cursor_type)
static void setup_window ()
void gc_board_end ()
 Call me to end an activity.
void gc_fullscreen_set (gboolean state)
 toggle full screen mode
int gc_canvas_item_grab (GnomeCanvasItem *item, unsigned int event_mask, GdkCursor *cursor, guint32 etime)
void gc_canvas_item_ungrab (GnomeCanvasItem *item, guint32 etime)
static void cleanup ()
void gc_exit ()
 miscelaneous functions
static void load_properties ()
GcomprisPropertiesgc_prop_get ()
gchar * gc_db_get_filename ()
const gchar * gc_locale_get ()
char * gc_locale_get_user_default ()
void gc_locale_set (gchar *locale)
void gc_log_handler (const gchar *log_domain, GLogLevelFlags log_level, const gchar *message, gpointer user_data)
int gc_init (int argc, char *argv[])

Variables

static GtkWidget * window
static GnomeCanvas * canvas
static GnomeCanvas * canvas_bar
static GnomeCanvas * canvas_bg
static GcomprisPropertiesproperties = NULL
static gboolean antialiased = FALSE
static gboolean is_mapped = FALSE
static GnomeCanvasItem * backgroundimg = NULL
static gchar * gc_locale = NULL
static gchar * gc_user_default_locale = NULL
static gboolean gc_debug = FALSE
static int popt_fullscreen = FALSE
static int popt_window = FALSE
static int popt_sound = FALSE
static int popt_mute = FALSE
static int popt_cursor = FALSE
static int popt_version = FALSE
static int popt_aalias = FALSE
static int popt_difficulty_filter = FALSE
static int popt_debug = FALSE
static int popt_noxf86vm = FALSE
static char * popt_root_menu = NULL
static char * popt_local_activity = NULL
static int popt_administration = FALSE
static char * popt_database = NULL
static char * popt_logs_database = NULL
static int popt_create_db = FALSE
static int popt_reread_menu = FALSE
static char * popt_profile = NULL
static int * popt_profile_list = FALSE
static char * popt_shared_dir = NULL
static char * popt_users_dir = NULL
static int popt_experimental = FALSE
static int popt_no_quit = FALSE
static int popt_no_config = FALSE
static int popt_display_resource = FALSE
static char * popt_server = NULL
static int * popt_web_only = NULL
static char * popt_cache_dir = NULL
static struct poptOption []

Define Documentation

Definition at line 72 of file gcompris.c.


Function Documentation

static gint board_widget_key_press_callback ( GtkWidget *  widget,
GdkEventKey *  event,
gpointer  client_data 
) [static]

Definition at line 256 of file gcompris.c.

{
  int kv = event->keyval;

  if(event->state & GDK_CONTROL_MASK && ((event->keyval == GDK_r)
                                    || (event->keyval == GDK_R))) {
    g_message("Refreshing the canvas\n");
    gnome_canvas_update_now(canvas);
    return TRUE;
  }

  if(event->state & GDK_CONTROL_MASK && ((event->keyval == GDK_q)
                                    || (event->keyval == GDK_Q))) {
    gc_exit();
    return TRUE;
  }

  switch (event->keyval)
    {
    case GDK_Escape:
      gc_close_all_dialog();

      if (gc_board_get_current()->previous_board != NULL)
       gc_board_stop();
      return TRUE;
    case GDK_F5:
      g_message("Refreshing the canvas\n");
      gnome_canvas_update_now(canvas);
      return TRUE;

    case GDK_KP_Multiply:
      break;
    case GDK_KP_0:
    case GDK_KP_Insert:
      event->keyval=GDK_0;
      break;
    case GDK_KP_1:
    case GDK_KP_End:
      event->keyval=GDK_1;
      break;
    case GDK_KP_2:
    case GDK_KP_Down:
      event->keyval=GDK_2;
      break;
    case GDK_KP_3:
    case GDK_KP_Page_Down:
      event->keyval=GDK_3;
      break;
    case GDK_KP_4:
    case GDK_KP_Left:
      event->keyval=GDK_4;
      break;
    case GDK_KP_5:
    case GDK_KP_Begin:
      event->keyval=GDK_5;
      break;
    case GDK_KP_6:
    case GDK_KP_Right:
      event->keyval=GDK_6;
      break;
    case GDK_KP_7:
    case GDK_KP_Home:
      event->keyval=GDK_7;
      break;
    case GDK_KP_8:
    case GDK_KP_Up:
      event->keyval=GDK_8;
      break;
    case GDK_KP_9:
    case GDK_KP_Page_Up:
      event->keyval=GDK_9;
      break;
    default:
      break;
    }

  /* pass through the IM context */
  if (gc_board_get_current() && (!gc_board_get_current()->disable_im_context))
    {
      if (gtk_im_context_filter_keypress (properties->context, event))
       {
         g_warning("%d key is handled by context", kv);
         return TRUE;
       }
    }

  g_warning("%d key is NOT handled by context", kv);
  /* If the board needs to receive key pressed */
  /* NOTE: If a board receives key press, it must bind the ENTER Keys to OK
   *       whenever possible
   */
  if (gc_board_get_current_board_plugin()!=NULL && gc_board_get_current_board_plugin()->key_press)
    {
      return(gc_board_get_current_board_plugin()->key_press (event->keyval, NULL, NULL));
    }
  else if (gc_board_get_current_board_plugin()!=NULL && gc_board_get_current_board_plugin()->ok &&
          (event->keyval == GDK_KP_Enter ||
           event->keyval == GDK_Return   ||
           event->keyval == GDK_KP_Space))
    {
      /* Else we send the OK signal. */
      gc_board_get_current_board_plugin()->ok ();
      return TRUE;
    }

  /* Event not handled; try parent item */
  return FALSE;
};

Here is the call graph for this function:

Here is the caller graph for this function:

static void cleanup ( ) [static]

Definition at line 1019 of file gcompris.c.

{
  /* Do not loopback in exit */
  signal(SIGINT,  NULL);
  signal(SIGSEGV, NULL);

  gc_board_stop();
  gc_db_exit();
  gc_fullscreen_set(FALSE);
  gc_menu_destroy();
  gc_prop_destroy(gc_prop_get());
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gc_board_end ( void  )

Call me to end an activity.

Definition at line 938 of file gcompris.c.

{
  if (gc_board_get_current()->previous_board) {
    /* Run the previous board */
    gc_board_play(gc_board_get_current()->previous_board);
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

int gc_canvas_item_grab ( GnomeCanvasItem *  item,
unsigned int  event_mask,
GdkCursor *  cursor,
guint32  etime 
)

Definition at line 985 of file gcompris.c.

{
  int retval;

  retval = gnome_canvas_item_grab(item, event_mask, cursor, etime);
  if (retval != GDK_GRAB_SUCCESS)
    return retval;

#ifdef XF86_VIDMODE
  /* When fullscreen override mouse grab with our own which
     confines the cursor to our fullscreen window */
  if (XF86VidModeData.fullscreen_active)
    if (gdk_pointer_grab(item->canvas->layout.bin_window, FALSE, event_mask,
          window->window, cursor, etime+1) != GDK_GRAB_SUCCESS)
      g_warning("Pointer grab failed");
#endif

  return retval;
}

Here is the caller graph for this function:

void gc_canvas_item_ungrab ( GnomeCanvasItem *  item,
guint32  etime 
)

Definition at line 1006 of file gcompris.c.

{
  gnome_canvas_item_ungrab(item, etime);
#ifdef XF86_VIDMODE
  /* When fullscreen restore the normal mouse grab which avoids
     scrolling the virtual desktop */
  if (XF86VidModeData.fullscreen_active)
    if (gdk_pointer_grab(window->window, TRUE, 0, window->window, NULL,
          etime+1) != GDK_GRAB_SUCCESS)
      g_warning("Pointer grab failed");
#endif
}

Here is the caller graph for this function:

static void gc_close_all_dialog ( ) [static]

Definition at line 246 of file gcompris.c.

Here is the call graph for this function:

Here is the caller graph for this function:

void gc_cursor_set ( guint  gdk_cursor_type)

Definition at line 531 of file gcompris.c.

{
  GdkCursor *cursor;

  // Little hack to force gcompris to use the default cursor
  if(gdk_cursor_type==GCOMPRIS_DEFAULT_CURSOR)
    gdk_cursor_type=properties->defaultcursor;

  // I suppose there is less than GCOMPRIS_FIRST_CUSTOM_CURSOR cursors defined in gdkcursors.h !
  if (gdk_cursor_type < GCOMPRIS_FIRST_CUSTOM_CURSOR) {
    cursor = gdk_cursor_new(gdk_cursor_type);
    gdk_window_set_cursor (window->window, cursor);
    gdk_cursor_destroy(cursor);
  } else { // we use a custom cursor
    GdkColor fg, bg;
    //    static const gchar * cursor;
    static const gchar ** bits;

    gdk_color_parse("rgb:FFFF/FFFF/FFFF",&fg);
    gdk_color_parse("rgb:FFFF/3FFF/0000",&bg);

    gdk_color_parse("black",&fg);
    gdk_color_parse("red",&bg);

    switch (gdk_cursor_type) {
    case GCOMPRIS_BIG_RED_ARROW_CURSOR :
      bits = big_red_arrow_cursor_bits;
      break;
    case GCOMPRIS_BIRD_CURSOR :
      bits = bird_cursor_bits;
      break;
    case GCOMPRIS_LINE_CURSOR :
      bits = big_red_line_cursor_bits;
      break;
    case GCOMPRIS_RECT_CURSOR :
      bits = big_red_rectangle_cursor_bits;
      break;
    case GCOMPRIS_FILLRECT_CURSOR :
      bits = big_red_filledrectangle_cursor_bits;
      break;
    case GCOMPRIS_CIRCLE_CURSOR :
      bits = big_red_circle_cursor_bits;
      break;
    case GCOMPRIS_FILLCIRCLE_CURSOR :
      bits = big_red_filledcircle_cursor_bits;
      break;
    case GCOMPRIS_FILL_CURSOR :
      bits = big_red_fill_cursor_bits;
      break;
    case GCOMPRIS_DEL_CURSOR :
      bits = big_red_del_cursor_bits;
      break;
    case GCOMPRIS_SELECT_CURSOR :
      bits = big_red_select_cursor_bits;
      break;
    default : bits = big_red_arrow_cursor_bits;
    }

    cursor = gdk_cursor_new_from_data(bits, 40 , 40, &fg, &bg, 0, 0);
    if(cursor)
      {
       gdk_window_set_cursor(window->window, cursor);
       gdk_cursor_unref(cursor);
      }
  }
}

Here is the call graph for this function:

Here is the caller graph for this function:

gchar* gc_db_get_filename ( )

Definition at line 1144 of file gcompris.c.

{
  g_assert(properties!=NULL);

  return (properties->database);
}

Here is the caller graph for this function:

void gc_exit ( )

miscelaneous functions

Definition at line 1032 of file gcompris.c.

{
  g_signal_emit_by_name(G_OBJECT(window), "delete_event");
}

Here is the caller graph for this function:

void gc_fullscreen_set ( gboolean  state)

toggle full screen mode

Definition at line 950 of file gcompris.c.

{
#ifdef XF86_VIDMODE
  xf86_vidmode_set_fullscreen(state);
#endif
  if(state)
    {
      gdk_window_set_decorations (window->window, 0);
      gdk_window_set_functions (window->window, 0);
#ifdef XF86_VIDMODE
      if(properties->noxf86vm)
#endif
       gtk_window_fullscreen (GTK_WINDOW(window));
      gtk_widget_set_uposition (window, 0, 0);
    }
  else
    {
      /* The hide must be done at least for KDE */
      if (is_mapped)
        gtk_widget_hide (window);
      gdk_window_set_decorations (window->window, GDK_DECOR_ALL);
      if (is_mapped)
        gtk_widget_show (window);
      gdk_window_set_functions (window->window, GDK_FUNC_ALL);
#ifdef XF86_VIDMODE
      if(properties->noxf86vm)
#endif
       gtk_window_unfullscreen (GTK_WINDOW(window));
      gtk_widget_set_uposition (window, 0, 0);
    }

}

Here is the caller graph for this function:

GnomeCanvas* gc_get_canvas ( void  )

Return the main canvas we run in.

Definition at line 370 of file gcompris.c.

{
  return canvas;
}

Here is the caller graph for this function:

GtkWidget* gc_get_window ( void  )

Definition at line 375 of file gcompris.c.

{
  return window;
}

Here is the caller graph for this function:

void gc_ignore_next_focus_out ( void  )

Definition at line 380 of file gcompris.c.

{
#ifdef XF86_VIDMODE
  XF86VidModeData.ignore_focus_out++;
#endif
}

Here is the caller graph for this function:

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:

const gchar* gc_locale_get ( void  )

Definition at line 1155 of file gcompris.c.

{
  const gchar *locale;

  /* First check locale got overrided by the user */
  if(gc_locale != NULL)
    return(gc_locale);

  locale = g_getenv("LC_ALL");
  if(locale == NULL)
    locale = g_getenv("LC_MESSAGES");
  if(locale == NULL)
    locale = g_getenv("LANG");

  if(locale!=NULL)
    return(locale);

  return("en_US.UTF-8");
}

Here is the caller graph for this function:

char* gc_locale_get_user_default ( void  )

Definition at line 1180 of file gcompris.c.

Here is the caller graph for this function:

void gc_locale_set ( gchar *  locale)

Definition at line 1190 of file gcompris.c.

{

  if(!locale)
    return;

  g_message("gc_locale_set '%s'\n", locale);
  if(gc_locale != NULL)
    g_free(gc_locale);

#if defined WIN32
  /* On windows, it always works */
  gc_locale = g_strdup(locale);
  setlocale(LC_MESSAGES, locale);
  setlocale(LC_ALL, locale);
#else
  gc_locale = g_strdup(setlocale(LC_MESSAGES, locale));
  if (!gc_locale)
    gc_locale = g_strdup(locale);
#endif

  if(gc_locale!=NULL && strcmp(locale, gc_locale))
    g_warning("Requested locale '%s' got '%s'", locale, gc_locale);

  if(gc_locale==NULL)
    g_warning("Failed to set requested locale %s got %s", locale, gc_locale);

  /* Override the env locale to what the user requested */
  /* This makes gettext to give us the new locale text  */
  gc_setenv ("LC_ALL", gc_locale_get());
  gc_setenv ("LC_MESSAGES", gc_locale_get());
  gc_setenv ("LANGUAGE", gc_locale_get());
  gc_setenv ("LANG", gc_locale_get());

  /* This does update gettext translation uppon next gettext call */
  /* Call for localization startup */
  bindtextdomain (GETTEXT_PACKAGE, properties->package_locale_dir);
  bind_textdomain_codeset (GETTEXT_PACKAGE, "UTF-8");
  textdomain (GETTEXT_PACKAGE);

#ifndef WIN32
  /* Make change known.  */
  {
    extern int  _nl_msg_cat_cntr;
    ++_nl_msg_cat_cntr;
  }
#endif

}

Here is the call graph for this function:

Here is the caller graph for this function:

void gc_log_handler ( const gchar *  log_domain,
GLogLevelFlags  log_level,
const gchar *  message,
gpointer  user_data 
)

Definition at line 1240 of file gcompris.c.

                                            {
  if(gc_debug)
    g_printerr ("%s: %s\n\n", "gcompris", message);
}

Here is the caller graph for this function:

Definition at line 1136 of file gcompris.c.

{
  return (properties);
}
GnomeCanvasItem* gc_set_background ( GnomeCanvasGroup *  parent,
gchar *  file 
)

Definition at line 387 of file gcompris.c.

{
  GdkPixbuf *background_pixmap = NULL;

  background_pixmap = gc_pixmap_load (file);

  if(backgroundimg)
      gnome_canvas_item_set (backgroundimg,
                          "pixbuf", background_pixmap,
                          NULL);
  else
    backgroundimg=gnome_canvas_item_new (parent,
                                    gnome_canvas_pixbuf_get_type (),
                                    "pixbuf", background_pixmap,
                                    "x", 0.0,
                                    "y", 0.0,
                                    "width", (double) BOARDWIDTH,
                                    "height", (double) BOARDHEIGHT,
                                    NULL);
  gnome_canvas_item_lower_to_bottom(backgroundimg);

  gdk_pixbuf_unref(background_pixmap);

  return (backgroundimg);
}

Here is the call graph for this function:

Here is the caller graph for this function:

void gc_terminate ( int  signum)

Definition at line 1071 of file gcompris.c.

{

  g_warning("gcompris got the %d signal, starting exit procedure", signum);

  gc_exit();

}

Here is the call graph for this function:

Here is the caller graph for this function:

static void init_background ( ) [static]

Definition at line 413 of file gcompris.c.

{
  double xratio, yratio, max;
  gint screen_height, screen_width;
  GtkWidget *vbox;

#ifdef XF86_VIDMODE
  xf86_vidmode_init();

  if(properties->fullscreen && !properties->noxf86vm) {
    screen_height = XF86VidModeData.fs_mode.vdisplay;
    screen_width  = XF86VidModeData.fs_mode.hdisplay;
  }
  else
#endif
  {
    screen_height = gdk_screen_height();
    screen_width  = gdk_screen_width();
  }

  yratio=screen_height/(float)(BOARDHEIGHT+BARHEIGHT);
  xratio=screen_width/(float)BOARDWIDTH;
  g_message("The screen_width=%f screen_height=%f\n",
           (double)screen_width, (double)screen_height);
  g_message("The xratio=%f yratio=%f\n", xratio, yratio);

  yratio=xratio=MIN(xratio, yratio);

  /* Depending on user preference, set the max ratio */
  switch(properties->screensize)
    {
    case 0: max = 0.8;
      break;
    case 1: max = 1;
      break;
    case 2: max = 1.28;
      break;
    default: max = 1;
      break;
    }
  xratio=MIN(max, xratio);

  g_message("Calculated x ratio xratio=%f\n", xratio);


  /* Background area if ratio above 1 */
  if(properties->fullscreen)
    {

      /* WARNING : I add 30 here for windows. don't know why it's needed. Doesn't hurt the Linux version */
      gnome_canvas_set_scroll_region (canvas_bg,
                                  0, 0,
                                  screen_width,
                                  screen_height + 30);

      gtk_widget_set_usize (GTK_WIDGET(canvas_bg), screen_width, screen_height);

      /* Create a black box for the background */
      gnome_canvas_item_new (gnome_canvas_root(canvas_bg),
                          gnome_canvas_rect_get_type (),
                          "x1", (double) 0,
                          "y1", (double) 0,
                          "x2", (double) screen_width,
                          "y2", (double) screen_height + 30,
                          "fill_color", "black",
                          "outline_color", "black",
                          "width_units", (double)0,
                          NULL);

    }

  /* Create a vertical box in which I put first the play board area, then the button bar */
  vbox = gtk_vbox_new (FALSE, 0);
  if(!properties->fullscreen)
    gtk_container_add (GTK_CONTAINER(window), GTK_WIDGET(vbox));

  gtk_widget_show (GTK_WIDGET(vbox));
  gtk_widget_show (GTK_WIDGET(canvas));
  gtk_widget_show (GTK_WIDGET(canvas_bar));

  gtk_box_pack_start (GTK_BOX(vbox), GTK_WIDGET(canvas), TRUE, TRUE, 0);
  gtk_box_pack_start (GTK_BOX(vbox), GTK_WIDGET(canvas_bar), TRUE, TRUE, 0);

  if(properties->fullscreen)
    {
      gnome_canvas_item_new (gnome_canvas_root(canvas_bg),
                          gnome_canvas_widget_get_type (),
                          "widget", vbox,
                          "x", (double) (screen_width-
                                       BOARDWIDTH*xratio)/2,
                          "y", (double) (screen_height-
                                       BOARDHEIGHT*xratio-BARHEIGHT*xratio)/2,
                          "width",  (double)BOARDWIDTH*xratio,
                          "height", (double)BOARDHEIGHT*xratio+BARHEIGHT*xratio,
                          "size_pixels", TRUE,
                          NULL);
    }

  /* Create the drawing area */
  gnome_canvas_set_pixels_per_unit (canvas, xratio);

  gnome_canvas_set_scroll_region (canvas,
                              0, 0,
                              BOARDWIDTH,
                              BOARDHEIGHT);

  gtk_widget_set_usize (GTK_WIDGET(canvas), BOARDWIDTH*xratio, BOARDHEIGHT*xratio);

  /* Create the spot for the bar */
  gnome_canvas_set_pixels_per_unit (canvas_bar, xratio);
  gnome_canvas_set_scroll_region (canvas_bar,
                              0, 0,
                              BOARDWIDTH,
                              BARHEIGHT);
  gtk_widget_set_usize (GTK_WIDGET(canvas_bar),  BOARDWIDTH*xratio,  BARHEIGHT*xratio);

}

Here is the caller graph for this function:

static void load_properties ( ) [static]

Definition at line 1080 of file gcompris.c.

{
  gchar *prefix_dir;
  gchar *tmpstr;

  properties = gc_prop_new ();

  /* Initialize the binary relocation API
   *  http://autopackage.org/docs/binreloc/
   */
  if(gbr_init (NULL))
    g_warning("Binary relocation enabled");
  else
    g_warning("Binary relocation disabled");

  prefix_dir = gbr_find_prefix(NULL);

  /* Check if we are in the source code (developper usage) */
  tmpstr = g_strconcat(prefix_dir, "/gcompris.c", NULL);
  if(g_file_test(tmpstr, G_FILE_TEST_EXISTS))
    {
      /* Set all directory to get data from the source code we are run in */
      properties->package_data_dir = g_strconcat(prefix_dir, "/../../boards", NULL);

      /* In source code, locale mo files are not generated, use the installed one */
      properties->package_locale_dir = g_strdup(PACKAGE_LOCALE_DIR);

      properties->package_plugin_dir = g_strconcat(prefix_dir, "/../boards/.libs", NULL);
      properties->package_python_plugin_dir = g_strconcat(prefix_dir, "/../boards/python", NULL);
      properties->system_icon_dir = g_strconcat(prefix_dir, "/../..", NULL);
    }
  else
    {
      gchar *pkg_data_dir = gbr_find_data_dir(PACKAGE_DATA_DIR);
      gchar *pkg_clib_dir = gbr_find_lib_dir(PACKAGE_CLIB_DIR);

      properties->package_data_dir = g_strconcat(pkg_data_dir, "/gcompris/boards", NULL);
      properties->package_locale_dir = gbr_find_locale_dir(PACKAGE_LOCALE_DIR);
      properties->package_plugin_dir = g_strconcat(pkg_clib_dir, "/gcompris", NULL);
      properties->package_python_plugin_dir = g_strconcat(pkg_data_dir, "/gcompris/python", NULL);
      properties->system_icon_dir = g_strconcat(pkg_data_dir, "/pixmaps", NULL);
      g_free(pkg_data_dir);
      g_free(pkg_clib_dir);
    }
  g_free(tmpstr);
  g_free(prefix_dir);


  /* Display the directory value we have */
  printf("package_data_dir         = %s\n", properties->package_data_dir);
  printf("package_locale_dir       = %s\n", properties->package_locale_dir);
  printf("package_plugin_dir       = %s\n", properties->package_plugin_dir);
  printf("package_python_plugin_dir= %s\n", properties->package_python_plugin_dir);

}

Here is the call graph for this function:

Here is the caller graph for this function:

static void map_cb ( GtkWidget *  widget,
gpointer  data 
) [static]

Definition at line 1057 of file gcompris.c.

{
  if(is_mapped == FALSE)
    {
      gc_fullscreen_set(properties->fullscreen);
      is_mapped = TRUE;
    }
  g_warning("gcompris window is now mapped");
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void quit_cb ( GtkWidget *  widget,
gpointer  data 
) [static]

Definition at line 1037 of file gcompris.c.

{

#ifdef DMALLOC
  dmalloc_shutdown();
#endif
  cleanup();
  gtk_main_quit();

  /*
   * Very important or GCompris crashes on exit when closed from the dialog
   * It's like if code in the dialog callback continue after the gtk_main_quit is done
   */
  exit(0);
}

Here is the call graph for this function:

Here is the caller graph for this function:

static void setup_window ( ) [static]

Definition at line 598 of file gcompris.c.

{
  GcomprisBoard *board_to_start;
  GdkPixbuf     *icon_pixbuf;
  gchar         *icon_file;

  window = gtk_window_new (GTK_WINDOW_TOPLEVEL);

  /*
   * Set an icon for gcompris
   * ------------------------
   */
  icon_file = g_strconcat(properties->system_icon_dir, "/gcompris.png", NULL);
  if (!g_file_test (icon_file, G_FILE_TEST_EXISTS)) {
      /* Now check if this file is on the net */
      icon_file = gc_net_get_url_from_file("gcompris.png", NULL);
  }

  if(!icon_file)
      g_warning ("Couldn't find file %s !", icon_file);

  icon_pixbuf = gc_net_load_pixmap(icon_file);
  if (!icon_pixbuf)
    {
      g_warning ("Failed to load pixbuf file: %s\n",
               icon_file);
    }
  g_free(icon_file);

  if (icon_pixbuf)
    {
      gtk_window_set_icon (GTK_WINDOW (window), icon_pixbuf);
      gdk_pixbuf_unref (icon_pixbuf);
    }
  gtk_window_set_title(GTK_WINDOW (window), "GCompris");

  /*
   * Set the main window
   * -------------------
   */

  gtk_window_set_policy (GTK_WINDOW (window), FALSE, FALSE, TRUE);
  gtk_window_set_default_size(GTK_WINDOW(window), 250, 350);
  gtk_window_set_wmclass(GTK_WINDOW(window), "gcompris", "GCompris");

  gtk_widget_realize (window);

  gtk_signal_connect (GTK_OBJECT (window), "delete_event",
                    GTK_SIGNAL_FUNC (quit_cb), NULL);

  gtk_signal_connect (GTK_OBJECT (window), "map_event",
                    GTK_SIGNAL_FUNC (map_cb), NULL);

#ifdef XF86_VIDMODE
  /* The Xf86VidMode code needs to accuratly now the window position,
     this is the only way to get it, and it needs to track the focus to
     enable/disable fullscreen on alt-tab */
  gtk_widget_add_events(GTK_WIDGET(window),
    GDK_STRUCTURE_MASK|GDK_FOCUS_CHANGE_MASK);
  gtk_signal_connect (GTK_OBJECT (window), "configure_event",
    GTK_SIGNAL_FUNC (xf86_window_configured), 0);
  gtk_signal_connect (GTK_OBJECT (window), "focus_in_event",
    GTK_SIGNAL_FUNC (xf86_focus_changed), 0);
  gtk_signal_connect (GTK_OBJECT (window), "focus_out_event",
    GTK_SIGNAL_FUNC (xf86_focus_changed), 0);
#endif

  /* For non anti alias canvas */
  gtk_widget_push_visual (gdk_rgb_get_visual ());
  gtk_widget_push_colormap (gdk_rgb_get_cmap ());

  // Set the cursor
  gc_cursor_set(GCOMPRIS_DEFAULT_CURSOR);

  /* For anti alias canvas */
  /*
  gtk_widget_push_visual(gdk_rgb_get_visual());
  gtk_widget_push_colormap(gdk_rgb_get_cmap());
  */

  if(antialiased)
    {
      /* For anti alias canvas */
       canvas     = GNOME_CANVAS(gnome_canvas_new_aa ());
       canvas_bar = GNOME_CANVAS(gnome_canvas_new_aa ());
       canvas_bg = GNOME_CANVAS(gnome_canvas_new_aa ());
    }
  else
    {
      /* For non anti alias canvas */
      canvas     = GNOME_CANVAS(gnome_canvas_new ());
      canvas_bar = GNOME_CANVAS(gnome_canvas_new ());
      canvas_bg  = GNOME_CANVAS(gnome_canvas_new ());
    }

  gtk_signal_connect_after (GTK_OBJECT (window), "key_press_event",
                         GTK_SIGNAL_FUNC (board_widget_key_press_callback), 0);
  gtk_signal_connect_after (GTK_OBJECT (canvas), "key_press_event",
                         GTK_SIGNAL_FUNC (board_widget_key_press_callback), 0);
  gtk_signal_connect_after (GTK_OBJECT (canvas_bar), "key_press_event",
                         GTK_SIGNAL_FUNC (board_widget_key_press_callback), 0);
  gtk_signal_connect_after (GTK_OBJECT (canvas_bg), "key_press_event",
                         GTK_SIGNAL_FUNC (board_widget_key_press_callback), 0);

  gc_im_init(window);


  if(properties->fullscreen)
    gtk_container_add (GTK_CONTAINER (window), GTK_WIDGET(canvas_bg));

  gtk_widget_pop_colormap ();
  gtk_widget_pop_visual ();


  gtk_widget_show (GTK_WIDGET(canvas_bg));

  gc_board_init();


  /* Load all the menu once */
  gc_menu_load();

  /* Load the mime type */
  gc_mime_type_load();

  /* Save the root_menu */
  properties->menu_board = gc_menu_section_get(properties->root_menu);

  /* By default, the menu will be started */
  board_to_start = properties->menu_board;

  /* Get and Run the root menu */
  if(properties->administration)
    {
      board_to_start = gc_menu_section_get("/administration/administration");
    }
  else
    {
      /* If we have a profile defined, run the login screen
       * (the login screen is a board that uppon login completion
       * starts the menu)
       */
      if(properties->profile && properties->profile->group_ids)
       {
         gboolean found = FALSE;

         GList *group_id;

         for (group_id = properties->profile->group_ids; group_id != NULL; group_id = group_id->next)
           if (g_list_length(gc_db_users_from_group_get( *((int *) group_id->data))) > 0){
             found = TRUE;
             break;
           }

         /* No profile start normally */
         if (found)
           board_to_start = gc_menu_section_get("/login/login");
         else {
           board_to_start = gc_menu_section_get(properties->root_menu);
           /* this will set user information to system one */
           gc_profile_set_current_user(NULL);
         }
       }
      else
       /* this will set user information to system one */
       gc_profile_set_current_user(NULL);
    }

    /* Run the bar */
  gc_bar_start(canvas_bar);

  init_background();

  if(!board_to_start) {
    gchar *tmpstr= g_strdup_printf("Couldn't find the board menu %s, or plugin execution error", properties->root_menu);
    gc_dialog(tmpstr, NULL);
    g_free(tmpstr);
  } else if(!gc_board_check_file(board_to_start)) {
    gchar *tmpstr= g_strdup_printf("Couldn't find the board menu, or plugin execution error");
    gc_dialog(tmpstr, NULL);
    g_free(tmpstr);
  } else {
    g_warning("Fine, we got the gcomprisBoardMenu, xml boards parsing went fine");
    gc_board_play(board_to_start);
  }

  display_activation_dialog();

}

Here is the call graph for this function:

Here is the caller graph for this function:


Variable Documentation

gboolean antialiased = FALSE [static]

Definition at line 77 of file gcompris.c.

GnomeCanvasItem* backgroundimg = NULL [static]

Definition at line 83 of file gcompris.c.

GnomeCanvas* canvas [static]

Definition at line 48 of file gcompris.c.

GnomeCanvas* canvas_bar [static]

Definition at line 49 of file gcompris.c.

GnomeCanvas* canvas_bg [static]

Definition at line 50 of file gcompris.c.

gboolean gc_debug = FALSE [static]

Definition at line 86 of file gcompris.c.

gchar* gc_locale = NULL [static]

Definition at line 84 of file gcompris.c.

gchar* gc_user_default_locale = NULL [static]

Definition at line 85 of file gcompris.c.

gboolean is_mapped = FALSE [static]

Definition at line 78 of file gcompris.c.

int popt_aalias = FALSE [static]

Definition at line 98 of file gcompris.c.

int popt_administration = FALSE [static]

Definition at line 104 of file gcompris.c.

char* popt_cache_dir = NULL [static]

Definition at line 119 of file gcompris.c.

int popt_create_db = FALSE [static]

Definition at line 107 of file gcompris.c.

int popt_cursor = FALSE [static]

Definition at line 96 of file gcompris.c.

char* popt_database = NULL [static]

Definition at line 105 of file gcompris.c.

int popt_debug = FALSE [static]

Definition at line 100 of file gcompris.c.

int popt_difficulty_filter = FALSE [static]

Definition at line 99 of file gcompris.c.

int popt_display_resource = FALSE [static]

Definition at line 116 of file gcompris.c.

int popt_experimental = FALSE [static]

Definition at line 113 of file gcompris.c.

int popt_fullscreen = FALSE [static]

Definition at line 92 of file gcompris.c.

char* popt_local_activity = NULL [static]

Definition at line 103 of file gcompris.c.

char* popt_logs_database = NULL [static]

Definition at line 106 of file gcompris.c.

int popt_mute = FALSE [static]

Definition at line 95 of file gcompris.c.

int popt_no_config = FALSE [static]

Definition at line 115 of file gcompris.c.

int popt_no_quit = FALSE [static]

Definition at line 114 of file gcompris.c.

int popt_noxf86vm = FALSE [static]

Definition at line 101 of file gcompris.c.

char* popt_profile = NULL [static]

Definition at line 109 of file gcompris.c.

int* popt_profile_list = FALSE [static]

Definition at line 110 of file gcompris.c.

int popt_reread_menu = FALSE [static]

Definition at line 108 of file gcompris.c.

char* popt_root_menu = NULL [static]

Definition at line 102 of file gcompris.c.

char* popt_server = NULL [static]

Definition at line 117 of file gcompris.c.

char* popt_shared_dir = NULL [static]

Definition at line 111 of file gcompris.c.

int popt_sound = FALSE [static]

Definition at line 94 of file gcompris.c.

char* popt_users_dir = NULL [static]

Definition at line 112 of file gcompris.c.

int popt_version = FALSE [static]

Definition at line 97 of file gcompris.c.

int* popt_web_only = NULL [static]

Definition at line 118 of file gcompris.c.

int popt_window = FALSE [static]

Definition at line 93 of file gcompris.c.

struct poptOption[] [static]

Definition at line 121 of file gcompris.c.

GcomprisProperties* properties = NULL [static]

Definition at line 76 of file gcompris.c.

GtkWidget* window [static]

Definition at line 47 of file gcompris.c.