From 37cf5807433b3d71204bd9413d5a46d21a1e322a Mon Sep 17 00:00:00 2001 From: James Bursa Date: Fri, 27 Feb 2004 14:09:15 +0000 Subject: [PATCH] [project @ 2004-02-27 14:09:15 by bursa] Implement option_language. svn path=/import/netsurf/; revision=574 --- riscos/constdata.c | 2 -- riscos/constdata.h | 2 -- riscos/dialog.c | 4 --- riscos/gui.c | 84 +++++++++++++++++++++++++++++++++++++++++----- riscos/menus.c | 2 -- riscos/options.h | 7 ++-- utils/utils.c | 9 +---- 7 files changed, 81 insertions(+), 29 deletions(-) diff --git a/riscos/constdata.c b/riscos/constdata.c index a7589e73e..f720ddec6 100644 --- a/riscos/constdata.c +++ b/riscos/constdata.c @@ -18,6 +18,4 @@ const char * const COOKIE_URL = "file:///%3CWimp$ScrapDir%3E/WWW/NetSurf/Cookies #endif const char * const GESTURES_URL = "file:///%3CNetSurf$Dir%3E/Resources/gestures"; -const char * const HOME_URL = "file:///%3CNetSurf$Dir%3E/Docs/en/intro"; -const char * const HELP_URL = "file:///%3CNetSurf$Dir%3E/Docs/en/index"; const char * const THEMES_URL = "http://netsurf.sourceforge.net/themes/"; diff --git a/riscos/constdata.h b/riscos/constdata.h index 088174678..909720a60 100644 --- a/riscos/constdata.h +++ b/riscos/constdata.h @@ -19,8 +19,6 @@ extern const char * const COOKIE_URL; #endif #endif extern const char * const GESTURES_URL; -extern const char * const HOME_URL; -extern const char * const HELP_URL; extern const char * const THEMES_URL; #endif diff --git a/riscos/dialog.c b/riscos/dialog.c index 7ba79591e..6f47f2dea 100644 --- a/riscos/dialog.c +++ b/riscos/dialog.c @@ -233,8 +233,6 @@ void ro_gui_dialog_click_config(wimp_pointer *pointer) void ro_gui_dialog_click_config_br(wimp_pointer *pointer) { - struct browser_window* bw; - switch (pointer->i) { case ICON_CONFIG_BR_OK: if (pointer->buttons == wimp_CLICK_SELECT) @@ -320,8 +318,6 @@ void ro_gui_dialog_click_config_prox(wimp_pointer *pointer) void ro_gui_dialog_click_config_th(wimp_pointer *pointer) { - struct browser_window* bw; - switch (pointer->i) { case ICON_CONFIG_TH_OK: if (pointer->buttons == wimp_CLICK_SELECT) diff --git a/riscos/gui.c b/riscos/gui.c index 40337f6d5..aa722e26f 100644 --- a/riscos/gui.c +++ b/riscos/gui.c @@ -17,6 +17,7 @@ #include "oslib/hourglass.h" #include "oslib/inetsuite.h" #include "oslib/os.h" +#include "oslib/osbyte.h" #include "oslib/osfile.h" #include "oslib/plugin.h" #include "oslib/wimp.h" @@ -103,6 +104,7 @@ struct ro_gui_poll_block { struct ro_gui_poll_block *ro_gui_poll_queued_blocks = 0; +static void ro_gui_choose_language(void); static void ro_gui_icon_bar_create(void); static void ro_gui_handle_event(wimp_event_no event, wimp_block *block); static void ro_gui_poll_queue(wimp_event_no event, wimp_block* block); @@ -128,13 +130,19 @@ static char *ro_path_to_url(const char *path); void gui_init(int argc, char** argv) { + char path[40]; char theme_fname[256]; - os_error *e; + os_error *error; xhourglass_start(1); + options_read("Choices:WWW.NetSurf.Choices"); + + ro_gui_choose_language(); + NETSURF_DIR = getenv("NetSurf$Dir"); - messages_load(".Resources.en.Messages"); + sprintf(path, ".Resources.%s.Messages", option_language); + messages_load(path); task_handle = wimp_initialise(wimp_VERSION_RO38, "NetSurf", (wimp_message_list*) &task_messages, 0); @@ -143,8 +151,6 @@ void gui_init(int argc, char** argv) if (getenv("NetSurf$Start_URI_Handler")) xwimp_start_task("Desktop", 0); - options_read("Choices:WWW.NetSurf.Choices"); - if (option_theme) { snprintf(theme_fname, sizeof(theme_fname), ".Themes.%s", option_theme); @@ -159,9 +165,13 @@ void gui_init(int argc, char** argv) } ro_theme_load(theme_fname); - e = xwimp_open_template(".Resources.en.Templates"); - if(e) { - die(e->errmess); + sprintf(path, ".Resources.%s.Templates", option_language); + error = xwimp_open_template(path); + if (error) { + LOG(("xwimp_open_template failed: 0x%x: %s", + error->errnum, error->errmess)); + warn_user(error->errmess); + exit(EXIT_FAILURE); } ro_gui_dialog_init(); ro_gui_download_init(); @@ -175,6 +185,56 @@ void gui_init(int argc, char** argv) } +/** + * 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. + */ + +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) { + if (2 < strlen(option_language)) + option_language[2] = 0; + sprintf(path, ".Resources.%s", option_language); + if (is_dir(path)) + return; + free(option_language); + option_language = 0; + } + + /* choose a language from the configured country number */ + error = xosbyte_read(osbyte_VAR_COUNTRY_NUMBER, &country); + if (error) { + LOG(("xosbyte_read failed: 0x%x: %s", + error->errnum, error->errmess)); + country = 1; + } + switch (country) { + case 6: /* France */ + case 18: /* Canada2 (French Canada?) */ + lang = "fr"; + break; + default: + lang = "en"; + break; + } + sprintf(path, ".Resources.%s", lang); + if (is_dir(path)) + option_language = strdup(lang); + else + option_language = strdup("en"); + assert(option_language); +} + + /** * Create an iconbar icon. */ @@ -500,7 +560,10 @@ void ro_gui_icon_bar_click(wimp_pointer *pointer) ro_gui_create_menu(iconbar_menu, pointer->pos.x - 64, 96 + iconbar_menu_height, NULL); } else if (pointer->buttons == wimp_CLICK_SELECT) { - browser_window_create(HOME_URL); + char url[80]; + sprintf(url, "file:///%%3CNetSurf$Dir%%3E/Docs/intro.%s", + option_language); + browser_window_create(url); } } @@ -865,7 +928,10 @@ void ro_gui_screen_size(int *width, int *height) void ro_gui_open_help_page(void) { - browser_window_create(HELP_URL); + char url[80]; + sprintf(url, "file:///%%3CNetSurf$Dir%%3E/Docs/docs.%s", + option_language); + browser_window_create(url); } diff --git a/riscos/menus.c b/riscos/menus.c index 2c753220d..ee4fc1254 100644 --- a/riscos/menus.c +++ b/riscos/menus.c @@ -252,8 +252,6 @@ void ro_gui_menu_selection(wimp_selection *selection) case 0: /* Open URL... */ break; case 1: /* Home */ - browser_window_go(current_gui->data.browser.bw, - HOME_URL); break; case 2: /* Back */ history_back(current_gui->data.browser.bw, diff --git a/riscos/options.h b/riscos/options.h index 965216170..a70e58198 100644 --- a/riscos/options.h +++ b/riscos/options.h @@ -19,17 +19,20 @@ extern bool option_use_mouse_gestures; extern bool option_allow_text_selection; extern bool option_show_toolbar; extern char *option_theme; +extern char *option_language; #define EXTRA_OPTION_DEFINE \ bool option_use_mouse_gestures = false;\ bool option_allow_text_selection = true;\ bool option_show_toolbar = true;\ -char *option_theme = 0; +char *option_theme = 0;\ +char *option_language = 0; #define EXTRA_OPTION_TABLE \ { "use_mouse_gestures", OPTION_BOOL, &option_use_mouse_gestures },\ { "allow_text_selection", OPTION_BOOL, &option_allow_text_selection },\ { "show_toolbar", OPTION_BOOL, &option_show_toolbar },\ -{ "theme", OPTION_STRING, &option_theme } +{ "theme", OPTION_STRING, &option_theme },\ +{ "language", OPTION_STRING, &option_language } #endif diff --git a/utils/utils.c b/utils/utils.c index 4e04af353..889985178 100644 --- a/utils/utils.c +++ b/utils/utils.c @@ -216,19 +216,12 @@ char *url_join(char *rel_url, char *base_url) return xstrdup(ABOUT_URL); } #ifdef WITH_COOKIES - else if (strcasecmp(rel_url, "about:cookies") == 0) { + if (strcasecmp(rel_url, "about:cookies") == 0) { cookie_create(); return xstrdup(COOKIE_URL); } #endif - else #endif - if (strcasecmp(rel_url, "help:") == 0) { - return xstrdup(HELP_URL); - } - else if (strcasecmp(rel_url, "home:") == 0) { - return xstrdup(HOME_URL); - } #endif if (!base_url) {