added support for different encodings
authorMelvin Hadasht <melvin.hadasht@free.fr>
Tue, 25 Sep 2001 10:59:20 +0000 (10:59 +0000)
committerMelvin Hadasht <melvin.hadasht@free.fr>
Tue, 25 Sep 2001 10:59:20 +0000 (10:59 +0000)
src/compose.c
src/gtkspell.c
src/gtkspell.h

index 35746fbc1e30730788cf2f584edc29e9bddcbf90..f43844629f585c5c572732403a2ba90880814ce8 100644 (file)
@@ -3581,7 +3581,8 @@ static Compose *compose_create(PrefsAccount *account, ComposeMode mode)
                gtkpspell = gtkpspell_new_with_config(gtkpspellconfig,
                                                      prefs_common.pspell_path,
                                                      prefs_common.dictionary,
-                                                     PSPELL_FASTMODE,NULL);
+                                                     PSPELL_FASTMODE,
+                                                     conv_get_current_charset_str());
                if (gtkpspell == NULL)
                        prefs_common.enable_pspell = FALSE;
                else
index 4cf55cd4727f6a9589310ea8f3058bfad70a06c3..0d9fb7be84dd55701398c81cdd2f06e459320272 100644 (file)
@@ -79,6 +79,7 @@ static void entry_insert_cb           (GtkXText *gtktext, gchar *newtext,
                                         guint len, guint *ppos, 
                                         GtkPspell *gtkpspell);
 static gint compare_dict               (Dictionary *a, Dictionary *b);
+guchar *convert_to_pspell_encoding     (const guchar *encoding);
 
 
 /* gtkspellconfig - only one config per session */
@@ -158,7 +159,7 @@ GtkPspell * gtkpspell_new(GtkPspellConfig *gtkpspellconfig)
  */
 GtkPspell *gtkpspell_new_with_config(GtkPspellConfig *gtkpspellconfig, 
                                      guchar *path, guchar *dict, 
-                                     guint mode, guchar *encoding)
+                                     guint mode, const guchar *encoding)
 {
        GtkPspell *gtkpspell;
 
@@ -187,8 +188,18 @@ GtkPspell *gtkpspell_new_with_config(GtkPspellConfig *gtkpspellconfig,
                return gtkpspell;
        }
        
-       if (encoding)
-               pspell_config_replace(gtkpspell->config,"encoding",encoding);
+       if (encoding) {
+               char *pspell_encoding;
+               pspell_encoding = convert_to_pspell_encoding (encoding);
+               debug_print(_("Pspell encoding: %s\n"), pspell_encoding);
+               pspell_config_replace(gtkpspell->config, "encoding", (const char *)pspell_encoding);
+               if (pspell_config_error_number(gtkpspell->config) !=0 ) {
+                       debug_print(_("Pspell encoding: %s\n"), pspell_config_error_message(gtkpspell->config));
+                       debug_print(_("Pspell encoding: setting error. Switching to iso8859-1 (sorry)\n"));
+                       pspell_config_replace(gtkpspell->config, "encoding", "iso8859-1");
+               }
+               g_free(pspell_encoding);
+       }
 
        gtkpspell->possible_err = new_pspell_manager(gtkpspell->config);
        gtkpspell->checker      = NULL;
@@ -1381,4 +1392,24 @@ gchar *gtkpspell_get_dictionary_menu_active_item(GtkWidget *menu)
         return g_strdup(result);
   
 }
+
+/* convert_to_pspell_encoding () - converts ISO-8859-* strings to iso8859-* 
+ * as needed by pspell. Returns an allocated string.
+ */
+
+guchar *convert_to_pspell_encoding (const guchar *encoding)
+{
+       guchar * pspell_encoding;
+       /* Beware, strstr2 returns 0 if string is found -1 if not */
+       if (!strstr2(encoding, "ISO-8859-")) {
+               pspell_encoding = g_strdup_printf("iso8859%s", encoding+8);
+       }
+       else
+               pspell_encoding = g_strdup(encoding);
+       return pspell_encoding;
+       
+}
+
+               
+               
 #endif
index dc282f17929ab2283a7905bc344eebaa12de4fad..74f9a1b27d9450fed89024f042ac9033d0ffcbae 100644 (file)
@@ -91,7 +91,7 @@ GtkPspell *gtkpspell_new_with_config(GtkPspellConfig *gtkpspellconfig,
                                      guchar *path, 
                                      guchar *dict, 
                                      guint mode, 
-                                     guchar *encoding);
+                                     const guchar *encoding);
 GtkPspell *gtkpspell_delete(GtkPspell *gtkpspell);
 
 int gtkpspell_set_path_and_dict(GtkPspell *gtkpspell, guchar * path,