Propagate mime icons from views to proxy items

This commit is contained in:
Christian Dywan 2009-01-06 02:09:35 +01:00
parent 8370b2f2c9
commit 2c1b05913a
2 changed files with 39 additions and 21 deletions

View file

@ -226,6 +226,7 @@ katze_array_action_generate_menu (KatzeArrayAction* array_action,
guint n, i; guint n, i;
KatzeItem* item; KatzeItem* item;
GtkWidget* menuitem; GtkWidget* menuitem;
const gchar* icon_name;
GdkPixbuf* icon; GdkPixbuf* icon;
GtkWidget* image; GtkWidget* image;
GtkWidget* submenu; GtkWidget* submenu;
@ -245,6 +246,10 @@ katze_array_action_generate_menu (KatzeArrayAction* array_action,
} }
menuitem = katze_image_menu_item_new_ellipsized ( menuitem = katze_image_menu_item_new_ellipsized (
katze_item_get_name (item)); 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_IS_ARRAY (item)) if (KATZE_IS_ARRAY (item))
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);
@ -253,6 +258,7 @@ katze_array_action_generate_menu (KatzeArrayAction* array_action,
katze_item_get_uri (item), NULL, proxy, NULL); 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);
}
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image); gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image);
gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem);
g_object_set_data (G_OBJECT (menuitem), "KatzeItem", item); g_object_set_data (G_OBJECT (menuitem), "KatzeItem", item);
@ -405,6 +411,13 @@ katze_array_action_item_notify_cb (KatzeItem* item,
gtk_widget_show (image); gtk_widget_show (image);
gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (toolitem), 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);
gtk_widget_show (image);
gtk_tool_button_set_icon_widget (GTK_TOOL_BUTTON (toolitem), image);
}
} }
/** /**

View file

@ -526,15 +526,15 @@ static GdkPixbuf*
midori_view_mime_icon (GtkIconTheme* icon_theme, midori_view_mime_icon (GtkIconTheme* icon_theme,
const gchar* format, const gchar* format,
const gchar* part1, const gchar* part1,
const gchar* part2) const gchar* part2,
gchar** name)
{ {
gchar* name;
GdkPixbuf* icon; GdkPixbuf* icon;
name = part2 ? g_strdup_printf (format, part1, part2) *name = part2 ? g_strdup_printf (format, part1, part2)
: g_strdup_printf (format, part1); : g_strdup_printf (format, part1);
icon = gtk_icon_theme_load_icon (icon_theme, name, 16, 0, NULL); if (!(icon = gtk_icon_theme_load_icon (icon_theme, *name, 16, 0, NULL)))
g_free (name); g_free (*name);
return icon ? g_object_ref (icon) : NULL; return icon ? g_object_ref (icon) : NULL;
} }
@ -547,31 +547,36 @@ midori_view_update_icon (MidoriView* view,
GdkScreen* screen; GdkScreen* screen;
GtkIconTheme* icon_theme; GtkIconTheme* icon_theme;
gchar** parts; gchar** parts;
gchar* icon_name;
if ((screen = gtk_widget_get_screen (GTK_WIDGET (view)))) if ((screen = gtk_widget_get_screen (GTK_WIDGET (view))))
{ {
icon_theme = gtk_icon_theme_get_for_screen (screen); icon_theme = gtk_icon_theme_get_for_screen (screen);
parts = g_strsplit (view->mime_type, "/", 2); if ((parts = g_strsplit (view->mime_type, "/", 2)))
parts = (parts[0] && parts[1]) ? parts : NULL;
} }
else else
parts = NULL; parts = NULL;
if (parts && parts[0] && parts[1]) if (parts)
icon = midori_view_mime_icon (icon_theme, "%s-%s", icon = midori_view_mime_icon (icon_theme, "%s-%s",
parts[0], parts[1]); parts[0], parts[1], &icon_name);
if (!icon && parts && parts[0] && parts[1]) if (!icon && parts)
icon = midori_view_mime_icon (icon_theme, "gnome-mime-%s-%s", icon = midori_view_mime_icon (icon_theme, "gnome-mime-%s-%s",
parts[0], parts[1]); parts[0], parts[1], &icon_name);
if (!icon && parts && parts[0]) if (!icon && parts)
icon = midori_view_mime_icon (icon_theme, "%s-x-generic", icon = midori_view_mime_icon (icon_theme, "%s-x-generic",
parts[0], NULL); parts[0], NULL, &icon_name);
if (!icon && parts && parts[0]) if (!icon && parts)
icon = midori_view_mime_icon (icon_theme, "gnome-mime-%s-x-generic", icon = midori_view_mime_icon (icon_theme, "gnome-mime-%s-x-generic",
parts[0], NULL); parts[0], NULL, &icon_name);
katze_item_set_icon (view->item, icon && view->item ? icon_name : NULL);
if (!icon) if (!icon)
icon = gtk_widget_render_icon (GTK_WIDGET (view), icon = gtk_widget_render_icon (GTK_WIDGET (view),
GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL); GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL);
} }
else
katze_item_set_icon (view->item, NULL);
katze_object_assign (view->icon, icon); katze_object_assign (view->icon, icon);
g_object_notify (G_OBJECT (view), "icon"); g_object_notify (G_OBJECT (view), "icon");