Back to index

gcompris  8.2.2
config.c
Go to the documentation of this file.
00001 /* gcompris - config.c
00002  *
00003  * Time-stamp: <2006/08/21 23:28:06 bruno>
00004  *
00005  * Copyright (C) 2000-2003 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 
00026 #include <string.h>
00027 
00028 #include "gcompris.h"
00029 #include "gc_core.h"
00030 #include "gcompris_config.h"
00031 #include "locale.h"
00032 
00033 static GnomeCanvasItem      *rootitem            = NULL;
00034 static GnomeCanvasItem      *item_locale_text    = NULL;
00035 static GnomeCanvasItem      *item_locale_flag    = NULL;
00036 static GnomeCanvasItem      *item_bad_flag              = NULL;
00037 static GnomeCanvasItem      *item_screen_text    = NULL;
00038 static GnomeCanvasItem      *item_timer_text     = NULL;
00039 static GnomeCanvasItem      *item_skin_text             = NULL;
00040 static GnomeCanvasItem      *item_filter_text    = NULL;
00041 static GdkPixbuf     *pixmap_checked             = NULL;
00042 static GdkPixbuf     *pixmap_unchecked    = NULL;
00043 
00044 static gchar         *current_locale             = NULL;
00045 static GList         *skinlist            = NULL;
00046 static guint         skin_index;
00047 
00048 static GnomeCanvasGroup     *stars_group         = NULL;
00049 static double           stars_group_x;
00050 static double           stars_group_y;
00051 
00052 #define Y_GAP 45
00053 
00054 static gboolean is_displayed                     = FALSE;
00055 
00056 #define SOUNDLISTFILE PACKAGE
00057 
00058 static gchar *linguas[] = {
00059   "",                N_("Your system default"),
00060   "am_ET.UTF-8",     N_("Amharic"),
00061   "ar_AE.UTF-8",     N_("Arabic"),
00062   "az_AZ.UTF-8",     N_("Turkish (Azerbaijan)"),
00063   "bg_BG.UTF-8",     N_("Bulgarian"),
00064   "ca_ES.UTF-8",     N_("Catalan"),
00065   "cs_CZ.UTF-8",     N_("Czech Republic"),
00066   "da_DK.UTF-8",     N_("Danish"),
00067   "de_DE.UTF-8",     N_("German"),
00068   "el_GR.UTF-8",     N_("Greek"),
00069   "en_CA.UTF-8",     N_("English (Canada)"),
00070   "en_GB.UTF-8",     N_("English (Great Britain)"),
00071   "es_ES.UTF-8",     N_("Spanish"),
00072   "eu_ES.UTF-8",     N_("Basque"),
00073   "fi_FI.UTF-8",     N_("Finnish"),
00074   "fr_FR.UTF-8",     N_("French"),
00075   "ga_IE.UTF-8",     N_("Irish (Gaelic)"),
00076   "he_IL.UTF-8",     N_("Hebrew"),
00077   "hi_IN.UTF-8",     N_("Hindi"),
00078   "gu_IN.UTF-8",     N_("Gujarati"),
00079   "pa_IN.UTF-8",     N_("Punjabi"),
00080   "hu_HU.UTF-8",     N_("Hungarian"),
00081   "hr_HR.UTF-8",     N_("Croatian"),
00082   "it_IT.UTF-8",     N_("Italian"),
00083   "ka_GE.UTF-8",        N_("Georgian"),
00084   "lt_LT.UTF-8",     N_("Lithuanian"),
00085   "mk_MK.UTF-8",     N_("Macedonian"),
00086   "ml_IN.UTF-8",     N_("Malayalam"),
00087   "mr_IN.UTF-8",     N_("Marathi"),
00088   "ms_MY.UTF-8",     N_("Malay"),
00089   "ne_NP.UTF-8",     N_("Nepal"),
00090   "nl_NL.UTF-8",     N_("Dutch"),
00091   "nb_NO.UTF-8",     N_("Norwegian Bokmal"),
00092   "nn_NO.UTF-8",     N_("Norwegian Nynorsk"),
00093   "pl_PL.UTF-8",     N_("Polish"),
00094   "pt_PT.UTF-8",     N_("Portuguese"),
00095   "pt_BR.UTF-8",     N_("Portuguese (Brazil)"),
00096   "ro_RO.UTF-8",     N_("Romanian"),
00097   "ru_RU.UTF-8",     N_("Russian"),
00098   "rw_RW.UTF-8",     N_("Kinyarwanda"),
00099   "sk_SK.UTF-8",     N_("Slovak"),
00100   "sl_SI.UTF-8",     N_("Slovenian"),
00101   "so_SO.UTF-8",     N_("Somali"),
00102   "sq_AL.UTF-8",     N_("Albanian"),
00103   "sr@Latn_YU.ISO-8859-2",  N_("Serbian (Latin)"),
00104   "sr_YU.UTF-8",     N_("Serbian"),
00105   "sv_FI.UTF-8",     N_("Swedish"),
00106   /*  "ta_IN.UTF-8", N_("Tamil"), */
00107   "th_TH.UTF-8",     N_("Thai"),
00108   "tr_TR.UTF-8",     N_("Turkish"),
00109   "vi_VN.UTF-8",     N_("Vietnamese"),
00110   "wa_BE.UTF-8",     N_("Walloon"),
00111   "zh_CN.UTF-8",     N_("Chinese (Simplified)"),
00112   "zh_TW.UTF-8",        N_("Chinese (Traditional)"),
00113   NULL, NULL
00114 };
00115 
00116 static gchar *timername[] = {
00117   N_("No time limit"),
00118   N_("Slow timer"),
00119   N_("Normal timer"),
00120   N_("Fast timer")
00121 };
00122 
00123 static gchar *screenname[] = {
00124   "640x480",
00125   N_("800x600 (Default for gcompris)"),
00126   "1024x768",
00127 };
00128 
00129 static gchar *filtername[] = {
00130   N_("<i>Use Gcompris administration module\nto filter boards</i>")
00131 };
00132 
00133 static void set_locale_flag(gchar *locale);
00134 static gchar *get_next_locale(gchar *locale);
00135 static gchar *get_previous_locale(gchar *locale);
00136 static gint   item_event_ok(GnomeCanvasItem *item, GdkEvent *event, gpointer data);
00137 static void   display_previous_next(guint x_start, guint y_start,
00138                                 gchar *eventname_previous, gchar *eventname_next);
00139 
00140 
00141 /*
00142  * Do all the bar display and register the events
00143  */
00144 void
00145 gc_config_start ()
00146 {
00147   GcomprisProperties *properties = gc_prop_get();
00148   GdkPixbuf   *pixmap = NULL;
00149   gint y_start = 0;
00150   gint x_start = 0;
00151   gint x_text_start = 0;
00152   gint x_flag_start = 0;
00153   gint y = 0;
00154   GnomeCanvasItem *item, *item2;
00155 
00156   /* Pause the board */
00157   gc_board_pause(TRUE);
00158 
00159   if(rootitem)
00160     return;
00161 
00162   gc_bar_hide(TRUE);
00163 
00164   rootitem = \
00165     gnome_canvas_item_new (gnome_canvas_root(gc_get_canvas()),
00166                         gnome_canvas_group_get_type (),
00167                         "x", (double)0,
00168                         "y", (double)0,
00169                         NULL);
00170 
00171   pixmap = gc_skin_pixmap_load("help_bg.png");
00172   y_start = (BOARDHEIGHT - gdk_pixbuf_get_height(pixmap))/2;
00173   x_start = (BOARDWIDTH - gdk_pixbuf_get_width(pixmap))/2;
00174   item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
00175                             gnome_canvas_pixbuf_get_type (),
00176                             "pixbuf", pixmap,
00177                             "x", (double) x_start,
00178                             "y", (double) y_start,
00179                             NULL);
00180   y = BOARDHEIGHT - (BOARDHEIGHT - gdk_pixbuf_get_height(pixmap))/2;
00181   gdk_pixbuf_unref(pixmap);
00182 
00183   gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
00184                       gnome_canvas_text_get_type (),
00185                       "text", _("GCompris Configuration"),
00186                       "font", gc_skin_font_title,
00187                       "x", (double) BOARDWIDTH/2 + 1.0,
00188                       "y", (double) y_start + 40 + 1.0,
00189                       "anchor", GTK_ANCHOR_CENTER,
00190                       "fill_color_rgba", gc_skin_color_shadow,
00191                       "weight", PANGO_WEIGHT_HEAVY,
00192                       NULL);
00193   gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
00194                       gnome_canvas_text_get_type (),
00195                       "text", _("GCompris Configuration"),
00196                       "font", gc_skin_font_title,
00197                       "x", (double) BOARDWIDTH/2,
00198                       "y", (double) y_start + 40,
00199                       "anchor", GTK_ANCHOR_CENTER,
00200                       "fill_color_rgba", gc_skin_color_title,
00201                       "weight", PANGO_WEIGHT_HEAVY,
00202                       NULL);
00203 
00204   pixmap_checked   = gc_skin_pixmap_load("button_checked.png");
00205   pixmap_unchecked = gc_skin_pixmap_load("button_unchecked.png");
00206 
00207 
00208   x_start += 150;
00209   x_flag_start = x_start + 50;
00210   x_text_start = x_start + 115;
00211 
00212   //--------------------------------------------------
00213   // Locale
00214   y_start += 105;
00215 
00216   display_previous_next(x_start, y_start, "locale_previous", "locale_next");
00217 
00218   item_locale_flag = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
00219                                        gnome_canvas_pixbuf_get_type (),
00220                                        "pixbuf", NULL,
00221                                        "x", (double) x_flag_start,
00222                                        "y", (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2,
00223                                        NULL);
00224 
00225   /* Display a bad icon if this locale is not available */
00226   pixmap   = gc_skin_pixmap_load("mini_bad.png");
00227   item_bad_flag = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
00228                                     gnome_canvas_pixbuf_get_type (),
00229                                     "pixbuf", pixmap,
00230                                     "x", (double) x_flag_start - 20,
00231                                     "y", (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2,
00232                                     NULL);
00233   gdk_pixbuf_unref(pixmap);
00234 
00235   /*
00236    * The current locale is the one found in the config file
00237    */
00238   current_locale = properties->locale;
00239   set_locale_flag(current_locale);
00240 
00241   item_locale_text = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
00242                                        gnome_canvas_text_get_type (),
00243                                        "text", gc_locale_get_name(current_locale),
00244                                        "font", gc_skin_font_subtitle,
00245                                        "x", (double) x_text_start,
00246                                        "y", (double) y_start,
00247                                        "anchor", GTK_ANCHOR_WEST,
00248                                        "fill_color_rgba", gc_skin_color_content,
00249                                        NULL);
00250 
00251   // Fullscreen / Window
00252   y_start += Y_GAP;
00253 
00254   item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
00255                             gnome_canvas_pixbuf_get_type (),
00256                             "pixbuf", (properties->fullscreen ? pixmap_checked : pixmap_unchecked),
00257                             "x", (double) x_start,
00258                             "y", (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2,
00259                             NULL);
00260 
00261   gtk_signal_connect(GTK_OBJECT(item), "event",
00262                    (GtkSignalFunc) item_event_ok,
00263                    "fullscreen");
00264   gtk_signal_connect(GTK_OBJECT(item), "event",
00265                    (GtkSignalFunc) gc_item_focus_event,
00266                    NULL);
00267 
00268 
00269   gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
00270                       gnome_canvas_text_get_type (),
00271                       "text", _("Fullscreen"),
00272                       "font", gc_skin_font_subtitle,
00273                       "x", (double) x_text_start,
00274                       "y", (double) y_start,
00275                       "anchor", GTK_ANCHOR_WEST,
00276                       "fill_color_rgba", gc_skin_color_content,
00277                       NULL);
00278 
00279   // Screen size
00280   y_start += Y_GAP;
00281 
00282   display_previous_next(x_start, y_start, "screen_previous", "screen_next");
00283 
00284   item_screen_text = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
00285                                        gnome_canvas_text_get_type (),
00286                                        "text", gettext(screenname[properties->screensize]),
00287                                        "font", gc_skin_font_subtitle,
00288                                        "x", (double) x_text_start,
00289                                        "y", (double) y_start,
00290                                        "anchor", GTK_ANCHOR_WEST,
00291                                        "fill_color_rgba", gc_skin_color_content,
00292                                        NULL);
00293 
00294   // Music
00295   y_start += Y_GAP;
00296 
00297   item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
00298                             gnome_canvas_pixbuf_get_type (),
00299                             "pixbuf", (properties->music ? pixmap_checked : pixmap_unchecked),
00300                             "x", (double) x_start,
00301                             "y", (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2,
00302                             NULL);
00303 
00304   gtk_signal_connect(GTK_OBJECT(item), "event",
00305                    (GtkSignalFunc) item_event_ok,
00306                    "music");
00307   gtk_signal_connect(GTK_OBJECT(item), "event",
00308                    (GtkSignalFunc) gc_item_focus_event,
00309                    NULL);
00310 
00311 
00312   gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
00313                       gnome_canvas_text_get_type (),
00314                       "text", _("Music"),
00315                       "font", gc_skin_font_subtitle,
00316                       "x", (double) x_text_start,
00317                       "y", (double) y_start,
00318                       "anchor", GTK_ANCHOR_WEST,
00319                       "fill_color_rgba", gc_skin_color_content,
00320                       NULL);
00321 
00322   // Effect
00323   y_start += Y_GAP;
00324 
00325   item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
00326                             gnome_canvas_pixbuf_get_type (),
00327                             "pixbuf", (properties->fx ? pixmap_checked : pixmap_unchecked),
00328                             "x", (double) x_start,
00329                             "y", (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2,
00330                             NULL);
00331 
00332   gtk_signal_connect(GTK_OBJECT(item), "event",
00333                    (GtkSignalFunc) item_event_ok,
00334                    "effect");
00335   gtk_signal_connect(GTK_OBJECT(item), "event",
00336                    (GtkSignalFunc) gc_item_focus_event,
00337                    NULL);
00338 
00339 
00340   gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
00341                       gnome_canvas_text_get_type (),
00342                       "text", _("Effect"),
00343                       "font", gc_skin_font_subtitle,
00344                       "x", (double) x_text_start,
00345                       "y", (double) y_start,
00346                       "anchor", GTK_ANCHOR_WEST,
00347                       "fill_color_rgba", gc_skin_color_content,
00348                       NULL);
00349 
00350   // Timer
00351   y_start += Y_GAP;
00352 
00353   display_previous_next(x_start, y_start, "timer_previous", "timer_next");
00354 
00355   item_timer_text = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
00356                                       gnome_canvas_text_get_type (),
00357                                       "text", gettext(timername[properties->timer]),
00358                                       "font", gc_skin_font_subtitle,
00359                                       "x", (double) x_text_start,
00360                                       "y", (double) y_start,
00361                                       "anchor", GTK_ANCHOR_WEST,
00362                                       "fill_color_rgba", gc_skin_color_content,
00363                                       NULL);
00364 
00365   // Skin
00366   {
00367     const gchar *one_dirent;
00368     guint  i;
00369     GDir  *dir;
00370     gchar *skin_dir;
00371     gchar *first_skin_name;
00372 
00373     /* Load the Pixpmaps directory file names */
00374     skin_dir = g_strconcat(properties->package_data_dir, "/skins", NULL);
00375     dir = g_dir_open(skin_dir, 0, NULL);
00376 
00377     if (!dir)
00378       g_warning (_("Couldn't open skin dir: %s"), skin_dir);
00379 
00380     /* Fill up the skin list */
00381     while((one_dirent = g_dir_read_name(dir)) != NULL) {
00382 
00383       if (one_dirent[0] != '.') {
00384        gchar *filename;
00385        /* Only directory here are skins */
00386        filename = g_strdup_printf("%s/skins/%s", properties->package_data_dir, one_dirent);
00387 
00388        if (g_file_test ((filename), G_FILE_TEST_IS_DIR)) {
00389          gchar *skin_name = g_strdup_printf("%s", one_dirent);
00390          skinlist = g_list_append (skinlist, skin_name);
00391        }
00392        g_free(filename);
00393       }
00394     }
00395     g_dir_close(dir);
00396 
00397     /* Find the current skin index */
00398     skin_index = 0;
00399     for(i=0; i<g_list_length(skinlist);  i++)
00400       if(!strcmp((char *)g_list_nth_data(skinlist, i), properties->skin))
00401        skin_index = i;
00402 
00403     y_start += Y_GAP;
00404 
00405     /* Should not happen. It the user found the config, there should be a skin */
00406     if(g_list_length(skinlist) > 0) {
00407       g_warning("No skin found in %s\n", skin_dir);
00408       display_previous_next(x_start, y_start, "skin_previous", "skin_next");
00409       first_skin_name = g_strdup_printf(_("Skin : %s"), (char *)g_list_nth_data(skinlist, skin_index));
00410     } else {
00411       first_skin_name = g_strdup(_("SKINS NOT FOUND"));
00412     }
00413 
00414     item_skin_text = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
00415                                        gnome_canvas_text_get_type (),
00416                                        "text", first_skin_name,
00417                                        "font", gc_skin_font_subtitle,
00418                                        "x", (double) x_text_start,
00419                                        "y", (double) y_start,
00420                                        "anchor", GTK_ANCHOR_WEST,
00421                                        "fill_color_rgba", gc_skin_color_content,
00422                                        NULL);
00423     g_free(first_skin_name);
00424     g_free(skin_dir);
00425 
00426   }
00427 
00428   // Difficulty Filter
00429   y_start += Y_GAP;
00430 
00431   //  display_previous_next(x_start, y_start, "filter_style_previous", "filter_style_next");
00432 
00433   stars_group_x = x_start + 45;
00434   stars_group_y = y_start - 25;
00435 
00436   item_filter_text = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
00437                                        gnome_canvas_text_get_type (),
00438                                        "markup", gettext(filtername[0]),
00439                                        "font", gc_skin_font_subtitle,
00440                                        "x", (double) x_text_start,
00441                                        "y", (double) y_start,
00442                                        "anchor", GTK_ANCHOR_WEST,
00443                                        "fill_color_rgba", gc_skin_color_content,
00444                                        NULL);
00445 
00446 
00447   // OK
00448   pixmap = gc_skin_pixmap_load("button_large.png");
00449   item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
00450                             gnome_canvas_pixbuf_get_type (),
00451                             "pixbuf", pixmap,
00452                             "x", (double) (BOARDWIDTH*0.5) - gdk_pixbuf_get_width(pixmap)/2,
00453                             "y", (double) y - gdk_pixbuf_get_height(pixmap) - 5,
00454                             NULL);
00455 
00456   gtk_signal_connect(GTK_OBJECT(item), "event",
00457                    (GtkSignalFunc) item_event_ok,
00458                    "ok");
00459   gtk_signal_connect(GTK_OBJECT(item), "event",
00460                    (GtkSignalFunc) gc_item_focus_event,
00461                    NULL);
00462 
00463   gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
00464                       gnome_canvas_text_get_type (),
00465                       "text", _("OK"),
00466                       "font", gc_skin_font_title,
00467                       "x", (double)  BOARDWIDTH*0.5 + 1.0,
00468                       "y", (double)  y - gdk_pixbuf_get_height(pixmap) + 20 + 1.0,
00469                       "anchor", GTK_ANCHOR_CENTER,
00470                       "fill_color_rgba", gc_skin_color_shadow,
00471                       "weight", PANGO_WEIGHT_HEAVY,
00472                       NULL);
00473   item2 = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
00474                              gnome_canvas_text_get_type (),
00475                              "text", _("OK"),
00476                              "font", gc_skin_font_title,
00477                              "x", (double)  BOARDWIDTH*0.5,
00478                              "y", (double)  y - gdk_pixbuf_get_height(pixmap) + 20,
00479                              "anchor", GTK_ANCHOR_CENTER,
00480                              "fill_color_rgba", gc_skin_color_text_button,
00481                              "weight", PANGO_WEIGHT_HEAVY,
00482                              NULL);
00483   gtk_signal_connect(GTK_OBJECT(item2), "event",
00484                    (GtkSignalFunc) item_event_ok,
00485                    "ok");
00486   gtk_signal_connect(GTK_OBJECT(item2), "event",
00487                    (GtkSignalFunc) gc_item_focus_event,
00488                    item);
00489   gdk_pixbuf_unref(pixmap);
00490 
00491 
00492   is_displayed = TRUE;
00493 }
00494 
00495 void gc_config_stop ()
00496 {
00497   // Destroy the help box
00498   if(rootitem!=NULL)
00499     {
00500       gtk_object_destroy(GTK_OBJECT(rootitem));
00501       gc_board_pause(FALSE);
00502     }
00503   rootitem = NULL;
00504 
00505   stars_group = NULL;
00506 
00507   if(pixmap_unchecked)
00508     gdk_pixbuf_unref(pixmap_unchecked);
00509   pixmap_unchecked = NULL;
00510 
00511   if(pixmap_checked)
00512     gdk_pixbuf_unref(pixmap_checked);
00513   pixmap_checked = NULL;
00514 
00515   /* UnPause the board */
00516   if(is_displayed)
00517     gc_board_pause(FALSE);
00518 
00519   gc_bar_hide(FALSE);
00520 
00521   is_displayed = FALSE;
00522 }
00523 
00524 
00529 gchar*
00530 gc_locale_get_name(gchar *locale)
00531 {
00532   guint i = 0;
00533 
00534   /* en (US) is not in the Linguas table */
00535   if(locale[0] != '\0' && !strncmp(locale, "en", strlen(locale)))
00536     return(_("English (United State)"));
00537 
00538   while(linguas[i] != NULL)
00539     {
00540 
00541       if(!strncmp(locale, linguas[i], strlen(locale)))
00542        return(gettext(linguas[i+1]));
00543 
00544       i=i+2;
00545     }
00546   // Oups this locale is not in the table. Return the first one (system default)
00547   return(linguas[1]);
00548 }
00549 
00550 /*-------------------------------------------------------------------------------*/
00551 /*-------------------------------------------------------------------------------*/
00552 /*-------------------------------------------------------------------------------*/
00553 /*-------------------------------------------------------------------------------*/
00554 static void
00555 display_previous_next(guint x_start, guint y_start,
00556                     gchar *eventname_previous, gchar *eventname_next)
00557 {
00558   GdkPixbuf   *pixmap = NULL;
00559   GnomeCanvasItem *item;
00560 
00561   pixmap = gc_skin_pixmap_load("button_backward.png");
00562   item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
00563                             gnome_canvas_pixbuf_get_type (),
00564                             "pixbuf", pixmap,
00565                             "x", (double) x_start - gdk_pixbuf_get_width(pixmap) - 10,
00566                             "y", (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2,
00567                             NULL);
00568 
00569   gtk_signal_connect(GTK_OBJECT(item), "event",
00570                    (GtkSignalFunc) item_event_ok,
00571                    eventname_previous);
00572   gtk_signal_connect(GTK_OBJECT(item), "event",
00573                    (GtkSignalFunc) gc_item_focus_event,
00574                    NULL);
00575   gdk_pixbuf_unref(pixmap);
00576 
00577 
00578   pixmap = gc_skin_pixmap_load("button_forward.png");
00579   item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem),
00580                             gnome_canvas_pixbuf_get_type (),
00581                             "pixbuf", pixmap,
00582                             "x", (double) x_start,
00583                             "y", (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2,
00584                             NULL);
00585 
00586   gtk_signal_connect(GTK_OBJECT(item), "event",
00587                    (GtkSignalFunc) item_event_ok,
00588                    eventname_next);
00589   gtk_signal_connect(GTK_OBJECT(item), "event",
00590                    (GtkSignalFunc) gc_item_focus_event,
00591                    NULL);
00592   gdk_pixbuf_unref(pixmap);
00593 }
00594 
00595 static void
00596 set_locale_flag(gchar *locale)
00597 {
00598   gchar *filename;
00599   GdkPixbuf *pixmap = NULL;
00600 
00601   if(locale == NULL)
00602     return;
00603 
00604   if(locale[0] == '\0') {
00605     /* Set the flag to the default user's locale */
00606     locale = gc_locale_get_user_default();
00607     g_message("gc_locale_get_user_default = %s\n", locale);
00608   }
00609 
00610   /* First try to find a flag for the long locale name */
00611   filename = gc_file_find_absolute("flags/%.5s.png", locale);
00612 
00613   /* Not found, Try now with the short locale name */
00614   if(!filename) {
00615     filename = gc_file_find_absolute("flags/%.2s.png", locale);
00616   }
00617 
00618   if(filename)
00619     {
00620       pixmap = gc_net_load_pixmap(filename);
00621 
00622       gnome_canvas_item_set (item_locale_flag,
00623                           "pixbuf", pixmap,
00624                           NULL);
00625 
00626       gdk_pixbuf_unref(pixmap);
00627       g_free(filename);
00628     }
00629   else
00630     {
00631       /* No flags */
00632       gnome_canvas_item_set (item_locale_flag,
00633                           "pixbuf", NULL,
00634                           NULL);
00635     }
00636 
00637   /* Check wether or not the locale is available */
00638 #ifdef WIN32
00639   /* On win32, it's always available, do not try to check */
00640   gnome_canvas_item_hide (item_bad_flag);
00641 #else
00642   if(setlocale(LC_MESSAGES, locale)==NULL)
00643     gnome_canvas_item_show (item_bad_flag);
00644   else
00645     gnome_canvas_item_hide (item_bad_flag);
00646 #endif
00647 
00648 }
00649 
00650 
00654 static gchar *
00655 get_next_locale(gchar *locale)
00656 {
00657   guint i = 0;
00658 
00659   while(linguas[i] != NULL)
00660     {
00661       if(!strcmp(locale, linguas[i]))
00662        {
00663          // Found it
00664          if(linguas[i+2]!=NULL)
00665            return(linguas[i+2]);
00666          else
00667            return(linguas[0]);
00668 
00669        }
00670       i=i+2;
00671     }
00672   // Oups this locale is not in the table. Return the first one
00673   return(linguas[0]);
00674 }
00675 
00679 static gchar *
00680 get_previous_locale(gchar *locale)
00681 {
00682   guint i = 0;
00683 
00684   while(linguas[i] != NULL)
00685     {
00686       if(!strcmp(locale, linguas[i]))
00687        {
00688          // Found it
00689          if(i!=0)
00690            return(linguas[i-2]);
00691          else
00692            {
00693              // Go to the end of the list
00694              while(linguas[i]!=NULL) { i=i+2; };
00695              return(linguas[i-2]);
00696            }
00697        }
00698       i=i+2;
00699     }
00700   return(locale);
00701 }
00702 
00703 /* Callback for the bar operations */
00704 static gint
00705 item_event_ok(GnomeCanvasItem *item, GdkEvent *event, gpointer data)
00706 {
00707   GcomprisProperties *properties = gc_prop_get();
00708 
00709   if(data==NULL)
00710     return FALSE;
00711 
00712   switch (event->type)
00713     {
00714     case GDK_ENTER_NOTIFY:
00715       break;
00716     case GDK_LEAVE_NOTIFY:
00717       break;
00718     case GDK_BUTTON_PRESS:
00719       if(!strcmp((char *)data, "ok"))
00720        {
00721          /* Set the new locale in the properties */
00722          if (properties->locale != current_locale)
00723            {
00724              g_free(properties->locale);
00725              properties->locale = strdup(current_locale);
00726            }
00727 
00728          if(current_locale[0] == '\0') {
00729            /* Set the locale to the default user's locale */
00730            gc_locale_set(gc_locale_get_user_default());
00731          } else {
00732            gc_locale_set(current_locale);
00733          }
00734          g_free(properties->skin);
00735          properties->skin = g_strdup((char *)g_list_nth_data(skinlist, skin_index));
00736          gc_skin_load(properties->skin);
00737          gc_config_stop();
00738 
00739          if(properties->music || properties->fx)
00740            gc_sound_init();
00741 
00742          if(!properties->music && !properties->fx)
00743            gc_sound_close();
00744          else
00745            {
00746              if(!properties->music)
00747               sdlplayer_halt_music();
00748              else
00749               sdlplayer_resume_music();
00750 
00751              if(!properties->fx)
00752               sdlplayer_halt_fx();
00753              else
00754               sdlplayer_resume_fx();
00755            }
00756          gc_prop_save(properties);
00757        }
00758       else if(!strcmp((char *)data, "fullscreen"))
00759        {
00760          properties->fullscreen = (properties->fullscreen ? 0 : 1);
00761 
00762 #ifdef XF86_VIDMODE
00763          /* Changing screen without xrandr is more complex, it requires to remove the
00764             black border we created manually.
00765          */
00766          if(!properties->noxf86vm)
00767            gc_fullscreen_set(properties->fullscreen);
00768 #endif
00769          /* Warning changing the image needs to update pixbuf_ref for the focus usage */
00770          gc_item_focus_free(item, NULL);
00771          gnome_canvas_item_set (item,
00772                              "pixbuf", (properties->fullscreen ? pixmap_checked : pixmap_unchecked),
00773                              NULL);
00774 
00775        }
00776       else if(!strcmp((char *)data, "music"))
00777        {
00778          properties->music = (properties->music ? 0 : 1);
00779          /* Warning changing the image needs to update pixbuf_ref for the focus usage */
00780          gc_item_focus_free(item, NULL);
00781          gnome_canvas_item_set (item,
00782                              "pixbuf", (properties->music ? pixmap_checked : pixmap_unchecked),
00783                              NULL);
00784          if(!properties->music)
00785            {
00786              sdlplayer_halt_music();
00787            }
00788          else
00789            {
00790              gc_sound_init();
00791              sdlplayer_resume_music();
00792            }
00793        }
00794       else if(!strcmp((char *)data, "effect"))
00795        {
00796          properties->fx = (properties->fx ? 0 : 1);
00797          /* Warning changing the image needs to update pixbuf_ref for the focus usage */
00798          gc_item_focus_free(item, NULL);
00799          gnome_canvas_item_set (item,
00800                              "pixbuf", (properties->fx ? pixmap_checked : pixmap_unchecked),
00801                              NULL);
00802 
00803 
00804        }
00805       else if(!strcmp((char *)data, "locale_previous"))
00806        {
00807          current_locale = get_previous_locale(current_locale);
00808          gnome_canvas_item_set (item_locale_text,
00809                              "text", gc_locale_get_name(current_locale),
00810                              NULL);
00811          set_locale_flag(current_locale);
00812        }
00813       else if(!strcmp((char *)data, "locale_next"))
00814        {
00815          current_locale = get_next_locale(current_locale);
00816          gnome_canvas_item_set (item_locale_text,
00817                              "text", gc_locale_get_name(current_locale),
00818                              NULL);
00819 
00820          set_locale_flag(current_locale);
00821        }
00822       else if(!strcmp((char *)data, "screen_previous"))
00823        {
00824          if(properties->screensize>0)
00825            properties->screensize--;
00826 
00827          gnome_canvas_item_set (item_screen_text,
00828                              "text", gettext(screenname[properties->screensize]),
00829                              NULL);
00830        }
00831       else if(!strcmp((char *)data, "screen_next"))
00832        {
00833          if(properties->screensize<MAX_SCREEN_VALUE)
00834            properties->screensize++;
00835 
00836          gnome_canvas_item_set (item_screen_text,
00837                              "text", gettext(screenname[properties->screensize]),
00838                              NULL);
00839        }
00840       else if(!strcmp((char *)data, "timer_previous"))
00841        {
00842          if(properties->timer>0)
00843            properties->timer--;
00844 
00845          gnome_canvas_item_set (item_timer_text,
00846                              "text", gettext(timername[properties->timer]),
00847                              NULL);
00848        }
00849       else if(!strcmp((char *)data, "timer_next"))
00850        {
00851          if(properties->timer<MAX_TIMER_VALUE)
00852            properties->timer++;
00853 
00854          gnome_canvas_item_set (item_timer_text,
00855                              "text", gettext(timername[properties->timer]),
00856                              NULL);
00857        }
00858       else if(!strcmp((char *)data, "skin_previous"))
00859        {
00860          gchar *skin_str;
00861          if(skin_index-- < 1)
00862            skin_index = g_list_length(skinlist)-1;
00863 
00864          skin_str = g_strdup_printf(_("Skin : %s"),
00865                                  (char *)g_list_nth_data(skinlist, skin_index));
00866 
00867          gnome_canvas_item_set (item_skin_text,
00868                              "text", skin_str,
00869                              NULL);
00870          g_free(skin_str);
00871        }
00872       else if(!strcmp((char *)data, "skin_next"))
00873        {
00874          gchar *skin_str;
00875          if(skin_index++ >= g_list_length(skinlist)-1)
00876            skin_index = 0;
00877 
00878          skin_str = g_strdup_printf(_("Skin : %s"),
00879                                  (char *)g_list_nth_data(skinlist, skin_index));
00880          gnome_canvas_item_set (item_skin_text,
00881                              "text", skin_str,
00882                              NULL);
00883          g_free(skin_str);
00884        }
00885     default:
00886       break;
00887     }
00888   return FALSE;
00889 
00890 }