From: Christian Dywan Date: Sat, 12 May 2012 23:53:19 +0000 (+0200) Subject: Add katze_item_get_pixbuf and use in panels X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=cf1321fe215155be59250edef3dbac2c593359f9;p=midori Add katze_item_get_pixbuf and use in panels --- diff --git a/katze/katze-item.c b/katze/katze-item.c index 36446b77..43ed856c 100644 --- a/katze/katze-item.c +++ b/katze/katze-item.c @@ -423,6 +423,40 @@ katze_item_set_icon (KatzeItem* item, 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: * @item: a #KatzeItem @@ -444,13 +478,8 @@ katze_item_get_image (KatzeItem* item) if (KATZE_ITEM_IS_FOLDER (item)) image = gtk_image_new_from_stock (GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU); - #if WEBKIT_CHECK_VERSION (1, 8, 0) - /* FIXME: Don't hard-code icon size */ - 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"))) + /* FIXME: Pass widget for icon size */ + else if ((pixbuf = katze_item_get_pixbuf (item, NULL))) image = gtk_image_new_from_pixbuf (pixbuf); else if ((icon = katze_item_get_icon (item)) && !strchr (icon, '/')) image = gtk_image_new_from_icon_name (icon, GTK_ICON_SIZE_MENU); diff --git a/katze/katze-item.h b/katze/katze-item.h index ceb7f3cf..0bd44fdb 100644 --- a/katze/katze-item.h +++ b/katze/katze-item.h @@ -91,6 +91,10 @@ void katze_item_set_icon (KatzeItem* item, const gchar* icon); +GdkPixbuf* +katze_item_get_pixbuf (KatzeItem* item, + GtkWidget* widget); + GtkWidget* katze_item_get_image (KatzeItem* item); diff --git a/panels/midori-bookmarks.c b/panels/midori-bookmarks.c index d6dfa29c..099e9d80 100644 --- a/panels/midori-bookmarks.c +++ b/panels/midori-bookmarks.c @@ -563,6 +563,8 @@ midori_bookmarks_treeview_render_icon_cb (GtkTreeViewColumn* column, if (KATZE_ITEM_IS_FOLDER (item)) pixbuf = gtk_widget_render_icon (treeview, GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL); + else if ((pixbuf = katze_item_get_pixbuf (item, treeview))) + ; else if (KATZE_ITEM_IS_BOOKMARK (item)) pixbuf = katze_load_cached_icon (katze_item_get_uri (item), treeview); g_object_set (renderer, "pixbuf", pixbuf, NULL); diff --git a/panels/midori-history.c b/panels/midori-history.c index f54a2b82..7ec1717f 100644 --- a/panels/midori-history.c +++ b/panels/midori-history.c @@ -594,6 +594,8 @@ midori_history_treeview_render_icon_cb (GtkTreeViewColumn* column, if (!item) pixbuf = NULL; + else if ((pixbuf = katze_item_get_pixbuf (item, treeview))) + ; else if (katze_item_get_uri (item)) pixbuf = katze_load_cached_icon (katze_item_get_uri (item), treeview); else