Add katze_item_get_pixbuf and use in panels

This commit is contained in:
Christian Dywan 2012-05-13 01:53:19 +02:00
parent 94c6fca20f
commit cf1321fe21
4 changed files with 44 additions and 7 deletions

View file

@ -423,6 +423,40 @@ katze_item_set_icon (KatzeItem* item,
g_object_notify (G_OBJECT (item), "icon"); g_object_notify (G_OBJECT (item), "icon");
} }
/**
* katze_item_get_pixbuf:
* @item: a #KatzeItem
* @widget: a #GtkWidget, or %NULL
*
* Retrieves a #GdkPixbuf fit to display @item.
*
* Return value: the icon of the item
*
* Since: 0.4.6
**/
GdkPixbuf*
katze_item_get_pixbuf (KatzeItem* item,
GtkWidget* widget)
{
GdkPixbuf* pixbuf;
g_return_val_if_fail (KATZE_IS_ITEM (item), NULL);
if (item->uri == NULL)
return NULL;
#if WEBKIT_CHECK_VERSION (1, 8, 0)
/* FIXME: Don't hard-code icon size */
if ((pixbuf = webkit_favicon_database_try_get_favicon_pixbuf (
webkit_get_favicon_database (), item->uri, 16, 16)))
return pixbuf;
#else
if ((pixbuf = g_object_get_data (G_OBJECT (item), "pixbuf")))
return pixbuf;
#endif
return NULL;
}
/** /**
* katze_item_get_image: * katze_item_get_image:
* @item: a #KatzeItem * @item: a #KatzeItem
@ -444,13 +478,8 @@ katze_item_get_image (KatzeItem* item)
if (KATZE_ITEM_IS_FOLDER (item)) if (KATZE_ITEM_IS_FOLDER (item))
image = gtk_image_new_from_stock (GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU); image = gtk_image_new_from_stock (GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU);
#if WEBKIT_CHECK_VERSION (1, 8, 0) /* FIXME: Pass widget for icon size */
/* FIXME: Don't hard-code icon size */ else if ((pixbuf = katze_item_get_pixbuf (item, NULL)))
else if ((pixbuf = webkit_favicon_database_try_get_favicon_pixbuf (
webkit_get_favicon_database (), item->uri, 16, 16)))
image = gtk_image_new_from_pixbuf (pixbuf);
#endif
else if ((pixbuf = g_object_get_data (G_OBJECT (item), "pixbuf")))
image = gtk_image_new_from_pixbuf (pixbuf); image = gtk_image_new_from_pixbuf (pixbuf);
else if ((icon = katze_item_get_icon (item)) && !strchr (icon, '/')) else if ((icon = katze_item_get_icon (item)) && !strchr (icon, '/'))
image = gtk_image_new_from_icon_name (icon, GTK_ICON_SIZE_MENU); image = gtk_image_new_from_icon_name (icon, GTK_ICON_SIZE_MENU);

View file

@ -91,6 +91,10 @@ void
katze_item_set_icon (KatzeItem* item, katze_item_set_icon (KatzeItem* item,
const gchar* icon); const gchar* icon);
GdkPixbuf*
katze_item_get_pixbuf (KatzeItem* item,
GtkWidget* widget);
GtkWidget* GtkWidget*
katze_item_get_image (KatzeItem* item); katze_item_get_image (KatzeItem* item);

View file

@ -563,6 +563,8 @@ midori_bookmarks_treeview_render_icon_cb (GtkTreeViewColumn* column,
if (KATZE_ITEM_IS_FOLDER (item)) if (KATZE_ITEM_IS_FOLDER (item))
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 ((pixbuf = katze_item_get_pixbuf (item, treeview)))
;
else if (KATZE_ITEM_IS_BOOKMARK (item)) else if (KATZE_ITEM_IS_BOOKMARK (item))
pixbuf = katze_load_cached_icon (katze_item_get_uri (item), treeview); pixbuf = katze_load_cached_icon (katze_item_get_uri (item), treeview);
g_object_set (renderer, "pixbuf", pixbuf, NULL); g_object_set (renderer, "pixbuf", pixbuf, NULL);

View file

@ -594,6 +594,8 @@ midori_history_treeview_render_icon_cb (GtkTreeViewColumn* column,
if (!item) if (!item)
pixbuf = NULL; pixbuf = NULL;
else if ((pixbuf = katze_item_get_pixbuf (item, treeview)))
;
else if (katze_item_get_uri (item)) else if (katze_item_get_uri (item))
pixbuf = katze_load_cached_icon (katze_item_get_uri (item), treeview); pixbuf = katze_load_cached_icon (katze_item_get_uri (item), treeview);
else else