[Epiphany] [patch] Favicons in tabs



The attached patch implements this.

Regards,
 Christian.

diff -urN epiphany/ChangeLog epiphany-modified/ChangeLog
--- epiphany/ChangeLog	2003-03-28 14:20:45.000000000 +0100
+++ epiphany-modified/ChangeLog	2003-03-28 14:47:18.000000000 +0100
@@ -1,3 +1,15 @@
+2003-03-28  Christian Persch  <chpe+epiphany@stud.uni-saarland.de>
+
+	Display favicons in tabs.
+
+	* lib/widgets/ephy-notebook.[ch]: (ephy_notebook_set_favicon):
+	New function.
+	* lib/widgets/ephy-notebook.c:
+	(tab_build_label), (ephy_notebook_set_page_status)
+	* src/ephy-tab.c: (ephy_tab_set_favicon),
+	(ephy_tab_favicon_cache_changed_cb): new functions
+	(ephy_tab_favicon_cb), (ephy_tab_location_cb)
+
 2003-03-27  Xan Lopez  <xan@masilla.org>
 
 	* src/bookmarks/ephy-node-view.c: (ephy_node_view_select_all):
diff -urN epiphany/lib/widgets/ephy-notebook.c epiphany-modified/lib/widgets/ephy-notebook.c
--- epiphany/lib/widgets/ephy-notebook.c	2003-02-14 19:52:56.000000000 +0100
+++ epiphany-modified/lib/widgets/ephy-notebook.c	2003-03-28 14:36:13.000000000 +0100
@@ -634,7 +634,7 @@
 			       GtkWidget *child,
 			       EphyNotebookPageLoadStatus status)
 {
-	GtkWidget *tab, *image;
+	GtkWidget *tab, *image, *favicon;
 
 	g_return_if_fail (nb != NULL);
 
@@ -650,22 +650,48 @@
 	image  = g_object_get_data (G_OBJECT (tab), "loading-image");
 
 	g_return_if_fail (image != NULL);
+	
+	favicon = g_object_get_data (G_OBJECT (tab), "favicon");
+
+	g_return_if_fail (favicon != NULL);
 
 	switch (status)
 	{
 		case EPHY_NOTEBOOK_TAB_LOAD_LOADING:
+			gtk_widget_hide (favicon);
 			gtk_widget_show (image);
 			break;
 
 		case EPHY_NOTEBOOK_TAB_LOAD_COMPLETED:
 		case EPHY_NOTEBOOK_TAB_LOAD_NORMAL:
 			gtk_widget_hide (image);
+			gtk_widget_show (favicon);
 			break;
 	}
 
 	nb->priv->current_status = status;
 }
 
+void
+ephy_notebook_set_favicon (EphyNotebook *nb,
+			   GtkWidget *child,
+			   GdkPixbuf *favicon)
+{
+	GtkWidget *tab, *image;
+
+	g_return_if_fail (nb != NULL);
+
+	tab = gtk_notebook_get_tab_label (GTK_NOTEBOOK (nb), child);
+
+	g_return_if_fail (tab != NULL);
+
+	image  = g_object_get_data (G_OBJECT (tab), "favicon");
+
+	g_return_if_fail (image != NULL);
+
+	gtk_image_set_from_pixbuf (GTK_IMAGE (image), favicon);
+}
+
 static void
 ephy_tab_close_button_clicked_cb (GtkWidget *widget,
 				  GtkWidget *child)
@@ -683,7 +709,7 @@
 	int h, w;
 	GClosure *closure;
 	GtkWidget *window;
-	GtkWidget *loading_image;
+	GtkWidget *loading_image, *favicon;
 	GdkPixbufAnimation *loading_pixbuf;
 
 	window = gtk_widget_get_toplevel (GTK_WIDGET (nb));
@@ -710,6 +736,10 @@
 	g_object_unref (loading_pixbuf);
 	gtk_box_pack_start (GTK_BOX (hbox), loading_image, FALSE, FALSE, 0);
 
+	/* setup favicon image*/
+	favicon = gtk_image_new ();
+	gtk_box_pack_start (GTK_BOX (hbox), favicon, FALSE, FALSE, 0);
+
 	/* setup label */
         label = gtk_label_new (_("Untitled"));
 	gtk_misc_set_alignment (GTK_MISC (label), 0.00, 0.5);
@@ -742,6 +772,7 @@
 
 	g_object_set_data (G_OBJECT (hbox), "label", label);
 	g_object_set_data (G_OBJECT (hbox), "loading-image", loading_image);
+	g_object_set_data (G_OBJECT (hbox), "favicon", favicon);
 
 	return hbox;
 }
diff -urN epiphany/lib/widgets/ephy-notebook.h epiphany-modified/lib/widgets/ephy-notebook.h
--- epiphany/lib/widgets/ephy-notebook.h	2002-12-30 20:27:38.000000000 +0100
+++ epiphany-modified/lib/widgets/ephy-notebook.h	2003-03-28 14:36:13.000000000 +0100
@@ -94,6 +94,10 @@
 						 GtkWidget *child,
 						 const char *title);
 
+void		ephy_notebook_set_favicon	(EphyNotebook *nb,
+						 GtkWidget *child,
+						 GdkPixbuf *favicon);
+
 G_END_DECLS;
 
 #endif /* EPHY_NOTEBOOK_H */
diff -urN epiphany/src/ephy-tab.c epiphany-modified/src/ephy-tab.c
--- epiphany/src/ephy-tab.c	2003-02-28 20:22:58.000000000 +0100
+++ epiphany-modified/src/ephy-tab.c	2003-03-28 14:36:13.000000000 +0100
@@ -61,6 +61,7 @@
 	int total_requests;
 	int width;
 	int height;
+	gulong fav_handler_id;
 };
 
 static void
@@ -120,6 +121,10 @@
 ephy_tab_zoom_changed_cb (EphyEmbed *embed, gint zoom,
 			  EphyTab *tab);
 
+static void
+ephy_tab_set_favicon	 (EphyTab *tab, 
+			  GdkPixbuf *pixbuf);
+
 static GObjectClass *parent_class = NULL;
 
 /* Class functions */
@@ -211,7 +216,7 @@
 	tab->priv->cur_requests = 0;
 	tab->priv->width = -1;
 	tab->priv->height = -1;
-
+	tab->priv->fav_handler_id = 0;
 
 	embed = G_OBJECT (tab->priv->embed);
 	embed_widget = G_OBJECT (tab->priv->embed);
@@ -440,15 +445,89 @@
 /* Private callbacks for embed signals */
 
 static void
+ephy_tab_set_favicon	 (EphyTab *tab, 
+			  GdkPixbuf *pixbuf)
+{
+	GtkWidget *nb;
+
+	nb = ephy_window_get_notebook (tab->priv->window);
+	ephy_notebook_set_favicon (EPHY_NOTEBOOK (nb),
+				   GTK_WIDGET (tab->priv->embed),
+				   pixbuf);
+	if (pixbuf != NULL)
+	{
+		g_object_unref (pixbuf);
+	}
+}
+
+
+static void
+ephy_tab_favicon_cache_changed_cb (EphyFaviconCache *cache, char *url, EphyTab *tab)
+{
+	GdkPixbuf *pixbuf = NULL;
+
+	LOG ("ephy_tab_favicon_cache_changed_cb tab_id=%lu, url=%s",
+	     tab->priv->fav_handler_id, url);
+
+	/* is this for us? */
+	if (strncmp (tab->priv->favicon_url, url, 255) != 0) return;
+
+	/* we got what we want, now disconnect */
+	g_signal_handler_disconnect (cache, tab->priv->fav_handler_id);
+	tab->priv->fav_handler_id = 0;
+
+	/* set favicon */
+	pixbuf = ephy_favicon_cache_get (cache, tab->priv->favicon_url);
+	ephy_tab_set_favicon (tab, pixbuf);
+}
+
+static void
 ephy_tab_favicon_cb (EphyEmbed *embed,
 		     const char *url,
 		     EphyTab *tab)
 {
 	EphyBookmarks *eb;
+	EphyFaviconCache *cache;
+	GdkPixbuf *pixbuf = NULL;
 
-	g_strlcpy (tab->priv->favicon_url,
-		   url, 255);
+	g_strlcpy (tab->priv->favicon_url, url, 255);
+
+	cache = ephy_embed_shell_get_favicon_cache
+		(EPHY_EMBED_SHELL (ephy_shell));
 
+	if (tab->priv->fav_handler_id != 0)
+	{
+		LOG ("ephy_tab_favicon_cb disconnecting cache callback, id=%lu",
+		     tab->priv->fav_handler_id)
+		
+		g_signal_handler_disconnect (cache, tab->priv->fav_handler_id);
+		tab->priv->fav_handler_id = 0;
+	}	
+
+	if (url && url[0] != '\0')
+	{
+		pixbuf = ephy_favicon_cache_get (cache, tab->priv->favicon_url);
+		ephy_tab_set_favicon (tab, pixbuf);
+		if (pixbuf == NULL)
+		{
+			/* favicon not cached yet, call back later */
+			tab->priv->fav_handler_id =  g_signal_connect_object (
+					G_OBJECT (cache),
+					"changed",
+					G_CALLBACK
+					(ephy_tab_favicon_cache_changed_cb),
+					tab,
+					0);
+			
+			LOG("ephy_tab_favicon_cb cache callback connected, id=%lu, url=%s",
+			    tab->priv->fav_handler_id, tab->priv->favicon_url)
+		}
+	}
+	else
+	{
+		ephy_tab_set_favicon (tab, NULL);
+	}
+	
 	if (!tab->priv->is_active) return;
 
 	eb = ephy_shell_get_bookmarks (ephy_shell);
@@ -480,6 +559,7 @@
 				 &tab->priv->location);
 	tab->priv->link_message[0] = '\0';
 	tab->priv->favicon_url[0] = '\0';
+	ephy_tab_set_favicon (tab, NULL);
 
 	if (tab->priv->is_active)
 	{


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]