config.c 24.8 KB
Newer Older
1 2
/* gcompris - config.c
 *
3
 * Time-stamp: <2006/08/15 03:53:37 bruno>
4
 *
5
 * Copyright (C) 2000-2003 Bruno Coudoin
6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25
 *
 *   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., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
 */

/**
 * Configuration of gcompris
 */

26 27
#include <string.h>

28 29
#include "gcompris.h"
#include "gcompris_config.h"
Bruno Coudoin's avatar
Bruno Coudoin committed
30
#include "locale.h"
31

32 33 34 35 36
#if defined _WIN32 || defined __WIN32__
# undef WIN32   /* avoid warning on mingw32 */
# define WIN32
#endif

37
static GnomeCanvasItem	*rootitem		= NULL;
38 39
static GnomeCanvasItem	*item_locale_text	= NULL;
static GnomeCanvasItem	*item_locale_flag	= NULL;
40
static GnomeCanvasItem	*item_bad_flag		= NULL;
41 42
static GnomeCanvasItem	*item_screen_text	= NULL;
static GnomeCanvasItem	*item_timer_text	= NULL;
Bruno Coudoin's avatar
Bruno Coudoin committed
43
static GnomeCanvasItem	*item_skin_text		= NULL;
44
static GnomeCanvasItem	*item_filter_text	= NULL;
45 46 47
static GdkPixbuf	*pixmap_checked		= NULL;
static GdkPixbuf	*pixmap_unchecked	= NULL;

48
static gchar		*current_locale		= NULL;
Bruno Coudoin's avatar
Bruno Coudoin committed
49 50
static GList		*skinlist		= NULL;
static guint		skin_index;
51 52 53 54 55

static GnomeCanvasGroup	*stars_group		= NULL;
static double           stars_group_x;
static double           stars_group_y;

Bruno Coudoin's avatar
Bruno Coudoin committed
56
#define Y_GAP	45
57

58 59
static gboolean is_displayed			= FALSE;

60 61
#define SOUNDLISTFILE PACKAGE

62
static gchar *linguas[] = {
63
  "",			N_("Your system default"),
Bruno Coudoin's avatar
Bruno Coudoin committed
64
  "am_ET.UTF-8", 	N_("Amharic"),
Bruno Coudoin's avatar
Bruno Coudoin committed
65
  "ar_AE.UTF-8", 	N_("Arabic"),
66
  "az_AZ.UTF-8", 	N_("Turkish (Azerbaijan)"),
67
  "bg_BG.UTF-8",	N_("Bulgarian"),
68
  "ca_ES.UTF-8",	N_("Catalan"),
69
  "cs_CZ.UTF-8",	N_("Czech Republic"),
70
  "da_DK.UTF-8", 	N_("Danish"),
71 72
  "de_DE.UTF-8", 	N_("German"),
  "el_GR.UTF-8", 	N_("Greek"),
73
  "en_CA.UTF-8",	N_("English (Canada)"),
74
  "en_GB.UTF-8",	N_("English (Great Britain)"),
75
  "es_ES.UTF-8", 	N_("Spanish"),
76
  "eu_ES.UTF-8",	N_("Basque"),
77 78
  "fi_FI.UTF-8", 	N_("Finnish"),
  "fr_FR.UTF-8", 	N_("French"),
79
  "ga_IE.UTF-8", 	N_("Irish (Gaelic)"),
80
  "he_IL.UTF-8",	N_("Hebrew"),
81 82 83
  "hi_IN.UTF-8",	N_("Hindi"),
  "gu_IN.UTF-8",	N_("Gujarati"),
  "pa_IN.UTF-8",	N_("Punjabi"),
84
  "hu_HU.UTF-8",	N_("Hungarian"),
85
  "hr_HR.UTF-8",	N_("Croatian"),
86
  "it_IT.UTF-8", 	N_("Italian"),
Yves Combe's avatar
Yves Combe committed
87
  "ka_GE.UTF-8",        N_("Georgian"),
88
  "lt_LT.UTF-8",	N_("Lithuanian"),
89 90
  "mk_MK.UTF-8",	N_("Macedonian"),
  "ml_IN.UTF-8",	N_("Malayalam"),
91
  "mr_IN.UTF-8",	N_("Marathi"),
92
  "ms_MY.UTF-8",	N_("Malay"),
Bruno Coudoin's avatar
Bruno Coudoin committed
93
  "ne_NP.UTF-8",	N_("Nepal"),
94
  "nl_NL.UTF-8",	N_("Dutch"),
95 96
  "nb_NO.UTF-8",	N_("Norwegian Bokmal"),
  "nn_NO.UTF-8",	N_("Norwegian Nynorsk"),
97
  "pl_PL.UTF-8",	N_("Polish"),
98
  "pt_PT.UTF-8",	N_("Portuguese"),
99
  "pt_BR.UTF-8",	N_("Portuguese (Brazil)"),
100 101
  "ro_RO.UTF-8",	N_("Romanian"),
  "ru_RU.UTF-8",	N_("Russian"),
102
  "rw_RW.UTF-8",	N_("Kinyarwanda"),
103
  "sk_SK.UTF-8",	N_("Slovak"),
104
  "sl_SI.UTF-8",	N_("Slovenian"),
105
  "sq_AL.UTF-8",	N_("Albanian"),
106 107
  "sr@Latn_YU.ISO-8859-2",	N_("Serbian (Latin)"),
  "sr_YU.UTF-8",	N_("Serbian"),
108
  "sv_FI.UTF-8",	N_("Swedish"),
109
  /*  "ta_IN.UTF-8",	N_("Tamil"), */
Bruno Coudoin's avatar
Bruno Coudoin committed
110
  "th_TH.UTF-8",	N_("Thai"),
Bruno Coudoin's avatar
Bruno Coudoin committed
111
  "tr_TR.UTF-8",	N_("Turkish"),
112
  "vi_VN.UTF-8",	N_("Vietnamese"),
113
  "wa_BE.UTF-8",	N_("Walloon"),
114
  "zh_CN.UTF-8",	N_("Chinese (Simplified)"),
115
  "zh_TW.UTF-8",        N_("Chinese (Traditional)"),
116 117 118
  NULL, NULL
};

119 120 121 122 123 124 125 126
static gchar *timername[] = {
  N_("No time limit"),
  N_("Slow timer"),
  N_("Normal timer"),
  N_("Fast timer")
};

static gchar *screenname[] = {
Bruno Coudoin's avatar
Bruno Coudoin committed
127
  "640x480",
128
  N_("800x600 (Default for gcompris)"),
Bruno Coudoin's avatar
Bruno Coudoin committed
129
  "1024x768",
130 131
};

132
static gchar *filtername[] = {
133
  N_("<i>Use Gcompris administration module\nto filter boards</i>")
134 135
};

136 137 138
static void set_locale_flag(gchar *locale);
static gchar *get_next_locale(gchar *locale);
static gchar *get_previous_locale(gchar *locale);
139 140 141
static gint   item_event_ok(GnomeCanvasItem *item, GdkEvent *event, gpointer data);
static void   display_previous_next(guint x_start, guint y_start, 
				    gchar *eventname_previous, gchar *eventname_next);
142 143 144 145 146 147 148 149 150 151 152 153


/*
 * Do all the bar display and register the events
 */
void gcompris_config_start ()
{
  GcomprisProperties	*properties = gcompris_get_properties();
  GdkPixbuf   *pixmap = NULL;
  gint y_start = 0;
  gint x_start = 0;
  gint x_text_start = 0;
154
  gint x_flag_start = 0;
155
  gint y = 0;
156
  GnomeCanvasItem *item, *item2;
157 158

  /* Pause the board */
159
  board_pause(TRUE);
160 161 162 163

  if(rootitem)
    return;

164 165
  gcompris_bar_hide(TRUE);

166 167 168 169 170 171 172
  rootitem = \
    gnome_canvas_item_new (gnome_canvas_root(gcompris_get_canvas()),
			   gnome_canvas_group_get_type (),
			   "x", (double)0,
			   "y", (double)0,
			   NULL);

Bruno Coudoin's avatar
Bruno Coudoin committed
173
  pixmap = gcompris_load_skin_pixmap("help_bg.png");
174 175 176 177 178 179 180 181 182 183 184
  y_start = (BOARDHEIGHT - gdk_pixbuf_get_height(pixmap))/2;
  x_start = (BOARDWIDTH - gdk_pixbuf_get_width(pixmap))/2;
  item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
				gnome_canvas_pixbuf_get_type (),
				"pixbuf", pixmap, 
				"x", (double) x_start,
				"y", (double) y_start,
				NULL);
  y = BOARDHEIGHT - (BOARDHEIGHT - gdk_pixbuf_get_height(pixmap))/2;
  gdk_pixbuf_unref(pixmap);

185 186 187 188 189 190 191 192
  gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
			 gnome_canvas_text_get_type (),
			 "text", _("GCompris Configuration"),
			 "font", gcompris_skin_font_title,
			 "x", (double) BOARDWIDTH/2 + 1.0,
			 "y", (double) y_start + 40 + 1.0,
			 "anchor", GTK_ANCHOR_CENTER,
			 "fill_color_rgba", gcompris_skin_color_shadow,
193
			 "weight", PANGO_WEIGHT_HEAVY,
194 195 196 197 198 199 200 201 202
			 NULL);
  gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
			 gnome_canvas_text_get_type (),
			 "text", _("GCompris Configuration"),
			 "font", gcompris_skin_font_title,
			 "x", (double) BOARDWIDTH/2,
			 "y", (double) y_start + 40,
			 "anchor", GTK_ANCHOR_CENTER,
			 "fill_color_rgba", gcompris_skin_color_title,
203
			 "weight", PANGO_WEIGHT_HEAVY,
204
			 NULL);
205

206 207
  pixmap_checked   = gcompris_load_skin_pixmap("button_checked.png");
  pixmap_unchecked = gcompris_load_skin_pixmap("button_unchecked.png");
208 209 210


  x_start += 150;
211
  x_flag_start = x_start + 50;
212
  x_text_start = x_start + 115;
213 214 215

  //--------------------------------------------------
  // Locale
216
  y_start += 105;
217

218
  display_previous_next(x_start, y_start, "locale_previous", "locale_next");
219

220 221 222 223 224 225 226
  item_locale_flag = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
					    gnome_canvas_pixbuf_get_type (),
					    "pixbuf", NULL, 
					    "x", (double) x_flag_start,
					    "y", (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2,
					    NULL);

227
  /* Display a bad icon if this locale is not available */
228
  pixmap   = gcompris_load_skin_pixmap("mini_bad.png");
229 230 231 232 233 234 235 236
  item_bad_flag = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
					    gnome_canvas_pixbuf_get_type (),
					    "pixbuf", pixmap,
					    "x", (double) x_flag_start - 20,
					    "y", (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2,
					    NULL);
  gdk_pixbuf_unref(pixmap);

237 238 239 240
  /*
   * The current locale is the one found in the config file
   */
  current_locale = properties->locale;
241
  set_locale_flag(current_locale);
242
 
243 244
  item_locale_text = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
					    gnome_canvas_text_get_type (),
245
					    "text", gcompris_get_locale_name(current_locale), 
246
					    "font", gcompris_skin_font_subtitle,
247 248 249
					    "x", (double) x_text_start,
					    "y", (double) y_start,
					    "anchor", GTK_ANCHOR_WEST,
250
					    "fill_color_rgba", gcompris_skin_color_content,
251
					    NULL);
252 253

  // Fullscreen / Window
Bruno Coudoin's avatar
Bruno Coudoin committed
254
  y_start += Y_GAP;
255 256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272

  item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
				gnome_canvas_pixbuf_get_type (),
				"pixbuf", (properties->fullscreen ? pixmap_checked : pixmap_unchecked), 
				"x", (double) x_start,
				"y", (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2,
				NULL);

  gtk_signal_connect(GTK_OBJECT(item), "event",
		     (GtkSignalFunc) item_event_ok,
		     "fullscreen");
  gtk_signal_connect(GTK_OBJECT(item), "event",
		     (GtkSignalFunc) gcompris_item_event_focus,
		     NULL);


  gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
			 gnome_canvas_text_get_type (),
Bruno Coudoin's avatar
Bruno Coudoin committed
273
			 "text", _("Fullscreen"), 
274
			 "font", gcompris_skin_font_subtitle,
275 276 277
			 "x", (double) x_text_start,
			 "y", (double) y_start,
			 "anchor", GTK_ANCHOR_WEST,
278
			 "fill_color_rgba", gcompris_skin_color_content,
279 280
			 NULL);

281
  // Screen size
Bruno Coudoin's avatar
Bruno Coudoin committed
282
  y_start += Y_GAP;
283 284 285 286 287

  display_previous_next(x_start, y_start, "screen_previous", "screen_next");

  item_screen_text = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
					    gnome_canvas_text_get_type (),
Bruno Coudoin's avatar
Bruno Coudoin committed
288
					    "text", gettext(screenname[properties->screensize]), 
289
					    "font", gcompris_skin_font_subtitle,
290 291 292
					    "x", (double) x_text_start,
					    "y", (double) y_start,
					    "anchor", GTK_ANCHOR_WEST,
293
					    "fill_color_rgba", gcompris_skin_color_content,
294 295
					    NULL);

296
  // Music
Bruno Coudoin's avatar
Bruno Coudoin committed
297
  y_start += Y_GAP;
298 299 300 301 302 303 304 305 306 307 308 309 310 311 312 313 314 315

  item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
				gnome_canvas_pixbuf_get_type (),
				"pixbuf", (properties->music ? pixmap_checked : pixmap_unchecked), 
				"x", (double) x_start,
				"y", (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2,
				NULL);

  gtk_signal_connect(GTK_OBJECT(item), "event",
		     (GtkSignalFunc) item_event_ok,
		     "music");
  gtk_signal_connect(GTK_OBJECT(item), "event",
		     (GtkSignalFunc) gcompris_item_event_focus,
		     NULL);


  gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
			 gnome_canvas_text_get_type (),
Bruno Coudoin's avatar
Bruno Coudoin committed
316
			 "text", _("Music"), 
317
			 "font", gcompris_skin_font_subtitle,
318 319 320
			 "x", (double) x_text_start,
			 "y", (double) y_start,
			 "anchor", GTK_ANCHOR_WEST,
321
			 "fill_color_rgba", gcompris_skin_color_content,
322 323 324
			 NULL);

  // Effect
Bruno Coudoin's avatar
Bruno Coudoin committed
325
  y_start += Y_GAP;
326 327 328 329 330 331 332 333 334 335 336 337 338 339 340 341 342 343

  item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
				gnome_canvas_pixbuf_get_type (),
				"pixbuf", (properties->fx ? pixmap_checked : pixmap_unchecked), 
				"x", (double) x_start,
				"y", (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2,
				NULL);

  gtk_signal_connect(GTK_OBJECT(item), "event",
		     (GtkSignalFunc) item_event_ok,
		     "effect");
  gtk_signal_connect(GTK_OBJECT(item), "event",
		     (GtkSignalFunc) gcompris_item_event_focus,
		     NULL);


  gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
			 gnome_canvas_text_get_type (),
Bruno Coudoin's avatar
Bruno Coudoin committed
344
			 "text", _("Effect"), 
345
			 "font", gcompris_skin_font_subtitle,
346 347 348
			 "x", (double) x_text_start,
			 "y", (double) y_start,
			 "anchor", GTK_ANCHOR_WEST,
349
			 "fill_color_rgba", gcompris_skin_color_content,
350 351
			 NULL);

352
  // Timer
Bruno Coudoin's avatar
Bruno Coudoin committed
353
  y_start += Y_GAP;
354 355 356 357 358

  display_previous_next(x_start, y_start, "timer_previous", "timer_next");

  item_timer_text = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
					   gnome_canvas_text_get_type (),
Bruno Coudoin's avatar
Bruno Coudoin committed
359
					   "text", gettext(timername[properties->timer]),
360
					   "font", gcompris_skin_font_subtitle,
361 362 363
					   "x", (double) x_text_start,
					   "y", (double) y_start,
					   "anchor", GTK_ANCHOR_WEST,
364
					   "fill_color_rgba", gcompris_skin_color_content,
365 366
					   NULL);

Bruno Coudoin's avatar
Bruno Coudoin committed
367 368
  // Skin
  {
369
    const gchar *one_dirent;
370 371
    guint  i;
    GDir  *dir;
372
    gchar *skin_dir;
373
    gchar *first_skin_name;
374

Bruno Coudoin's avatar
Bruno Coudoin committed
375
    /* Load the Pixpmaps directory file names */
376 377
    skin_dir = g_strconcat(properties->package_data_dir, "/skins", NULL);
    dir = g_dir_open(skin_dir, 0, NULL);
378 379

    if (!dir)
380
      g_warning (_("Couldn't open skin dir: %s"), skin_dir);
381

Bruno Coudoin's avatar
Bruno Coudoin committed
382
    /* Fill up the skin list */
383
    while((one_dirent = g_dir_read_name(dir)) != NULL) {
384

385
      if (one_dirent[0] != '.') {
386
	gchar *filename;
Bruno Coudoin's avatar
Bruno Coudoin committed
387
	/* Only directory here are skins */
388
	filename = g_strdup_printf("%s/skins/%s", properties->package_data_dir, one_dirent);
389

Bruno Coudoin's avatar
Bruno Coudoin committed
390
	if (g_file_test ((filename), G_FILE_TEST_IS_DIR)) {
391
	  gchar *skin_name = g_strdup_printf("%s", one_dirent);
392
	  skinlist = g_list_append (skinlist, skin_name);
Bruno Coudoin's avatar
Bruno Coudoin committed
393 394 395
	}
	g_free(filename);
      }
396
    }
397
    g_dir_close(dir);
398

399 400
    g_free(skin_dir);

Bruno Coudoin's avatar
Bruno Coudoin committed
401 402 403 404
    /* Find the current skin index */
    skin_index = 0;
    for(i=0; i<g_list_length(skinlist);  i++)
      if(!strcmp((char *)g_list_nth_data(skinlist, i), properties->skin))
405
	skin_index = i;
Bruno Coudoin's avatar
Bruno Coudoin committed
406

407 408
    y_start += Y_GAP;

409 410 411 412 413 414 415 416
    /* Should not happen. It the user found the config, there should be a skin */
    if(g_list_length(skinlist) > 0) {
      g_warning("No skin found in %s\n", skin_dir);
      display_previous_next(x_start, y_start, "skin_previous", "skin_next");
      first_skin_name = g_strdup_printf(_("Skin : %s"), (char *)g_list_nth_data(skinlist, skin_index));
    } else {
      first_skin_name = g_strdup(_("SKINS NOT FOUND"));
    }
Bruno Coudoin's avatar
Bruno Coudoin committed
417

418 419
    item_skin_text = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
					    gnome_canvas_text_get_type (),
420
					    "text", first_skin_name,
421
					    "font", gcompris_skin_font_subtitle,
422 423 424 425 426
					    "x", (double) x_text_start,
					    "y", (double) y_start,
					    "anchor", GTK_ANCHOR_WEST,
					    "fill_color_rgba", gcompris_skin_color_content,
					    NULL);
427
    g_free(first_skin_name);
428
  }
429 430 431 432

  // Difficulty Filter
  y_start += Y_GAP;

433
  //  display_previous_next(x_start, y_start, "filter_style_previous", "filter_style_next");
434

435
  stars_group_x = x_start + 45;
436 437
  stars_group_y = y_start - 25;

438
  item_filter_text = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
439
						gnome_canvas_text_get_type (),
440
						"markup", gettext(filtername[0]), 
441 442 443 444 445 446 447 448
						"font", gcompris_skin_font_subtitle,
						"x", (double) x_text_start,
						"y", (double) y_start,
						"anchor", GTK_ANCHOR_WEST,
						"fill_color_rgba", gcompris_skin_color_content,
						NULL);


449 450 451 452 453 454 455 456 457 458 459 460 461 462 463 464 465 466 467 468 469 470 471 472
  // OK
  pixmap = gcompris_load_skin_pixmap("button_large.png");
  item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
				gnome_canvas_pixbuf_get_type (),
				"pixbuf", pixmap, 
				"x", (double) (BOARDWIDTH*0.5) - gdk_pixbuf_get_width(pixmap)/2,
				"y", (double) y - gdk_pixbuf_get_height(pixmap) - 5,
				NULL);

  gtk_signal_connect(GTK_OBJECT(item), "event",
		     (GtkSignalFunc) item_event_ok,
		     "ok");
  gtk_signal_connect(GTK_OBJECT(item), "event",
		     (GtkSignalFunc) gcompris_item_event_focus,
		     NULL);

  gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
			 gnome_canvas_text_get_type (),
			 "text", _("OK"),
			 "font", gcompris_skin_font_title,
			 "x", (double)  BOARDWIDTH*0.5 + 1.0,
			 "y", (double)  y - gdk_pixbuf_get_height(pixmap) + 20 + 1.0,
			 "anchor", GTK_ANCHOR_CENTER,
			 "fill_color_rgba", gcompris_skin_color_shadow,
473
			 "weight", PANGO_WEIGHT_HEAVY,
474 475
			 NULL);
  item2 = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
476 477 478 479 480 481 482 483 484
				 gnome_canvas_text_get_type (),
				 "text", _("OK"),
				 "font", gcompris_skin_font_title,
				 "x", (double)  BOARDWIDTH*0.5,
				 "y", (double)  y - gdk_pixbuf_get_height(pixmap) + 20,
				 "anchor", GTK_ANCHOR_CENTER,
				 "fill_color_rgba", gcompris_skin_color_text_button,
				 "weight", PANGO_WEIGHT_HEAVY,
				 NULL);
485 486 487 488 489 490 491 492 493
  gtk_signal_connect(GTK_OBJECT(item2), "event",
		     (GtkSignalFunc) item_event_ok,
		     "ok");
  gtk_signal_connect(GTK_OBJECT(item2), "event",
		     (GtkSignalFunc) gcompris_item_event_focus,
		     item);
  gdk_pixbuf_unref(pixmap);


494
  is_displayed = TRUE;
495 496 497 498 499 500 501 502
}

void gcompris_config_stop ()
{
  // Destroy the help box
  if(rootitem!=NULL)
    {
      gtk_object_destroy(GTK_OBJECT(rootitem));
503
      board_pause(FALSE);
504 505 506
    }
  rootitem = NULL;	  

507 508
  stars_group = NULL;

509 510 511 512 513 514 515
  if(pixmap_unchecked)
    gdk_pixbuf_unref(pixmap_unchecked);
  pixmap_unchecked = NULL;

  if(pixmap_checked)
    gdk_pixbuf_unref(pixmap_checked);
  pixmap_checked = NULL;
516 517

  /* UnPause the board */
518 519
  if(is_displayed)
    board_pause(FALSE);
520

521
  gcompris_bar_hide(FALSE);
522 523

  is_displayed = FALSE;
524 525 526 527 528 529 530
}


/*-------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------*/
/*-------------------------------------------------------------------------------*/
531
static void
532 533 534 535 536 537
display_previous_next(guint x_start, guint y_start, 
		      gchar *eventname_previous, gchar *eventname_next)
{
  GdkPixbuf   *pixmap = NULL;
  GnomeCanvasItem *item;

Bruno Coudoin's avatar
Bruno Coudoin committed
538
  pixmap = gcompris_load_skin_pixmap("button_backward.png");
539 540 541 542 543 544 545 546 547 548 549 550 551 552 553 554
  item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
				gnome_canvas_pixbuf_get_type (),
				"pixbuf", pixmap, 
				"x", (double) x_start - gdk_pixbuf_get_width(pixmap) - 10,
				"y", (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2,
				NULL);

  gtk_signal_connect(GTK_OBJECT(item), "event",
		     (GtkSignalFunc) item_event_ok,
		     eventname_previous);
  gtk_signal_connect(GTK_OBJECT(item), "event",
		     (GtkSignalFunc) gcompris_item_event_focus,
		     NULL);
  gdk_pixbuf_unref(pixmap);


Bruno Coudoin's avatar
Bruno Coudoin committed
555
  pixmap = gcompris_load_skin_pixmap("button_forward.png");
556 557 558 559 560 561 562 563 564 565 566 567 568 569 570 571
  item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
				gnome_canvas_pixbuf_get_type (),
				"pixbuf", pixmap, 
				"x", (double) x_start,
				"y", (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2,
				NULL);

  gtk_signal_connect(GTK_OBJECT(item), "event",
		     (GtkSignalFunc) item_event_ok,
		     eventname_next);
  gtk_signal_connect(GTK_OBJECT(item), "event",
		     (GtkSignalFunc) gcompris_item_event_focus,
		     NULL);
  gdk_pixbuf_unref(pixmap);
}
  
572 573
static void set_locale_flag(gchar *locale)
{
574
  gchar *filename;
575 576
  GdkPixbuf *pixmap = NULL;

577 578 579 580 581 582
  if(locale == NULL)
    return;

  if(locale[0] == '\0') {
    /* Set the flag to the default user's locale */
    locale = gcompris_get_user_default_locale();
583
    g_message("gcompris_get_user_default_locale = %s\n", locale);
584 585
  }

586
  /* First try to find a flag for the long locale name */
587
  filename = gcompris_find_absolute_filename("flags/%.5s.png", locale);
588

589
  /* Not found, Try now with the short locale name */
590
  if(!filename) {
591
    filename = gcompris_find_absolute_filename("flags/%.2s.png", locale);
592 593
  }

594 595
  if(filename)
    {
596
      pixmap = gc_net_load_pixmap(filename);
597 598 599 600 601 602 603 604

      gnome_canvas_item_set (item_locale_flag,
			     "pixbuf", pixmap,
			     NULL);

      gdk_pixbuf_unref(pixmap);
      g_free(filename);
    }
605 606 607 608 609 610 611
  else
    {
      /* No flags */
      gnome_canvas_item_set (item_locale_flag,
			     "pixbuf", NULL,
			     NULL);
    }
612 613

  /* Check wether or not the locale is available */
614 615 616 617
#ifdef WIN32
  /* On win32, it's always available, do not try to check */
  gnome_canvas_item_hide (item_bad_flag);
#else
618
  if(setlocale(LC_MESSAGES, locale)==NULL)
619 620 621
    gnome_canvas_item_show (item_bad_flag);
  else
    gnome_canvas_item_hide (item_bad_flag);
622
#endif
623

624 625 626 627
}


/**
628 629
 * Given the locale name, return the full translated name
 * If not found, simply return the name
630
 */
631 632
gchar*
gcompris_get_locale_name(gchar *locale)
633 634 635
{
  guint i = 0;

636
  /* en (US) is not in the Linguas table */
637
  if(locale[0] != '\0' && !strncmp(locale, "en", strlen(locale)))
638 639
    return(_("English (United State)"));

640 641
  while(linguas[i] != NULL)
    {
642 643

      if(!strncmp(locale, linguas[i], strlen(locale)))
644
	return(gettext(linguas[i+1]));
645 646 647

      i=i+2;
    }
648 649
  // Oups this locale is not in the table. Return the first one (system default)
  return(linguas[1]);
650 651 652 653 654 655 656 657 658 659 660
}

/**
 * Given the short locale name, return the next one in our linguas table
 */
static gchar *get_next_locale(gchar *locale)
{
  guint i = 0;

  while(linguas[i] != NULL)
    {
661
      if(!strcmp(locale, linguas[i]))
662 663 664 665 666 667 668 669 670 671
	{
	  // Found it
	  if(linguas[i+2]!=NULL)
	    return(linguas[i+2]);
	  else
	    return(linguas[0]);
	  
	}
      i=i+2;
    }
672 673
  // Oups this locale is not in the table. Return the first one
  return(linguas[0]);
674 675 676 677 678 679 680 681
}

/**
 * Given the short locale name, return the previous one in our linguas table
 */
static gchar *get_previous_locale(gchar *locale)
{
  guint i = 0;
682

683 684
  while(linguas[i] != NULL)
    {
685
      if(!strcmp(locale, linguas[i]))
686 687 688 689 690 691 692 693 694 695 696 697 698 699 700
	{
	  // Found it
	  if(i!=0)
	    return(linguas[i-2]);
	  else
	    {
	      // Go to the end of the list
	      while(linguas[i]!=NULL) { i=i+2; };
	      return(linguas[i-2]);
	    }	  
	}
      i=i+2;
    }
  return(locale);
}
701 702 703 704 705 706 707

/* Callback for the bar operations */
static gint
item_event_ok(GnomeCanvasItem *item, GdkEvent *event, gpointer data)
{
  GcomprisProperties	*properties = gcompris_get_properties();

708
  if(data==NULL)
709
    return FALSE;
710

711 712 713 714 715 716 717 718 719
  switch (event->type) 
    {
    case GDK_ENTER_NOTIFY:
      break;
    case GDK_LEAVE_NOTIFY:
      break;
    case GDK_BUTTON_PRESS:
      if(!strcmp((char *)data, "ok"))
	{
720 721 722 723 724 725
	  if(current_locale[0] == '\0') {
	    /* Set the locale to the default user's locale */
	    gcompris_set_locale(gcompris_get_user_default_locale());
	  } else {
	    gcompris_set_locale(current_locale);
	  }
Bruno Coudoin's avatar
Bruno Coudoin committed
726
	  properties->skin = g_strdup((char *)g_list_nth_data(skinlist, skin_index));
727
	  gcompris_skin_load(properties->skin);
728
	  gcompris_config_stop();
729
	  gcompris_properties_save(properties);
730 731 732 733

	  if(properties->music || properties->fx) {
	    initSound();
	  }
734 735 736 737
	}
      else if(!strcmp((char *)data, "fullscreen"))
	{
	  properties->fullscreen = (properties->fullscreen ? 0 : 1);
738

739
#ifdef XF86_VIDMODE
740 741 742
	  /* Changing screen without xrandr is more complex, it requires to remove the
	     black border we created manually.
	  */
743
	  if(!properties->noxf86vm)
744 745
	    gcompris_set_fullscreen(properties->fullscreen);
#endif
746 747 748
	  /* Warning changing the image needs to update pixbuf_ref for the focus usage */
	  g_object_set_data (G_OBJECT (item), "pixbuf_ref",  
			     (properties->fullscreen ? pixmap_checked : pixmap_unchecked));
749 750 751 752 753 754 755 756
	  gnome_canvas_item_set (item,
				 "pixbuf", (properties->fullscreen ? pixmap_checked : pixmap_unchecked),
				 NULL);

	}
      else if(!strcmp((char *)data, "music"))
	{
	  properties->music = (properties->music ? 0 : 1);
757 758 759
	  /* Warning changing the image needs to update pixbuf_ref for the focus usage */
	  g_object_set_data (G_OBJECT (item), "pixbuf_ref",  
			     (properties->music ? pixmap_checked : pixmap_unchecked));
760 761 762 763 764 765 766 767
	  gnome_canvas_item_set (item,
				 "pixbuf", (properties->music ? pixmap_checked : pixmap_unchecked),
				 NULL);

	}
      else if(!strcmp((char *)data, "effect"))
	{
	  properties->fx = (properties->fx ? 0 : 1);
768 769 770
	  /* Warning changing the image needs to update pixbuf_ref for the focus usage */
	  g_object_set_data (G_OBJECT (item), "pixbuf_ref",  
			     (properties->fx ? pixmap_checked : pixmap_unchecked));
771 772 773 774
	  gnome_canvas_item_set (item,
				 "pixbuf", (properties->fx ? pixmap_checked : pixmap_unchecked),
				 NULL);

775

776
	}
777 778 779 780
      else if(!strcmp((char *)data, "locale_previous"))
	{
	  current_locale = get_previous_locale(current_locale);
	  gnome_canvas_item_set (item_locale_text,
781
				 "text", gcompris_get_locale_name(current_locale),
782 783 784 785 786 787 788 789
				 NULL);
	  set_locale_flag(current_locale);
	  properties->locale = current_locale;
	}
      else if(!strcmp((char *)data, "locale_next"))
	{
	  current_locale = get_next_locale(current_locale);
	  gnome_canvas_item_set (item_locale_text,
790
				 "text", gcompris_get_locale_name(current_locale),
791 792 793 794 795
				 NULL);

	  set_locale_flag(current_locale);
	  properties->locale = current_locale;
	}
796 797 798 799 800 801
      else if(!strcmp((char *)data, "screen_previous"))
	{
	  if(properties->screensize>0)
	    properties->screensize--;

	  gnome_canvas_item_set (item_screen_text,
Bruno Coudoin's avatar
Bruno Coudoin committed
802
				 "text", gettext(screenname[properties->screensize]), 
803 804 805 806 807 808 809 810
				 NULL);
	}
      else if(!strcmp((char *)data, "screen_next"))
	{
	  if(properties->screensize<MAX_SCREEN_VALUE)
	    properties->screensize++;

	  gnome_canvas_item_set (item_screen_text,
Bruno Coudoin's avatar
Bruno Coudoin committed
811
				 "text", gettext(screenname[properties->screensize]), 
812 813 814 815 816 817 818 819
				 NULL);
	}
      else if(!strcmp((char *)data, "timer_previous"))
	{
	  if(properties->timer>0)
	    properties->timer--;

	  gnome_canvas_item_set (item_timer_text,
Bruno Coudoin's avatar
Bruno Coudoin committed
820
				 "text", gettext(timername[properties->timer]), 
821 822 823 824 825 826 827 828
				 NULL);
	}
      else if(!strcmp((char *)data, "timer_next"))
	{
	  if(properties->timer<MAX_TIMER_VALUE)
	    properties->timer++;

	  gnome_canvas_item_set (item_timer_text,
Bruno Coudoin's avatar
Bruno Coudoin committed
829
				 "text", gettext(timername[properties->timer]), 
830 831
				 NULL);
	}
Bruno Coudoin's avatar
Bruno Coudoin committed
832 833
      else if(!strcmp((char *)data, "skin_previous"))
	{
834
	  gchar *skin_str;
Bruno Coudoin's avatar
Bruno Coudoin committed
835 836 837
	  if(skin_index-- < 1)
	    skin_index = g_list_length(skinlist)-1;

838 839 840
	  skin_str = g_strdup_printf(_("Skin : %s"), 
				     (char *)g_list_nth_data(skinlist, skin_index));

Bruno Coudoin's avatar
Bruno Coudoin committed
841
	  gnome_canvas_item_set (item_skin_text,
842
				 "text", skin_str,
Bruno Coudoin's avatar
Bruno Coudoin committed
843
				 NULL);
844
	  g_free(skin_str);
Bruno Coudoin's avatar
Bruno Coudoin committed
845 846 847
	}
      else if(!strcmp((char *)data, "skin_next"))
	{
848
	  gchar *skin_str;
Bruno Coudoin's avatar
Bruno Coudoin committed
849 850 851
	  if(skin_index++ >= g_list_length(skinlist)-1)
	    skin_index = 0;

852 853
	  skin_str = g_strdup_printf(_("Skin : %s"), 
				     (char *)g_list_nth_data(skinlist, skin_index));
Bruno Coudoin's avatar
Bruno Coudoin committed
854
	  gnome_canvas_item_set (item_skin_text,
855
				 "text", skin_str,
Bruno Coudoin's avatar
Bruno Coudoin committed
856
				 NULL);
857
	  g_free(skin_str);
Bruno Coudoin's avatar
Bruno Coudoin committed
858
	}
859 860 861 862 863 864 865 866 867 868 869 870 871 872 873 874 875
    default:
      break;
    }
  return FALSE;

}




/* 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: */