aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2003-10-11 17:09:22 +0800
committerChristian Persch <chpe@src.gnome.org>2003-10-11 17:09:22 +0800
commit6c4b99d210e3391080ce18502a507dc38869189c (patch)
tree8af86c847ac4472d9646dde842e86ef809818626
parent44592d8463a27f756746201136a97e2d47dcc4f8 (diff)
downloadgsoc2013-epiphany-6c4b99d210e3391080ce18502a507dc38869189c.tar
gsoc2013-epiphany-6c4b99d210e3391080ce18502a507dc38869189c.tar.gz
gsoc2013-epiphany-6c4b99d210e3391080ce18502a507dc38869189c.tar.bz2
gsoc2013-epiphany-6c4b99d210e3391080ce18502a507dc38869189c.tar.lz
gsoc2013-epiphany-6c4b99d210e3391080ce18502a507dc38869189c.tar.xz
gsoc2013-epiphany-6c4b99d210e3391080ce18502a507dc38869189c.tar.zst
gsoc2013-epiphany-6c4b99d210e3391080ce18502a507dc38869189c.zip
Encodings menu improvements, part 1: Ported to new gtk ui manager api, and
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), (ephy_encoding_menu_get_property), (ephy_encoding_menu_class_init), (ephy_encoding_menu_new), (ephy_encoding_menu_rebuild): * src/ephy-encoding-menu.h: Encodings menu improvements, part 1: Ported to new gtk ui manager api, and general code cleanups.
-rw-r--r--ChangeLog12
-rw-r--r--src/ephy-encoding-menu.c358
-rw-r--r--src/ephy-encoding-menu.h34
3 files changed, 205 insertions, 199 deletions
diff --git a/ChangeLog b/ChangeLog
index 510485d37..805756d42 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,3 +1,15 @@
+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),
+ (ephy_encoding_menu_get_property), (ephy_encoding_menu_class_init),
+ (ephy_encoding_menu_new), (ephy_encoding_menu_rebuild):
+ * src/ephy-encoding-menu.h:
+
+ Encodings menu improvements, part 1: Ported to new gtk ui manager
+ api, and general code cleanups.
+
2003-10-10 Marco Pesenti Gritti <marco@gnome.org>
* embed/mozilla/FilePicker.cpp:
diff --git a/src/ephy-encoding-menu.c b/src/ephy-encoding-menu.c
index 09e3b10b1..741e4226e 100644
--- a/src/ephy-encoding-menu.c
+++ b/src/ephy-encoding-menu.c
@@ -1,5 +1,7 @@
/*
* Copyright (C) 2002 Ricardo Fernández Pascual
+ * Copyright (C) 2003 Marco Pesenti Gritti
+ * Copyright (C) 2003 Christian Persch
*
* 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
@@ -28,44 +30,35 @@
#include "ephy-debug.h"
#include <bonobo/bonobo-i18n.h>
+#include <gtk/gtkaction.h>
#include <gtk/gtkuimanager.h>
#include <string.h>
-/**
- * Private data
- */
-
#define EPHY_ENCODING_MENU_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_ENCODING_MENU, EphyEncodingMenuPrivate))
struct _EphyEncodingMenuPrivate
{
EphyWindow *window;
+ GtkUIManager *manager;
GtkActionGroup *action_group;
+ gboolean update_tag;
+ guint merge_id;
};
-/**
- * Private functions, only availble from this file
- */
-static void ephy_encoding_menu_class_init (EphyEncodingMenuClass *klass);
-static void ephy_encoding_menu_init (EphyEncodingMenu *wrhm);
-static void ephy_encoding_menu_finalize_impl (GObject *o);
-static void ephy_encoding_menu_rebuild (EphyEncodingMenu *wrhm);
-static void ephy_encoding_menu_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec);
-static void ephy_encoding_menu_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec);
+#define ENCODING_PLACEHOLDER_PATH "/menubar/ViewMenu/ViewEncodingsPlaceholder"
+#define ENCODING_MENU_PATH "/menubar/ViewMenu/ViewEncodingsPlaceholder/ViewEncodingMenu"
+
+static void ephy_encoding_menu_class_init (EphyEncodingMenuClass *klass);
+static void ephy_encoding_menu_init (EphyEncodingMenu *menu);
+static void ephy_encoding_menu_rebuild (EphyEncodingMenu *menu);
enum
{
PROP_0,
- PROP_EPHY_WINDOW
+ PROP_WINDOW
};
-static gpointer g_object_class;
+static GObjectClass *parent_class = NULL;
GType
ephy_encoding_menu_get_type (void)
@@ -88,235 +81,236 @@ ephy_encoding_menu_get_type (void)
};
ephy_encoding_menu_type = g_type_register_static (G_TYPE_OBJECT,
- "EphyEncodingMenu",
- &our_info, 0);
+ "EphyEncodingMenu",
+ &our_info, 0);
}
return ephy_encoding_menu_type;
}
+
static void
-ephy_encoding_menu_class_init (EphyEncodingMenuClass *klass)
+ephy_encoding_menu_verb_cb (GtkAction *action,
+ EphyEncodingMenu *menu)
{
- GObjectClass *object_class = G_OBJECT_CLASS (klass);
+ EphyEmbed *embed;
+ const char *encoding;
+ const char *action_name;
- G_OBJECT_CLASS (klass)->finalize = ephy_encoding_menu_finalize_impl;
- g_object_class = g_type_class_peek_parent (klass);
+
+ embed = ephy_window_get_active_embed (menu->priv->window);
+ g_return_if_fail (embed != NULL);
- object_class->set_property = ephy_encoding_menu_set_property;
- object_class->get_property = ephy_encoding_menu_get_property;
+ action_name = gtk_action_get_name (action);
- g_object_class_install_property (object_class,
- PROP_EPHY_WINDOW,
- g_param_spec_object ("EphyWindow",
- "EphyWindow",
- "Parent window",
- EPHY_TYPE_WINDOW,
- G_PARAM_READWRITE |
- G_PARAM_CONSTRUCT_ONLY));
+ if (strncmp (action_name, "Encoding", 8) == 0)
+ {
+ encoding = action_name + 8;
- g_type_class_add_private (object_class, sizeof(EphyEncodingMenuPrivate));
+ LOG ("Switching to encoding %s", encoding)
+
+ ephy_embed_set_encoding (embed, encoding);
+ }
}
static void
-ephy_encoding_menu_init (EphyEncodingMenu *wrhm)
+ephy_encoding_menu_init (EphyEncodingMenu *menu)
{
- EphyEncodingMenuPrivate *p = EPHY_ENCODING_MENU_GET_PRIVATE (wrhm);
- wrhm->priv = p;
+ menu->priv = EPHY_ENCODING_MENU_GET_PRIVATE (menu);
- wrhm->priv->action_group = NULL;
+ menu->priv->update_tag = FALSE;
+ menu->priv->action_group = NULL;
+ menu->priv->merge_id = 0;
}
static void
-ephy_encoding_menu_finalize_impl (GObject *o)
+ephy_encoding_menu_set_window (EphyEncodingMenu *menu, EphyWindow *window)
{
- EphyEncodingMenu *wrhm = EPHY_ENCODING_MENU (o);
- EphyEncodingMenuPrivate *p = wrhm->priv;
+ EphyEmbedSingle *single;
+ GtkActionGroup *action_group;
+ GList *encodings, *groups, *l;
+
+ g_return_if_fail (EPHY_IS_WINDOW (window));
+
+ menu->priv->window = window;
+ menu->priv->manager = GTK_UI_MANAGER (window->ui_merge);
+
+ action_group = gtk_action_group_new ("EncodingActions");
+ menu->priv->action_group = action_group;
+
+ single = ephy_embed_shell_get_embed_single (EPHY_EMBED_SHELL (ephy_shell));
+ g_return_if_fail (single != NULL);
+
+ ephy_embed_single_get_encodings (single, LG_ALL, FALSE, &encodings);
+
+ 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,
+ "name", name,
+ "label", info->title,
+ NULL);
+
+ g_signal_connect (action, "activate",
+ G_CALLBACK (ephy_encoding_menu_verb_cb),
+ menu);
+
+ gtk_action_group_add_action (menu->priv->action_group, action);
+ g_object_unref (action);
+ }
+
+ g_list_foreach (encodings, (GFunc) encoding_info_free, NULL);
+ g_list_free (encodings);
+
+ ephy_embed_single_get_language_groups (single, &groups);
- if (p->action_group != NULL)
+ for (l = groups; l != NULL; l = l->next)
{
- g_object_unref (p->action_group);
+ const LanguageGroupInfo *info = (LanguageGroupInfo *) l->data;
+ GtkAction *action;
+ char name[32];
+
+ g_snprintf (name, 32, "EncodingGroup%d", info->group);
+
+ action = g_object_new (GTK_TYPE_ACTION,
+ "name", name,
+ "label", info->title,
+ NULL);
+ gtk_action_group_add_action (menu->priv->action_group, action);
+ g_object_unref (action);
}
- G_OBJECT_CLASS (g_object_class)->finalize (o);
+ g_list_foreach (groups, (GFunc) language_group_info_free, NULL);
+ g_list_free (groups);
+
+ gtk_ui_manager_insert_action_group (menu->priv->manager,
+ action_group, 0);
+ g_object_unref (action_group);
+
+ ephy_encoding_menu_rebuild (menu);
}
static void
ephy_encoding_menu_set_property (GObject *object,
- guint prop_id,
- const GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ const GValue *value,
+ GParamSpec *pspec)
{
- EphyEncodingMenu *m = EPHY_ENCODING_MENU (object);
-
- switch (prop_id)
- {
- case PROP_EPHY_WINDOW:
- m->priv->window = g_value_get_object (value);
- ephy_encoding_menu_rebuild (m);
- break;
- }
+ EphyEncodingMenu *menu = EPHY_ENCODING_MENU (object);
+
+ switch (prop_id)
+ {
+ case PROP_WINDOW:
+ ephy_encoding_menu_set_window (menu, g_value_get_object (value));
+ break;
+ }
}
static void
ephy_encoding_menu_get_property (GObject *object,
- guint prop_id,
- GValue *value,
- GParamSpec *pspec)
+ guint prop_id,
+ GValue *value,
+ GParamSpec *pspec)
{
- EphyEncodingMenu *m = EPHY_ENCODING_MENU (object);
-
- switch (prop_id)
- {
- case PROP_EPHY_WINDOW:
- g_value_set_object (value, m->priv->window);
- break;
- }
-}
+ EphyEncodingMenu *menu = EPHY_ENCODING_MENU (object);
-EphyEncodingMenu *
-ephy_encoding_menu_new (EphyWindow *window)
-{
- EphyEncodingMenu *ret = g_object_new (EPHY_TYPE_ENCODING_MENU,
- "EphyWindow", window,
- NULL);
- return ret;
+ switch (prop_id)
+ {
+ case PROP_WINDOW:
+ g_value_set_object (value, menu->priv->window);
+ break;
+ }
}
static void
-ephy_encoding_menu_verb_cb (GtkAction *action,
- EphyEncodingMenu *menu)
+ephy_encoding_menu_class_init (EphyEncodingMenuClass *klass)
{
- EphyWindow *window;
- EphyEmbed *embed;
- const char *encoding;
- const char *action_name;
-
- window = menu->priv->window;
-
- embed = ephy_window_get_active_embed (window);
- g_return_if_fail (embed != NULL);
-
- action_name = gtk_action_get_name (action);
+ GObjectClass *object_class = G_OBJECT_CLASS (klass);
- if (strncmp (action_name, "Encoding", 8) == 0)
- {
- encoding = action_name + 8;
+ parent_class = g_type_class_peek_parent (klass);
- LOG ("Switching to encoding %s", encoding)
+ object_class->set_property = ephy_encoding_menu_set_property;
+ object_class->get_property = ephy_encoding_menu_get_property;
- ephy_embed_set_encoding (embed, encoding);
- }
-}
+ g_object_class_install_property (object_class,
+ PROP_WINDOW,
+ g_param_spec_object ("window",
+ "Window",
+ "Parent window",
+ EPHY_TYPE_WINDOW,
+ G_PARAM_READWRITE |
+ G_PARAM_CONSTRUCT_ONLY));
-static void
-build_group (GtkActionGroup *action_group,
- GString *xml_string,
- const LanguageGroupInfo *info)
-{
- gchar *tmp;
- gchar *verb;
- GtkAction *action;
-
- verb = g_strdup_printf ("EncodingGroup%d", info->group);
-
- action = g_object_new (GTK_TYPE_ACTION,
- "name", verb,
- "label", info->title,
- NULL);
- gtk_action_group_add_action (action_group, action);
- g_object_unref (action);
-
- tmp = g_strdup_printf ("<menu name=\"%sItem\" action=\"%s\">\n",
- verb, verb);
- xml_string = g_string_append (xml_string, tmp);
- g_free (tmp);
- g_free (verb);
+ g_type_class_add_private (object_class, sizeof(EphyEncodingMenuPrivate));
}
-static void
-build_encoding (EphyEncodingMenu *menu,
- GtkActionGroup *action_group,
- GString *xml_string,
- const EncodingInfo *info)
+EphyEncodingMenu *
+ephy_encoding_menu_new (EphyWindow *window)
{
- char *tmp;
- char *verb;
- GtkAction *action;
-
- verb = g_strdup_printf ("Encoding%s", info->encoding);
- action = g_object_new (GTK_TYPE_ACTION,
- "name", verb,
- "label", info->title,
- NULL);
- g_signal_connect (action, "activate",
- G_CALLBACK (ephy_encoding_menu_verb_cb),
- menu);
-
- gtk_action_group_add_action (action_group, action);
- g_object_unref (action);
-
- tmp = g_strdup_printf ("<menuitem name=\"%sItem\" action=\"%s\"/>\n",
- verb, verb);
- xml_string = g_string_append (xml_string, tmp);
-
- g_free (tmp);
- g_free (verb);
+ return g_object_new (EPHY_TYPE_ENCODING_MENU,
+ "window", window,
+ NULL);
}
static void
-ephy_encoding_menu_rebuild (EphyEncodingMenu *wrhm)
+ephy_encoding_menu_rebuild (EphyEncodingMenu *menu)
{
EphyEmbedSingle *single;
- EphyEncodingMenuPrivate *p = wrhm->priv;
- GtkUIManager *merge = GTK_UI_MANAGER (p->window->ui_merge);
- GString *xml;
- GList *groups, *lg, *encodings, *enc;
-
- p->action_group = NULL;
-
- LOG ("Rebuilding encoding menu")
+ EphyEncodingMenuPrivate *p = menu->priv;
+ GList *encodings, *groups, *l;
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, "<ui><menubar><menu name=\"ViewMenu\" action=\"View\">"
- "<placeholder name=\"ViewEncodingsPlaceholder\">"
- "<menu name=\"ViewEncodingMenu\" action=\"ViewEncoding\">");
+ if (p->merge_id > 0)
+ {
+ gtk_ui_manager_remove_ui (p->manager, p->merge_id);
+ gtk_ui_manager_ensure_update (p->manager);
+ }
+
+ p->merge_id = gtk_ui_manager_new_merge_id (p->manager);
+
+ gtk_ui_manager_add_ui (p->manager, p->merge_id, ENCODING_PLACEHOLDER_PATH,
+ "ViewEncodingMenu", "ViewEncoding",
+ GTK_UI_MANAGER_MENU, FALSE);
- p->action_group = gtk_action_group_new ("EncodingActions");
- gtk_ui_manager_insert_action_group (merge, p->action_group, 0);
+ for (l = groups; l != NULL; l = l->next)
+ {
+ const LanguageGroupInfo *info = (LanguageGroupInfo *) l->data;
+ char name[32], action[36], path[128];
+ GList *enc;
- for (lg = groups; lg != NULL; lg = lg->next)
- {
- const LanguageGroupInfo *lang_info = (LanguageGroupInfo *) lg->data;
+ g_snprintf (action, 32, "EncodingGroup%d", info->group);
+ g_snprintf (name, 36, "%sMenu", action);
+ g_snprintf (path, 128, "%s/%s", ENCODING_MENU_PATH, name);
- build_group (p->action_group, xml, lang_info);
+ gtk_ui_manager_add_ui (p->manager, p->merge_id,
+ ENCODING_MENU_PATH,
+ name, action,
+ GTK_UI_MANAGER_MENU, FALSE);
- ephy_embed_single_get_encodings (single, lang_info->group,
- FALSE, &encodings);
+ ephy_embed_single_get_encodings (single, info->group,
+ FALSE, &encodings);
for (enc = encodings; enc != NULL; enc = enc->next)
- {
+ {
const EncodingInfo *info = (EncodingInfo *) enc->data;
- build_encoding (wrhm, p->action_group, xml, info);
+ g_snprintf (action, 32, "Encoding%s", info->encoding);
+ g_snprintf (name, 36, "%sItem", action);
+
+ gtk_ui_manager_add_ui (p->manager, p->merge_id, path,
+ name, action,
+ GTK_UI_MANAGER_MENUITEM, FALSE);
}
g_list_foreach (encodings, (GFunc) encoding_info_free, NULL);
g_list_free (encodings);
-
- g_string_append (xml, "</menu>");
}
g_list_foreach (groups, (GFunc) language_group_info_free, NULL);
g_list_free (groups);
-
- g_string_append (xml, "</menu></placeholder></menu></menubar></ui>");
-
- gtk_ui_manager_add_ui_from_string (merge, xml->str, -1, NULL);
-
- g_string_free (xml, TRUE);
}
diff --git a/src/ephy-encoding-menu.h b/src/ephy-encoding-menu.h
index 1cfa44f82..b1ed37bc8 100644
--- a/src/ephy-encoding-menu.h
+++ b/src/ephy-encoding-menu.h
@@ -1,5 +1,7 @@
/*
- * Copyright (C) 2002 Ricardo Fernández Pascual
+ * Copyright (C) 2002 Ricardo Fernández Pascual
+ * Copyright (C) 2003 Marco Pesenti Gritti
+ * Copyright (C) 2003 Christian Persch
*
* 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 +16,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_ENCODING_MENU_H
@@ -21,29 +25,24 @@
#include "ephy-window.h"
-/* object forward declarations */
+G_BEGIN_DECLS
+
+#define EPHY_TYPE_ENCODING_MENU (ephy_encoding_menu_get_type())
+#define EPHY_ENCODING_MENU(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EPHY_TYPE_ENCODING_MENU, EphyEncodingMenu))
+#define EPHY_ENCODING_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EPHY_TYPE_ENCODING_MENU, EphyEncodingMenuClass))
+#define EPHY_IS_ENCODING_MENU(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EPHY_TYPE_ENCODING_MENU))
+#define EPHY_IS_ENCODING_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EPHY_TYPE_ENCODING_MENU))
+#define EPHY_ENCODING_MENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EPHY_TYPE_ENCODING_MENU, EphyEncodingMenuClass))
typedef struct _EphyEncodingMenu EphyEncodingMenu;
typedef struct _EphyEncodingMenuClass EphyEncodingMenuClass;
typedef struct _EphyEncodingMenuPrivate EphyEncodingMenuPrivate;
-/**
- * Editor object
- */
-
-#define EPHY_TYPE_ENCODING_MENU (ephy_encoding_menu_get_type())
-#define EPHY_ENCODING_MENU(object) (G_TYPE_CHECK_INSTANCE_CAST((object), EPHY_TYPE_ENCODING_MENU, EphyEncodingMenu))
-#define EPHY_ENCODING_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_CAST((klass), EPHY_TYPE_ENCODING_MENU, EphyEncodingMenuClass))
-#define EPHY_IS_ENCODING_MENU(object) (G_TYPE_CHECK_INSTANCE_TYPE((object), EPHY_TYPE_ENCODING_MENU))
-#define EPHY_IS_ENCODING_MENU_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE((klass), EPHY_TYPE_ENCODING_MENU))
-#define EPHY_ENCODING_MENU_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EPHY_TYPE_ENCODING_MENU, EphyEncodingMenuClass))
-
struct _EphyEncodingMenuClass
{
GObjectClass parent_class;
};
-/* Remember: fields are public read-only */
struct _EphyEncodingMenu
{
GObject parent_object;
@@ -51,9 +50,10 @@ struct _EphyEncodingMenu
EphyEncodingMenuPrivate *priv;
};
-GType ephy_encoding_menu_get_type (void);
+GType ephy_encoding_menu_get_type (void);
-EphyEncodingMenu *ephy_encoding_menu_new (EphyWindow *window);
+EphyEncodingMenu *ephy_encoding_menu_new (EphyWindow *window);
-#endif
+G_END_DECLS
+#endif