~ubuntu-branches/ubuntu/trusty/gcompris/trusty

« back to all changes in this revision

Viewing changes to src/boards/click_on_letter.c

  • Committer: Bazaar Package Importer
  • Author(s): Yann Dirson
  • Date: 2006-12-15 23:08:17 UTC
  • mfrom: (1.1.4 upstream)
  • Revision ID: james.westby@ubuntu.com-20061215230817-exr5ks1hd73s3tlk
Tags: 8.2.2-1
* New upstream bugfix release, fixes among other things the support for
  the version of gnucap shipped in etch.
* Add missing dependency on python-gtk2 (Closes: #396523).
* Removed reference to non-existent sound file from memory.c (upstream
  fix - impacts 8.2 as well).  
* Now suggests gnuchess, gnucap, and tuxpaint.
* Updated extended description for the main package.

Show diffs side-by-side

added added

removed removed

Lines of Context:
17
17
 *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
18
18
 */
19
19
 
20
 
#include <ctype.h>
21
 
#include <math.h>
22
 
#include <assert.h>
23
20
#include <glib.h>
 
21
#include <string.h>
24
22
 
25
23
#include "gcompris/gcompris.h"
26
24
 
29
27
#define SOUNDLISTFILE PACKAGE
30
28
 
31
29
static GcomprisBoard *gcomprisBoard = NULL;
32
 
static gboolean board_paused = TRUE;
 
30
static gboolean board_paused;
33
31
 
34
32
static void              start_board (GcomprisBoard *agcomprisBoard);
35
33
static void              pause_board (gboolean pause);
43
41
static void              highlight_selected(GnomeCanvasItem *);
44
42
static void              game_won(void);
45
43
static void              repeat(void);
 
44
static void              config_start(GcomprisBoard *agcomprisBoard,
 
45
                                      GcomprisProfile *aProfile);
 
46
static void              config_stop(void);
 
47
 
46
48
 
47
49
#define VERTICAL_SEPARATION 408
48
50
#define HORIZONTAL_SEPARATION 0
51
53
#define NUMBER_OF_LEVELS 5
52
54
#define MAX_NUMBER_OF_LETTERS 4
53
55
 
 
56
#define NOT_OK          0
 
57
#define OK              1
 
58
#define OK_NO_INIT      2
 
59
 
54
60
#define TEXT_COLOR "white"
55
61
 
56
62
static GnomeCanvasGroup *boardRootItem = NULL;
64
70
static void click_on_letter_destroy_all_items(void);
65
71
static void click_on_letter_next_level(void);
66
72
static gint item_event(GnomeCanvasItem *item, GdkEvent *event, gpointer data);
67
 
static gint phone_event(GnomeCanvasItem *item, GdkEvent *event, gpointer data);
68
 
static gboolean sounds_are_fine(gchar* letter);
 
73
static gboolean sounds_are_fine();
69
74
 
70
75
static int right_position;
71
76
static int number_of_letters=MAX_NUMBER_OF_LETTERS;
72
77
static gchar *right_letter;
73
78
 
 
79
static gchar *alphabet;
 
80
 
 
81
static void sound_played(gchar *file);
 
82
 
 
83
static gboolean uppercase_only;
74
84
 
75
85
/* Description of this plugin */
76
86
static BoardPlugin menu_bp =
77
87
  {
78
88
    NULL,
79
89
    NULL,
80
 
    N_("Read a letter"),
81
 
    N_("Learn to recognize letters"),
 
90
    "Read a letter",
 
91
    "Learn to recognize letters",
82
92
    "Pascal Georges pascal.georges1@free.fr>",
83
93
    NULL,
84
94
    NULL,
89
99
    end_board,
90
100
    is_our_board,
91
101
    NULL,
92
 
    process_ok,
 
102
    NULL,
93
103
    set_level,
94
104
    NULL,
95
 
    repeat
 
105
    repeat,
 
106
    config_start,
 
107
    config_stop
96
108
  };
97
109
 
98
110
/*
101
113
 *
102
114
 */
103
115
 
104
 
BoardPlugin
105
 
*get_bplugin_info(void)
106
 
{
107
 
  return &menu_bp;
108
 
}
 
116
GET_BPLUGIN_INFO(click_on_letter)
109
117
 
110
118
/*
111
119
 * in : boolean TRUE = PAUSE : FALSE = CONTINUE
112
120
 *
113
121
 */
114
 
static void pause_board (gboolean pause)
 
122
     static void pause_board (gboolean pause)
115
123
{
116
124
  if(gcomprisBoard==NULL)
117
125
    return;
128
136
 */
129
137
static void start_board (GcomprisBoard *agcomprisBoard)
130
138
{
131
 
 
132
 
  if(!sounds_are_fine("a"))
133
 
    return;
134
 
 
135
 
  if(agcomprisBoard!=NULL)
 
139
  GHashTable *config = gc_db_get_board_conf();
 
140
  int ready;
 
141
 
 
142
  board_paused = TRUE;
 
143
 
 
144
  gc_locale_set(g_hash_table_lookup( config, "locale_sound"));
 
145
 
 
146
  gchar *up_init_str = g_hash_table_lookup( config, "uppercase_only");
 
147
 
 
148
  if (up_init_str && (strcmp(up_init_str, "True")==0))
 
149
    uppercase_only = TRUE;
 
150
  else
 
151
    uppercase_only = FALSE;
 
152
 
 
153
  g_hash_table_destroy(config);
 
154
 
 
155
  ready = sounds_are_fine();
 
156
 
 
157
  gc_sound_pause();
 
158
 
 
159
  if (agcomprisBoard!=NULL)
136
160
    {
137
161
      gcomprisBoard=agcomprisBoard;
138
 
      gcompris_set_background(gnome_canvas_root(gcomprisBoard->canvas), "images/scenery4_background.png");
 
162
      gc_set_background(gnome_canvas_root(gcomprisBoard->canvas),
 
163
                              "images/scenery4_background.png");
139
164
      gcomprisBoard->level=1;
140
165
      gcomprisBoard->maxlevel=NUMBER_OF_LEVELS;
141
166
      gcomprisBoard->sublevel=1;
142
 
      gcomprisBoard->number_of_sublevel=NUMBER_OF_SUBLEVELS; /* Go to next level after this number of 'play' */
143
 
      gcompris_bar_set(GCOMPRIS_BAR_LEVEL|GCOMPRIS_BAR_REPEAT);
144
 
      gcompris_score_start(SCORESTYLE_NOTE,
145
 
                           50,
146
 
                           50,
147
 
                           gcomprisBoard->number_of_sublevel);
148
 
 
149
 
      click_on_letter_next_level();
150
 
 
151
 
      gamewon = FALSE;
152
 
      pause_board(FALSE);
153
 
 
 
167
 
 
168
      /* Go to next level after this number of 'play' */
 
169
      gcomprisBoard->number_of_sublevel=NUMBER_OF_SUBLEVELS;
 
170
 
 
171
      if(ready)
 
172
        {
 
173
          /* Warning, bar buttons are set in click_on_letter_next_level()
 
174
             to avoid them to appear in the case a dialog is displayed */
 
175
          gc_score_start(SCORESTYLE_NOTE,
 
176
                               50,
 
177
                               50,
 
178
                               gcomprisBoard->number_of_sublevel);
 
179
 
 
180
          if(ready == OK)
 
181
            click_on_letter_next_level();
 
182
 
 
183
          gamewon = FALSE;
 
184
          pause_board(FALSE);
 
185
        }
154
186
    }
 
187
 
155
188
}
156
189
/* ======================================= */
157
190
static void end_board ()
159
192
  if(gcomprisBoard!=NULL)
160
193
    {
161
194
      pause_board(TRUE);
162
 
      gcompris_score_end();
 
195
      gc_score_end();
163
196
      click_on_letter_destroy_all_items();
164
197
    }
 
198
  gc_locale_reset();
165
199
  gcomprisBoard = NULL;
 
200
  gc_sound_resume();
166
201
}
167
202
 
168
203
/* ======================================= */
195
230
/* ======================================= */
196
231
static void repeat ()
197
232
{
198
 
   if(gcomprisBoard!=NULL)
 
233
  if(gcomprisBoard!=NULL)
199
234
    {
200
 
 
201
235
      gchar *str1 = NULL;
202
236
      gchar *right_letter_ogg = NULL;
203
237
 
204
 
      right_letter_ogg = g_strdup_printf("%s%s",right_letter,".ogg");
205
 
      str1 = gcompris_get_asset_file("gcompris alphabet", NULL, "audio/x-ogg", right_letter_ogg);
206
 
 
207
 
      if(str1) {
208
 
        gcompris_play_ogg(str1, NULL);
209
 
      }
210
 
 
 
238
      str1 = gc_sound_alphabet(right_letter);
 
239
 
 
240
      right_letter_ogg = g_strdup_printf("sounds/$LOCALE/alphabet/%s", str1);
211
241
      g_free(str1);
 
242
 
 
243
      if(right_letter_ogg) {
 
244
        gc_sound_play_ogg_cb(right_letter_ogg, sound_played);
 
245
      }
 
246
 
212
247
      g_free(right_letter_ogg);
213
248
    }
214
249
}
215
250
 
216
 
static gboolean sounds_are_fine (gchar* letter)
 
251
static gboolean sounds_are_fine()
217
252
{
218
 
  char *str1 = NULL;
219
 
  char *str2 = NULL;
220
 
  GcomprisProperties    *properties = gcompris_get_properties();
221
 
  gchar *locale;
222
 
  gboolean fine = TRUE;
223
 
 
224
 
  locale= g_strndup(gcompris_get_locale(), 2);
225
 
  
226
 
  str1 = g_strdup_printf("%s%s", letter, ".ogg");
227
 
  str2 = gcompris_get_asset_file("gcompris alphabet", NULL, "audio/x-ogg", str1);
228
 
  
229
 
  if(!str2) {
230
 
    gchar *msg = g_strdup_printf("%s%s", _("Error: this activity requires you that you first install \nthe package assetml-voices-alphabet-"),
231
 
                                 locale);
232
 
    gcompris_dialog(msg, gcompris_end_board);
233
 
    g_free(msg);
234
 
    fine = FALSE;
235
 
  } else {
236
 
    if(!properties->fx) {
237
 
      gcompris_dialog(_("Error: this activity cannot be played with the\nsound effects disabled.\nGo in the configuration dialog to\nenable the sound"), gcompris_end_board);
238
 
      fine = FALSE;
239
 
    }
240
 
  }
241
 
  
242
 
  g_free(locale);
243
 
  g_free(str1);
244
 
  g_free(str2);
245
 
  
246
 
  return(fine);
247
 
  
 
253
  char *letter_str;
 
254
  char *str2;
 
255
  GcomprisProperties    *properties = gc_prop_get();
 
256
 
 
257
  if(!properties->fx)
 
258
    {
 
259
      gc_dialog(_("Error: this activity cannot be played with the\nsound effects disabled.\nGo to the configuration dialog to\nenable the sound"), gc_board_stop);
 
260
      return(NOT_OK);
 
261
    }
 
262
 
 
263
  /* TRANSLATORS: Put here the alphabet in your language */
 
264
  alphabet=_("abcdefghijklmnopqrstuvwxyz");
 
265
  g_assert(g_utf8_validate(alphabet, -1, NULL)); // require by all utf8-functions
 
266
 
 
267
  gchar *letter = g_new0(gchar, 8);
 
268
  g_unichar_to_utf8(g_utf8_get_char(alphabet), letter);
 
269
  letter_str = gc_sound_alphabet(letter);
 
270
  g_free(letter);
 
271
 
 
272
  str2 = gc_file_find_absolute("sounds/$LOCALE/alphabet/%s", letter_str);
 
273
 
 
274
  if (!str2)
 
275
    {
 
276
      gchar *locale = NULL;
 
277
 
 
278
      locale = g_strndup(gc_locale_get(), 2);
 
279
      gc_locale_reset();
 
280
      gc_locale_set("en_US");
 
281
 
 
282
      str2 = gc_file_find_absolute("sounds/en/alphabet/%s", letter_str);
 
283
 
 
284
      if (!str2)
 
285
        {
 
286
          gchar *msg = g_strdup_printf( _("Error: this activity requires that you first install\nthe packages with gcompris voices for the locale '%s' or '%s'"),
 
287
                                        locale, "en");
 
288
          gc_dialog(msg, gc_board_stop);
 
289
          g_free(msg);
 
290
          return (NOT_OK);
 
291
        }
 
292
      else
 
293
        {
 
294
          gchar *msg = g_strdup_printf( _("Error: this activity requires that you first install\nthe packages with GCompris voices for the locale '%s' ! Fallback to english, sorry!"), locale);
 
295
          gc_dialog(msg, click_on_letter_next_level);
 
296
          g_free(msg);
 
297
          g_free(str2);
 
298
          return(OK_NO_INIT);
 
299
        }
 
300
    }
 
301
  else
 
302
    {
 
303
      g_free(str2);
 
304
    }
 
305
 
 
306
  return(OK);
248
307
}
249
308
 
250
309
/*-------------------------------------------------------------------------------*/
251
310
/*-------------------------------------------------------------------------------*/
252
311
/* set initial values for the next level */
253
 
static void click_on_letter_next_level()
 
312
static void
 
313
click_on_letter_next_level()
254
314
{
255
 
  gcompris_bar_set_level(gcomprisBoard);
 
315
  /* It must be set it for the warning dialogs */
 
316
  gc_bar_set(GC_BAR_CONFIG|GC_BAR_LEVEL|GC_BAR_REPEAT);
 
317
 
 
318
  gc_bar_set_level(gcomprisBoard);
256
319
 
257
320
  click_on_letter_destroy_all_items();
258
321
  gamewon = FALSE;
259
322
  selected_button = NULL;
260
 
  gcompris_score_set(gcomprisBoard->sublevel);
 
323
  gc_score_set(gcomprisBoard->sublevel);
261
324
  g_free (right_letter);
262
325
  /* Try the next level */
 
326
  gc_sound_play_ogg("sounds/$LOCALE/misc/click_on_letter.ogg", NULL);
263
327
  click_on_letter_create_item(gnome_canvas_root(gcomprisBoard->canvas));
264
328
}
265
329
/* ==================================== */
278
342
  int xOffset,yOffset,i,j;
279
343
  GdkPixbuf *button_pixmap = NULL;
280
344
 
281
 
  /* TRANSLATORS: Put here the alphabet in your language */
282
 
  gchar *alphabet=_("abcdefghijklmnopqrstuvwxyz");
283
 
  assert(g_utf8_validate(alphabet,-1,NULL)); // require by all utf8-functions
284
 
 
285
 
 
286
345
  int length_of_aphabet=g_utf8_strlen (alphabet,-1);
287
346
 
288
347
  number_of_letters=gcomprisBoard->level+1;
289
348
  if (number_of_letters>MAX_NUMBER_OF_LETTERS) number_of_letters=MAX_NUMBER_OF_LETTERS;
290
349
 
291
350
  int numbers[number_of_letters];
 
351
 
292
352
  gchar *letters[number_of_letters];
293
 
  assert(number_of_letters<=length_of_aphabet); // because we must set unique letter on every "vagon"
 
353
  g_assert(number_of_letters<=length_of_aphabet); // because we must set unique letter on every "vagon"
294
354
 
295
355
  for (i=0;i<number_of_letters;i++){
296
 
        numbers[i]=((int)(((float)length_of_aphabet)*rand()/(RAND_MAX+1.0)));
 
356
    numbers[i]=((int)(((float)length_of_aphabet)*rand()/(RAND_MAX+1.0)));
297
357
 
298
 
        // check that the letter has not been taken yet 
299
 
        for(j=0;j<i;j++){
300
 
                if (numbers[i]==numbers[j]) {
301
 
                        i--;
302
 
                        continue;
303
 
                }
304
 
        }
 
358
    // check that the letter has not been taken yet
 
359
    for(j=0;j<i;j++){
 
360
      if (numbers[i]==numbers[j]) {
 
361
        i--;
 
362
        continue;
 
363
      }
 
364
    }
305
365
 
306
366
  }
307
367
 
308
 
 
309
 
 
310
 
 
311
368
  for (i=0;i<number_of_letters;i++){
312
 
   gchar *copy_from=g_utf8_offset_to_pointer(alphabet, numbers[i]);
313
 
   gchar *copy_to=g_utf8_offset_to_pointer(alphabet, numbers[i]+1);
314
 
   letters[i]=g_strndup(copy_from,copy_to-copy_from);
315
 
   switch (gcomprisBoard->level) {
316
 
        case 1  :
317
 
        case 2  : letters[i]=g_strndup(copy_from,copy_to-copy_from); break;
318
 
        case 3  : letters[i]=g_utf8_strup(copy_from,copy_to-copy_from); break;
319
 
        default : 
320
 
                if ( rand() > (RAND_MAX/2) ) 
321
 
                        letters[i]=g_strndup(copy_from,copy_to-copy_from);
322
 
                else 
323
 
                        letters[i]=g_utf8_strup(copy_from,copy_to-copy_from);
324
 
        }
 
369
    gchar *copy_from=g_utf8_offset_to_pointer(alphabet, numbers[i]);
 
370
    gchar *copy_to=g_utf8_offset_to_pointer(alphabet, numbers[i]+1);
 
371
    letters[i]=g_strndup(copy_from,copy_to-copy_from);
325
372
 
 
373
    if (uppercase_only)
 
374
      letters[i]=g_utf8_strup(copy_from,copy_to-copy_from);
 
375
    else {
 
376
      switch (gcomprisBoard->level) {
 
377
      case 1    :
 
378
      case 2  : letters[i]=g_strndup(copy_from,copy_to-copy_from); break;
 
379
      case 3  : letters[i]=g_utf8_strup(copy_from,copy_to-copy_from); break;
 
380
      default :
 
381
        if ( rand() > (RAND_MAX/2) )
 
382
          letters[i]=g_strndup(copy_from,copy_to-copy_from);
 
383
        else
 
384
          letters[i]=g_utf8_strup(copy_from,copy_to-copy_from);
 
385
      }
 
386
    }
326
387
  }
327
388
 
328
389
  /*  */
329
390
  right_position = ((int)(((float)number_of_letters)*rand()/(RAND_MAX+1.0)));
330
 
  assert(right_position >= 0  && right_position < number_of_letters);
 
391
  g_assert(right_position >= 0  && right_position < number_of_letters);
331
392
  right_letter = g_utf8_strdown(letters[right_position],-1);
332
393
 
333
394
  repeat();
334
 
 
 
395
 
335
396
 
336
397
  boardRootItem = GNOME_CANVAS_GROUP(
337
398
                                     gnome_canvas_item_new (gnome_canvas_root(gcomprisBoard->canvas),
341
402
                                                            NULL));
342
403
 
343
404
 
344
 
  button_pixmap = gcompris_load_pixmap("images/wagon-yellow.png");
 
405
  button_pixmap = gc_pixmap_load("images/wagon-yellow.png");
345
406
 
346
407
  yOffset = VERTICAL_SEPARATION;
347
408
  xOffset = 5;
348
409
 
349
410
 
350
411
  for (i=0; i< number_of_letters; i++) {
351
 
 
352
 
  buttons[i] = gnome_canvas_item_new (boardRootItem,
353
 
                                   gnome_canvas_pixbuf_get_type (),
354
 
                                   "pixbuf",  button_pixmap,
355
 
                                   "x",  (double) xOffset,
356
 
                                   "y",  (double) yOffset,
357
 
                                   NULL);
358
 
 
359
 
 
360
 
  l_items[i] = gnome_canvas_item_new (boardRootItem,
361
 
                                   gnome_canvas_text_get_type (),
362
 
                                   "text", letters[i] ,
363
 
                                   "font", gcompris_skin_font_board_huge_bold,
364
 
                                   "anchor", GTK_ANCHOR_CENTER,
365
 
                                   "fill_color_rgba", 0x0000ffff,
366
 
                                   "x",  (double) xOffset + gdk_pixbuf_get_width(button_pixmap)/2,
367
 
                                   "y",  (double) yOffset + gdk_pixbuf_get_height(button_pixmap)/2 - 5,
368
 
                                   NULL);
369
 
  g_free(letters[i]);
370
 
  xOffset +=HORIZONTAL_SEPARATION +gdk_pixbuf_get_width(button_pixmap);
371
 
 
372
 
  gtk_signal_connect(GTK_OBJECT(l_items[i]), "event", (GtkSignalFunc) item_event, GINT_TO_POINTER(i));
373
 
  gtk_signal_connect(GTK_OBJECT(buttons[i]), "event",  (GtkSignalFunc) item_event, GINT_TO_POINTER(i));
374
 
  gtk_signal_connect(GTK_OBJECT(buttons[i]), "event", (GtkSignalFunc) gcompris_item_event_focus, NULL);
 
412
    buttons[i] = gnome_canvas_item_new (boardRootItem,
 
413
                                        gnome_canvas_pixbuf_get_type (),
 
414
                                        "pixbuf",  button_pixmap,
 
415
                                        "x",  (double) xOffset,
 
416
                                        "y",  (double) yOffset,
 
417
                                        NULL);
 
418
 
 
419
 
 
420
    l_items[i] = gnome_canvas_item_new (boardRootItem,
 
421
                                        gnome_canvas_text_get_type (),
 
422
                                        "text", letters[i],
 
423
                                        "font", gc_skin_font_board_huge_bold,
 
424
                                        "anchor", GTK_ANCHOR_CENTER,
 
425
                                        "fill_color_rgba", 0x0000ffff,
 
426
                                        "x",  (double) xOffset + gdk_pixbuf_get_width(button_pixmap)/2,
 
427
                                        "y",  (double) yOffset + gdk_pixbuf_get_height(button_pixmap)/2 - 5,
 
428
                                        NULL);
 
429
 
 
430
    g_free(letters[i]);
 
431
    xOffset +=HORIZONTAL_SEPARATION +gdk_pixbuf_get_width(button_pixmap);
 
432
 
 
433
    gtk_signal_connect(GTK_OBJECT(l_items[i]), "event", (GtkSignalFunc) item_event, GINT_TO_POINTER(i));
 
434
    gtk_signal_connect(GTK_OBJECT(buttons[i]), "event",  (GtkSignalFunc) item_event, GINT_TO_POINTER(i));
 
435
    //  gtk_signal_connect(GTK_OBJECT(buttons[i]), "event", (GtkSignalFunc) gc_item_focus_event, NULL);
375
436
  }
376
437
 
377
438
 
389
450
    gcomprisBoard->sublevel=1;
390
451
    gcomprisBoard->level++;
391
452
    if(gcomprisBoard->level>gcomprisBoard->maxlevel) { // the current board is finished : bail out
392
 
      board_finished(BOARD_FINISHED_TUXPLANE);
 
453
      gc_bonus_end_display(BOARD_FINISHED_TUXPLANE);
393
454
      return;
394
455
    }
395
456
  }
398
459
 
399
460
/* ==================================== */
400
461
static gboolean process_ok_timeout() {
401
 
  gcompris_display_bonus(gamewon, BONUS_FLOWER);
 
462
  gc_bonus_display(gamewon, BONUS_FLOWER);
402
463
  return FALSE;
403
464
}
404
465
 
407
468
  g_timeout_add(TIME_CLICK_TO_BONUS, process_ok_timeout, NULL);
408
469
}
409
470
/* ==================================== */
410
 
static gint phone_event(GnomeCanvasItem *item, GdkEvent *event, gpointer data) {
411
 
  switch (event->type)
412
 
    {
413
 
    case GDK_BUTTON_PRESS:
414
 
      repeat();
415
 
      break;
416
 
    default:
417
 
      break;
418
 
    }
419
 
  return TRUE;
420
 
}
421
 
/* ==================================== */
422
471
static gint
423
472
item_event(GnomeCanvasItem *item, GdkEvent *event, gpointer data)
424
473
{
436
485
    case GDK_BUTTON_PRESS:
437
486
      /* We really don't want the user to change his/her mind */
438
487
      board_paused = TRUE;
439
 
  
 
488
 
440
489
      if ( pos == right_position ) {
441
490
        gamewon = TRUE;
442
491
      } else {
443
492
        gamewon = FALSE;
444
493
      }
445
 
     highlight_selected(item);
 
494
      highlight_selected(item);
446
495
      process_ok();
447
496
      break;
448
497
 
461
510
  /* Replace text item by button item */
462
511
  button = item;
463
512
  for (i=0; i<number_of_letters;i++) {
464
 
     if ( l_items[i] == item ) {
465
 
        button = buttons[i];
466
 
     }
 
513
    if ( l_items[i] == item ) {
 
514
      button = buttons[i];
 
515
    }
467
516
  }
468
517
 
469
518
  if (selected_button != NULL && selected_button != button) {
470
 
        button_pixmap = gcompris_load_pixmap("images/wagon-yellow.png");
471
 
        /* Warning changing the image needs to update pixbuf_ref for the focus usage */
472
 
        g_object_set_data (G_OBJECT (selected_button), "pixbuf_ref", button_pixmap);
473
 
        gnome_canvas_item_set(selected_button, "pixbuf", button_pixmap, NULL);
474
 
        gdk_pixbuf_unref(button_pixmap);
 
519
    button_pixmap = gc_pixmap_load("images/wagon-yellow.png");
 
520
    /* Warning changing the image needs to update pixbuf_ref for the focus usage */
 
521
    gc_item_focus_free(selected_button, NULL);
 
522
    gnome_canvas_item_set(selected_button, "pixbuf", button_pixmap, NULL);
 
523
    gdk_pixbuf_unref(button_pixmap);
475
524
  }
476
525
 
477
526
  if (selected_button != button) {
478
 
        button_pixmap_selected = gcompris_load_pixmap("images/wagon-green.png");
479
 
        /* Warning changing the image needs to update pixbuf_ref for the focus usage */
480
 
        g_object_set_data (G_OBJECT (button), "pixbuf_ref", button_pixmap_selected);
481
 
        gnome_canvas_item_set(button, "pixbuf", button_pixmap_selected, NULL);
482
 
        selected_button = button;
483
 
        gdk_pixbuf_unref(button_pixmap_selected);
484
 
  }
485
 
 
 
527
    button_pixmap_selected = gc_pixmap_load("images/wagon-green.png");
 
528
    /* Warning changing the image needs to update pixbuf_ref for the focus usage */
 
529
      gc_item_focus_free(button, NULL);
 
530
    gnome_canvas_item_set(button, "pixbuf", button_pixmap_selected, NULL);
 
531
    selected_button = button;
 
532
    gdk_pixbuf_unref(button_pixmap_selected);
 
533
  }
 
534
 
 
535
}
 
536
 
 
537
 
 
538
/* ************************************* */
 
539
/* *            Configuration          * */
 
540
/* ************************************* */
 
541
 
 
542
 
 
543
/* ======================= */
 
544
/* = config_start        = */
 
545
/* ======================= */
 
546
 
 
547
static GcomprisProfile *profile_conf;
 
548
static GcomprisBoard   *board_conf;
 
549
 
 
550
static GHFunc save_table (gpointer key,
 
551
                          gpointer value,
 
552
                          gpointer user_data)
 
553
{
 
554
  gc_db_set_board_conf ( profile_conf,
 
555
                            board_conf,
 
556
                            (gchar *) key,
 
557
                            (gchar *) value);
 
558
 
 
559
  return NULL;
 
560
}
 
561
 
 
562
static void
 
563
conf_ok(GHashTable *table)
 
564
{
 
565
  if (!table){
 
566
    if (gcomprisBoard)
 
567
      pause_board(FALSE);
 
568
 
 
569
    return;
 
570
  }
 
571
 
 
572
 
 
573
  g_hash_table_foreach(table, (GHFunc) save_table, NULL);
 
574
 
 
575
  board_conf = NULL;
 
576
  profile_conf = NULL;
 
577
 
 
578
  if (gcomprisBoard){
 
579
    GHashTable *config;
 
580
    if (profile_conf)
 
581
      config = gc_db_get_board_conf();
 
582
    else
 
583
      config = table;
 
584
 
 
585
    gc_locale_reset();
 
586
    gc_locale_set(g_hash_table_lookup(config, "locale_sound"));
 
587
 
 
588
    gchar *up_init_str = g_hash_table_lookup( config, "uppercase_only");
 
589
    if (up_init_str)
 
590
      {
 
591
        if(strcmp(up_init_str, "True")==0)
 
592
          uppercase_only = TRUE;
 
593
        else
 
594
          uppercase_only = FALSE;
 
595
      }
 
596
 
 
597
    if (profile_conf)
 
598
      g_hash_table_destroy(config);
 
599
 
 
600
    sounds_are_fine();
 
601
 
 
602
    click_on_letter_next_level();
 
603
 
 
604
    gamewon = FALSE;
 
605
    pause_board(FALSE);
 
606
 
 
607
  }
 
608
 
 
609
  board_conf = NULL;
 
610
  profile_conf = NULL;
 
611
}
 
612
 
 
613
static void
 
614
config_start(GcomprisBoard *agcomprisBoard,
 
615
             GcomprisProfile *aProfile)
 
616
{
 
617
  board_conf = agcomprisBoard;
 
618
  profile_conf = aProfile;
 
619
 
 
620
  if (gcomprisBoard)
 
621
    pause_board(TRUE);
 
622
 
 
623
  gchar *label = g_strdup_printf("<b>%s</b> configuration\n for profile <b>%s</b>",
 
624
                                 agcomprisBoard->name,
 
625
                                 aProfile ? aProfile->name : "");
 
626
 
 
627
  gc_board_config_window_display(label, conf_ok);
 
628
 
 
629
  g_free(label);
 
630
 
 
631
  /* init the combo to previously saved value */
 
632
  GHashTable *config = gc_db_get_conf( profile_conf, board_conf);
 
633
 
 
634
  gchar *saved_locale_sound = g_hash_table_lookup( config, "locale_sound");
 
635
 
 
636
  gc_board_config_combo_locales_asset( "Select sound locale", saved_locale_sound,
 
637
                                "sounds/$LOCALE/colors/purple.ogg");
 
638
 
 
639
  gboolean up_init = FALSE;
 
640
 
 
641
  gchar *up_init_str = g_hash_table_lookup( config, "uppercase_only");
 
642
 
 
643
  if (up_init_str && (strcmp(up_init_str, "True")==0))
 
644
    up_init = TRUE;
 
645
 
 
646
  gc_board_config_boolean_box(_("Uppercase only text"),
 
647
                       "uppercase_only",
 
648
                       up_init);
 
649
 
 
650
  g_hash_table_destroy(config);
 
651
}
 
652
 
 
653
 
 
654
/* ======================= */
 
655
/* = config_stop        = */
 
656
/* ======================= */
 
657
static void
 
658
config_stop()
 
659
{
 
660
}
 
661
 
 
662
static void
 
663
sound_played (gchar *file)
 
664
{
 
665
  g_warning ("Sound_played %s\n", file);
486
666
}