2006-01-25 05:43:07 +03:00
|
|
|
/*
|
|
|
|
* Copyright 2004 John M Bell <jmb202@ecs.soton.ac.uk>
|
|
|
|
* Copyright 2006 Richard Wilson <info@tinct.net>
|
2007-08-08 20:16:03 +04:00
|
|
|
*
|
|
|
|
* This file is part of NetSurf, http://www.netsurf-browser.org/
|
|
|
|
*
|
|
|
|
* NetSurf is free software; you can redistribute it and/or modify
|
|
|
|
* it under the terms of the GNU General Public License as published by
|
|
|
|
* the Free Software Foundation; version 2 of the License.
|
|
|
|
*
|
|
|
|
* NetSurf is distributed in the hope that it will be useful,
|
|
|
|
* but WITHOUT ANY WARRANTY; without even the implied warranty of
|
|
|
|
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
|
|
|
|
* GNU General Public License for more details.
|
|
|
|
*
|
|
|
|
* You should have received a copy of the GNU General Public License
|
|
|
|
* along with this program. If not, see <http://www.gnu.org/licenses/>.
|
2006-01-25 05:43:07 +03:00
|
|
|
*/
|
|
|
|
|
2008-07-27 02:29:15 +04:00
|
|
|
#include <stdbool.h>
|
2014-06-06 02:01:37 +04:00
|
|
|
|
2013-05-26 01:46:27 +04:00
|
|
|
#include "utils/nsoption.h"
|
2014-06-06 02:01:37 +04:00
|
|
|
#include "utils/log.h"
|
|
|
|
#include "utils/messages.h"
|
|
|
|
#include "utils/utils.h"
|
|
|
|
|
2007-05-31 02:39:54 +04:00
|
|
|
#include "riscos/gui.h"
|
|
|
|
#include "riscos/menus.h"
|
|
|
|
#include "riscos/wimp.h"
|
|
|
|
#include "riscos/wimp_event.h"
|
|
|
|
#include "riscos/configure.h"
|
|
|
|
#include "riscos/configure/configure.h"
|
2014-06-06 02:01:37 +04:00
|
|
|
#include "riscos/dialog.h"
|
2006-01-25 05:43:07 +03:00
|
|
|
|
|
|
|
|
|
|
|
#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);
|
|
|
|
|
2006-06-21 01:35:33 +04:00
|
|
|
bool ro_gui_options_language_initialise(wimp_w w)
|
|
|
|
{
|
2006-01-25 05:43:07 +03:00
|
|
|
/* set the current values */
|
|
|
|
ro_gui_set_icon_string(w, LANGUAGE_INTERFACE_FIELD,
|
2012-03-22 13:34:34 +04:00
|
|
|
ro_gui_options_language_name(nsoption_charp(language) ?
|
|
|
|
nsoption_charp(language) : "en"), true);
|
2006-01-25 05:43:07 +03:00
|
|
|
ro_gui_set_icon_string(w, LANGUAGE_WEB_PAGES_FIELD,
|
2012-03-22 13:34:34 +04:00
|
|
|
ro_gui_options_language_name(nsoption_charp(accept_language) ?
|
|
|
|
nsoption_charp(accept_language) : "en"), true);
|
2006-01-25 05:43:07 +03:00
|
|
|
|
|
|
|
/* 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;
|
|
|
|
|
|
|
|
}
|
|
|
|
|
2006-06-21 01:35:33 +04:00
|
|
|
void ro_gui_options_language_default(wimp_pointer *pointer)
|
|
|
|
{
|
2006-01-25 05:43:07 +03:00
|
|
|
const char *code;
|
2006-06-21 01:35:33 +04:00
|
|
|
|
2006-01-25 05:43:07 +03:00
|
|
|
code = ro_gui_default_language();
|
|
|
|
ro_gui_set_icon_string(pointer->w, LANGUAGE_INTERFACE_FIELD,
|
|
|
|
ro_gui_options_language_name(code ?
|
2008-08-05 05:32:15 +04:00
|
|
|
code : "en"), true);
|
2006-01-25 05:43:07 +03:00
|
|
|
ro_gui_set_icon_string(pointer->w, LANGUAGE_WEB_PAGES_FIELD,
|
|
|
|
ro_gui_options_language_name(code ?
|
2008-08-05 05:32:15 +04:00
|
|
|
code : "en"), true);
|
2006-01-25 05:43:07 +03:00
|
|
|
}
|
|
|
|
|
2006-06-21 01:35:33 +04:00
|
|
|
bool ro_gui_options_language_ok(wimp_w w)
|
|
|
|
{
|
2006-01-25 05:43:07 +03:00
|
|
|
const char *code;
|
|
|
|
char *temp;
|
2006-06-21 01:35:33 +04:00
|
|
|
|
2006-01-25 05:43:07 +03:00
|
|
|
code = ro_gui_menu_find_menu_entry_key(languages_menu,
|
|
|
|
ro_gui_get_icon_string(w, LANGUAGE_INTERFACE_FIELD));
|
|
|
|
if (code) {
|
2006-06-21 01:35:33 +04:00
|
|
|
code += 5; /* skip 'lang_' */
|
2012-03-22 13:34:34 +04:00
|
|
|
if ((!nsoption_charp(language)) ||
|
|
|
|
(strcmp(nsoption_charp(language), code))) {
|
2006-01-25 05:43:07 +03:00
|
|
|
temp = strdup(code);
|
|
|
|
if (temp) {
|
2012-03-22 13:34:34 +04:00
|
|
|
nsoption_set_charp(language, temp);
|
2006-01-25 05:43:07 +03:00
|
|
|
} else {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("No memory to duplicate language code");
|
2016-04-26 17:16:33 +03:00
|
|
|
ro_warn_user("NoMemory", 0);
|
2006-01-25 05:43:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
code = ro_gui_menu_find_menu_entry_key(languages_menu,
|
|
|
|
ro_gui_get_icon_string(w, LANGUAGE_WEB_PAGES_FIELD));
|
|
|
|
if (code) {
|
2006-06-21 01:35:33 +04:00
|
|
|
code += 5; /* skip 'lang_' */
|
2012-03-22 13:34:34 +04:00
|
|
|
if ((!nsoption_charp(accept_language)) ||
|
|
|
|
(strcmp(nsoption_charp(accept_language), code))) {
|
2006-01-25 05:43:07 +03:00
|
|
|
temp = strdup(code);
|
|
|
|
if (temp) {
|
2012-03-22 13:34:34 +04:00
|
|
|
nsoption_set_charp(accept_language,temp);
|
2006-01-25 05:43:07 +03:00
|
|
|
} else {
|
2015-05-28 18:08:46 +03:00
|
|
|
LOG("No memory to duplicate language code");
|
2016-04-26 17:16:33 +03:00
|
|
|
ro_warn_user("NoMemory", 0);
|
2006-01-25 05:43:07 +03:00
|
|
|
}
|
|
|
|
}
|
|
|
|
}
|
|
|
|
ro_gui_save_options();
|
2006-06-21 01:35:33 +04:00
|
|
|
return true;
|
2006-01-25 05:43:07 +03:00
|
|
|
}
|
|
|
|
|
|
|
|
|
|
|
|
/**
|
|
|
|
* 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
|
|
|
|
*/
|
2006-06-21 01:35:33 +04:00
|
|
|
const char *ro_gui_options_language_name(const char *code)
|
|
|
|
{
|
2006-01-25 05:43:07 +03:00
|
|
|
char key[] = "lang_xx";
|
|
|
|
key[5] = code[0];
|
|
|
|
key[6] = code[1];
|
2006-06-21 01:35:33 +04:00
|
|
|
|
2006-01-25 05:43:07 +03:00
|
|
|
return messages_get(key);
|
|
|
|
}
|