uri = katze_item_get_uri (pitem);
if (uri)
{
- pixbuf = katze_net_load_icon (panel->net, uri, NULL, NULL, NULL);
+ pixbuf = katze_load_cached_icon (uri, NULL);
if (!pixbuf)
pixbuf = panel->pixbuf;
}
icon = gtk_widget_render_icon (menuitem,
GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);
else
- icon = katze_net_load_icon (array_action->net,
- katze_item_get_uri (item), NULL, proxy, NULL);
+ icon = katze_load_cached_icon (katze_item_get_uri (item), proxy);
image = gtk_image_new_from_pixbuf (icon);
g_object_unref (icon);
}
}
else if (!KATZE_IS_ARRAY (item) && !strcmp (property, "uri"))
{
- icon = katze_net_load_icon (array_action->net, katze_item_get_uri (item),
- NULL, GTK_WIDGET (toolitem), NULL);
+ icon = katze_load_cached_icon (katze_item_get_uri (item), GTK_WIDGET (toolitem));
image = gtk_image_new_from_pixbuf (icon);
g_object_unref (icon);
gtk_widget_show (image);
icon = gtk_widget_render_icon (menuitem,
GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);
else
- icon = katze_net_load_icon (array_action->net,
- katze_item_get_uri (item), NULL, proxy, NULL);
+ icon = katze_load_cached_icon (katze_item_get_uri (item), proxy);
image = gtk_image_new_from_pixbuf (icon);
g_object_unref (icon);
}
icon = gtk_widget_render_icon (GTK_WIDGET (toolitem),
GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);
else
- icon = katze_net_load_icon (array_action->net, uri,
- NULL, GTK_WIDGET (toolitem), NULL);
+ icon = katze_load_cached_icon (uri, GTK_WIDGET (toolitem));
image = gtk_image_new_from_pixbuf (icon);
g_object_unref (icon);
gtk_widget_show (image);
#include <glib/gstdio.h>
#include <glib/gi18n.h>
#include <gio/gio.h>
+#include <libsoup/soup.h>
#include <string.h>
return enabled;
}
}
+
+/**
+ * katze_load_cached_icon:
+ * @uri: an URI string
+ * @widget: a #GtkWidget, or %NULL
+ *
+ * Loads a cached icon for the specified @uri. If there is no
+ * icon and @widget is specified, a default will be returned.
+ *
+ * Returns: a #GdkPixbuf, or %NULL
+ *
+ * Since: 0.2.2
+ */
+GdkPixbuf*
+katze_load_cached_icon (const gchar* uri,
+ GtkWidget* widget)
+{
+ GdkPixbuf* icon = NULL;
+
+ if (g_str_has_prefix (uri, "http://"))
+ {
+ guint i;
+ gchar* icon_uri;
+ gchar* checksum;
+ gchar* ext;
+ gchar* filename;
+ gchar* path;
+
+ i = 8;
+ while (uri[i] != '\0' && uri[i] != '/')
+ i++;
+ if (uri[i] == '/')
+ {
+ icon_uri = g_strdup (uri);
+ icon_uri[i] = '\0';
+ icon_uri = g_strdup_printf ("%s/favicon.ico", icon_uri);
+ }
+ else
+ icon_uri = g_strdup_printf ("%s/favicon.ico", uri);
+
+ checksum = g_compute_checksum_for_string (G_CHECKSUM_MD5, icon_uri, -1);
+ ext = g_strrstr (icon_uri, ".");
+ g_free (icon_uri);
+ filename = g_strdup_printf ("%s%s", checksum, ext ? ext : "");
+ g_free (checksum);
+ path = g_build_filename (g_get_user_cache_dir (), PACKAGE_NAME,
+ "icons", filename, NULL);
+ if ((icon = gdk_pixbuf_new_from_file_at_size (path, 16, 16, NULL)))
+ {
+ g_free (path);
+ return icon;
+ }
+ g_free (path);
+ }
+
+ return icon || !widget ? icon : gtk_widget_render_icon (widget,
+ GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL);
+}
gboolean
katze_widget_has_touchscreen_mode (GtkWidget* widget);
+GdkPixbuf*
+katze_load_cached_icon (const gchar* uri,
+ GtkWidget* widget);
+
G_END_DECLS
#endif /* __KATZE_UTILS_H__ */
gtk_tree_model_get (model, iter, URI_COL, &uri, TITLE_COL, &title,
FAVICON_COL, &icon, -1);
- if (G_UNLIKELY (!icon))
+ if (G_UNLIKELY (!icon) && uri)
{
#if !HAVE_HILDON
MidoriLocationAction* action
= g_object_get_data (G_OBJECT (renderer), "location-action");
- icon = katze_net_load_icon (action->net, uri, NULL, NULL, NULL);
- if (G_LIKELY (icon))
+ if ((icon = katze_load_cached_icon (uri, NULL)))
{
midori_location_action_set_icon_for_uri (action, icon, uri);
g_object_unref (icon);
midori_location_action_set_icon_for_uri (action, action->default_icon, uri);
#endif
}
- else
+ else if (icon)
g_object_unref (icon);
desc = desc_uri = desc_title = key = NULL;
}
if ((icon = katze_item_get_uri (item)) && (g_strstr_len (icon, 8, "://")))
- return katze_net_load_icon (net, icon, NULL, widget, NULL);
+ return katze_load_cached_icon (icon, widget);
return gtk_widget_render_icon (widget, GTK_STOCK_FILE,
GTK_ICON_SIZE_MENU, NULL);
pixbuf = gtk_widget_render_icon (treeview, GTK_STOCK_DIRECTORY,
GTK_ICON_SIZE_MENU, NULL);
else if (katze_item_get_uri (item))
- pixbuf = katze_net_load_icon (
- MIDORI_BOOKMARKS (gtk_widget_get_parent (treeview))->net,
- katze_item_get_uri (item), NULL, treeview, NULL);
+ pixbuf = katze_load_cached_icon (katze_item_get_uri (item), treeview);
g_object_set (renderer, "pixbuf", pixbuf, NULL);
if (pixbuf)
pixbuf = gtk_widget_render_icon (treeview, GTK_STOCK_DIRECTORY,
GTK_ICON_SIZE_MENU, NULL);
else
- pixbuf = katze_net_load_icon (
- MIDORI_HISTORY (gtk_widget_get_parent (treeview))->net,
- katze_item_get_uri (item), NULL, treeview, NULL);
+ pixbuf = katze_load_cached_icon (katze_item_get_uri (item), treeview);
g_object_set (renderer, "pixbuf", pixbuf, NULL);