-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathlanguage.cxx
375 lines (305 loc) · 11.5 KB
/
language.cxx
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
/*
* Language support for GeeXboX FLTK Generator
* Copyright (C) 2005-2006 Amir Shalem
* Copyright (C) 2007-2008 Mathieu Schroeter
*
* This program 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; either version 2 of the License, or
* (at your option) any later version.
* This program 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, write to the Free Software
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
*/
#include "generatorUI.h"
#include "config.h"
#include "configparser.h"
#include "compile.h"
#include "fs.h"
#include "language.h"
#include "system.h"
#include "theme.h"
#include "utils.h"
#include <FL/fl_ask.H> /* fl_alert */
#include <FL/filename.H> /* fl_filename_name */
#include <FL/Fl_File_Chooser.H> /* fl_file_chooser */
void change_font(Fl_Output *o, Fl_Check_Button *b)
{
const char *new_file;
const char *old_file = o->value();
if (!old_file || !*old_file)
old_file = PATH_FONTS;
new_file = fl_file_chooser("Choose font?", "*.ttf", old_file);
if (new_file)
{
o->value(new_file);
o->activate();
b->value(1);
}
}
int init_language_tab(GeneratorUI *ui)
{
char buf[256], *word;
char buf2[50], buf3[256], buf4[256], buf5[256];
char lang[256];
struct lang_info *l;
struct charset_info *c;
const Fl_Menu_Item *m;
config_t *config;
if (target_arch == TARGET_ARCH_I386 || target_arch == TARGET_ARCH_X86_64) {
config = config_open(PATH_BASEISO "/boot/isolinux.cfg", 0);
if (!config) {
fl_alert("Missing isolinux configuration files.\n");
return 0;
}
config_getvar(config, "lang", lang, sizeof(lang));
config_destroy(config);
}
else if (target_arch == TARGET_ARCH_POWERPC) {
config = config_open(PATH_BASEISO "/boot/yaboot.conf", 0);
if (!config) {
fl_alert("Missing yaboot configuration files.\n");
return 0;
}
config_getvar(config, "lang", lang, sizeof(lang));
config_destroy(config);
}
config = config_open(PATH_LANGCONF, 1);
if (!config) {
fl_alert("Missing language configuration files.\n");
return 0;
}
config_getvar(config, "CHARSETS", buf, sizeof(buf));
for (word = strtok(buf, " \t"); word; word = strtok(NULL, " \t"))
{
c = (struct charset_info*)malloc(sizeof(struct charset_info));
if (c)
{
ui->sub_charset->add(word, 0, NULL, c);
c->menu_font = c->sub_font = NULL;
c->name = strdup(word);
replace_char(word, '-', '_');
c->codename = strdup(word);
sprintf(buf2, "%s_menufont", word);
config_getvar(config, buf2, buf3, sizeof(buf3));
if (buf3[0])
c->menu_font = strdup(buf3);
sprintf(buf2, "%s_subfont", word);
config_getvar(config, buf2, buf3, sizeof(buf3));
if (buf3[0])
c->sub_font = strdup(buf3);
sprintf(buf2, "%s_font", word);
config_getvar(config, buf2, buf3, sizeof(buf3));
if (!buf3[0])
config_getvar(config, "DEFAULT_FONT", buf3, sizeof(buf3));
if (!c->menu_font)
c->menu_font = strdup(buf3);
if (!c->sub_font)
c->sub_font = strdup(buf3);
}
}
config_getvar(config, "LANGUAGES", buf, sizeof(buf));
for (word = strtok(buf, " \t"); word; word = strtok(NULL, " \t"))
{
sprintf(buf2, "%s_name", word);
config_getvar(config, buf2, buf3, sizeof(buf3));
l = (struct lang_info*)malloc(sizeof(struct lang_info));
if (l)
{
l->c = NULL;
ui->menu_lang->add(buf3, 0, NULL, l);
l->shortname = strdup(word);
sprintf(buf2, "%s_charset", word);
config_getvar(config, buf2, buf3, sizeof(buf3));
m = ui->sub_charset->find_item(buf3);
if (!m) {
fl_alert("Missing language character set %s.\n", buf3);
config_destroy(config);
return 0;
}
l->c = (struct charset_info*)m->user_data();
}
}
if (ui->sub_charset->size() < 1 || ui->menu_lang->size() < 1) {
fl_alert("No languages or character set found.\n");
config_destroy(config);
return 0;
}
config_getvar(config, "DEFAULT_LANGUAGE", buf, sizeof(buf));
sprintf(buf2, "%s_charset", buf);
sprintf(buf4, "%s_charset", lang);
config_getvar(config, buf2, buf3, sizeof(buf3));
config_getvar(config, buf4, buf5, sizeof(buf5));
if ((m = ui->sub_charset->find_item(buf5)))
ui->sub_charset->value(m);
else if ((m = ui->sub_charset->find_item(buf3)))
ui->sub_charset->value(m);
else
ui->sub_charset->value(0);
sprintf(buf2, "%s_name", buf);
sprintf(buf4, "%s_name", lang);
config_getvar(config, buf2, buf3, sizeof(buf3));
config_getvar(config, buf4, buf5, sizeof(buf5));
if ((m = ui->menu_lang->find_item(buf5)))
ui->menu_lang->value(m);
else if ((m = ui->menu_lang->find_item(buf3)))
ui->menu_lang->value(m);
else
ui->menu_lang->value(0);
config_destroy(config);
return 1;
}
int write_language_settings(GeneratorUI *ui)
{
struct lang_info *l;
if (!ui->menu_lang->mvalue()) {
fl_alert("Please pick menu language.\n");
return 0;
}
l = (struct lang_info*)ui->menu_lang->mvalue()->user_data();
if (target_arch == TARGET_ARCH_I386 || target_arch == TARGET_ARCH_X86_64) {
config_t *config, *config2;
config = config_open(PATH_BASEISO "/boot/isolinux.cfg", 0);
config2 = config_open(PATH_BASEISO "/boot/pxelinux.cfg/default", 0);
if (!config || !config2) {
fl_alert("Failed to open for write isolinux configuration.\n");
return 0;
}
config_setvar(config, "lang", l->shortname);
config_setvar(config2, "lang", l->shortname);
config_write(config, PATH_BASEISO "/boot/isolinux.cfg");
config_write(config2, PATH_BASEISO "/boot/pxelinux.cfg/default");
config_destroy(config);
config_destroy(config2);
}
else if (target_arch == TARGET_ARCH_POWERPC) {
config_t *config, *config2;
config = config_open(PATH_BASEISO "/boot/yaboot.conf", 0);
config2 = config_open(PATH_BASEISO "/boot/netboot/yaboot.conf", 0);
if (!config || !config2) {
fl_alert("Failed to open for write yaboot configuration.\n");
return 0;
}
config_setvar(config, "lang", l->shortname);
config_setvar(config2, "lang", l->shortname);
config_write(config, PATH_BASEISO "/boot/yaboot.conf");
config_write(config2, PATH_BASEISO "/boot/netboot/yaboot.conf");
config_destroy(config);
config_destroy(config2);
}
return 1;
}
static void show_font_warning(const char *font)
{
fl_alert("Font '%s' is missing.\nBut exists as an external package, please download it using the Packages tab.\n", font);
}
int copy_language_files(GeneratorUI *ui)
{
char buf[256], buf2[256], *tmp;
const char *filename;
struct charset_info *c;
struct lang_info *l;
FILE *fp;
if (!ui->menu_lang->mvalue()) {
fl_alert("Please pick menu language.\n");
return 0;
}
if (!ui->sub_charset->mvalue()) {
fl_alert("Please pick subtitle character set.\n");
return 0;
}
l = (struct lang_info*)ui->menu_lang->mvalue()->user_data();
c = (struct charset_info*)ui->sub_charset->mvalue()->user_data();
if (!fl_filename_isdir(PATH_BASEISO "/etc/installator"))
my_mkdir(PATH_BASEISO "/etc/installator");
if (!fl_filename_isdir(PATH_BASEISO "/etc/configurator"))
my_mkdir(PATH_BASEISO "/etc/configurator");
sprintf(buf2, "i18n/texts/help_en.txt");
sprintf(buf, PATH_BASEISO "/usr/share/mplayer/help_en.txt");
copy_file(buf2, buf);
strcpy(buf2, "i18n/texts/en.lang");
strcpy(buf, PATH_BASEISO "/etc/mplayer/en.lang");
copy_file(buf2, buf);
strcpy(buf2, "i18n/texts/en.install");
strcpy(buf, PATH_BASEISO "/etc/installator/en.install");
copy_file(buf2, buf);
strcpy(buf2, "i18n/texts/en.config");
strcpy(buf, PATH_BASEISO "/etc/configurator/en.config");
copy_file(buf2, buf);
if (strcmp(l->shortname, "en")) {
sprintf(buf2, "i18n/texts/help_%s.txt", l->shortname);
sprintf(buf, PATH_BASEISO "/usr/share/mplayer/help_%s.txt", l->shortname);
if (file_exists(buf2))
copy_file(buf2, buf);
sprintf(buf2, "i18n/texts/%s.lang", l->shortname);
sprintf(buf, PATH_BASEISO "/etc/mplayer/%s.lang", l->shortname);
if (file_exists(buf2))
copy_file(buf2, buf);
sprintf(buf2, "i18n/texts/%s.install", l->shortname);
sprintf(buf, PATH_BASEISO "/etc/installator/%s.install", l->shortname);
if (file_exists(buf2))
copy_file(buf2, buf);
sprintf(buf2, "i18n/texts/%s.config", l->shortname);
sprintf(buf, PATH_BASEISO "/etc/configurator/%s.config", l->shortname);
if (file_exists(buf2))
copy_file(buf2, buf);
}
sprintf(buf2, "i18n/lang.conf");
sprintf(buf, PATH_BASEISO "/etc/lang.conf");
copy_file(buf2, buf);
fp = fopen(PATH_BASEISO "/etc/subfont", "wb");
if (!fp) {
fl_alert("Failed to write language configuration (%s).\n", "/etc/subfont");
return 0;
}
fprintf(fp, "%s", c->name);
fclose(fp);
fp = fopen(PATH_BASEISO "/etc/lang.conf", "ab");
if (!fp) {
fl_alert("Failed to write language configuration (%s).\n", "/etc/lang.conf");
return 0;
}
if (ui->override_sub_font->value()) {
filename = fl_filename_name(ui->sub_font->value());
sprintf(buf, PATH_BASEISO "/usr/share/fonts/%s", filename);
copy_file(ui->sub_font->value(), buf);
fprintf(fp, "%s_subfont=\"%s\"\n", c->codename, filename);
} else {
sprintf(buf2, PATH_FONTS "/%s", c->sub_font);
sprintf(buf, PATH_BASEISO "/usr/share/fonts/%s", c->sub_font);
if (!file_exists(buf2))
{
fclose(fp);
show_font_warning(c->sub_font);
return 0;
}
copy_file(buf2, buf);
}
/* Menu Font */
if (ui->override_menu_font->value()) {
filename = fl_filename_name(ui->menu_font->value());
sprintf(buf, PATH_BASEISO "/usr/share/fonts/%s", filename);
copy_file(ui->menu_font->value(), buf);
fprintf(fp, "%s_menufont=\"%s\"\n", l->c->codename, filename);
} else if ((tmp = valid_theme_font(ui->theme->mvalue()->label(), l->c))) {
strcpy(buf, PATH_BASEISO "/usr/share/fonts/themefont.ttf");
copy_file(tmp, buf);
free(tmp);
} else {
sprintf(buf2, PATH_FONTS "/%s", l->c->menu_font);
sprintf(buf, PATH_BASEISO "/usr/share/fonts/%s", l->c->menu_font);
if (!file_exists(buf2))
{
fclose(fp);
show_font_warning(l->c->menu_font);
return 0;
}
copy_file(buf2, buf);
}
fclose(fp); /* close /etc/lang.conf */
return 1;
}