From: Christian Dywan Date: Tue, 6 Jan 2009 01:09:35 +0000 (+0100) Subject: Propagate mime icons from views to proxy items X-Git-Url: https://spindle.queued.net/cgi-bin/gitweb.cgi?a=commitdiff_plain;h=2c1b05913ae108a1e09d2e9e2dae4d12abe5aca8;p=midori Propagate mime icons from views to proxy items --- diff --git a/katze/katze-arrayaction.c b/katze/katze-arrayaction.c index 5ab26c09..fe3657d2 100644 --- a/katze/katze-arrayaction.c +++ b/katze/katze-arrayaction.c @@ -226,6 +226,7 @@ katze_array_action_generate_menu (KatzeArrayAction* array_action, guint n, i; KatzeItem* item; GtkWidget* menuitem; + const gchar* icon_name; GdkPixbuf* icon; GtkWidget* image; GtkWidget* submenu; @@ -245,14 +246,19 @@ katze_array_action_generate_menu (KatzeArrayAction* array_action, } menuitem = katze_image_menu_item_new_ellipsized ( katze_item_get_name (item)); - if (KATZE_IS_ARRAY (item)) - icon = gtk_widget_render_icon (menuitem, - GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL); + if ((icon_name = katze_item_get_icon (item)) && *icon_name) + image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU); else - icon = katze_net_load_icon (array_action->net, - katze_item_get_uri (item), NULL, proxy, NULL); - image = gtk_image_new_from_pixbuf (icon); - g_object_unref (icon); + { + if (KATZE_IS_ARRAY (item)) + icon = gtk_widget_render_icon (menuitem, + GTK_STOCK_DIRECTORY, GTK_ICON_SIZE_MENU, NULL); + else + icon = katze_net_load_icon (array_action->net, + katze_item_get_uri (item), NULL, proxy, NULL); + image = gtk_image_new_from_pixbuf (icon); + g_object_unref (icon); + } gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (menuitem), image); gtk_menu_shell_append (GTK_MENU_SHELL (menu), menuitem); 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_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); + } } /** diff --git a/midori/midori-view.c b/midori/midori-view.c index 0ee35119..89b5e600 100644 --- a/midori/midori-view.c +++ b/midori/midori-view.c @@ -526,15 +526,15 @@ static GdkPixbuf* midori_view_mime_icon (GtkIconTheme* icon_theme, const gchar* format, const gchar* part1, - const gchar* part2) + const gchar* part2, + gchar** name) { - gchar* name; GdkPixbuf* icon; - name = part2 ? g_strdup_printf (format, part1, part2) + *name = part2 ? g_strdup_printf (format, part1, part2) : g_strdup_printf (format, part1); - icon = gtk_icon_theme_load_icon (icon_theme, name, 16, 0, NULL); - g_free (name); + if (!(icon = gtk_icon_theme_load_icon (icon_theme, *name, 16, 0, NULL))) + g_free (*name); return icon ? g_object_ref (icon) : NULL; } @@ -547,31 +547,36 @@ midori_view_update_icon (MidoriView* view, GdkScreen* screen; GtkIconTheme* icon_theme; gchar** parts; + gchar* icon_name; if ((screen = gtk_widget_get_screen (GTK_WIDGET (view)))) { 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 parts = NULL; - if (parts && parts[0] && parts[1]) + if (parts) icon = midori_view_mime_icon (icon_theme, "%s-%s", - parts[0], parts[1]); - if (!icon && parts && parts[0] && parts[1]) + parts[0], parts[1], &icon_name); + if (!icon && parts) icon = midori_view_mime_icon (icon_theme, "gnome-mime-%s-%s", - parts[0], parts[1]); - if (!icon && parts && parts[0]) + parts[0], parts[1], &icon_name); + if (!icon && parts) icon = midori_view_mime_icon (icon_theme, "%s-x-generic", - parts[0], NULL); - if (!icon && parts && parts[0]) + parts[0], NULL, &icon_name); + if (!icon && parts) 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) icon = gtk_widget_render_icon (GTK_WIDGET (view), GTK_STOCK_FILE, GTK_ICON_SIZE_MENU, NULL); } + else + katze_item_set_icon (view->item, NULL); katze_object_assign (view->icon, icon); g_object_notify (G_OBJECT (view), "icon");