Commit 6279e8d7 authored by Ramiro Estrugo's avatar Ramiro Estrugo
Browse files

reviewed by: Maciej Stachowiak <mjs@eazel.com> (Post Mortem)

	Fix bug 6824 - Mozilla component charset encodings are not translated.

	* components/mozilla/Makefile.am:
	Add new encoding tables sources.  Add GNOMELOCALEDIR define to
	make gettext happy.
	* components/mozilla/main.c: (main):
	Add gettext binding setup.

	* components/mozilla/nautilus-mozilla-content-view.c:
	(mozilla_view_create_charset_encoding_submenu):
	Use the translated strings for menu labels.

	* components/mozilla/nautilus-mozilla-embed-extensions.h:
	* components/mozilla/nautilus-mozilla-embed-extensions.cpp:
	Simplified by using an stl vector instead of a GList.  Moved the
	encoding tables to their own place.   Added functions for
	obtaining the encoding titles and encoding groups as translated
	strings.

	* components/mozilla/nautilus-mozilla-encoding-tables.h:
	* components/mozilla/nautilus-mozilla-encoding-tables.c:
	Moved the encoding tables to their own place.
parent d620356b
2001-02-22 Ramiro Estrugo <ramiro@eazel.com>
reviewed by: Maciej Stachowiak <mjs@eazel.com> (Post Mortem)
Fix bug 6824 - Mozilla component charset encodings are not translated.
* components/mozilla/Makefile.am:
Add new encoding tables sources. Add GNOMELOCALEDIR define to
make gettext happy.
* components/mozilla/main.c: (main):
Add gettext binding setup.
* components/mozilla/nautilus-mozilla-content-view.c:
(mozilla_view_create_charset_encoding_submenu):
Use the translated strings for menu labels.
* components/mozilla/nautilus-mozilla-embed-extensions.h:
* components/mozilla/nautilus-mozilla-embed-extensions.cpp:
Simplified by using an stl vector instead of a GList. Moved the
encoding tables to their own place. Added functions for
obtaining the encoding titles and encoding groups as translated
strings.
* components/mozilla/nautilus-mozilla-encoding-tables.h:
* components/mozilla/nautilus-mozilla-encoding-tables.c:
Moved the encoding tables to their own place.
2001-02-22 Gene Z. Ragan <gzr@eazel.com>
reviewed by: Pavel Cisler <pavel@eazel.com>
......
include $(top_srcdir)/Makefile.shared
INCLUDES = \
-DGNOMELOCALEDIR=\""$(datadir)/locale"\" \
-DPREFIX=\"$(prefix)\" \
-DG_LOG_DOMAIN=\"Nautilus-Mozilla\" \
-DDATADIR=\"$(datadir)\" \
......@@ -21,22 +22,24 @@ bin_PROGRAMS =\
$(NULL)
nautilus_mozilla_content_view_SOURCES = \
bonobo-extensions.c \
main.c \
mozilla-components.cpp \
mozilla-events.cpp \
mozilla-preferences.cpp \
nautilus-mozilla-embed-extensions.cpp \
nautilus-mozilla-content-view.c \
bonobo-extensions.c \
nautilus-mozilla-embed-extensions.cpp \
nautilus-mozilla-encoding-tables.c \
$(NULL)
noinst_HEADERS =\
bonobo-extensions.h \
mozilla-components.h \
mozilla-events.h \
mozilla-preferences.h \
nautilus-mozilla-embed-extensions.h \
nautilus-mozilla-content-view.h \
bonobo-extensions.h \
nautilus-mozilla-embed-extensions.h \
nautilus-mozilla-encoding-tables.h \
$(NULL)
nautilus_mozilla_content_view_LDADD = \
......
......@@ -187,7 +187,13 @@ main (int argc, char *argv[])
mozilla_make_object,
NULL);
g_free (registration_id);
/* Initialize gettext support */
#ifdef ENABLE_NLS
bindtextdomain (PACKAGE, GNOMELOCALEDIR);
textdomain (PACKAGE);
#endif
gnome_vfs_init ();
#ifdef EAZEL_SERVICES
......
......@@ -533,34 +533,36 @@ encoding_menu_data_free_cover (gpointer callback_data)
g_free (data->encoding);
}
static void
mozilla_view_create_charset_encoding_submenu (NautilusMozillaContentView *mozilla_view)
{
GList *node = NULL;
GList *groups = NULL;
GList *node = NULL;
GList *groups = NULL;
guint num_encodings;
guint i;
guint menu_index = 0;
guint i;
guint menu_index = 0;
const GtkMozEmbed *mozilla;
g_return_if_fail (NAUTILUS_IS_MOZILLA_CONTENT_VIEW (mozilla_view));
g_return_if_fail (BONOBO_IS_UI_COMPONENT (mozilla_view->details->ui));
g_return_if_fail (GTK_IS_MOZ_EMBED (mozilla_view->details->mozilla));
mozilla = mozilla_view->details->mozilla;
num_encodings = mozilla_charset_get_num_encodings (mozilla_view->details->mozilla);
num_encodings = mozilla_charset_get_num_encodings (mozilla);
/* Collect the list of encoding groups */
for (i = 0; i < num_encodings; i++) {
char *encoding_title;
char *encoding_group;
encoding_title = mozilla_charset_get_nth_encoding_title (mozilla_view->details->mozilla, i);
encoding_group = mozilla_charset_find_encoding_group (mozilla_view->details->mozilla,
encoding_title = mozilla_charset_get_nth_encoding_title (mozilla, i);
encoding_group = mozilla_charset_find_encoding_group (mozilla,
encoding_title);
/* Add new encodings to the list only once */
if (encoding_group != NULL) {
if (!g_list_find_custom (groups, encoding_group, (GCompareFunc) g_strcasecmp)) {
if (!g_list_find_custom (groups, encoding_group, (GCompareFunc) strcoll)) {
groups = g_list_append (groups, encoding_group);
}
}
......@@ -571,28 +573,34 @@ mozilla_view_create_charset_encoding_submenu (NautilusMozillaContentView *mozill
/* Create the encoding group submenus */
node = groups;
while (node) {
char *translated_encoding_group;
char *encoding_group;
char *encoded_encoding_group;
char *escaped_encoding_group;
char *path;
g_assert (node->data != NULL);
encoding_group = node->data;
encoded_encoding_group = bonobo_ui_util_encode_str (encoding_group);
translated_encoding_group = mozilla_charset_encoding_group_get_translated (mozilla,
encoding_group);
g_assert (translated_encoding_group != NULL);
escaped_encoding_group = bonobo_ui_util_encode_str (encoding_group);
/* From now onwards we use the groups list to store indeces of items */
/* HACK: From now onwards we use the groups list to store indeces of items */
node->data = GINT_TO_POINTER (0);
nautilus_bonobo_add_submenu (mozilla_view->details->ui,
MENU_VIEW_CHARSET_ENCODING_PATH,
encoded_encoding_group);
path = g_strdup_printf ("%s/%s", MENU_VIEW_CHARSET_ENCODING_PATH, encoded_encoding_group);
escaped_encoding_group);
path = g_strdup_printf ("%s/%s", MENU_VIEW_CHARSET_ENCODING_PATH, escaped_encoding_group);
nautilus_bonobo_set_label (mozilla_view->details->ui,
path,
encoding_group);
translated_encoding_group);
g_free (path);
node = node->next;
g_free (translated_encoding_group);
g_free (escaped_encoding_group);
g_free (encoding_group);
g_free (encoded_encoding_group);
}
/* We start adding items to the root submenu right after the last encoding group submenu */
......@@ -605,6 +613,7 @@ mozilla_view_create_charset_encoding_submenu (NautilusMozillaContentView *mozill
for (i = 0; i < num_encodings; i++) {
char *encoding;
char *encoding_title;
char *translated_encoding_title;
char *encoding_group;
char *ui_path;
char *verb_name;
......@@ -612,19 +621,20 @@ mozilla_view_create_charset_encoding_submenu (NautilusMozillaContentView *mozill
char *new_item_path;
guint new_item_index;
encoding = mozilla_charset_get_nth_encoding (mozilla_view->details->mozilla, i);
encoding_title = mozilla_charset_get_nth_encoding_title (mozilla_view->details->mozilla, i);
encoding_group = mozilla_charset_find_encoding_group (mozilla_view->details->mozilla,
encoding = mozilla_charset_get_nth_encoding (mozilla, i);
encoding_title = mozilla_charset_get_nth_encoding_title (mozilla, i);
encoding_group = mozilla_charset_find_encoding_group (mozilla,
encoding_title);
translated_encoding_title = mozilla_charset_get_nth_translated_encoding_title (mozilla, i);
/* Add item to an existing encoding group submenu */
if (encoding_group != NULL) {
int enconding_group_index;
GList *nth_node;
char *encoded_encoding_group;
char *escaped_encoding_group;
enconding_group_index = mozilla_charset_get_encoding_group_index (mozilla_view->details->mozilla,
encoding_group);
enconding_group_index = mozilla_charset_get_encoding_group_index (mozilla,
encoding_group);
g_assert (enconding_group_index >= 0);
g_assert ((guint) enconding_group_index < g_list_length (groups));
......@@ -632,12 +642,13 @@ mozilla_view_create_charset_encoding_submenu (NautilusMozillaContentView *mozill
g_assert (nth_node != NULL);
encoded_encoding_group = bonobo_ui_util_encode_str (encoding_group);
escaped_encoding_group = bonobo_ui_util_encode_str (encoding_group);
new_item_path = g_strdup_printf ("%s/%s", MENU_VIEW_CHARSET_ENCODING_PATH, encoded_encoding_group);
new_item_path = g_strdup_printf ("%s/%s", MENU_VIEW_CHARSET_ENCODING_PATH,
escaped_encoding_group);
new_item_index = GPOINTER_TO_INT (nth_node->data);
g_free (encoded_encoding_group);
g_free (escaped_encoding_group);
/* Bump the child index */
nth_node->data = GINT_TO_POINTER (new_item_index + 1);
......@@ -651,7 +662,7 @@ mozilla_view_create_charset_encoding_submenu (NautilusMozillaContentView *mozill
nautilus_bonobo_add_numbered_menu_item (mozilla_view->details->ui,
new_item_path,
new_item_index,
encoding_title,
translated_encoding_title,
NULL);
/* Add the status tip */
......@@ -661,7 +672,7 @@ mozilla_view_create_charset_encoding_submenu (NautilusMozillaContentView *mozill
/* NOTE: The encoding_title comes to us already localized */
nautilus_bonobo_set_tip (mozilla_view->details->ui,
ui_path,
encoding_title);
translated_encoding_title);
g_free (ui_path);
/* Add verb to new bookmark menu item */
......@@ -683,6 +694,7 @@ mozilla_view_create_charset_encoding_submenu (NautilusMozillaContentView *mozill
g_free (encoding);
g_free (encoding_title);
g_free (translated_encoding_title);
g_free (encoding_group);
}
......
......@@ -28,6 +28,7 @@
#include <config.h>
#include "nautilus-mozilla-embed-extensions.h"
#include "nautilus-mozilla-encoding-tables.h"
#include "gtkmozembed_internal.h"
#include <libgnome/gnome-defs.h>
......@@ -40,189 +41,97 @@
#include "nsIMarkupDocumentViewer.h"
#include "nsICharsetConverterManager.h"
#include "nsICharsetConverterManager2.h"
#include <vector>
#include <string>
typedef struct
struct Encoding
{
char *encoding;
char *encoding_title;
} Entry;
typedef struct
{
char *encoding_title;
char *translated_encoding_title;
} TranslatedEncoding;
Encoding (const char *encoding,
const char *encoding_title,
const char *translated_encoding_title) :
m_encoding (encoding),
m_encoding_title (encoding_title),
m_translated_encoding_title (translated_encoding_title)
{
}
static GList *encoding_entry_list = NULL;
string m_encoding;
string m_encoding_title;
string m_translated_encoding_title;
};
static nsIDocShell *mozilla_embed_get_primary_docshell (const GtkMozEmbed *mozilla_embed);
static guint translated_encoding_get_count (void);
static const char * translated_encoding_peek_nth_encoding_title (guint n);
static const char * translated_encoding_peek_nth_translated_encoding_title (guint n);
static const char * translated_encoding_peek_nth_translated_encoding_title (guint n);
static const char * translated_encoding_find_translated_title (const char *title);
static guint encoding_group_get_count (void);
static char * convert_ns_string_to_c_string (const nsString &ns_string);
static void
encoding_entry_list_free_one_entry (gpointer data,
gpointer user_data)
static vector<Encoding>
encoding_get_encoding_table (void)
{
Entry *entry;
g_return_if_fail (data != NULL);
entry = static_cast<Entry *>(data);
g_free (entry->encoding);
g_free (entry->encoding_title);
g_free (entry);
}
static void
encoding_entry_list_free (void)
{
if (encoding_entry_list == NULL) {
return;
}
g_list_foreach (encoding_entry_list, encoding_entry_list_free_one_entry, NULL);
g_list_free (encoding_entry_list);
encoding_entry_list = NULL;
}
static const Entry *
encoding_entry_list_find_entry (const char *encoding_title)
{
GList *node;
const char *find;
node = encoding_entry_list;
while (node) {
const Entry *entry;
entry = static_cast<Entry *>(node->data);
g_assert (entry != NULL);
static vector<Encoding> empty_encodings;
static vector<Encoding> encodings;
if (strcmp (entry->encoding_title, encoding_title) == 0) {
return entry;
}
node = node->next;
}
return NULL;
}
static const Entry *
encoding_entry_list_peek_nth_entry (guint n)
{
if (n >= g_list_length (encoding_entry_list)) {
return NULL;
if (encodings.size () > 0) {
return encodings;
}
nsresult rv;
return static_cast<Entry *>(g_list_nth_data (encoding_entry_list, n));
}
static guint
encoding_entry_list_length (void)
{
return g_list_length (encoding_entry_list);
}
static void
encoding_entry_list_insert (const char *encoding,
const char *encoding_title)
{
Entry *entry;
g_return_if_fail (encoding != NULL);
g_return_if_fail (encoding[0] != '\0');
g_return_if_fail (encoding_title != NULL);
g_return_if_fail (encoding_title[0] != '\0');
g_return_if_fail (encoding_entry_list_find_entry (encoding_title) == NULL);
entry = g_new0 (Entry, 1);
entry->encoding = g_strdup (encoding);
entry->encoding_title = g_strdup (encoding_title);
encoding_entry_list = g_list_append (encoding_entry_list, entry);
}
static int
compare_entry (const Entry *a,
const Entry *b)
{
g_return_val_if_fail (a != NULL, 1);
g_return_val_if_fail (b != NULL, 1);
nsCOMPtr<nsICharsetConverterManager2> charsetManager =
do_GetService (NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
g_return_val_if_fail (NS_SUCCEEDED (rv), empty_encodings);
return g_strcasecmp (a->encoding_title, b->encoding_title);
}
nsCOMPtr <nsISupportsArray> decoderArray;
static void
encoding_entry_list_populate_once (void)
{
static gboolean populated = FALSE;
rv = charsetManager->GetDecoderList (getter_AddRefs (decoderArray));
g_return_val_if_fail (NS_SUCCEEDED (rv), empty_encodings);
if (populated) {
return;
}
PRUint32 numDecoders;
rv = decoderArray->Count (&numDecoders);
g_return_val_if_fail (NS_SUCCEEDED (rv), empty_encodings);
populated = TRUE;
for (PRUint32 i = 0; i < numDecoders; i++) {
nsCOMPtr<nsISupports> decoder = (dont_AddRef) (decoderArray->ElementAt (i));
nsCOMPtr<nsIAtom> decoderAtom (do_QueryInterface (decoder));
nsresult rv;
PRUint32 cscount;
nsCOMPtr<nsIAtom> docCharsetAtom;
nsString decoderName;
rv = decoderAtom->ToString (decoderName);
g_return_val_if_fail (NS_SUCCEEDED (rv), empty_encodings);
nsCOMPtr<nsICharsetConverterManager2> ccm2 = do_GetService (NS_CHARSETCONVERTERMANAGER_CONTRACTID, &rv);
g_return_if_fail (NS_SUCCEEDED (rv));
nsCOMPtr <nsISupportsArray> cs_list;
char *charset = convert_ns_string_to_c_string (decoderName);
g_assert (charset != NULL);
rv = ccm2->GetDecoderList(getter_AddRefs(cs_list));
g_return_if_fail (NS_SUCCEEDED (rv));
rv = cs_list->Count (&cscount);
g_assert (NS_SUCCEEDED (rv));
nsString decoderTitle;
for (PRUint32 i = 0; i < cscount; i++) {
nsCOMPtr<nsISupports> cssupports = (dont_AddRef)(cs_list->ElementAt(i));
nsCOMPtr<nsIAtom> csatom ( do_QueryInterface(cssupports) );
rv = charsetManager->GetCharsetTitle2 (decoderAtom, &decoderTitle);
char *charset_title = NULL;
nsString ns_charset;
rv = csatom->ToString (ns_charset);
g_assert (NS_SUCCEEDED (rv));
char *charset = convert_ns_string_to_c_string (ns_charset);
g_assert (charset != NULL);
if (NS_SUCCEEDED (rv)) {
charset_title = convert_ns_string_to_c_string (decoderTitle);
}
nsString ns_charset_title;
rv = ccm2->GetCharsetTitle2 (csatom, &ns_charset_title);
char *charset_title = NULL;
if (NS_SUCCEEDED (rv)) {
charset_title = convert_ns_string_to_c_string (ns_charset_title);
}
if (charset_title == NULL || charset_title[0] == '\0') {
g_free (charset_title);
charset_title = g_strdup (charset);
if (charset_title == NULL || strlen (charset_title) <= 0) {
g_free (charset_title);
charset_title = g_strdup (charset);
}
const char *tmp = translated_encoding_find_translated_title (charset_title);
char *translated_charset_title;
const char *translated_charset_title = mozilla_encoding_table_find_translated (charset_title);
if (tmp && strlen (tmp) > 0) {
translated_charset_title = g_strdup (tmp);
} else {
translated_charset_title = g_strdup (charset_title);
if (translated_charset_title == NULL || strlen (translated_charset_title) <= 0) {
translated_charset_title = charset_title;
}
encoding_entry_list_insert (charset, translated_charset_title);
g_free (charset);
g_free (charset_title);
g_free (translated_charset_title);
encodings.push_back (Encoding (charset, charset_title, translated_charset_title));
g_free (charset);
g_free (charset_title);
}
encoding_entry_list = g_list_sort (encoding_entry_list, (GCompareFunc) compare_entry);
return encodings;
}
extern "C" guint
......@@ -230,33 +139,45 @@ mozilla_charset_get_num_encodings (const GtkMozEmbed *mozilla_embed)
{
g_return_val_if_fail (GTK_IS_MOZ_EMBED (mozilla_embed), 0);
encoding_entry_list_populate_once ();
vector<Encoding> encodings = encoding_get_encoding_table ();
return encoding_entry_list_length ();
return encodings.size ();
}
extern "C" char *
mozilla_charset_get_nth_encoding (const GtkMozEmbed *mozilla_embed,
guint n)
{
g_return_val_if_fail (GTK_IS_MOZ_EMBED (mozilla_embed), NULL);
g_return_val_if_fail (n < mozilla_charset_get_num_encodings (mozilla_embed), NULL);
g_return_val_if_fail (GTK_IS_MOZ_EMBED (mozilla_embed), NULL);
g_return_val_if_fail (n < mozilla_charset_get_num_encodings (mozilla_embed), NULL);
vector<Encoding> encodings = encoding_get_encoding_table ();
const Entry *entry = encoding_entry_list_peek_nth_entry (n);
g_return_val_if_fail (entry != NULL, NULL);
return g_strdup (entry->encoding);
return g_strdup (encodings[n].m_encoding.c_str ());
}
extern "C" char *
mozilla_charset_get_nth_encoding_title (const GtkMozEmbed *mozilla_embed,
guint n)
{
g_return_val_if_fail (GTK_IS_MOZ_EMBED (mozilla_embed), NULL);
g_return_val_if_fail (n < mozilla_charset_get_num_encodings (mozilla_embed), NULL);
g_return_val_if_fail (GTK_IS_MOZ_EMBED (mozilla_embed), NULL);
g_return_val_if_fail (n < mozilla_charset_get_num_encodings (mozilla_embed), NULL);
vector<Encoding> encodings = encoding_get_encoding_table ();
const Entry *entry = encoding_entry_list_peek_nth_entry (n);
g_return_val_if_fail (entry != NULL, NULL);
return g_strdup (entry->encoding_title);
return g_strdup (encodings[n].m_encoding_title.c_str ());
}
extern "C" char *
mozilla_charset_get_nth_translated_encoding_title (const GtkMozEmbed *mozilla_embed,
guint n)
{
g_return_val_if_fail (GTK_IS_MOZ_EMBED (mozilla_embed), NULL);
g_return_val_if_fail (n < mozilla_charset_get_num_encodings (mozilla_embed), NULL);
vector<Encoding> encodings = encoding_get_encoding_table ();
return g_strdup (encodings[n].m_translated_encoding_title.c_str ());
}
extern "C" gboolean
......@@ -293,48 +214,6 @@ mozilla_charset_set_encoding (GtkMozEmbed *mozilla_embed,
return NS_SUCCEEDED (rv) ? TRUE : FALSE;
}
/* This nonsense is needed to get the allocators right */
static char *
convert_ns_string_to_c_string (const nsString & ns_string)
{
char *c_string;
char *ns_c_string = ns_string.ToNewCString ();
if (ns_c_string == NULL) {
return NULL;
}
c_string = g_strdup (ns_c_string);
nsMemory::Free (ns_c_string);
return c_string;
}
static char *encoding_groups[] =
{
N_("Arabic"),
N_("Baltic"),
N_("Central European"),
N_("Chinese"),
N_("Cyrillic"),
N_("Greek"),
N_("Hebrew"),
N_("Japanese"),
N_("Turkish"),
N_("Unicode"),
N_("UTF"),
N_("Vietnamese"),
N_("Western")
};
static guint