aboutsummaryrefslogtreecommitdiffstats
path: root/src/ephy-location-action.c
diff options
context:
space:
mode:
Diffstat (limited to 'src/ephy-location-action.c')
-rw-r--r--src/ephy-location-action.c224
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);
+}