diff options
author | Bruno Coudoin <bcoudoin@src.gnome.org> | 2006-09-25 21:20:26 (GMT) |
---|---|---|
committer | Bruno Coudoin <bcoudoin@src.gnome.org> | 2006-09-25 21:20:26 (GMT) |
commit | bf2de288b1b4ad09aa43a75f6edf42d7e97ab8ae (patch) | |
tree | d9bfa67c79650afcddba950221eb3fef39d08d18 | |
parent | bb62b10e9c2bfbe6ec720f42ad407082c154b939 (diff) |
- fixed missing config.h.mingw.in (that replaces config.h.mingw)
- added support for python plugin compilation under mingw
- improved wordprocessor activity. it no more crashes and allow
two styles, on for the layout, one for the color (on an idea
of my daughter Clara)
- This activity could be moved out of --experimental now but
we are in string freeze.
- Added a double switch in electricity. It is now possible to make
a 2 switches corridor like circuit (va et vient in french).
- config.c : fixed a double memory free on locale that crashed GC at exit time.
- file_selector.c: fixed mime type loading and display. now uses gettext instead of
inline xml translation.
- menu.c: fixed a misplaced free that makes all board description in the database to be junk
-rw-r--r-- | ChangeLog | 51 | ||||
-rw-r--r-- | Makefile.mingw | 9 | ||||
-rw-r--r-- | boards/electric/switch2_icon.png | bin | 0 -> 3324 bytes | |||
-rw-r--r-- | boards/electric/switch2_off.png | bin | 0 -> 2494 bytes | |||
-rw-r--r-- | boards/electric/switch2_on.png | bin | 0 -> 2419 bytes | |||
-rw-r--r-- | boards/gcompris/mimetypes/Makefile.am | 3 | ||||
-rw-r--r-- | config.h.mingw.in | 129 | ||||
-rw-r--r-- | src/boards/python/electric.py | 163 | ||||
-rw-r--r-- | src/boards/wordprocessor.c | 291 | ||||
-rw-r--r-- | src/gcompris/config.c | 69 | ||||
-rw-r--r-- | src/gcompris/file_selector.c | 94 | ||||
-rw-r--r-- | src/gcompris/gameutil.c | 47 | ||||
-rw-r--r-- | src/gcompris/gcompris.c | 14 | ||||
-rw-r--r-- | src/gcompris/gcompris_db.c | 773 | ||||
-rw-r--r-- | src/gcompris/menu.c | 107 | ||||
-rw-r--r-- | src/gcompris/properties.c | 2 |
16 files changed, 1105 insertions, 647 deletions
@@ -1,3 +1,54 @@ +2006-09-25 Bruno coudoin <bruno.coudoin@free.fr> + + - fixed missing config.h.mingw.in (that replaces config.h.mingw) + - added support for python plugin compilation under mingw + - improved wordprocessor activity. it no more crashes and allow + two styles, on for the layout, one for the color (on an idea + of my daughter Clara) + - This activity could be moved out of --experimental now but + we are in string freeze. + - Added a double switch in electricity. It is now possible to make + a 2 switches corridor like circuit (va et vient in french). + - config.c : fixed a double memory free on locale that crashed GC at exit time. + - file_selector.c: fixed mime type loading and display. now uses gettext instead of + inline xml translation. + - menu.c: fixed a misplaced free that makes all board description in the database to be junk. + + * Makefile.mingw: + * boards/gcompris/mimetypes/Makefile.am: + * config.h.mingw.in: + * src/boards/python/electric.py: + * src/boards/wordprocessor.c: (wordprocessor_create), + (display_style_buttons), (item_event), (create_tags), + (set_default_style), (display_style_selector), + (display_color_style_selector), (tag_style_set), + (item_event_style_selection), (item_event_color_style_selection), + (key_press_event): + * src/gcompris/config.c: (gc_config_start), (gc_config_stop), + (display_previous_next), (get_next_locale), (get_previous_locale), + (item_event_ok): + * src/gcompris/file_selector.c: (gc_selector_file_stop), + (display_file_selector), (display_files), (item_event_directory), + (item_event_scroll), (item_event_file_selector), (parseMime), + (parse_doc), (load_mime_type_from_file), (gc_mime_type_load): + * src/gcompris/gameutil.c: (gc_pixmap_load), (gc_item_focus_set), + (reactivate_newline), (gc_item_rotate_relative), + (gc_difficulty_display), (g_utf8_strndup), (gc_file_find_absolute): + * src/gcompris/gcompris.c: (board_widget_key_press_callback): + * src/gcompris/gcompris_db.c: (gc_db_init), (gc_db_set_date), + (gc_db_set_version), (gc_db_check_boards), (gc_db_board_update), + (gc_menu_load_db), (gc_db_get_board_id), (gc_db_remove_board), + (gc_db_get_profile_from_id), (gc_db_profile_from_name_get), + (gc_db_get_profile), (gc_db_users_from_group_get), + (gc_db_get_user_from_id), (gc_db_get_class_from_id), + (gc_db_set_board_conf), (gc_db_conf_with_table_get), + (gc_db_get_board_conf), (gc_db_profiles_list_get), + (gc_db_get_group_from_id), (gc_db_get_groups_list), + (gc_db_get_board_from_id), (gc_db_get_users_list), + (gc_db_get_classes_list), (gc_db_is_activity_in_profile): + * src/gcompris/menu.c: (_add_xml_to_data), (gc_menu_load): + * src/gcompris/properties.c: (gc_prop_destroy): + 2006-09-23 Bruno coudoin <bruno.coudoin@free.fr> - Start of support of python plugin on window. diff --git a/Makefile.mingw b/Makefile.mingw index 1cbe99e..6c7739a 100644 --- a/Makefile.mingw +++ b/Makefile.mingw @@ -18,7 +18,6 @@ LIBXML2_TOP := /libxml2 SDL_TOP := /sdl CANVAS_TOP := /gnomecanvas GNUCHESS_TOP := /gnuchess -PYTHON_TOP := /c/Python24 MAKENSIS := "/c/Program Files/NSIS/makensis.exe" @@ -55,11 +54,9 @@ NEEDED_DLLS = $(GNUCHESS_TOP)/bin/pthreadGC.dll \ $(GTK_TOP)/expat/bin/xmlparse.dll \ $(GTK_TOP)/expat/bin/xmltok.dll \ $(GTK_TOP)/bin/iconv.dll \ - $(GTK_TOP)/bin/libpng13.dll \ - $(GTK_TOP)/bin/jpeg62.dll \ - $(GTK_TOP)/bin/libcairo-2.dll \ - $(GTK_TOP)/bin/libpangocairo-1.0-0.dll \ - /c/WINDOWS/system32/python24.dll + $(GTK_TOP)/bin/intl.dll \ + $(GTK_TOP)/bin/libpng12.dll \ + $(GTK_TOP)/bin/jpeg62.dll NEEDED_FILES = README \ COPYING \ diff --git a/boards/electric/switch2_icon.png b/boards/electric/switch2_icon.png Binary files differnew file mode 100644 index 0000000..8e88924 --- /dev/null +++ b/boards/electric/switch2_icon.png diff --git a/boards/electric/switch2_off.png b/boards/electric/switch2_off.png Binary files differnew file mode 100644 index 0000000..0d2fd27 --- /dev/null +++ b/boards/electric/switch2_off.png diff --git a/boards/electric/switch2_on.png b/boards/electric/switch2_on.png Binary files differnew file mode 100644 index 0000000..48c541d --- /dev/null +++ b/boards/electric/switch2_on.png diff --git a/boards/gcompris/mimetypes/Makefile.am b/boards/gcompris/mimetypes/Makefile.am index b739aeb..36589b6 100644 --- a/boards/gcompris/mimetypes/Makefile.am +++ b/boards/gcompris/mimetypes/Makefile.am @@ -14,5 +14,4 @@ $(xml_DATA): %.xml: %.xml.in sed -e "s/\(\<\)\/*_//g" $< > $@ - - +CLEANFILES = $(xml_DATA) diff --git a/config.h.mingw.in b/config.h.mingw.in new file mode 100644 index 0000000..fdbbb29 --- /dev/null +++ b/config.h.mingw.in @@ -0,0 +1,129 @@ +/* config.h. Generated by configure. */ +/* config.h.in. Generated from configure.in by autoheader. */ + +/* Version number of package */ +#define VERSION "@VERSION@" + +/* Supported languages */ +#define ALL_LINGUAS "am ar az bg ca cs da de el en_CA en_GB es et fi fr ga gu he hi hr hu it lt mk ml ms nl nb nn pa pl pt pt_BR ro ru sk sl sq sr sr@Latn sv tr wa zh_CN" + +/* Global assetml directory */ +#define ASSETML_DIR "share/assetml" + +/* "Enable debug messages." */ +/* #undef DEBUG */ + +/* always defined to indicate that i18n is enabled */ +/* #undef ENABLE_NLS */ + +/* Gettext package name */ +#define GETTEXT_PACKAGE "gcompris" + +/* Defines where GNU Chess resides on the system */ +#define GNUCHESS "gnuchess.exe" + +/* Define to 1 if you have the `bind_textdomain_codeset' function. */ +/* #undef HAVE_BIND_TEXTDOMAIN_CODESET */ + +/* Define to 1 if you have the `dcgettext' function. */ +/* #undef HAVE_DCGETTEXT */ + +/* Define to 1 if you have the <dirent.h> header file, and it defines `DIR'. + */ +#define HAVE_DIRENT_H 1 + +/* Define to 1 if you have the <dlfcn.h> header file. */ +/* #undef HAVE_DLFCN_H */ + +/* Define if the GNU gettext() function is already present or preinstalled. */ +/* #undef HAVE_GETTEXT */ + +/* Define if you have the iconv() function. */ +/* #undef HAVE_ICONV */ + +/* Define to 1 if you have the <inttypes.h> header file. */ +#define HAVE_INTTYPES_H 1 + +/* Define if your <locale.h> file defines LC_MESSAGES. */ +/* #undef HAVE_LC_MESSAGES */ + +/* Define to 1 if you have the `popt' library (-lpopt). */ +#define HAVE_LIBPOPT 1 + +/* Define to 1 if you have the `SDL_mixer' library (-lSDL_mixer). */ +#define HAVE_LIBSDL_MIXER 1 + +/* Define to 1 if you have the <locale.h> header file. */ +#define HAVE_LOCALE_H 1 + +/* Define to 1 if you have the <memory.h> header file. */ +#define HAVE_MEMORY_H 1 + +/* Define to 1 if you have the <ndir.h> header file, and it defines `DIR'. */ +/* #undef HAVE_NDIR_H */ + +/* Define to 1 if you have the <stdint.h> header file. */ +#define HAVE_STDINT_H 1 + +/* Define to 1 if you have the <stdlib.h> header file. */ +#define HAVE_STDLIB_H 1 + +/* Define to 1 if you have the <strings.h> header file. */ +#define HAVE_STRINGS_H 1 + +/* Define to 1 if you have the <string.h> header file. */ +#define HAVE_STRING_H 1 + +/* Define to 1 if you have the <sys/dir.h> header file, and it defines `DIR'. + */ +/* #undef HAVE_SYS_DIR_H */ + +/* Define to 1 if you have the <sys/ndir.h> header file, and it defines `DIR'. + */ +/* #undef HAVE_SYS_NDIR_H */ + +/* Define to 1 if you have the <sys/stat.h> header file. */ +#define HAVE_SYS_STAT_H 1 + +/* Define to 1 if you have the <sys/types.h> header file. */ +#define HAVE_SYS_TYPES_H 1 + +/* Define to 1 if you have the <unistd.h> header file. */ +#define HAVE_UNISTD_H 1 + +/* Define as const if the declaration of iconv() needs const. */ +/* #undef ICONV_CONST */ + +/* Name of package */ +#define PACKAGE "gcompris" + +/* Define to the address where bug reports for this package should be sent. */ +#define PACKAGE_BUGREPORT "" + +/* Gcompris data directory */ +#define PACKAGE_DATA_DIR "share" + +/* Gcompris plugins directory (not needed, static compile on windows) */ +#define PACKAGE_CLIB_DIR "" + +/* Gcompris help directory */ +#define PACKAGE_HELP_DIR "share/gnome/help/gcompris" + +/* Gcompris locale directory */ +#define PACKAGE_LOCALE_DIR "share/locale" + +/* Define to the full name of this package. */ +#define PACKAGE_NAME "" + +/* Define to the full name and version of this package. */ +#define PACKAGE_STRING "" + +/* Define to the one symbol short name of this package. */ +#define PACKAGE_TARNAME "" + +/* Define to the version of this package. */ +#define PACKAGE_VERSION "" + +/* Define to 1 if you have the ANSI C header files. */ +#define STDC_HEADERS 1 + diff --git a/src/boards/python/electric.py b/src/boards/python/electric.py index 611ea80..27e651e 100644 --- a/src/boards/python/electric.py +++ b/src/boards/python/electric.py @@ -32,7 +32,7 @@ import os import tempfile # Set to True to debug -debug = False +debug = True from gcompris import gcompris_gettext as _ @@ -280,6 +280,7 @@ class Gcompris_electric: (Bulb, 0.11), (Rheostat, 1000), (Switch, None), + (Switch2, None), (Connection, None), ) elif(level == 3): @@ -730,11 +731,13 @@ class Component(object): self.center_x = pixmap.get_width()/2 self.center_y = pixmap.get_height()/2 + self.component_item_offset_x = 0 + self.component_item_offset_y = 0 self.component_item = self.comp_rootitem.add( gnome.canvas.CanvasPixbuf, pixbuf = pixmap, - x = self.x, - y = self.y, + x = self.x + self.component_item_offset_x, + y = self.y + self.component_item_offset_y, ) self.component_item.connect("event", self.component_move, self) @@ -780,8 +783,8 @@ class Component(object): self.item_values.set(x = self.item_values_x + self.x, y = self.item_values_y + self.y) - self.component_item.set(x = self.x, - y = self.y) + self.component_item.set(x = self.x + self.component_item_offset_x, + y = self.y + self.component_item_offset_y ) for node in self.nodes: node.move( self.x, self.y) @@ -1058,6 +1061,156 @@ class Switch(Component): return True # ---------------------------------------- +# SWITCH2 +# +# +class Switch2(Component): + image = "electric/switch2_on.png" + icon = "electric/switch2_icon.png" + def __init__(self, electric, + x, y, dummy): + self.click_ofset_x = 22 + self.click_ofset_y = -28 + self.gnucap_current_resistor = 1 + self.gnucap_nb_resistor = 0 + self.value_on = "0" + self.value_off = "10000k" + self.value_top = self.value_on + self.value_bottom = self.value_off + + super(Switch2, self).__init__(electric, + "R", + self.value_off, + self.image, + [Node("electric/connect.png", "C", -15, 0), + Node("electric/connect.png", "A", 80, -25), + Node("electric/connect.png", "B", 80, 25)]) + + # Overide some values + self.item_values.hide() + + self.move(x, y) + + pixmap = gcompris.utils.load_pixmap("electric/switch_click.png") + self.click_item = self.comp_rootitem.add( + gnome.canvas.CanvasPixbuf, + pixbuf = pixmap, + x = self.x + self.click_ofset_x, + y = self.y + self.click_ofset_y, + ) + self.click_item.connect("event", self.component_click) + self.show() + + + # Callback event on the switch + def component_click(self, widget, event): + if event.state & gtk.gdk.BUTTON1_MASK: + if(self.value_top == self.value_off): + self.value_top = self.value_on + self.value_bottom = self.value_off + self.component_item_offset_y = - 6 + pixmap = gcompris.utils.load_pixmap("electric/switch2_on.png") + else: + self.value_top = self.value_off + self.value_bottom = self.value_on + self.component_item_offset_y = 10 + pixmap = gcompris.utils.load_pixmap("electric/switch2_off.png") + + self.component_item.set(y = self.y + self.component_item_offset_y) + self.component_item.set(pixbuf = pixmap) + self.electric.run_simulation() + + return False + + # Callback event to move the component + def component_move(self, widget, event, component): + super(Switch2, self).component_move(widget, event, component) + + if(self.electric.get_current_tools()=="DEL"): + return True + + self.click_item.set( + x = self.x + self.click_ofset_x, + y = self.y + self.click_ofset_y) + + return True + + # Return True if this component is connected and can provides a gnucap + # description + # + # The switch2 needs at least 2 connected nodes + # + def is_connected(self): + count = 0 + for node in self.nodes: + if node.get_wires(): + count += 1 + + if count >= 2: + return True + + return False + + # Return the gnucap definition for a single resitor of the switch2 + # node_id1 and node_id2 are the index in the list of nodes + def to_gnucap_res(self, gnucap_name, node_id1, node_id2, gnucap_value): + gnucap = gnucap_name + gnucap += " " + + for i in (node_id1, node_id2): + node = self.nodes[i] + if node.get_wires(): + gnucap += str(node.get_wires()[0].get_wire_id()) + + gnucap += " " + + gnucap += " " + gnucap += str(gnucap_value) + gnucap += "\n" + gnucap += ".print dc + v(%s) i(%s)\n" %(gnucap_name, gnucap_name) + + return gnucap + + # Return the gnucap definition for this component + # depending of the connected nodes, it create one or two resistor + def to_gnucap(self, model): + + gnucap = "" + + # reset set_voltage_intensity counter + self.gnucap_current_resistor = 0 + self.gnucap_nb_resistor = 0 + + # top resistor + if self.nodes[0].get_wires() and \ + self.nodes[1].get_wires(): + gnucap += self.to_gnucap_res(self.gnucap_name + "_top", 0, 1, + self.value_top) + self.gnucap_nb_resistor += 1 + + # bottom resistor + if self.nodes[0].get_wires() and \ + self.nodes[2].get_wires(): + gnucap += self.to_gnucap_res(self.gnucap_name + "_bot", 0, 2, + self.value_bottom) + self.gnucap_nb_resistor += 1 + + return gnucap + + # Return False if we need more value to complete our component + # This is usefull in case where one Component is made of several gnucap component + def set_voltage_intensity(self, valid_value, voltage, intensity): + # Never show values + self.item_values.hide() + + self.gnucap_current_resistor += 1 + + if(self.gnucap_nb_resistor == self.gnucap_current_resistor): + return True + else: + return False + +# ---------------------------------------- # RHEOSTAT # # diff --git a/src/boards/wordprocessor.c b/src/boards/wordprocessor.c index d8610ce..41c6f49 100644 --- a/src/boards/wordprocessor.c +++ b/src/boards/wordprocessor.c @@ -36,32 +36,90 @@ typedef struct { gint indent; gint pixels_above_lines; gint pixels_below_lines; - gchar *foreground; } style_t; -static style_t doctype_default[] = +#define NUMBER_OF_STYLE 4 + +static GtkTextTag *tag_list[NUMBER_OF_STYLE]; + + +/* + * The document styles + */ +typedef struct { + gchar *name; + style_t style[NUMBER_OF_STYLE]; +} doctype_t; + +doctype_t type_normal = + { + .name = N_("Default"), + .style = { + { "H0", "Serif 30", PANGO_WEIGHT_ULTRABOLD, GTK_JUSTIFY_CENTER, 0, 40, 20 }, + { "H1", "Serif 26", PANGO_WEIGHT_BOLD, GTK_JUSTIFY_LEFT, 0, 30, 15 }, + { "H2", "Serif 20", PANGO_WEIGHT_SEMIBOLD, GTK_JUSTIFY_LEFT, 0, 20, 12 }, + { "P", "Serif 16", PANGO_WEIGHT_NORMAL, GTK_JUSTIFY_LEFT, 30, 3, 3 } + } + }; + +doctype_t type_letter = { - { "H0", "Serif 30", PANGO_WEIGHT_ULTRABOLD, GTK_JUSTIFY_CENTER, 0, 40, 20, "black"}, - { "H1", "Serif 26", PANGO_WEIGHT_BOLD, GTK_JUSTIFY_LEFT, 0, 30, 15, "black" }, - { "H2", "Serif 20", PANGO_WEIGHT_SEMIBOLD, GTK_JUSTIFY_LEFT, 0, 20, 12, "black" }, - { "P", "Serif 16", PANGO_WEIGHT_NORMAL, GTK_JUSTIFY_LEFT, 30, 3, 3, "black" } + .name = N_("Letter"), + .style = { + { "H0", "Serif 26", PANGO_WEIGHT_ULTRABOLD, GTK_JUSTIFY_CENTER, 0, 40, 20 }, + { "H1", "Serif 20", PANGO_WEIGHT_BOLD, GTK_JUSTIFY_LEFT, 0, 30, 15 }, + { "H2", "Serif 16", PANGO_WEIGHT_SEMIBOLD, GTK_JUSTIFY_LEFT, 0, 20, 12 }, + { "P", "Serif 14", PANGO_WEIGHT_NORMAL, GTK_JUSTIFY_LEFT, 30, 3, 3 } + }, }; -#define NUMBER_OF_STYLE G_N_ELEMENTS(doctype_default) -static style_t doctype_love_letter[] = +doctype_t type_small = { - { "Hx0", "Serif 30", PANGO_WEIGHT_ULTRABOLD, GTK_JUSTIFY_CENTER, 0, 40, 20, "DeepPink" }, - { "Hx1", "Serif 26", PANGO_WEIGHT_BOLD, GTK_JUSTIFY_LEFT, 0, 30, 15, "HotPink" }, - { "Hx2", "Serif 20", PANGO_WEIGHT_SEMIBOLD, GTK_JUSTIFY_LEFT, 0, 20, 12, "MediumOrchid" }, - { "Px", "Serif 16", PANGO_WEIGHT_NORMAL, GTK_JUSTIFY_LEFT, 30, 3, 3, "black" } + .name = N_("Small"), + .style = { + { "H0", "Serif 18", PANGO_WEIGHT_ULTRABOLD, GTK_JUSTIFY_CENTER, 0, 40, 20 }, + { "H1", "Serif 16", PANGO_WEIGHT_BOLD, GTK_JUSTIFY_LEFT, 0, 30, 15 }, + { "H2", "Serif 14", PANGO_WEIGHT_SEMIBOLD, GTK_JUSTIFY_LEFT, 0, 20, 12 }, + { "P", "Serif 12", PANGO_WEIGHT_NORMAL, GTK_JUSTIFY_LEFT, 30, 3, 3 } + }, }; -static style_t *doctype_list[] = +doctype_t type_text = { - doctype_default, - doctype_love_letter + .name = N_("Text"), + .style = { + { "H0", "Serif 12", PANGO_WEIGHT_ULTRABOLD, GTK_JUSTIFY_CENTER, 0, 40, 20 }, + { "H1", "Serif 12", PANGO_WEIGHT_BOLD, GTK_JUSTIFY_LEFT, 0, 30, 15 }, + { "H2", "Serif 12", PANGO_WEIGHT_SEMIBOLD, GTK_JUSTIFY_LEFT, 0, 20, 12 }, + { "P", "Serif 12", PANGO_WEIGHT_NORMAL, GTK_JUSTIFY_LEFT, 30, 3, 3 } + }, }; +doctype_t type_big = + { + .name = N_("Big"), + .style = { + { "H0", "Serif 34", PANGO_WEIGHT_ULTRABOLD, GTK_JUSTIFY_CENTER, 0, 40, 20 }, + { "H1", "Serif 30", PANGO_WEIGHT_BOLD, GTK_JUSTIFY_LEFT, 0, 30, 15 }, + { "H2", "Serif 26", PANGO_WEIGHT_SEMIBOLD, GTK_JUSTIFY_LEFT, 0, 20, 12 }, + { "P", "Serif 18", PANGO_WEIGHT_NORMAL, GTK_JUSTIFY_LEFT, 30, 3, 3 } + }, + }; +#define NUMBER_OF_DOCTYPE 5 +static doctype_t *doctype_list[NUMBER_OF_DOCTYPE]; + +/* + * The color styles + */ +#define NUMBER_OF_COLOR_STYLE 4 +static gchar *color_style_list[NUMBER_OF_COLOR_STYLE][NUMBER_OF_STYLE+1] = +{ + {N_("Black"), "black", "black", "black", "black"}, + {N_("Red"), "red", "blue", "light blue", "black"}, + {N_("Blue"), "blue", "red", "light blue", "black"}, + {N_("Pink"), "DeepPink", "HotPink", "MediumOrchid", "black"}, +}; + static GcomprisBoard *gcomprisBoard = NULL; static gboolean board_paused = TRUE; static GtkWidget *gtk_combo_filetypes = NULL; @@ -79,27 +137,33 @@ static GnomeCanvasGroup *boardRootItem = NULL; static GnomeCanvasItem *wordprocessor_create(void); static void wordprocessor_destroy_all_items(void); static gint item_event(GnomeCanvasItem *item, GdkEvent *event, gpointer data); -static void display_style_buttons(GnomeCanvasGroup *boardRootItem, +static void display_style_buttons(GnomeCanvasGroup *boardRootItem, int x, int y); -static void create_tags (GtkTextBuffer *buffer, style_t style[]); +static void create_tags (GtkTextBuffer *buffer, doctype_t *doctype); static void set_default_style (GtkTextBuffer *buffer, style_t *style); static void display_style_selector(GnomeCanvasGroup *boardRootItem); -static void item_event_style_selection (GtkComboBox *widget, void *styles_tab[]); +static void display_color_style_selector(GnomeCanvasGroup *boardRootItem); +static void item_event_style_selection (GtkComboBox *widget, void *data); +static void item_event_color_style_selection (GtkComboBox *widget, void *data); #define word_area_x1 120 #define word_area_y1 80 #define word_area_width 580 #define word_area_height 420 -#define combo_style_x1 500 +#define combo_style_x1 300 #define combo_style_y1 20 +#define combo_style_width 200 + +#define combo_color_style_x1 500 +#define combo_color_style_y1 20 +#define combo_color_style_width 200 static style_t *current_style_default; -static style_t **current_doctype_default; +static doctype_t *current_doctype_default; static GtkTextBuffer *buffer; static GtkWidget *view; -static GHashTable* styles_hash = NULL; /* Description of this plugin */ static BoardPlugin menu_bp = @@ -230,11 +294,11 @@ static GnomeCanvasItem *wordprocessor_create() view = gtk_text_view_new (); gtk_text_view_set_wrap_mode (GTK_TEXT_VIEW (view), GTK_WRAP_WORD); - g_signal_connect (view, "key-release-event", + g_signal_connect (view, "key-release-event", G_CALLBACK (key_press_event), NULL); buffer = gtk_text_view_get_buffer (GTK_TEXT_VIEW (view)); - + sw = gtk_scrolled_window_new (NULL, NULL); gtk_scrolled_window_set_policy (GTK_SCROLLED_WINDOW (sw), @@ -258,8 +322,14 @@ static GnomeCanvasItem *wordprocessor_create() /* * Create the default style tags */ - current_doctype_default = &doctype_list[0]; - create_tags(buffer, *current_doctype_default); + doctype_list[0] = &type_normal; + doctype_list[1] = &type_letter; + doctype_list[2] = &type_small; + doctype_list[3] = &type_text; + doctype_list[4] = &type_big; + + current_doctype_default = doctype_list[0]; + create_tags(buffer, current_doctype_default); /* * Display the style buttons @@ -269,6 +339,7 @@ static GnomeCanvasItem *wordprocessor_create() word_area_y1); display_style_selector(boardRootItem); + display_color_style_selector(boardRootItem); return NULL; } @@ -276,7 +347,7 @@ static GnomeCanvasItem *wordprocessor_create() /* * Display the style buttons */ -static void display_style_buttons(GnomeCanvasGroup *boardRootItem, +static void display_style_buttons(GnomeCanvasGroup *boardRootItem, int x, int y) { @@ -350,10 +421,10 @@ item_event(GnomeCanvasItem *item, GdkEvent *event, gpointer data) if(board_paused) return FALSE; - switch (event->type) + switch (event->type) { case GDK_BUTTON_PRESS: - switch(event->button.button) + switch(event->button.button) { case 1: case 2: @@ -412,7 +483,7 @@ item_event(GnomeCanvasItem *item, GdkEvent *event, gpointer data) */ static void -create_tags (GtkTextBuffer *buffer, style_t style[]) +create_tags (GtkTextBuffer *buffer, doctype_t *doctype) { gint i; @@ -420,22 +491,22 @@ create_tags (GtkTextBuffer *buffer, style_t style[]) { GtkTextTag *tag; - tag = gtk_text_buffer_create_tag (buffer, style[i].name, - "weight", style[i].weight, - "font", style[i].font, - "justification", style[i].justification, - "indent", style[i].indent, - "pixels-above-lines", style[i].pixels_above_lines, - "pixels-below-lines", style[i].pixels_below_lines, - "foreground", style[i].foreground, + tag = gtk_text_buffer_create_tag (buffer, doctype->style[i].name, + "weight", doctype->style[i].weight, + "font", doctype->style[i].font, + "justification", doctype->style[i].justification, + "indent", doctype->style[i].indent, + "pixels-above-lines", doctype->style[i].pixels_above_lines, + "pixels-below-lines", doctype->style[i].pixels_below_lines, NULL); - g_object_set_data (G_OBJECT (tag), "style", &style[i]); + tag_list[i] = tag; + g_object_set_data (G_OBJECT (tag), "style", &doctype->style[i]); } /* Point to the last style */ i--; - current_style_default = &style[i]; + current_style_default = &doctype->style[i]; set_default_style(buffer, current_style_default); } @@ -453,9 +524,9 @@ set_default_style (GtkTextBuffer *buffer, style_t *style) font_desc = pango_font_description_from_string (style->font); gtk_widget_modify_font (view, font_desc); pango_font_description_free (font_desc); - + /* Change default color throughout the widget */ - gdk_color_parse (style->foreground, &color); + gdk_color_parse ("black", &color); gtk_widget_modify_text (view, GTK_STATE_NORMAL, &color); /* Change left margin, justification, ... throughout the widget */ @@ -475,32 +546,17 @@ display_style_selector(GnomeCanvasGroup *boardRootItem) { int i = 0; - /* The list of all styles */ - gchar *doctype_names[] = { - _("Default"), - _("Love letter"), - NULL - }; - - styles_hash = g_hash_table_new (g_str_hash, g_str_equal); - gtk_combo_filetypes = gtk_combo_box_new_text(); - while ( doctype_names[i] != NULL) - { - g_hash_table_insert(styles_hash, doctype_names[i], &doctype_list[i]); - - gtk_combo_box_append_text(GTK_COMBO_BOX(gtk_combo_filetypes), (gchar *)doctype_names[i]); - - i++; - } + while (i < NUMBER_OF_DOCTYPE) + gtk_combo_box_append_text(GTK_COMBO_BOX(gtk_combo_filetypes), doctype_list[i++]->name); gnome_canvas_item_new (GNOME_CANVAS_GROUP(boardRootItem), gnome_canvas_widget_get_type (), "widget", GTK_WIDGET(gtk_combo_filetypes), "x", (double) combo_style_x1, "y", (double) combo_style_y1, - "width", (double) BOARDWIDTH - combo_style_x1 - 10, + "width", (double) combo_style_width, "height", 35.0, "anchor", GTK_ANCHOR_NW, "size_pixels", FALSE, @@ -512,34 +568,119 @@ display_style_selector(GnomeCanvasGroup *boardRootItem) g_signal_connect(G_OBJECT(gtk_combo_filetypes), "changed", G_CALLBACK(item_event_style_selection), - doctype_names); + NULL); } -/* Catch all typing events to apply the proper tags +/* + * Create the combo with the color styles + * -------------------------------------- + */ +static void +display_color_style_selector(GnomeCanvasGroup *boardRootItem) +{ + int i = 0; + + gtk_combo_filetypes = gtk_combo_box_new_text(); + + while (i < NUMBER_OF_COLOR_STYLE) + gtk_combo_box_append_text(GTK_COMBO_BOX(gtk_combo_filetypes), color_style_list[i++][0]); + + gnome_canvas_item_new (GNOME_CANVAS_GROUP(boardRootItem), + gnome_canvas_widget_get_type (), + "widget", GTK_WIDGET(gtk_combo_filetypes), + "x", (double) combo_color_style_x1, + "y", (double) combo_color_style_y1, + "width", (double) combo_color_style_width, + "height", 35.0, + "anchor", GTK_ANCHOR_NW, + "size_pixels", FALSE, + NULL); + + gtk_widget_show(GTK_WIDGET(gtk_combo_filetypes)); + gtk_combo_box_set_active(GTK_COMBO_BOX(gtk_combo_filetypes), 0); + + g_signal_connect(G_OBJECT(gtk_combo_filetypes), + "changed", + G_CALLBACK(item_event_color_style_selection), + NULL); +} + +static void tag_style_set(int i, doctype_t *doctype) +{ + printf("Setting style %s tag %s\n", doctype->name, doctype->style[i].name); + g_object_set(tag_list[i], + "weight", doctype->style[i].weight, + "font", doctype->style[i].font, + "justification", doctype->style[i].justification, + "indent", doctype->style[i].indent, + "pixels-above-lines", doctype->style[i].pixels_above_lines, + "pixels-below-lines", doctype->style[i].pixels_below_lines, + NULL); +} + +/* Set a new style from the combo box selection * */ static void item_event_style_selection (GtkComboBox *widget, - void *doctype_names[]) + void *data) { gchar *style_str; - style_t *doctype[1]; + int i; style_str = gtk_combo_box_get_active_text((GtkComboBox *)widget); printf("item_event_style_selection %s\n", style_str); + /* Search the doctype */ + for(i=0; i<NUMBER_OF_DOCTYPE; i++) + { + printf(" trying i=%d %s\n", i, doctype_list[i]->name); + if(strcmp(doctype_list[i]->name, style_str)==0) + { + /* Change the tag */ + int j = 0; + + for(j=0; j<NUMBER_OF_STYLE; j++) + { + tag_style_set(j, doctype_list[i]); + } + + break; + } + } +} + + +/* Set a new color style from the combo box selection + * + */ +static void +item_event_color_style_selection (GtkComboBox *widget, + void *data) +{ + gchar *style_str; + int i; + + style_str = gtk_combo_box_get_active_text((GtkComboBox *)widget); + + printf("item_event_color_style_selection %s\n", style_str); /* Search the doctype */ - doctype[0] = (style_t *)(g_hash_table_lookup(styles_hash, style_str)); - if(doctype) { - int i = 0; - - while(doctype[i]) - { - printf("==>%s\n", doctype[i]->name); - i++; - } - } + for(i=0; i<NUMBER_OF_COLOR_STYLE; i++) + { + printf(" trying i=%d %s\n", i, color_style_list[i][0]); + if(strcmp(color_style_list[i][0], style_str)==0) + { + int j; + /* Change the color */ + for(j=0; j<NUMBER_OF_STYLE; j++) + g_object_set(tag_list[j], + "foreground",color_style_list[i][j+1], + NULL); + break; + } + } + } @@ -590,8 +731,8 @@ key_press_event (GtkWidget *text_view, &iter_start, &iter_end); } - - if (tags) + + if (tags) g_slist_free (tags); else { diff --git a/src/gcompris/config.c b/src/gcompris/config.c index 28135c1..f95b560 100644 --- a/src/gcompris/config.c +++ b/src/gcompris/config.c @@ -138,7 +138,7 @@ static void set_locale_flag(gchar *locale); static gchar *get_next_locale(gchar *locale); static gchar *get_previous_locale(gchar *locale); static gint item_event_ok(GnomeCanvasItem *item, GdkEvent *event, gpointer data); -static void display_previous_next(guint x_start, guint y_start, +static void display_previous_next(guint x_start, guint y_start, gchar *eventname_previous, gchar *eventname_next); @@ -177,7 +177,7 @@ gc_config_start () x_start = (BOARDWIDTH - gdk_pixbuf_get_width(pixmap))/2; item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem), gnome_canvas_pixbuf_get_type (), - "pixbuf", pixmap, + "pixbuf", pixmap, "x", (double) x_start, "y", (double) y_start, NULL); @@ -221,7 +221,7 @@ gc_config_start () item_locale_flag = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem), gnome_canvas_pixbuf_get_type (), - "pixbuf", NULL, + "pixbuf", NULL, "x", (double) x_flag_start, "y", (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2, NULL); @@ -241,10 +241,10 @@ gc_config_start () */ current_locale = properties->locale; set_locale_flag(current_locale); - + item_locale_text = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem), gnome_canvas_text_get_type (), - "text", gc_locale_get_name(current_locale), + "text", gc_locale_get_name(current_locale), "font", gc_skin_font_subtitle, "x", (double) x_text_start, "y", (double) y_start, @@ -257,7 +257,7 @@ gc_config_start () item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem), gnome_canvas_pixbuf_get_type (), - "pixbuf", (properties->fullscreen ? pixmap_checked : pixmap_unchecked), + "pixbuf", (properties->fullscreen ? pixmap_checked : pixmap_unchecked), "x", (double) x_start, "y", (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2, NULL); @@ -272,7 +272,7 @@ gc_config_start () gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem), gnome_canvas_text_get_type (), - "text", _("Fullscreen"), + "text", _("Fullscreen"), "font", gc_skin_font_subtitle, "x", (double) x_text_start, "y", (double) y_start, @@ -287,7 +287,7 @@ gc_config_start () item_screen_text = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem), gnome_canvas_text_get_type (), - "text", gettext(screenname[properties->screensize]), + "text", gettext(screenname[properties->screensize]), "font", gc_skin_font_subtitle, "x", (double) x_text_start, "y", (double) y_start, @@ -300,7 +300,7 @@ gc_config_start () item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem), gnome_canvas_pixbuf_get_type (), - "pixbuf", (properties->music ? pixmap_checked : pixmap_unchecked), + "pixbuf", (properties->music ? pixmap_checked : pixmap_unchecked), "x", (double) x_start, "y", (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2, NULL); @@ -315,7 +315,7 @@ gc_config_start () gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem), gnome_canvas_text_get_type (), - "text", _("Music"), + "text", _("Music"), "font", gc_skin_font_subtitle, "x", (double) x_text_start, "y", (double) y_start, @@ -328,7 +328,7 @@ gc_config_start () item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem), gnome_canvas_pixbuf_get_type (), - "pixbuf", (properties->fx ? pixmap_checked : pixmap_unchecked), + "pixbuf", (properties->fx ? pixmap_checked : pixmap_unchecked), "x", (double) x_start, "y", (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2, NULL); @@ -343,7 +343,7 @@ gc_config_start () gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem), gnome_canvas_text_get_type (), - "text", _("Effect"), + "text", _("Effect"), "font", gc_skin_font_subtitle, "x", (double) x_text_start, "y", (double) y_start, @@ -439,7 +439,7 @@ gc_config_start () item_filter_text = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem), gnome_canvas_text_get_type (), - "markup", gettext(filtername[0]), + "markup", gettext(filtername[0]), "font", gc_skin_font_subtitle, "x", (double) x_text_start, "y", (double) y_start, @@ -452,7 +452,7 @@ gc_config_start () pixmap = gc_skin_pixmap_load("button_large.png"); item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem), gnome_canvas_pixbuf_get_type (), - "pixbuf", pixmap, + "pixbuf", pixmap, "x", (double) (BOARDWIDTH*0.5) - gdk_pixbuf_get_width(pixmap)/2, "y", (double) y - gdk_pixbuf_get_height(pixmap) - 5, NULL); @@ -504,7 +504,7 @@ void gc_config_stop () gtk_object_destroy(GTK_OBJECT(rootitem)); gc_board_pause(FALSE); } - rootitem = NULL; + rootitem = NULL; stars_group = NULL; @@ -556,7 +556,7 @@ gc_locale_get_name(gchar *locale) /*-------------------------------------------------------------------------------*/ /*-------------------------------------------------------------------------------*/ static void -display_previous_next(guint x_start, guint y_start, +display_previous_next(guint x_start, guint y_start, gchar *eventname_previous, gchar *eventname_next) { GdkPixbuf *pixmap = NULL; @@ -565,7 +565,7 @@ display_previous_next(guint x_start, guint y_start, pixmap = gc_skin_pixmap_load("button_backward.png"); item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem), gnome_canvas_pixbuf_get_type (), - "pixbuf", pixmap, + "pixbuf", pixmap, "x", (double) x_start - gdk_pixbuf_get_width(pixmap) - 10, "y", (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2, NULL); @@ -582,7 +582,7 @@ display_previous_next(guint x_start, guint y_start, pixmap = gc_skin_pixmap_load("button_forward.png"); item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem), gnome_canvas_pixbuf_get_type (), - "pixbuf", pixmap, + "pixbuf", pixmap, "x", (double) x_start, "y", (double) y_start - gdk_pixbuf_get_width(pixmap_checked)/2, NULL); @@ -595,7 +595,7 @@ display_previous_next(guint x_start, guint y_start, NULL); gdk_pixbuf_unref(pixmap); } - + static void set_locale_flag(gchar *locale) { @@ -669,7 +669,7 @@ get_next_locale(gchar *locale) return(linguas[i+2]); else return(linguas[0]); - + } i=i+2; } @@ -697,7 +697,7 @@ get_previous_locale(gchar *locale) // Go to the end of the list while(linguas[i]!=NULL) { i=i+2; }; return(linguas[i-2]); - } + } } i=i+2; } @@ -713,7 +713,7 @@ item_event_ok(GnomeCanvasItem *item, GdkEvent *event, gpointer data) if(data==NULL) return FALSE; - switch (event->type) + switch (event->type) { case GDK_ENTER_NOTIFY: break; @@ -731,6 +731,11 @@ item_event_ok(GnomeCanvasItem *item, GdkEvent *event, gpointer data) properties->skin = g_strdup((char *)g_list_nth_data(skinlist, skin_index)); gc_skin_load(properties->skin); gc_config_stop(); + + /* Set the new locale in the properties */ + g_free(properties->locale); + properties->locale = strdup(current_locale); + gc_prop_save(properties); if(properties->music || properties->fx) { @@ -749,7 +754,7 @@ item_event_ok(GnomeCanvasItem *item, GdkEvent *event, gpointer data) gc_fullscreen_set(properties->fullscreen); #endif /* Warning changing the image needs to update pixbuf_ref for the focus usage */ - g_object_set_data (G_OBJECT (item), "pixbuf_ref", + g_object_set_data (G_OBJECT (item), "pixbuf_ref", (properties->fullscreen ? pixmap_checked : pixmap_unchecked)); gnome_canvas_item_set (item, "pixbuf", (properties->fullscreen ? pixmap_checked : pixmap_unchecked), @@ -760,7 +765,7 @@ item_event_ok(GnomeCanvasItem *item, GdkEvent *event, gpointer data) { properties->music = (properties->music ? 0 : 1); /* Warning changing the image needs to update pixbuf_ref for the focus usage */ - g_object_set_data (G_OBJECT (item), "pixbuf_ref", + g_object_set_data (G_OBJECT (item), "pixbuf_ref", (properties->music ? pixmap_checked : pixmap_unchecked)); gnome_canvas_item_set (item, "pixbuf", (properties->music ? pixmap_checked : pixmap_unchecked), @@ -771,7 +776,7 @@ item_event_ok(GnomeCanvasItem *item, GdkEvent *event, gpointer data) { properties->fx = (properties->fx ? 0 : 1); /* Warning changing the image needs to update pixbuf_ref for the focus usage */ - g_object_set_data (G_OBJECT (item), "pixbuf_ref", + g_object_set_data (G_OBJECT (item), "pixbuf_ref", (properties->fx ? pixmap_checked : pixmap_unchecked)); gnome_canvas_item_set (item, "pixbuf", (properties->fx ? pixmap_checked : pixmap_unchecked), @@ -786,7 +791,6 @@ item_event_ok(GnomeCanvasItem *item, GdkEvent *event, gpointer data) "text", gc_locale_get_name(current_locale), NULL); set_locale_flag(current_locale); - properties->locale = current_locale; } else if(!strcmp((char *)data, "locale_next")) { @@ -796,7 +800,6 @@ item_event_ok(GnomeCanvasItem *item, GdkEvent *event, gpointer data) NULL); set_locale_flag(current_locale); - properties->locale = current_locale; } else if(!strcmp((char *)data, "screen_previous")) { @@ -804,7 +807,7 @@ item_event_ok(GnomeCanvasItem *item, GdkEvent *event, gpointer data) properties->screensize--; gnome_canvas_item_set (item_screen_text, - "text", gettext(screenname[properties->screensize]), + "text", gettext(screenname[properties->screensize]), NULL); } else if(!strcmp((char *)data, "screen_next")) @@ -813,7 +816,7 @@ item_event_ok(GnomeCanvasItem *item, GdkEvent *event, gpointer data) properties->screensize++; gnome_canvas_item_set (item_screen_text, - "text", gettext(screenname[properties->screensize]), + "text", gettext(screenname[properties->screensize]), NULL); } else if(!strcmp((char *)data, "timer_previous")) @@ -822,7 +825,7 @@ item_event_ok(GnomeCanvasItem *item, GdkEvent *event, gpointer data) properties->timer--; gnome_canvas_item_set (item_timer_text, - "text", gettext(timername[properties->timer]), + "text", gettext(timername[properties->timer]), NULL); } else if(!strcmp((char *)data, "timer_next")) @@ -831,7 +834,7 @@ item_event_ok(GnomeCanvasItem *item, GdkEvent *event, gpointer data) properties->timer++; gnome_canvas_item_set (item_timer_text, - "text", gettext(timername[properties->timer]), + "text", gettext(timername[properties->timer]), NULL); } else if(!strcmp((char *)data, "skin_previous")) @@ -840,7 +843,7 @@ item_event_ok(GnomeCanvasItem *item, GdkEvent *event, gpointer data) if(skin_index-- < 1) skin_index = g_list_length(skinlist)-1; - skin_str = g_strdup_printf(_("Skin : %s"), + skin_str = g_strdup_printf(_("Skin : %s"), (char *)g_list_nth_data(skinlist, skin_index)); gnome_canvas_item_set (item_skin_text, @@ -854,7 +857,7 @@ item_event_ok(GnomeCanvasItem *item, GdkEvent *event, gpointer data) if(skin_index++ >= g_list_length(skinlist)-1) skin_index = 0; - skin_str = g_strdup_printf(_("Skin : %s"), + skin_str = g_strdup_printf(_("Skin : %s"), (char *)g_list_nth_data(skinlist, skin_index)); gnome_canvas_item_set (item_skin_text, "text", skin_str, diff --git a/src/gcompris/file_selector.c b/src/gcompris/file_selector.c index acf8c0d..b3cf781 100644 --- a/src/gcompris/file_selector.c +++ b/src/gcompris/file_selector.c @@ -41,17 +41,17 @@ #define MODE_SAVE 2 static gint mode; -static gint item_event_file_selector(GnomeCanvasItem *item, - GdkEvent *event, +static gint item_event_file_selector(GnomeCanvasItem *item, + GdkEvent *event, gpointer data); static gint item_event_scroll(GnomeCanvasItem *item, GdkEvent *event, GnomeCanvas *canvas); -static gint item_event_directory(GnomeCanvasItem *item, - GdkEvent *event, +static gint item_event_directory(GnomeCanvasItem *item, + GdkEvent *event, char *dir); static void display_files(GnomeCanvasItem *rootitem, gchar *rootdir); -static int display_file_selector(int mode, +static int display_file_selector(int mode, GcomprisBoard *gcomprisBoard, gchar *rootdir, gchar *file_types, @@ -107,7 +107,7 @@ static GHashTable* mimetypes_ext_hash = NULL; /* Mime type with the key being t static GHashTable* mimetypes_desc_hash = NULL; /* Mime type with the key being the description */ /* - * Main entry point + * Main entry point * ---------------- * */ @@ -149,7 +149,7 @@ void gc_selector_file_stop () if(rootitem!=NULL) gtk_object_destroy(GTK_OBJECT(rootitem)); - rootitem = NULL; + rootitem = NULL; /* No need to destroy it since it's in rootitem but just clear it */ file_root_item = NULL; @@ -173,8 +173,8 @@ void gc_selector_file_stop () /*-------------------------------------------------------------------------------*/ -static int -display_file_selector(int the_mode, +static int +display_file_selector(int the_mode, GcomprisBoard *gcomprisBoard, gchar *rootdir, gchar *file_types, @@ -224,7 +224,7 @@ display_file_selector(int the_mode, x_start = (BOARDWIDTH - gdk_pixbuf_get_width(pixmap))/2; item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem), gnome_canvas_pixbuf_get_type (), - "pixbuf", pixmap, + "pixbuf", pixmap, "x", (double) x_start, "y", (double) y_start, NULL); @@ -250,7 +250,7 @@ display_file_selector(int the_mode, gtk_widget_show(GTK_WIDGET(widget_entry)); /* - * Create the combo with the file types + * Create the combo with the file types * ------------------------------------ */ if(mode==MODE_SAVE && file_types_string && *file_types_string!='\0') { @@ -265,7 +265,7 @@ display_file_selector(int the_mode, /* Extract the mime type */ mimeType = (GcomprisMimeType *)(g_hash_table_lookup(mimetypes_hash, str)); if(mimeType) { - result = strdup(mimeType->description); + result = strdup(gettext(mimeType->description)); } else { result = str; } @@ -278,7 +278,7 @@ display_file_selector(int the_mode, /* Extract the mime type */ mimeType = (GcomprisMimeType *)(g_hash_table_lookup(mimetypes_hash, sub_string)); if(mimeType) { - result = strdup(mimeType->description); + result = strdup(gettext(mimeType->description)); } else { result = str; } @@ -316,7 +316,7 @@ display_file_selector(int the_mode, // CANCEL item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem), gnome_canvas_pixbuf_get_type (), - "pixbuf", pixmap, + "pixbuf", pixmap, "x", (double) (BOARDWIDTH*0.33) - gdk_pixbuf_get_width(pixmap)/2, "y", (double) y - gdk_pixbuf_get_height(pixmap) - 25, NULL); @@ -347,7 +347,7 @@ display_file_selector(int the_mode, // OK item = gnome_canvas_item_new (GNOME_CANVAS_GROUP(rootitem), gnome_canvas_pixbuf_get_type (), - "pixbuf", pixmap, + "pixbuf", pixmap, "x", (double) (BOARDWIDTH*0.66) - gdk_pixbuf_get_width(pixmap)/2, "y", (double) y - gdk_pixbuf_get_height(pixmap) - 25, NULL); @@ -439,7 +439,7 @@ static void display_files(GnomeCanvasItem *root_item, gchar *rootdir) g_list_free(file_list); } file_list = NULL; - + /* Create a root item to put the image list in it */ file_root_item = \ gnome_canvas_item_new (GNOME_CANVAS_GROUP(root_item), @@ -616,7 +616,7 @@ static void display_files(GnomeCanvasItem *root_item, gchar *rootdir) (GtkSignalFunc) item_event_file_selector, allfilename); } - + ix+=IMAGE_WIDTH + IMAGE_GAP; if(ix>=DRAWING_AREA_X2 - DRAWING_AREA_X1 -IMAGE_GAP) { @@ -624,8 +624,8 @@ static void display_files(GnomeCanvasItem *root_item, gchar *rootdir) iy+=IMAGE_HEIGHT + IMAGE_GAP; - gnome_canvas_set_scroll_region (GNOME_CANVAS (canvas), 0, 0, - DRAWING_AREA_X2- DRAWING_AREA_X1, + gnome_canvas_set_scroll_region (GNOME_CANVAS (canvas), 0, 0, + DRAWING_AREA_X2- DRAWING_AREA_X1, iy + IMAGE_HEIGHT + IMAGE_GAP); if(iy>=DRAWING_AREA_Y2-DRAWING_AREA_Y1) { @@ -649,7 +649,7 @@ item_event_directory(GnomeCanvasItem *item, GdkEvent *event, gchar *dir) if(!rootitem) return FALSE; - switch (event->type) + switch (event->type) { case GDK_ENTER_NOTIFY: break; @@ -679,7 +679,7 @@ item_event_scroll(GnomeCanvasItem *item, GdkEvent *event, GnomeCanvas *canvas) if(!rootitem) return FALSE; - switch (event->type) + switch (event->type) { case GDK_SCROLL: gnome_canvas_get_scroll_offsets (canvas, &x, &y); @@ -703,7 +703,7 @@ item_event_file_selector(GnomeCanvasItem *item, GdkEvent *event, gpointer data) if(!rootitem) return FALSE; - switch (event->type) + switch (event->type) { case GDK_ENTER_NOTIFY: break; @@ -722,7 +722,7 @@ item_event_file_selector(GnomeCanvasItem *item, GdkEvent *event, gpointer data) gchar *file_type=NULL; result = g_strdup_printf("%s/%s", current_rootdir, gtk_entry_get_text(widget_entry)); - + if(mode==MODE_SAVE) { GcomprisMimeType *mimeType = NULL; GtkTreeModel *model; @@ -808,25 +808,15 @@ void parseMime (xmlDocPtr doc, xmlNodePtr xmlnode) { gcomprisMime->mimetype = (gchar *)xmlGetProp(xmlnode, BAD_CAST "mimetype"); gcomprisMime->extension = (gchar *)xmlGetProp(xmlnode, BAD_CAST "extension"); gcomprisMime->icon = (gchar *)xmlGetProp(xmlnode, BAD_CAST "icon"); - gcomprisMime->description = NULL; - - /* get the help user credit of the board */ - xmlnode = xmlnode->xmlChildrenNode; - while (xmlnode != NULL) { - gchar *lang = (gchar *)xmlGetProp(xmlnode, BAD_CAST "lang"); - if (!strcmp((char *)xmlnode->name, "description") - && (lang==NULL || - !strcmp(lang, gc_locale_get()) - || !strncmp(lang, gc_locale_get(), 2))) - { - if(gcomprisMime->description) - g_free(gcomprisMime->description); - - gcomprisMime->description = (gchar *)xmlNodeListGetString(doc, - xmlnode->xmlChildrenNode, 1); - } - g_free(lang); - xmlnode = xmlnode->next; + + for (xmlnode = xmlnode->xmlChildrenNode; xmlnode != NULL; xmlnode = xmlnode->next) { + if (xmlHasProp(xmlnode, BAD_CAST "lang")) + continue; + + /* get the title of the board */ + if (!strcmp((char *)xmlnode->name, "description")) + gcomprisMime->description = (gchar *)xmlNodeListGetString(doc, + xmlnode->xmlChildrenNode, 0); } if(!gcomprisMime->mimetype || !gcomprisMime->extension || !gcomprisMime->description ) { @@ -851,7 +841,7 @@ void parseMime (xmlDocPtr doc, xmlNodePtr xmlnode) { static void parse_doc(xmlDocPtr doc) { xmlNodePtr cur; - cur = xmlDocGetRootElement(doc); + cur = xmlDocGetRootElement(doc); if (cur == NULL) { fprintf(stderr,"empty document\n"); xmlFreeDoc(doc); @@ -863,10 +853,10 @@ static void parse_doc(xmlDocPtr doc) { if ((!xmlStrcmp(cur->name, (const xmlChar *)"MimeType"))){ parseMime (doc, cur); } - + cur = cur->next; } - + return; } @@ -881,7 +871,7 @@ gboolean load_mime_type_from_file(gchar *fname) g_return_val_if_fail(fname!=NULL,FALSE); /* if the file doesn't exist */ - if(!g_file_test ((fname), G_FILE_TEST_EXISTS)) + if(!g_file_test ((fname), G_FILE_TEST_EXISTS)) { g_warning("Couldn't find file %s !", fname); return FALSE; @@ -893,7 +883,7 @@ gboolean load_mime_type_from_file(gchar *fname) /* in case something went wrong */ if(!doc) return FALSE; - + if(/* if there is no root element */ !doc->children || /* if it doesn't have a name */ @@ -903,12 +893,12 @@ gboolean load_mime_type_from_file(gchar *fname) xmlFreeDoc(doc); return FALSE; } - + /* parse our document and replace old data */ parse_doc(doc); - + xmlFreeDoc(doc); - + return TRUE; } @@ -919,7 +909,7 @@ gboolean load_mime_type_from_file(gchar *fname) * Must be called once at GCompris startup. * */ -void gc_mime_type_load() +void gc_mime_type_load() { const gchar *one_dirent; GcomprisProperties *properties = gc_prop_get(); @@ -946,7 +936,7 @@ void gc_mime_type_load() while((one_dirent = g_dir_read_name(dir)) != NULL) { /* add the board to the list */ gchar *filename; - + filename = g_strdup_printf("%s/%s", mime_dir, one_dirent); if(!g_file_test(filename, G_FILE_TEST_IS_REGULAR)) { diff --git a/src/gcompris/gameutil.c b/src/gcompris/gameutil.c index 502870f..a1e31f5 100644 --- a/src/gcompris/gameutil.c +++ b/src/gcompris/gameutil.c @@ -38,7 +38,7 @@ extern GnomeCanvas *canvas; typedef void (*sighandler_t)(int); -/** load a pixmap from the filesystem +/** load a pixmap from the filesystem * * \param format: If format contains $LOCALE, it will be first replaced by the current long locale * and if not found the short locale name. It support printf formating. @@ -75,7 +75,7 @@ GdkPixbuf *gc_pixmap_load(const gchar *format, ...) else g_warning ("Couldn't find file %s !", pixmapfile); - str = g_strdup_printf("%s\n%s\n%s\n%s", + str = g_strdup_printf("%s\n%s\n%s\n%s", _("Couldn't find or load the file"), pixmapfile, _("This activity is incomplete."), @@ -192,7 +192,7 @@ void gc_item_focus_set(GnomeCanvasItem *item, gboolean focus) NULL); } - + switch (focus) { @@ -255,22 +255,21 @@ gchar *reactivate_newline(char *str) { gchar *newstr; - xmlParserCtxtPtr ctxt = xmlNewParserCtxt (); + xmlParserCtxtPtr ctxt = xmlNewParserCtxt(); if(str==NULL) return NULL; + newstr = (gchar *)xmlStringDecodeEntities(ctxt, + BAD_CAST str, + XML_SUBSTITUTE_REF, + 0, + 0, + 0); + + xmlFreeParserCtxt(ctxt); - newstr = (gchar *)xmlStringDecodeEntities (ctxt, - BAD_CAST str, - XML_SUBSTITUTE_REF, - 0, - 0, - 0); - - xmlFreeParserCtxt (ctxt); - return newstr; } @@ -285,7 +284,7 @@ void gc_item_absolute_move(GnomeCanvasItem *item, int x, int y) { /** As gnome does not implement its own API : gc_item_rotate we have to do it ourselves .... IMPORTANT NOTE : This is designed for an item with "anchor" = GTK_ANCHOR_CENTER - rotation is clockwise if angle > 0 + rotation is clockwise if angle > 0 */ void gc_item_rotate(GnomeCanvasItem *item, double angle) { @@ -351,7 +350,7 @@ gc_item_rotate_relative(GnomeCanvasItem *item, double angle) { y1 = MIN(ty1,ty2); x2 = MAX(tx1,tx2); y2 = MAX(ty1,ty2); - + cx = (x2+x1)/2; cy = (y2+y1)/2; @@ -421,8 +420,8 @@ gc_item_rotate_relative_with_center(GnomeCanvasItem *item, double angle, int x, * The new group in which the stars are created is returned. * This is only usefull for the menu plugin and the configuration dialog box. */ -GnomeCanvasGroup *gc_difficulty_display(GnomeCanvasGroup *parent, - double x, double y, +GnomeCanvasGroup *gc_difficulty_display(GnomeCanvasGroup *parent, + double x, double y, double ratio, gint difficulty) { @@ -455,10 +454,10 @@ GnomeCanvasGroup *gc_difficulty_display(GnomeCanvasGroup *parent, "y", y, "width", (double) gdk_pixbuf_get_width(pixmap) * ratio, "height", (double) gdk_pixbuf_get_height(pixmap) * ratio, - "width_set", TRUE, + "width_set", TRUE, "height_set", TRUE, NULL)); - + gtk_signal_connect(GTK_OBJECT(item), "event", (GtkSignalFunc) gc_item_focus_event, NULL); @@ -480,10 +479,10 @@ gchar *g_utf8_strndup(gchar* utf8text, gint n) result = g_strndup(utf8text, g_utf8_offset_to_pointer(utf8text, len) - utf8text); return result; -} +} /** \brief search a given relative file in all gcompris dir it could be found - * + * * \param format: If format contains $LOCALE, it will be first replaced by the current long locale * and if not found the short locale name. It support printf formating. * \param ...: additional params for the format (printf like) @@ -521,14 +520,14 @@ gc_file_find_absolute(const gchar *format, ...) /* * Search it on the file system */ - + dir_to_search[i++] = properties->package_data_dir; dir_to_search[i++] = properties->user_data_dir; dir_to_search[i++] = NULL; absolute_filename = g_strdup(filename); i = 0; - + while (dir_to_search[i]) { gchar **tmp; @@ -598,7 +597,7 @@ gc_file_find_absolute(const gchar *format, ...) i++; } - + g_free(filename); g_free(absolute_filename); return NULL; diff --git a/src/gcompris/gcompris.c b/src/gcompris/gcompris.c index 109d112..fe51200 100644 --- a/src/gcompris/gcompris.c +++ b/src/gcompris/gcompris.c @@ -80,7 +80,7 @@ static void map_cb (GtkWidget *widget, gpointer data); static gint board_widget_key_press_callback (GtkWidget *widget, GdkEventKey *event, gpointer client_data); -void gc_terminate(int signum); +void gc_terminate(int signum); static GcomprisProperties *properties = NULL; static gboolean antialiased = FALSE; @@ -293,18 +293,6 @@ board_widget_key_press_callback (GtkWidget *widget, return TRUE; } - if(event->state & GDK_CONTROL_MASK && ((event->keyval == GDK_p) - || (event->keyval == GDK_P))) { - properties->key="thanks_for_your_help"; - gc_prop_save(properties); - gc_menu_load(); - - gc_close_all_dialog(); - - gc_board_stop(); - return TRUE; - } - if(event->keyval>=GDK_0 && event->keyval<=GDK_9) current_keycode[current_keycode_index++] = event->keyval; diff --git a/src/gcompris/gcompris_db.c b/src/gcompris/gcompris_db.c index 8055b9e..f0bec9f 100644 --- a/src/gcompris/gcompris_db.c +++ b/src/gcompris/gcompris_db.c @@ -29,85 +29,85 @@ static sqlite3 *gcompris_db=NULL; extern GnomeCanvas *canvas; -#define CREATE_TABLE_USERS \ - "CREATE TABLE users (user_id INT UNIQUE, login TEXT, lastname TEXT, firstname TEXT, birthdate TEXT, class_id INT ); " -#define CREATE_TABLE_CLASS \ - "CREATE TABLE class (class_id INT UNIQUE, name TEXT, teacher TEXT, wholegroup_id INT ); " -#define CREATE_TABLE_GROUPS \ - "CREATE TABLE groups (group_id INT UNIQUE, name TEXT, class_id INT, description TEXT ); " -#define CREATE_TABLE_USERS_IN_GROUPS \ - "CREATE TABLE list_users_in_groups (user_id INT, group_id INT ); " -#define CREATE_TABLE_GROUPS_IN_PROFILES \ - "CREATE TABLE list_groups_in_profiles (profile_id INT, group_id INT ); " -#define CREATE_TABLE_ACTIVITIES_OUT \ - "CREATE TABLE activities_out (board_id INT, type INT, out_id INT ); " -#define CREATE_TABLE_PROFILES \ - "CREATE TABLE profiles (profile_id INT UNIQUE, name TEXT, profile_directory TEXT, description TEXT); " -#define CREATE_TABLE_BOARDS_PROFILES_CONF \ - "CREATE TABLE board_profile_conf (profile_id INT, board_id INT, conf_key TEXT, conf_value TEXT ); " -#define CREATE_TABLE_BOARDS \ - "CREATE TABLE boards (board_id INT UNIQUE, name TEXT, section_id INT, section TEXT, author TEXT, type TEXT, mode TEXT, difficulty INT, icon TEXT, boarddir TEXT, mandatory_sound_file TEXT, mandatory_sound_dataset TEXT, filename TEXT, title TEXT, description TEXT, prerequisite TEXT, goal TEXT, manual TEXT, credit TEXT);" - -#define CREATE_TABLE_INFO \ - "CREATE TABLE informations (gcompris_version TEXT UNIQUE, init_date TEXTUNIQUE, profile_id INT UNIQUE ); " - -#define PRAGMA_INTEGRITY \ - "PRAGMA integrity_check; " +#define CREATE_TABLE_USERS \ + "CREATE TABLE users (user_id INT UNIQUE, login TEXT, lastname TEXT, firstname TEXT, birthdate TEXT, class_id INT ); " +#define CREATE_TABLE_CLASS \ + "CREATE TABLE class (class_id INT UNIQUE, name TEXT, teacher TEXT, wholegroup_id INT ); " +#define CREATE_TABLE_GROUPS \ + "CREATE TABLE groups (group_id INT UNIQUE, name TEXT, class_id INT, description TEXT ); " +#define CREATE_TABLE_USERS_IN_GROUPS \ + "CREATE TABLE list_users_in_groups (user_id INT, group_id INT ); " +#define CREATE_TABLE_GROUPS_IN_PROFILES \ + "CREATE TABLE list_groups_in_profiles (profile_id INT, group_id INT ); " +#define CREATE_TABLE_ACTIVITIES_OUT \ + "CREATE TABLE activities_out (board_id INT, type INT, out_id INT ); " +#define CREATE_TABLE_PROFILES \ + "CREATE TABLE profiles (profile_id INT UNIQUE, name TEXT, profile_directory TEXT, description TEXT); " +#define CREATE_TABLE_BOARDS_PROFILES_CONF \ + "CREATE TABLE board_profile_conf (profile_id INT, board_id INT, conf_key TEXT, conf_value TEXT ); " +#define CREATE_TABLE_BOARDS \ + "CREATE TABLE boards (board_id INT UNIQUE, name TEXT, section_id INT, section TEXT, author TEXT, type TEXT, mode TEXT, difficulty INT, icon TEXT, boarddir TEXT, mandatory_sound_file TEXT, mandatory_sound_dataset TEXT, filename TEXT, title TEXT, description TEXT, prerequisite TEXT, goal TEXT, manual TEXT, credit TEXT);" + +#define CREATE_TABLE_INFO \ + "CREATE TABLE informations (gcompris_version TEXT UNIQUE, init_date TEXTUNIQUE, profile_id INT UNIQUE ); " + +#define PRAGMA_INTEGRITY \ + "PRAGMA integrity_check; " /* WARNING: template for g_strdup_printf */ -#define SET_VERSION(v)\ - "INSERT INTO informations (gcompris_version) VALUES(\'%s\'); ", v +#define SET_VERSION(v) \ + "INSERT INTO informations (gcompris_version) VALUES(\'%s\'); ", v -#define CHECK_VERSION \ - "SELECT gcompris_version FROM informations;" +#define CHECK_VERSION \ + "SELECT gcompris_version FROM informations;" -#define SET_DEFAULT_PROFILE \ - "INSERT INTO profiles (profile_id, name, profile_directory, description) VALUES ( 1, \'Default\', \'Default\', \'Default profil for gcompris\');" -#define ACTIVATE_DEFAULT_PROFILE \ - "UPDATE informations SET profile_id=1;" +#define SET_DEFAULT_PROFILE \ + "INSERT INTO profiles (profile_id, name, profile_directory, description) VALUES ( 1, \'Default\', \'Default\', \'Default profil for gcompris\');" +#define ACTIVATE_DEFAULT_PROFILE \ + "UPDATE informations SET profile_id=1;" -#define SET_DEFAULT_GROUP \ - "INSERT INTO groups (group_id, name, class_id, description) VALUES ( 1, \'All\', 1, \'All users\');" +#define SET_DEFAULT_GROUP \ + "INSERT INTO groups (group_id, name, class_id, description) VALUES ( 1, \'All\', 1, \'All users\');" /* * TRIGGERS * -------- */ -#define TRIGGER_DELETE_CLASS \ +#define TRIGGER_DELETE_CLASS \ "CREATE TRIGGER delete_class DELETE ON class\ BEGIN \ DELETE FROM groups WHERE class_id=old.class_id; \ UPDATE users SET class_id=1 WHERE class_id=old.class_id; \ END;" -#define TRIGGER_DELETE_GROUPS \ +#define TRIGGER_DELETE_GROUPS \ "CREATE TRIGGER delete_groups DELETE ON groups\ BEGIN \ DELETE FROM list_users_in_groups WHERE group_id=old.group_id; \ DELETE FROM list_groups_in_profiles WHERE group_id=old.group_id; \ END;" -#define TRIGGER_DELETE_PROFILES \ +#define TRIGGER_DELETE_PROFILES \ "CREATE TRIGGER delete_profiles DELETE ON profiles\ BEGIN \ DELETE FROM list_groups_in_profiles WHERE profile_id=old.profile_id; \ DELETE FROM board_profile_conf WHERE profile_id=old.profile_id; \ END;" -#define TRIGGER_DELETE_USERS \ +#define TRIGGER_DELETE_USERS \ "CREATE TRIGGER delete_users DELETE ON users\ BEGIN \ DELETE FROM list_users_in_groups WHERE user_id=old.user_id; \ END;" -#define TRIGGER_INSERT_USERS \ +#define TRIGGER_INSERT_USERS \ "CREATE TRIGGER insert_users INSERT ON users\ BEGIN \ INSERT INTO list_users_in_groups (user_id, group_id) VALUES (new.user_id, (SELECT wholegroup_id FROM class WHERE class_id=new.class_id)); \ END;" -#define TRIGGER_UPDATE_USERS \ +#define TRIGGER_UPDATE_USERS \ "CREATE TRIGGER update_wholegroup UPDATE OF class_id ON users\ BEGIN \ UPDATE list_users_in_groups SET group_id=(SELECT wholegroup_id FROM class WHERE class_id=new.class_id) WHERE user_id=new.user_id; \ @@ -126,14 +126,14 @@ int gc_db_init() gchar *request; GcomprisProperties *properties = gc_prop_get(); - + if (!g_file_test(properties->database, G_FILE_TEST_EXISTS)) creation = TRUE; else { /* we have to check this file is not empty, because bug in administration */ struct stat buf; - + if (stat(properties->database, &buf)!=0) g_error("Can't stat %s", properties->database); @@ -143,7 +143,7 @@ int gc_db_init() g_warning("Database file is empty! Trying to create table..."); } } - + rc = sqlite3_open(properties->database, &gcompris_db); if( rc ){ g_error("Can't open database: %s\n", sqlite3_errmsg(gcompris_db)); @@ -226,8 +226,8 @@ int gc_db_init() request = g_strdup_printf(SET_VERSION(VERSION)); - rc = sqlite3_get_table(gcompris_db, - request, + rc = sqlite3_get_table(gcompris_db, + request, &result, &nrow, &ncolumn, @@ -269,8 +269,8 @@ int gc_db_init() } else { /* Check the db integrity */ - rc = sqlite3_get_table(gcompris_db, - PRAGMA_INTEGRITY, + rc = sqlite3_get_table(gcompris_db, + PRAGMA_INTEGRITY, &result, &nrow, &ncolumn, @@ -284,8 +284,8 @@ int gc_db_init() g_warning("Database Integrity ok"); sqlite3_free_table(result); - rc = sqlite3_get_table(gcompris_db, - CHECK_VERSION, + rc = sqlite3_get_table(gcompris_db, + CHECK_VERSION, &result, &nrow, &ncolumn, @@ -314,8 +314,8 @@ void gc_db_exit() #endif } -#define BOARDS_SET_DATE(date) \ - "UPDATE informations SET init_date=\'%s\';",date +#define BOARDS_SET_DATE(date) \ + "UPDATE informations SET init_date=\'%s\';",date void gc_db_set_date(gchar *date) { @@ -329,25 +329,25 @@ void gc_db_set_date(gchar *date) gchar *request; request = g_strdup_printf(BOARDS_SET_DATE(date)); - rc = sqlite3_get_table(gcompris_db, - request, + rc = sqlite3_get_table(gcompris_db, + request, &result, &nrow, &ncolumn, &zErrMsg ); - if( rc!=SQLITE_OK ){ - g_error("SQL error: %s\n", zErrMsg); - } - g_free(request); + if( rc!=SQLITE_OK ){ + g_error("SQL error: %s\n", zErrMsg); + } + g_free(request); - sqlite3_free_table(result); + sqlite3_free_table(result); #endif } -#define BOARDS_UPDATE_VERSION(version) \ - "UPDATE informations SET gcompris_version=\'%s\';",version +#define BOARDS_UPDATE_VERSION(version) \ + "UPDATE informations SET gcompris_version=\'%s\';",version void gc_db_set_version(gchar *version) { @@ -361,25 +361,25 @@ void gc_db_set_version(gchar *version) gchar *request; request = g_strdup_printf(BOARDS_UPDATE_VERSION(version)); - rc = sqlite3_get_table(gcompris_db, - request, + rc = sqlite3_get_table(gcompris_db, + request, &result, &nrow, &ncolumn, &zErrMsg ); - if( rc!=SQLITE_OK ){ - g_error("SQL error: %s\n", zErrMsg); - } - g_free(request); + if( rc!=SQLITE_OK ){ + g_error("SQL error: %s\n", zErrMsg); + } + g_free(request); - sqlite3_free_table(result); + sqlite3_free_table(result); #endif } -#define BOARDS_CHECK \ - "SELECT gcompris_version, init_date FROM informations;" +#define BOARDS_CHECK \ + "SELECT gcompris_version, init_date FROM informations;" gboolean gc_db_check_boards() { #ifdef USE_SQLITE @@ -391,64 +391,65 @@ gboolean gc_db_check_boards() int ncolumn; gboolean ret_value; - rc = sqlite3_get_table(gcompris_db, - BOARDS_CHECK, + rc = sqlite3_get_table(gcompris_db, + BOARDS_CHECK, &result, &nrow, &ncolumn, &zErrMsg ); - if( rc!=SQLITE_OK ){ - g_error("SQL error: %s\n", zErrMsg); - } + if( rc!=SQLITE_OK ){ + g_error("SQL error: %s\n", zErrMsg); + } - ret_value = (strcmp(result[2],VERSION)==0) && (result[3] != NULL); + ret_value = (strcmp(result[2],VERSION)==0) && (result[3] != NULL); - sqlite3_free_table(result); + sqlite3_free_table(result); - return ret_value; + return ret_value; #else - return FALSE; + return FALSE; #endif } -#define BOARD_INSERT \ - "INSERT OR REPLACE INTO boards VALUES (%d, %Q, %d, %Q, %Q, %Q, %Q, %d, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q);" - -#define MAX_BOARD_ID \ - "SELECT MAX(board_id) FROM boards;" - -#define SECTION_ID(s) \ - "SELECT section_id FROM boards WHERE section=\'%s\';",s - -#define MAX_SECTION_ID \ - "SELECT MAX(section_id) FROM boards;" - -#define CHECK_BOARD(n) \ - "SELECT board_id FROM boards WHERE name=\'%s\';",n - - -void gc_db_board_update(guint *board_id, - guint *section_id, - gchar *name, - gchar *section, - gchar *author, - gchar *type, - gchar *mode, - int difficulty, - gchar *icon, - gchar *boarddir, - gchar *mandatory_sound_file, - gchar *mandatory_sound_dataset, - gchar *filename, - gchar *title, - gchar *description, - gchar *prerequisite, - gchar *goal, - gchar *manual, - gchar *credit - ) +#define BOARD_INSERT \ + "INSERT OR REPLACE INTO boards VALUES (%d, %Q, %d, %Q, %Q, %Q, %Q, %d, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q, %Q);" + +#define MAX_BOARD_ID \ + "SELECT MAX(board_id) FROM boards;" + +#define SECTION_ID(s) \ + "SELECT section_id FROM boards WHERE section=\'%s\';",s + +#define MAX_SECTION_ID \ + "SELECT MAX(section_id) FROM boards;" + +#define CHECK_BOARD(n) \ + "SELECT board_id FROM boards WHERE name=\'%s\';",n + + +void +gc_db_board_update(guint *board_id, + guint *section_id, + gchar *name, + gchar *section, + gchar *author, + gchar *type, + gchar *mode, + int difficulty, + gchar *icon, + gchar *boarddir, + gchar *mandatory_sound_file, + gchar *mandatory_sound_dataset, + gchar *filename, + gchar *title, + gchar *description, + gchar *prerequisite, + gchar *goal, + gchar *manual, + gchar *credit + ) { #ifdef USE_SQLITE @@ -464,19 +465,19 @@ void gc_db_board_update(guint *board_id, if (*board_id==0){ /* board not yet registered */ - + /* assume name is unique */ - + request = g_strdup_printf(CHECK_BOARD(name)); - rc = sqlite3_get_table(gcompris_db, - request, + rc = sqlite3_get_table(gcompris_db, + request, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } @@ -489,124 +490,124 @@ void gc_db_board_update(guint *board_id, } else { /* get last board_id written */ - rc = sqlite3_get_table(gcompris_db, + rc = sqlite3_get_table(gcompris_db, MAX_BOARD_ID, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } - + if (result[1] == NULL) *board_id = 1; else *board_id = atoi(result[1]) + 1; sqlite3_free_table(result); - - } + + } } - + /* get section_id */ request = g_strdup_printf(SECTION_ID(section)); - - rc = sqlite3_get_table(gcompris_db, + + rc = sqlite3_get_table(gcompris_db, request, &result, &nrow, &ncolumn, &zErrMsg ); - + g_free(request); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } - + if (nrow == 0){ - + /* get max section_id */ - - rc = sqlite3_get_table(gcompris_db, + + rc = sqlite3_get_table(gcompris_db, MAX_SECTION_ID, &result, &nrow, &ncolumn, &zErrMsg ); - - + + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } - + if (result[1] == NULL){ *section_id = 1; } else { *section_id = atoi(result[1]) + 1; } sqlite3_free_table(result); - } else { + } else { *section_id = atoi(result[1]); sqlite3_free_table(result); } request = sqlite3_mprintf( BOARD_INSERT, - *board_id, - name, - *section_id, - section, - author, - type, - mode, - difficulty, - icon, - boarddir, - mandatory_sound_file, - mandatory_sound_dataset, - filename, - title, - description, - prerequisite, - goal, - manual, - credit - ); - - rc = sqlite3_get_table(gcompris_db, - request, + *board_id, + name, + *section_id, + section, + author, + type, + mode, + difficulty, + icon, + boarddir, + mandatory_sound_file, + mandatory_sound_dataset, + filename, + title, + description, + prerequisite, + goal, + manual, + credit + ); + + rc = sqlite3_get_table(gcompris_db, + request, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } - + sqlite3_free_table(result); - + sqlite3_free(request); - + #endif } -#define BOARDS_READ \ - "SELECT board_id ,name, section_id, section, author, type, mode, difficulty, icon, boarddir, mandatory_sound_file, mandatory_sound_dataset, filename, title, description, prerequisite, goal, manual, credit FROM boards;" +#define BOARDS_READ \ + "SELECT board_id ,name, section_id, section, author, type, mode, difficulty, icon, boarddir, mandatory_sound_file, mandatory_sound_dataset, filename, title, description, prerequisite, goal, manual, credit FROM boards;" GList *gc_menu_load_db(GList *boards_list) { #ifdef USE_SQLITE GcomprisProperties *properties = gc_prop_get(); - + GList *boards = boards_list; char *zErrMsg; @@ -616,42 +617,42 @@ GList *gc_menu_load_db(GList *boards_list) int ncolumn; int i; - rc = sqlite3_get_table(gcompris_db, - BOARDS_READ, + rc = sqlite3_get_table(gcompris_db, + BOARDS_READ, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } /* first ncolumns are columns labels. */ i = ncolumn; - + while (i < (nrow +1)*ncolumn) { GcomprisBoard *gcomprisBoard = NULL; gcomprisBoard = g_malloc0 (sizeof (GcomprisBoard)); - + gcomprisBoard->plugin=NULL; gcomprisBoard->previous_board=NULL; gcomprisBoard->board_ready=FALSE; gcomprisBoard->canvas=canvas; - + gcomprisBoard->gmodule = NULL; gcomprisBoard->gmodule_file = NULL; - + /* From DB we have only package_data_dir. */ gcomprisBoard->board_dir = properties->package_data_dir; - + /* Fixed since I use the canvas own pixel_per_unit scheme */ gcomprisBoard->width = BOARDWIDTH; gcomprisBoard->height = BOARDHEIGHT; - - + + gcomprisBoard->board_id = atoi(result[i++]); gcomprisBoard->name = g_strdup(result[i++]); gcomprisBoard->section_id = atoi(result[i++]); @@ -671,12 +672,12 @@ GList *gc_menu_load_db(GList *boards_list) gcomprisBoard->goal = reactivate_newline(gettext(result[i++])); gcomprisBoard->manual = reactivate_newline(gettext(result[i++])); gcomprisBoard->credit = reactivate_newline(gettext(result[i++])); - + boards = g_list_append(boards, gcomprisBoard); - } + } sqlite3_free_table(result); - + return boards; #else @@ -690,13 +691,13 @@ GList *gc_db_read_board_from_section(gchar *section) } -#define BOARD_ID_READ \ - "SELECT board_id FROM boards;" +#define BOARD_ID_READ \ + "SELECT board_id FROM boards;" GList *gc_db_get_board_id(GList *list) { #ifdef USE_SQLITE - + GList *board_id_list = list; char *zErrMsg; @@ -705,25 +706,25 @@ GList *gc_db_get_board_id(GList *list) int nrow; int ncolumn; int i; - - rc = sqlite3_get_table(gcompris_db, - BOARD_ID_READ, + + rc = sqlite3_get_table(gcompris_db, + BOARD_ID_READ, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } /* first ncolumns are columns labels. */ i = ncolumn; - + while (i < (nrow +1)*ncolumn) { int *board_id = g_malloc(sizeof(int)); - + *board_id = atoi(result[i++]); board_id_list = g_list_append(board_id_list, board_id); } @@ -735,8 +736,8 @@ GList *gc_db_get_board_id(GList *list) #endif } -#define DELETE_BOARD(table, board_id) \ - "DELETE FROM %s WHERE board_id=%d;", table, board_id +#define DELETE_BOARD(table, board_id) \ + "DELETE FROM %s WHERE board_id=%d;", table, board_id void gc_db_remove_board(int board_id) { @@ -753,14 +754,14 @@ void gc_db_remove_board(int board_id) /* get section_id */ request = g_strdup_printf(DELETE_BOARD("boards",board_id)); - rc = sqlite3_get_table(gcompris_db, - request, + rc = sqlite3_get_table(gcompris_db, + request, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } @@ -771,14 +772,14 @@ void gc_db_remove_board(int board_id) /* get section_id */ request = g_strdup_printf(DELETE_BOARD("board_profile_conf",board_id)); - rc = sqlite3_get_table(gcompris_db, - request, + rc = sqlite3_get_table(gcompris_db, + request, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } @@ -789,14 +790,14 @@ void gc_db_remove_board(int board_id) /* get section_id */ request = g_strdup_printf(DELETE_BOARD("activities_out",board_id)); - rc = sqlite3_get_table(gcompris_db, - request, + rc = sqlite3_get_table(gcompris_db, + request, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } @@ -806,17 +807,17 @@ void gc_db_remove_board(int board_id) } -#define GET_PROFILE(n) \ - "SELECT name, profile_directory, description FROM profiles WHERE profile_id=%d;",n +#define GET_PROFILE(n) \ + "SELECT name, profile_directory, description FROM profiles WHERE profile_id=%d;",n -#define GET_PROFILE_FROM_NAME(n) \ - "SELECT profile_id, profile_directory, description FROM profiles WHERE name='%s';",n +#define GET_PROFILE_FROM_NAME(n) \ + "SELECT profile_id, profile_directory, description FROM profiles WHERE name='%s';",n -#define GET_GROUPS_IN_PROFILE(n) \ - "SELECT group_id FROM list_groups_in_profiles WHERE profile_id=%d;",n +#define GET_GROUPS_IN_PROFILE(n) \ + "SELECT group_id FROM list_groups_in_profiles WHERE profile_id=%d;",n -#define GET_ACTIVITIES_OUT_OF_PROFILE(n) \ - "SELECT board_id FROM activities_out WHERE out_id=%d;",n +#define GET_ACTIVITIES_OUT_OF_PROFILE(n) \ + "SELECT board_id FROM activities_out WHERE out_id=%d;",n GcomprisProfile *gc_db_get_profile_from_id(gint profile_id) { @@ -835,57 +836,57 @@ GcomprisProfile *gc_db_get_profile_from_id(gint profile_id) /* get section_id */ request = g_strdup_printf(GET_PROFILE(profile_id)); - - rc = sqlite3_get_table(gcompris_db, - request, + + rc = sqlite3_get_table(gcompris_db, + request, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } - + if (nrow != 0){ profile = g_malloc0(sizeof(GcomprisProfile)); - profile->profile_id = profile_id; + profile->profile_id = profile_id; + - profile->name = g_strdup(result[3]); profile->directory = g_strdup(result[4]); profile->description = g_strdup(result[5]); sqlite3_free_table(result); g_free(request); - + request = g_strdup_printf(GET_GROUPS_IN_PROFILE(profile->profile_id)); - rc = sqlite3_get_table(gcompris_db, - request, + rc = sqlite3_get_table(gcompris_db, + request, &result, &nrow, &ncolumn, &zErrMsg - ); - + ); + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } g_free(request); - + if (nrow == 0){ g_warning("No users' groups for profile %s", profile->name); profile->group_ids = NULL; } else { ids = NULL; - + i = ncolumn; while (i < (nrow +1)*ncolumn) { int *group_id = g_malloc(sizeof(int)); - + *group_id = atoi(result[i++]); ids = g_list_append(ids, group_id); } @@ -894,30 +895,30 @@ GcomprisProfile *gc_db_get_profile_from_id(gint profile_id) sqlite3_free_table(result); request = g_strdup_printf(GET_ACTIVITIES_OUT_OF_PROFILE(profile->profile_id)); - rc = sqlite3_get_table(gcompris_db, - request, + rc = sqlite3_get_table(gcompris_db, + request, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } - + g_free(request); - + if (nrow == 0){ g_warning("No activities for profile %s", profile->name); profile->activities = NULL; } else { ids = NULL; - + i = ncolumn; while (i < (nrow +1)*ncolumn) { int *board_id = g_malloc(sizeof(int)); - + *board_id = atoi(result[i++]); ids = g_list_append(ids, board_id); } @@ -935,7 +936,7 @@ GcomprisProfile *gc_db_get_profile_from_id(gint profile_id) /** \brief Given a profile name, return a GcomprisProfile struct * * \param profile_name: the profile to retrieve. - * + * * \return *GcomprisProfile */ GcomprisProfile * @@ -954,18 +955,18 @@ gc_db_profile_from_name_get(gchar *profile_name) /* get section_id */ request = g_strdup_printf(GET_PROFILE_FROM_NAME(profile_name)); - rc = sqlite3_get_table(gcompris_db, - request, + rc = sqlite3_get_table(gcompris_db, + request, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } - + if (nrow != 0){ gint profile_id; @@ -986,8 +987,8 @@ gc_db_profile_from_name_get(gchar *profile_name) -#define GET_ACTIVE_PROFILE_ID \ - "SELECT profile_id FROM informations;" +#define GET_ACTIVE_PROFILE_ID \ + "SELECT profile_id FROM informations;" GcomprisProfile *gc_db_get_profile() { @@ -999,19 +1000,19 @@ GcomprisProfile *gc_db_get_profile() int ncolumn; int profile_id; - rc = sqlite3_get_table(gcompris_db, - GET_ACTIVE_PROFILE_ID, + rc = sqlite3_get_table(gcompris_db, + GET_ACTIVE_PROFILE_ID, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } - profile_id = atoi(result[1]); + profile_id = atoi(result[1]); sqlite3_free_table(result); @@ -1022,8 +1023,8 @@ GcomprisProfile *gc_db_get_profile() #endif } -#define USERS_FROM_GROUP(n) \ - "SELECT users.user_id, users.login, users.lastname, users.firstname, users.birthdate, users.class_id FROM users, list_users_in_groups WHERE users.user_id = list_users_in_groups.user_id AND list_users_in_groups.group_id = %d;",n +#define USERS_FROM_GROUP(n) \ + "SELECT users.user_id, users.login, users.lastname, users.firstname, users.birthdate, users.class_id FROM users, list_users_in_groups WHERE users.user_id = list_users_in_groups.user_id AND list_users_in_groups.group_id = %d;",n GList *gc_db_users_from_group_get(gint group_id) { @@ -1039,14 +1040,14 @@ GList *gc_db_users_from_group_get(gint group_id) GList *users = NULL; request = g_strdup_printf(USERS_FROM_GROUP(group_id)); - rc = sqlite3_get_table(gcompris_db, - request, + rc = sqlite3_get_table(gcompris_db, + request, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } @@ -1059,14 +1060,14 @@ GList *gc_db_users_from_group_get(gint group_id) i = ncolumn; while (i < (nrow +1)*ncolumn) { GcomprisUser *user = g_malloc0(sizeof(GcomprisUser)); - + user->user_id = atoi(result[i++]); user->login = g_strdup(result[i++]); user->lastname = g_strdup(result[i++]); user->firstname = g_strdup(result[i++]); user->birthdate = g_strdup(result[i++]); user->class_id = atoi(result[i++]); - + users = g_list_append(users, user); } } @@ -1077,8 +1078,8 @@ GList *gc_db_users_from_group_get(gint group_id) #endif } -#define USER_FROM_ID(n) \ - "SELECT users.login, lastname, firstname, birthdate, class_id FROM users WHERE user_id = %d;",n +#define USER_FROM_ID(n) \ + "SELECT users.login, lastname, firstname, birthdate, class_id FROM users WHERE user_id = %d;",n GcomprisUser *gc_db_get_user_from_id(gint user_id) { @@ -1093,14 +1094,14 @@ GcomprisUser *gc_db_get_user_from_id(gint user_id) GcomprisUser *user = NULL; request = g_strdup_printf(USER_FROM_ID(user_id)); - rc = sqlite3_get_table(gcompris_db, - request, + rc = sqlite3_get_table(gcompris_db, + request, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } @@ -1113,7 +1114,7 @@ GcomprisUser *gc_db_get_user_from_id(gint user_id) } else { i = ncolumn; user = g_malloc0(sizeof(GcomprisUser)); - + user->user_id = user_id; user->login = g_strdup(result[i++]); user->lastname = g_strdup(result[i++]); @@ -1121,7 +1122,7 @@ GcomprisUser *gc_db_get_user_from_id(gint user_id) user->birthdate = g_strdup(result[i++]); user->class_id = atoi(result[i++]); } - + return user ; #else @@ -1129,11 +1130,11 @@ GcomprisUser *gc_db_get_user_from_id(gint user_id) #endif } -#define CLASS_FROM_ID(n) \ - "SELECT name, teacher, wholegroup_id FROM class WHERE class_id = %d;",n +#define CLASS_FROM_ID(n) \ + "SELECT name, teacher, wholegroup_id FROM class WHERE class_id = %d;",n -#define GROUPS_IN_CLASS(n) \ - "SELECT group_id FROM groups WHERE class_id = %d;",n +#define GROUPS_IN_CLASS(n) \ + "SELECT group_id FROM groups WHERE class_id = %d;",n GcomprisClass *gc_db_get_class_from_id(gint class_id) { @@ -1149,14 +1150,14 @@ GcomprisClass *gc_db_get_class_from_id(gint class_id) GcomprisClass *class = NULL; request = g_strdup_printf(CLASS_FROM_ID(class_id)); - rc = sqlite3_get_table(gcompris_db, - request, + rc = sqlite3_get_table(gcompris_db, + request, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } @@ -1184,14 +1185,14 @@ GcomprisClass *gc_db_get_class_from_id(gint class_id) request = g_strdup_printf(GROUPS_IN_CLASS(class_id)); - rc = sqlite3_get_table(gcompris_db, - request, + rc = sqlite3_get_table(gcompris_db, + request, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } @@ -1199,7 +1200,7 @@ GcomprisClass *gc_db_get_class_from_id(gint class_id) g_free(request); if (nrow == 0){ - g_error("No groups found for class id %d: there must be at least one for the whole class with id (%d)", + g_error("No groups found for class id %d: there must be at least one for the whole class with id (%d)", class_id, class->wholegroup_id); g_free(class); class = NULL; @@ -1222,19 +1223,19 @@ GcomprisClass *gc_db_get_class_from_id(gint class_id) } -#define CHECK_CONF \ - "SELECT * FROM board_profile_conf WHERE profile_id=%d AND board_id=%d AND conf_key=%Q;" +#define CHECK_CONF \ + "SELECT * FROM board_profile_conf WHERE profile_id=%d AND board_id=%d AND conf_key=%Q;" -#define INSERT_KEY \ - "INSERT INTO board_profile_conf (profile_id, board_id, conf_key, conf_value) VALUES (%d, %d, %Q, %Q);" +#define INSERT_KEY \ + "INSERT INTO board_profile_conf (profile_id, board_id, conf_key, conf_value) VALUES (%d, %d, %Q, %Q);" -#define UPDATE_KEY \ - "UPDATE board_profile_conf SET conf_value=%Q WHERE profile_id=%d AND board_id=%d AND conf_key=%Q;" +#define UPDATE_KEY \ + "UPDATE board_profile_conf SET conf_value=%Q WHERE profile_id=%d AND board_id=%d AND conf_key=%Q;" -void gc_db_set_board_conf(GcomprisProfile *profile, - GcomprisBoard *board, - gchar *key, - gchar *value) +void gc_db_set_board_conf(GcomprisProfile *profile, + GcomprisBoard *board, + gchar *key, + gchar *value) { #ifdef USE_SQLITE char *zErrMsg; @@ -1245,71 +1246,71 @@ void gc_db_set_board_conf(GcomprisProfile *profile, gchar *request; request = sqlite3_mprintf(CHECK_CONF, - profile->profile_id, - board->board_id, + profile->profile_id, + board->board_id, key); - rc = sqlite3_get_table(gcompris_db, - request, + rc = sqlite3_get_table(gcompris_db, + request, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } - + sqlite3_free(request); - + if (nrow == 0){ - request = sqlite3_mprintf(INSERT_KEY, - profile->profile_id, - board->board_id, + request = sqlite3_mprintf(INSERT_KEY, + profile->profile_id, + board->board_id, key, value); - - rc = sqlite3_get_table(gcompris_db, - request, + + rc = sqlite3_get_table(gcompris_db, + request, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } - + sqlite3_free(request); } else { request = sqlite3_mprintf(UPDATE_KEY, value, - profile->profile_id, - board->board_id, + profile->profile_id, + board->board_id, key ); - - rc = sqlite3_get_table(gcompris_db, - request, + + rc = sqlite3_get_table(gcompris_db, + request, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } - + sqlite3_free(request); } #endif -} +} -#define GET_CONF(p, b) \ - "SELECT conf_key, conf_value FROM board_profile_conf WHERE profile_id=%d AND board_id=%d;", p, b +#define GET_CONF(p, b) \ + "SELECT conf_key, conf_value FROM board_profile_conf WHERE profile_id=%d AND board_id=%d;", p, b GHashTable *gc_db_conf_with_table_get(int profile_id, int board_id, GHashTable *table ) { @@ -1324,25 +1325,25 @@ GHashTable *gc_db_conf_with_table_get(int profile_id, int board_id, GHashTable * gchar *request; int i; - request = g_strdup_printf(GET_CONF(profile_id, + request = g_strdup_printf(GET_CONF(profile_id, board_id)); - + g_warning ( "Request get_conf : %s", request); - rc = sqlite3_get_table(gcompris_db, - request, + rc = sqlite3_get_table(gcompris_db, + request, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } g_free(request); - + for ( i=ncolumn; i < (nrow +1)*ncolumn; i+=2){ if (strcmp(result[i+1],"NULL")!=0){ /* "NULL" values are ignored */ @@ -1356,7 +1357,7 @@ GHashTable *gc_db_conf_with_table_get(int profile_id, int board_id, GHashTable * } sqlite3_free_table(result); -#endif +#endif return hash_conf; } @@ -1379,26 +1380,26 @@ GHashTable *gc_db_get_board_conf() /* conf values for default profile and current board */ hash_result = gc_db_conf_with_table_get(1, - gc_board_get_current()->board_id, - hash_result); + gc_board_get_current()->board_id, + hash_result); /* conf values for profile (board independant) */ if(gc_profile_get_current()) { hash_result = gc_db_conf_with_table_get(gc_profile_get_current()->profile_id, - -1, - hash_result); + -1, + hash_result); /* conf value for current profile and current board */ hash_result = gc_db_conf_with_table_get(gc_profile_get_current()->profile_id, - gc_board_get_current()->board_id, - hash_result); + gc_board_get_current()->board_id, + hash_result); } return hash_result; } -#define GET_ALL_PROFILES \ - "SELECT profile_id, name, profile_directory, description FROM profiles;" +#define GET_ALL_PROFILES \ + "SELECT profile_id, name, profile_directory, description FROM profiles;" GList *gc_db_profiles_list_get() @@ -1423,58 +1424,58 @@ GList *gc_db_profiles_list_get() int i_; GList *ids_; - - rc = sqlite3_get_table(gcompris_db, - GET_ALL_PROFILES, + + rc = sqlite3_get_table(gcompris_db, + GET_ALL_PROFILES, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } if (nrow == 0) return NULL; - + i = ncolumn; while (i < (nrow +1)*ncolumn) { GcomprisProfile *profile = g_malloc0(sizeof(GcomprisProfile)); - profile->profile_id = atoi(result[i++]); - + profile->profile_id = atoi(result[i++]); + profile->name = g_strdup(result[i++]); profile->directory = g_strdup(result[i++]); profile->description = g_strdup(result[i++]); - + request = g_strdup_printf(GET_GROUPS_IN_PROFILE(profile->profile_id)); - rc = sqlite3_get_table(gcompris_db, - request, + rc = sqlite3_get_table(gcompris_db, + request, &result_, &nrow_, &ncolumn_, &zErrMsg - ); - + ); + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } g_free(request); - + if (nrow_ == 0){ g_warning("No users groups for profile %s", profile->name); profile->group_ids = NULL; } else { ids_ = NULL; - + i_ = ncolumn_; while (i_ < (nrow_ +1)*ncolumn_) { int *group_id = g_malloc(sizeof(int)); - + *group_id = atoi(result_[i_++]); ids_ = g_list_append(ids_, group_id); } @@ -1484,50 +1485,50 @@ GList *gc_db_profiles_list_get() sqlite3_free_table(result_); request = g_strdup_printf(GET_ACTIVITIES_OUT_OF_PROFILE(profile->profile_id)); - rc = sqlite3_get_table(gcompris_db, - request, + rc = sqlite3_get_table(gcompris_db, + request, &result_, &nrow_, &ncolumn_, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } - + g_free(request); - + if (nrow_ == 0){ g_warning("No activities out for profile %s", profile->name); profile->activities = NULL; } else { ids_ = NULL; - + i_ = ncolumn_; while (i_ < (nrow_ +1)*ncolumn_) { int *board_id = g_malloc(sizeof(int)); - + *board_id = atoi(result_[i_++]); ids_ = g_list_append(ids_, board_id); } profile->activities = ids_; } - sqlite3_free_table(result_); - profiles_list = g_list_append( profiles_list, profile); - } + sqlite3_free_table(result_); + profiles_list = g_list_append( profiles_list, profile); + } + + sqlite3_free_table(result); - sqlite3_free_table(result); - return profiles_list; #else return NULL; #endif } -#define GROUP_FROM_ID(n) \ - "SELECT name, class_id, description FROM groups WHERE group_id=%d;",n +#define GROUP_FROM_ID(n) \ + "SELECT name, class_id, description FROM groups WHERE group_id=%d;",n GcomprisGroup *gc_db_get_group_from_id(int group_id) { @@ -1544,14 +1545,14 @@ GcomprisGroup *gc_db_get_group_from_id(int group_id) GcomprisGroup *group = NULL; request = g_strdup_printf(GROUP_FROM_ID(group_id)); - rc = sqlite3_get_table(gcompris_db, - request, + rc = sqlite3_get_table(gcompris_db, + request, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } @@ -1581,8 +1582,8 @@ GcomprisGroup *gc_db_get_group_from_id(int group_id) #endif } -#define GET_ALL_GROUPS \ - "SELECT group_id, name, class_id, description FROM groups;" +#define GET_ALL_GROUPS \ + "SELECT group_id, name, class_id, description FROM groups;" GList *gc_db_get_groups_list() { @@ -1597,14 +1598,14 @@ GList *gc_db_get_groups_list() int i; GcomprisGroup *group = NULL; - rc = sqlite3_get_table(gcompris_db, - GET_ALL_GROUPS, + rc = sqlite3_get_table(gcompris_db, + GET_ALL_GROUPS, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } @@ -1622,7 +1623,7 @@ GList *gc_db_get_groups_list() group->name = g_strdup(result[i++]); group->class_id = atoi(result[i++]); group->description = g_strdup(result[i++]); - + group->user_ids = gc_db_users_from_group_get(group->group_id); groups_list = g_list_append(groups_list, group); @@ -1637,15 +1638,15 @@ GList *gc_db_get_groups_list() } -#define BOARDS_READ_FROM_ID(n) \ - "SELECT name, section_id, section, author, type, mode, difficulty, icon, boarddir, mandatory_sound_file, mandatory_sound_dataset, filename, title, description, prerequisite, goal, manual, credit FROM boards WHERE board_id=%d;",n +#define BOARDS_READ_FROM_ID(n) \ + "SELECT name, section_id, section, author, type, mode, difficulty, icon, boarddir, mandatory_sound_file, mandatory_sound_dataset, filename, title, description, prerequisite, goal, manual, credit FROM boards WHERE board_id=%d;",n GcomprisBoard *gc_db_get_board_from_id(int board_id) { #ifdef USE_SQLITE GcomprisProperties *properties = gc_prop_get(); - + char *zErrMsg; char **result; int rc; @@ -1656,14 +1657,14 @@ GcomprisBoard *gc_db_get_board_from_id(int board_id) request = g_strdup_printf(BOARDS_READ_FROM_ID(board_id)); - rc = sqlite3_get_table(gcompris_db, - request, + rc = sqlite3_get_table(gcompris_db, + request, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } @@ -1672,28 +1673,28 @@ GcomprisBoard *gc_db_get_board_from_id(int board_id) /* first ncolumns are columns labels. */ i = ncolumn; - + GcomprisBoard *gcomprisBoard = NULL; gcomprisBoard = g_malloc0 (sizeof (GcomprisBoard)); - - + + gcomprisBoard->plugin=NULL; gcomprisBoard->previous_board=NULL; gcomprisBoard->board_ready=FALSE; gcomprisBoard->canvas=canvas; - + gcomprisBoard->gmodule = NULL; gcomprisBoard->gmodule_file = NULL; - + /* From DB we have only package_data_dir. */ gcomprisBoard->board_dir = properties->package_data_dir; - + /* Fixed since I use the canvas own pixel_per_unit scheme */ gcomprisBoard->width = BOARDWIDTH; gcomprisBoard->height = BOARDHEIGHT; - - + + gcomprisBoard->board_id = board_id; gcomprisBoard->name = g_strdup(result[i++]); gcomprisBoard->section_id = atoi(result[i++]); @@ -1713,18 +1714,18 @@ GcomprisBoard *gc_db_get_board_from_id(int board_id) gcomprisBoard->goal = reactivate_newline(gettext(result[i++])); gcomprisBoard->manual = reactivate_newline(gettext(result[i++])); gcomprisBoard->credit = reactivate_newline(gettext(result[i++])); - + sqlite3_free_table(result); - + return gcomprisBoard; #else return NULL; #endif } -#define GET_ALL_USERS \ - "SELECT user_id, login, lastname, firstname, birthdate, class_id FROM users;" - +#define GET_ALL_USERS \ + "SELECT user_id, login, lastname, firstname, birthdate, class_id FROM users;" + GList *gc_db_get_users_list() { #ifdef USE_SQLITE @@ -1738,14 +1739,14 @@ GList *gc_db_get_users_list() int i; GcomprisUser *user = NULL; - rc = sqlite3_get_table(gcompris_db, - GET_ALL_USERS, + rc = sqlite3_get_table(gcompris_db, + GET_ALL_USERS, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } @@ -1765,7 +1766,7 @@ GList *gc_db_get_users_list() user->lastname = g_strdup(result[i++]); user->birthdate = g_strdup(result[i++]); user->class_id = atoi(result[i++]); - + users_list = g_list_append(users_list, user); } } @@ -1777,8 +1778,8 @@ GList *gc_db_get_users_list() #endif } -#define GET_ALL_CLASSES \ - "SELECT class_id, name, teacher, wholegroup_id FROM class;" +#define GET_ALL_CLASSES \ + "SELECT class_id, name, teacher, wholegroup_id FROM class;" GList *gc_db_get_classes_list() { @@ -1793,14 +1794,14 @@ GList *gc_db_get_classes_list() int i; GcomprisClass *class = NULL; - rc = sqlite3_get_table(gcompris_db, - GET_ALL_CLASSES, + rc = sqlite3_get_table(gcompris_db, + GET_ALL_CLASSES, &result, &nrow, &ncolumn, &zErrMsg ); - + if( rc!=SQLITE_OK ){ g_error("SQL error: %s\n", zErrMsg); } @@ -1846,14 +1847,14 @@ int gc_db_is_activity_in_profile(GcomprisProfile *profile, char *activity_name) request = g_strdup_printf(DB_IS_ACTIVITY_IN_PROFILE_ID(profile->profile_id, activity_name)); - rc = sqlite3_get_table(gcompris_db, - request, + rc = sqlite3_get_table(gcompris_db, + request, &result, &nrow, &ncolumn, &zErrMsg ); - + g_free(request); if( rc!=SQLITE_OK ){ @@ -1864,7 +1865,7 @@ int gc_db_is_activity_in_profile(GcomprisProfile *profile, char *activity_name) /* IS IN THE PROFILE */ return TRUE; } - + /* IS NOT IN THE PROFILE */ return FALSE; diff --git a/src/gcompris/menu.c b/src/gcompris/menu.c index ce815a0..46b215a 100644 --- a/src/gcompris/menu.c +++ b/src/gcompris/menu.c @@ -190,25 +190,25 @@ _add_xml_to_data(xmlDocPtr doc, xmlNodePtr xmlnode, GNode * child, if (db){ gc_db_board_update( &gcomprisBoard->board_id, - &gcomprisBoard->section_id, - gcomprisBoard->name, - gcomprisBoard->section, - gcomprisBoard->author, - gcomprisBoard->type, - gcomprisBoard->mode, - atoi(gcomprisBoard->difficulty), - gcomprisBoard->icon_name, - gcomprisBoard->boarddir, - gcomprisBoard->mandatory_sound_file, - gcomprisBoard->mandatory_sound_dataset, - gcomprisBoard->filename, - title, - description, - prerequisite, - goal, - manual, - credit - ); + &gcomprisBoard->section_id, + gcomprisBoard->name, + gcomprisBoard->section, + gcomprisBoard->author, + gcomprisBoard->type, + gcomprisBoard->mode, + atoi(gcomprisBoard->difficulty), + gcomprisBoard->icon_name, + gcomprisBoard->boarddir, + gcomprisBoard->mandatory_sound_file, + gcomprisBoard->mandatory_sound_dataset, + gcomprisBoard->filename, + gcomprisBoard->title, + gcomprisBoard->description, + gcomprisBoard->prerequisite, + gcomprisBoard->goal, + gcomprisBoard->manual, + gcomprisBoard->credit + ); g_warning("db board written %d in %d %s/%s", gcomprisBoard->board_id, gcomprisBoard->section_id, @@ -597,42 +597,47 @@ void gc_menu_load() { GcomprisProperties *properties = gc_prop_get(); - if(boards_list) { - cleanup_menus(); - return; - } + if(boards_list) + { + cleanup_menus(); + return; + } - if ((!properties->reread_menu) && gc_db_check_boards()){ - boards_list = gc_menu_load_db(boards_list); + if ((!properties->reread_menu) && gc_db_check_boards()) + { + boards_list = gc_menu_load_db(boards_list); - if (!properties->administration){ - GList *out_boards = NULL; - GList *list = NULL; - GcomprisBoard *board; + if (!properties->administration) + { + GList *out_boards = NULL; + GList *list = NULL; + GcomprisBoard *board; - for (list = boards_list; list != NULL; list = list->next){ - board = (GcomprisBoard *)list->data; - if (g_list_find_custom(gc_profile_get_current()->activities, - &(board->board_id), compare_id)) - out_boards = g_list_append(out_boards, board); - } - for (list = out_boards; list != NULL; list = list->next) - boards_list = g_list_remove(boards_list, list->data); + for (list = boards_list; list != NULL; list = list->next) + { + board = (GcomprisBoard *)list->data; + if (g_list_find_custom(gc_profile_get_current()->activities, + &(board->board_id), compare_id)) + out_boards = g_list_append(out_boards, board); + } + for (list = out_boards; list != NULL; list = list->next) + boards_list = g_list_remove(boards_list, list->data); + } + } + else + { + int db = (gc_profile_get_current() ? TRUE: FALSE); + properties->reread_menu = TRUE; + gc_menu_load_dir(properties->package_data_dir, db); + GDate *today = g_date_new(); + g_date_set_time (today, time (NULL)); + + gchar date[11]; + g_date_strftime (date, 11, "%F", today); + gc_db_set_date(date); + gc_db_set_version(VERSION); + g_date_free(today); } - } - else { - int db = (gc_profile_get_current() ? TRUE: FALSE); - properties->reread_menu = TRUE; - gc_menu_load_dir(properties->package_data_dir, db); - GDate *today = g_date_new(); - g_date_set_time (today, time (NULL)); - - gchar date[11]; - g_date_strftime (date, 11, "%F", today); - gc_db_set_date(date); - gc_db_set_version(VERSION); - g_date_free(today); - } if (properties->local_directory){ diff --git a/src/gcompris/properties.c b/src/gcompris/properties.c index 209fb47..12dc9b8 100644 --- a/src/gcompris/properties.c +++ b/src/gcompris/properties.c @@ -320,6 +320,8 @@ gc_prop_new () void gc_prop_destroy (GcomprisProperties *props) { + if(!props) + return; g_free(props->user_data_dir); g_free(props->package_data_dir); g_free(props->package_locale_dir); |