]>
Commit | Line | Data |
---|---|---|
0cb1d1e1 AA |
1 | diff -Nur old/dillorc new/dillorc |
2 | --- old/dillorc 2004-01-25 16:18:12.000000000 +0100 | |
3 | +++ new/dillorc 2004-03-07 17:42:28.000000000 +0100 | |
1605e886 | 4 | @@ -35,6 +35,9 @@ |
5 | # If you prefer oblique over italic fonts, uncoment next line | |
6 | #use_oblique=YES | |
7 | ||
8 | +# Use this value as charset part of font for loading. (default is iso8859-1) | |
9 | +# font_charset=iso8859-5 | |
10 | + | |
11 | # Show tooltip popup for images? | |
12 | # Note: We use the "title" attribute and not "alt". | |
13 | # More info at: http://bugzilla.mozilla.org/show_bug.cgi?id=25537 | |
0cb1d1e1 AA |
14 | diff -Nur old/encodings new/encodings |
15 | --- old/encodings 1970-01-01 01:00:00.000000000 +0100 | |
16 | +++ new/encodings 2004-03-07 17:32:50.000000000 +0100 | |
1605e886 | 17 | @@ -0,0 +1,18 @@ |
18 | +<enc value="ASCII">7-bit ASCII</enc> | |
19 | +<enc value="ISO8859-1">Western European (ISO 8859-1)</enc> | |
20 | +<enc value="ISO8859-15">Western European (ISO 8859-15)</enc> | |
21 | +<enc value="CP1252">Western European (CodePage1252)</enc> | |
22 | +<enc value="ISO8859-2">Central European (ISO 8859-2)</enc> | |
23 | +<enc value="CP1250">Central European (CodePage1250)</enc> | |
24 | +<enc value="ISO8859-3">Southern European (ISO 8859-3)</enc> | |
25 | +<enc value="KOI8-R">Cyrillic (KOI8-R)</enc> | |
26 | +<enc value="CP1251">Cyrillic (CodePage1251)</enc> | |
27 | +<enc value="IBM866">Cyrillic (IBM866)</enc> | |
28 | +<enc value="ISO8859-13">Baltic (ISO 8859-13)</enc> | |
29 | +<enc value="ISO8859-4">Baltic (ISO 8859-4)</enc> | |
30 | +<enc value="CP1257">Baltic (CodePage1257)</enc> | |
31 | +<enc value="ISO8859-10">Nordic (ISO 8859-10)</enc> | |
32 | +<enc value="ISO8859-14">Celtic (ISO 8859-14)</enc> | |
33 | +<enc value="KOI8-U">Ukraine (KOI8-U)</enc> | |
34 | +<enc value="UTF-8">Unicode (UTF-8)</enc> | |
35 | +<enc value="UTF-16">Unicode (UTF-16)</enc> | |
0cb1d1e1 AA |
36 | diff -Nur old/src/browser.h new/src/browser.h |
37 | --- old/src/browser.h 2004-02-03 20:03:28.000000000 +0100 | |
38 | +++ new/src/browser.h 2004-03-07 17:45:51.000000000 +0100 | |
39 | @@ -4,9 +4,8 @@ | |
1605e886 | 40 | #include <sys/types.h> |
41 | #include <gdk/gdk.h> | |
42 | #include <gtk/gtk.h> | |
43 | - | |
44 | #include "url.h" /* for DilloUrl */ | |
45 | - | |
1605e886 | 46 | +#include "encodings-types.h" |
0cb1d1e1 | 47 | |
1605e886 | 48 | typedef struct _BrowserWindow BrowserWindow; |
49 | typedef struct _DilloMenuPopup DilloMenuPopup; | |
0cb1d1e1 AA |
50 | @@ -65,6 +64,9 @@ |
51 | /* Popup menu for this BrowserWindow */ | |
52 | DilloMenuPopup menu_popup; | |
1605e886 | 53 | |
54 | + /* The encoding menu */ | |
55 | + GtkWidget *enc_menu; | |
56 | + | |
57 | /* The "Headings" and "Anchors" menus */ | |
58 | GtkWidget *pagemarks_menuitem; | |
59 | GtkWidget *pagemarks_menu; | |
0cb1d1e1 | 60 | @@ -132,6 +134,10 @@ |
1605e886 | 61 | |
0cb1d1e1 AA |
62 | /* The id for the idle function that sets button sensitivity. */ |
63 | guint sens_idle_id; | |
1605e886 | 64 | + |
65 | + /* encodings variable */ | |
66 | + gchar* encoding; /* the selected character set (pointer to static content -don't free it*/ | |
67 | + deConversion dcv; /* handle for character set conversion */ | |
68 | }; | |
69 | ||
70 | ||
0cb1d1e1 AA |
71 | diff -Nur old/src/dillo.c new/src/dillo.c |
72 | --- old/src/dillo.c 2004-02-06 16:53:59.000000000 +0100 | |
73 | +++ new/src/dillo.c 2004-03-07 19:43:48.000000000 +0100 | |
1605e886 | 74 | @@ -22,6 +22,13 @@ |
75 | #include <stdio.h> | |
76 | #include <gtk/gtk.h> | |
77 | ||
78 | +#ifdef HAVE_LANGINFO | |
79 | +#include <langinfo.h> | |
80 | +#if ! defined(CODESET) && defined (_NL_CTYPE_CODESET_NAME) | |
81 | +#define CODESET _NL_CTYPE_CODESET_NAME | |
82 | +#endif | |
83 | +#endif | |
84 | + | |
85 | #include <sys/types.h> | |
86 | #include <sys/stat.h> | |
87 | #include <string.h> | |
0cb1d1e1 | 88 | @@ -41,6 +48,7 @@ |
1605e886 | 89 | #include "nav.h" |
90 | #include "history.h" | |
91 | #include "bookmark.h" | |
92 | +#include "encodings.h" | |
93 | #include "dicache.h" | |
94 | #include "dns.h" | |
95 | #include "IO/mime.h" | |
0cb1d1e1 | 96 | @@ -198,7 +206,7 @@ |
1605e886 | 97 | */ |
98 | gint main(int argc, char *argv[]) | |
99 | { | |
eadaba5f | 100 | - gchar *dir, *curr_locale; |
101 | + gchar *dir, *loctmp; | |
1605e886 | 102 | DilloUrl *start_url; |
103 | BrowserWindow *bw; | |
104 | guint32 xid = 0; | |
0cb1d1e1 AA |
105 | @@ -210,9 +218,6 @@ |
106 | gint xpos = D_GEOMETRY_DEFAULT_XPOS, ypos = D_GEOMETRY_DEFAULT_YPOS; | |
107 | gint width = D_GEOMETRY_DEFAULT_WIDTH, height = D_GEOMETRY_DEFAULT_HEIGHT; | |
1605e886 | 108 | |
109 | - /* set locale */ | |
110 | - curr_locale = g_strdup(setlocale(LC_ALL, NULL)); | |
111 | - gtk_set_locale(); | |
112 | /* Initialize GUI and parse GTK related args */ | |
113 | gtk_init(&argc, &argv); | |
114 | gdk_rgb_init(); | |
0cb1d1e1 | 115 | @@ -254,9 +259,21 @@ |
1605e886 | 116 | } |
117 | } | |
118 | ||
119 | - /* Send a delayed locale-related message */ | |
0cb1d1e1 | 120 | - MSG("Setting locale to %s...\n", curr_locale); |
1605e886 | 121 | - g_free(curr_locale); |
122 | + curr_locale=gtk_set_locale(); | |
123 | +#ifdef HAVE_LANGINFO | |
124 | + curr_locale = nl_langinfo(CODESET); | |
125 | +#else | |
126 | + loctmp = strchr(curr_locale, '.'); | |
127 | + if (loctmp != NULL) { | |
128 | + gchar** trk = g_strsplit(++loctmp, ";", 1); | |
129 | + curr_locale = g_strdup(trk[0]); | |
130 | + g_strfreev(trk); | |
131 | + } else { | |
132 | + curr_locale = "ASCII"; | |
133 | + } | |
134 | +#endif | |
135 | + | |
136 | + g_print("Setting locale to %s\n",curr_locale); | |
137 | ||
138 | /* This lets threads in the file module end peacefully when aborted | |
139 | * todo: implement a cleaner mechanism (in file.c) */ | |
0cb1d1e1 AA |
140 | @@ -300,6 +317,7 @@ |
141 | gtk_widget_set_uposition(bw->main_window, prefs.xpos, prefs.ypos); | |
1605e886 | 142 | |
143 | a_Bookmarks_init(); | |
144 | + a_Encodings_init(); | |
145 | ||
146 | /* Send dillo startup screen */ | |
0cb1d1e1 AA |
147 | start_url = a_Url_new("splash", "about:", 0, 0, 0); |
148 | diff -Nur old/src/dillo.h new/src/dillo.h | |
149 | --- old/src/dillo.h 2003-09-05 14:07:06.000000000 +0200 | |
150 | +++ new/src/dillo.h 2004-03-07 19:26:40.000000000 +0100 | |
151 | @@ -4,6 +4,7 @@ | |
1605e886 | 152 | #include "browser.h" |
153 | #include "web.h" | |
154 | ||
155 | +char* curr_locale; | |
0cb1d1e1 AA |
156 | extern gboolean dillo_dbg_rendering; |
157 | ||
1605e886 | 158 | #endif /* __DILLO_H__ */ |
0cb1d1e1 AA |
159 | diff -Nur old/src/dw_style.c new/src/dw_style.c |
160 | --- old/src/dw_style.c 2003-11-15 22:57:53.000000000 +0100 | |
161 | +++ new/src/dw_style.c 2004-03-07 19:34:53.000000000 +0100 | |
162 | @@ -11,6 +11,7 @@ | |
1605e886 | 163 | |
0cb1d1e1 AA |
164 | #include "dw_style.h" |
165 | #include "dw_widget.h" | |
166 | +#include "prefs.h" | |
167 | ||
168 | #include <gdk/gdk.h> | |
169 | #include <stdio.h> | |
43d8e822 | 170 | @@ -300,40 +301,37 @@ |
0cb1d1e1 AA |
171 | break; |
172 | } | |
43d8e822 | 173 | |
1605e886 | 174 | - sprintf (fontname, "-*-%s-%s-%s-*-*-%d-*-75-75-*-*-iso8859-1", |
175 | + sprintf (fontname, "-*-%s-%s-%s-*-*-%d-*-75-75-*-*-%s", | |
176 | font->name, | |
0cb1d1e1 AA |
177 | (font->weight >= 500) ? "bold" : "medium", |
178 | - style_char_1, font->size); | |
179 | + style_char_1, font->size, prefs.font_charset); | |
1605e886 | 180 | font->font = gdk_font_load (fontname); |
181 | ||
0cb1d1e1 | 182 | if (font->font == NULL && font->style != DW_STYLE_FONT_STYLE_NORMAL) { |
1605e886 | 183 | - sprintf (fontname, "-*-%s-%s-%s-*-*-%d-*-75-75-*-*-iso8859-1", |
184 | + sprintf (fontname, "-*-%s-%s-%s-*-*-%d-*-75-75-*-*-%s", | |
185 | font->name, | |
0cb1d1e1 AA |
186 | (font->weight >= 500) ? "bold" : "medium", |
187 | - style_char_2, font->size); | |
188 | + style_char_2, font->size, prefs.font_charset); | |
1605e886 | 189 | font->font = gdk_font_load (fontname); |
190 | } | |
191 | ||
192 | if (try_all) { | |
193 | if (font->font == NULL) { | |
194 | /* Can't load the font - substitute the default instead. */ | |
195 | - font->font = | |
196 | - gdk_font_load | |
197 | - ("-adobe-helvetica-medium-r-normal--*-100-*-*-*-*-iso8859-1"); | |
0cb1d1e1 | 198 | + sprintf(fontname,"-adobe-helvetica-medium-r-normal--*-100-*-*-*-*-%s", prefs.font_charset); |
1605e886 | 199 | + font->font = gdk_font_load (fontname); |
200 | } | |
201 | ||
202 | if (font->font == NULL) { | |
203 | /* Try another platform-font that should be available. (iPaq) */ | |
204 | - font->font = | |
205 | - gdk_font_load | |
206 | - ("-misc-fixed-medium-r-normal--13-120-75-75-c-80-iso8859-1"); | |
0cb1d1e1 | 207 | + sprintf(fontname,"-misc-fixed-medium-r-normal--13-120-75-75-c-80-%s", prefs.font_charset); |
1605e886 | 208 | + font->font = gdk_font_load (fontname); |
209 | } | |
210 | ||
211 | if (font->font == NULL) { | |
212 | /* Can't load any suitable font! */ | |
213 | - g_warning ("Can't load any ISO8859-1 font!?! :("); | |
214 | - font->font = | |
215 | - gdk_font_load ("-adobe-helvetica-*-*-*--*-*-*-*-*-*-*-*"); | |
216 | + g_warning ("Can't load any font with charset '%s'!?! :(",prefs.font_charset); | |
217 | + font->font = gdk_fontset_load("-adobe-helvetica-*-*-*--*-*-*-*-*-*-*-*,-misc-fixed-*,*"); | |
218 | } | |
219 | } | |
220 | ||
0cb1d1e1 AA |
221 | diff -Nur old/src/encodings.c new/src/encodings.c |
222 | --- old/src/encodings.c 1970-01-01 01:00:00.000000000 +0100 | |
223 | +++ new/src/encodings.c 2004-03-07 17:32:50.000000000 +0100 | |
1605e886 | 224 | @@ -0,0 +1,383 @@ |
225 | +/* cruelty :) */ | |
226 | + | |
227 | +/* Copyright (C) 2002 Grigory Bakunov <black@asplinux.ru> */ | |
228 | + | |
229 | +/* Copyright (C) 1997 Ian Main | |
230 | + * | |
231 | + * This program is free software; you can redistribute it and/or modify | |
232 | + * it under the terms of the GNU General Public License as published by | |
233 | + * the Free Software Foundation; either version 2 of the License, or | |
234 | + * (at your option) any later version. | |
235 | + * | |
236 | + * This program is distributed in the hope that it will be useful, | |
237 | + * but WITHOUT ANY WARRANTY; without even the implied warranty of | |
238 | + * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the | |
239 | + * GNU General Public License for more details. | |
240 | + * | |
241 | + * You should have received a copy of the GNU General Public License | |
242 | + * along with this program; if not, write to the Free Software | |
243 | + * Foundation, Inc., 675 Mass Ave, Cambridge, MA 02139, USA. | |
244 | + */ | |
245 | + | |
246 | +#include <gtk/gtk.h> | |
247 | + | |
248 | +#include <errno.h> | |
249 | +#include <stdio.h> | |
250 | +#include <unistd.h> | |
251 | +#include <stdlib.h> | |
252 | +#include <string.h> | |
253 | + | |
254 | +#include "list.h" | |
255 | +#include "interface.h" | |
256 | +#include "dillo.h" | |
257 | +#include "nav.h" | |
258 | +#include "browser.h" | |
259 | +#include "menu.h" | |
260 | +#include "misc.h" | |
261 | +#include "url.h" | |
262 | + | |
263 | +#define LOAD_ENCODINGS 1 | |
264 | +#define SAVE_ENCODING 2 | |
265 | +#define CLOSE_ENCODINGS 3 | |
266 | + | |
267 | +/* this #define will cut page title if > 39 chars */ | |
268 | +#define TITLE39 | |
269 | + | |
270 | +/* double quote */ | |
271 | +#define D_QUOTE 0x22 | |
272 | + | |
273 | +/* Data types */ | |
274 | + | |
275 | +typedef struct _Encoding Encoding; | |
276 | +typedef struct _CallbackInfo CallbackInfo; | |
277 | + | |
278 | +struct _Encoding { | |
279 | + char *title; | |
280 | + char *iconv_name; | |
281 | + GtkWidget *menuitem; | |
282 | +}; | |
283 | + | |
284 | +struct _CallbackInfo { | |
285 | + BrowserWindow *bw; | |
286 | + guint index; | |
287 | +}; | |
288 | + | |
289 | +/* | |
290 | + * Forward declarations | |
291 | + */ | |
292 | +static void | |
293 | + Encodings_load_to_menu(FILE *fp), | |
294 | + Encodings_file_op(gint operation, const char *title, const char *iconv_name), | |
295 | + Encodings_save_to_file(FILE *fp, const char *title, const char *iconv_name); | |
296 | + | |
297 | +static char* | |
298 | + Encodings_search_line(char *line, char *start_text, char *end_text); | |
299 | + | |
300 | +extern BrowserWindow **browser_window; | |
301 | + | |
302 | +/* | |
303 | + * Local data | |
304 | + */ | |
305 | +static Encoding *encodings = NULL; | |
306 | +static gint num_encodings = 0; | |
307 | +static gint num_encodings_max = 16; | |
308 | + | |
309 | + | |
310 | +/* | |
311 | + * Allocate memory and load the encodings list | |
312 | + */ | |
313 | +void a_Encodings_init(void) | |
314 | +{ | |
315 | + gchar *file; | |
316 | + | |
317 | + /* Here we load and set the encodings */ | |
318 | + file = a_Misc_prepend_user_home(".dillo/encodings"); | |
319 | + if (access(file, R_OK)) | |
320 | + Encodings_file_op(LOAD_ENCODINGS, "/etc/dillo/encodings", NULL); | |
321 | + else | |
322 | + Encodings_file_op(LOAD_ENCODINGS, file, NULL); | |
323 | + g_free(file); | |
324 | +} | |
325 | + | |
326 | +/* | |
327 | + * ? | |
328 | + */ | |
329 | +void Encodings_set_encoding(GtkWidget *widget, CallbackInfo *CbInfo) | |
330 | +{ | |
331 | + if (CbInfo->index >= num_encodings) { | |
332 | + g_warning("encoding not found!\n"); | |
333 | + return; | |
334 | + } | |
335 | + g_print("Selected encoding: %s\n",encodings[CbInfo->index].iconv_name); | |
336 | + CbInfo->bw->encoding=encodings[CbInfo->index].iconv_name; | |
337 | + a_Nav_reload(CbInfo->bw); | |
338 | + /*HERE!!! LOOKOUT!!!! */ | |
339 | +} | |
340 | + | |
341 | +/* | |
342 | + * Add a encoding to the encodings menu of a particular browser window | |
343 | + */ | |
344 | +void Encodings_add_to_menu(BrowserWindow *bw, GtkWidget *menuitem, guint index) | |
345 | +{ | |
346 | + CallbackInfo *CbInfo; | |
347 | + | |
348 | + gtk_menu_append(GTK_MENU(bw->enc_menu), menuitem); | |
349 | + | |
350 | + CbInfo = g_new(CallbackInfo, 1); | |
351 | + CbInfo->bw = bw; | |
352 | + CbInfo->index = index; | |
353 | + | |
354 | + /* accelerator goes here */ | |
355 | + gtk_signal_connect(GTK_OBJECT (menuitem), "activate", | |
356 | + (GtkSignalFunc)Encodings_set_encoding, CbInfo); | |
357 | +} | |
358 | + | |
359 | +/* | |
360 | + * ? | |
361 | + */ | |
362 | +static GtkWidget *Encodings_insert(const char *title, const char *iconv_name) | |
363 | +{ | |
364 | + GtkWidget *menuitem; | |
365 | + | |
366 | + menuitem = gtk_menu_item_new_with_label(title); | |
367 | + gtk_widget_show(menuitem); | |
368 | + | |
369 | + a_List_add(encodings, num_encodings, num_encodings_max); | |
370 | + encodings[num_encodings].title = g_strdup(title); | |
371 | + encodings[num_encodings].iconv_name = g_strdup(iconv_name); | |
372 | + encodings[num_encodings].menuitem = menuitem; | |
373 | + num_encodings++; | |
374 | + return menuitem; | |
375 | +} | |
376 | + | |
377 | +/* | |
378 | + * Add the new encoding to encodings menu of _all_ browser windows and then | |
379 | + * write the new encoding to file | |
380 | + */ | |
381 | +/* | |
382 | +void a_Encodings_add(GtkWidget *widget, gpointer client_data) | |
383 | +{ | |
384 | + BrowserWindow *bw = (BrowserWindow *)client_data; | |
385 | + gint i; | |
386 | +#ifdef TITLE39 | |
387 | + gboolean allocated = FALSE; | |
388 | +#endif | |
389 | + char *title; | |
390 | + char *iconv_name; | |
391 | + GtkWidget *menuitem; | |
392 | + | |
393 | + title = bw->menu_popup.info.title; | |
394 | + iconv_name = bw->menu_popup.info.iconv_name; | |
395 | + | |
396 | +#ifdef TITLE39 | |
397 | + if (strlen (title) > 39) { | |
398 | + char buf1[20]; | |
399 | + char buf2[20]; | |
400 | + | |
401 | + memcpy (buf1, title, 18); | |
402 | + buf1[18] = '\0'; | |
403 | + strcpy (buf2, title + strlen (title) - 18); | |
404 | + buf2[18] = '\0'; | |
405 | + title = g_strconcat (buf1, "...", buf2, NULL); | |
406 | + allocated = TRUE; | |
407 | + } | |
408 | +#endif | |
409 | + | |
410 | + menuitem = Encodings_insert(title, iconv_name); | |
411 | + Encodings_add_to_menu(browser_window[0], menuitem, num_encodings-1); | |
412 | + for (i = 1; i < num_bw; i++) { | |
413 | + menuitem= gtk_menu_item_new_with_label(encodings[num_encodings-1].title); | |
414 | + gtk_widget_show(menuitem); | |
415 | + Encodings_add_to_menu(browser_window[i], menuitem, num_encodings-1); | |
416 | + } | |
417 | + | |
418 | + Encodings_file_op(SAVE_ENCODING, title, iconv_name); | |
419 | + | |
420 | +#ifdef TITLE39 | |
421 | + if (allocated) | |
422 | + g_free (title); | |
423 | +#endif | |
424 | +} | |
425 | +*/ | |
426 | +/* | |
427 | + * Never called (the file remains open all the time) --Jcid | |
428 | + */ | |
429 | +void Encodings_close(void) | |
430 | +{ | |
431 | + Encodings_file_op(CLOSE_ENCODINGS, NULL, NULL); | |
432 | +} | |
433 | + | |
434 | +/* | |
435 | + * Performs operations on the encoding file.. | |
436 | + * for first call, title is the filename | |
437 | + */ | |
438 | +static void | |
439 | + Encodings_file_op(gint operation, const char *title, const char *iconv_name) | |
440 | +{ | |
441 | + static FILE *fp; | |
442 | + static gint initialized = 0; | |
443 | + | |
444 | + if (!initialized) { | |
445 | + if (operation == LOAD_ENCODINGS) { | |
446 | + /* SAVE_ENCODINGS is broken anyway, better make use of /etc/dillo/encodings */ | |
447 | + if ((fp = fopen(title, "r")) == NULL) | |
448 | + g_print("dillo: opening encoding file %s: %s\n", | |
449 | + title, strerror(errno)); | |
450 | + else | |
451 | + initialized = 1; | |
452 | + } else | |
453 | + g_print("Error: invalid call to Encodings_file_op.\n"); | |
454 | + } | |
455 | + | |
456 | + g_return_if_fail( initialized ); | |
457 | + | |
458 | + switch (operation) { | |
459 | + case LOAD_ENCODINGS: | |
460 | + Encodings_load_to_menu(fp); | |
461 | + break; | |
462 | + | |
463 | + case SAVE_ENCODING: | |
464 | + Encodings_save_to_file(fp, title, iconv_name); | |
465 | + break; | |
466 | + | |
467 | + case CLOSE_ENCODINGS: | |
468 | + fclose(fp); | |
469 | + break; | |
470 | + | |
471 | + default: | |
472 | + break; | |
473 | + } | |
474 | +} | |
475 | + | |
476 | +/* | |
477 | + * Save encodings to ~/.dillo/encodings | |
478 | + */ | |
479 | +static void | |
480 | + Encodings_save_to_file(FILE *fp, const char *title, const char* iconv_name) | |
481 | +{ | |
482 | + fseek(fp, 0L, SEEK_END); | |
483 | + fprintf(fp, "<enc value=\"%s\">%s</a>\n", iconv_name,title); | |
484 | + fflush(fp); | |
485 | +} | |
486 | + | |
487 | +/* | |
488 | + * Load encodings | |
489 | + */ | |
490 | +static void Encodings_load_to_menu(FILE *fp) | |
491 | +{ | |
492 | + gchar *title=NULL; | |
493 | + gchar *iconv_name=NULL; | |
494 | + char buf[4096]; | |
495 | + gint i = 0; | |
496 | + GtkWidget *menuitem; | |
497 | + | |
498 | + rewind(fp); | |
499 | + | |
500 | + g_print("Loading encodings...\n"); | |
501 | + while (1) { | |
502 | + /* Read a whole line from the file */ | |
503 | + if ((fgets(buf, 4096, fp)) == NULL) | |
504 | + break; | |
505 | + | |
506 | + /* get url from line */ | |
507 | + if ( !(iconv_name = Encodings_search_line(buf, "=\"", "\">")) ) | |
508 | + continue; | |
509 | + | |
510 | + /* get title from line */ | |
511 | + if ( !(title = Encodings_search_line(buf, "\">", "</")) ){ | |
512 | + g_free(iconv_name); | |
513 | + continue; | |
514 | + } | |
515 | + printf("%s = %s\n",title,iconv_name); | |
516 | + menuitem = Encodings_insert(title, iconv_name); | |
517 | + Encodings_add_to_menu(browser_window[0], menuitem, i); | |
518 | + g_free(iconv_name); | |
519 | + g_free(title); | |
520 | + i++; | |
521 | + } | |
522 | +} | |
523 | + | |
524 | +/* | |
525 | + * Copy encodings when new browser windows are opened. | |
526 | + * Called by 'a_Menu_mainbar_new()' | |
527 | + */ | |
528 | +void a_Encodings_fill_new_menu(BrowserWindow *bw) | |
529 | +{ | |
530 | + gint i; | |
531 | + GtkWidget *menuitem; | |
532 | + | |
533 | + for (i = 0; i < num_encodings; i++) { | |
534 | + menuitem = gtk_menu_item_new_with_label(encodings[i].title); | |
535 | + gtk_widget_show(menuitem); | |
536 | + Encodings_add_to_menu(bw, menuitem, i); | |
537 | + } | |
538 | +} | |
539 | + | |
540 | +static char * | |
541 | + Encodings_search_line(char *line, char *start_text, char *end_text) { | |
542 | + gint segment_length; | |
543 | + char *start_index, *end_index; | |
544 | + | |
545 | + /* if string is not found, return NULL */ | |
546 | + if ((start_index = strstr(line, start_text)) == NULL) | |
547 | + return (NULL); | |
548 | + if ((end_index = strstr(line, end_text)) == NULL) | |
549 | + return (NULL); | |
550 | + | |
551 | + /* adjustment cause strstr returns the start of the text */ | |
552 | + start_index += strlen(start_text); | |
553 | + | |
554 | + /* find length of text segment */ | |
555 | + segment_length = end_index - start_index; | |
556 | + return g_strndup(start_index, segment_length); | |
557 | +}; | |
558 | + | |
559 | +void a_Encoding_get_conversion(BrowserWindow *bw, char* charset) { | |
560 | + bw->dcv.c_from=iconv_open(curr_locale,charset); | |
561 | + bw->dcv.c_to=iconv_open(charset,curr_locale); | |
562 | + if (bw->dcv.c_from == (iconv_t)-1 || bw->dcv.c_to == (iconv_t)-1) | |
563 | + g_warning ("could not allocate character encoding converter."); | |
564 | + return; | |
565 | +}; | |
566 | + | |
567 | +#define MAX_CHAR_SIZE 4 | |
568 | +gchar *a_Encoding_translate_encoding(deConversion dcv, gchar *buf, gint bufsize,deDirection dir) { | |
569 | + char *result, *source, *dest; | |
570 | + size_t s_left, d_left; | |
571 | + iconv_t conversion; | |
572 | + if (dir==DE_DECODE) | |
573 | + conversion=dcv.c_from; | |
574 | + else | |
575 | + conversion=dcv.c_to; | |
576 | + /* no conversion is needed, or none is available */ | |
577 | + if (conversion == (iconv_t)-1) | |
578 | + return g_strndup(buf, bufsize); | |
579 | + | |
580 | + /* Note that for some conversions, the translated buffer can be larger | |
581 | + * than the input buffer. This is particularly important for conversions | |
582 | + * to UTF8 (check the unicode standard to find out the scale factor). */ | |
583 | + result = g_malloc((bufsize + 1)*MAX_CHAR_SIZE); | |
584 | + | |
585 | + source = buf; | |
586 | + dest = result; | |
587 | + s_left = bufsize; | |
588 | + d_left = bufsize*MAX_CHAR_SIZE; | |
589 | + if (iconv(conversion, &source, &s_left, &dest, &d_left) | |
590 | + == (size_t)-1) { | |
591 | + g_warning ("unable to fully convert page to native character set"); | |
592 | + /* This just skips past unconvertable characters, putting "?" in the | |
593 | + * output, then retries the conversion. This is a hack, but it seems | |
594 | + * like the best course of action in the circumstances. */ | |
595 | + while (s_left > 0 && d_left > 0 && errno == EILSEQ) { | |
596 | + source++; | |
597 | + s_left--; | |
598 | + *dest = '?'; | |
599 | + dest++; | |
600 | + d_left--; | |
601 | + if (s_left > 0 && d_left > 0) | |
602 | + iconv(conversion, &source, &s_left, &dest, &d_left); | |
603 | + } | |
604 | + } | |
605 | + *dest = 0; /* terminate the string */ | |
606 | + return result; | |
607 | +} | |
0cb1d1e1 AA |
608 | diff -Nur old/src/encodings.h new/src/encodings.h |
609 | --- old/src/encodings.h 1970-01-01 01:00:00.000000000 +0100 | |
610 | +++ new/src/encodings.h 2004-03-07 17:32:50.000000000 +0100 | |
1605e886 | 611 | @@ -0,0 +1,18 @@ |
612 | +#ifndef __DILLO_ENCODING_H__ | |
613 | +#define __DILLO_ENCODING_H__ | |
614 | +#include <gtk/gtk.h> | |
615 | +#include <iconv.h> | |
616 | +#include "browser.h" | |
617 | +#include "encodings-types.h" | |
618 | + | |
619 | + | |
620 | +/* Copyright (C) 2002 Grigory Bakunov <black@asplinux.ru> */ | |
621 | + | |
622 | +void a_Encodings_init(); | |
623 | +void a_Encodings_add(GtkWidget *widget, gpointer client_data); | |
624 | +void a_Encodings_fill_new_menu(BrowserWindow *bw); | |
625 | +void a_Encoding_get_conversion(BrowserWindow *bw, char* charset); | |
626 | +char *a_Encoding_translate_encoding(deConversion dcv, char *buf, | |
627 | + gint bufsize,deDirection dir); | |
628 | + | |
629 | +#endif /* __DILLO_ENCODING_H__ */ | |
0cb1d1e1 AA |
630 | diff -Nur old/src/encodings-types.h new/src/encodings-types.h |
631 | --- old/src/encodings-types.h 1970-01-01 01:00:00.000000000 +0100 | |
632 | +++ new/src/encodings-types.h 2004-03-07 17:32:50.000000000 +0100 | |
1605e886 | 633 | @@ -0,0 +1,19 @@ |
634 | +#ifndef __DILLO_ENCODING_TYPES_H__ | |
635 | +#define __DILLO_ENCODING_TYPES_H__ | |
636 | +#include <iconv.h> | |
637 | +/* Copyright (C) 2002 Grigory Bakunov <black@asplinux.ru> */ | |
638 | + | |
639 | +typedef struct _deConversion deConversion; | |
640 | + | |
641 | +struct _deConversion { | |
642 | + iconv_t c_from; | |
643 | + iconv_t c_to; | |
644 | +}; | |
645 | + | |
646 | + | |
647 | +typedef enum { | |
648 | + DE_DECODE, | |
649 | + DE_ENCODE | |
650 | +} deDirection; | |
651 | + | |
652 | +#endif /* __DILLO_ENCODING_TYPES_H__ */ | |
0cb1d1e1 AA |
653 | diff -Nur old/src/html.c new/src/html.c |
654 | --- old/src/html.c 2004-02-07 00:10:45.000000000 +0100 | |
655 | +++ new/src/html.c 2004-03-07 18:21:23.000000000 +0100 | |
1605e886 | 656 | @@ -21,6 +21,7 @@ |
657 | #include <stdlib.h> | |
658 | #include <stdio.h> /* for sprintf */ | |
659 | #include <math.h> /* for rint */ | |
0cb1d1e1 | 660 | +#include <errno.h> /* for iconv error codes */ |
1605e886 | 661 | |
662 | #include <gtk/gtk.h> | |
663 | ||
0cb1d1e1 | 664 | @@ -51,6 +52,7 @@ |
1605e886 | 665 | #include "progressbar.h" |
666 | #include "prefs.h" | |
667 | #include "misc.h" | |
668 | +#include "encodings.h" | |
669 | #include "capi.h" | |
670 | #include "html.h" | |
671 | ||
0cb1d1e1 | 672 | @@ -3140,7 +3142,7 @@ |
1605e886 | 673 | if ((form->method == DILLO_HTML_METHOD_GET) || |
674 | (form->method == DILLO_HTML_METHOD_POST)) { | |
675 | GString *DataStr = g_string_sized_new(4096); | |
676 | - | |
677 | + GString *DataStrEnc; | |
678 | DEBUG_MSG(3,"Html_submit_form form->action=%s\n",URL_STR_(form->action)); | |
679 | ||
680 | for (input_index = 0; input_index < form->num_inputs; input_index++) { | |
0cb1d1e1 | 681 | @@ -3204,6 +3206,12 @@ |
1605e886 | 682 | break; |
683 | } /* switch */ | |
684 | } /* for (inputs) */ | |
685 | + DataStrEnc = g_string_new(a_Encoding_translate_encoding(html_lb->bw->dcv, | |
0cb1d1e1 AA |
686 | + DataStr -> str, |
687 | + DataStr -> len, | |
688 | + DE_ENCODE)); | |
1605e886 | 689 | + g_string_free(DataStr,TRUE); |
690 | + DataStr = DataStrEnc; | |
691 | ||
692 | if ( DataStr->str[DataStr->len - 1] == '&' ) | |
693 | g_string_truncate(DataStr, DataStr->len - 1); | |
0cb1d1e1 | 694 | @@ -4374,6 +4382,22 @@ |
1605e886 | 695 | Html_write(Client->CbData, Client->Buf, Client->BufSize, 0); |
696 | } | |
697 | ||
698 | +static void Html_set_encoding(DilloHtml *html, char *buf, gint bufsize) { | |
699 | + /* only do _anything_ if told so */ | |
700 | + if (html->bw->encoding != NULL) | |
701 | + a_Encoding_get_conversion(html->bw, html->bw->encoding); | |
702 | + return; | |
703 | +} | |
704 | + | |
705 | +static char *Html_translate_encoding(DilloHtml *html, char *buf, | |
0cb1d1e1 | 706 | + gint bufsize) { |
1605e886 | 707 | + char* result=a_Encoding_translate_encoding(html->bw->dcv, |
0cb1d1e1 AA |
708 | + buf, bufsize, |
709 | + DE_DECODE); | |
1605e886 | 710 | + return result; |
711 | + | |
712 | +} | |
713 | + | |
714 | /* | |
715 | * Here's where we parse the html and put it into the page structure. | |
716 | * Return value: number of bytes parsed | |
0cb1d1e1 | 717 | @@ -4511,8 +4535,12 @@ |
1605e886 | 718 | |
719 | g_return_if_fail ( (page = DW_PAGE (html->dw)) != NULL ); | |
720 | ||
721 | + Html_set_encoding(html, buf, bufsize); | |
722 | + buf = Html_translate_encoding(html, buf, bufsize); | |
723 | + | |
0cb1d1e1 | 724 | html->Start_Buf = Buf; |
1605e886 | 725 | token_start = Html_write_raw(html, buf, bufsize, Eof); |
726 | + g_free(buf); | |
727 | html->Start_Ofs += token_start; | |
728 | ||
729 | if ( html->bw ) { | |
0cb1d1e1 AA |
730 | diff -Nur old/src/interface.c new/src/interface.c |
731 | --- old/src/interface.c 2004-02-03 20:10:42.000000000 +0100 | |
732 | +++ new/src/interface.c 2004-03-07 18:22:51.000000000 +0100 | |
733 | @@ -55,7 +55,7 @@ | |
1605e886 | 734 | */ |
735 | /* BrowserWindow holds all the widgets (and perhaps more) | |
736 | * for each new_browser.*/ | |
737 | -static BrowserWindow **browser_window; | |
738 | +BrowserWindow **browser_window; | |
739 | static gint num_bw, num_bw_max; | |
740 | ||
0cb1d1e1 AA |
741 | /* We need only one of them. */ |
742 | @@ -969,6 +969,9 @@ | |
1605e886 | 743 | bw->question_dialog_window = NULL; |
744 | bw->question_dialog_data = NULL; | |
745 | bw->viewsource_window = NULL; | |
746 | + bw->encoding=NULL; | |
747 | + bw->dcv.c_from = (iconv_t)-1; /* no conversion yet */ | |
748 | + bw->dcv.c_to = (iconv_t)-1; | |
0cb1d1e1 | 749 | bw->pagebugs_window = NULL; |
1605e886 | 750 | |
751 | /* now that the bw is made, let's customize it.. */ | |
0cb1d1e1 AA |
752 | diff -Nur old/src/Makefile.am new/src/Makefile.am |
753 | --- old/src/Makefile.am 2004-01-29 21:34:05.000000000 +0100 | |
754 | +++ new/src/Makefile.am 2004-03-07 18:32:22.000000000 +0100 | |
755 | @@ -63,6 +63,9 @@ | |
756 | dw_tooltip.h \ | |
757 | dw_widget.c \ | |
758 | dw_widget.h \ | |
759 | + encodings.c \ | |
760 | + encodings.h \ | |
761 | + encoding-types.h \ | |
762 | findtext.c \ | |
763 | findtext.h \ | |
764 | selection.c \ | |
765 | diff -Nur old/src/menu.c new/src/menu.c | |
766 | --- old/src/menu.c 2004-02-03 20:03:11.000000000 +0100 | |
767 | +++ new/src/menu.c 2004-03-07 18:26:30.000000000 +0100 | |
1605e886 | 768 | @@ -33,6 +33,7 @@ |
769 | #include "bookmark.h" | |
770 | #include "interface.h" | |
771 | #include "menu.h" | |
772 | +#include "encodings.h" | |
0cb1d1e1 | 773 | #include "selection.h" |
1605e886 | 774 | |
775 | /* | |
0cb1d1e1 AA |
776 | @@ -141,6 +142,7 @@ |
777 | GtkWidget *menubar; | |
1605e886 | 778 | GtkWidget *file_menu; |
1605e886 | 779 | /* GtkWidget *help_menu; */ |
780 | + GtkWidget *enc_menu; | |
781 | ||
782 | bw->menubar = menubar = gtk_menu_bar_new(); | |
783 | ||
0cb1d1e1 AA |
784 | @@ -167,6 +169,10 @@ |
785 | Menu_add(help_menu, "Dillo _Home", NULL, bw, | |
786 | a_Commands_helphome_callback, bw); | |
1605e886 | 787 | */ |
788 | + enc_menu = Menu_new(menubar, tiny ? "_E" : "_Encodings", FALSE, bw); | |
789 | + bw->enc_menu = enc_menu; | |
790 | + a_Encodings_fill_new_menu(bw); | |
791 | + | |
792 | return menubar; | |
793 | } | |
794 | ||
0cb1d1e1 AA |
795 | diff -Nur old/src/prefs.c new/src/prefs.c |
796 | --- old/src/prefs.c 2004-01-25 16:17:53.000000000 +0100 | |
797 | +++ new/src/prefs.c 2004-03-07 18:30:13.000000000 +0100 | |
798 | @@ -52,6 +52,7 @@ | |
1605e886 | 799 | { "small_icons", DRC_TOKEN_SMALL_ICONS }, |
800 | { "limit_text_width", DRC_TOKEN_LIMIT_TEXT_WIDTH }, | |
801 | { "font_factor", DRC_TOKEN_FONT_FACTOR }, | |
802 | + { "font_charset", DRC_TOKEN_FONT_CHARSET }, | |
803 | { "use_dicache", DRC_TOKEN_USE_DICACHE }, | |
804 | { "show_back", DRC_TOKEN_SHOW_BACK }, | |
805 | { "show_forw", DRC_TOKEN_SHOW_FORW }, | |
0cb1d1e1 | 806 | @@ -172,6 +173,10 @@ |
1605e886 | 807 | case DRC_TOKEN_FONT_FACTOR: |
808 | prefs.font_factor = strtod(scanner->value.v_string, NULL); | |
809 | break; | |
810 | + case DRC_TOKEN_FONT_CHARSET: | |
811 | + if (prefs.font_charset) g_free(prefs.font_charset); | |
812 | + prefs.font_charset = g_strdup(scanner->value.v_string); | |
813 | + break; | |
814 | case DRC_TOKEN_LIMIT_TEXT_WIDTH: | |
815 | prefs.limit_text_width = (strcmp(scanner->value.v_string, "YES") == 0); | |
816 | break; | |
0cb1d1e1 | 817 | @@ -363,6 +368,7 @@ |
1605e886 | 818 | prefs.small_icons = FALSE; |
819 | prefs.limit_text_width = FALSE; | |
820 | prefs.font_factor = 1.0; | |
821 | + prefs.font_charset = g_strdup("iso8859-1"); | |
822 | prefs.use_dicache = FALSE; | |
823 | prefs.show_back=TRUE; | |
824 | prefs.show_forw=TRUE; | |
0cb1d1e1 | 825 | @@ -405,6 +411,8 @@ |
1605e886 | 826 | g_free(prefs.no_proxy); |
827 | if (prefs.no_proxy_vec) | |
828 | g_strfreev(prefs.no_proxy_vec); | |
829 | + if (prefs.font_charset) | |
830 | + g_free (prefs.font_charset); | |
831 | a_Url_free(prefs.http_proxy); | |
832 | g_free(prefs.fw_fontname); | |
833 | g_free(prefs.vw_fontname); | |
0cb1d1e1 AA |
834 | diff -Nur old/src/prefs.h new/src/prefs.h |
835 | --- old/src/prefs.h 2004-01-25 16:17:37.000000000 +0100 | |
836 | +++ new/src/prefs.h 2004-03-07 18:31:25.000000000 +0100 | |
837 | @@ -43,6 +43,7 @@ | |
1605e886 | 838 | DRC_TOKEN_PANEL_SIZE, |
839 | DRC_TOKEN_SMALL_ICONS, | |
840 | DRC_TOKEN_FONT_FACTOR, | |
841 | + DRC_TOKEN_FONT_CHARSET, | |
842 | DRC_TOKEN_SHOW_TOOLTIP, | |
843 | DRC_TOKEN_LIMIT_TEXT_WIDTH, | |
844 | DRC_TOKEN_USE_DICACHE, | |
0cb1d1e1 | 845 | @@ -95,6 +96,7 @@ |
1605e886 | 846 | gboolean small_icons; |
847 | gboolean limit_text_width; | |
848 | gdouble font_factor; | |
849 | + char *font_charset; | |
850 | gboolean use_dicache; | |
851 | gboolean show_back; | |
852 | gboolean show_forw; |