diff options
author | Marco Pesenti Gritti <marco@it.gnome.org> | 2003-01-26 01:03:04 +0800 |
---|---|---|
committer | Marco Pesenti Gritti <mpeseng@src.gnome.org> | 2003-01-26 01:03:04 +0800 |
commit | f0ed62fd5de56876d5257d6def06a761aa364e09 (patch) | |
tree | 9395c41e4e4a13299a0869c3a360c85c438f49d7 | |
parent | 19a39f46e3982211744c0162812faa129190ee1f (diff) | |
download | gsoc2013-epiphany-f0ed62fd5de56876d5257d6def06a761aa364e09.tar gsoc2013-epiphany-f0ed62fd5de56876d5257d6def06a761aa364e09.tar.gz gsoc2013-epiphany-f0ed62fd5de56876d5257d6def06a761aa364e09.tar.bz2 gsoc2013-epiphany-f0ed62fd5de56876d5257d6def06a761aa364e09.tar.lz gsoc2013-epiphany-f0ed62fd5de56876d5257d6def06a761aa364e09.tar.xz gsoc2013-epiphany-f0ed62fd5de56876d5257d6def06a761aa364e09.tar.zst gsoc2013-epiphany-f0ed62fd5de56876d5257d6def06a761aa364e09.zip |
Complete bookmark action implementation (with smb too)
2003-01-25 Marco Pesenti Gritti <marco@it.gnome.org>
* configure.in:
* src/bookmarks/ephy-bookmark-action.c: (create_tool_item),
(ephy_bookmark_action_sync_icon),
(ephy_bookmark_action_sync_label), (entry_activated_cb),
(button_clicked_cb), (connect_proxy),
(ephy_bookmark_action_set_property),
(ephy_bookmark_action_finalize), (ephy_bookmark_action_class_init),
(ephy_bookmark_action_init), (ephy_bookmark_action_new):
* src/bookmarks/ephy-bookmark-action.h:
* src/ephy-favicon-action.c: (ephy_favicon_action_sync_icon):
Complete bookmark action implementation (with smb too)
-rw-r--r-- | ChangeLog | 15 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmark-action.c | 220 | ||||
-rw-r--r-- | src/bookmarks/ephy-bookmark-action.h | 2 | ||||
-rw-r--r-- | src/ephy-favicon-action.c | 1 |
4 files changed, 228 insertions, 10 deletions
@@ -1,3 +1,18 @@ +2003-01-25 Marco Pesenti Gritti <marco@it.gnome.org> + + * configure.in: + * src/bookmarks/ephy-bookmark-action.c: (create_tool_item), + (ephy_bookmark_action_sync_icon), + (ephy_bookmark_action_sync_label), (entry_activated_cb), + (button_clicked_cb), (connect_proxy), + (ephy_bookmark_action_set_property), + (ephy_bookmark_action_finalize), (ephy_bookmark_action_class_init), + (ephy_bookmark_action_init), (ephy_bookmark_action_new): + * src/bookmarks/ephy-bookmark-action.h: + * src/ephy-favicon-action.c: (ephy_favicon_action_sync_icon): + + Complete bookmark action implementation (with smb too) + 2003-01-24 Marco Pesenti Gritti <marco@it.gnome.org> * NEWS: diff --git a/src/bookmarks/ephy-bookmark-action.c b/src/bookmarks/ephy-bookmark-action.c index 8ce9e9f4c..59e27fd09 100644 --- a/src/bookmarks/ephy-bookmark-action.c +++ b/src/bookmarks/ephy-bookmark-action.c @@ -28,16 +28,30 @@ static void ephy_bookmark_action_class_init (EphyBookmarkActionClass *class); struct EphyBookmarkActionPrivate { int bookmark_id; + char *location; + char *smart_url; + char *icon; }; enum { PROP_0, - PROP_BOOKMARK_ID + PROP_BOOKMARK_ID, + PROP_LOCATION, + PROP_SMART_URL, + PROP_ICON +}; + +enum +{ + GO_LOCATION, + LAST_SIGNAL }; static GObjectClass *parent_class = NULL; +static guint ephy_bookmark_action_signals[LAST_SIGNAL] = { 0 }; + GType ephy_bookmark_action_get_type (void) { @@ -72,48 +86,152 @@ create_tool_item (EggAction *action) GtkWidget *button; GtkWidget *hbox; GtkWidget *label; + GtkWidget *icon; item = (* EGG_ACTION_CLASS (parent_class)->create_tool_item) (action); + hbox = gtk_hbox_new (FALSE, 0); + gtk_widget_show (hbox); + gtk_container_add (GTK_CONTAINER (item), hbox); + button = gtk_button_new (); gtk_button_set_relief (GTK_BUTTON (button), GTK_RELIEF_NONE); gtk_widget_show (button); + gtk_container_add (GTK_CONTAINER (hbox), button); + g_object_set_data (G_OBJECT (item), "button", button); + + if (EPHY_BOOKMARK_ACTION (action)->priv->smart_url) + { + GtkWidget *entry; + + entry = gtk_entry_new (); + gtk_widget_show (entry); + gtk_box_pack_start (GTK_BOX (hbox), entry, TRUE, TRUE, 0); + g_object_set_data (G_OBJECT (item), "entry", entry); + } hbox = gtk_hbox_new (FALSE, 0); gtk_widget_show (hbox); gtk_container_add (GTK_CONTAINER (button), hbox); + icon = gtk_image_new (); + gtk_widget_show (icon); + gtk_box_pack_start (GTK_BOX (hbox), icon, TRUE, TRUE, 0); + g_object_set_data (G_OBJECT (item), "icon", icon); + label = gtk_label_new (NULL); gtk_widget_show (label); gtk_box_pack_start (GTK_BOX (hbox), label, TRUE, TRUE, 0); - - gtk_container_add (GTK_CONTAINER (item), button); - g_object_set_data (G_OBJECT (item), "button", label); + g_object_set_data (G_OBJECT (item), "label", label); return item; } static void +ephy_bookmark_action_sync_icon (EggAction *action, GParamSpec *pspec, GtkWidget *proxy) +{ + char *icon_location; + GtkImage *icon; + EphyFaviconCache *cache; + GdkPixbuf *pixbuf = NULL; + + icon = GTK_IMAGE (g_object_get_data (G_OBJECT (proxy), "icon")); + g_return_if_fail (icon != NULL); + + icon_location = EPHY_BOOKMARK_ACTION (action)->priv->icon; + + cache = ephy_embed_shell_get_favicon_cache + (EPHY_EMBED_SHELL (ephy_shell)); + + if (icon_location) + { + pixbuf = ephy_favicon_cache_get (cache, icon_location); + } + + if (pixbuf) + { + gtk_image_set_from_pixbuf (icon, pixbuf); + g_object_unref (pixbuf); + } + else + { + gtk_image_set_from_stock (icon, + GTK_STOCK_JUMP_TO, + GTK_ICON_SIZE_MENU); + } +} + +static void ephy_bookmark_action_sync_label (EggAction *action, GParamSpec *pspec, GtkWidget *proxy) { GtkLabel *label; LOG ("Set bookmark action proxy label to %s", action->label) - label = GTK_LABEL (g_object_get_data (G_OBJECT (proxy), "button")); + label = GTK_LABEL (g_object_get_data (G_OBJECT (proxy), "label")); g_return_if_fail (label != NULL); gtk_label_set_label (label, action->label); } static void +entry_activated_cb (GtkWidget *entry, EggAction *action) +{ + char *text; + char *solved; + char *smart_url; + EphyBookmarks *bookmarks; + + bookmarks = ephy_shell_get_bookmarks (ephy_shell); + + text = gtk_editable_get_chars (GTK_EDITABLE (entry), 0, -1); + if (text == NULL) return; + + smart_url = EPHY_BOOKMARK_ACTION (action)->priv->smart_url; + solved = ephy_bookmarks_solve_smart_url (bookmarks, + smart_url, + text); + g_signal_emit (action, + ephy_bookmark_action_signals[GO_LOCATION], + 0, solved); + + g_free (text); + g_free (smart_url); +} + +static void +button_clicked_cb (GtkWidget *button, EggAction *action) +{ + g_signal_emit (action, + ephy_bookmark_action_signals[GO_LOCATION], + 0, EPHY_BOOKMARK_ACTION (action)->priv->location); +} + +static void connect_proxy (EggAction *action, GtkWidget *proxy) { - (* EGG_ACTION_CLASS (parent_class)->connect_proxy) (action, proxy); + GtkWidget *button; - ephy_bookmark_action_sync_label (action, NULL, proxy); - g_signal_connect_object (action, "notify::label", - G_CALLBACK (ephy_bookmark_action_sync_label), proxy, 0); + (* EGG_ACTION_CLASS (parent_class)->connect_proxy) (action, proxy); + + ephy_bookmark_action_sync_label (action, NULL, proxy); + g_signal_connect_object (action, "notify::label", + G_CALLBACK (ephy_bookmark_action_sync_label), proxy, 0); + + ephy_bookmark_action_sync_icon (action, NULL, proxy); + g_signal_connect_object (action, "notify::icon", + G_CALLBACK (ephy_bookmark_action_sync_icon), proxy, 0); + + button = GTK_WIDGET (g_object_get_data (G_OBJECT (proxy), "button")); + g_signal_connect (button, "clicked", G_CALLBACK (button_clicked_cb), action); + + if (EPHY_BOOKMARK_ACTION (action)->priv->smart_url) + { + GtkWidget *entry; + + entry = GTK_WIDGET (g_object_get_data (G_OBJECT (proxy), "entry")); + g_signal_connect (entry, "activate", G_CALLBACK (entry_activated_cb), action); + } } static void @@ -131,6 +249,19 @@ ephy_bookmark_action_set_property (GObject *object, case PROP_BOOKMARK_ID: bmk->priv->bookmark_id = g_value_get_int (value); break; + case PROP_LOCATION: + g_free (bmk->priv->location); + bmk->priv->location = g_strdup (g_value_get_string (value)); + break; + case PROP_SMART_URL: + g_free (bmk->priv->smart_url); + bmk->priv->smart_url = g_strdup (g_value_get_string (value)); + break; + case PROP_ICON: + g_free (bmk->priv->icon); + bmk->priv->icon = g_strdup (g_value_get_string (value)); + g_object_notify(object, "icon"); + break; } } @@ -153,6 +284,28 @@ ephy_bookmark_action_get_property (GObject *object, } static void +ephy_bookmark_action_finalize (GObject *object) +{ + EphyBookmarkAction *eba; + + g_return_if_fail (EPHY_IS_BOOKMARK_ACTION (object)); + + eba = EPHY_BOOKMARK_ACTION (object); + + g_return_if_fail (eba->priv != NULL); + + g_free (eba->priv->location); + g_free (eba->priv->smart_url); + g_free (eba->priv->icon); + + g_free (eba->priv); + + LOG ("Bookmark action finalized") + + G_OBJECT_CLASS (parent_class)->finalize (object); +} + +static void ephy_bookmark_action_class_init (EphyBookmarkActionClass *class) { EggActionClass *action_class; @@ -165,9 +318,21 @@ ephy_bookmark_action_class_init (EphyBookmarkActionClass *class) action_class->create_tool_item = create_tool_item; action_class->connect_proxy = connect_proxy; + object_class->finalize = ephy_bookmark_action_finalize; object_class->set_property = ephy_bookmark_action_set_property; object_class->get_property = ephy_bookmark_action_get_property; + ephy_bookmark_action_signals[GO_LOCATION] = + g_signal_new ("go_location", + G_OBJECT_CLASS_TYPE (object_class), + G_SIGNAL_RUN_FIRST, + G_STRUCT_OFFSET (EphyBookmarkActionClass, go_location), + NULL, NULL, + g_cclosure_marshal_VOID__STRING, + G_TYPE_NONE, + 1, + G_TYPE_STRING); + g_object_class_install_property (object_class, PROP_BOOKMARK_ID, g_param_spec_int ("bookmark_id", @@ -177,19 +342,44 @@ ephy_bookmark_action_class_init (EphyBookmarkActionClass *class) G_MAXINT, 0, G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_LOCATION, + g_param_spec_string ("location", + "Location", + "Location", + NULL, + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_SMART_URL, + g_param_spec_string ("smart_url", + "Smart url", + "Smart url", + NULL, + G_PARAM_READWRITE)); + g_object_class_install_property (object_class, + PROP_ICON, + g_param_spec_string ("icon", + "Icon", + "Icon", + NULL, + G_PARAM_READWRITE)); } static void ephy_bookmark_action_init (EphyBookmarkAction *action) { action->priv = g_new0 (EphyBookmarkActionPrivate, 1); + + action->priv->location = NULL; + action->priv->smart_url = NULL; + action->priv->icon = NULL; } EggAction * ephy_bookmark_action_new (const char *name, guint id) { EphyNode *bmk; - const char *title; + const char *title, *location, *smart_url, *icon; EphyBookmarks *bookmarks; bookmarks = ephy_shell_get_bookmarks (ephy_shell); @@ -197,12 +387,22 @@ ephy_bookmark_action_new (const char *name, guint id) bmk = ephy_node_get_from_id (id); g_return_val_if_fail (bmk != NULL, NULL); + icon = ephy_node_get_property_string + (bmk, EPHY_NODE_BMK_PROP_ICON); title = ephy_node_get_property_string (bmk, EPHY_NODE_BMK_PROP_TITLE); + location = ephy_node_get_property_string + (bmk, EPHY_NODE_BMK_PROP_LOCATION); + smart_url = ephy_node_get_property_string + (bmk, EPHY_NODE_BMK_PROP_SMART_LOCATION); + if (smart_url && *smart_url == '\0') smart_url = NULL; return EGG_ACTION (g_object_new (EPHY_TYPE_BOOKMARK_ACTION, "name", name, "label", title, + "location", location, + "smart_url", smart_url, + "icon", icon, NULL)); } diff --git a/src/bookmarks/ephy-bookmark-action.h b/src/bookmarks/ephy-bookmark-action.h index ca67b0d0c..2aa7a7ed0 100644 --- a/src/bookmarks/ephy-bookmark-action.h +++ b/src/bookmarks/ephy-bookmark-action.h @@ -42,6 +42,8 @@ struct _EphyBookmarkAction struct _EphyBookmarkActionClass { EggActionClass parent_class; + + void (*go_location) (EphyBookmarkAction *action, char *location); }; GType ephy_bookmark_action_get_type (void); diff --git a/src/ephy-favicon-action.c b/src/ephy-favicon-action.c index 91605cf67..87fddc8db 100644 --- a/src/ephy-favicon-action.c +++ b/src/ephy-favicon-action.c @@ -143,6 +143,7 @@ ephy_favicon_action_sync_icon (EggAction *action, GParamSpec *pspec, if (pixbuf) { gtk_image_set_from_pixbuf (GTK_IMAGE (image), pixbuf); + g_object_unref (pixbuf); } else { |