aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rw-r--r--ChangeLog13
-rw-r--r--embed/ephy-embed.c8
-rw-r--r--embed/ephy-embed.h5
-rw-r--r--embed/mozilla/EphyWrapper.cpp18
-rw-r--r--embed/mozilla/EphyWrapper.h6
-rw-r--r--embed/mozilla/mozilla-embed.cpp29
-rw-r--r--src/ephy-encoding-menu.c69
7 files changed, 140 insertions, 8 deletions
diff --git a/ChangeLog b/ChangeLog
index 805756d42..7ae00aa7b 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,18 @@
2003-10-11 Christian Persch <chpe@cvs.gnome.org>
+ * embed/ephy-embed.c: (ephy_embed_get_encoding):
+ * embed/ephy-embed.h:
+ * embed/mozilla/EphyWrapper.cpp:
+ * embed/mozilla/EphyWrapper.h:
+ * embed/mozilla/mozilla-embed.cpp:
+ * src/ephy-encoding-menu.c: (ephy_encoding_menu_verb_cb),
+ (update_encoding_menu_cb), (ephy_encoding_menu_set_window):
+
+ Encoding menu improvements, part 2: Implement ephy_embed_get_encoding,
+ and use it in the menu to indicate the encoding of the loaded page.
+
+2003-10-11 Christian Persch <chpe@cvs.gnome.org>
+
* src/ephy-encoding-menu.c: (ephy_encoding_menu_get_type),
(ephy_encoding_menu_verb_cb), (ephy_encoding_menu_init),
(ephy_encoding_menu_set_window), (ephy_encoding_menu_set_property),
diff --git a/embed/ephy-embed.c b/embed/ephy-embed.c
index 9b3b31289..145498665 100644
--- a/embed/ephy-embed.c
+++ b/embed/ephy-embed.c
@@ -575,6 +575,14 @@ ephy_embed_set_encoding (EphyEmbed *embed,
}
gresult
+ephy_embed_get_encoding (EphyEmbed *embed,
+ char **encoding)
+{
+ EphyEmbedClass *klass = EPHY_EMBED_GET_CLASS (embed);
+ return klass->get_encoding (embed, encoding);
+}
+
+gresult
ephy_embed_print (EphyEmbed *embed,
EmbedPrintInfo *info)
{
diff --git a/embed/ephy-embed.h b/embed/ephy-embed.h
index 07daea595..5bcac1ae1 100644
--- a/embed/ephy-embed.h
+++ b/embed/ephy-embed.h
@@ -270,6 +270,8 @@ struct EphyEmbedClass
gint pageNum);
gresult (* set_encoding) (EphyEmbed *embed,
const char *encoding);
+ gresult (* get_encoding) (EphyEmbed *embed,
+ char **encoding);
};
GType ephy_embed_get_type (void);
@@ -390,6 +392,9 @@ gresult ephy_embed_find_next (EphyEmbed *embed,
gresult ephy_embed_set_encoding (EphyEmbed *embed,
const char *encoding);
+gresult ephy_embed_get_encoding (EphyEmbed *embed,
+ char **encoding);
+
gresult ephy_embed_activate (EphyEmbed *embed);
/* Printing */
diff --git a/embed/mozilla/EphyWrapper.cpp b/embed/mozilla/EphyWrapper.cpp
index 8bd7051d4..bd3fe3ab4 100644
--- a/embed/mozilla/EphyWrapper.cpp
+++ b/embed/mozilla/EphyWrapper.cpp
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2000 Marco Pesenti Gritti
+ * Copyright (C) 2000-2003 Marco Pesenti Gritti
*
* 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
@@ -14,6 +14,8 @@
* 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.
+ *
+ * $Id$
*/
#include "EphyWrapper.h"
@@ -749,3 +751,17 @@ nsresult EphyWrapper::PopTargetDocument ()
return NS_OK;
}
+
+nsresult EphyWrapper::GetEncoding (nsCString &aEncoding)
+{
+ nsresult result;
+
+ nsCOMPtr<nsIDOMDocument> domDoc;
+ result = GetDOMDocument (getter_AddRefs(domDoc));
+ if (NS_FAILED (result) || !domDoc) return NS_ERROR_FAILURE;
+
+ nsCOMPtr<nsIDocument> doc = do_QueryInterface(domDoc, &result);
+ if (NS_FAILED (result) || !doc) return NS_ERROR_FAILURE;
+
+ return doc->GetDocumentCharacterSet (aEncoding);
+}
diff --git a/embed/mozilla/EphyWrapper.h b/embed/mozilla/EphyWrapper.h
index 2f5131ee6..51e99ad66 100644
--- a/embed/mozilla/EphyWrapper.h
+++ b/embed/mozilla/EphyWrapper.h
@@ -1,5 +1,5 @@
/*
- * Copyright (C) 2000 Marco Pesenti Gritti
+ * Copyright (C) 2000-2003 Marco Pesenti Gritti
*
* 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
@@ -14,6 +14,8 @@
* 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.
+ *
+ * $Id$
*/
#ifndef EPHY_WRAPPER_H
@@ -76,6 +78,8 @@ public:
nsresult ForceEncoding (const char *encoding);
+ nsresult GetEncoding (nsCString &aEncoding);
+
nsresult CanCutSelection(PRBool *result);
nsresult CanCopySelection(PRBool *result);
diff --git a/embed/mozilla/mozilla-embed.cpp b/embed/mozilla/mozilla-embed.cpp
index 0ca866a05..ae1f7f7b1 100644
--- a/embed/mozilla/mozilla-embed.cpp
+++ b/embed/mozilla/mozilla-embed.cpp
@@ -147,7 +147,9 @@ impl_get_security_level (EphyEmbed *embed,
static gresult
impl_set_encoding (EphyEmbed *embed,
const char *encoding);
-
+static gresult
+impl_get_encoding (EphyEmbed *embed,
+ char **encoding);
static gresult
impl_print (EphyEmbed *embed,
EmbedPrintInfo *info);
@@ -378,6 +380,7 @@ ephy_embed_init (EphyEmbedClass *embed_class)
embed_class->activate = impl_activate;
embed_class->find_set_properties = impl_find_set_properties;
embed_class->set_encoding = impl_set_encoding;
+ embed_class->get_encoding = impl_get_encoding;
embed_class->select_all = impl_select_all;
embed_class->print = impl_print;
embed_class->print_preview_close = impl_print_preview_close;
@@ -1173,7 +1176,7 @@ static gresult
impl_set_encoding (EphyEmbed *embed,
const char *encoding)
{
- nsresult result = NS_OK;
+ nsresult result;
EphyWrapper *wrapper;
wrapper = MOZILLA_EMBED(embed)->priv->wrapper;
@@ -1188,6 +1191,28 @@ impl_set_encoding (EphyEmbed *embed,
return NS_SUCCEEDED(result) ? G_OK : G_FAILED;
}
+static gresult
+impl_get_encoding (EphyEmbed *embed,
+ char **encoding)
+{
+ nsresult result;
+ EphyWrapper *wrapper;
+ nsCAutoString enc;
+
+ g_return_val_if_fail (encoding != NULL, G_FAILED);
+ *encoding = NULL;
+
+ wrapper = MOZILLA_EMBED(embed)->priv->wrapper;
+ g_return_val_if_fail (wrapper != NULL, G_FAILED);
+
+ result = wrapper->GetEncoding (enc);
+ if (NS_FAILED (result)) return G_FAILED;
+
+ *encoding = g_strdup (enc.get());
+
+ return G_OK;
+}
+
static void
mozilla_embed_location_changed_cb (GtkMozEmbed *embed,
MozillaEmbed *membed)
diff --git a/src/ephy-encoding-menu.c b/src/ephy-encoding-menu.c
index 741e4226e..2f3596c23 100644
--- a/src/ephy-encoding-menu.c
+++ b/src/ephy-encoding-menu.c
@@ -31,6 +31,8 @@
#include <bonobo/bonobo-i18n.h>
#include <gtk/gtkaction.h>
+#include <gtk/gtktoggleaction.h>
+#include <gtk/gtkradioaction.h>
#include <gtk/gtkuimanager.h>
#include <string.h>
@@ -96,7 +98,15 @@ ephy_encoding_menu_verb_cb (GtkAction *action,
const char *encoding;
const char *action_name;
-
+ /* do nothing if this action was _de_activated, or if we're updating
+ * the menu, i.e. setting the active encoding from the document
+ */
+ if (gtk_toggle_action_get_active (GTK_TOGGLE_ACTION (action)) == FALSE
+ || menu->priv->update_tag)
+ {
+ return;
+ }
+
embed = ephy_window_get_active_embed (menu->priv->window);
g_return_if_fail (embed != NULL);
@@ -123,11 +133,52 @@ ephy_encoding_menu_init (EphyEncodingMenu *menu)
}
static void
+update_encoding_menu_cb (GtkAction *dummy, EphyEncodingMenu *menu)
+{
+ EphyEmbed *embed;
+ GtkAction *action = NULL;
+ char *encoding;
+
+ embed = ephy_window_get_active_embed (menu->priv->window);
+ g_return_if_fail (embed != NULL);
+
+ ephy_embed_get_encoding (embed, &encoding);
+
+ if (encoding != NULL)
+ {
+ char name[32];
+
+ g_snprintf (name, 32, "Encoding%s", encoding);
+ action = gtk_action_group_get_action (menu->priv->action_group,
+ name);
+ }
+
+ if (action != NULL)
+ {
+ /* FIXME: block the "activate" signal instead; needs to wait
+ * until g_signal_handlers_block_matched supports blocking
+ * by signal id alone.
+ */
+ menu->priv->update_tag = TRUE;
+ gtk_toggle_action_set_active (GTK_TOGGLE_ACTION (action), TRUE);
+ menu->priv->update_tag = FALSE;
+ }
+ else
+ {
+ g_warning ("Could not find action for encoding '%s'!\n", encoding);
+ }
+
+ g_free (encoding);
+}
+
+static void
ephy_encoding_menu_set_window (EphyEncodingMenu *menu, EphyWindow *window)
{
EphyEmbedSingle *single;
GtkActionGroup *action_group;
+ GtkAction *action;
GList *encodings, *groups, *l;
+ GSList *radio_group = NULL;
g_return_if_fail (EPHY_IS_WINDOW (window));
@@ -145,15 +196,17 @@ ephy_encoding_menu_set_window (EphyEncodingMenu *menu, EphyWindow *window)
for (l = encodings; l != NULL; l = l->next)
{
const EncodingInfo *info = (EncodingInfo *) l->data;
- GtkAction *action;
char name[32];
g_snprintf (name, 32, "Encoding%s", info->encoding);
- action = g_object_new (GTK_TYPE_ACTION,
+ action = g_object_new (GTK_TYPE_RADIO_ACTION,
"name", name,
"label", info->title,
NULL);
+ gtk_radio_action_set_group (GTK_RADIO_ACTION (action), radio_group);
+ radio_group = gtk_radio_action_get_group (GTK_RADIO_ACTION (action));
+
g_signal_connect (action, "activate",
G_CALLBACK (ephy_encoding_menu_verb_cb),
menu);
@@ -170,7 +223,6 @@ ephy_encoding_menu_set_window (EphyEncodingMenu *menu, EphyWindow *window)
for (l = groups; l != NULL; l = l->next)
{
const LanguageGroupInfo *info = (LanguageGroupInfo *) l->data;
- GtkAction *action;
char name[32];
g_snprintf (name, 32, "EncodingGroup%d", info->group);
@@ -190,6 +242,15 @@ ephy_encoding_menu_set_window (EphyEncodingMenu *menu, EphyWindow *window)
action_group, 0);
g_object_unref (action_group);
+ action = gtk_ui_manager_get_action (menu->priv->manager,
+ "/menubar/ViewMenu");
+ if (action != NULL)
+ {
+ g_signal_connect_object (action, "activate",
+ G_CALLBACK (update_encoding_menu_cb),
+ menu, 0);
+ }
+
ephy_encoding_menu_rebuild (menu);
}