From 655eaf25ae253adfabdc69d531e3973d054d6042 Mon Sep 17 00:00:00 2001 From: Richard Wilson Date: Wed, 25 Jan 2006 02:43:07 +0000 Subject: [project @ 2006-01-25 02:43:07 by rjw] Language configuration tool svn path=/import/netsurf/; revision=2038 --- !NetSurf/Resources/de/Messages | 3 + !NetSurf/Resources/de/Templates,fec | Bin 13191 -> 13764 bytes !NetSurf/Resources/en/Messages | 3 + !NetSurf/Resources/en/Templates,fec | Bin 13134 -> 13707 bytes !NetSurf/Resources/fr/Messages | 3 + !NetSurf/Resources/fr/Templates,fec | Bin 13318 -> 13891 bytes !NetSurf/Resources/nl/Messages | 3 + !NetSurf/Resources/nl/Templates,fec | Bin 13220 -> 13793 bytes makefile | 2 +- riscos/configure.c | 3 + riscos/configure/con_language.c | 124 ++++++++++++++++++++++++++++++++++++ riscos/configure/configure.h | 1 + riscos/gui.c | 31 ++++++--- riscos/gui.h | 1 + riscos/menus.c | 75 +++++++--------------- riscos/menus.h | 5 +- 16 files changed, 188 insertions(+), 66 deletions(-) create mode 100644 riscos/configure/con_language.c diff --git a/!NetSurf/Resources/de/Messages b/!NetSurf/Resources/de/Messages index 3c62f3b44..16dc68a75 100644 --- a/!NetSurf/Resources/de/Messages +++ b/!NetSurf/Resources/de/Messages @@ -692,6 +692,9 @@ con_image:Images con_theme:Themes con_cache:Cache con_home:Home page +con_inter:Interface +con_language:Language +con_security:Security # Unused tokens diff --git a/!NetSurf/Resources/de/Templates,fec b/!NetSurf/Resources/de/Templates,fec index abc92196d..57b229adc 100755 Binary files a/!NetSurf/Resources/de/Templates,fec and b/!NetSurf/Resources/de/Templates,fec differ diff --git a/!NetSurf/Resources/en/Messages b/!NetSurf/Resources/en/Messages index ef84d79dd..711174640 100644 --- a/!NetSurf/Resources/en/Messages +++ b/!NetSurf/Resources/en/Messages @@ -691,6 +691,9 @@ con_image:Images con_theme:Themes con_cache:Cache con_home:Home page +con_inter:Interface +con_language:Language +con_security:Security # Unused tokens diff --git a/!NetSurf/Resources/en/Templates,fec b/!NetSurf/Resources/en/Templates,fec index e2b1c4b53..75cac71bf 100644 Binary files a/!NetSurf/Resources/en/Templates,fec and b/!NetSurf/Resources/en/Templates,fec differ diff --git a/!NetSurf/Resources/fr/Messages b/!NetSurf/Resources/fr/Messages index 75b83a73a..4296edabb 100644 --- a/!NetSurf/Resources/fr/Messages +++ b/!NetSurf/Resources/fr/Messages @@ -692,6 +692,9 @@ con_image:Images con_theme:Themes con_cache:Cache con_home:Home page +con_inter:Interface +con_language:Language +con_security:Security # Unused tokens diff --git a/!NetSurf/Resources/fr/Templates,fec b/!NetSurf/Resources/fr/Templates,fec index 71af2d095..4d709fffb 100644 Binary files a/!NetSurf/Resources/fr/Templates,fec and b/!NetSurf/Resources/fr/Templates,fec differ diff --git a/!NetSurf/Resources/nl/Messages b/!NetSurf/Resources/nl/Messages index 60e23980e..ef8265de1 100644 --- a/!NetSurf/Resources/nl/Messages +++ b/!NetSurf/Resources/nl/Messages @@ -693,6 +693,9 @@ con_image:Images con_theme:Themes con_cache:Cache con_home:Home page +con_inter:Interface +con_language:Language +con_security:Security # Unused tokens diff --git a/!NetSurf/Resources/nl/Templates,fec b/!NetSurf/Resources/nl/Templates,fec index 68fbaa994..30a272787 100644 Binary files a/!NetSurf/Resources/nl/Templates,fec and b/!NetSurf/Resources/nl/Templates,fec differ diff --git a/makefile b/makefile index b3ba87e21..c5a6fc75e 100644 --- a/makefile +++ b/makefile @@ -41,7 +41,7 @@ OBJECTS_RISCOS += 401login.o artworks.o assert.o awrender.o bitmap.o \ theme_install.o thumbnail.o treeview.o ucstables.o uri.o \ url_complete.o url_protocol.o wimp.o wimp_event.o window.o # riscos/ OBJECTS_RISCOS += con_cache.o con_fonts.o con_home.o con_image.o \ - con_memory.o con_theme.o # riscos/configure/ + con_language.o con_memory.o con_theme.o # riscos/configure/ # OBJECTS_RISCOS += memdebug.o OBJECTS_NCOS = $(OBJECTS_RISCOS) diff --git a/riscos/configure.c b/riscos/configure.c index c9a504a7f..1217e3800 100644 --- a/riscos/configure.c +++ b/riscos/configure.c @@ -80,6 +80,9 @@ void ro_gui_configure_initialise(void) { ro_gui_configure_register("con_home", ro_gui_options_home_initialise, ro_gui_wimp_event_finalise); + ro_gui_configure_register("con_language", + ro_gui_options_language_initialise, + ro_gui_wimp_event_finalise); } void ro_gui_configure_show(void) { diff --git a/riscos/configure/con_language.c b/riscos/configure/con_language.c new file mode 100644 index 000000000..8725452a4 --- /dev/null +++ b/riscos/configure/con_language.c @@ -0,0 +1,124 @@ +/* + * This file is part of NetSurf, http://netsurf.sourceforge.net/ + * Licensed under the GNU General Public License, + * http://www.opensource.org/licenses/gpl-license + * Copyright 2004 John M Bell + * Copyright 2006 Richard Wilson + */ + +#include "netsurf/desktop/options.h" +#include "netsurf/riscos/dialog.h" +#include "netsurf/riscos/gui.h" +#include "netsurf/riscos/menus.h" +#include "netsurf/riscos/options.h" +#include "netsurf/riscos/wimp.h" +#include "netsurf/riscos/wimp_event.h" +#include "netsurf/riscos/configure.h" +#include "netsurf/riscos/configure/configure.h" +#include "netsurf/utils/log.h" +#include "netsurf/utils/messages.h" +#include "netsurf/utils/utils.h" + + +#define LANGUAGE_INTERFACE_FIELD 3 +#define LANGUAGE_INTERFACE_GRIGHT 4 +#define LANGUAGE_WEB_PAGES_FIELD 6 +#define LANGUAGE_WEB_PAGES_GRIGHT 7 +#define LANGUAGE_DEFAULT_BUTTON 8 +#define LANGUAGE_CANCEL_BUTTON 9 +#define LANGUAGE_OK_BUTTON 10 + +static void ro_gui_options_language_default(wimp_pointer *pointer); +static bool ro_gui_options_language_ok(wimp_w w); +static const char *ro_gui_options_language_name(const char *code); + +bool ro_gui_options_language_initialise(wimp_w w) { + + /* set the current values */ + ro_gui_set_icon_string(w, LANGUAGE_INTERFACE_FIELD, + ro_gui_options_language_name(option_language ? + option_language : "en")); + ro_gui_set_icon_string(w, LANGUAGE_WEB_PAGES_FIELD, + ro_gui_options_language_name(option_accept_language ? + option_accept_language : "en")); + + /* initialise all functions for a newly created window */ + ro_gui_wimp_event_register_menu_gright(w, LANGUAGE_INTERFACE_FIELD, + LANGUAGE_INTERFACE_GRIGHT, languages_menu); + ro_gui_wimp_event_register_menu_gright(w, LANGUAGE_WEB_PAGES_FIELD, + LANGUAGE_WEB_PAGES_GRIGHT, languages_menu); + ro_gui_wimp_event_register_button(w, LANGUAGE_DEFAULT_BUTTON, + ro_gui_options_language_default); + ro_gui_wimp_event_register_cancel(w, LANGUAGE_CANCEL_BUTTON); + ro_gui_wimp_event_register_ok(w, LANGUAGE_OK_BUTTON, + ro_gui_options_language_ok); + ro_gui_wimp_event_set_help_prefix(w, "HelpLanguageConfig"); + ro_gui_wimp_event_memorise(w); + return true; + +} + +void ro_gui_options_language_default(wimp_pointer *pointer) { + const char *code; + + code = ro_gui_default_language(); + ro_gui_set_icon_string(pointer->w, LANGUAGE_INTERFACE_FIELD, + ro_gui_options_language_name(code ? + code : "en")); + ro_gui_set_icon_string(pointer->w, LANGUAGE_WEB_PAGES_FIELD, + ro_gui_options_language_name(code ? + code : "en")); +} + +bool ro_gui_options_language_ok(wimp_w w) { + const char *code; + char *temp; + + code = ro_gui_menu_find_menu_entry_key(languages_menu, + ro_gui_get_icon_string(w, LANGUAGE_INTERFACE_FIELD)); + if (code) { + code += 5; /* skip 'lang_' */ + if ((!option_language) || (strcmp(option_language, code))) { + temp = strdup(code); + if (temp) { + free(option_language); + option_language = temp; + } else { + LOG(("No memory to duplicate language code")); + warn_user("NoMemory", 0); + } + } + } + code = ro_gui_menu_find_menu_entry_key(languages_menu, + ro_gui_get_icon_string(w, LANGUAGE_WEB_PAGES_FIELD)); + if (code) { + code += 5; /* skip 'lang_' */ + if ((!option_accept_language) || + (strcmp(option_accept_language, code))) { + temp = strdup(code); + if (temp) { + free(option_accept_language); + option_accept_language = temp; + } else { + LOG(("No memory to duplicate language code")); + warn_user("NoMemory", 0); + } + } + } + ro_gui_save_options(); + return true; +} + + +/** + * Convert a 2-letter ISO language code to the language name. + * + * \param code 2-letter ISO language code + * \return language name, or code if unknown + */ +const char *ro_gui_options_language_name(const char *code) { + char key[] = "lang_xx"; + key[5] = code[0]; + key[6] = code[1]; + return messages_get(key); +} diff --git a/riscos/configure/configure.h b/riscos/configure/configure.h index acc28491e..9ec796c84 100644 --- a/riscos/configure/configure.h +++ b/riscos/configure/configure.h @@ -20,6 +20,7 @@ bool ro_gui_options_fonts_initialise(wimp_w w); bool ro_gui_options_home_initialise(wimp_w w); bool ro_gui_options_image_initialise(wimp_w w); void ro_gui_options_image_finalise(wimp_w w); +bool ro_gui_options_language_initialise(wimp_w w); bool ro_gui_options_memory_initialise(wimp_w w); bool ro_gui_options_theme_initialise(wimp_w w); void ro_gui_options_theme_finalise(wimp_w w); diff --git a/riscos/gui.c b/riscos/gui.c index 86301099d..7a7be6515 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -487,18 +487,12 @@ void ro_gui_create_dirs(void) } /** - * Determine the language to use. - * - * RISC OS has no standard way of determining which language the user prefers. - * We have to guess from the 'Country' setting. + * Choose the language to use. */ void ro_gui_choose_language(void) { char path[40]; - const char *lang; - int country; - os_error *error; /* if option_language exists and is valid, use that */ if (option_language) { @@ -513,6 +507,25 @@ void ro_gui_choose_language(void) free(option_language); option_language = 0; } + + option_language = strdup(ro_gui_default_language()); + assert(option_language); + option_accept_language = strdup(option_language); + assert(option_accept_language); +} + + +/** + * Determine the default language to use. + * + * RISC OS has no standard way of determining which language the user prefers. + * We have to guess from the 'Country' setting. + */ +const char *ro_gui_default_language(void) { + char path[40]; + const char *lang; + int country; + os_error *error; /* choose a language from the configured country number */ error = xosbyte_read(osbyte_VAR_COUNTRY_NUMBER, &country); @@ -540,8 +553,8 @@ void ro_gui_choose_language(void) } sprintf(path, "NetSurf:Resources.%s", lang); if (is_dir(path)) - option_language = strdup(lang); - else + return lang; + return "en"; option_language = strdup("en"); assert(option_language); if (!option_accept_language) diff --git a/riscos/gui.h b/riscos/gui.h index 59becd3ad..9a60379fd 100644 --- a/riscos/gui.h +++ b/riscos/gui.h @@ -103,6 +103,7 @@ void ro_gui_screen_size(int *width, int *height); void ro_gui_view_source(struct content *content); void ro_gui_drag_box_start(wimp_pointer *pointer); bool ro_gui_prequit(void); +const char *ro_gui_default_language(void); /* in download.c */ void ro_gui_download_init(void); diff --git a/riscos/menus.c b/riscos/menus.c index 59e41e230..de4866d85 100644 --- a/riscos/menus.c +++ b/riscos/menus.c @@ -817,25 +817,6 @@ void ro_gui_prepare_navigate(struct gui_window *gui) { } -/** - * Prepare the image quality menu for use - * - * \param tinct_options the options to set the menu status for - */ -void ro_gui_menu_prepare_image_quality(unsigned int tinct_options) { - for (int i = 0; i < 4; i++) - image_quality_menu->entries[i].menu_flags &= ~wimp_MENU_TICKED; - if (tinct_options & tinct_USE_OS_SPRITE_OP) - image_quality_menu->entries[0].menu_flags |= wimp_MENU_TICKED; - else if (tinct_options & tinct_ERROR_DIFFUSE) - image_quality_menu->entries[3].menu_flags |= wimp_MENU_TICKED; - else if (tinct_options & tinct_DITHER) - image_quality_menu->entries[2].menu_flags |= wimp_MENU_TICKED; - else - image_quality_menu->entries[1].menu_flags |= wimp_MENU_TICKED; -} - - /** * Prepare the page info window for use * @@ -915,40 +896,6 @@ void ro_gui_menu_prepare_objectinfo(struct box *box) { } -/** - * Prepare languages menu for use - * - * \param accept For Accept-Languages selection - * \param lang Currently selected language - */ -void ro_gui_menu_prepare_languages(bool accept, const char *lang) -{ - struct menu_definition *menu; - struct menu_definition_entry *entry; - char path_buf[40]; - int offset = strlen("lang_"); - - menu = ro_gui_menu_find_menu(languages_menu); - for (entry = menu->entries; entry; entry = entry->next) { - if (!accept) { - snprintf(path_buf, sizeof path_buf, - "NetSurf:Resources.%.2s", - entry->entry_key + offset); - - entry->menu_entry->icon_flags |= is_dir(path_buf) ? - 0 : wimp_ICON_SHADED; - } - else - entry->menu_entry->icon_flags &= ~wimp_ICON_SHADED; - - /* set ticked status */ - if (strncmp(lang, entry->entry_key + offset, 2) == 0) - entry->menu_entry->menu_flags |= wimp_MENU_TICKED; - else - entry->menu_entry->menu_flags &= ~wimp_MENU_TICKED; - } -} - /** * Display a menu of options for a form select control. * @@ -1291,6 +1238,28 @@ struct menu_definition *ro_gui_menu_find_menu(wimp_menu *menu) { } +/** + * Finds the key associated with a menu entry translation. + * + * \param menu the menu to search + * \param translated the translated text + * \return the original message key, or NULL if one could not be found + */ +const char *ro_gui_menu_find_menu_entry_key(wimp_menu *menu, + const char *translated) { + struct menu_definition_entry *entry; + struct menu_definition *definition = ro_gui_menu_find_menu(menu); + + if (!definition) + return NULL; + + for (entry = definition->entries; entry; entry = entry->next) + if (!strcmp(entry->menu_entry->data.indirected_text.text, translated)) + return entry->entry_key; + return NULL; +} + + /** * Finds the menu_definition_entry corresponding to an action for a wimp_menu. * diff --git a/riscos/menus.h b/riscos/menus.h index e42849206..ea6df7a24 100644 --- a/riscos/menus.h +++ b/riscos/menus.h @@ -132,8 +132,7 @@ void ro_gui_menu_selection(wimp_selection* selection); void ro_gui_menu_warning(wimp_message_menu_warning *warning); void ro_gui_menu_init_structure(wimp_menu *menu, int entries); void ro_gui_prepare_navigate(struct gui_window *gui); -void ro_gui_menu_prepare_image_quality(unsigned int tinct_options); -void ro_gui_menu_prepare_languages(bool accept, const char *lang); -void ro_gui_display_font_menu(const char *tick, wimp_w w, wimp_i i); +const char *ro_gui_menu_find_menu_entry_key(wimp_menu *menu, + const char *translated); #endif -- cgit v1.2.3