diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2004-01-06 22:36:23 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2004-01-06 22:36:23 +0800 |
commit | fe2f4ed250c08dc3a4f7b2816fcf6894f446f1ee (patch) | |
tree | f6381d82b2f5f2736ecba8e5c0e8c4d8757b0c01 | |
parent | 1158a826cc4f3b9d71745bff312f25e0122ec445 (diff) | |
download | gsoc2013-epiphany-fe2f4ed250c08dc3a4f7b2816fcf6894f446f1ee.tar gsoc2013-epiphany-fe2f4ed250c08dc3a4f7b2816fcf6894f446f1ee.tar.gz gsoc2013-epiphany-fe2f4ed250c08dc3a4f7b2816fcf6894f446f1ee.tar.bz2 gsoc2013-epiphany-fe2f4ed250c08dc3a4f7b2816fcf6894f446f1ee.tar.lz gsoc2013-epiphany-fe2f4ed250c08dc3a4f7b2816fcf6894f446f1ee.tar.xz gsoc2013-epiphany-fe2f4ed250c08dc3a4f7b2816fcf6894f446f1ee.tar.zst gsoc2013-epiphany-fe2f4ed250c08dc3a4f7b2816fcf6894f446f1ee.zip |
Behave better when the encoding used on the page is unknown to us.
2004-01-06 Christian Persch <chpe@cvs.gnome.org>
* embed/ephy-encodings.c: (add_encoding),
(ephy_encodings_get_node), (ephy_encodings_add_recent),
(ephy_encodings_get_recent), (ephy_encodings_init):
* embed/ephy-encodings.h:
* src/ephy-encoding-dialog.c: (sync_embed_cb):
* src/ephy-encoding-menu.c: (update_encoding_menu_cb),
(add_action), (ephy_encoding_menu_set_window):
* src/prefs-dialog.c: (create_node_combo):
Behave better when the encoding used on the page is unknown to us.
Previously we skipped important steps in menu building, resulting in
incorrect encoding indicator. Now, we dynamically add an entry with
name "Unknown" to our menu.
Also add back some rarely used encodings (us-ascii, UTF-16*, UTF-32*)
to our known encodings repertoire.
-rw-r--r-- | ChangeLog | 19 | ||||
-rw-r--r-- | embed/ephy-encodings.c | 159 | ||||
-rw-r--r-- | embed/ephy-encodings.h | 3 | ||||
-rw-r--r-- | src/ephy-encoding-dialog.c | 4 | ||||
-rw-r--r-- | src/ephy-encoding-menu.c | 40 | ||||
-rw-r--r-- | src/prefs-dialog.c | 2 |
6 files changed, 154 insertions, 73 deletions
@@ -1,5 +1,24 @@ 2004-01-06 Christian Persch <chpe@cvs.gnome.org> + * embed/ephy-encodings.c: (add_encoding), + (ephy_encodings_get_node), (ephy_encodings_add_recent), + (ephy_encodings_get_recent), (ephy_encodings_init): + * embed/ephy-encodings.h: + * src/ephy-encoding-dialog.c: (sync_embed_cb): + * src/ephy-encoding-menu.c: (update_encoding_menu_cb), + (add_action), (ephy_encoding_menu_set_window): + * src/prefs-dialog.c: (create_node_combo): + + Behave better when the encoding used on the page is unknown to us. + Previously we skipped important steps in menu building, resulting in + incorrect encoding indicator. Now, we dynamically add an entry with + name "Unknown" to our menu. + + Also add back some rarely used encodings (us-ascii, UTF-16*, UTF-32*) + to our known encodings repertoire. + +2004-01-06 Christian Persch <chpe@cvs.gnome.org> + * src/ephy-encoding-menu.c: (update_encoding_menu_cb): Always set the "automatic" toggle button correctly, even if the encoding diff --git a/embed/ephy-encodings.c b/embed/ephy-encodings.c index 2500c78b8..7af9877ee 100644 --- a/embed/ephy-encodings.c +++ b/embed/ephy-encodings.c @@ -137,6 +137,15 @@ encoding_entries [] = { N_("Western (_MacRoman)"), "x-mac-roman", LG_WESTERN, FALSE }, { N_("Western (_Windows-1252)"), "windows-1252", LG_WESTERN, FALSE }, + /* the following encodings are so rarely used that we don't want to pollute the "related" + * part of the encodings menu with them, so we set the language group to 0 here + */ + { N_("English (_US-ASCII)"), "us-ascii", 0, FALSE }, + { N_("Unicode (UTF-_16 BE)"), "UTF-16BE", 0, FALSE }, + { N_("Unicode (UTF-1_6 LE)"), "UTF-16LE", 0, FALSE}, + { N_("Unicode (UTF-_32 BE)"), "UTF-32BE", 0, FALSE }, + { N_("Unicode (UTF-3_2 LE)"), "UTF-32LE", 0, FALSE }, + { N_("Off"), "", LG_NONE, TRUE }, { N_("Chinese"), "zh_parallel_state_machine", LG_CHINESE_TRAD | LG_CHINESE_SIMP, TRUE }, { N_("Chinese Simplified"), "zhcn_parallel_state_machine", LG_CHINESE_SIMP, TRUE }, @@ -226,13 +235,92 @@ ephy_encodings_class_init (EphyEncodingsClass *klass) g_type_class_add_private (object_class, sizeof (EphyEncodingsPrivate)); } +static EphyNode * +add_encoding (EphyEncodings *encodings, + const char *title, + const char *code, + EphyLanguageGroup groups, + gboolean is_autodetector) +{ + EphyNode *node; + char *elided, *normalised; + GValue value = { 0, }; + + node = ephy_node_new (encodings->priv->db); + + g_value_init (&value, G_TYPE_STRING); + g_value_set_string (&value, title); + ephy_node_set_property (node, EPHY_NODE_ENCODING_PROP_TITLE, &value); + g_value_unset (&value); + + elided = ephy_string_elide_underscores (title); + normalised = g_utf8_normalize (elided, -1, G_NORMALIZE_DEFAULT); + + g_value_init (&value, G_TYPE_STRING); + g_value_take_string (&value, g_utf8_collate_key (normalised, -1)); + ephy_node_set_property (node, EPHY_NODE_ENCODING_PROP_COLLATION_KEY, &value); + g_value_unset (&value); + + g_free (normalised); + + g_value_init (&value, G_TYPE_STRING); + g_value_take_string (&value, elided); + ephy_node_set_property (node, EPHY_NODE_ENCODING_PROP_TITLE_ELIDED, &value); + g_value_unset (&value); + + g_value_init (&value, G_TYPE_STRING); + g_value_set_string (&value, code); + ephy_node_set_property (node, EPHY_NODE_ENCODING_PROP_ENCODING, &value); + g_value_unset (&value); + + g_value_init (&value, G_TYPE_INT); + g_value_set_int (&value, groups); + ephy_node_set_property (node, EPHY_NODE_ENCODING_PROP_LANGUAGE_GROUPS, &value); + g_value_unset (&value); + + g_value_init (&value, G_TYPE_BOOLEAN); + g_value_set_boolean (&value, is_autodetector); + ephy_node_set_property (node, EPHY_NODE_ENCODING_PROP_IS_AUTODETECTOR, &value); + g_value_unset (&value); + + /* now insert the node in our structure */ + ephy_node_add_child (encodings->priv->root, node); + g_hash_table_insert (encodings->priv->hash, g_strdup (code), node); + + if (is_autodetector) + { + ephy_node_add_child (encodings->priv->detectors, node); + } + else + { + ephy_node_add_child (encodings->priv->encodings, node); + } + + return node; +} + EphyNode * ephy_encodings_get_node (EphyEncodings *encodings, - const char *code) + const char *code, + gboolean add_if_not_found) { + EphyNode *node; + g_return_val_if_fail (EPHY_IS_ENCODINGS (encodings), NULL); - return g_hash_table_lookup (encodings->priv->hash, code); + node = g_hash_table_lookup (encodings->priv->hash, code); + + /* if it doesn't exist, add a node for it */ + if (!EPHY_IS_NODE (node) && add_if_not_found) + { + char *title; + + title = g_strdup_printf (_("Unknown (%s)"), code); + node = add_encoding (encodings, title, code, 0, FALSE); + g_free (title); + } + + return node; } GList * @@ -287,7 +375,8 @@ ephy_encodings_add_recent (EphyEncodings *encodings, g_return_if_fail (EPHY_IS_ENCODINGS (encodings)); g_return_if_fail (code != NULL); - g_return_if_fail (ephy_encodings_get_node (encodings, code) != NULL); + + if (ephy_encodings_get_node (encodings, code, FALSE) == NULL) return; /* keep the list elements unique */ element = g_slist_find_custom (encodings->priv->recent, code, @@ -328,7 +417,7 @@ ephy_encodings_get_recent (EphyEncodings *encodings) { EphyNode *node; - node = ephy_encodings_get_node (encodings, (char *) l->data); + node = ephy_encodings_get_node (encodings, (char *) l->data, FALSE); g_return_val_if_fail (EPHY_IS_NODE (node), NULL); list = g_list_prepend (list, node); @@ -351,7 +440,9 @@ ephy_encodings_init (EphyEncodings *encodings) db = ephy_node_db_new ("EncodingsDB"); encodings->priv->db = db; - encodings->priv->hash = g_hash_table_new (g_str_hash, g_str_equal); + encodings->priv->hash = g_hash_table_new_full (g_str_hash, g_str_equal, + (GDestroyNotify) g_free, + NULL); encodings->priv->root = ephy_node_new_with_id (db, ALL_NODE_ID); encodings->priv->encodings = ephy_node_new_with_id (db, ENCODINGS_NODE_ID); @@ -364,57 +455,11 @@ ephy_encodings_init (EphyEncodings *encodings) /* now fill the db */ for (i = 0; i < n_encoding_entries; i++) { - EphyNode *node; - char *elided, *normalised; - GValue value = { 0, }; - - node = ephy_node_new (db); - ephy_node_add_child (encodings->priv->root, node); - g_hash_table_insert (encodings->priv->hash, encoding_entries[i].code, node); - - if (encoding_entries[i].is_autodetector) - { - ephy_node_add_child (encodings->priv->detectors, node); - } - else - { - ephy_node_add_child (encodings->priv->encodings, node); - } - - g_value_init (&value, G_TYPE_STRING); - g_value_set_string (&value, _(encoding_entries[i].title)); - ephy_node_set_property (node, EPHY_NODE_ENCODING_PROP_TITLE, &value); - g_value_unset (&value); - - elided = ephy_string_elide_underscores (_(encoding_entries[i].title)); - normalised = g_utf8_normalize (elided, -1, G_NORMALIZE_DEFAULT); - - g_value_init (&value, G_TYPE_STRING); - g_value_take_string (&value, g_utf8_collate_key (normalised, -1)); - ephy_node_set_property (node, EPHY_NODE_ENCODING_PROP_COLLATION_KEY, &value); - g_value_unset (&value); - - g_free (normalised); - - g_value_init (&value, G_TYPE_STRING); - g_value_take_string (&value, elided); - ephy_node_set_property (node, EPHY_NODE_ENCODING_PROP_TITLE_ELIDED, &value); - g_value_unset (&value); - - g_value_init (&value, G_TYPE_STRING); - g_value_set_string (&value, encoding_entries[i].code); - ephy_node_set_property (node, EPHY_NODE_ENCODING_PROP_ENCODING, &value); - g_value_unset (&value); - - g_value_init (&value, G_TYPE_INT); - g_value_set_int (&value, encoding_entries[i].groups); - ephy_node_set_property (node, EPHY_NODE_ENCODING_PROP_LANGUAGE_GROUPS, &value); - g_value_unset (&value); - - g_value_init (&value, G_TYPE_BOOLEAN); - g_value_set_boolean (&value, encoding_entries[i].is_autodetector); - ephy_node_set_property (node, EPHY_NODE_ENCODING_PROP_IS_AUTODETECTOR, &value); - g_value_unset (&value); + add_encoding (encodings, + _(encoding_entries[i].title), + encoding_entries[i].code, + encoding_entries[i].groups, + encoding_entries[i].is_autodetector); } /* get the list of recently used encodings */ @@ -428,7 +473,7 @@ ephy_encodings_init (EphyEncodings *encodings) { if (g_slist_find (encodings->priv->recent, l->data) == NULL && g_slist_length (encodings->priv->recent) < RECENT_MAX - && ephy_encodings_get_node (encodings, l->data) != NULL) + && ephy_encodings_get_node (encodings, l->data, FALSE) != NULL) { encodings->priv->recent = g_slist_prepend (encodings->priv->recent, diff --git a/embed/ephy-encodings.h b/embed/ephy-encodings.h index 9a565344a..6ab26cfa4 100644 --- a/embed/ephy-encodings.h +++ b/embed/ephy-encodings.h @@ -130,7 +130,8 @@ GType ephy_encodings_get_type (void); EphyEncodings *ephy_encodings_new (void); EphyNode *ephy_encodings_get_node (EphyEncodings *encodings, - const char *code); + const char *code, + gboolean add_if_not_found); GList *ephy_encodings_get_encodings (EphyEncodings *encodings, EphyLanguageGroup group_mask); diff --git a/src/ephy-encoding-dialog.c b/src/ephy-encoding-dialog.c index e57ec558a..700f15c61 100644 --- a/src/ephy-encoding-dialog.c +++ b/src/ephy-encoding-dialog.c @@ -128,8 +128,8 @@ sync_embed_cb (EphyEncodingDialog *dialog, GParamSpec *pspec, gpointer dummy) info = ephy_embed_get_encoding_info (embed); if (info == NULL) return; - node = ephy_encodings_get_node (dialog->priv->encodings, info->encoding); - if (!EPHY_IS_NODE (node)) return; + node = ephy_encodings_get_node (dialog->priv->encodings, info->encoding, TRUE); + g_assert (EPHY_IS_NODE (node)); /* select the current encoding in the list view */ ephy_node_view_select_node (EPHY_NODE_VIEW (dialog->priv->enc_view), diff --git a/src/ephy-encoding-menu.c b/src/ephy-encoding-menu.c index ee42f692d..11c4d44aa 100644 --- a/src/ephy-encoding-menu.c +++ b/src/ephy-encoding-menu.c @@ -183,11 +183,8 @@ update_encoding_menu_cb (GtkAction *dummy, EphyEncodingMenu *menu) encoding = info->encoding; - enc_node = ephy_encodings_get_node (p->encodings, encoding); - if (!EPHY_IS_NODE (enc_node)) - { - goto build_menu; - } + enc_node = ephy_encodings_get_node (p->encodings, encoding, TRUE); + g_assert (EPHY_IS_NODE (enc_node)); /* set the encodings group's active member */ g_snprintf (name, sizeof (name), "Encoding%s", encoding); @@ -207,7 +204,7 @@ update_encoding_menu_cb (GtkAction *dummy, EphyEncodingMenu *menu) if (g_list_find (related, enc_node) == NULL && g_list_find (recent, enc_node) == NULL) { - recent = g_list_prepend (recent, enc_node); + related = g_list_prepend (related, enc_node); } /* make sure related and recent are disjoint so we don't display twice */ @@ -227,7 +224,6 @@ build_menu: gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), is_automatic); g_object_set (G_OBJECT (action), "sensitive", !is_automatic, NULL); - /* clear the menu */ if (p->merge_id > 0) { @@ -313,7 +309,7 @@ encoding_activate_cb (GtkAction *action, EphyEncodingMenu *menu) } static void -add_action (EphyNode *node, EphyEncodingMenu *menu) +add_action (EphyNode *encodings, EphyNode *node, EphyEncodingMenu *menu) { GtkAction *action; char name[128]; @@ -324,6 +320,8 @@ add_action (EphyNode *node, EphyEncodingMenu *menu) title = ephy_node_get_property_string (node, EPHY_NODE_ENCODING_PROP_TITLE); + LOG ("add_action for encoding '%s'", encoding) + g_snprintf (name, sizeof (name), "Encoding%s", encoding); action = g_object_new (GTK_TYPE_RADIO_ACTION, @@ -397,7 +395,9 @@ ephy_encoding_menu_set_window (EphyEncodingMenu *menu, EphyWindow *window) { GtkActionGroup *action_group; GtkAction *action; - GList *encodings; + EphyNode *encodings; + GPtrArray *children; + int i; g_return_if_fail (EPHY_IS_WINDOW (window)); @@ -413,9 +413,25 @@ ephy_encoding_menu_set_window (EphyEncodingMenu *menu, EphyWindow *window) gtk_action_group_add_toggle_actions (action_group, toggle_menu_entries, n_toggle_menu_entries, menu); - encodings = ephy_encodings_get_encodings (menu->priv->encodings, LG_ALL); - g_list_foreach (encodings, (GFunc) add_action, menu); - g_list_free (encodings); + /* add actions for the existing encodings */ + encodings = ephy_encodings_get_all (menu->priv->encodings); + children = ephy_node_get_children (encodings); + for (i = 0; i < children->len; i++) + { + EphyNode *encoding; + + encoding = (EphyNode *) g_ptr_array_index (children, i); + add_action (encodings, encoding, menu); + } + + /* when we encounter an unknown encoding, it is added to the database, + * so we need to listen to child_added on the encodings node to + * add an action for it + */ + ephy_node_signal_connect_object (encodings, + EPHY_NODE_CHILD_ADDED, + (EphyNodeCallback) add_action, + G_OBJECT (menu)); gtk_ui_manager_insert_action_group (menu->priv->manager, action_group, 0); diff --git a/src/prefs-dialog.c b/src/prefs-dialog.c index f0efa27b2..5046aa267 100644 --- a/src/prefs-dialog.c +++ b/src/prefs-dialog.c @@ -590,7 +590,7 @@ create_node_combo (EphyDialog *dialog, int title_col, data_col; code = eel_gconf_get_string (key); - if (code == NULL || ephy_encodings_get_node (encodings, code) == NULL) + if (code == NULL || ephy_encodings_get_node (encodings, code, FALSE) == NULL) { /* safe default */ eel_gconf_set_string (key, default_value); |