gint summand;
KatzeItem* item;
GtkWidget* menuitem;
- const gchar* icon_name;
- GdkPixbuf* icon;
GtkWidget* image;
GtkWidget* submenu;
}
menuitem = katze_image_menu_item_new_ellipsized (
katze_item_get_name (item));
- if ((icon_name = katze_item_get_icon (item)) && *icon_name)
- image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
- else
- {
- if (KATZE_ITEM_IS_FOLDER (item))
- icon = gtk_widget_render_icon (menuitem,
- GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);
- else
- icon = katze_load_cached_icon (katze_item_get_uri (item), proxy);
- image = gtk_image_new_from_pixbuf (icon);
- g_object_unref (icon);
- }
+ image = katze_item_get_image (item);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
gtk_image_menu_item_set_always_show_image (
GTK_IMAGE_MENU_ITEM (menuitem), TRUE);
const gchar* property;
const gchar* title;
const gchar* desc;
- GdkPixbuf* icon;
GtkWidget* image;
if (!G_IS_PARAM_SPEC_STRING (pspec))
}
else if (KATZE_ITEM_IS_BOOKMARK (item) && !strcmp (property, "uri"))
{
- icon = katze_load_cached_icon (katze_item_get_uri (item), GTK_WIDGET (toolitem));
- image = gtk_image_new_from_pixbuf (icon);
- g_object_unref (icon);
+ image = katze_item_get_image (item);
gtk_widget_show (image);
gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (toolitem), image);
}
else if (!strcmp (property, "icon"))
{
- image = gtk_image_new_from_icon_name (katze_item_get_icon (item),
- GTK_ICON_SIZE_MENU);
+ image = katze_item_get_image (item);
gtk_widget_show (image);
gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (toolitem), image);
}
{
KatzeArrayAction* array_action;
GtkWidget* menuitem;
- const gchar* icon_name;
GtkWidget* image;
- GdkPixbuf* icon;
array_action = g_object_get_data (G_OBJECT (proxy), "KatzeArrayAction");
menuitem = katze_image_menu_item_new_ellipsized (
katze_item_get_name (item));
- if ((icon_name = katze_item_get_icon (item)) && *icon_name)
- image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
- else
- {
- if (KATZE_ITEM_IS_FOLDER (item))
- icon = gtk_widget_render_icon (menuitem,
- GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);
- else
- icon = katze_load_cached_icon (katze_item_get_uri (item), proxy);
- image = gtk_image_new_from_pixbuf (icon);
- g_object_unref (icon);
- }
+ image = katze_item_get_image (item);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
gtk_image_menu_item_set_always_show_image (
GTK_IMAGE_MENU_ITEM (menuitem), TRUE);
const gchar* uri;
const gchar* desc;
GtkToolItem* toolitem;
- GdkPixbuf* icon;
GtkWidget* image;
GtkWidget* label;
return gtk_separator_tool_item_new ();
if (KATZE_ITEM_IS_FOLDER (item))
- {
toolitem = gtk_toggle_tool_button_new ();
- icon = gtk_widget_render_icon (GTK_WIDGET (toolitem),
- GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL);
- }
else
- {
toolitem = gtk_tool_button_new (NULL, "");
- icon = katze_load_cached_icon (uri, GTK_WIDGET (toolitem));
- }
g_signal_connect (toolitem, "create-menu-proxy",
G_CALLBACK (katze_array_action_proxy_create_menu_proxy_cb), item);
- image = gtk_image_new_from_pixbuf (icon);
- g_object_unref (icon);
+ image = katze_item_get_image (item);
gtk_widget_show (image);
gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (toolitem), image);
label = gtk_label_new (NULL);
g_object_notify (G_OBJECT (item), "icon");
}
+/**
+ * katze_item_get_image:
+ * @item: a #KatzeItem
+ *
+ * Retrieves a #GtkImage fit to display @item.
+ *
+ * Return value: the icon of the item
+ *
+ * Since: 0.4.4
+ **/
+GtkWidget*
+katze_item_get_image (KatzeItem* item)
+{
+ GtkWidget* image;
+ GdkPixbuf* pixbuf;
+ const gchar* icon;
+
+ g_return_val_if_fail (KATZE_IS_ITEM (item), NULL);
+
+ if (KATZE_ITEM_IS_FOLDER (item))
+ image = gtk_image_new_from_stock (GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU);
+ else if ((pixbuf = g_object_get_data (G_OBJECT (item), "pixbuf")))
+ 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);
+ else
+ {
+ if (!(pixbuf = katze_load_cached_icon (icon, NULL)))
+ pixbuf = katze_load_cached_icon (item->uri, NULL);
+ if (pixbuf)
+ {
+ image = gtk_image_new_from_pixbuf (pixbuf);
+ g_object_unref (pixbuf);
+ }
+ else
+ image = gtk_image_new_from_stock (GTK_STOCK_FILE, GTK_ICON_SIZE_MENU);
+ }
+ return image;
+}
+
/**
* katze_item_get_token:
* @item: a #KatzeItem
const gchar* icon_name)
{
katze_item_set_icon (view->item, icon_name);
+ /* katze_item_get_image knows about this pixbuf */
+ g_object_set_data_full (G_OBJECT (view->item), "pixbuf", g_object_ref (icon),
+ (GDestroyNotify)g_object_unref);
katze_object_assign (view->icon, icon);
g_object_notify (G_OBJECT (view), "icon");
}
if (view->menu_item)
{
- GtkWidget* image;
- if (icon_name && !strchr (icon_name, '/'))
- image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
- else
- image = gtk_image_new_from_pixbuf (view->icon);
+ GtkWidget* image = katze_item_get_image (view->item);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (view->menu_item), image);
}
}