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 | |
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')
-rw-r--r-- | src/ephy-location-action.c | 224 | ||||
-rw-r--r-- | src/ephy-location-action.h | 20 | ||||
-rwxr-xr-x | src/toolbar.c | 161 | ||||
-rw-r--r-- | src/toolbar.h | 2 | ||||
-rw-r--r-- | src/window-commands.c | 3 |
5 files changed, 273 insertions, 137 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); +} diff --git a/src/ephy-location-action.h b/src/ephy-location-action.h index fd27ec8b8..8058eb64f 100644 --- a/src/ephy-location-action.h +++ b/src/ephy-location-action.h @@ -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_LOCATION_ACTION_H @@ -30,12 +32,15 @@ G_BEGIN_DECLS #define EPHY_IS_LOCATION_ACTION_CLASS(klass) (G_TYPE_CHECK_CLASS_TYPE ((obj), EPHY_TYPE_LOCATION_ACTION)) #define EPHY_LOCATION_ACTION_GET_CLASS(obj) (G_TYPE_INSTANCE_GET_CLASS((obj), EPHY_TYPE_LOCATION_ACTION, EphyLocationActionClass)) -typedef struct _EphyLocationAction EphyLocationAction; -typedef struct _EphyLocationActionClass EphyLocationActionClass; - +typedef struct _EphyLocationAction EphyLocationAction; +typedef struct _EphyLocationActionClass EphyLocationActionClass; +typedef struct _EphyLocationActionPrivate EphyLocationActionPrivate; + struct _EphyLocationAction { GtkAction parent; + + EphyLocationActionPrivate *priv; }; struct _EphyLocationActionClass @@ -45,9 +50,14 @@ struct _EphyLocationActionClass void (*go_location) (EphyLocationAction *action, char *location); }; -GType ephy_location_action_get_type (void); +GType ephy_location_action_get_type (void); + +const char *ephy_location_action_get_address (EphyLocationAction *action); + +void ephy_location_action_set_address (EphyLocationAction *action, + const char *address); -GtkWidget *ephy_location_action_get_widget (EphyLocationAction *action); +void ephy_location_action_clear_history (EphyLocationAction *action); G_END_DECLS diff --git a/src/toolbar.c b/src/toolbar.c index 326a47f71..a1b4553f1 100755 --- a/src/toolbar.c +++ b/src/toolbar.c @@ -87,7 +87,7 @@ struct ToolbarPrivate GtkUIManager *ui_merge; GtkActionGroup *action_group; gboolean visibility; - gboolean can_set_location; + gboolean updating_address; GtkWidget *spinner; GtkWidget *favicon; GtkWidget *go; @@ -217,8 +217,8 @@ toolbar_class_init (ToolbarClass *klass) g_object_class_install_property (object_class, PROP_EPHY_WINDOW, - g_param_spec_object ("EphyWindow", - "EphyWindow", + g_param_spec_object ("window", + "Window", "Parent window", EPHY_TYPE_WINDOW, G_PARAM_READWRITE | @@ -238,8 +238,8 @@ toolbar_set_property (GObject *object, switch (prop_id) { case PROP_EPHY_WINDOW: - toolbar_set_window (t, g_value_get_object (value)); - break; + toolbar_set_window (t, g_value_get_object (value)); + break; } } @@ -260,6 +260,26 @@ toolbar_get_property (GObject *object, } static void +sync_user_input_cb (EphyLocationAction *action, GParamSpec *pspec, Toolbar *t) +{ + EphyTab *tab; + const char *address; + + LOG ("sync_user_input_cb") + + if (t->priv->updating_address) return; + + tab = ephy_window_get_active_tab (t->priv->window); + g_return_if_fail (EPHY_IS_TAB (tab)); + + address = ephy_location_action_get_address (action); + + t->priv->updating_address = TRUE; + ephy_tab_set_location (tab, address, TAB_ADDRESS_EXPIRE_CURRENT); + t->priv->updating_address = FALSE; +} + +static void toolbar_setup_actions (Toolbar *t) { GtkAction *action; @@ -324,6 +344,8 @@ toolbar_setup_actions (Toolbar *t) NULL); g_signal_connect (action, "go_location", G_CALLBACK (go_location_cb), t->priv->window); + g_signal_connect (action, "notify::address", + G_CALLBACK (sync_user_input_cb), t); gtk_action_group_add_action (t->priv->action_group, action); g_object_unref (action); @@ -430,36 +452,6 @@ update_toolbar_remove_flag (EphyToolbarsModel *model, gpointer data) } } -static GtkWidget * -get_location_entry (Toolbar *t) -{ - GtkAction *action; - GtkWidget *location; - - action = gtk_action_group_get_action - (t->priv->action_group, "Location"); - location = ephy_location_action_get_widget - (EPHY_LOCATION_ACTION (action)); - - return location; -} - -static void -location_user_changed_cb (GtkWidget *entry, Toolbar *t) -{ - EphyTab *tab; - char *address; - - tab = ephy_window_get_active_tab (t->priv->window); - g_return_if_fail (EPHY_IS_TAB (tab)); - - t->priv->can_set_location = FALSE; - address = ephy_location_entry_get_location (EPHY_LOCATION_ENTRY (entry)); - ephy_tab_set_location (tab, address, TAB_ADDRESS_EXPIRE_CURRENT); - g_free (address); - t->priv->can_set_location = TRUE; -} - static void init_normal_mode (Toolbar *t) { @@ -536,10 +528,6 @@ toolbar_set_window (Toolbar *t, EphyWindow *window) NULL); init_normal_mode (t); - - g_signal_connect_object (get_location_entry (t), "user_changed", - G_CALLBACK (location_user_changed_cb), - t, 0); } static void @@ -550,19 +538,13 @@ toolbar_init (Toolbar *t) t->priv->window = NULL; t->priv->ui_merge = NULL; t->priv->visibility = TRUE; - t->priv->can_set_location = TRUE; + t->priv->updating_address = FALSE; } static void toolbar_finalize (GObject *object) { - Toolbar *t; - ToolbarPrivate *p; - GtkUIManager *merge; - - t = EPHY_TOOLBAR (object); - p = t->priv; - merge = GTK_UI_MANAGER (t->priv->window->ui_merge); + Toolbar *t = EPHY_TOOLBAR (object); /* FIXME: why not at the end? */ G_OBJECT_CLASS (parent_class)->finalize (object); @@ -575,46 +557,21 @@ toolbar_finalize (GObject *object) Toolbar * toolbar_new (EphyWindow *window) { - Toolbar *t; - - t = EPHY_TOOLBAR (g_object_new (EPHY_TYPE_TOOLBAR, - "EphyWindow", window, - NULL)); - - return t; -} - -static void -location_finished_cb (GtkWidget *location, GtkWidget *toolbar) -{ - gtk_widget_hide (toolbar); - - g_signal_handlers_disconnect_by_func (G_OBJECT (location), - G_CALLBACK (location_finished_cb), - toolbar); + return EPHY_TOOLBAR (g_object_new (EPHY_TYPE_TOOLBAR, + "window", window, + NULL)); } void toolbar_activate_location (Toolbar *t) { - GtkWidget *location; - GtkWidget *location_tb; - - location = get_location_entry (t); - g_return_if_fail (location != NULL); - - location_tb = gtk_widget_get_ancestor (location, GTK_TYPE_TOOLBAR); - g_return_if_fail (location_tb != NULL); + GtkActionGroup *action_group; + GtkAction *action; - if (!GTK_WIDGET_VISIBLE (location_tb)) - { - g_signal_connect (location, "finished", - G_CALLBACK (location_finished_cb), location_tb); - gtk_widget_show (location_tb); - } + action_group = t->priv->action_group; + action = gtk_action_group_get_action (action_group, "Location"); - ephy_location_entry_activate - (EPHY_LOCATION_ENTRY(location)); + gtk_action_activate (action); } void @@ -641,19 +598,22 @@ toolbar_spinner_stop (Toolbar *t) void toolbar_set_location (Toolbar *t, - const char *alocation) + const char *address) { - GtkWidget *location; + GtkActionGroup *action_group; + GtkAction *action; - if (t->priv->can_set_location) - { - location = get_location_entry (t); - g_return_if_fail (location != NULL); + LOG ("toolbar set location %s", address) + LOG ("updating is %d", t->priv->updating_address) - ephy_location_entry_set_location - (EPHY_LOCATION_ENTRY (location), - alocation ? alocation : ""); - } + if (t->priv->updating_address) return; + + action_group = t->priv->action_group; + action = gtk_action_group_get_action (action_group, "Location"); + + t->priv->updating_address = TRUE; + ephy_location_action_set_address (EPHY_LOCATION_ACTION (action), address); + t->priv->updating_address = FALSE; } void @@ -671,27 +631,28 @@ toolbar_update_favicon (Toolbar *t) g_object_set (action, "icon", url, NULL); } -char * +const char * toolbar_get_location (Toolbar *t) { - GtkWidget *location; + GtkActionGroup *action_group; + GtkAction *action; - location = get_location_entry (t); - g_return_val_if_fail (location != NULL, NULL); + action_group = t->priv->action_group; + action = gtk_action_group_get_action (action_group, "Location"); - return ephy_location_entry_get_location - (EPHY_LOCATION_ENTRY (location)); + return ephy_location_action_get_address (EPHY_LOCATION_ACTION (action)); } void toolbar_clear_location_history (Toolbar *t) { - GtkWidget *location; + GtkActionGroup *action_group; + GtkAction *action; - location = get_location_entry (t), - g_return_if_fail (location != NULL); + action_group = t->priv->action_group; + action = gtk_action_group_get_action (action_group, "Location"); - ephy_location_entry_clear_history (EPHY_LOCATION_ENTRY (location)); + ephy_location_action_clear_history (EPHY_LOCATION_ACTION (action)); } void diff --git a/src/toolbar.h b/src/toolbar.h index a9d598ae8..f62021a20 100644 --- a/src/toolbar.h +++ b/src/toolbar.h @@ -56,7 +56,7 @@ void toolbar_spinner_start (Toolbar *t); void toolbar_spinner_stop (Toolbar *t); -char *toolbar_get_location (Toolbar *t); +const char *toolbar_get_location (Toolbar *t); void toolbar_set_location (Toolbar *t, const char *location); diff --git a/src/window-commands.c b/src/window-commands.c index b111ef50f..e4dcac9d5 100644 --- a/src/window-commands.c +++ b/src/window-commands.c @@ -915,7 +915,7 @@ window_cmd_load_location (GtkAction *action, EphyWindow *window) { Toolbar *toolbar; - char *location; + const char *location; toolbar = ephy_window_get_toolbar (window); location = toolbar_get_location (toolbar); @@ -923,7 +923,6 @@ window_cmd_load_location (GtkAction *action, if (location) { ephy_window_load_url (window, location); - g_free (location); } } |