diff options
author | Christian Persch <chpe@cvs.gnome.org> | 2005-07-27 01:41:04 +0800 |
---|---|---|
committer | Christian Persch <chpe@src.gnome.org> | 2005-07-27 01:41:04 +0800 |
commit | fc69f229f306940d351fd20606fe6a77104ef48d (patch) | |
tree | 4ebf2c194552d38c330a9ac974b5c38abe1b198c /src | |
parent | 185ea56fa4d1b5626ff1418a90d979f3cc15b108 (diff) | |
download | gsoc2013-epiphany-fc69f229f306940d351fd20606fe6a77104ef48d.tar gsoc2013-epiphany-fc69f229f306940d351fd20606fe6a77104ef48d.tar.gz gsoc2013-epiphany-fc69f229f306940d351fd20606fe6a77104ef48d.tar.bz2 gsoc2013-epiphany-fc69f229f306940d351fd20606fe6a77104ef48d.tar.lz gsoc2013-epiphany-fc69f229f306940d351fd20606fe6a77104ef48d.tar.xz gsoc2013-epiphany-fc69f229f306940d351fd20606fe6a77104ef48d.tar.zst gsoc2013-epiphany-fc69f229f306940d351fd20606fe6a77104ef48d.zip |
Unify bookmarks/smart bookmarks address resolution, and add a signal to
2005-07-26 Christian Persch <chpe@cvs.gnome.org>
* lib/ephy-marshal.list:
* src/bookmarks/ephy-bookmark-action.c: (open_in_tab_activate_cb),
(open_in_window_activate_cb), (activate_cb):
* src/bookmarks/ephy-bookmarks.c: (ephy_bookmarks_class_init),
(impl_resolve_address), (ephy_bookmarks_resolve_address):
* src/bookmarks/ephy-bookmarks.h:
* src/bookmarks/ephy-topic-action.c: (menu_activate_cb),
(open_in_tabs_activate_cb):
* src/ephy-location-action.c: (action_activated_cb),
(entry_activate_cb):
* src/epiphany.defs:
Unify bookmarks/smart bookmarks address resolution, and add a signal
to EphyBookmarks for it.
Diffstat (limited to 'src')
-rw-r--r-- | src/bookmarks/ephy-bookmark-action.c | 90 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks.c | 52 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmarks.h | 9 | ||||
-rw-r--r-- | src/bookmarks/ephy-topic-action.c | 24 | ||||
-rw-r--r-- | src/ephy-location-action.c | 17 | ||||
-rw-r--r-- | src/epiphany.defs | 8 |
6 files changed, 132 insertions, 68 deletions
diff --git a/src/bookmarks/ephy-bookmark-action.c b/src/bookmarks/ephy-bookmark-action.c index 983b2aedb..f7459c477 100644 --- a/src/bookmarks/ephy-bookmark-action.c +++ b/src/bookmarks/ephy-bookmark-action.c @@ -308,81 +308,79 @@ static void open_in_tab_activate_cb (GtkWidget *widget, EphyBookmarkAction *action) { - const char *url; + EphyBookmarkActionPrivate *priv = action->priv; + EphyBookmarks *bookmarks; + const char *location; + char *address; - g_return_if_fail (action->priv->node != NULL); + g_return_if_fail (priv->node != NULL); - url = ephy_node_get_property_string (action->priv->node, - EPHY_NODE_BMK_PROP_LOCATION); - ephy_link_open (EPHY_LINK (action), url, NULL, + location = ephy_node_get_property_string + (priv->node, EPHY_NODE_BMK_PROP_LOCATION); + g_return_if_fail (location != NULL); + + bookmarks = ephy_shell_get_bookmarks (ephy_shell_get_default ()); + address = ephy_bookmarks_resolve_address (bookmarks, location, NULL); + g_return_if_fail (address != NULL); + + ephy_link_open (EPHY_LINK (action), address, NULL, EPHY_LINK_NEW_TAB | EPHY_LINK_JUMP_TO); + + g_free (address); } static void open_in_window_activate_cb (GtkWidget *widget, EphyBookmarkAction *action) { - const char *url; + EphyBookmarkActionPrivate *priv = action->priv; + EphyBookmarks *bookmarks; + const char *location; + char *address; - g_return_if_fail (action->priv->node != NULL); + g_return_if_fail (priv->node != NULL); + + location = ephy_node_get_property_string + (priv->node, EPHY_NODE_BMK_PROP_LOCATION); + g_return_if_fail (location != NULL); + + bookmarks = ephy_shell_get_bookmarks (ephy_shell_get_default ()); + address = ephy_bookmarks_resolve_address (bookmarks, location, NULL); + g_return_if_fail (address != NULL); - url = ephy_node_get_property_string (action->priv->node, - EPHY_NODE_BMK_PROP_LOCATION); + ephy_link_open (EPHY_LINK (action), address, NULL, EPHY_LINK_NEW_WINDOW); - ephy_link_open (EPHY_LINK (action), url, NULL, EPHY_LINK_NEW_WINDOW); + g_free (address); } static void activate_cb (GtkWidget *widget, EphyBookmarkAction *action) { - const char *url; - char *location = NULL, *text = NULL; + EphyBookmarkActionPrivate *priv = action->priv; + EphyBookmarks *bookmarks; + const char *location; + char *address, *text = NULL; - g_return_if_fail (action->priv->node != NULL); + g_return_if_fail (priv->node != NULL); - url = ephy_node_get_property_string (action->priv->node, - EPHY_NODE_BMK_PROP_LOCATION); + location = ephy_node_get_property_string + (priv->node, EPHY_NODE_BMK_PROP_LOCATION); + g_return_if_fail (location != NULL); if (GTK_IS_EDITABLE (widget)) { text = gtk_editable_get_chars (GTK_EDITABLE (widget), 0, -1); } - if (text != NULL && text[0] != '\0') - { - EphyBookmarks *bookmarks; - - bookmarks = ephy_shell_get_bookmarks (ephy_shell); - - location = ephy_bookmarks_solve_smart_url (bookmarks, - url, - text); - } - else - { - if (action->priv->smart_url) - { - GnomeVFSURI *uri; - - uri = gnome_vfs_uri_new (url); - - if (uri) - { - location = g_strdup (gnome_vfs_uri_get_host_name (uri)); - gnome_vfs_uri_unref (uri); - } - } + bookmarks = ephy_shell_get_bookmarks (ephy_shell_get_default ()); - if (location == NULL) - { - location = g_strdup (url); - } - } + address = ephy_bookmarks_resolve_address (bookmarks, location, text); + g_return_if_fail (address != NULL); - ephy_link_open (EPHY_LINK (action), location, NULL, + ephy_link_open (EPHY_LINK (action), address, NULL, ephy_gui_is_middle_click () ? EPHY_LINK_NEW_TAB : 0); - g_free (location); + g_free (address); g_free (text); } diff --git a/src/bookmarks/ephy-bookmarks.c b/src/bookmarks/ephy-bookmarks.c index 948679577..b81ae3d46 100644 --- a/src/bookmarks/ephy-bookmarks.c +++ b/src/bookmarks/ephy-bookmarks.c @@ -35,6 +35,8 @@ #include "ephy-bookmarks-import.h" #include "ephy-bookmark-properties.h" #include "ephy-prefs.h" +#include "ephy-marshal.h" +#include "ephy-signal-accumulator.h" #include "eel-gconf-extensions.h" @@ -116,6 +118,7 @@ enum enum { TREE_CHANGED, + RESOLVE_ADDRESS, LAST_SIGNAL }; @@ -124,6 +127,7 @@ static guint ephy_bookmarks_signals[LAST_SIGNAL] = { 0 }; static void ephy_bookmarks_class_init (EphyBookmarksClass *klass); static void ephy_bookmarks_init (EphyBookmarks *tab); static void ephy_bookmarks_finalize (GObject *object); +static char *impl_resolve_address (EphyBookmarks*, const char*, const char*); static GObjectClass *parent_class = NULL; @@ -295,8 +299,10 @@ ephy_bookmarks_class_init (EphyBookmarksClass *klass) object_class->set_property = ephy_bookmarks_set_property; object_class->get_property = ephy_bookmarks_get_property; + klass->resolve_address = impl_resolve_address; + ephy_bookmarks_signals[TREE_CHANGED] = - g_signal_new ("tree_changed", + g_signal_new ("tree-changed", G_OBJECT_CLASS_TYPE (object_class), G_SIGNAL_RUN_LAST, G_STRUCT_OFFSET (EphyBookmarksClass, tree_changed), @@ -305,6 +311,18 @@ ephy_bookmarks_class_init (EphyBookmarksClass *klass) G_TYPE_NONE, 0); + ephy_bookmarks_signals[RESOLVE_ADDRESS] = + g_signal_new ("resolve-address", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_LAST, + G_STRUCT_OFFSET (EphyBookmarksClass, resolve_address), + ephy_signal_accumulator_string, NULL, + ephy_marshal_STRING__STRING_STRING, + G_TYPE_STRING, + 2, + G_TYPE_STRING, + G_TYPE_STRING); + g_object_class_install_property (object_class, PROP_TOOLBARS_MODEL, g_param_spec_object ("toolbars-model", @@ -1315,20 +1333,22 @@ get_option (char *start, return g_strndup (start, end - start); } -char * -ephy_bookmarks_solve_smart_url (EphyBookmarks *eb, - const char *smart_url, - const char *content) +static char * +impl_resolve_address (EphyBookmarks *eb, + const char *address, + const char *content) { GString *result; char *pos, *oldpos, *arg, *escaped_arg, *encoding, *optionsend; - if (content == NULL || smart_url == NULL) return NULL; + if (address == NULL) return NULL; - result = g_string_new_len (NULL, strlen (content) + strlen (smart_url)); + if (content == NULL) content = ""; + + result = g_string_new_len (NULL, strlen (content) + strlen (address)); /* substitute %s's */ - oldpos = (char*) smart_url; + oldpos = (char*) address; while ((pos = strstr (oldpos, "%s")) != NULL) { g_string_append_len (result, oldpos, pos - oldpos); @@ -1371,6 +1391,22 @@ ephy_bookmarks_solve_smart_url (EphyBookmarks *eb, return g_string_free (result, FALSE); } +char * +ephy_bookmarks_resolve_address (EphyBookmarks *eb, + const char *address, + const char *parameter) +{ + char *retval = NULL; + + g_return_val_if_fail (EPHY_IS_BOOKMARKS (eb), NULL); + g_return_val_if_fail (address != NULL, NULL); + + g_signal_emit (eb, ephy_bookmarks_signals[RESOLVE_ADDRESS], 0, + address, parameter, &retval); + + return retval; +} + guint ephy_bookmarks_get_smart_bookmark_width (EphyNode *bookmark) { diff --git a/src/bookmarks/ephy-bookmarks.h b/src/bookmarks/ephy-bookmarks.h index 64073a211..cae6b82ba 100644 --- a/src/bookmarks/ephy-bookmarks.h +++ b/src/bookmarks/ephy-bookmarks.h @@ -66,6 +66,9 @@ struct _EphyBookmarksClass GObjectClass parent_class; void (* tree_changed) (EphyBookmarks *eb); + char * (* resolve_address) (EphyBookmarks *eb, + const char *address, + const char *argument); }; GType ephy_bookmarks_get_type (void); @@ -94,9 +97,9 @@ void ephy_bookmarks_set_address (EphyBookmarks *eb, EphyNode *bookmark, const char *address); -char *ephy_bookmarks_solve_smart_url (EphyBookmarks *eb, - const char *smart_url, - const char *content); +char *ephy_bookmarks_resolve_address (EphyBookmarks *eb, + const char *address, + const char *parameter); guint ephy_bookmarks_get_smart_bookmark_width (EphyNode *bookmark); diff --git a/src/bookmarks/ephy-topic-action.c b/src/bookmarks/ephy-topic-action.c index 1ca923fb2..51cb42e60 100644 --- a/src/bookmarks/ephy-topic-action.c +++ b/src/bookmarks/ephy-topic-action.c @@ -161,15 +161,24 @@ menu_deactivate_cb (GtkMenuShell *ms, GtkWidget *button) static void menu_activate_cb (GtkWidget *item, GtkAction *action) { + EphyBookmarks *bookmarks; EphyNode *node; const char *location; + char *address; node = g_object_get_data (G_OBJECT (item), "node"); location = ephy_node_get_property_string (node, EPHY_NODE_BMK_PROP_LOCATION); + g_return_if_fail (location != NULL); + + bookmarks = ephy_shell_get_bookmarks (ephy_shell_get_default ()); + address = ephy_bookmarks_resolve_address (bookmarks, location, NULL); + g_return_if_fail (address != NULL); - ephy_link_open (EPHY_LINK (action), location, NULL, + ephy_link_open (EPHY_LINK (action), address, NULL, ephy_gui_is_middle_click () ? EPHY_LINK_NEW_TAB : 0); + + g_free (address); } static void @@ -332,6 +341,7 @@ append_bookmarks_menu (EphyTopicAction *action, GtkWidget *menu, EphyNode *node, static void open_in_tabs_activate_cb (GtkWidget *item, EphyTopicAction *action) { + EphyBookmarks *bookmarks; EphyNode *node; GPtrArray *children; EphyTab *tab = NULL; @@ -350,16 +360,24 @@ open_in_tabs_activate_cb (GtkWidget *item, EphyTopicAction *action) node_list = g_list_sort (node_list, (GCompareFunc) sort_bookmarks); + bookmarks = ephy_shell_get_bookmarks (ephy_shell_get_default ()); + for (l = node_list; l != NULL; l = l->next) { EphyNode *child = (EphyNode *) l->data; - const char *address; + const char *location; + char *address; - address = ephy_node_get_property_string + location = ephy_node_get_property_string (child, EPHY_NODE_BMK_PROP_LOCATION); + g_return_if_fail (location != NULL); + + address = ephy_bookmarks_resolve_address (bookmarks, location, NULL); + g_return_if_fail (address != NULL); tab = ephy_link_open (EPHY_LINK (action), address, tab, tab ? EPHY_LINK_NEW_TAB : EPHY_LINK_NEW_WINDOW); + g_free (address); } g_list_free (node_list); diff --git a/src/ephy-location-action.c b/src/ephy-location-action.c index 73d4456a3..1abf8c43b 100644 --- a/src/ephy-location-action.c +++ b/src/ephy-location-action.c @@ -133,7 +133,7 @@ action_activated_cb (GtkEntryCompletion *completion, (node, EPHY_NODE_BMK_PROP_LOCATION); g_return_if_fail (smart_url != NULL); - url = ephy_bookmarks_solve_smart_url + url = ephy_bookmarks_resolve_address (action->priv->bookmarks, smart_url, content); g_return_if_fail (url != NULL); @@ -148,13 +148,20 @@ static void entry_activate_cb (GtkEntry *entry, EphyLocationAction *action) { - const char *content; + EphyBookmarks *bookmarks; GdkEvent *event; gboolean control = FALSE; + const char *content; + char *address; content = gtk_entry_get_text (entry); if (content == NULL || content[0] == '\0') return; + bookmarks = ephy_shell_get_bookmarks (ephy_shell_get_default ()); + + address = ephy_bookmarks_resolve_address (bookmarks, content, NULL); + g_return_if_fail (address != NULL); + event = gtk_get_current_event (); if (event) { @@ -167,9 +174,11 @@ entry_activate_cb (GtkEntry *entry, gdk_event_free (event); } - - ephy_link_open (EPHY_LINK (action), content, NULL, + /* FIXME use ephy_bookmarks_resolve_address here too? */ + ephy_link_open (EPHY_LINK (action), address, NULL, control ? EPHY_LINK_NEW_TAB : 0); + + g_free (address); } static void diff --git a/src/epiphany.defs b/src/epiphany.defs index 5526d2562..ef00b7585 100644 --- a/src/epiphany.defs +++ b/src/epiphany.defs @@ -1965,13 +1965,13 @@ ) ) -(define-method solve_smart_url +(define-method resolve_address (of-object "EphyBookmarks") - (c-name "ephy_bookmarks_solve_smart_url") + (c-name "ephy_bookmarks_resolve_address") (return-type "char*") (parameters - '("const-char*" "smart_url") - '("const-char*" "content") + '("const-char*" "address") + '("const-char*" "parameter") ) ) |