Refactor loading cached page icon into katze_load_cached_icon
The function is optimized for loading icons and independant from a KatzeNet instance.
This commit is contained in:
parent
ba70a6fd5a
commit
9eefb25bb6
8 changed files with 74 additions and 20 deletions
|
@ -91,7 +91,7 @@ feed_panel_treeview_render_icon_cb (GtkTreeViewColumn* column,
|
||||||
uri = katze_item_get_uri (pitem);
|
uri = katze_item_get_uri (pitem);
|
||||||
if (uri)
|
if (uri)
|
||||||
{
|
{
|
||||||
pixbuf = katze_net_load_icon (panel->net, uri, NULL, NULL, NULL);
|
pixbuf = katze_load_cached_icon (uri, NULL);
|
||||||
if (!pixbuf)
|
if (!pixbuf)
|
||||||
pixbuf = panel->pixbuf;
|
pixbuf = panel->pixbuf;
|
||||||
}
|
}
|
||||||
|
|
|
@ -301,8 +301,7 @@ katze_array_action_generate_menu (KatzeArrayAction* array_action,
|
||||||
icon = gtk_widget_render_icon (menuitem,
|
icon = gtk_widget_render_icon (menuitem,
|
||||||
GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);
|
GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);
|
||||||
else
|
else
|
||||||
icon = katze_net_load_icon (array_action->net,
|
icon = katze_load_cached_icon (katze_item_get_uri (item), proxy);
|
||||||
katze_item_get_uri (item), NULL, proxy, NULL);
|
|
||||||
image = gtk_image_new_from_pixbuf (icon);
|
image = gtk_image_new_from_pixbuf (icon);
|
||||||
g_object_unref (icon);
|
g_object_unref (icon);
|
||||||
}
|
}
|
||||||
|
@ -460,8 +459,7 @@ katze_array_action_item_notify_cb (KatzeItem* item,
|
||||||
}
|
}
|
||||||
else if (!KATZE_IS_ARRAY (item) && !strcmp (property, "uri"))
|
else if (!KATZE_IS_ARRAY (item) && !strcmp (property, "uri"))
|
||||||
{
|
{
|
||||||
icon = katze_net_load_icon (array_action->net, katze_item_get_uri (item),
|
icon = katze_load_cached_icon (katze_item_get_uri (item), GTK_WIDGET (toolitem));
|
||||||
NULL, GTK_WIDGET (toolitem), NULL);
|
|
||||||
image = gtk_image_new_from_pixbuf (icon);
|
image = gtk_image_new_from_pixbuf (icon);
|
||||||
g_object_unref (icon);
|
g_object_unref (icon);
|
||||||
gtk_widget_show (image);
|
gtk_widget_show (image);
|
||||||
|
@ -497,8 +495,7 @@ katze_array_action_proxy_create_menu_proxy_cb (GtkWidget* proxy,
|
||||||
icon = gtk_widget_render_icon (menuitem,
|
icon = gtk_widget_render_icon (menuitem,
|
||||||
GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);
|
GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);
|
||||||
else
|
else
|
||||||
icon = katze_net_load_icon (array_action->net,
|
icon = katze_load_cached_icon (katze_item_get_uri (item), proxy);
|
||||||
katze_item_get_uri (item), NULL, proxy, NULL);
|
|
||||||
image = gtk_image_new_from_pixbuf (icon);
|
image = gtk_image_new_from_pixbuf (icon);
|
||||||
g_object_unref (icon);
|
g_object_unref (icon);
|
||||||
}
|
}
|
||||||
|
@ -569,8 +566,7 @@ katze_array_action_create_tool_item_for (KatzeArrayAction* array_action,
|
||||||
icon = gtk_widget_render_icon (GTK_WIDGET (toolitem),
|
icon = gtk_widget_render_icon (GTK_WIDGET (toolitem),
|
||||||
GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);
|
GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);
|
||||||
else
|
else
|
||||||
icon = katze_net_load_icon (array_action->net, uri,
|
icon = katze_load_cached_icon (uri, GTK_WIDGET (toolitem));
|
||||||
NULL, GTK_WIDGET (toolitem), NULL);
|
|
||||||
image = gtk_image_new_from_pixbuf (icon);
|
image = gtk_image_new_from_pixbuf (icon);
|
||||||
g_object_unref (icon);
|
g_object_unref (icon);
|
||||||
gtk_widget_show (image);
|
gtk_widget_show (image);
|
||||||
|
|
|
@ -14,6 +14,7 @@
|
||||||
#include <glib/gstdio.h>
|
#include <glib/gstdio.h>
|
||||||
#include <glib/gi18n.h>
|
#include <glib/gi18n.h>
|
||||||
#include <gio/gio.h>
|
#include <gio/gio.h>
|
||||||
|
#include <libsoup/soup.h>
|
||||||
|
|
||||||
#include <string.h>
|
#include <string.h>
|
||||||
|
|
||||||
|
@ -1402,3 +1403,61 @@ katze_widget_has_touchscreen_mode (GtkWidget* widget)
|
||||||
return enabled;
|
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);
|
||||||
|
}
|
||||||
|
|
|
@ -147,6 +147,10 @@ katze_mkdir_with_parents (const gchar* pathname,
|
||||||
gboolean
|
gboolean
|
||||||
katze_widget_has_touchscreen_mode (GtkWidget* widget);
|
katze_widget_has_touchscreen_mode (GtkWidget* widget);
|
||||||
|
|
||||||
|
GdkPixbuf*
|
||||||
|
katze_load_cached_icon (const gchar* uri,
|
||||||
|
GtkWidget* widget);
|
||||||
|
|
||||||
G_END_DECLS
|
G_END_DECLS
|
||||||
|
|
||||||
#endif /* __KATZE_UTILS_H__ */
|
#endif /* __KATZE_UTILS_H__ */
|
||||||
|
|
|
@ -642,13 +642,12 @@ midori_location_entry_render_text_cb (GtkCellLayout* layout,
|
||||||
gtk_tree_model_get (model, iter, URI_COL, &uri, TITLE_COL, &title,
|
gtk_tree_model_get (model, iter, URI_COL, &uri, TITLE_COL, &title,
|
||||||
FAVICON_COL, &icon, -1);
|
FAVICON_COL, &icon, -1);
|
||||||
|
|
||||||
if (G_UNLIKELY (!icon))
|
if (G_UNLIKELY (!icon) && uri)
|
||||||
{
|
{
|
||||||
#if !HAVE_HILDON
|
#if !HAVE_HILDON
|
||||||
MidoriLocationAction* action
|
MidoriLocationAction* action
|
||||||
= g_object_get_data (G_OBJECT (renderer), "location-action");
|
= g_object_get_data (G_OBJECT (renderer), "location-action");
|
||||||
icon = katze_net_load_icon (action->net, uri, NULL, NULL, NULL);
|
if ((icon = katze_load_cached_icon (uri, NULL)))
|
||||||
if (G_LIKELY (icon))
|
|
||||||
{
|
{
|
||||||
midori_location_action_set_icon_for_uri (action, icon, uri);
|
midori_location_action_set_icon_for_uri (action, icon, uri);
|
||||||
g_object_unref (icon);
|
g_object_unref (icon);
|
||||||
|
@ -657,7 +656,7 @@ midori_location_entry_render_text_cb (GtkCellLayout* layout,
|
||||||
midori_location_action_set_icon_for_uri (action, action->default_icon, uri);
|
midori_location_action_set_icon_for_uri (action, action->default_icon, uri);
|
||||||
#endif
|
#endif
|
||||||
}
|
}
|
||||||
else
|
else if (icon)
|
||||||
g_object_unref (icon);
|
g_object_unref (icon);
|
||||||
|
|
||||||
desc = desc_uri = desc_title = key = NULL;
|
desc = desc_uri = desc_title = key = NULL;
|
||||||
|
|
|
@ -432,7 +432,7 @@ midori_search_action_get_icon (KatzeNet* net,
|
||||||
}
|
}
|
||||||
|
|
||||||
if ((icon = katze_item_get_uri (item)) && (g_strstr_len (icon, 8, "://")))
|
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,
|
return gtk_widget_render_icon (widget, GTK_STOCK_FILE,
|
||||||
GTK_ICON_SIZE_MENU, NULL);
|
GTK_ICON_SIZE_MENU, NULL);
|
||||||
|
|
|
@ -563,9 +563,7 @@ midori_bookmarks_treeview_render_icon_cb (GtkTreeViewColumn* column,
|
||||||
pixbuf = gtk_widget_render_icon (treeview, GTK_STOCK_DIRECTORY,
|
pixbuf = gtk_widget_render_icon (treeview, GTK_STOCK_DIRECTORY,
|
||||||
GTK_ICON_SIZE_MENU, NULL);
|
GTK_ICON_SIZE_MENU, NULL);
|
||||||
else if (katze_item_get_uri (item))
|
else if (katze_item_get_uri (item))
|
||||||
pixbuf = katze_net_load_icon (
|
pixbuf = katze_load_cached_icon (katze_item_get_uri (item), treeview);
|
||||||
MIDORI_BOOKMARKS (gtk_widget_get_parent (treeview))->net,
|
|
||||||
katze_item_get_uri (item), NULL, treeview, NULL);
|
|
||||||
g_object_set (renderer, "pixbuf", pixbuf, NULL);
|
g_object_set (renderer, "pixbuf", pixbuf, NULL);
|
||||||
|
|
||||||
if (pixbuf)
|
if (pixbuf)
|
||||||
|
|
|
@ -560,9 +560,7 @@ midori_history_treeview_render_icon_cb (GtkTreeViewColumn* column,
|
||||||
pixbuf = gtk_widget_render_icon (treeview, GTK_STOCK_DIRECTORY,
|
pixbuf = gtk_widget_render_icon (treeview, GTK_STOCK_DIRECTORY,
|
||||||
GTK_ICON_SIZE_MENU, NULL);
|
GTK_ICON_SIZE_MENU, NULL);
|
||||||
else
|
else
|
||||||
pixbuf = katze_net_load_icon (
|
pixbuf = katze_load_cached_icon (katze_item_get_uri (item), treeview);
|
||||||
MIDORI_HISTORY (gtk_widget_get_parent (treeview))->net,
|
|
||||||
katze_item_get_uri (item), NULL, treeview, NULL);
|
|
||||||
|
|
||||||
g_object_set (renderer, "pixbuf", pixbuf, NULL);
|
g_object_set (renderer, "pixbuf", pixbuf, NULL);
|
||||||
|
|
||||||
|
|
Loading…
Reference in a new issue