diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2003-05-28 23:43:24 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2003-05-28 23:43:24 +0800 |
commit | bbda044fa543cce525dd4b585941ea2a6f1f249f (patch) | |
tree | 359c60a50a270a34b843b5d290724775132ce441 | |
parent | 6d3a2386b12ff5505fa9a78a7130240c94df3986 (diff) | |
download | gsoc2013-epiphany-bbda044fa543cce525dd4b585941ea2a6f1f249f.tar gsoc2013-epiphany-bbda044fa543cce525dd4b585941ea2a6f1f249f.tar.gz gsoc2013-epiphany-bbda044fa543cce525dd4b585941ea2a6f1f249f.tar.bz2 gsoc2013-epiphany-bbda044fa543cce525dd4b585941ea2a6f1f249f.tar.lz gsoc2013-epiphany-bbda044fa543cce525dd4b585941ea2a6f1f249f.tar.xz gsoc2013-epiphany-bbda044fa543cce525dd4b585941ea2a6f1f249f.tar.zst gsoc2013-epiphany-bbda044fa543cce525dd4b585941ea2a6f1f249f.zip |
continuing checkin of previous patch (cvs aborted "broken pipe")
2003-05-28 Christian Persch <chpe@cvs.gnome.org>
continuing checkin of previous patch (cvs aborted "broken pipe")
-rw-r--r-- | embed/ephy-embed-prefs.h | 4 | ||||
-rw-r--r-- | embed/ephy-embed-single.c | 15 | ||||
-rw-r--r-- | embed/ephy-embed-single.h | 27 | ||||
-rw-r--r-- | embed/ephy-embed-utils.c | 134 | ||||
-rw-r--r-- | embed/ephy-embed-utils.h | 10 | ||||
-rw-r--r-- | embed/ephy-embed.c | 6 | ||||
-rw-r--r-- | embed/ephy-embed.h | 10 | ||||
-rw-r--r-- | embed/mozilla/EphyWrapper.cpp | 4 | ||||
-rw-r--r-- | embed/mozilla/EphyWrapper.h | 2 | ||||
-rw-r--r-- | embed/mozilla/mozilla-embed-single.cpp | 254 | ||||
-rw-r--r-- | embed/mozilla/mozilla-embed.cpp | 14 | ||||
-rw-r--r-- | embed/mozilla/mozilla-notifiers.cpp | 50 | ||||
-rw-r--r-- | lib/Makefile.am | 1 | ||||
-rw-r--r-- | lib/ephy-langs.c | 42 | ||||
-rw-r--r-- | lib/ephy-langs.h | 45 | ||||
-rw-r--r-- | lib/ephy-string.c | 31 | ||||
-rw-r--r-- | lib/ephy-string.h | 2 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks-export.c | 1 | ||||
-rw-r--r-- | src/ephy-encoding-menu.c | 123 | ||||
-rw-r--r-- | src/ephy-nautilus-view.c | 33 | ||||
-rw-r--r-- | src/ephy-window.h | 2 | ||||
-rw-r--r-- | src/prefs-dialog.c | 93 |
22 files changed, 494 insertions, 409 deletions
diff --git a/embed/ephy-embed-prefs.h b/embed/ephy-embed-prefs.h index 3ced536ee..7a723f6ca 100644 --- a/embed/ephy-embed-prefs.h +++ b/embed/ephy-embed-prefs.h @@ -16,8 +16,8 @@ #define CONF_SECURITY_JAVA_ENABLED "/apps/epiphany/security/java_enabled" #define CONF_SECURITY_JAVASCRIPT_ENABLED "/apps/epiphany/security/javascript_enabled" #define CONF_SECURITY_COOKIES_ACCEPT "/apps/epiphany/security/cookie_accept" -#define CONF_LANGUAGE_AUTODETECT_CHARSET "/apps/epiphany/rendering/autodetect_charset" -#define CONF_LANGUAGE_DEFAULT_CHARSET "/apps/epiphany/rendering/default_charset" +#define CONF_LANGUAGE_AUTODETECT_ENCODING "/apps/epiphany/rendering/autodetect_encoding" +#define CONF_LANGUAGE_DEFAULT_ENCODING "/apps/epiphany/rendering/default_encoding" #define CONF_RENDERING_DEFAULT_FONT "/apps/epiphany/rendering/default_font" #define CONF_FILTERING_DEFAULT_STATUSBAR "/apps/epiphany/filtering/default_allow_statusbar" diff --git a/embed/ephy-embed-single.c b/embed/ephy-embed-single.c index dfeaf4c44..0e383499a 100644 --- a/embed/ephy-embed-single.c +++ b/embed/ephy-embed-single.c @@ -167,20 +167,21 @@ ephy_embed_single_load_proxy_autoconf (EphyEmbedSingle *shell, } gresult -ephy_embed_single_get_charset_titles (EphyEmbedSingle *shell, - const char *group, - GList **charsets) +ephy_embed_single_get_encodings (EphyEmbedSingle *shell, + LanguageGroup group, + gboolean elide_underscores, + GList **encodings) { EphyEmbedSingleClass *klass = EPHY_EMBED_SINGLE_GET_CLASS (shell); - return klass->get_charset_titles (shell, group, charsets); + return klass->get_encodings (shell, group, elide_underscores, encodings); } gresult -ephy_embed_single_get_charset_groups (EphyEmbedSingle *shell, - GList **groups) +ephy_embed_single_get_language_groups (EphyEmbedSingle *shell, + GList **groups) { EphyEmbedSingleClass *klass = EPHY_EMBED_SINGLE_GET_CLASS (shell); - return klass->get_charset_groups (shell, groups); + return klass->get_language_groups (shell, groups); } gresult diff --git a/embed/ephy-embed-single.h b/embed/ephy-embed-single.h index ebd065a92..3d271842e 100644 --- a/embed/ephy-embed-single.h +++ b/embed/ephy-embed-single.h @@ -23,6 +23,7 @@ #include "ephy-favicon-cache.h" #include "ephy-history.h" #include "downloader-view.h" +#include "ephy-langs.h" #include <glib-object.h> #include <glib.h> @@ -82,12 +83,6 @@ typedef struct gchar *username; } PasswordInfo; -typedef struct -{ - const char *name; - const char *title; -} CharsetInfo; - /** * PasswordType: To distinguish actual passwords from blocked password sites */ @@ -134,11 +129,12 @@ struct EphyEmbedSingleClass const char* url); gresult (* show_java_console) (EphyEmbedSingle *shell); gresult (* show_js_console) (EphyEmbedSingle *shell); - gresult (* get_charset_groups) (EphyEmbedSingle *shell, + gresult (* get_language_groups) (EphyEmbedSingle *shell, GList **groups); - gresult (* get_charset_titles) (EphyEmbedSingle *shell, - const char *group, - GList **charsets); + gresult (* get_encodings) (EphyEmbedSingle *shell, + LanguageGroup group, + gboolean elide_underscores, + GList **encodings); gresult (* get_font_list) (EphyEmbedSingle *shell, const char *langGroup, const char *fontType, @@ -178,13 +174,14 @@ gresult ephy_embed_single_set_offline_mode (EphyEmbedSingle *shell, gresult ephy_embed_single_load_proxy_autoconf (EphyEmbedSingle *shell, const char* url); -/* Charsets */ -gresult ephy_embed_single_get_charset_groups (EphyEmbedSingle *shell, +/* Encodings */ +gresult ephy_embed_single_get_language_groups (EphyEmbedSingle *shell, GList **groups); -gresult ephy_embed_single_get_charset_titles (EphyEmbedSingle *shell, - const char *group, - GList **charsets); +gresult ephy_embed_single_get_encodings (EphyEmbedSingle *shell, + LanguageGroup group, + gboolean elide_underscores, + GList **encodings); gresult ephy_embed_single_get_font_list (EphyEmbedSingle *shell, const char *langGroup, diff --git a/embed/ephy-embed-utils.c b/embed/ephy-embed-utils.c index 76ddd699e..57ef3beb4 100644 --- a/embed/ephy-embed-utils.c +++ b/embed/ephy-embed-utils.c @@ -26,6 +26,7 @@ #include "ephy-bonobo-extensions.h" #include "ephy-gui.h" #include "ephy-debug.h" +#include "ephy-langs.h" #include <gtk/gtkdialog.h> #include <gtk/gtkmessagedialog.h> @@ -168,129 +169,94 @@ ephy_embed_utils_save (GtkWidget *window, g_free (fileName); } -static void -build_group (GString *xml_string, const char *group, int index) -{ - char *tmp; - - tmp = g_strdup_printf ("<submenu label=\"%s\" name=\"CharsetGroup%d\">\n", - group, index); - xml_string = g_string_append (xml_string, tmp); - g_free (tmp); -} - -static void -build_charset (GString *xml_string, const CharsetInfo *info, int index) -{ - char *tmp; - char *verb; - - verb = g_strdup_printf ("Charset%d", index); - tmp = g_strdup_printf ("<menuitem label=\"%s\" name=\"%s\" verb=\"%s\"/>\n", - info->title, verb, verb); - xml_string = g_string_append (xml_string, tmp); - - g_free (tmp); - g_free (verb); -} - -static void -add_verbs (BonoboUIComponent *ui_component, - BonoboUIVerbFn fn, GList *verbs) -{ - GList *l; - char verb[15]; - int charset_index = 0; - - for (l = verbs; l != NULL; l = l->next) - { - EncodingMenuData *edata = (EncodingMenuData *)l->data; - - sprintf (verb, "Charset%d", charset_index); - charset_index++; - bonobo_ui_component_add_verb_full - (ui_component, verb, - g_cclosure_new (G_CALLBACK (fn), edata, - (GClosureNotify)g_free)); - } -} - /** - * ephy_embed_utils_build_charsets_submenu: + * ephy_embed_utils_build_encodings_submenu: * @ui_component: the parent #BonoboUIComponent * @path: the bonoboui path where to create the submenu. * It's recommended to use a <placeholder/> - * @fn: callback to report the selected charsets + * @fn: callback to report the selected encodings * @data: the data passed to the callback * - * Create a charset submenu using bonobo ui. + * Create a encoding submenu using bonobo ui. **/ void -ephy_embed_utils_build_charsets_submenu (BonoboUIComponent *ui_component, - const char *path, - BonoboUIVerbFn fn, - gpointer data) +ephy_embed_utils_build_encodings_submenu (BonoboUIComponent *ui_component, + const char *path, + BonoboUIVerbFn fn, + gpointer view) { - GList *groups, *gl; + gchar *tmp, *verb; GString *xml_string; + GList *groups, *gl, *encodings, *l; GList *verbs = NULL; - int group_index = 0; - int charset_index = 0; EphyEmbedSingle *single; - single = ephy_embed_shell_get_embed_single - (EPHY_EMBED_SHELL (embed_shell)); - - START_PROFILER ("Charsets menu") - + single = ephy_embed_shell_get_embed_single (EPHY_EMBED_SHELL (embed_shell)); g_return_if_fail (IS_EPHY_EMBED_SHELL (embed_shell)); - g_return_if_fail (ephy_embed_single_get_charset_groups (single, &groups) == G_OK); + START_PROFILER ("Encodings menu") + + ephy_embed_single_get_language_groups (single, &groups); + g_return_if_fail (groups != NULL); + xml_string = g_string_new (NULL); g_string_append (xml_string, "<submenu name=\"Encoding\" _label=\"_Encoding\">"); for (gl = groups; gl != NULL; gl = gl->next) { - GList *charsets, *cl; - const char *group = (const char *)gl->data; - - build_group (xml_string, group, group_index); + const LanguageGroupInfo *lang_info = (LanguageGroupInfo *) gl->data; - ephy_embed_single_get_charset_titles (single, - group, - &charsets); + tmp = g_strdup_printf ("<submenu label=\"%s\" name=\"EncodingGroup%d\">\n", + lang_info->title, lang_info->group); + xml_string = g_string_append (xml_string, tmp); + g_free (tmp); - for (cl = charsets; cl != NULL; cl = cl->next) + ephy_embed_single_get_encodings (single, lang_info->group, + FALSE, &encodings); + + for (l = encodings; l != NULL; l = l->next) { - const CharsetInfo *info = cl->data; - EncodingMenuData *edata; + const EncodingInfo *info = (EncodingInfo *) l->data; - edata = g_new0 (EncodingMenuData, 1); - edata->encoding = info->name; - edata->data = data; - verbs = g_list_append (verbs, edata); + verb = g_strdup_printf ("Encoding%s", info->encoding); + tmp = g_strdup_printf ("<menuitem label=\"%s\" name=\"%s\" verb=\"%s\"/>\n", + info->title, verb, verb); + xml_string = g_string_append (xml_string, tmp); - build_charset (xml_string, info, charset_index); - charset_index++; + verbs = g_list_prepend (verbs, verb); + + g_free (tmp); } + g_list_foreach (encodings, (GFunc) encoding_info_free, NULL); + g_list_free (encodings); - g_list_free (charsets); g_string_append (xml_string, "</submenu>"); - group_index++; } + g_list_foreach (groups, (GFunc) language_group_info_free, NULL); + g_list_free (groups); + g_string_append (xml_string, "</submenu>"); bonobo_ui_component_set_translate (ui_component, path, xml_string->str, NULL); - add_verbs (ui_component, fn, verbs); + verbs = g_list_reverse (verbs); + + for (l = verbs; l != NULL; l = l->next) + { + bonobo_ui_component_add_verb (ui_component, + (const char *) l->data, + fn, view); + } + + g_list_foreach (verbs, (GFunc) g_free, NULL); g_list_free (verbs); - g_list_free (groups); + g_string_free (xml_string, TRUE); - STOP_PROFILER ("Charsets menu") + STOP_PROFILER ("Encodings menu") } /** diff --git a/embed/ephy-embed-utils.h b/embed/ephy-embed-utils.h index c24119828..5ce61cb7e 100644 --- a/embed/ephy-embed-utils.h +++ b/embed/ephy-embed-utils.h @@ -26,22 +26,16 @@ G_BEGIN_DECLS -typedef struct -{ - const char *encoding; - gpointer data; -} EncodingMenuData; - void ephy_embed_utils_save (GtkWidget *window, const char *default_dir_pref, gboolean ask_dest, gboolean with_content, EphyEmbedPersist *persist); -void ephy_embed_utils_build_charsets_submenu (BonoboUIComponent *ui_component, +void ephy_embed_utils_build_encodings_submenu (BonoboUIComponent *ui_component, const char *path, BonoboUIVerbFn fn, - gpointer data); + gpointer view); void ephy_embed_utils_nohandler_dialog_run (GtkWidget *parent); diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c index c0858a32f..3360e9e67 100644 --- a/embed/ephy-embed.c +++ b/embed/ephy-embed.c @@ -536,11 +536,11 @@ ephy_embed_find (EphyEmbed *embed, } gresult -ephy_embed_set_charset (EphyEmbed *embed, - const char *charset) +ephy_embed_set_encoding (EphyEmbed *embed, + const char *encoding) { EphyEmbedClass *klass = EPHY_EMBED_GET_CLASS (embed); - return klass->set_charset (embed, charset); + return klass->set_encoding (embed, encoding); } gresult diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h index c8e732e09..c4cac0aef 100644 --- a/embed/ephy-embed.h +++ b/embed/ephy-embed.h @@ -64,7 +64,7 @@ typedef enum EMBED_FIND_CAP = 1 << 7, EMBED_SCROLL_CAP = 1 << 8, EMBED_SECURITY_CAP = 1 << 9, - EMBED_CHARSET_CAP = 1 << 10, + EMBED_ENCODING_CAP = 1 << 10, EMBED_SHISTORY_CAP = 1 << 11 } EmbedCapabilities; @@ -272,8 +272,8 @@ struct EphyEmbedClass gresult (* print_preview_navigate) (EphyEmbed *embed, EmbedPrintPreviewNavType navType, gint pageNum); - gresult (* set_charset) (EphyEmbed *embed, - const char *charset); + gresult (* set_encoding) (EphyEmbed *embed, + const char *encoding); }; GType ephy_embed_get_type (void); @@ -386,8 +386,8 @@ gresult ephy_embed_get_security_level (EphyEmbed *embed, gresult ephy_embed_find (EphyEmbed *embed, EmbedFindInfo *find); -gresult ephy_embed_set_charset (EphyEmbed *embed, - const char *charset); +gresult ephy_embed_set_encoding (EphyEmbed *embed, + const char *encoding); /* Printing */ diff --git a/embed/mozilla/EphyWrapper.cpp b/embed/mozilla/EphyWrapper.cpp index 7268c4a69..b08447145 100644 --- a/embed/mozilla/EphyWrapper.cpp +++ b/embed/mozilla/EphyWrapper.cpp @@ -714,7 +714,7 @@ nsresult EphyWrapper::CopyHistoryTo (EphyWrapper *dest) return NS_OK; } -nsresult EphyWrapper::ForceCharacterSet (const char *charset) +nsresult EphyWrapper::ForceEncoding (const char *encoding) { nsresult result; @@ -730,7 +730,7 @@ nsresult EphyWrapper::ForceCharacterSet (const char *charset) &result); if (NS_FAILED(result) || !mdv) return NS_ERROR_FAILURE; - result = mdv->SetForceCharacterSet (NS_ConvertUTF8toUCS2(charset).get()); + result = mdv->SetForceCharacterSet (NS_ConvertUTF8toUCS2(encoding).get()); return result; } diff --git a/embed/mozilla/EphyWrapper.h b/embed/mozilla/EphyWrapper.h index d083da44a..dd9d1c228 100644 --- a/embed/mozilla/EphyWrapper.h +++ b/embed/mozilla/EphyWrapper.h @@ -75,7 +75,7 @@ public: nsresult GoToHistoryIndex (PRInt16 index); - nsresult ForceCharacterSet (const char *charset); + nsresult ForceEncoding (const char *encoding); nsresult CanCutSelection(PRBool *result); diff --git a/embed/mozilla/mozilla-embed-single.cpp b/embed/mozilla/mozilla-embed-single.cpp index bc6084d7b..51377f6c8 100644 --- a/embed/mozilla/mozilla-embed-single.cpp +++ b/embed/mozilla/mozilla-embed-single.cpp @@ -62,56 +62,46 @@ #define MOZILLA_PROFILE_NAME "epiphany" #define MOZILLA_PROFILE_FILE "prefs.js" -/* language groups */ -typedef enum -{ - LG_ARABIC, - LG_BALTIC, - LG_CENTRAL_EUROPEAN, - LG_CHINESE, - LG_CYRILLIC, - LG_GREEK, - LG_HEBREW, - LG_INDIAN, - LG_JAPANESE, - LG_KOREAN, - LG_TURKISH, - LG_UNICODE, - LG_VIETNAMESE, - LG_WESTERN, - LG_OTHER, -} LanguageGroup; - /* language groups names */ -static const gchar *lgroups[] = +static const +struct +{ + gchar *title; + LanguageGroup group; +} +lang_groups[] = { - N_("Arabic"), - N_("Baltic"), - N_("Central European"), - N_("Chinese"), - N_("Cyrillic"), - N_("Greek"), - N_("Hebrew"), - N_("Indian"), - N_("Japanese"), - N_("Korean"), - N_("Turkish"), - N_("Unicode"), - N_("Vietnamese"), - N_("Western"), - N_("Other") + { N_("Arabic"), LG_ARABIC }, + { N_("Baltic"), LG_BALTIC }, + { N_("Central European"), LG_CENTRAL_EUROPEAN }, + { N_("Chinese"), LG_CHINESE }, + { N_("Cyrillic"), LG_CYRILLIC }, + { N_("Greek"), LG_GREEK }, + { N_("Hebrew"), LG_HEBREW }, + { N_("Indian"), LG_INDIAN }, + { N_("Japanese"), LG_JAPANESE }, + { N_("Korean"), LG_KOREAN }, + { N_("Turkish"), LG_TURKISH }, + { N_("Unicode"), LG_UNICODE }, + { N_("Vietnamese"), LG_VIETNAMESE }, + { N_("Western"), LG_WESTERN }, + { N_("Other"), LG_OTHER } }; -static const guint n_lgroups = G_N_ELEMENTS (lgroups); +static const guint n_lang_groups = G_N_ELEMENTS (lang_groups); -/* translated charset titles */ -static const +/** + * translatable encodings titles + * NOTE: if you add /change encodings, please also update the schema file + * epiphany.schemas.in + */ +static const struct { - gchar *charset_title; - gchar *charset_name; - LanguageGroup lgroup; + gchar *title; + gchar *name; + LanguageGroup group; } -charset_trans_array[] = +encodings[] = { { N_("Arabic (IBM-864)"), "IBM864", LG_ARABIC }, { N_("Arabic (IBM-864-I)"), "IBM864i", LG_ARABIC }, @@ -196,12 +186,12 @@ charset_trans_array[] = { N_("Western (ISO-8859-15)"), "ISO-8859-15", LG_WESTERN }, { N_("Western (MacRoman)"), "x-mac-roman", LG_WESTERN }, { N_("Western (Windows-1252)"), "windows-1252", LG_WESTERN }, - /* charsets whithout posibly translatable names */ + /* encodings whithout posibly translatable names */ { "T.61-8bit", "T.61-8bit", LG_OTHER }, { "x-imap4-modified-utf7", "x-imap4-modified-utf7", LG_UNICODE }, { "x-u-escaped", "x-u-escaped", LG_OTHER } }; -static const guint n_charset_trans_array = G_N_ELEMENTS (charset_trans_array); +static const guint n_encodings = G_N_ELEMENTS (encodings); static void mozilla_embed_single_class_init (MozillaEmbedSingleClass *klass); @@ -220,12 +210,13 @@ static gresult impl_load_proxy_autoconf (EphyEmbedSingle *shell, const char* url); static gresult -impl_get_charset_titles (EphyEmbedSingle *shell, - const char *group, - GList **charsets); +impl_get_encodings (EphyEmbedSingle *shell, + LanguageGroup group, + gboolean elide_underscores, + GList **encodings_list); static gresult -impl_get_charset_groups (EphyEmbedSingle *shell, - GList **groups); +impl_get_language_groups (EphyEmbedSingle *shell, + GList **groups); static gresult impl_get_font_list (EphyEmbedSingle *shell, const char *langGroup, @@ -262,11 +253,13 @@ static void mozilla_embed_single_new_window_orphan_cb (GtkMozEmbedSingle *embed, guint chrome_mask, EphyEmbedSingle *shell); +#ifdef GNOME_ENABLE_DEBUG +static gresult control_encodings_list (void); +#endif + struct MozillaEmbedSinglePrivate { char *user_prefs; - GHashTable *charsets_hash; - GList *sorted_charsets_titles; }; static NS_DEFINE_CID(kJVMManagerCID, NS_JVMMANAGER_CID); @@ -315,8 +308,8 @@ mozilla_embed_single_class_init (MozillaEmbedSingleClass *klass) shell_class->clear_cache = impl_clear_cache; shell_class->set_offline_mode = impl_set_offline_mode; shell_class->load_proxy_autoconf = impl_load_proxy_autoconf; - shell_class->get_charset_titles = impl_get_charset_titles; - shell_class->get_charset_groups = impl_get_charset_groups; + shell_class->get_encodings = impl_get_encodings; + shell_class->get_language_groups = impl_get_language_groups; shell_class->get_font_list = impl_get_font_list; shell_class->list_cookies = impl_list_cookies; shell_class->remove_cookies = impl_remove_cookies; @@ -472,8 +465,6 @@ static void mozilla_embed_single_init (MozillaEmbedSingle *mes) { mes->priv = g_new0 (MozillaEmbedSinglePrivate, 1); - mes->priv->charsets_hash = NULL; - mes->priv->sorted_charsets_titles = NULL; mes->priv->user_prefs = g_build_filename (ephy_dot_dir (), @@ -501,6 +492,9 @@ mozilla_embed_single_init (MozillaEmbedSingle *mes) mozilla_register_external_protocols (); +#ifdef GNOME_ENABLE_DEBUG + control_encodings_list (); +#endif /* FIXME alert if fails */ } @@ -622,13 +616,15 @@ impl_load_proxy_autoconf (EphyEmbedSingle *shell, return G_OK; } +#ifdef GNOME_ENABLE_DEBUG static gresult -fill_charsets_lists (MozillaEmbedSinglePrivate *priv) +control_encodings_list (void) { nsresult rv; char *tmp; PRUint32 cscount; - char *charset_str, *charset_title_str; + char *encoding_str, *encoding_title_str; + gresult ret = G_OK; nsCOMPtr<nsIAtom> docCharsetAtom; nsCOMPtr<nsICharsetConverterManager2> ccm2 = @@ -640,131 +636,151 @@ fill_charsets_lists (MozillaEmbedSinglePrivate *priv) if (!NS_SUCCEEDED(rv)) return G_FAILED; rv = cs_list->Count(&cscount); - priv->charsets_hash = g_hash_table_new (g_str_hash, g_str_equal); for (PRUint32 i = 0; i < cscount; i++) { nsCOMPtr<nsISupports> cssupports = (dont_AddRef)(cs_list->ElementAt(i)); nsCOMPtr<nsIAtom> csatom ( do_QueryInterface(cssupports) ); - nsAutoString charset_ns, charset_title_ns; + nsAutoString encoding_ns, encoding_title_ns; - /* charset name */ - rv = csatom->ToString(charset_ns); - tmp = ToNewCString (charset_ns); + /* encoding name */ + rv = csatom->ToString(encoding_ns); + tmp = ToNewCString (encoding_ns); if (tmp == NULL || strlen (tmp) == 0) { continue; } - charset_str = g_strdup (tmp); + encoding_str = g_strdup (tmp); nsMemory::Free (tmp); tmp = nsnull; - /* charset readable title */ - rv = ccm2->GetCharsetTitle2(csatom, &charset_title_ns); - tmp = ToNewCString (charset_title_ns); + /* encoding readable title */ + rv = ccm2->GetCharsetTitle2(csatom, &encoding_title_ns); + tmp = ToNewCString (encoding_title_ns); if (tmp == NULL || strlen (tmp) == 0) { - charset_title_str = g_strdup (charset_str); + encoding_title_str = g_strdup (encoding_str); } else { - charset_title_str = g_strdup (tmp); + encoding_title_str = g_strdup (tmp); } if (tmp) nsMemory::Free (tmp); tmp = nsnull; -#ifdef GNOME_ENABLE_DEBUG gboolean found = FALSE; -#endif - for (PRUint32 j = 0; j < n_charset_trans_array; j++) + for (PRUint32 j = 0; j < n_encodings; j++) { if (g_ascii_strcasecmp ( - charset_str, - charset_trans_array[j].charset_name) == 0) + encoding_str, + encodings[j].name) == 0) { - g_free (charset_title_str); - charset_title_str = (char *) - _(charset_trans_array[j].charset_title); -#ifdef GNOME_ENABLE_DEBUG + LOG ("Mozilla reported encoding %s with title %s found in our list.", + encoding_str, encoding_title_str) + found = TRUE; -#endif break; } } -#ifdef GNOME_ENABLE_DEBUG if (found == FALSE) { - g_warning ("Charset %s with title %s not in list!", - charset_str, charset_title_str); + g_warning ("Mozilla reported encoding %s with title %s NOT found in our list!", + encoding_str, encoding_title_str); + ret = G_FAILED; } -#endif - - /* fill the hash and the sorted list */ - g_hash_table_insert (priv->charsets_hash, charset_title_str, charset_str); - priv->sorted_charsets_titles = - g_list_insert_sorted (priv->sorted_charsets_titles, - (gpointer)charset_title_str, - (GCompareFunc)g_ascii_strcasecmp); } - return G_OK; + return ret; } +#endif -static void -ensure_charsets_tables (MozillaEmbedSingle *shell) +static gint +encoding_info_cmp (const EncodingInfo *i1, const EncodingInfo *i2) { - if (!shell->priv->charsets_hash) - { - fill_charsets_lists (shell->priv); - } + return strcmp (i1->key, i2->key); } static gresult -impl_get_charset_titles (EphyEmbedSingle *shell, - const char *group, - GList **charsets) +impl_get_encodings (EphyEmbedSingle *shell, + LanguageGroup group, + gboolean elide_underscores, + GList **encodings_list) { - MozillaEmbedSingle *mshell = MOZILLA_EMBED_SINGLE(shell); GList *l = NULL; - guint j; - - ensure_charsets_tables (mshell); - g_return_val_if_fail (mshell->priv->charsets_hash != NULL, G_FAILED); + guint i; - for (j = 0; j < n_charset_trans_array; j++) - { - if (group == NULL || - strcmp (group, lgroups[charset_trans_array[j].lgroup]) == 0) + for (i = 0; i < n_encodings; i++) + { + if (group == LG_ALL || group == encodings[i].group) { - CharsetInfo *info; - info = g_new0 (CharsetInfo, 1); - info->name = charset_trans_array[j].charset_name; - info->title = charset_trans_array[j].charset_title; + EncodingInfo *info; + gchar *elided = NULL; + + info = g_new0 (EncodingInfo, 1); + + info->encoding = g_strdup (encodings[i].name); + + elided = ephy_str_elide_underscores (_(encodings[i].title)); + + if (elide_underscores) + { + info->title = g_strdup (elided); + } + else + { + info->title = g_strdup (_(encodings[i].title)); + } + + /* collate without underscores */ + info->key = g_utf8_collate_key (elided, -1); + + info->group = encodings[i].group; + l = g_list_prepend (l, info); + g_free (elided); } } - *charsets = g_list_reverse (l); + *encodings_list = g_list_sort (l, (GCompareFunc) encoding_info_cmp); return G_OK; } +static gint +language_group_info_cmp (const LanguageGroupInfo *i1, const LanguageGroupInfo *i2) +{ + return strcmp (i1->key, i2->key); +} + static gresult -impl_get_charset_groups (EphyEmbedSingle *shell, - GList **groups) +impl_get_language_groups (EphyEmbedSingle *shell, + GList **groups) { GList *l = NULL; guint i; - for (i = 0; i < n_lgroups; i++) + for (i = 0; i < n_lang_groups; i++) { - l = g_list_prepend (l, (gpointer)lgroups[i]); + LanguageGroupInfo *info; + gchar *elided = NULL; + + info = g_new0 (LanguageGroupInfo, 1); + + info->title = g_strdup (_(lang_groups[i].title)); + info->group = lang_groups[i].group; + + /* collate without underscores */ + elided = ephy_str_elide_underscores (info->title); + info->key = g_utf8_collate_key (elided, -1); + g_free (elided); + + l = g_list_prepend (l, info); } - *groups = g_list_reverse (l); + *groups = g_list_sort (l, (GCompareFunc) language_group_info_cmp); return G_OK; } diff --git a/embed/mozilla/mozilla-embed.cpp b/embed/mozilla/mozilla-embed.cpp index 06c12b032..6d6a34726 100644 --- a/embed/mozilla/mozilla-embed.cpp +++ b/embed/mozilla/mozilla-embed.cpp @@ -149,8 +149,8 @@ impl_find (EphyEmbed *embed, EmbedFindInfo *info); static gresult -impl_set_charset (EphyEmbed *embed, - const char *charset); +impl_set_encoding (EphyEmbed *embed, + const char *encoding); static gresult impl_print (EphyEmbed *embed, @@ -327,7 +327,7 @@ ephy_embed_init (EphyEmbedClass *embed_class) embed_class->shistory_copy = impl_shistory_copy; embed_class->get_security_level = impl_get_security_level; embed_class->find = impl_find; - embed_class->set_charset = impl_set_charset; + embed_class->set_encoding = impl_set_encoding; embed_class->select_all = impl_select_all; embed_class->print = impl_print; embed_class->print_preview_close = impl_print_preview_close; @@ -437,7 +437,7 @@ impl_get_capabilities (EphyEmbed *embed, EMBED_PRINT_CAP | EMBED_FIND_CAP | EMBED_SECURITY_CAP | - EMBED_CHARSET_CAP | + EMBED_ENCODING_CAP | EMBED_SHISTORY_CAP ); *caps = mozilla_caps; @@ -1155,8 +1155,8 @@ impl_find (EphyEmbed *embed, } static gresult -impl_set_charset (EphyEmbed *embed, - const char *charset) +impl_set_encoding (EphyEmbed *embed, + const char *encoding) { nsresult result = NS_OK; EphyWrapper *wrapper; @@ -1164,7 +1164,7 @@ impl_set_charset (EphyEmbed *embed, wrapper = MOZILLA_EMBED(embed)->priv->wrapper; g_return_val_if_fail (wrapper != NULL, G_FAILED); - result = wrapper->ForceCharacterSet (charset); + result = wrapper->ForceEncoding (encoding); if (NS_FAILED (result)) return G_FAILED; gtk_moz_embed_reload (GTK_MOZ_EMBED (embed), diff --git a/embed/mozilla/mozilla-notifiers.cpp b/embed/mozilla/mozilla-notifiers.cpp index 1f05f5abd..de02d9a38 100644 --- a/embed/mozilla/mozilla-notifiers.cpp +++ b/embed/mozilla/mozilla-notifiers.cpp @@ -80,10 +80,10 @@ mozilla_language_notifier(GConfClient *client, EphyEmbedSingle *single); static void -mozilla_autodetect_charset_notifier(GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - EphyEmbedSingle *single); +mozilla_autodetect_encoding_notifier(GConfClient *client, + guint cnxn_id, + GConfEntry *entry, + EphyEmbedSingle *single); static void mozilla_default_font_notifier(GConfClient *client, @@ -109,10 +109,10 @@ mozilla_user_agent_notifier(GConfClient *client, EphyEmbedSingle *single); static void -mozilla_default_charset_notifier (GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - EphyEmbedSingle *single); +mozilla_default_encoding_notifier (GConfClient *client, + guint cnxn_id, + GConfEntry *entry, + EphyEmbedSingle *single); static void mozilla_socks_version_notifier (GConfClient *client, guint cnxn_id, @@ -174,12 +174,12 @@ custom_notifiers [] = (GConfClientNotifyFunc) mozilla_own_fonts_notifier }, { CONF_SECURITY_ALLOW_POPUPS, (GConfClientNotifyFunc) mozilla_allow_popups_notifier }, - { CONF_LANGUAGE_DEFAULT_CHARSET, - (GConfClientNotifyFunc) mozilla_default_charset_notifier }, + { CONF_LANGUAGE_DEFAULT_ENCODING, + (GConfClientNotifyFunc) mozilla_default_encoding_notifier }, { CONF_RENDERING_LANGUAGE, (GConfClientNotifyFunc) mozilla_language_notifier }, - { CONF_LANGUAGE_AUTODETECT_CHARSET, - (GConfClientNotifyFunc) mozilla_autodetect_charset_notifier }, + { CONF_LANGUAGE_AUTODETECT_ENCODING, + (GConfClientNotifyFunc) mozilla_autodetect_encoding_notifier }, { CONF_RENDERING_DEFAULT_FONT, (GConfClientNotifyFunc) mozilla_default_font_notifier }, { CONF_NETWORK_SOCKS_PROXY_VERSION, @@ -527,10 +527,10 @@ generic_mozilla_bool_notifier(GConfClient *client, } static void -mozilla_default_charset_notifier(GConfClient *client, - guint cnxn_id, - GConfEntry *entry, - EphyEmbedSingle *single) +mozilla_default_encoding_notifier(GConfClient *client, + guint cnxn_id, + GConfEntry *entry, + EphyEmbedSingle *single) { /* FIXME */ } @@ -633,7 +633,7 @@ mozilla_language_notifier(GConfClient *client, g_slist_free (languages); } -static char *autodetect_charset_prefs[] = +static char *autodetect_encoding_prefs[] = { "", "zh_parallel_state_machine", @@ -647,22 +647,22 @@ static char *autodetect_charset_prefs[] = }; static void -mozilla_autodetect_charset_notifier(GConfClient *client, +mozilla_autodetect_encoding_notifier(GConfClient *client, guint cnxn_id, GConfEntry *entry, EphyEmbedSingle *single) { - int charset = eel_gconf_get_integer (CONF_LANGUAGE_AUTODETECT_CHARSET); - if (charset < 0 || - charset >= (int)(sizeof(autodetect_charset_prefs) - / sizeof(autodetect_charset_prefs[0]))) + int encoding = eel_gconf_get_integer (CONF_LANGUAGE_AUTODETECT_ENCODING); + if (encoding < 0 || + encoding >= (int)(sizeof(autodetect_encoding_prefs) + / sizeof(autodetect_encoding_prefs[0]))) { - g_warning ("mozilla_autodetect_charset_notifier: " - "unsupported value: %d", charset); + g_warning ("mozilla_autodetect_encoding_notifier: " + "unsupported value: %d", encoding); return; } mozilla_prefs_set_string ("intl.charset.detector", - autodetect_charset_prefs[charset]); + autodetect_encoding_prefs[encoding]); } static void diff --git a/lib/Makefile.am b/lib/Makefile.am index a4769da1a..81edc43be 100644 --- a/lib/Makefile.am +++ b/lib/Makefile.am @@ -35,6 +35,7 @@ libephy_la_SOURCES = \ ephy-gui.c \ ephy-gui.h \ ephy-langs.h \ + ephy-langs.c \ ephy-marshal.c \ ephy-marshal.h \ ephy-node.c \ diff --git a/lib/ephy-langs.c b/lib/ephy-langs.c new file mode 100644 index 000000000..583aeb4dc --- /dev/null +++ b/lib/ephy-langs.c @@ -0,0 +1,42 @@ +/* + * Copyright (C) 2003 Christian Persch + * + * 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, 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., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. + */ + + #include "ephy-langs.h" + +void +language_group_info_free (LanguageGroupInfo *info) +{ + g_return_if_fail (info != NULL); + + g_free (info->title); + g_free (info->key); + + g_free (info); +} + +void +encoding_info_free (EncodingInfo *info) +{ + g_return_if_fail (info != NULL); + + g_free (info->title); + g_free (info->key); + g_free (info->encoding); + + g_free (info); +} diff --git a/lib/ephy-langs.h b/lib/ephy-langs.h index 38df4fecf..2d2c79dd2 100644 --- a/lib/ephy-langs.h +++ b/lib/ephy-langs.h @@ -16,6 +16,9 @@ * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ +#ifndef EPHY_LANGS_H +#define EPHY_LANGS_H + #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -24,6 +27,42 @@ G_BEGIN_DECLS +/* language groups */ +typedef enum +{ + LG_ARABIC, + LG_BALTIC, + LG_CENTRAL_EUROPEAN, + LG_CHINESE, + LG_CYRILLIC, + LG_GREEK, + LG_HEBREW, + LG_INDIAN, + LG_JAPANESE, + LG_KOREAN, + LG_TURKISH, + LG_UNICODE, + LG_VIETNAMESE, + LG_WESTERN, + LG_OTHER, + LG_ALL +} LanguageGroup; + +typedef struct +{ + gchar *title; + gchar *key; + LanguageGroup group; +} LanguageGroupInfo; + +typedef struct +{ + gchar *title; + gchar *key; + gchar *encoding; + LanguageGroup group; +} EncodingInfo; + /* language encoding groups */ static const gchar *lang_encode_item[] = { @@ -44,4 +83,10 @@ static const gchar *lang_encode_item[] = }; static const guint n_lang_encode_items = G_N_ELEMENTS (lang_encode_item); +void language_group_info_free (LanguageGroupInfo *info); + +void encoding_info_free (EncodingInfo *info); + G_END_DECLS + +#endif diff --git a/lib/ephy-string.c b/lib/ephy-string.c index 46a6b6d9f..b97e0485c 100644 --- a/lib/ephy-string.c +++ b/lib/ephy-string.c @@ -15,7 +15,7 @@ * along with this program; if not, write to the Free Software * Foundation, Inc., 59 Temple Place - Suite 330, Boston, MA 02111-1307, USA. */ - + #ifdef HAVE_CONFIG_H #include <config.h> #endif @@ -499,3 +499,32 @@ ephy_str_replace_substring (const char *string, return result; } + +/* copied from egg-toolbar-editor.c */ +gchar * +ephy_str_elide_underscores (const gchar *original) +{ + gchar *q, *result; + const gchar *p; + gboolean last_underscore; + + q = result = g_malloc (strlen (original) + 1); + last_underscore = FALSE; + + for (p = original; *p; p++) + { + if (!last_underscore && *p == '_') + { + last_underscore = TRUE; + } + else + { + last_underscore = FALSE; + *q++ = *p; + } + } + + *q = '\0'; + + return result; +} diff --git a/lib/ephy-string.h b/lib/ephy-string.h index 97e15e756..56dad3552 100644 --- a/lib/ephy-string.h +++ b/lib/ephy-string.h @@ -61,7 +61,7 @@ char *ephy_str_replace_substring (const char *string, const char *substring, const char *replacement); - +gchar *ephy_str_elide_underscores (const gchar *original); G_END_DECLS diff --git a/src/bookmarks/ephy-bookmarks-export.c b/src/bookmarks/ephy-bookmarks-export.c index e17a67dc0..223297f87 100644 --- a/src/bookmarks/ephy-bookmarks-export.c +++ b/src/bookmarks/ephy-bookmarks-export.c @@ -20,6 +20,7 @@ #include "ephy-bookmarks-export.h" #include "ephy-node-common.h" +#include "ephy-file-helpers.h" #include "ephy-debug.h" static void diff --git a/src/ephy-encoding-menu.c b/src/ephy-encoding-menu.c index dac05a0af..58dd153a1 100644 --- a/src/ephy-encoding-menu.c +++ b/src/ephy-encoding-menu.c @@ -29,6 +29,8 @@ #include <bonobo/bonobo-i18n.h> +#include <string.h> + /** * Private data */ @@ -38,12 +40,6 @@ struct _EphyEncodingMenuPrivate EggActionGroup *action_group; }; -typedef struct -{ - EphyWindow *window; - const char *encoding; -} EncodingData; - /** * Private functions, only availble from this file */ @@ -167,68 +163,77 @@ ephy_encoding_menu_new (EphyWindow *window) } static void -ephy_encoding_menu_verb_cb (EggMenuMerge *merge, - EncodingData *data) +ephy_encoding_menu_verb_cb (EggAction *action, + EphyEncodingMenu *menu) { - EphyWindow *window = data->window; + EphyWindow *window; EphyEmbed *embed; + gchar *encoding; + + window = menu->priv->window; embed = ephy_window_get_active_embed (window); g_return_if_fail (embed != NULL); - ephy_embed_set_charset (embed, data->encoding); + if (strncmp (action->name, "Encoding", 8) == 0) + { + encoding = action->name + 8; + + LOG ("Switching to encoding %s", encoding) + + ephy_embed_set_encoding (embed, encoding); + } } static void -build_group (EggActionGroup *action_group, GString *xml_string, const char *group, int index) +build_group (EggActionGroup *action_group, + GString *xml_string, + const LanguageGroupInfo *info) { - char *tmp; - char *verb; + gchar *tmp; + gchar *verb; EggAction *action; - verb = g_strdup_printf ("CharsetGroup%d", index); + verb = g_strdup_printf ("EncodingGroup%d", info->group); action = g_object_new (EGG_TYPE_ACTION, "name", verb, - "label", _(group), + "label", info->title, NULL); egg_action_group_add_action (action_group, action); g_object_unref (action); - tmp = g_strdup_printf ("<submenu name=\"CharsetGroup%dItem\" name=\"%s\">\n", - index, verb); + tmp = g_strdup_printf ("<submenu name=\"%sItem\" name=\"%s\">\n", + verb, verb); xml_string = g_string_append (xml_string, tmp); g_free (tmp); g_free (verb); } static void -build_charset (EggActionGroup *action_group, - GString *xml_string, - const CharsetInfo *info, - int index, - EncodingData *edata) +build_encoding (EphyEncodingMenu *menu, + EggActionGroup *action_group, + GString *xml_string, + const EncodingInfo *info) { char *tmp; char *verb; EggAction *action; - verb = g_strdup_printf ("Charset%d", index); + verb = g_strdup_printf ("Encoding%s", info->encoding); action = g_object_new (EGG_TYPE_ACTION, "name", verb, - "label", _(info->title), + "label", info->title, NULL); - g_signal_connect_closure - (action, "activate", - g_cclosure_new (G_CALLBACK (ephy_encoding_menu_verb_cb), - edata, - (GClosureNotify)g_free), - FALSE); + g_signal_connect (action, "activate", + G_CALLBACK (ephy_encoding_menu_verb_cb), + menu); + egg_action_group_add_action (action_group, action); g_object_unref (action); - tmp = g_strdup_printf ("<menuitem name=\"Charset%dItem\" verb=\"%s\"/>\n", - index, verb); + tmp = g_strdup_printf ("<menuitem name=\"%sItem\" verb=\"%s\"/>\n", + verb, verb); xml_string = g_string_append (xml_string, tmp); g_free (tmp); @@ -238,18 +243,21 @@ build_charset (EggActionGroup *action_group, static void ephy_encoding_menu_rebuild (EphyEncodingMenu *wrhm) { + EphyEmbedSingle *single; EphyEncodingMenuPrivate *p = wrhm->priv; - GString *xml; - GList *groups, *gl; EggMenuMerge *merge = EGG_MENU_MERGE (p->window->ui_merge); - int group_index = 0, charset_index = 0; - EphyEmbedSingle *single; + GString *xml; + GList *groups, *lg, *encodings, *enc; - single = ephy_embed_shell_get_embed_single - (EPHY_EMBED_SHELL (ephy_shell)); + p->action_group = NULL; LOG ("Rebuilding encoding menu") + single = ephy_embed_shell_get_embed_single (EPHY_EMBED_SHELL (ephy_shell)); + g_return_if_fail (single != NULL); + + ephy_embed_single_get_language_groups (single, &groups); + xml = g_string_new (NULL); g_string_append (xml, "<Root><menu><submenu name=\"ViewMenu\">" "<placeholder name=\"ViewEncodingsPlaceholder\">" @@ -258,43 +266,34 @@ ephy_encoding_menu_rebuild (EphyEncodingMenu *wrhm) p->action_group = egg_action_group_new ("EncodingActions"); egg_menu_merge_insert_action_group (merge, p->action_group, 0); - ephy_embed_single_get_charset_groups (single, &groups); - - for (gl = groups; gl != NULL; gl = gl->next) + for (lg = groups; lg != NULL; lg = lg->next) { - GList *charsets, *cl; - const char *group = (const char *)gl->data; + const LanguageGroupInfo *lang_info = (LanguageGroupInfo *) lg->data; - build_group (p->action_group, xml, group, group_index); + build_group (p->action_group, xml, lang_info); - ephy_embed_single_get_charset_titles (single, - group, - &charsets); + ephy_embed_single_get_encodings (single, lang_info->group, + FALSE, &encodings); - for (cl = charsets; cl != NULL; cl = cl->next) + for (enc = encodings; enc != NULL; enc = enc->next) { - const CharsetInfo *info = cl->data; - EncodingData *edata; + const EncodingInfo *info = (EncodingInfo *) enc->data; - edata = g_new0 (EncodingData, 1); - edata->encoding = info->name; - edata->window = p->window; - - build_charset (p->action_group, xml, info, - charset_index, edata); - charset_index++; + build_encoding (wrhm, p->action_group, xml, info); } - g_list_foreach (charsets, (GFunc)g_free, NULL); - g_list_free (charsets); + g_list_foreach (encodings, (GFunc) encoding_info_free, NULL); + g_list_free (encodings); + g_string_append (xml, "</submenu>"); - group_index++; } + g_list_foreach (groups, (GFunc) language_group_info_free, NULL); + g_list_free (groups); + g_string_append (xml, "</submenu></placeholder></submenu></menu></Root>"); - egg_menu_merge_add_ui_from_string - (merge, xml->str, -1, NULL); + egg_menu_merge_add_ui_from_string (merge, xml->str, -1, NULL); g_string_free (xml, TRUE); } diff --git a/src/ephy-nautilus-view.c b/src/ephy-nautilus-view.c index f4373667b..9e977dd25 100644 --- a/src/ephy-nautilus-view.c +++ b/src/ephy-nautilus-view.c @@ -74,8 +74,8 @@ static void gnv_zoomable_zoom_to_fit_cb (BonoboZoomable *zoomable, static void gnv_zoomable_zoom_to_default_cb (BonoboZoomable *zoomable, EphyNautilusView *view); /* commands */ -static void gnv_cmd_set_charset (BonoboUIComponent *uic, - EncodingMenuData *data, +static void gnv_cmd_set_encoding (BonoboUIComponent *uic, + EphyNautilusView *view, const char* verbname); static void gnv_cmd_file_print (BonoboUIComponent *uic, EphyNautilusView *view, @@ -131,7 +131,7 @@ BonoboUIVerb ephy_verbs [] = { BONOBO_UI_VERB_END }; -#define CHARSET_MENU_PATH "/menu/View/Encoding" +#define ENCODING_MENU_PATH "/menu/View/Encoding" BONOBO_CLASS_BOILERPLATE (EphyNautilusView, ephy_nautilus_view, @@ -470,9 +470,9 @@ gnv_bonobo_control_activate_cb (BonoboControl *control, gboolean state, EphyNaut "nautilus-epiphany-view.xml", "EphyNautilusView"); g_return_if_fail (BONOBO_IS_UI_COMPONENT (p->ui)); - ephy_embed_utils_build_charsets_submenu (p->ui, - CHARSET_MENU_PATH, - (BonoboUIVerbFn) gnv_cmd_set_charset, + ephy_embed_utils_build_encodings_submenu (p->ui, + ENCODING_MENU_PATH, + (BonoboUIVerbFn) gnv_cmd_set_encoding, view); bonobo_ui_component_add_verb_list_with_data (p->ui, ephy_verbs, view); @@ -544,19 +544,22 @@ gnv_popup_cmd_frame_in_new_window (BonoboUIComponent *uic, } void -gnv_cmd_set_charset (BonoboUIComponent *uic, - EncodingMenuData *data, - const char* verbname) +gnv_cmd_set_encoding (BonoboUIComponent *uic, + EphyNautilusView *view, + const char* verbname) { - EphyNautilusView *view = data->data; - EphyNautilusViewPrivate *p; + const char *encoding; g_return_if_fail (EPHY_IS_NAUTILUS_VIEW (view)); - p = view->priv; - - LOG ("Set charset %s", data->encoding) - ephy_embed_set_charset (p->embed, data->encoding); + if (strncmp (verbname, "Encoding", 8) == 0) + { + encoding = verbname + 8; + + LOG ("Set encoding %s", encoding) + + ephy_embed_set_encoding (view->priv->embed, encoding); + } } static void diff --git a/src/ephy-window.h b/src/ephy-window.h index 39b051f0d..839c7f569 100644 --- a/src/ephy-window.h +++ b/src/ephy-window.h @@ -65,7 +65,7 @@ typedef enum NavControl, FindControl, ZoomControl, - CharsetsControl, + EncodingsControl, TitleControl, LocationControl, FaviconControl, diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c index 8e7793d16..1f4bf8485 100644 --- a/src/prefs-dialog.c +++ b/src/prefs-dialog.c @@ -24,6 +24,7 @@ #include "ephy-dialog.h" #include "ephy-prefs.h" #include "ephy-embed-prefs.h" +#include "ephy-embed-single.h" #include "ephy-shell.h" #include "ephy-gui.h" #include "eel-gconf-extensions.h" @@ -176,8 +177,8 @@ enum /* General */ OPEN_IN_TABS_PROP, HOMEPAGE_ENTRY_PROP, - AUTOCHARSET_PROP, - DEFAULT_CHARSET_PROP, + AUTO_ENCODING_PROP, + DEFAULT_ENCODING_PROP, LANGUAGE_PROP, /* Appeareance */ @@ -212,8 +213,8 @@ EphyDialogProperty properties [] = /* General */ { OPEN_IN_TABS_PROP, "open_in_tabs_checkbutton", CONF_TABS_TABBED, PT_AUTOAPPLY, NULL }, { HOMEPAGE_ENTRY_PROP, "homepage_entry", CONF_GENERAL_HOMEPAGE, PT_AUTOAPPLY, NULL }, - { AUTOCHARSET_PROP, "autocharset_optionmenu", CONF_LANGUAGE_AUTODETECT_CHARSET, PT_AUTOAPPLY, NULL }, - { DEFAULT_CHARSET_PROP, "default_charset_optionmenu", NULL, PT_NORMAL, NULL }, + { AUTO_ENCODING_PROP, "auto_encoding_optionmenu", CONF_LANGUAGE_AUTODETECT_ENCODING, PT_AUTOAPPLY, NULL }, + { DEFAULT_ENCODING_PROP, "default_encoding_optionmenu", NULL, PT_NORMAL, NULL }, { LANGUAGE_PROP, "language_optionmenu", NULL, PT_NORMAL, NULL }, /* Appeareance */ @@ -254,6 +255,7 @@ struct PrefsDialogPrivate GtkWidget *window; GList *langs; + GList *encodings; int language; gboolean switching; @@ -338,6 +340,9 @@ prefs_dialog_finalize (GObject *object) g_list_foreach (pd->priv->langs, (GFunc) free_lang_item, NULL); g_list_free (pd->priv->langs); + g_list_foreach (pd->priv->encodings, (GFunc) encoding_info_free, NULL); + g_list_free (pd->priv->encodings); + g_free (pd->priv); G_OBJECT_CLASS (parent_class)->finalize (object); @@ -584,87 +589,72 @@ setup_fonts (PrefsDialog *dialog) } static void -default_charset_menu_changed_cb (GtkOptionMenu *option_menu, - EphyEmbedShell *shell) +default_encoding_menu_changed_cb (GtkOptionMenu *option_menu, + PrefsDialog *dialog) { - GList *charsets; - int i; - CharsetInfo *info; - EphyEmbedSingle *single; - - single = ephy_embed_shell_get_embed_single - (EPHY_EMBED_SHELL (ephy_shell)); - - ephy_embed_single_get_charset_titles (single, NULL, &charsets); + GList *encoding; + gint i; + EncodingInfo *info; i = gtk_option_menu_get_history (option_menu); - charsets = g_list_nth (charsets, i); - g_assert (charsets != NULL); - info = (CharsetInfo *) charsets->data; - eel_gconf_set_string (CONF_LANGUAGE_DEFAULT_CHARSET, - info->name); + encoding = g_list_nth (dialog->priv->encodings, i); + g_assert (encoding != NULL); - g_list_free (charsets); + info = (EncodingInfo *) encoding->data; + eel_gconf_set_string (CONF_LANGUAGE_DEFAULT_ENCODING, info->encoding); } static gint -find_charset_in_list_cmp (gconstpointer a, - gconstpointer b) +find_encoding_in_list_cmp (const EncodingInfo *info, const gchar *encoding) { - CharsetInfo *info = (CharsetInfo *)a; - const char *value = b; - - return (strcmp (info->name, value)); + return strcmp (info->encoding, encoding); } static void -create_default_charset_menu (PrefsDialog *dialog) +create_default_encoding_menu (PrefsDialog *dialog) { GList *l; - GList *charsets; - GtkWidget *menu; - GtkWidget *optionmenu; - char *value; + GtkWidget *menu, *optionmenu; + gchar *encoding; EphyEmbedSingle *single; single = ephy_embed_shell_get_embed_single (EPHY_EMBED_SHELL (ephy_shell)); - ephy_embed_single_get_charset_titles (single, NULL, &l); + ephy_embed_single_get_encodings (single, LG_ALL, TRUE, + &dialog->priv->encodings); menu = gtk_menu_new (); optionmenu = ephy_dialog_get_control (EPHY_DIALOG (dialog), - DEFAULT_CHARSET_PROP); + DEFAULT_ENCODING_PROP); - for (charsets = l; charsets != NULL; charsets = charsets->next) + for (l = dialog->priv->encodings; l != NULL; l = l->next) { - CharsetInfo *info = (CharsetInfo *) charsets->data; + EncodingInfo *info = (EncodingInfo *) l->data; GtkWidget *item; - item = gtk_menu_item_new_with_label (_(info->title)); - gtk_menu_shell_append (GTK_MENU_SHELL(menu), - item); + item = gtk_menu_item_new_with_label (info->title); + gtk_menu_shell_append (GTK_MENU_SHELL(menu), item); gtk_widget_show (item); } gtk_option_menu_set_menu (GTK_OPTION_MENU(optionmenu), menu); /* init value */ - charsets = l; - value = eel_gconf_get_string (CONF_LANGUAGE_DEFAULT_CHARSET); - g_return_if_fail (value != NULL); - charsets = g_list_find_custom (charsets, (gconstpointer)value, - (GCompareFunc)find_charset_in_list_cmp); + encoding = eel_gconf_get_string (CONF_LANGUAGE_DEFAULT_ENCODING); + /* fallback */ + if (encoding == NULL) encoding = g_strdup ("ISO-8859-1"); + + l = g_list_find_custom (dialog->priv->encodings, encoding, + (GCompareFunc) find_encoding_in_list_cmp); gtk_option_menu_set_history (GTK_OPTION_MENU(optionmenu), - g_list_position (l, charsets)); - g_free (value); + g_list_position (dialog->priv->encodings, l)); + g_free (encoding); g_signal_connect (optionmenu, "changed", - G_CALLBACK (default_charset_menu_changed_cb), - embed_shell); - - g_list_free (l); + G_CALLBACK (default_encoding_menu_changed_cb), + dialog); } static gint @@ -858,6 +848,7 @@ prefs_dialog_init (PrefsDialog *pd) pd->priv->window = ephy_dialog_get_control (dialog, WINDOW_PROP); pd->priv->notebook = ephy_dialog_get_control (dialog, NOTEBOOK_PROP); pd->priv->langs = NULL; + pd->priv->encodings = NULL; icon = gtk_widget_render_icon (pd->priv->window, GTK_STOCK_PREFERENCES, @@ -872,7 +863,7 @@ prefs_dialog_init (PrefsDialog *pd) attach_fonts_signals (pd); attach_size_controls_signals (pd); create_languages_list (pd); - create_default_charset_menu (pd); + create_default_encoding_menu (pd); create_language_menu (pd); } |