]> git.pld-linux.org Git - packages/dillo.git/blob - dillo-0.7.0-alt-asp-charset-encodings-sysconfdir.patch
- updated for 0.8.6
[packages/dillo.git] / dillo-0.7.0-alt-asp-charset-encodings-sysconfdir.patch
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
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
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
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>
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 @@
40  #include <sys/types.h>
41  #include <gdk/gdk.h>
42  #include <gtk/gtk.h>
43 -
44  #include "url.h"     /* for DilloUrl */
45 -
46 +#include "encodings-types.h"
47  
48  typedef struct _BrowserWindow BrowserWindow;
49  typedef struct _DilloMenuPopup DilloMenuPopup;
50 @@ -65,6 +64,9 @@
51     /* Popup menu for this BrowserWindow */
52     DilloMenuPopup menu_popup;
53  
54 +   /* The encoding menu */
55 +   GtkWidget *enc_menu;
56 +
57     /* The "Headings" and "Anchors" menus */
58     GtkWidget *pagemarks_menuitem;
59     GtkWidget *pagemarks_menu;
60 @@ -132,6 +134,10 @@
61  
62     /* The id for the idle function that sets button sensitivity. */
63     guint sens_idle_id;
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  
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
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>
88 @@ -41,6 +48,7 @@
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"
96 @@ -198,7 +206,7 @@
97   */
98  gint main(int argc, char *argv[])
99  {
100 -   gchar *dir, *curr_locale;
101 +   gchar *dir, *loctmp;
102     DilloUrl *start_url;
103     BrowserWindow *bw;
104     guint32 xid = 0;
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;
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();
115 @@ -254,9 +259,21 @@
116       }
117     }
118  
119 -   /* Send a delayed locale-related message */
120 -   MSG("Setting locale to %s...\n", curr_locale);
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) */
140 @@ -300,6 +317,7 @@
141        gtk_widget_set_uposition(bw->main_window, prefs.xpos, prefs.ypos);
142  
143     a_Bookmarks_init();
144 +   a_Encodings_init();
145  
146     /* Send dillo startup screen */
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 @@
152  #include "browser.h"
153  #include "web.h"
154  
155 +char* curr_locale;
156  extern gboolean dillo_dbg_rendering;
157  
158  #endif /* __DILLO_H__ */
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 @@
163  
164  #include "dw_style.h"
165  #include "dw_widget.h"
166 +#include "prefs.h"
167  
168  #include <gdk/gdk.h>
169  #include <stdio.h>
170 @@ -300,40 +301,37 @@
171        break;
172     }
173  
174 -   sprintf (fontname, "-*-%s-%s-%s-*-*-%d-*-75-75-*-*-iso8859-1",
175 +   sprintf (fontname, "-*-%s-%s-%s-*-*-%d-*-75-75-*-*-%s",
176              font->name,
177              (font->weight >= 500) ? "bold" : "medium",
178 -            style_char_1, font->size);
179 +            style_char_1, font->size, prefs.font_charset);
180     font->font = gdk_font_load (fontname);
181  
182     if (font->font == NULL && font->style != DW_STYLE_FONT_STYLE_NORMAL) {
183 -      sprintf (fontname, "-*-%s-%s-%s-*-*-%d-*-75-75-*-*-iso8859-1",
184 +      sprintf (fontname, "-*-%s-%s-%s-*-*-%d-*-75-75-*-*-%s",
185                 font->name,
186                 (font->weight >= 500) ? "bold" : "medium",
187 -               style_char_2, font->size);
188 +               style_char_2, font->size, prefs.font_charset);
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");
198 +         sprintf(fontname,"-adobe-helvetica-medium-r-normal--*-100-*-*-*-*-%s", prefs.font_charset);
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");
207 +         sprintf(fontname,"-misc-fixed-medium-r-normal--13-120-75-75-c-80-%s", prefs.font_charset);
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  
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
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 +}
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
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__ */
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
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__ */
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
656 @@ -51,6 +52,7 @@
657  #include "progressbar.h"
658  #include "prefs.h"
659  #include "misc.h"
660 +#include "encodings.h"
661  #include "capi.h"
662  #include "html.h"
663  
664 @@ -3140,7 +3142,7 @@
665     if ((form->method == DILLO_HTML_METHOD_GET) ||
666         (form->method == DILLO_HTML_METHOD_POST)) {
667        GString *DataStr = g_string_sized_new(4096);
668 -
669 +      GString *DataStrEnc;
670        DEBUG_MSG(3,"Html_submit_form form->action=%s\n",URL_STR_(form->action));
671  
672        for (input_index = 0; input_index < form->num_inputs; input_index++) {
673 @@ -3204,6 +3206,12 @@
674              break;
675           } /* switch */
676        } /* for (inputs) */
677 +      DataStrEnc = g_string_new(a_Encoding_translate_encoding(html_lb->bw->dcv,
678 +                                                                DataStr -> str,
679 +                                                                DataStr -> len,
680 +                                                                DE_ENCODE));
681 +      g_string_free(DataStr,TRUE);
682 +      DataStr = DataStrEnc;
683  
684        if ( DataStr->str[DataStr->len - 1] == '&' )
685           g_string_truncate(DataStr, DataStr->len - 1);
686 @@ -4374,6 +4382,22 @@
687        Html_write(Client->CbData, Client->Buf, Client->BufSize, 0);
688  }
689  
690 +static void Html_set_encoding(DilloHtml *html, char *buf, gint bufsize) {
691 +   /* only do _anything_ if told so */
692 +   if (html->bw->encoding != NULL)
693 +       a_Encoding_get_conversion(html->bw, html->bw->encoding);
694 +   return;
695 +}
696 +
697 +static char *Html_translate_encoding(DilloHtml *html, char *buf,
698 +                                   gint bufsize) {
699 +    char* result=a_Encoding_translate_encoding(html->bw->dcv,
700 +                                              buf, bufsize,
701 +                                              DE_DECODE);
702 +    return result;
703 +
704 +}
705 +
706  /*
707   * Here's where we parse the html and put it into the page structure.
708   * Return value: number of bytes parsed
709 @@ -4511,8 +4535,12 @@
710  
711     g_return_if_fail ( (page = DW_PAGE (html->dw)) != NULL );
712  
713 +   Html_set_encoding(html, buf, bufsize);
714 +   buf = Html_translate_encoding(html, buf, bufsize);
715 +
716     html->Start_Buf = Buf;
717     token_start = Html_write_raw(html, buf, bufsize, Eof);
718 +   g_free(buf);
719     html->Start_Ofs += token_start;
720  
721     if ( html->bw ) {
722 diff -Nur old/src/interface.c new/src/interface.c
723 --- old/src/interface.c 2004-02-03 20:10:42.000000000 +0100
724 +++ new/src/interface.c 2004-03-07 18:22:51.000000000 +0100
725 @@ -55,7 +55,7 @@
726   */
727  /* BrowserWindow holds all the widgets (and perhaps more)
728   * for each new_browser.*/
729 -static BrowserWindow **browser_window;
730 +BrowserWindow **browser_window;
731  static gint num_bw, num_bw_max;
732  
733  /* We need only one of them. */
734 @@ -969,6 +969,9 @@
735     bw->question_dialog_window = NULL;
736     bw->question_dialog_data = NULL;
737     bw->viewsource_window = NULL;
738 +   bw->encoding=NULL;
739 +   bw->dcv.c_from  = (iconv_t)-1; /* no conversion yet */
740 +   bw->dcv.c_to  = (iconv_t)-1;
741     bw->pagebugs_window = NULL;
742  
743     /* now that the bw is made, let's customize it.. */
744 diff -Nur old/src/Makefile.am new/src/Makefile.am
745 --- old/src/Makefile.am 2004-01-29 21:34:05.000000000 +0100
746 +++ new/src/Makefile.am 2004-03-07 18:32:22.000000000 +0100
747 @@ -63,6 +63,9 @@
748         dw_tooltip.h \
749         dw_widget.c \
750         dw_widget.h \
751 +        encodings.c \
752 +        encodings.h \
753 +        encoding-types.h \
754         findtext.c \
755         findtext.h \
756         selection.c \
757 diff -Nur old/src/menu.c new/src/menu.c
758 --- old/src/menu.c      2004-02-03 20:03:11.000000000 +0100
759 +++ new/src/menu.c      2004-03-07 18:26:30.000000000 +0100
760 @@ -33,6 +33,7 @@
761  #include "bookmark.h"
762  #include "interface.h"
763  #include "menu.h"
764 +#include "encodings.h"
765  #include "selection.h"
766  
767  /*
768 @@ -141,6 +142,7 @@
769     GtkWidget *menubar;
770     GtkWidget *file_menu;
771     /* GtkWidget *help_menu; */
772 +   GtkWidget *enc_menu;
773  
774     bw->menubar = menubar = gtk_menu_bar_new();
775  
776 @@ -167,6 +169,10 @@
777     Menu_add(help_menu, "Dillo _Home", NULL, bw,
778              a_Commands_helphome_callback, bw);
779     */
780 +   enc_menu = Menu_new(menubar, tiny ? "_E" : "_Encodings", FALSE, bw);
781 +   bw->enc_menu = enc_menu;
782 +   a_Encodings_fill_new_menu(bw);
783 +
784     return menubar;
785  }
786  
787 diff -Nur old/src/prefs.c new/src/prefs.c
788 --- old/src/prefs.c     2004-01-25 16:17:53.000000000 +0100
789 +++ new/src/prefs.c     2004-03-07 18:30:13.000000000 +0100
790 @@ -52,6 +52,7 @@
791     { "small_icons", DRC_TOKEN_SMALL_ICONS },
792     { "limit_text_width", DRC_TOKEN_LIMIT_TEXT_WIDTH },
793     { "font_factor", DRC_TOKEN_FONT_FACTOR },
794 +   { "font_charset", DRC_TOKEN_FONT_CHARSET },
795     { "use_dicache", DRC_TOKEN_USE_DICACHE },
796     { "show_back", DRC_TOKEN_SHOW_BACK },
797     { "show_forw", DRC_TOKEN_SHOW_FORW },
798 @@ -172,6 +173,10 @@
799     case DRC_TOKEN_FONT_FACTOR:
800        prefs.font_factor = strtod(scanner->value.v_string, NULL);
801        break;
802 +   case DRC_TOKEN_FONT_CHARSET:
803 +       if (prefs.font_charset) g_free(prefs.font_charset);
804 +       prefs.font_charset = g_strdup(scanner->value.v_string);
805 +      break;
806     case DRC_TOKEN_LIMIT_TEXT_WIDTH:
807        prefs.limit_text_width = (strcmp(scanner->value.v_string, "YES") == 0);
808        break;
809 @@ -363,6 +368,7 @@
810     prefs.small_icons = FALSE;
811     prefs.limit_text_width = FALSE;
812     prefs.font_factor = 1.0;
813 +   prefs.font_charset = g_strdup("iso8859-1");
814     prefs.use_dicache = FALSE;
815     prefs.show_back=TRUE;
816     prefs.show_forw=TRUE;
817 @@ -405,6 +411,8 @@
818     g_free(prefs.no_proxy);
819     if (prefs.no_proxy_vec)
820        g_strfreev(prefs.no_proxy_vec);
821 +   if (prefs.font_charset)
822 +      g_free (prefs.font_charset);
823     a_Url_free(prefs.http_proxy);
824     g_free(prefs.fw_fontname);
825     g_free(prefs.vw_fontname);
826 diff -Nur old/src/prefs.h new/src/prefs.h
827 --- old/src/prefs.h     2004-01-25 16:17:37.000000000 +0100
828 +++ new/src/prefs.h     2004-03-07 18:31:25.000000000 +0100
829 @@ -43,6 +43,7 @@
830     DRC_TOKEN_PANEL_SIZE,
831     DRC_TOKEN_SMALL_ICONS,
832     DRC_TOKEN_FONT_FACTOR,
833 +   DRC_TOKEN_FONT_CHARSET,
834     DRC_TOKEN_SHOW_TOOLTIP,
835     DRC_TOKEN_LIMIT_TEXT_WIDTH,
836     DRC_TOKEN_USE_DICACHE,
837 @@ -95,6 +96,7 @@
838     gboolean small_icons;
839     gboolean limit_text_width;
840     gdouble font_factor;
841 +   char *font_charset;
842     gboolean use_dicache;
843     gboolean show_back;
844     gboolean show_forw;
This page took 0.178045 seconds and 3 git commands to generate.