Back to index

gcompris  8.2.2
reading.c
Go to the documentation of this file.
00001 /* gcompris - reading.c
00002  *
00003  * Time-stamp: <2006/08/21 23:34:48 bruno>
00004  *
00005  * Copyright (C) 2000 Bruno Coudoin
00006  *
00007  *   This program is free software; you can redistribute it and/or modify
00008  *   it under the terms of the GNU General Public License as published by
00009  *   the Free Software Foundation; either version 2 of the License, or
00010  *   (at your option) any later version.
00011  *
00012  *   This program is distributed in the hope that it will be useful,
00013  *   but WITHOUT ANY WARRANTY; without even the implied warranty of
00014  *   MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00015  *   GNU General Public License for more details.
00016  *
00017  *   You should have received a copy of the GNU General Public License
00018  *   along with this program; if not, write to the Free Software
00019  *   Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00020  */
00021 
00022 // FIXME: Cleanup of LettersItem created struct is not done
00023 
00024 #include <string.h>
00025 
00026 #include "gcompris/gcompris.h"
00027 
00028 
00029 #define SOUNDLISTFILE PACKAGE
00030 #define MAXWORDSLENGTH 50
00031 #define MAX_WORDS 100
00032 
00033 
00034 static GcomprisWordlist *gc_wordlist = NULL;
00035 
00036 static GcomprisBoard *gcomprisBoard = NULL;
00037 
00038 static gint drop_items_id    = 0;
00039 static gint next_level_timer = 0;
00040 
00041 static gchar *textToFind = NULL;
00042 static gint textToFindIndex = 0;
00043 #define NOT_THERE -1000
00044 
00045 static GnomeCanvasGroup *boardRootItem = NULL;
00046 
00047 typedef enum
00048 {
00049   MODE_HORIZONTAL           = 0,
00050   MODE_VERTICAL                    = 1
00051 } Mode;
00052 static Mode currentMode = MODE_VERTICAL;
00053 
00054 /* Store the moving words */
00055 typedef struct {
00056   GnomeCanvasGroup *rootItem;
00057   GnomeCanvasItem  *overwriteItem;
00058   GnomeCanvasItem  *item;
00059 } LettersItem;
00060 
00061 static LettersItem previousFocus;
00062 static LettersItem toDeleteFocus;
00063 
00064 
00065 /* Define the page area where text can be displayed */
00066 #define BASE_X1 70
00067 #define BASE_Y1 120
00068 #define BASE_X2 350
00069 #define BASE_Y2 520
00070 #define BASE_CX  BASE_X1+(BASE_X2-BASE_X1)/2
00071 
00072 gint current_x;
00073 gint current_y;
00074 gint numberOfLine;
00075 gint font_size;
00076 gint interline;
00077 
00078 
00079 static void           start_board (GcomprisBoard *agcomprisBoard);
00080 static void           pause_board (gboolean pause);
00081 static void           end_board (void);
00082 static gboolean              is_our_board (GcomprisBoard *gcomprisBoard);
00083 static void           set_level (guint level);
00084 static int            wait_for_ready;
00085 static int            gamewon;
00086 
00087 static gboolean              reading_create_item(GnomeCanvasGroup *parent);
00088 static gint           reading_drop_items (void);
00089 //static void reading_destroy_item(LettersItem *item);
00090 static void           reading_destroy_all_items(void);
00091 static gint           reading_next_level(void);
00092 static void           reading_config_start(GcomprisBoard *agcomprisBoard,
00093                                         GcomprisProfile *aProfile);
00094 static void           reading_config_stop(void);
00095 
00096 static void           player_win(void);
00097 static void           player_loose(void);
00098 static gchar         *get_random_word(const gchar *except);
00099 static GnomeCanvasItem      *display_what_to_do(GnomeCanvasGroup *parent);
00100 static void           ask_ready(gboolean status);
00101 static void           ask_yes_no(void);
00102 static gint           item_event_valid(GnomeCanvasItem *item, GdkEvent *event, gpointer data);
00103 
00104 static  guint32          fallSpeed = 0;
00105 
00106 /* Description of this plugin */
00107 static BoardPlugin menu_bp =
00108 {
00109    NULL,
00110    NULL,
00111    "Reading",
00112    "Read a list of words and then work out if the given word is in it",
00113    "Bruno Coudoin <bruno.coudoin@free.fr>",
00114    NULL,
00115    NULL,
00116    NULL,
00117    NULL,
00118    start_board,
00119    pause_board,
00120    end_board,
00121    is_our_board,
00122    NULL,
00123    NULL,
00124    set_level,
00125    NULL,
00126    NULL,
00127    reading_config_start,
00128    reading_config_stop
00129 };
00130 
00131 /*
00132  * Main entry point mandatory for each Gcompris's game
00133  * ---------------------------------------------------
00134  *
00135  */
00136 
00137 GET_BPLUGIN_INFO(reading)
00138 
00139 /*
00140  * in : boolean TRUE = PAUSE : FALSE = UNPAUSE
00141  *
00142  */
00143 static void pause_board (gboolean pause)
00144 {
00145   // after the bonus is ended, the board is unpaused, but we must wait for
00146   // the player to be ready (this board does not use the same framework as others)
00147   if (wait_for_ready)
00148     return;
00149 
00150   if(gcomprisBoard==NULL)
00151     return;
00152 
00153   if(pause)
00154     {
00155       if (drop_items_id) {
00156        gtk_timeout_remove (drop_items_id);
00157        drop_items_id = 0;
00158       }
00159     }
00160   else
00161     {
00162       if(!drop_items_id) {
00163        reading_drop_items();
00164       }
00165     }
00166 }
00167 
00168 /*
00169  */
00170 static void start_board (GcomprisBoard *agcomprisBoard)
00171 {
00172   GHashTable *config = gc_db_get_board_conf();
00173 
00174   gc_locale_set(g_hash_table_lookup( config, "locale"));
00175 
00176   g_hash_table_destroy(config);
00177 
00178   if(agcomprisBoard!=NULL)
00179     {
00180       gchar *img;
00181 
00182       gcomprisBoard=agcomprisBoard;
00183 
00184       img = gc_skin_image_get("reading-bg.jpg");
00185       gc_set_background(gnome_canvas_root(gcomprisBoard->canvas),
00186                            img);
00187       g_free(img);
00188       wait_for_ready = TRUE;
00189       gamewon = FALSE;
00190 
00191       gcomprisBoard->level = 1;
00192       gcomprisBoard->maxlevel = 9;
00193       gc_bar_set(GC_BAR_CONFIG|GC_BAR_LEVEL);
00194 
00195       font_size = PANGO_PIXELS(pango_font_description_get_size (pango_font_description_from_string (gc_skin_font_board_medium)));
00196       interline = (int) (1.5*font_size);
00197 
00198       PangoContext *pango_context = gtk_widget_get_pango_context  (GTK_WIDGET(agcomprisBoard->canvas));
00199 
00200       PangoFontMetrics* pango_metrics =  pango_context_get_metrics (pango_context,
00201                                                             pango_font_description_from_string (gc_skin_font_board_medium),
00202                                                             pango_language_from_string   (gc_locale_get()));
00203 
00204       int ascent = PANGO_PIXELS(pango_font_metrics_get_ascent (pango_metrics));
00205       int descent = PANGO_PIXELS(pango_font_metrics_get_descent (pango_metrics));
00206       interline = ascent + descent;
00207 
00208       g_warning ("Font to display words have size %d  ascent : %d, descent : %d.\n Set inerline to %d", font_size, ascent, descent, interline);
00209 
00210       /* Default mode */
00211       currentMode=MODE_VERTICAL;
00212       if(gcomprisBoard->mode && g_strcasecmp(gcomprisBoard->mode, "horizontal")==0)
00213        currentMode=MODE_HORIZONTAL;
00214 
00215       gc_wordlist = gc_wordlist_get_from_file("wordsgame/default-$LOCALE.xml");
00216 
00217       if(!gc_wordlist)
00218        {
00219          /* Fallback to english */
00220          gc_wordlist = gc_wordlist_get_from_file("wordsgame/default-en.xml");
00221 
00222          if(!gc_wordlist)
00223            {
00224              gcomprisBoard = NULL;
00225              gc_dialog(_("Error: We can't find\na list of words to play this game.\n"), gc_board_end);
00226              return;
00227            }
00228        }
00229 
00230       reading_next_level();
00231     }
00232 }
00233 
00234 static void
00235 end_board ()
00236 {
00237 
00238   if(gcomprisBoard!=NULL)
00239     {
00240       pause_board(TRUE);
00241       reading_destroy_all_items();
00242     }
00243 
00244   if (gc_wordlist != NULL){
00245     gc_wordlist_free(gc_wordlist);
00246     gc_wordlist = NULL;
00247   }
00248 
00249   gc_locale_reset();
00250 
00251   gcomprisBoard = NULL;
00252 }
00253 
00254 static void
00255 set_level (guint level)
00256 {
00257 
00258   if(gcomprisBoard!=NULL)
00259     {
00260       gcomprisBoard->level=level;
00261       reading_next_level();
00262     }
00263 }
00264 
00265 gboolean
00266 is_our_board (GcomprisBoard *gcomprisBoard)
00267 {
00268   if (gcomprisBoard)
00269     {
00270       if(g_strcasecmp(gcomprisBoard->type, "reading")==0)
00271        {
00272          /* Set the plugin entry */
00273          gcomprisBoard->plugin=&menu_bp;
00274 
00275          return TRUE;
00276        }
00277     }
00278   return FALSE;
00279 }
00280 
00281 
00282 /*-------------------------------------------------------------------------------*/
00283 /*-------------------------------------------------------------------------------*/
00284 /*-------------------------------------------------------------------------------*/
00285 /*-------------------------------------------------------------------------------*/
00286 
00287 /* set initial values for the next level */
00288 static gint reading_next_level()
00289 {
00290 
00291   gc_bar_set_level(gcomprisBoard);
00292 
00293   gamewon = FALSE;
00294 
00295   reading_destroy_all_items();
00296 
00297   boardRootItem = GNOME_CANVAS_GROUP(
00298                                  gnome_canvas_item_new (gnome_canvas_root(gcomprisBoard->canvas),
00299                                                      gnome_canvas_group_get_type (),
00300                                                      "x", (double) 0,
00301                                                      "y", (double) 0,
00302                                                      NULL));
00303 
00304   /* Default speed */
00305   fallSpeed=1400-gcomprisBoard->level*120;
00306 
00307   if(currentMode==MODE_VERTICAL)
00308     {
00309       current_x = BASE_CX;
00310       numberOfLine=7+gcomprisBoard->level;
00311     }
00312   else
00313     {
00314       current_x = BASE_X1;
00315       numberOfLine=2+gcomprisBoard->level;
00316     }
00317 
00318   current_y = BASE_Y1 - 2 * interline;
00319 
00320   gcomprisBoard->number_of_sublevel=1;
00321   gcomprisBoard->sublevel=1;
00322 
00323   display_what_to_do(boardRootItem);
00324   ask_ready(TRUE);
00325   return (FALSE);
00326 }
00327 
00328 /* Destroy all the items */
00329 static void reading_destroy_all_items()
00330 {
00331 
00332   if (drop_items_id) {
00333     gtk_timeout_remove (drop_items_id);
00334     drop_items_id = 0;
00335   }
00336 
00337   if (next_level_timer) {
00338     gtk_timeout_remove (next_level_timer);
00339     drop_items_id = 0;
00340   }
00341 
00342   if(boardRootItem!=NULL)
00343       gtk_object_destroy (GTK_OBJECT(boardRootItem));
00344 
00345   boardRootItem = NULL;
00346   previousFocus.rootItem = NULL;
00347   toDeleteFocus.rootItem = NULL;
00348 
00349   if (textToFind!=NULL)
00350     {
00351     g_free(textToFind);
00352     textToFind=NULL;
00353     }
00354 }
00355 
00356 static GnomeCanvasItem *display_what_to_do(GnomeCanvasGroup *parent)
00357 {
00358 
00359   gint base_Y = 110;
00360   gint base_X = 580;
00361   gint i;
00362 
00363   /* Load the text to find */
00364 
00365   textToFind = get_random_word(NULL);
00366 
00367   g_assert(textToFind != NULL);
00368 
00369   /* Decide now if this time we will display the text to find */
00370   /* Use this formula to have a better random number see 'man 3 rand' */
00371   i=((int)(2.0*rand()/(RAND_MAX+1.0)));
00372   if(i==0)
00373       textToFindIndex = rand() % numberOfLine;
00374   else
00375     textToFindIndex = NOT_THERE;
00376 
00377   gnome_canvas_item_new (parent,
00378                       gnome_canvas_text_get_type (),
00379                       "text", _("Please, check if the word"),
00380                       "font", gc_skin_font_board_big,
00381                       "x", (double) base_X,
00382                       "y", (double) base_Y,
00383                       "anchor", GTK_ANCHOR_CENTER,
00384                       "fill_color", "white",
00385                       NULL);
00386 
00387   gnome_canvas_item_new (parent,
00388                       gnome_canvas_text_get_type (),
00389                       "text", textToFind,
00390                       "font", gc_skin_font_board_big,
00391                       "x", (double) base_X,
00392                       "y", (double) base_Y + 30,
00393                       "anchor", GTK_ANCHOR_CENTER,
00394                       "fill_color", "green",
00395                       NULL);
00396 
00397   gnome_canvas_item_new (parent,
00398                       gnome_canvas_text_get_type (),
00399                       "text", _("is being displayed"),
00400                       "font", gc_skin_font_board_big,
00401                       "x", (double) base_X,
00402                       "y", (double) base_Y + 60,
00403                       "anchor", GTK_ANCHOR_CENTER,
00404                       "fill_color", "white",
00405                       NULL);
00406 
00407 
00408   return NULL;
00409 }
00410 
00411 static gboolean reading_create_item(GnomeCanvasGroup *parent)
00412 {
00413   gint   anchor = GTK_ANCHOR_CENTER;
00414   gchar *word;
00415 
00416   g_assert(textToFind!=NULL);
00417 
00418   if(toDeleteFocus.rootItem)
00419     {
00420       gtk_object_destroy (GTK_OBJECT(toDeleteFocus.rootItem));
00421       toDeleteFocus.rootItem = NULL;
00422     }
00423 
00424   if(previousFocus.rootItem)
00425     {
00426       gnome_canvas_item_show (previousFocus.overwriteItem);
00427       toDeleteFocus.rootItem = previousFocus.rootItem;
00428     }
00429 
00430   if(numberOfLine<=0)
00431     {
00432       gtk_object_destroy (GTK_OBJECT(toDeleteFocus.rootItem));
00433       toDeleteFocus.rootItem = NULL;
00434 
00435       ask_yes_no();
00436       return FALSE;
00437     }
00438 
00439 
00440   if(textToFindIndex!=0)
00441     {
00442       word = get_random_word(textToFind);
00443     }
00444   else
00445     {
00446       word = g_strdup(textToFind);
00447     }
00448 
00449   g_assert(word!=NULL);
00450 
00451   if(textToFindIndex>=0)
00452     textToFindIndex--;
00453 
00454   previousFocus.rootItem = \
00455     GNOME_CANVAS_GROUP( gnome_canvas_item_new (parent,
00456                                           gnome_canvas_group_get_type (),
00457                                           "x", (double) current_x,
00458                                           "y", (double) current_y,
00459                                           NULL));
00460 
00461   if(currentMode==MODE_HORIZONTAL)
00462     anchor=GTK_ANCHOR_WEST;
00463 
00464   previousFocus.item = \
00465     gnome_canvas_item_new (GNOME_CANVAS_GROUP(previousFocus.rootItem),
00466                         gnome_canvas_text_get_type (),
00467                         "text", word,
00468                         "font", gc_skin_font_board_medium,
00469                         "x", (double) 0,
00470                         "y", (double) 0,
00471                         "anchor", anchor,
00472                         "fill_color", "black",
00473                         NULL);
00474 
00475 
00476   gchar *oldword = g_strdup_printf("<span foreground=\"black\" background=\"black\">%s</span>", word);
00477 
00478   g_free(word);
00479 
00480   previousFocus.overwriteItem =                                       \
00481     gnome_canvas_item_new (GNOME_CANVAS_GROUP(previousFocus.rootItem),
00482                         gnome_canvas_text_get_type (),
00483                         "markup", oldword,
00484                         "font", gc_skin_font_board_medium,
00485                         "x", (double) 0,
00486                         "y", (double) 0,
00487                         "anchor", anchor,
00488                         NULL);
00489 
00490   g_free(oldword);
00491   gnome_canvas_item_hide(previousFocus.overwriteItem);
00492 
00493   // Calculate the next spot
00494   if(currentMode==MODE_VERTICAL)
00495     {
00496       current_y += interline;
00497       numberOfLine--;
00498     }
00499   else
00500     {
00501       double x1, y1, x2, y2;
00502 
00503       gnome_canvas_item_get_bounds(GNOME_CANVAS_ITEM(previousFocus.rootItem), &x1, &y1, &x2, &y2);
00504 
00505       // Are we out of bound
00506       if(x2>BASE_X2)
00507        {
00508          // Do the line Wrapping
00509          gnome_canvas_item_move(GNOME_CANVAS_ITEM(previousFocus.rootItem), BASE_X1-x1, interline);
00510          current_y += interline;
00511          current_x = BASE_X1;
00512          numberOfLine--;
00513        }
00514       current_x += x2-x1 + font_size;
00515     }
00516 
00517   return (TRUE);
00518 }
00519 
00520 /*
00521  * This is called on a low frequency and is used to display new items
00522  *
00523  */
00524 static gint reading_drop_items ()
00525 {
00526 
00527   if(reading_create_item(boardRootItem))
00528     drop_items_id = gtk_timeout_add (fallSpeed,
00529                                  (GtkFunction) reading_drop_items, NULL);
00530   return (FALSE);
00531 }
00532 
00533 static void ask_ready(gboolean status)
00534 {
00535   static GnomeCanvasItem *item1 = NULL;
00536   static GnomeCanvasItem *item2 = NULL;
00537   GdkPixbuf *button_pixmap = NULL;
00538   double y_offset = 310;
00539   double x_offset = 430;
00540 
00541   if(textToFind==NULL)
00542     return;
00543 
00544   if(status==FALSE)
00545     {
00546       if(item1!=NULL)
00547        gtk_object_destroy(GTK_OBJECT(item1));
00548 
00549       if(item2!=NULL)
00550        gtk_object_destroy(GTK_OBJECT(item2));
00551 
00552       item1 = NULL;
00553       item2 = NULL;
00554       return;
00555     }
00556 
00557   /*----- READY -----*/
00558   button_pixmap = gc_skin_pixmap_load("button_large2.png");
00559   item1 = gnome_canvas_item_new (boardRootItem,
00560                             gnome_canvas_pixbuf_get_type (),
00561                             "pixbuf",  button_pixmap,
00562                             "x", x_offset,
00563                             "y", y_offset,
00564                             NULL);
00565 
00566   gdk_pixbuf_unref(button_pixmap);
00567   gtk_signal_connect(GTK_OBJECT(item1), "event",
00568                    (GtkSignalFunc) item_event_valid,
00569                    "R");
00570 
00571   item2 = gnome_canvas_item_new (boardRootItem,
00572                             gnome_canvas_text_get_type (),
00573                             "text", _("I am Ready"),
00574                             "font", gc_skin_font_board_big,
00575                             "x", (double) x_offset +
00576                             gdk_pixbuf_get_width(button_pixmap)/2,
00577                             "y", (double) y_offset + 40,
00578                             "anchor", GTK_ANCHOR_CENTER,
00579                             "fill_color", "white",
00580                             NULL);
00581 
00582   gtk_signal_connect(GTK_OBJECT(item2), "event",
00583                    (GtkSignalFunc) item_event_valid,
00584                    "R");
00585 }
00586 
00587 static void ask_yes_no()
00588 {
00589   GnomeCanvasItem *item;
00590   GdkPixbuf *button_pixmap = NULL;
00591   double y_offset = 310;
00592   double x_offset = 430;
00593 
00594   if(textToFind==NULL)
00595     return;
00596 
00597   /*----- YES -----*/
00598   button_pixmap = gc_skin_pixmap_load("button_large2.png");
00599   item = gnome_canvas_item_new (boardRootItem,
00600                             gnome_canvas_pixbuf_get_type (),
00601                             "pixbuf",  button_pixmap,
00602                             "x", x_offset,
00603                             "y", y_offset,
00604                             NULL);
00605 
00606   gdk_pixbuf_unref(button_pixmap);
00607   gtk_signal_connect(GTK_OBJECT(item), "event",
00608                    (GtkSignalFunc) item_event_valid,
00609                    "Y");
00610 
00611   item = gnome_canvas_item_new (boardRootItem,
00612                             gnome_canvas_text_get_type (),
00613                             "text", _("Yes, I saw it"),
00614                             "font", gc_skin_font_board_big,
00615                             "x", (double) x_offset +
00616                             gdk_pixbuf_get_width(button_pixmap)/2,
00617                             "y", (double) y_offset + 40,
00618                             "anchor", GTK_ANCHOR_CENTER,
00619                             "fill_color", "white",
00620                             NULL);
00621 
00622   gtk_signal_connect(GTK_OBJECT(item), "event",
00623                    (GtkSignalFunc) item_event_valid,
00624                    "Y");
00625 
00626   /*----- NO -----*/
00627   y_offset += 100;
00628   button_pixmap = gc_skin_pixmap_load("button_large2.png");
00629   item = gnome_canvas_item_new (boardRootItem,
00630                             gnome_canvas_pixbuf_get_type (),
00631                             "pixbuf",  button_pixmap,
00632                             "x", x_offset,
00633                             "y", y_offset,
00634                             NULL);
00635 
00636   gdk_pixbuf_unref(button_pixmap);
00637   gtk_signal_connect(GTK_OBJECT(item), "event",
00638                    (GtkSignalFunc) item_event_valid,
00639                    "N");
00640 
00641   item = gnome_canvas_item_new (boardRootItem,
00642                             gnome_canvas_text_get_type (),
00643                             "text", _("No, it was not there"),
00644                             "font", gc_skin_font_board_big,
00645                             "x", (double) x_offset +
00646                             gdk_pixbuf_get_width(button_pixmap)/2,
00647                             "y", (double) y_offset + 40,
00648                             "anchor", GTK_ANCHOR_CENTER,
00649                             "fill_color", "white",
00650                             NULL);
00651 
00652   gtk_signal_connect(GTK_OBJECT(item), "event",
00653                    (GtkSignalFunc) item_event_valid,
00654                    "N");
00655 }
00656 
00657 
00658 static void player_win()
00659 {
00660   gamewon = TRUE;
00661   wait_for_ready = TRUE;
00662   gc_bonus_display(gamewon, BONUS_FLOWER);
00663   /* Try the next level */
00664   gcomprisBoard->level++;
00665   if(gcomprisBoard->level>gcomprisBoard->maxlevel) { // the current board is finished : bail out
00666     gc_bonus_end_display(BOARD_FINISHED_RANDOM);
00667     return;
00668   }
00669 
00670   next_level_timer = g_timeout_add(3000, (GtkFunction)reading_next_level, NULL);
00671 }
00672 
00673 static void player_loose()
00674 {
00675   gchar *expected;
00676   gchar *got;
00677   gamewon = FALSE;
00678   wait_for_ready = TRUE;
00679 
00680   /* Report what was wrong in the log */
00681   expected = g_strdup_printf(_("The word to find was '%s'"), textToFind);
00682 
00683   if(textToFindIndex == NOT_THERE)
00684     got    = g_strdup_printf(_("But it was not displayed"));
00685   else
00686     got    = g_strdup_printf(_("And it was displayed"));
00687 
00688   gc_log_set_comment (gcomprisBoard, expected, got);
00689 
00690   g_free(expected);
00691   g_free(got);
00692 
00693   gc_bonus_display(gamewon, BONUS_FLOWER);
00694 
00695   next_level_timer = g_timeout_add(3000, (GtkFunction)reading_next_level, NULL);
00696 }
00697 
00698 /* Callback for the yes and no buttons */
00699 static gint
00700 item_event_valid(GnomeCanvasItem *item, GdkEvent *event, gpointer data)
00701 {
00702 
00703   switch (event->type)
00704     {
00705     case GDK_ENTER_NOTIFY:
00706       break;
00707     case GDK_LEAVE_NOTIFY:
00708       break;
00709     case GDK_BUTTON_PRESS:
00710       if (((char *)data)[0]=='R')
00711        {
00712          // The user is Ready
00713          wait_for_ready = FALSE;
00714          ask_ready(FALSE);
00715          pause_board(FALSE);
00716        }
00717       else if(!wait_for_ready) {
00718        if ((((char *)data)[0]=='Y' && textToFindIndex == -1)
00719            || (((char *)data)[0]=='N' && textToFindIndex == NOT_THERE))
00720          {
00721            player_win();
00722          }
00723        else
00724          {
00725            player_loose();
00726          }
00727        return TRUE;
00728       }
00729       break;
00730 
00731     default:
00732       break;
00733     }
00734   return FALSE;
00735 
00736 }
00737 
00738 
00746 static gchar *
00747 get_random_word(const gchar* except)
00748 {
00749   gchar *word;
00750 
00751   word = gc_wordlist_random_word_get(gc_wordlist, gcomprisBoard->level);
00752 
00753   if(except)
00754     while(strcmp(except, word)==0)
00755       {
00756        g_free(word);
00757        word = gc_wordlist_random_word_get(gc_wordlist, gcomprisBoard->level);
00758       }
00759 
00760   return(word);
00761 }
00762 
00763 
00764 /* ************************************* */
00765 /* *            Configuration          * */
00766 /* ************************************* */
00767 
00768 
00769 /* ======================= */
00770 /* = config_start        = */
00771 /* ======================= */
00772 
00773 static GcomprisProfile *profile_conf;
00774 static GcomprisBoard   *board_conf;
00775 
00776 static void save_table (gpointer key,
00777                      gpointer value,
00778                      gpointer user_data)
00779 {
00780   gc_db_set_board_conf ( profile_conf,
00781                          board_conf,
00782                          (gchar *) key,
00783                          (gchar *) value);
00784 }
00785 
00786 static void conf_ok(GHashTable *table)
00787 {
00788   if (!table){
00789     if (gcomprisBoard)
00790       pause_board(FALSE);
00791     return;
00792   }
00793 
00794   g_hash_table_foreach(table, (GHFunc) save_table, NULL);
00795 
00796   if (gcomprisBoard){
00797     gc_locale_reset();
00798 
00799     GHashTable *config;
00800 
00801     if (profile_conf)
00802       config = gc_db_get_board_conf();
00803     else
00804       config = table;
00805 
00806     gc_locale_set(g_hash_table_lookup( config, "locale"));
00807 
00808     if (profile_conf)
00809       g_hash_table_destroy(config);
00810 
00811     reading_next_level();
00812 
00813     pause_board(FALSE);
00814   }
00815 
00816   board_conf = NULL;
00817   profile_conf = NULL;
00818 
00819 }
00820 
00821 static void
00822 reading_config_start(GcomprisBoard *agcomprisBoard,
00823                   GcomprisProfile *aProfile)
00824 {
00825   board_conf = agcomprisBoard;
00826   profile_conf = aProfile;
00827 
00828   if (gcomprisBoard)
00829     pause_board(TRUE);
00830 
00831   gchar *label = g_strdup_printf("<b>%s</b> configuration\n for profile <b>%s</b>",
00832                              agcomprisBoard->name,
00833                              aProfile? aProfile->name: "");
00834 
00835   gc_board_config_window_display( label,
00836                              (GcomprisConfCallback )conf_ok);
00837 
00838   g_free(label);
00839 
00840   /* init the combo to previously saved value */
00841   GHashTable *config = gc_db_get_conf( profile_conf, board_conf);
00842 
00843   gchar *locale = g_hash_table_lookup( config, "locale");
00844 
00845   gc_board_config_combo_locales( locale);
00846 
00847 }
00848 
00849 
00850 /* ======================= */
00851 /* = config_stop        = */
00852 /* ======================= */
00853 static void
00854 reading_config_stop()
00855 {
00856 }