NetSurf
con_language.c
Go to the documentation of this file.
1/*
2 * Copyright 2004 John M Bell <jmb202@ecs.soton.ac.uk>
3 * Copyright 2006 Richard Wilson <info@tinct.net>
4 *
5 * This file is part of NetSurf, http://www.netsurf-browser.org/
6 *
7 * NetSurf is free software; you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation; version 2 of the License.
10 *
11 * NetSurf is distributed in the hope that it will be useful,
12 * but WITHOUT ANY WARRANTY; without even the implied warranty of
13 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
14 * GNU General Public License for more details.
15 *
16 * You should have received a copy of the GNU General Public License
17 * along with this program. If not, see <http://www.gnu.org/licenses/>.
18 */
19
20#include <stdbool.h>
21
22#include "utils/nsoption.h"
23#include "utils/log.h"
24#include "utils/messages.h"
25
26#include "riscos/gui.h"
27#include "riscos/menus.h"
28#include "riscos/wimp.h"
29#include "riscos/wimp_event.h"
30#include "riscos/configure.h"
32#include "riscos/dialog.h"
33
34
35#define LANGUAGE_INTERFACE_FIELD 3
36#define LANGUAGE_INTERFACE_GRIGHT 4
37#define LANGUAGE_WEB_PAGES_FIELD 6
38#define LANGUAGE_WEB_PAGES_GRIGHT 7
39#define LANGUAGE_DEFAULT_BUTTON 8
40#define LANGUAGE_CANCEL_BUTTON 9
41#define LANGUAGE_OK_BUTTON 10
42
43static void ro_gui_options_language_default(wimp_pointer *pointer);
44static bool ro_gui_options_language_ok(wimp_w w);
45static const char *ro_gui_options_language_name(const char *code);
46
48{
49 /* set the current values */
52 nsoption_charp(language) : "en"), true);
55 nsoption_charp(accept_language) : "en"), true);
56
57 /* initialise all functions for a newly created window */
67 ro_gui_wimp_event_set_help_prefix(w, "HelpLanguageConfig");
69 return true;
70
71}
72
73void ro_gui_options_language_default(wimp_pointer *pointer)
74{
75 const char *code;
76
80 code : "en"), true);
83 code : "en"), true);
84}
85
87{
88 const char *code;
89 char *temp;
90
93 if (code) {
94 code += 5; /* skip 'lang_' */
95 if ((!nsoption_charp(language)) ||
96 (strcmp(nsoption_charp(language), code))) {
97 temp = strdup(code);
98 if (temp) {
99 nsoption_set_charp(language, temp);
100 } else {
101 NSLOG(netsurf, INFO,
102 "No memory to duplicate language code");
103 ro_warn_user("NoMemory", 0);
104 }
105 }
106 }
109 if (code) {
110 code += 5; /* skip 'lang_' */
111 if ((!nsoption_charp(accept_language)) ||
112 (strcmp(nsoption_charp(accept_language), code))) {
113 temp = strdup(code);
114 if (temp) {
115 nsoption_set_charp(accept_language,temp);
116 } else {
117 NSLOG(netsurf, INFO,
118 "No memory to duplicate language code");
119 ro_warn_user("NoMemory", 0);
120 }
121 }
122 }
124 return true;
125}
126
127
128/**
129 * Convert a 2-letter ISO language code to the language name.
130 *
131 * \param code 2-letter ISO language code
132 * \return language name, or code if unknown
133 */
134const char *ro_gui_options_language_name(const char *code)
135{
136 char key[] = "lang_xx";
137 key[5] = code[0];
138 key[6] = code[1];
139
140 return messages_get(key);
141}
#define LANGUAGE_INTERFACE_GRIGHT
Definition: con_language.c:36
bool ro_gui_options_language_initialise(wimp_w w)
Definition: con_language.c:47
#define LANGUAGE_INTERFACE_FIELD
Definition: con_language.c:35
#define LANGUAGE_DEFAULT_BUTTON
Definition: con_language.c:39
static void ro_gui_options_language_default(wimp_pointer *pointer)
Definition: con_language.c:73
#define LANGUAGE_WEB_PAGES_GRIGHT
Definition: con_language.c:38
static bool ro_gui_options_language_ok(wimp_w w)
Definition: con_language.c:86
static const char * ro_gui_options_language_name(const char *code)
Convert a 2-letter ISO language code to the language name.
Definition: con_language.c:134
#define LANGUAGE_WEB_PAGES_FIELD
Definition: con_language.c:37
#define LANGUAGE_OK_BUTTON
Definition: con_language.c:41
#define LANGUAGE_CANCEL_BUTTON
Definition: con_language.c:40
Automated RISC OS WIMP event handling (interface).
RISC OS option setting (interface).
void ro_gui_save_options(void)
Save the current options.
Definition: dialog.c:670
#define NSLOG(catname, level, logmsg, args...)
Definition: log.h:116
const char * ro_gui_menu_find_menu_entry_key(wimp_menu *menu, const char *translated)
Finds the key associated with a menu entry translation.
Definition: menus.c:735
wimp_menu * languages_menu
Definition: menus.c:104
const char * messages_get(const char *key)
Fast lookup of a message by key from the standard Messages hash.
Definition: messages.c:241
Localised message support (interface).
nserror ro_warn_user(const char *warning, const char *detail)
Display a warning for a serious problem (eg memory exhaustion).
Definition: gui.c:2076
const char * ro_gui_default_language(void)
Determine the default language to use.
Definition: gui.c:1383
Option reading and saving interface.
#define nsoption_charp(OPTION)
Get the value of a string option.
Definition: nsoption.h:297
#define nsoption_set_charp(OPTION, VALUE)
set string option in default table
Definition: nsoption.h:338
void ro_gui_set_icon_string(wimp_w w, wimp_i i, const char *text, bool is_utf8)
Set the contents of a text or sprite icon to a string.
Definition: wimp.c:269
const char * ro_gui_get_icon_string(wimp_w w, wimp_i i)
Read the contents of a text or sprite icon.
Definition: wimp.c:235
General RISC OS WIMP/OS library functions (interface).
bool ro_gui_wimp_event_set_help_prefix(wimp_w w, const char *help_prefix)
Set the associated help prefix for a given window.
Definition: wimp_event.c:390
bool ro_gui_wimp_event_register_menu_gright(wimp_w w, wimp_i i, wimp_i gright, wimp_menu *menu)
Register an icon menu to be automatically handled.
Definition: wimp_event.c:1331
bool ro_gui_wimp_event_register_cancel(wimp_w w, wimp_i i)
Register a function to be called for the Cancel action on a window.
Definition: wimp_event.c:1403
bool ro_gui_wimp_event_memorise(wimp_w w)
Memorises the current state of any registered components in a window.
Definition: wimp_event.c:139
bool ro_gui_wimp_event_register_ok(wimp_w w, wimp_i i, bool(*callback)(wimp_w w))
Register a function to be called for the OK action on a window.
Definition: wimp_event.c:1417
bool ro_gui_wimp_event_register_button(wimp_w w, wimp_i i, void(*callback)(wimp_pointer *pointer))
Register a function to be called when a particular button is pressed.
Definition: wimp_event.c:1387
Automated RISC OS WIMP event handling (interface).