aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorChristian Persch <chpe@cvs.gnome.org>2003-09-20 17:37:26 +0800
committerChristian Persch <chpe@src.gnome.org>2003-09-20 17:37:26 +0800
commit68616208eeeee369e62c9256fc9aba5dbe139e3e (patch)
tree279fbbbeb9bfb24372c9a3a9b6d169284c877e8d
parentf7c6e1db094b8f4da058aaec9b2faa9498326b59 (diff)
downloadgsoc2013-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.
-rw-r--r--ChangeLog35
-rw-r--r--lib/widgets/ephy-location-entry.c62
-rw-r--r--lib/widgets/ephy-location-entry.h7
-rw-r--r--src/ephy-location-action.c224
-rw-r--r--src/ephy-location-action.h20
-rwxr-xr-xsrc/toolbar.c161
-rw-r--r--src/toolbar.h2
-rw-r--r--src/window-commands.c3
8 files changed, 351 insertions, 163 deletions
diff --git a/ChangeLog b/ChangeLog
index 4b8697589..ff0993e42 100644
--- a/ChangeLog
+++ b/ChangeLog
@@ -1,5 +1,40 @@
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.
+
+2003-09-20 Christian Persch <chpe@cvs.gnome.org>
+
* lib/widgets/ephy-tree-model-node.c:
(ephy_tree_model_node_init):
diff --git a/lib/widgets/ephy-location-entry.c b/lib/widgets/ephy-location-entry.c
index 0f2fb663b..e7b30f867 100644
--- a/lib/widgets/ephy-location-entry.c
+++ b/lib/widgets/ephy-location-entry.c
@@ -1,5 +1,6 @@
/*
* 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
@@ -32,6 +33,7 @@
#include <gtk/gtkwindow.h>
#include <gdk/gdkkeysyms.h>
#include <gtk/gtkmain.h>
+#include <gtk/gtktoolbar.h>
#include <gtk/gtktooltips.h>
#include <libgnomeui/gnome-entry.h>
#include <string.h>
@@ -53,6 +55,7 @@ struct _EphyLocationEntryPrivate {
gboolean block_set_autocompletion_key;
gboolean going_to_site;
gboolean user_changed;
+ gboolean activation_mode;
char *autocompletion_key;
char *last_action_target;
@@ -111,7 +114,6 @@ static GObjectClass *parent_class = NULL;
*/
enum EphyLocationEntrySignalsEnum {
ACTIVATED,
- FINISHED,
USER_CHANGED,
LAST_SIGNAL
};
@@ -184,15 +186,6 @@ ephy_location_entry_class_init (EphyLocationEntryClass *klass)
2,
G_TYPE_STRING,
G_TYPE_STRING);
- EphyLocationEntrySignals[FINISHED] = g_signal_new (
- "finished", G_OBJECT_CLASS_TYPE (klass),
- G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST | G_SIGNAL_RUN_CLEANUP,
- G_STRUCT_OFFSET (EphyLocationEntryClass, finished),
- NULL, NULL,
- g_cclosure_marshal_VOID__VOID,
- G_TYPE_NONE,
- 0,
- G_TYPE_NONE);
EphyLocationEntrySignals[USER_CHANGED] = g_signal_new (
"user_changed", G_OBJECT_CLASS_TYPE (klass),
G_SIGNAL_RUN_FIRST | G_SIGNAL_RUN_LAST | G_SIGNAL_RUN_CLEANUP,
@@ -206,10 +199,25 @@ ephy_location_entry_class_init (EphyLocationEntryClass *klass)
g_type_class_add_private (object_class, sizeof (EphyLocationEntryPrivate));
}
+static void
+ephy_location_entry_activation_finished (EphyLocationEntry *entry)
+{
+ if (entry->priv->activation_mode)
+ {
+ GtkWidget *toolbar;
+
+ entry->priv->activation_mode = FALSE;
+
+ toolbar = gtk_widget_get_ancestor (GTK_WIDGET (entry),
+ GTK_TYPE_TOOLBAR);
+ gtk_widget_hide (toolbar);
+ }
+}
+
static gboolean
location_focus_out_cb (GtkWidget *widget, GdkEventFocus *event, EphyLocationEntry *w)
{
- g_signal_emit (w, EphyLocationEntrySignals[FINISHED], 0);
+ ephy_location_entry_activation_finished (w);
return FALSE;
}
@@ -227,6 +235,7 @@ ephy_location_entry_init (EphyLocationEntry *w)
p->last_action_target = NULL;
p->before_completion = NULL;
p->user_changed = TRUE;
+ p->activation_mode = FALSE;
p->autocompletion_key = NULL;
ephy_location_entry_construct_contents (w);
@@ -325,7 +334,7 @@ ephy_location_entry_construct_contents (EphyLocationEntry *w)
static gboolean
ephy_location_ignore_prefix (EphyLocationEntry *w)
{
- char *text;
+ const char *text;
int text_len;
int i, k;
gboolean result = FALSE;
@@ -335,6 +344,8 @@ ephy_location_ignore_prefix (EphyLocationEntry *w)
};
text = ephy_location_entry_get_location (w);
+ g_return_val_if_fail (text != NULL, FALSE);
+
text_len = g_utf8_strlen (text, -1);
for (i = 0; prefixes[i] != NULL; i++)
@@ -351,8 +362,6 @@ ephy_location_ignore_prefix (EphyLocationEntry *w)
}
}
- g_free (text);
-
return result;
}
@@ -550,7 +559,7 @@ ephy_location_entry_activate_cb (GtkEntry *entry, EphyLocationEntry *w)
LOG ("In ephy_location_entry_activate_cb, activating %s", content)
g_signal_emit (w, EphyLocationEntrySignals[ACTIVATED], 0, content, target);
- g_signal_emit (w, EphyLocationEntrySignals[FINISHED], 0);
+ ephy_location_entry_activation_finished (w);
g_free (content);
g_free (target);
@@ -580,6 +589,8 @@ ephy_location_entry_set_location (EphyLocationEntry *w,
EphyLocationEntryPrivate *p = w->priv;
int pos;
+ g_return_if_fail (new_location != NULL);
+
p->user_changed = FALSE;
g_signal_handlers_block_by_func (G_OBJECT (p->entry),
@@ -598,11 +609,10 @@ ephy_location_entry_set_location (EphyLocationEntry *w,
p->user_changed = TRUE;
}
-gchar *
+const char *
ephy_location_entry_get_location (EphyLocationEntry *w)
{
- char *location = gtk_editable_get_chars (GTK_EDITABLE (w->priv->entry), 0, -1);
- return location;
+ return gtk_entry_get_text (GTK_ENTRY (w->priv->entry));
}
static void
@@ -717,7 +727,16 @@ ephy_location_entry_autocompletion_window_hidden_cb (EphyAutocompletionWindow *a
void
ephy_location_entry_activate (EphyLocationEntry *w)
{
- GtkWidget *toplevel;
+ GtkWidget *toplevel, *toolbar;
+
+ toolbar = gtk_widget_get_ancestor (GTK_WIDGET (w), GTK_TYPE_TOOLBAR);
+
+ if (!GTK_WIDGET_VISIBLE (toolbar))
+ {
+ w->priv->activation_mode = TRUE;
+
+ gtk_widget_show (toolbar);
+ }
toplevel = gtk_widget_get_toplevel (w->priv->entry);
@@ -727,7 +746,6 @@ ephy_location_entry_activate (EphyLocationEntry *w)
w->priv->entry);
}
-
static void
ephy_location_entry_list_event_after_cb (GtkWidget *list,
GdkEvent *event,
@@ -749,13 +767,12 @@ ephy_location_entry_editable_changed_cb (GtkEditable *editable, EphyLocationEntr
if (p->going_to_site)
{
- char *url = ephy_location_entry_get_location (e);
+ const char *url = ephy_location_entry_get_location (e);
if (url && url[0] != '\0')
{
p->going_to_site = FALSE;
g_signal_emit (e, EphyLocationEntrySignals[ACTIVATED], 0, NULL, url);
}
- g_free (url);
}
if (p->user_changed)
@@ -786,4 +803,3 @@ ephy_location_entry_clear_history (EphyLocationEntry *w)
{
gnome_entry_clear_history (GNOME_ENTRY (w->priv->combo));
}
-
diff --git a/lib/widgets/ephy-location-entry.h b/lib/widgets/ephy-location-entry.h
index 8af364cd7..e4ad695d8 100644
--- a/lib/widgets/ephy-location-entry.h
+++ b/lib/widgets/ephy-location-entry.h
@@ -1,5 +1,6 @@
/*
* 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
@@ -15,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_LOCATION_ENTRY_H
@@ -53,8 +56,6 @@ struct _EphyLocationEntryClass
const char *content,
const char *target);
- void (*finished) (EphyLocationEntry *w);
-
void (*user_changed) (EphyLocationEntry *w);
};
@@ -70,7 +71,7 @@ GType ephy_location_entry_get_type (void);
GtkWidget *ephy_location_entry_new (void);
void ephy_location_entry_set_location (EphyLocationEntry *w,
const gchar *new_location);
-gchar *ephy_location_entry_get_location (EphyLocationEntry *w);
+const char *ephy_location_entry_get_location (EphyLocationEntry *w);
void ephy_location_entry_set_autocompletion (EphyLocationEntry *w,
EphyAutocompletion *ac);
void ephy_location_entry_activate (EphyLocationEntry *w);
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);
}
}