diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2003-10-18 06:40:17 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2003-10-18 06:40:17 +0800 |
commit | 0e078cd9825b89e128d0501d4a7b5885670c2347 (patch) | |
tree | 932814c057bd8d2c6cdee449dc6b267091cef6c5 /src/prefs-dialog.c | |
parent | 4d9d732ba340aae6430bd687f0cf3252bff2217d (diff) | |
download | gsoc2013-epiphany-0e078cd9825b89e128d0501d4a7b5885670c2347.tar gsoc2013-epiphany-0e078cd9825b89e128d0501d4a7b5885670c2347.tar.gz gsoc2013-epiphany-0e078cd9825b89e128d0501d4a7b5885670c2347.tar.bz2 gsoc2013-epiphany-0e078cd9825b89e128d0501d4a7b5885670c2347.tar.lz gsoc2013-epiphany-0e078cd9825b89e128d0501d4a7b5885670c2347.tar.xz gsoc2013-epiphany-0e078cd9825b89e128d0501d4a7b5885670c2347.tar.zst gsoc2013-epiphany-0e078cd9825b89e128d0501d4a7b5885670c2347.zip |
Encoding menu improvements, Part 4: The Rewrite.
2003-10-18 Christian Persch <chpe@cvs.gnome.org>
Encoding menu improvements, Part 4:
The Rewrite.
* data/glade/epiphany.glade:
* data/ui/epiphany-ui.xml:
* data/ui/nautilus-epiphany-view.xml.in:
* embed/Makefile.am:
* embed/ephy-embed-shell.c: (ephy_embed_shell_init),
(ephy_embed_shell_finalize), (ephy_embed_shell_new),
(ephy_embed_shell_get_encodings):
* embed/ephy-embed-shell.h:
* embed/ephy-embed-utils.c: (ephy_embed_utils_save):
* embed/ephy-embed-utils.h:
* embed/ephy-embed.c: (ephy_embed_get_encoding_info):
* embed/ephy-embed.h:
* embed/ephy-encodings.c: (ephy_encodings_get_type),
(ephy_encodings_finalize), (ephy_encodings_class_init),
(ephy_encodings_get_node), (ephy_encodings_get_encodings),
(ephy_encodings_get_detectors), (ephy_encodings_get_all),
(ephy_encodings_get_categories), (ephy_encodings_add_recent),
(ephy_encodings_get_recent), (ephy_encodings_init),
(ephy_encoding_info_free), (ephy_encodings_new):
* embed/ephy-encodings.h:
* embed/mozilla/EphyWrapper.cpp:
* embed/mozilla/EphyWrapper.h:
* embed/mozilla/Makefile.am:
* embed/mozilla/mozilla-embed.cpp:
* embed/mozilla/mozilla-notifiers.cpp:
* lib/Makefile.am:
* lib/ephy-encodings.c:
* lib/ephy-encodings.h:
* lib/ephy-langs.c: (ephy_font_languages), (ephy_font_n_languages):
* lib/ephy-langs.h:
* src/Makefile.am:
* src/ephy-encoding-dialog.c: (ephy_encoding_dialog_get_type),
(setup_filter), (sync_embed_cb), (sync_active_tab),
(ephy_encoding_dialog_set_window), (activate_choice),
(activate_automatic), (ephy_encoding_dialog_response_cb),
(category_node_selected_cb), (view_node_selected_cb),
(view_node_activated_cb), (ephy_encoding_dialog_init),
(ephy_encoding_dialog_finalize),
(ephy_encoding_dialog_set_property),
(ephy_encoding_dialog_get_property),
(ephy_encoding_dialog_class_init), (ephy_encoding_dialog_new):
* src/ephy-encoding-dialog.h:
* src/ephy-encoding-menu.c: (ephy_encoding_menu_init),
(sort_encodings), (add_menu_item), (update_encoding_menu_cb),
(encoding_activate_cb), (add_action),
(ephy_encoding_menu_view_dialog_cb),
(ephy_encoding_menu_automatic_cb), (ephy_encoding_menu_set_window),
(ephy_encoding_menu_finalize), (ephy_encoding_menu_class_init),
(ephy_encoding_menu_new):
* src/ephy-nautilus-view.c: (gnv_bonobo_control_activate_cb),
(gnv_cmd_select_encoding), (gnv_cmd_edit_find):
* src/ephy-window.c: (ephy_window_set_active_tab),
(setup_notebook), (ephy_window_set_property),
(ephy_window_get_property), (ephy_window_class_init):
* src/language-editor.h:
* src/pdm-dialog.c: (setup_passwords_treeview),
(setup_cookies_treeview):
* src/prefs-dialog.c: (prefs_dialog_finalize),
(get_current_language_code), (fonts_language_info_cmp),
(create_fonts_language_menu), (find_encoding_in_list_cmp),
(sort_encodings), (create_optionmenu), (prefs_dialog_init):
Made encodings menu dynamic, containing recently used items + items
related to the currently active encoding. Split encodings out as a
embed shell service, port all users over to that. Harvest all encoding
info we can get from mozilla.
Diffstat (limited to 'src/prefs-dialog.c')
-rw-r--r-- | src/prefs-dialog.c | 282 |
1 files changed, 114 insertions, 168 deletions
diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c index 1b0999956..0b297374f 100644 --- a/src/prefs-dialog.c +++ b/src/prefs-dialog.c @@ -25,6 +25,8 @@ #include "prefs-dialog.h" #include "ephy-dialog.h" #include "ephy-prefs.h" +#include "ephy-embed-shell.h" +#include "ephy-shell.h" #include "ephy-embed-prefs.h" #include "ephy-embed-single.h" #include "ephy-shell.h" @@ -33,6 +35,7 @@ #include "language-editor.h" #include "ephy-langs.h" #include "ephy-encodings.h" +#include "ephy-debug.h" #include <bonobo/bonobo-i18n.h> #include <gtk/gtkframe.h> @@ -148,27 +151,6 @@ languages [] = }; static guint n_languages = G_N_ELEMENTS (languages); -typedef struct -{ - gchar *title; - gchar *name; -} EncodingAutodetectorInfo; - -static EncodingAutodetectorInfo encoding_autodetector[] = -{ - { N_("Off"), "" }, - { N_("Chinese"), "zh_parallel_state_machine" }, - { N_("East Asian"), "cjk_parallel_state_machine" }, - { N_("Japanese"), "ja_parallel_state_machine" }, - { N_("Korean"), "ko_parallel_state_machine" }, - { N_("Russian"), "ruprob" }, - { N_("Simplified Chinese"), "zhcn_parallel_state_machine" }, - { N_("Traditional Chinese"), "zhtw_parallel_state_machine" }, - { N_("Universal"), "universal_charset_detector" }, - { N_("Ukrainian"), "ukprob" } -}; -static guint n_encoding_autodetectors = G_N_ELEMENTS (encoding_autodetector); - static const char *cookies_accept_enum [] = { @@ -267,8 +249,8 @@ EphyDialogProperty properties [] = { DISK_CACHE_PROP, "disk_cache_spin", CONF_NETWORK_CACHE_SIZE, PT_AUTOAPPLY, NULL }, /* Languages */ - { AUTO_ENCODING_PROP, "auto_encoding_optionmenu", NULL, PT_NORMAL, NULL }, - { DEFAULT_ENCODING_PROP, "default_encoding_optionmenu", NULL, PT_NORMAL, NULL }, + { AUTO_ENCODING_PROP, "auto_encoding_optionmenu", CONF_LANGUAGE_AUTODETECT_ENCODING, PT_AUTOAPPLY, NULL }, + { DEFAULT_ENCODING_PROP, "default_encoding_optionmenu", CONF_LANGUAGE_DEFAULT_ENCODING, PT_AUTOAPPLY, NULL }, { LANGUAGE_PROP, "language_optionmenu", NULL, PT_NORMAL, NULL }, { LANGUAGE_LABEL_PROP, "language_label", NULL, PT_NORMAL, NULL }, { DEFAULT_ENCODING_LABEL_PROP, "default_encoding_label", NULL, PT_NORMAL, NULL }, @@ -301,8 +283,6 @@ struct PrefsDialogPrivate GtkWidget *window; GList *langs; - GList *encodings; - GList *autodetectors; GList *fonts_languages; guint language; @@ -383,12 +363,6 @@ 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) ephy_encoding_info_free, NULL); - g_list_free (pd->priv->encodings); - - g_list_foreach (pd->priv->autodetectors, (GFunc) g_free, NULL); - g_list_free (pd->priv->autodetectors); - g_list_foreach (pd->priv->fonts_languages, (GFunc) g_free, NULL); g_list_free (pd->priv->fonts_languages); @@ -415,15 +389,15 @@ prefs_dialog_show_help (PrefsDialog *pd) ephy_gui_help (GTK_WINDOW (pd->priv->window), "epiphany", help_preferences[id]); } -static const gchar * +static const char * get_current_language_code (PrefsDialog *dialog) { GList *lang; - const FontsLanguageInfo *info; + const EphyFontsLanguageInfo *info; lang = g_list_nth (dialog->priv->fonts_languages, dialog->priv->language); g_assert (lang != NULL); - info = (FontsLanguageInfo *) lang->data; + info = (EphyFontsLanguageInfo *) lang->data; return info->code; } @@ -648,24 +622,47 @@ setup_fonts (PrefsDialog *dialog) dialog->priv->switching = FALSE; } +static int +fonts_language_info_cmp (const EphyFontsLanguageInfo *i1, + const EphyFontsLanguageInfo *i2) +{ + return g_utf8_collate (i1->title, i2->title); +} + static void create_fonts_language_menu (PrefsDialog *dialog) { GtkWidget *optionmenu, *menu; - GList *l = NULL; - guint n_fonts_languages, i = 0; + GList *list = NULL, *l; + guint n_fonts_languages, i; char **lang_codes; + const EphyFontsLanguageInfo *fonts_languages; optionmenu = ephy_dialog_get_control (EPHY_DIALOG (dialog), FONTS_LANGUAGE_PROP); menu = gtk_menu_new (); - dialog->priv->fonts_languages = ephy_font_langs_get_list (); - n_fonts_languages = g_list_length (dialog->priv->fonts_languages); + fonts_languages = ephy_font_languages (); + n_fonts_languages = ephy_font_n_languages (); + + for (i = 0; i < n_fonts_languages; i++) + { + EphyFontsLanguageInfo *info; + + info = g_new0 (EphyFontsLanguageInfo, 1); + info->title = _(fonts_languages[i].title); + info->code = fonts_languages[i].code; + + list = g_list_prepend (list, info); + } + + dialog->priv->fonts_languages = + g_list_sort (list, (GCompareFunc) fonts_language_info_cmp); + for (l = dialog->priv->fonts_languages; l != NULL; l = l->next) { - FontsLanguageInfo *info = (FontsLanguageInfo *) l->data; + EphyFontsLanguageInfo *info = (EphyFontsLanguageInfo *) l->data; GtkWidget *item; item = gtk_menu_item_new_with_label (info->title); @@ -676,12 +673,12 @@ create_fonts_language_menu (PrefsDialog *dialog) gtk_option_menu_set_menu (GTK_OPTION_MENU(optionmenu), menu); lang_codes = g_new0 (char *, n_fonts_languages); - for (l = dialog->priv->fonts_languages; l != NULL; l = l->next) + for (l = dialog->priv->fonts_languages, i=0; l != NULL; l = l->next) { - FontsLanguageInfo *info = (FontsLanguageInfo *) l->data; + EphyFontsLanguageInfo *info = (EphyFontsLanguageInfo *) l->data; lang_codes[i] = info->code; - + i++; } ephy_dialog_add_enum (EPHY_DIALOG (dialog), FONTS_LANGUAGE_PROP, @@ -697,160 +694,97 @@ create_fonts_language_menu (PrefsDialog *dialog) dialog); } -static void -default_encoding_menu_changed_cb (GtkOptionMenu *option_menu, - PrefsDialog *dialog) +static int +find_encoding_in_list_cmp (gconstpointer info, const char *encoding) { - GList *encoding; - gint i; - const EphyEncodingInfo *info; + EphyNode *node = (EphyNode *) info; + const char *code; - i = gtk_option_menu_get_history (option_menu); - encoding = g_list_nth (dialog->priv->encodings, i); - g_assert (encoding != NULL); + code = ephy_node_get_property_string + (node, EPHY_NODE_ENCODING_PROP_ENCODING); - info = (EphyEncodingInfo *) encoding->data; - eel_gconf_set_string (CONF_LANGUAGE_DEFAULT_ENCODING, info->encoding); + return strcmp (code, encoding); } -static gint -find_encoding_in_list_cmp (const EphyEncodingInfo *info, const char *encoding) +static int +sort_encodings (gconstpointer a, gconstpointer b) { - return strcmp (info->encoding, encoding); + EphyNode *node1 = (EphyNode *) a; + EphyNode *node2 = (EphyNode *) b; + const char *key1, *key2; + + key1 = ephy_node_get_property_string + (node1, EPHY_NODE_ENCODING_PROP_COLLATION_KEY); + key2 = ephy_node_get_property_string + (node2, EPHY_NODE_ENCODING_PROP_COLLATION_KEY); + + return strcmp (key1, key2); } static void -create_default_encoding_menu (PrefsDialog *dialog) +create_optionmenu (PrefsDialog *dialog, + int property, + GList *list, + const char *key, + const char *default_value) { - GList *l; + GList *element, *l; GtkWidget *menu, *optionmenu; - gchar *encoding; + char *value; + char **codes; + guint pos, i, num; menu = gtk_menu_new (); optionmenu = ephy_dialog_get_control (EPHY_DIALOG (dialog), - DEFAULT_ENCODING_PROP); - - dialog->priv->encodings = ephy_encodings_get_list (LG_ALL, TRUE); - for (l = dialog->priv->encodings; l != NULL; l = l->next) - { - const EphyEncodingInfo *info = (EphyEncodingInfo *) l->data; - GtkWidget *item; - - item = gtk_menu_item_new_with_label (info->title); - gtk_menu_shell_append (GTK_MENU_SHELL(menu), item); - gtk_widget_show (item); - } + property); - gtk_option_menu_set_menu (GTK_OPTION_MENU(optionmenu), menu); + list = g_list_sort (list, (GCompareFunc) sort_encodings); - /* init value */ - encoding = eel_gconf_get_string (CONF_LANGUAGE_DEFAULT_ENCODING); - /* fallback */ - if (encoding == NULL) encoding = g_strdup ("ISO-8859-1"); + num = g_list_length (list); + codes = g_new0 (char *, num); - 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 (dialog->priv->encodings, l)); - g_free (encoding); - - g_signal_connect (optionmenu, "changed", - G_CALLBACK (default_encoding_menu_changed_cb), - dialog); -} - -static void -autodetect_encoding_menu_changed_cb (GtkOptionMenu *option_menu, gpointer data) -{ - GList *l; - guint i; - EncodingAutodetectorInfo *info; - - g_return_if_fail (EPHY_IS_PREFS_DIALOG (data)); - - i = gtk_option_menu_get_history (option_menu); - - l = g_list_nth (EPHY_PREFS_DIALOG (data)->priv->autodetectors, i); - - if (l) - { - info = (EncodingAutodetectorInfo *) l->data; - - eel_gconf_set_string (CONF_LANGUAGE_AUTODETECT_ENCODING, info->name); - } -} - -static gint -autodetector_info_cmp (const EncodingAutodetectorInfo *i1, const EncodingAutodetectorInfo *i2) -{ - return g_utf8_collate (i1->title, i2->title); -} - -static gint -find_autodetector_info (const EncodingAutodetectorInfo *info, const gchar *name) -{ - return strcmp (info->name, name); -} - -static void -create_encoding_autodetectors_menu (PrefsDialog *dialog) -{ - GtkWidget *optionmenu, *menu, *item; - gint i, position = 0; - GList *l, *list = NULL; - gchar *detector = NULL; - EncodingAutodetectorInfo *info; - - optionmenu = ephy_dialog_get_control (EPHY_DIALOG (dialog), - AUTO_ENCODING_PROP); - - for (i = 0; i < n_encoding_autodetectors; i++) + for (l = list, i=0; l != NULL; l = l->next, i++) { - info = g_new0 (EncodingAutodetectorInfo, 1); - - info->title = _(encoding_autodetector[i].title); - info->name = encoding_autodetector[i].name; - - list = g_list_prepend (list, info); - } - - list = g_list_sort (list, (GCompareFunc) autodetector_info_cmp); - dialog->priv->autodetectors = list; - - menu = gtk_menu_new (); + EphyNode *node = (EphyNode *) l->data; + const char *title, *code; + GtkWidget *item; - for (l = list; l != NULL; l = l->next) - { - info = (EncodingAutodetectorInfo *) l->data; + title = ephy_node_get_property_string + (node, EPHY_NODE_ENCODING_PROP_TITLE_ELIDED); - item = gtk_menu_item_new_with_label (info->title); + item = gtk_menu_item_new_with_label (title); gtk_menu_shell_append (GTK_MENU_SHELL(menu), item); gtk_widget_show (item); - g_object_set_data (G_OBJECT (item), "desc", info->title); + + code = ephy_node_get_property_string + (node, EPHY_NODE_ENCODING_PROP_ENCODING); + codes[i] = (char *) code; } gtk_option_menu_set_menu (GTK_OPTION_MENU (optionmenu), menu); /* init value */ - detector = eel_gconf_get_string (CONF_LANGUAGE_AUTODETECT_ENCODING); - if (detector == NULL) detector = g_strdup (""); - - l = g_list_find_custom (list, detector, - (GCompareFunc) find_autodetector_info); - - g_free (detector); - - if (l) + value = eel_gconf_get_string (key); + /* fallback */ + if (value == NULL || value[0] == '\0') { - position = g_list_position (list, l); + g_free (value); + value = g_strdup (default_value); } - gtk_option_menu_set_history (GTK_OPTION_MENU(optionmenu), position); + element = g_list_find_custom (list, value, + (GCompareFunc) find_encoding_in_list_cmp); + g_free (value); + pos = g_list_position (list, element); - g_signal_connect (optionmenu, "changed", - G_CALLBACK (autodetect_encoding_menu_changed_cb), - dialog); + ephy_dialog_add_enum (EPHY_DIALOG (dialog), property, + num, (const char **) codes); + + gtk_option_menu_set_history (GTK_OPTION_MENU(optionmenu), pos); + + /* the entries themselves are const, so we don't use g_strfreev here */ + g_free (codes); } static gint @@ -1033,7 +967,9 @@ static void prefs_dialog_init (PrefsDialog *pd) { EphyDialog *dialog = EPHY_DIALOG (pd); + EphyEncodings *encodings; GdkPixbuf *icon; + GList *list; pd->priv = EPHY_PREFS_DIALOG_GET_PRIVATE (pd); @@ -1051,8 +987,6 @@ 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; - pd->priv->autodetectors = NULL; pd->priv->fonts_languages = NULL; icon = gtk_widget_render_icon (pd->priv->window, @@ -1067,8 +1001,20 @@ prefs_dialog_init (PrefsDialog *pd) attach_fonts_signals (pd); attach_size_controls_signals (pd); create_languages_list (pd); - create_default_encoding_menu (pd); - create_encoding_autodetectors_menu (pd); + + encodings = EPHY_ENCODINGS (ephy_embed_shell_get_encodings + (EPHY_EMBED_SHELL (ephy_shell))); + + list = ephy_encodings_get_encodings (encodings, LG_ALL); + create_optionmenu (pd, DEFAULT_ENCODING_PROP, list, + CONF_LANGUAGE_DEFAULT_ENCODING, "ISO-8859-1"); + g_list_free (list); + + list = ephy_encodings_get_detectors (encodings); + create_optionmenu (pd, AUTO_ENCODING_PROP, list, + CONF_LANGUAGE_AUTODETECT_ENCODING, ""); + g_list_free (list); + create_language_menu (pd); } |