Re: [Epiphany] [patch] Favicons in tabs
- From: Christian Persch <chpe stud uni-saarland de>
- To: epiphany devel list <epiphany mozdev org>
- Cc: "mpeseng tin it" <mpeseng tin it>
- Subject: Re: [Epiphany] [patch] Favicons in tabs
- Date: 31 Mar 2003 11:16:34 +0200
Hi,
Here's what I hope to be the final version of my patch.
Changes since last version:
- remove the favicon_cache_changed_cb in src/ephy-window.c,
it's not needed anymore since every tab gets notified
individually, including the active tab
- move some code from ephy_tab_favicon_cb to ephy_tab_set_favicon,
so that it gets executed regardless of whether the favicon was
found directly or by cache callback
Regards,
Christian.
--- epiphany/lib/widgets/ephy-notebook.h 2002-12-30 20:27:38.000000000 +0100
+++ epiphany-build/lib/widgets/ephy-notebook.h 2003-03-30 19:35:07.000000000 +0200
@@ -94,6 +94,10 @@
GtkWidget *child,
const char *title);
+void ephy_notebook_set_page_icon (EphyNotebook *nb,
+ GtkWidget *child,
+ GdkPixbuf *icon);
+
G_END_DECLS;
#endif /* EPHY_NOTEBOOK_H */
--- epiphany/lib/widgets/ephy-notebook.c 2003-02-14 19:52:56.000000000 +0100
+++ epiphany-build/lib/widgets/ephy-notebook.c 2003-03-30 19:35:50.000000000 +0200
@@ -634,7 +634,7 @@
GtkWidget *child,
EphyNotebookPageLoadStatus status)
{
- GtkWidget *tab, *image;
+ GtkWidget *tab, *image, *icon;
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);
+
+ icon = g_object_get_data (G_OBJECT (tab), "icon");
+
+ g_return_if_fail (icon != NULL);
switch (status)
{
case EPHY_NOTEBOOK_TAB_LOAD_LOADING:
+ gtk_widget_hide (icon);
gtk_widget_show (image);
break;
case EPHY_NOTEBOOK_TAB_LOAD_COMPLETED:
case EPHY_NOTEBOOK_TAB_LOAD_NORMAL:
gtk_widget_hide (image);
+ gtk_widget_show (icon);
break;
}
nb->priv->current_status = status;
}
+void
+ephy_notebook_set_page_icon (EphyNotebook *nb,
+ GtkWidget *child,
+ GdkPixbuf *icon)
+{
+ 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), "icon");
+
+ g_return_if_fail (image != NULL);
+
+ gtk_image_set_from_pixbuf (GTK_IMAGE (image), icon);
+}
+
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, *icon;
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 site icon, empty by default */
+ icon = gtk_image_new ();
+ gtk_box_pack_start (GTK_BOX (hbox), icon, 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), "icon", icon);
return hbox;
}
--- epiphany/src/ephy-tab.h 2003-01-20 19:57:20.000000000 +0100
+++ epiphany-build/src/ephy-tab.h 2003-03-30 19:34:47.000000000 +0200
@@ -95,6 +95,9 @@
void ephy_tab_set_location (EphyTab *tab,
char *location);
+void ephy_tab_set_favicon (EphyTab *tab,
+ GdkPixbuf *favicon);
+
void ephy_tab_get_size (EphyTab *tab,
int *width,
int *height);
--- epiphany/src/ephy-tab.c 2003-02-28 20:22:58.000000000 +0100
+++ epiphany-build/src/ephy-tab.c 2003-03-31 10:55:21.000000000 +0200
@@ -81,6 +82,10 @@
const char *url,
EphyTab *tab);
static void
+ephy_tab_favicon_cache_changed_cb (EphyFaviconCache *cache,
+ char *url,
+ EphyTab *tab);
+static void
ephy_tab_link_message_cb (EphyEmbed *embed,
const char *message,
EphyTab *tab);
@@ -187,6 +192,7 @@
{
GObject *embed, *embed_widget;
EphyEmbedSingle *single;
+ EphyFaviconCache *cache;
single = ephy_embed_shell_get_embed_single
(EPHY_EMBED_SHELL (ephy_shell));
@@ -267,6 +272,11 @@
g_signal_connect (embed, "ge_favicon",
GTK_SIGNAL_FUNC (ephy_tab_favicon_cb),
tab);
+
+ cache = ephy_embed_shell_get_favicon_cache (EPHY_EMBED_SHELL (ephy_shell));
+ g_signal_connect_object (G_OBJECT (cache), "changed",
+ G_CALLBACK (ephy_tab_favicon_cache_changed_cb),
+ tab, 0);
}
/* Destructor */
@@ -437,25 +447,70 @@
tab->priv->visibility = visible;
}
+void
+ephy_tab_set_favicon (EphyTab *tab,
+ GdkPixbuf *favicon)
+{
+ GtkWidget *nb;
+ EphyBookmarks *eb;
+
+ nb = ephy_window_get_notebook (tab->priv->window);
+ ephy_notebook_set_page_icon (EPHY_NOTEBOOK (nb),
+ GTK_WIDGET (tab->priv->embed),
+ favicon);
+
+ if (!tab->priv->is_active) return;
+
+ eb = ephy_shell_get_bookmarks (ephy_shell);
+ ephy_bookmarks_set_icon (eb, tab->priv->location,
+ tab->priv->favicon_url);
+ ephy_window_update_control (tab->priv->window,
+ FaviconControl);
+}
+
/* Private callbacks for embed signals */
static void
+ephy_tab_favicon_cache_changed_cb (EphyFaviconCache *cache,
+ char *url,
+ EphyTab *tab)
+{
+ GdkPixbuf *pixbuf = NULL;
+
+ /* is this for us? */
+ if (strncmp (tab->priv->favicon_url, url, 255) != 0) return;
+
+ /* set favicon */
+ pixbuf = ephy_favicon_cache_get (cache, tab->priv->favicon_url);
+ ephy_tab_set_favicon (tab, pixbuf);
+
+ if (pixbuf) g_object_unref (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);
- if (!tab->priv->is_active) return;
+ cache = ephy_embed_shell_get_favicon_cache
+ (EPHY_EMBED_SHELL (ephy_shell));
- eb = ephy_shell_get_bookmarks (ephy_shell);
- ephy_bookmarks_set_icon (eb, tab->priv->location,
- tab->priv->favicon_url);
- ephy_window_update_control (tab->priv->window,
- FaviconControl);
+ if (url && url[0] != '\0')
+ {
+ pixbuf = ephy_favicon_cache_get (cache, tab->priv->favicon_url);
+ ephy_tab_set_favicon (tab, pixbuf);
+ if (pixbuf) g_object_unref (pixbuf);
+ }
+ else
+ {
+ ephy_tab_set_favicon (tab, NULL);
+ }
}
static void
@@ -479,7 +534,9 @@
ephy_embed_get_location (embed, TRUE,
&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)
{
--- epiphany/src/ephy-window.c 2003-03-26 10:26:05.000000000 +0100
+++ epiphany-modified/src/ephy-window.c 2003-03-31 11:02:38.000000000 +0200
@@ -489,16 +489,9 @@
}
static void
-favicon_cache_changed_cb (EphyFaviconCache *cache, char *url, EphyWindow *window)
-{
- ephy_window_update_control (window, FaviconControl);
-}
-
-static void
ephy_window_init (EphyWindow *window)
{
Session *session;
- EphyFaviconCache *cache;
session = ephy_shell_get_session (ephy_shell);
@@ -509,13 +502,6 @@
window->priv->ppview_toolbar = NULL;
window->priv->toolbars = NULL;
- cache = ephy_embed_shell_get_favicon_cache (EPHY_EMBED_SHELL (ephy_shell));
- g_signal_connect_object (G_OBJECT (cache),
- "changed",
- G_CALLBACK (favicon_cache_changed_cb),
- window,
- 0);
-
/* Setup the window and connect verbs */
setup_window (window);
[
Date Prev][Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]