diff options
Diffstat (limited to 'src')
-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 |
5 files changed, 123 insertions, 129 deletions
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); } |