diff options
author | Bruno Coudoin <bcoudoin@src.gnome.org> | 2009-01-30 21:29:10 (GMT) |
---|---|---|
committer | Bruno Coudoin <bcoudoin@src.gnome.org> | 2009-01-30 21:29:10 (GMT) |
commit | bfad4f36c3177697c4280648703e7982249e9f0d (patch) | |
tree | 3b5c0b7bbf4d513c450bdbc5f05b535afc745466 /src/gcompris | |
parent | 82f8cd260494e0c2e119db6911965d1c7def881b (diff) |
Missing files from Miguel
svn path=/trunk/; revision=3701
Diffstat (limited to 'src/gcompris')
-rw-r--r-- | src/gcompris/board_config_combo.c | 553 | ||||
-rw-r--r-- | src/gcompris/board_config_common.c | 55 | ||||
-rw-r--r-- | src/gcompris/board_config_common.h | 39 | ||||
-rw-r--r-- | src/gcompris/board_config_radio.c | 161 | ||||
-rw-r--r-- | src/gcompris/board_config_textview.c | 281 | ||||
-rw-r--r-- | src/gcompris/board_config_wordlist.c | 254 |
6 files changed, 1343 insertions, 0 deletions
diff --git a/src/gcompris/board_config_combo.c b/src/gcompris/board_config_combo.c new file mode 100644 index 0000000..7fe3e52 --- /dev/null +++ b/src/gcompris/board_config_combo.c @@ -0,0 +1,553 @@ +/* gcompris - board_config_combo.c + * + * Copyright (C) 2009 Miguel De Izarra + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + + +#include "board_config.h" +#include "board_config_common.h" +#include <string.h> + +/***********************************************/ +/* L10n */ +/***********************************************/ + +/** \brief return the list of locales in which GCompris has been translated + * even partialy. + * + * \note The list is calculated at the first call and must not be freed. + * Uppon next call, the same list is returned. + * + * \return a list containing the locales we suport + */ +GList* +gc_locale_gets_list(){ + + static GList *gcompris_locales_list = NULL; + + GcomprisProperties *properties = gc_prop_get(); + GDir *textdomain_dir; + GError **error = NULL; + GList *locales = NULL; + + if(gcompris_locales_list) + return(gcompris_locales_list); + + /* There is no english locale but it exists anyway */ + locales = g_list_append(locales, g_strdup("en")); + + textdomain_dir = g_dir_open (properties->package_locale_dir, 0, error); + const gchar *fname; + gchar *fname_abs; + gchar *catalog; + + if(textdomain_dir) { + while ((fname = g_dir_read_name(textdomain_dir))) { + fname_abs = g_strdup_printf("%s/%s", properties->package_locale_dir, fname); + if (!g_file_test(fname_abs, G_FILE_TEST_IS_DIR)) + continue; + + catalog = g_strdup_printf("%s/LC_MESSAGES/gcompris.mo", fname_abs); + + if (g_file_test(catalog, G_FILE_TEST_EXISTS)){ + locales = g_list_append(locales, g_strdup(fname)); + } + g_free (fname_abs); + g_free(catalog); + } + g_dir_close (textdomain_dir); + } + +#if DEBUG /* to find locales list when run from src directory */ + if(g_file_test("po", G_FILE_TEST_IS_DIR)) + { + textdomain_dir= g_dir_open("po",0, error); + while((fname = g_dir_read_name(textdomain_dir))) + { + if(g_str_has_suffix(fname,".po")) + locales = g_list_append(locales, g_strndup(fname,2)); + } + g_dir_close(textdomain_dir); + + } +#endif + /* Save it for next call */ + gcompris_locales_list = locales; + + return locales; +} + + +void +gc_board_config_combo_locales_changed(GtkComboBox *combobox, + gpointer data) +{ + _gc_boardconf_key*u = (_gc_boardconf_key*)data; + gchar *the_key = g_strdup((gchar *)u->key); + gchar *value; + gint index = gtk_combo_box_get_active (combobox); + + if (index == 0) + /* Default value of gcompris selected */ + value = g_strdup ("NULL"); + else + value = _get_active_text (combobox); + + g_hash_table_replace(u->config->hash_conf, (gpointer) the_key, (gpointer) value); +} + +/* key = "locale" */ +GtkComboBox* +gc_board_config_combo_locales(GcomprisBoardConf *config, gchar *init) +{ + g_return_val_if_fail(config, NULL); + GtkWidget *combobox; + GtkWidget *hbox = gtk_hbox_new (FALSE, 8); + GList *list, *strings; + GtkWidget *label_combo; + gint init_index = 0; + + strings = gc_locale_gets_list(); + + strings = g_list_prepend( strings, _("Default")); + + if (init) + init_index = g_list_position(strings, + g_list_find_custom(strings, + (gconstpointer) init, + (GCompareFunc) strcmp)); + + if (init_index < 0) + init_index=0; + + gtk_widget_show(hbox); + + gtk_box_pack_start (GTK_BOX(config->main_conf_box), + hbox, + FALSE, + FALSE, + 0); + + /* Label */ + label_combo = gtk_label_new ((gchar *)NULL); + gtk_widget_show(label_combo); + gtk_box_pack_start (GTK_BOX(hbox), + label_combo, + FALSE, + FALSE, + 0); + + gtk_label_set_justify (GTK_LABEL(label_combo), + GTK_JUSTIFY_RIGHT); + + gtk_label_set_markup (GTK_LABEL(label_combo), + _("Select the language\n to use in the board")); + + combobox = gtk_combo_box_new_text(); + + gtk_widget_show(combobox); + + gtk_box_pack_start (GTK_BOX(hbox), + combobox, + FALSE, + FALSE, + 0); + + + for (list = strings; list != NULL; list = list->next) + gtk_combo_box_append_text (GTK_COMBO_BOX(combobox), + list->data); + + if (g_list_length(strings) > COMBOBOX_COL_MAX) + gtk_combo_box_set_wrap_width (GTK_COMBO_BOX(combobox), + g_list_length(strings) / COMBOBOX_COL_MAX +1 ); + + gtk_combo_box_set_active (GTK_COMBO_BOX(combobox), + init_index); + _gc_boardconf_key *u = g_malloc0(sizeof(_gc_boardconf_key)); + u -> key = g_strdup("locale"); + u -> config = config; + g_signal_connect(G_OBJECT(combobox), + "changed", + G_CALLBACK(gc_board_config_combo_locales_changed), + u); + g_signal_connect(G_OBJECT(combobox), + "destroy", + G_CALLBACK(_gc_destroy_boardconf_key), + u); + + return GTK_COMBO_BOX(combobox); + +} + +void +gc_board_config_combo_drag_changed(GtkComboBox *combobox, + gpointer data) +{ + _gc_boardconf_key *u = (_gc_boardconf_key*)data; + gchar *the_key = g_strdup((gchar *)u->key); + gchar *value; + gint index = gtk_combo_box_get_active (combobox); + + if (index == 0) + /* Default value of gcompris selected */ + value = g_strdup ("NULL"); + else + value = g_strdup_printf("%d", index); + + g_hash_table_replace(u->config->hash_conf, (gpointer) the_key, (gpointer) value); +} + +/* key = "locale" */ +GtkComboBox* +gc_board_config_combo_drag(GcomprisBoardConf *config, gint init) +{ + g_return_val_if_fail(config, NULL); + GtkWidget *combobox; + GtkWidget *hbox = gtk_hbox_new (FALSE, 8); + GList *list, *strings; + GtkWidget *label_combo; + gint init_index; + + strings = NULL; + + strings = g_list_prepend( strings, _("Global GCompris mode")); + strings = g_list_append( strings, _("Normal")); + strings = g_list_append( strings, _("2 clicks")); + strings = g_list_append( strings, _("both modes")); + + if (init < 0) + init_index =0; + else + init_index = init; + + gtk_widget_show(hbox); + + gtk_box_pack_start (GTK_BOX(config->main_conf_box), + hbox, + FALSE, + FALSE, + 0); + + /* Label */ + label_combo = gtk_label_new ((gchar *)NULL); + gtk_widget_show(label_combo); + gtk_box_pack_start (GTK_BOX(hbox), + label_combo, + FALSE, + FALSE, + 0); + + gtk_label_set_justify (GTK_LABEL(label_combo), + GTK_JUSTIFY_RIGHT); + + gtk_label_set_markup (GTK_LABEL(label_combo), + _("Select the drag and drop mode\n to use in the board")); + + combobox = gtk_combo_box_new_text(); + + gtk_widget_show(combobox); + + gtk_box_pack_start (GTK_BOX(hbox), + combobox, + FALSE, + FALSE, + 0); + + + for (list = strings; list != NULL; list = list->next) + gtk_combo_box_append_text (GTK_COMBO_BOX(combobox), + list->data); + + if (g_list_length(strings) > COMBOBOX_COL_MAX) + gtk_combo_box_set_wrap_width (GTK_COMBO_BOX(combobox), + g_list_length(strings) / COMBOBOX_COL_MAX +1 ); + + gtk_combo_box_set_active (GTK_COMBO_BOX(combobox), + init_index); + _gc_boardconf_key *u = g_malloc0(sizeof(_gc_boardconf_key)); + u->key = g_strdup("drag_mode"); + u->config = config; + + g_signal_connect(G_OBJECT(combobox), + "changed", + G_CALLBACK(gc_board_config_combo_drag_changed), + u); + g_signal_connect(G_OBJECT(combobox), + "destroy", + G_CALLBACK(_gc_destroy_boardconf_key), + u); + return GTK_COMBO_BOX(combobox); + +} + +static gchar *current_locale = NULL; +void +gc_locale_change(gchar *locale) +{ + if (!locale) + return; + + if (strcmp(locale, "NULL") == 0){ + gc_locale_reset(); + return; + } + + current_locale = g_strdup(gc_locale_get()); + + gc_locale_set(locale); +} + +void +gc_locale_reset() +{ + if (current_locale == NULL) + return; + + gc_locale_change(current_locale); + + g_free(current_locale); + current_locale = NULL; +} + + +/** \brief Search the given file for each locale and returns the locale list + * + * \param file: the file to search. In order to work, you need to provide a + * filename that includes a $LOCALE in it like: + * voices/$LOCALE/colors/blue.ogg + * + * \return a list of locale + */ +GList* +gc_locale_gets_asset_list(const gchar *filename) +{ + GList *locales, *list, *locales_asset = NULL; + gchar *abs_filename; + + locales = gc_locale_gets_list(); + + for (list = locales; list != NULL; list = list->next) + { + gchar **tmp; + + /* Check there is a $LOCALE to replace */ + if((tmp = g_strsplit(filename, "$LOCALE", -1))) + { + gchar locale[6]; + gchar *filename2; + + /* try with the locale */ + g_strlcpy(locale, list->data, sizeof(locale)); + filename2 = g_strjoinv(locale, tmp); + g_warning("trying locale file '%s'\n", filename2); + abs_filename = gc_file_find_absolute(filename2); + g_free(filename2); + + g_strfreev(tmp); + } + else + { + abs_filename = gc_file_find_absolute(filename); + } + + if(abs_filename) + { + /* It would be cleaner to provide the real locale name but then we need a way + * to get back the locale code from it's name and from the boards + * + * locales_asset = g_list_append(locales_asset, gc_locale_get_name(list->data)); + * + */ + locales_asset = g_list_append(locales_asset, list->data); + g_free(abs_filename); + } + } + + + return locales_asset; +} + +/* key = "locale_sound" */ +GtkComboBox *gc_board_config_combo_locales_asset(GcomprisBoardConf *config, const gchar *label, + gchar *init, + const gchar *file) +{ + g_return_val_if_fail(config, NULL); + GtkWidget *combobox; + GtkWidget *hbox = gtk_hbox_new (FALSE, 8); + GList *list, *strings; + GtkWidget *label_combo; + gint init_index = 0; + + strings = gc_locale_gets_asset_list(file); + + strings = g_list_prepend( strings, _("Default")); + + if (init) + { + init_index = g_list_position(strings, + g_list_find_custom(strings, + (gconstpointer)init, + (GCompareFunc) strcmp)); + } + + if (init_index < 0) + init_index=0; + + gtk_widget_show(hbox); + + gtk_box_pack_start (GTK_BOX(config->main_conf_box), + hbox, + FALSE, + FALSE, + 0); + + /* Label */ + label_combo = gtk_label_new ((gchar *)NULL); + gtk_widget_show(label_combo); + gtk_box_pack_start (GTK_BOX(hbox), + label_combo, + FALSE, + FALSE, + 0); + + gtk_label_set_justify (GTK_LABEL(label_combo), + GTK_JUSTIFY_RIGHT); + + gtk_label_set_markup (GTK_LABEL(label_combo), + label); + + combobox = gtk_combo_box_new_text(); + + gtk_widget_show(combobox); + + gtk_box_pack_start (GTK_BOX(hbox), + combobox, + FALSE, + FALSE, + 0); + + + for (list = strings; list != NULL; list = list->next) + gtk_combo_box_append_text(GTK_COMBO_BOX(combobox), + list->data); + + if (g_list_length(strings) > COMBOBOX_COL_MAX) + gtk_combo_box_set_wrap_width(GTK_COMBO_BOX(combobox), + g_list_length(strings) / COMBOBOX_COL_MAX +1 ); + + gtk_combo_box_set_active (GTK_COMBO_BOX(combobox), + init_index); + + g_signal_connect(G_OBJECT(combobox), + "changed", + G_CALLBACK(gc_board_config_combo_locales_changed), + "locale_sound"); + + return GTK_COMBO_BOX(combobox); + +} + +static void +_combo_box_changed(GtkComboBox *combobox, + gpointer data) +{ + _gc_boardconf_key *u = (_gc_boardconf_key*)data; + gchar *the_key = g_strdup(u->key); + + gchar *value = g_strdup_printf("%s", _get_active_text (combobox)); + + g_hash_table_replace(u->config->hash_conf, (gpointer) the_key, (gpointer) value); +} + + +GtkComboBox *gc_board_config_combo_box(GcomprisBoardConf *config, const gchar *label, GList *strings, gchar *key, gchar *init) +{ + g_return_val_if_fail(config, NULL); + check_key(key); + GtkWidget *combobox; + GtkWidget *hbox = gtk_hbox_new (FALSE, 8); + GList *list; + GtkWidget *label_combo; + gint init_index = 0; + + if (init) + init_index = g_list_position ( strings, g_list_find_custom ( strings,(gconstpointer) init, (GCompareFunc) strcmp)); + + if (init_index < 0) + init_index=0; + + gtk_widget_show(hbox); + + gtk_box_pack_start (GTK_BOX(config->main_conf_box), + hbox, + FALSE, + FALSE, + 0); + + /* Label */ + label_combo = gtk_label_new ((gchar *)NULL); + gtk_widget_show(label_combo); + gtk_box_pack_start (GTK_BOX(hbox), + label_combo, + FALSE, + FALSE, + 0); + + gtk_label_set_justify (GTK_LABEL(label_combo), + GTK_JUSTIFY_RIGHT); + + gtk_label_set_markup (GTK_LABEL(label_combo), + (const gchar *)label); + + + combobox = gtk_combo_box_new_text(); + + gtk_widget_show(combobox); + + gtk_box_pack_start (GTK_BOX(hbox), + combobox, + FALSE, + FALSE, + 0); + + + for (list = strings; list != NULL; list = list->next) + gtk_combo_box_append_text (GTK_COMBO_BOX(combobox), + list->data); + + if (g_list_length(strings) > COMBOBOX_COL_MAX) + gtk_combo_box_set_wrap_width (GTK_COMBO_BOX(combobox), + g_list_length(strings) / COMBOBOX_COL_MAX +1 ); + + gtk_combo_box_set_active (GTK_COMBO_BOX(combobox), + init_index); + _gc_boardconf_key *u = g_malloc0(sizeof(_gc_boardconf_key)); + u -> key = g_strdup(key); + u -> config = config; + g_signal_connect(G_OBJECT(combobox), + "changed", + G_CALLBACK(_combo_box_changed), + u); + g_signal_connect(G_OBJECT(combobox), + "destroy", + G_CALLBACK(_gc_destroy_boardconf_key), + u); + + return GTK_COMBO_BOX(combobox); +} + diff --git a/src/gcompris/board_config_common.c b/src/gcompris/board_config_common.c new file mode 100644 index 0000000..de9eef7 --- /dev/null +++ b/src/gcompris/board_config_common.c @@ -0,0 +1,55 @@ +/* gcompris - board_config_common.c + * + * Copyright (C) 2009 Miguel De Izarra + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +/* code get from gtk */ +/* included here to not depend on gtk 2.6 */ + +#include "gcompris.h" +#include "board_config_common.h" +#include <string.h> + +gchar *_get_active_text (GtkComboBox *combo_box) +{ + GtkTreeIter iter; + gchar *text = NULL; + + g_return_val_if_fail (GTK_IS_LIST_STORE (gtk_combo_box_get_model (combo_box)), NULL); + + if (gtk_combo_box_get_active_iter (combo_box, &iter)) + gtk_tree_model_get (gtk_combo_box_get_model (combo_box), &iter, + 0, &text, -1); + + return text; +} + +void check_key(gchar *key) +{ + if ((strcmp(key, "locale") == 0) || + (strcmp(key, "locale_sound") == 0) || + (strcmp(key, "wordlist") == 0)) + g_error(" Key %s forbiden ! Change !", key); +} + +void _gc_destroy_boardconf_key(GtkWidget *widget, gpointer data) +{ + _gc_boardconf_key *u = (_gc_boardconf_key*)data; + g_free(u->key); + g_free(u); +} + + diff --git a/src/gcompris/board_config_common.h b/src/gcompris/board_config_common.h new file mode 100644 index 0000000..f807fa2 --- /dev/null +++ b/src/gcompris/board_config_common.h @@ -0,0 +1,39 @@ +/* gcompris - board_config_common.h + * + * Copyright (C) 2009 Miguel De Izarra + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + + +#ifndef BOARD_CONFIG_COMMON_H +#define BOARD_CONFIG_COMMON_H + +gchar *_get_active_text (GtkComboBox *combo_box); + +void check_key(gchar *key); + +typedef struct +{ + gchar *key; + GcomprisBoardConf *config; +} _gc_boardconf_key; + +void _gc_destroy_boardconf_key(GtkWidget*w, gpointer data); + + +#define COMBOBOX_COL_MAX 15 + +#endif + diff --git a/src/gcompris/board_config_radio.c b/src/gcompris/board_config_radio.c new file mode 100644 index 0000000..555bdd3 --- /dev/null +++ b/src/gcompris/board_config_radio.c @@ -0,0 +1,161 @@ +/* gcompris - board_config_radio.c + * + * Copyright (C) 2009 Miguel De Izarra + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +#include "board_config.h" +#include "board_config_common.h" +#include <string.h> + +typedef struct +{ +GcomprisBoardConf *config; +GHashTable *hash_radio; +gchar *key; +GSList *radio_group ; +GtkWidget *radio_box; +gchar *radio_key; +gchar *radio_init; +} Gconfig_radio; + +static void radio_changed(GtkToggleButton *togglebutton, + gpointer data) +{ + gboolean state = gtk_toggle_button_get_active (togglebutton); + Gconfig_radio *u = (Gconfig_radio*)data; + gchar *h_key; + gchar *h_value; + + if (state){ + h_key = g_strdup (u->radio_key); + h_value = g_strdup((gchar *) u->key); + g_hash_table_replace (u->config->hash_conf, h_key, h_value); + } +} + +static void radio_destroy(GtkWidget*w, gpointer data) +{ + Gconfig_radio *u = (Gconfig_radio*)data; + + /* simply free key and Gconfig_radio */ + g_free(u->key); + g_free(u); +} + +static void +create_radio_buttons(gpointer key, + gpointer value, + gpointer data) +{ + Gconfig_radio * u = (Gconfig_radio*)data; + Gconfig_radio *u_copy; + GtkWidget *radio_button; + + radio_button = gtk_radio_button_new_with_label (u->radio_group, + (const gchar *) g_strdup(value)); + + gtk_box_pack_start (GTK_BOX (u->radio_box), radio_button, TRUE, TRUE, 2); + + gtk_widget_show (GTK_WIDGET (radio_button)); + + u->radio_group = gtk_radio_button_get_group (GTK_RADIO_BUTTON (radio_button)); + + /* make a copy of Gconfig_radio, and set key */ + u_copy = g_memdup(u,sizeof(Gconfig_radio)); + u_copy->key = g_strdup ((gchar *)key); + + if (strcmp(u_copy->key, u->radio_init)==0) + gtk_toggle_button_set_active (GTK_TOGGLE_BUTTON(radio_button),TRUE); + + g_signal_connect(G_OBJECT(radio_button), + "toggled", + G_CALLBACK(radio_changed), + (gpointer) u_copy); + g_signal_connect(G_OBJECT(radio_button), + "destroy", + G_CALLBACK(radio_destroy), + (gpointer) u_copy); + g_hash_table_replace ( u->hash_radio, (gpointer) u_copy->key, (gpointer) radio_button); +} + +static void +radio_box_destroy(GtkObject *object, + gpointer data) +{ + Gconfig_radio *u = (Gconfig_radio*) data; + g_hash_table_destroy(u->hash_radio); + u->radio_group = NULL; + g_free(u->radio_key); + g_free(u->radio_init); + g_free(u); +} + +GHashTable * +gc_board_config_radio_buttons(GcomprisBoardConf *conf, const gchar *label, + gchar *key, + GHashTable *buttons_label, + gchar *init) +{ + g_return_val_if_fail(conf, NULL); + check_key( key); + + GtkWidget *radio_label; + + GHashTable *buttons = g_hash_table_new_full (g_str_hash, + g_str_equal, + g_free, + NULL); + Gconfig_radio *u = g_malloc0(sizeof(Gconfig_radio)); + u->hash_radio = buttons; + + u->radio_box = gtk_vbox_new (TRUE, 2); + gtk_widget_show (GTK_WIDGET (u->radio_box)); + + gtk_box_pack_start (GTK_BOX(conf->main_conf_box), + u->radio_box, + FALSE, + FALSE, + 0); + + radio_label = gtk_label_new ((gchar *)NULL); + gtk_widget_show(radio_label); + + gtk_box_pack_start (GTK_BOX(u->radio_box), + radio_label, + FALSE, + FALSE, + 0); + + gtk_label_set_justify (GTK_LABEL(radio_label), + GTK_JUSTIFY_CENTER); + + gchar * radio_text = g_strdup(label); + gtk_label_set_markup (GTK_LABEL(radio_label), + (const gchar *)radio_text); + g_free(radio_text); + + u->radio_key = g_strdup(key); + u->radio_init = g_strdup(init); + + g_hash_table_foreach( buttons_label, + (GHFunc) create_radio_buttons, + (gpointer) buttons); + + g_signal_connect (G_OBJECT(u->radio_box), "destroy", G_CALLBACK(radio_box_destroy), (gpointer) u); + + return buttons; +} + diff --git a/src/gcompris/board_config_textview.c b/src/gcompris/board_config_textview.c new file mode 100644 index 0000000..38cd255 --- /dev/null +++ b/src/gcompris/board_config_textview.c @@ -0,0 +1,281 @@ +/* gcompris - board_config_textview.c + * + * Copyright (C) 2009 Miguel De Izarra + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + + +#include "board_config.h" + +/****************************************/ +/* TextView */ + +typedef struct { + gchar *key; + GcomprisTextCallback callback; + GtkLabel *feedback; + GtkTextBuffer *TextBuffer; + GcomprisBoardConf *config; +} user_param_type; + +static void * +_textview_destroy (GtkButton *button, + gpointer user_data) +{ + g_free(((user_param_type *)user_data)->key); + g_free(user_data); + + return NULL; +} + + +static void * +_textbuffer_changed (GtkTextBuffer *buffer, + gpointer user_data) +{ + gtk_widget_set_sensitive (GTK_WIDGET(user_data), + TRUE); + + return NULL; +} + +static void * +_textview_yes (GtkButton *button, + gpointer user_data) +{ + + user_param_type *params= (user_param_type *) user_data; + + gchar *key = params->key; + GcomprisTextCallback validate = params->callback; + GtkLabel *label = params->feedback; + GtkTextBuffer *text_buffer = params->TextBuffer; + + GtkTextIter start_iter; + GtkTextIter end_iter; + + gtk_text_buffer_get_start_iter (text_buffer, + &start_iter); + + gtk_text_buffer_get_end_iter (text_buffer, + &end_iter); + + /* has this to be freed ? */ + gchar *text = gtk_text_buffer_get_slice (text_buffer, + &start_iter, + &end_iter, + TRUE); + + + + gchar *in_memoriam_text = g_strdup (text); + gchar *in_memoriam_key = g_strdup (key); + + if (validate( key, text, label)){ + g_hash_table_replace (params->config->hash_conf, (gpointer) in_memoriam_key, (gpointer) in_memoriam_text); + gtk_widget_set_sensitive (GTK_WIDGET(button), + FALSE); + } + else { + g_free (in_memoriam_text); + g_free (in_memoriam_key); + } + g_free(text); + + return NULL; +} + +GtkTextView * +gc_board_config_textview(GcomprisBoardConf *config, + const gchar *label, + gchar *key, + const gchar*description, + gchar *init_text, + GcomprisTextCallback validate) +{ + g_return_val_if_fail(config, NULL); + GtkWidget*frame = gtk_frame_new ("GCompris text tool"); + gtk_widget_show(frame); + + gtk_box_pack_start (GTK_BOX(config->main_conf_box), + frame, + FALSE, + FALSE, + 8); + + + + /* Main vbox for all our widegt */ + GtkWidget *textVbox = gtk_vbox_new ( FALSE, 8); + gtk_widget_show(textVbox); + + gtk_container_add(GTK_CONTAINER(frame), + textVbox); + /* Title */ + GtkWidget *title = gtk_label_new ((gchar *)NULL); + gtk_widget_show(title); + + gtk_box_pack_start (GTK_BOX(textVbox), + title, + FALSE, + FALSE, + 8); + + gtk_label_set_justify (GTK_LABEL(title), + GTK_JUSTIFY_CENTER); + + gchar *title_text = g_strdup(label); + gtk_label_set_markup (GTK_LABEL(title), + (const gchar *)title_text); + + GtkWidget *separator = gtk_hseparator_new (); + + gtk_widget_show(separator); + + gtk_box_pack_start (GTK_BOX(textVbox), + separator, + FALSE, + FALSE, + 0); + + /* Description */ + GtkWidget *desc = gtk_label_new ((gchar *)NULL); + gtk_widget_show(desc); + + gtk_box_pack_start (GTK_BOX(textVbox), + desc, + FALSE, + FALSE, + 0); + + //gtk_label_set_justify (GTK_LABEL(title), + // GTK_JUSTIFY_CENTER); + + gtk_label_set_line_wrap(GTK_LABEL(desc), TRUE); + + gchar *desc_text = g_strdup(description); + gtk_label_set_markup (GTK_LABEL(desc), + (const gchar *)desc_text); + + GtkWidget *scroll = gtk_scrolled_window_new ( NULL, NULL); + + + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(scroll), + GTK_POLICY_AUTOMATIC, + GTK_POLICY_AUTOMATIC); + + gtk_widget_set_size_request (scroll, + -1, + 100); + + gtk_widget_show( scroll); + + gtk_box_pack_start (GTK_BOX(textVbox), + scroll, + FALSE, + FALSE, + 0); + + /* TextView */ + GtkWidget *textView = gtk_text_view_new (); + gtk_widget_show(textView); + + gtk_container_add (GTK_CONTAINER(scroll), + textView); + + gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (textView), GTK_WRAP_WORD_CHAR); + + + GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (textView)); + + gtk_text_buffer_set_text (buffer, g_strdup(init_text), -1); + + + /* hbox for feedback and validation button */ + GtkWidget *validationHbox = gtk_vbox_new ( FALSE, 8); + gtk_widget_show(validationHbox); + + gtk_box_pack_start (GTK_BOX(textVbox), + validationHbox, + FALSE, + FALSE, + 0); + + /* Feedback */ + GtkWidget *feedback = gtk_label_new ((gchar *)NULL); + gtk_widget_show(feedback); + + gtk_box_pack_start (GTK_BOX(validationHbox), + feedback, + FALSE, + FALSE, + 0); + + gtk_label_set_justify (GTK_LABEL(title), + GTK_JUSTIFY_FILL); + + gtk_label_set_line_wrap(GTK_LABEL(feedback), TRUE); + + user_param_type *user_param = g_malloc0(sizeof(user_param_type)); + + user_param->key = g_strdup(key); + user_param->callback = validate; + user_param->feedback = GTK_LABEL(feedback); + user_param->TextBuffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW(textView)); + user_param->config = config; + + + /* vbox for feedback and validation button */ + GtkWidget *validationVbox = gtk_hbox_new ( FALSE, 8); + gtk_widget_show(validationVbox); + + gtk_box_pack_end (GTK_BOX(validationHbox), + validationVbox, + FALSE, + FALSE, + 0); + + + /* Validate button */ + GtkWidget *button = gtk_button_new_from_stock (GTK_STOCK_YES); + gtk_widget_show(button); + gtk_box_pack_end (GTK_BOX(validationVbox), + button, + FALSE, + FALSE, + 0); + + g_signal_connect(G_OBJECT(button), + "clicked", + G_CALLBACK(_textview_yes), + (gpointer) user_param); + + + g_signal_connect(G_OBJECT(button), + "destroy", + G_CALLBACK(_textview_destroy), + (gpointer) user_param); + + g_signal_connect(G_OBJECT(user_param->TextBuffer), + "changed", + G_CALLBACK(_textbuffer_changed), + (gpointer) button); + + gtk_widget_set_sensitive (button, + FALSE); + + return GTK_TEXT_VIEW(textView); +} + diff --git a/src/gcompris/board_config_wordlist.c b/src/gcompris/board_config_wordlist.c new file mode 100644 index 0000000..c0dd7c1 --- /dev/null +++ b/src/gcompris/board_config_wordlist.c @@ -0,0 +1,254 @@ +/* gcompris - board_config_wordlist.c + * + * Copyright (C) 2009 Miguel De Izarra + * + * 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 3 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, see <http://www.gnu.org/licenses/>. + */ + +#include "gcompris.h" +#include "board_config_common.h" +#include <string.h> + +typedef struct { + GtkComboBox *combo_lang, *combo_level; + GtkTextView *textview; + GtkButton *button; + const gchar *files; + GcomprisWordlist *wordlist; +} user_param_type_wordlist; + +static void _combo_level_changed(GtkComboBox *combo_level, gpointer user_data) +{ + LevelWordlist *lw; + GSList *list; + gchar **wordsArray, *text; + guint level; + int i; + user_param_type_wordlist *w = (user_param_type_wordlist*)user_data; + GtkTextBuffer *buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (w->textview)); + + level = gtk_combo_box_get_active(combo_level)+1; + + lw = gc_wordlist_get_levelwordlist(w->wordlist, level); + if(!lw) + { + gtk_text_buffer_set_text(buffer, "", -1); + gtk_widget_set_sensitive(GTK_WIDGET(w->button), FALSE); + return; + } + + wordsArray = g_malloc0(sizeof(gpointer)*(g_slist_length(lw->words)+1)); + + for(i=0, list = lw->words; list; list=list->next) + { + wordsArray[i]=(gchar*)list->data; + i++; + } + text = g_strjoinv(" ", wordsArray); + g_free(wordsArray); + + gtk_text_buffer_set_text (buffer, g_strdup(text), -1); + g_free(text); + gtk_widget_set_sensitive(GTK_WIDGET(w->button), FALSE); +} + +static void _combo_lang_changed(GtkComboBox *combo_lang, gpointer user_data) +{ + user_param_type_wordlist *w = (user_param_type_wordlist*)user_data; + gchar * lang, *filename, *temp, **tmp; + int i; + + if(gtk_combo_box_get_active(combo_lang)<0) + return; + /* get the filename of the xml */ + lang =_get_active_text(combo_lang); + if((tmp = g_strsplit(w->files, "$LOCALE", -1))) + { + filename = g_strjoinv(lang, tmp); + g_strfreev(tmp); + } + else + filename = g_strdup(w->files); + g_free(lang); + + /* clear combo level entry */ + if(w->wordlist) + { + gtk_list_store_clear(GTK_LIST_STORE(gtk_combo_box_get_model (w->combo_level))); + gc_wordlist_free(w->wordlist); + } + /* load wordlist */ + w->wordlist = gc_wordlist_get_from_file(filename); + g_free(filename); + + /* combo level */ + for(i=1; i <= w->wordlist->number_of_level; i++) + { + if((temp = g_strdup_printf("%d", i))) + { + gtk_combo_box_append_text(w->combo_level,temp); + g_free(temp); + } + } + + /* add a new level*/ + if((temp = g_strdup_printf(_("%d (New level)"), i))) + { + gtk_combo_box_append_text(w->combo_level,temp); + g_free(temp); + } + gtk_combo_box_set_active(w->combo_level, 0); + _combo_level_changed(w->combo_level, (gpointer)w); +} + +static void _textview_changed(GtkWidget *w, gpointer data) +{ + user_param_type_wordlist *u = (user_param_type_wordlist*)data; + gtk_widget_set_sensitive(GTK_WIDGET(u->button), TRUE); +} + +static void _button_clicked(GtkWidget *w, gpointer data) +{ + user_param_type_wordlist *u = (user_param_type_wordlist*)data; + int level; + gchar *text; + GtkTextBuffer *buffer; + GtkTextIter start_iter, end_iter; + + level = gtk_combo_box_get_active(u->combo_level)+1; + buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (u->textview)); + + gtk_text_buffer_get_start_iter(buffer, &start_iter); + gtk_text_buffer_get_end_iter(buffer, &end_iter); + text = gtk_text_buffer_get_slice(buffer, &start_iter, &end_iter, TRUE); + gc_wordlist_set_wordlist(u->wordlist, level, text); + g_free(text); + gc_wordlist_save(u->wordlist); + _combo_lang_changed(u->combo_lang, u); + gtk_combo_box_set_active(u->combo_level, level-1); + _combo_level_changed(u->combo_level, u); +} + +static void _destroy(GtkWidget *w, gpointer data) +{ + user_param_type_wordlist *u = (user_param_type_wordlist*)data; + + gc_wordlist_free(u->wordlist); + g_free(u); +} + +/* wordlist edit */ +GtkWidget *gc_board_config_wordlist(GcomprisBoardConf *config, const gchar *files) +{ + g_return_val_if_fail(config, NULL); + GtkWidget *combo_lang, *combo_level, *label; + GtkWidget *hbox, *vbox, *frame; + GtkWidget *textview; + GtkWidget *button; + GList *file_list, *list; + user_param_type_wordlist *user_data; + const gchar *locale; + + /* frame */ + frame = gtk_frame_new("Change wordlist"); + gtk_widget_show(frame); + gtk_box_pack_start(GTK_BOX(config->main_conf_box), frame, FALSE, FALSE, 8); + + vbox = gtk_vbox_new(FALSE, 8); + gtk_widget_show(vbox); + + gtk_container_add(GTK_CONTAINER(frame), vbox); + /* Combo_box lang */ + combo_lang = gtk_combo_box_new_text(); + + locale = gc_locale_get(); + file_list = gc_locale_gets_asset_list(files); + for(list = file_list; list; list = list->next) + { + gtk_combo_box_append_text(GTK_COMBO_BOX(combo_lang), list->data); + if(strncmp((char*)list->data, locale,2)==0) + { + gtk_combo_box_set_active(GTK_COMBO_BOX(combo_lang), g_list_position(file_list, list)); + } + } + if (g_list_length(file_list) > COMBOBOX_COL_MAX) + gtk_combo_box_set_wrap_width (GTK_COMBO_BOX(combo_lang), + g_list_length(file_list) / COMBOBOX_COL_MAX +1 ); + + g_list_free(file_list); + + gtk_widget_show(combo_lang); + hbox = gtk_hbox_new(FALSE, 8); + label = gtk_label_new(_("Choice language")); + gtk_widget_show(label); + gtk_widget_show(hbox); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 8); + gtk_box_pack_start(GTK_BOX(hbox), combo_lang, FALSE, FALSE, 8); + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 8); + + /* Combo_box level */ + combo_level = gtk_combo_box_new_text(); + + gtk_widget_show(combo_level); + hbox = gtk_hbox_new(FALSE, 8); + label = gtk_label_new(_("Choice level")); + gtk_widget_show(label); + gtk_widget_show(hbox); + gtk_box_pack_start(GTK_BOX(hbox), label, FALSE, FALSE, 8); + gtk_box_pack_start(GTK_BOX(hbox), combo_level, FALSE, FALSE, 8); + gtk_box_pack_start(GTK_BOX(vbox), hbox, FALSE, FALSE, 8); + + /* scroll and Textview */ + GtkWidget *scroll = gtk_scrolled_window_new ( NULL, NULL); + gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW(scroll), + GTK_POLICY_AUTOMATIC, GTK_POLICY_AUTOMATIC); + gtk_widget_set_size_request(scroll, -1, 100); + gtk_widget_show( scroll); + gtk_box_pack_start(GTK_BOX(vbox), scroll, FALSE, FALSE, 8); + + textview = gtk_text_view_new(); + gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (textview), GTK_WRAP_WORD_CHAR); + gtk_widget_show(textview); + gtk_container_add (GTK_CONTAINER(scroll), textview); + + /* valid button */ + button = gtk_button_new_from_stock(GTK_STOCK_APPLY); + gtk_widget_show(button); + gtk_widget_set_sensitive(button, FALSE); + gtk_box_pack_start(GTK_BOX(vbox), button, FALSE, FALSE, 8); + + /* user_data */ + user_data = g_malloc0(sizeof(user_param_type_wordlist)); + user_data -> combo_lang = GTK_COMBO_BOX(combo_lang); + user_data -> combo_level = GTK_COMBO_BOX(combo_level); + user_data -> textview = GTK_TEXT_VIEW(textview); + user_data -> button = GTK_BUTTON(button); + user_data -> files = files; + + g_signal_connect(G_OBJECT(combo_lang), "changed", + G_CALLBACK(_combo_lang_changed), (gpointer)user_data); + g_signal_connect(G_OBJECT(combo_level), "changed", + G_CALLBACK(_combo_level_changed), (gpointer)user_data); + g_signal_connect(G_OBJECT(combo_lang), "destroy", + G_CALLBACK(_destroy), (gpointer)user_data); + g_signal_connect(G_OBJECT(gtk_text_view_get_buffer(user_data->textview)), "changed", + G_CALLBACK(_textview_changed), (gpointer)user_data); + g_signal_connect(G_OBJECT(button), "clicked", + G_CALLBACK(_button_clicked), (gpointer)user_data); + + + _combo_lang_changed(GTK_COMBO_BOX(combo_lang), user_data); + return NULL; +} + |