diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2003-09-20 17:37:26 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2003-09-20 17:37:26 +0800 |
commit | 68616208eeeee369e62c9256fc9aba5dbe139e3e (patch) | |
tree | 279fbbbeb9bfb24372c9a3a9b6d169284c877e8d /src/ephy-location-action.c | |
parent | f7c6e1db094b8f4da058aaec9b2faa9498326b59 (diff) | |
download | gsoc2013-epiphany-68616208eeeee369e62c9256fc9aba5dbe139e3e.tar gsoc2013-epiphany-68616208eeeee369e62c9256fc9aba5dbe139e3e.tar.gz gsoc2013-epiphany-68616208eeeee369e62c9256fc9aba5dbe139e3e.tar.bz2 gsoc2013-epiphany-68616208eeeee369e62c9256fc9aba5dbe139e3e.tar.lz gsoc2013-epiphany-68616208eeeee369e62c9256fc9aba5dbe139e3e.tar.xz gsoc2013-epiphany-68616208eeeee369e62c9256fc9aba5dbe139e3e.tar.zst gsoc2013-epiphany-68616208eeeee369e62c9256fc9aba5dbe139e3e.zip |
Remember the address in the location action, so we can restore it when we
2003-09-20 Christian Persch <chpe@cvs.gnome.org>
* lib/widgets/ephy-location-entry.c:
(ephy_location_entry_class_init),
(ephy_location_entry_activation_finished), (location_focus_out_cb),
(ephy_location_entry_init), (ephy_location_ignore_prefix),
(ephy_location_entry_activate_cb),
(ephy_location_entry_set_location),
(ephy_location_entry_get_location), (ephy_location_entry_activate),
(ephy_location_entry_editable_changed_cb),
(ephy_location_entry_clear_history):
* lib/widgets/ephy-location-entry.h:
* src/ephy-location-action.c: (location_url_activate_cb),
(user_changed_cb), (sync_address), (connect_proxy),
(disconnect_proxy), (ephy_location_action_set_property),
(ephy_location_action_get_property),
(ephy_location_action_activate), (ephy_location_action_class_init),
(ephy_location_action_init), (ephy_location_action_finalize),
(ephy_location_action_get_address),
(ephy_location_action_set_address), (clear_history),
(ephy_location_action_clear_history):
* src/ephy-location-action.h:
* src/toolbar.c: (toolbar_class_init), (toolbar_set_property),
(sync_user_input_cb), (toolbar_setup_actions),
(toolbar_set_window), (toolbar_init), (toolbar_finalize),
(toolbar_new), (toolbar_activate_location), (toolbar_set_location),
(toolbar_get_location), (toolbar_clear_location_history):
* src/toolbar.h:
* src/window-commands.c: (window_cmd_load_location):
Remember the address in the location action, so we can restore it when we
get a new proxy widget.
Do some misc cleanups on location entry, removing finished signal; move
activation from toolbar into location entry.
Diffstat (limited to 'src/ephy-location-action.c')
-rw-r--r-- | src/ephy-location-action.c | 224 |
1 files changed, 195 insertions, 29 deletions
diff --git a/src/ephy-location-action.c b/src/ephy-location-action.c index bd28e8e6a..bd18275a7 100644 --- a/src/ephy-location-action.c +++ b/src/ephy-location-action.c @@ -1,5 +1,6 @@ /* * 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 +15,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 "ephy-location-action.h" @@ -21,8 +24,27 @@ #include "ephy-shell.h" #include "ephy-debug.h" +#define EPHY_LOCATION_ACTION_GET_PRIVATE(object)(G_TYPE_INSTANCE_GET_PRIVATE ((object), EPHY_TYPE_LOCATION_ACTION, EphyLocationActionPrivate)) + +struct _EphyLocationActionPrivate +{ + char *address; +}; + static void ephy_location_action_init (EphyLocationAction *action); static void ephy_location_action_class_init (EphyLocationActionClass *class); +static void ephy_location_action_finalize (GObject *object); +static void user_changed_cb (GtkWidget *proxy, + EphyLocationAction *action); +static void sync_address (GtkAction *action, + GParamSpec *pspec, + GtkWidget *proxy); + +enum +{ + PROP_0, + PROP_ADDRESS +}; enum { @@ -32,7 +54,7 @@ enum static GObjectClass *parent_class = NULL; -static guint ephy_location_action_signals[LAST_SIGNAL] = { 0 }; +static guint signals[LAST_SIGNAL] = { 0 }; GType ephy_location_action_get_type (void) @@ -76,9 +98,7 @@ location_url_activate_cb (EphyLocationEntry *entry, if (!content) { LOG ("Go to %s", target); - g_signal_emit (action, - ephy_location_action_signals[GO_LOCATION], - 0, target); + g_signal_emit (action, signals[GO_LOCATION], 0, target); } else { @@ -88,47 +108,150 @@ location_url_activate_cb (EphyLocationEntry *entry, (bookmarks, target, content); g_return_if_fail (url != NULL); LOG ("Go to %s", url); - g_signal_emit (action, - ephy_location_action_signals[GO_LOCATION], - 0, url); + g_signal_emit (action, signals[GO_LOCATION], 0, url); g_free (url); } } static void +user_changed_cb (GtkWidget *proxy, EphyLocationAction *action) +{ + const char *address; + + address = ephy_location_entry_get_location (EPHY_LOCATION_ENTRY (proxy)); + + LOG ("user_changed_cb, new address %s", address) + + g_signal_handlers_block_by_func (action, G_CALLBACK (sync_address), proxy); + ephy_location_action_set_address (action, address); + g_signal_handlers_unblock_by_func (action, G_CALLBACK (sync_address), proxy); +} + +static void +sync_address (GtkAction *act, GParamSpec *pspec, GtkWidget *proxy) +{ + EphyLocationAction *action = EPHY_LOCATION_ACTION (act); + + LOG ("sync_address") + + g_return_if_fail (EPHY_IS_LOCATION_ENTRY (proxy)); + g_signal_handlers_block_by_func (proxy, G_CALLBACK (user_changed_cb), action); + ephy_location_entry_set_location (EPHY_LOCATION_ENTRY (proxy), + action->priv->address); + g_signal_handlers_unblock_by_func (proxy, G_CALLBACK (user_changed_cb), action); +} + +static void connect_proxy (GtkAction *action, GtkWidget *proxy) { - EphyAutocompletion *ac; - EphyLocationEntry *e = EPHY_LOCATION_ENTRY (proxy); + LOG ("Connect proxy") - ac = EPHY_AUTOCOMPLETION (ephy_shell_get_autocompletion (ephy_shell)); + if (EPHY_IS_LOCATION_ENTRY (proxy)) + { + EphyAutocompletion *ac; - LOG ("Connect location proxy") + ac = EPHY_AUTOCOMPLETION (ephy_shell_get_autocompletion (ephy_shell)); - g_return_if_fail (EPHY_IS_LOCATION_ENTRY (e)); + ephy_location_entry_set_autocompletion (EPHY_LOCATION_ENTRY (proxy), ac); - ephy_location_entry_set_autocompletion (e, ac); + sync_address (action, NULL, proxy); + g_signal_connect_object (action, "notify::address", + G_CALLBACK (sync_address), proxy, 0); - g_signal_connect (e, "activated", - GTK_SIGNAL_FUNC(location_url_activate_cb), - action); + g_signal_connect_object (proxy, "activated", + G_CALLBACK (location_url_activate_cb), + action, 0); + g_signal_connect_object (proxy, "user_changed", + G_CALLBACK (user_changed_cb), action, 0); + } (* GTK_ACTION_CLASS (parent_class)->connect_proxy) (action, proxy); } static void +disconnect_proxy (GtkAction *action, GtkWidget *proxy) +{ + LOG ("Disconnect proxy") + + if (EPHY_IS_LOCATION_ENTRY (proxy)) + { + g_signal_handlers_disconnect_by_func + (action, G_CALLBACK (sync_address), proxy); + + g_signal_handlers_disconnect_by_func + (proxy, G_CALLBACK (location_url_activate_cb), action); + + g_signal_handlers_disconnect_by_func + (proxy, G_CALLBACK (user_changed_cb), action); + } + + (* GTK_ACTION_CLASS (parent_class)->disconnect_proxy) (action, proxy); +} + +static void +ephy_location_action_set_property (GObject *object, + guint prop_id, + const GValue *value, + GParamSpec *pspec) +{ + EphyLocationAction *action = EPHY_LOCATION_ACTION (object); + + switch (prop_id) + { + case PROP_ADDRESS: + ephy_location_action_set_address (action, g_value_get_string (value)); + break; + } +} + +static void +ephy_location_action_get_property (GObject *object, + guint prop_id, + GValue *value, + GParamSpec *pspec) +{ + EphyLocationAction *action = EPHY_LOCATION_ACTION (object); + + switch (prop_id) + { + case PROP_ADDRESS: + g_value_set_string (value, ephy_location_action_get_address (action)); + break; + } +} + +static void +ephy_location_action_activate (GtkAction *action) +{ + GSList *proxies; + + /* Note: this makes sense only for a single proxy */ + proxies = gtk_action_get_proxies (action); + + if (proxies) + { + ephy_location_entry_activate (EPHY_LOCATION_ENTRY (proxies->data)); + } +} + +static void ephy_location_action_class_init (EphyLocationActionClass *class) { - GtkActionClass *action_class; GObjectClass *object_class = G_OBJECT_CLASS (class); + GtkActionClass *action_class = GTK_ACTION_CLASS (class); parent_class = g_type_class_peek_parent (class); - action_class = GTK_ACTION_CLASS (class); + + object_class->finalize = ephy_location_action_finalize; + object_class->get_property = ephy_location_action_get_property; + object_class->set_property = ephy_location_action_set_property; action_class->toolbar_item_type = EPHY_TYPE_LOCATION_ENTRY; action_class->connect_proxy = connect_proxy; + action_class->disconnect_proxy = disconnect_proxy; + action_class->activate = ephy_location_action_activate; - ephy_location_action_signals[GO_LOCATION] = + signals[GO_LOCATION] = g_signal_new ("go_location", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_FIRST, @@ -138,27 +261,70 @@ ephy_location_action_class_init (EphyLocationActionClass *class) G_TYPE_NONE, 1, G_TYPE_STRING); + + g_object_class_install_property (object_class, + PROP_ADDRESS, + g_param_spec_string ("address", + "Address", + "The address", + "", + G_PARAM_READWRITE)); + + g_type_class_add_private (object_class, sizeof (EphyLocationActionPrivate)); } static void ephy_location_action_init (EphyLocationAction *action) { + action->priv = EPHY_LOCATION_ACTION_GET_PRIVATE (action); + + action->priv->address = g_strdup (""); +} + +static void +ephy_location_action_finalize (GObject *object) +{ + EphyLocationAction *action = EPHY_LOCATION_ACTION (object); + + g_free (action->priv->address); } -GtkWidget * -ephy_location_action_get_widget (EphyLocationAction *action) +const char * +ephy_location_action_get_address (EphyLocationAction *action) { - GSList *slist; + g_return_val_if_fail (EPHY_IS_LOCATION_ACTION (action), ""); - slist = gtk_action_get_proxies (GTK_ACTION (action)); + return action->priv->address; +} - if (slist) - { - return GTK_WIDGET (slist->data); - } - else +void +ephy_location_action_set_address (EphyLocationAction *action, + const char *address) +{ + g_return_if_fail (EPHY_IS_LOCATION_ACTION (action)); + + LOG ("set_address %s", address) + + g_free (action->priv->address); + action->priv->address = g_strdup (address ? address : ""); + g_object_notify (G_OBJECT (action), "address"); +} + +static void +clear_history (GtkWidget *proxy, gpointer user_data) +{ + if (EPHY_IS_LOCATION_ENTRY (proxy)) { - return NULL; + ephy_location_entry_clear_history (EPHY_LOCATION_ENTRY (proxy)); } } +void +ephy_location_action_clear_history (EphyLocationAction *action) +{ + GSList *proxies; + + proxies = gtk_action_get_proxies (GTK_ACTION (action)); + + g_slist_foreach (proxies, (GFunc) clear_history, NULL); +} |