Optimize icon handling in MidoriView and use Find for blank page

We return early where appropriate and use icon names when possible.
This commit is contained in:
Christian Dywan 2009-12-26 13:59:54 +01:00
parent 799b22b34e
commit be5c679b39

View file

@ -601,73 +601,101 @@ midori_view_update_title (MidoriView* view)
#undef title #undef title
} }
static GdkPixbuf* static void
midori_view_mime_icon (GtkIconTheme* icon_theme, midori_view_apply_icon (MidoriView* view,
GdkPixbuf* icon,
const gchar* icon_name)
{
if (view->item)
katze_item_set_icon (view->item, icon_name);
katze_object_assign (view->icon, icon);
g_object_notify (G_OBJECT (view), "icon");
if (view->tab_icon)
{
if (icon_name)
katze_throbber_set_static_icon_name (KATZE_THROBBER (view->tab_icon),
icon_name);
else
katze_throbber_set_static_pixbuf (KATZE_THROBBER (view->tab_icon),
view->icon);
}
if (view->menu_item)
{
GtkWidget* image;
if (icon_name)
image = gtk_image_new_from_icon_name (icon_name, GTK_ICON_SIZE_MENU);
else
image = gtk_image_new_from_pixbuf (view->icon);
gtk_image_menu_item_set_image (GTK_IMAGE_MENU_ITEM (view->menu_item), image);
}
}
static gboolean
midori_view_mime_icon (MidoriView* view,
GtkIconTheme* icon_theme,
const gchar* format, const gchar* format,
const gchar* part1, const gchar* part1,
const gchar* part2, const gchar* part2)
gchar** name)
{ {
gchar* icon_name;
GdkPixbuf* icon; GdkPixbuf* icon;
*name = part2 ? g_strdup_printf (format, part1, part2) icon_name = part2 ? g_strdup_printf (format, part1, part2)
: g_strdup_printf (format, part1); : g_strdup_printf (format, part1);
if (!(icon = gtk_icon_theme_load_icon (icon_theme, *name, 16, 0, NULL))) if (!(icon = gtk_icon_theme_load_icon (icon_theme, icon_name, 16, 0, NULL)))
g_free (*name); {
return icon ? g_object_ref (icon) : NULL; g_free (icon_name);
return FALSE;
}
g_object_ref (icon);
midori_view_apply_icon (view, icon, icon_name);
g_free (icon_name);
return TRUE;
} }
static void static void
midori_view_update_icon (MidoriView* view, midori_view_update_icon (MidoriView* view,
GdkPixbuf* icon) GdkPixbuf* icon)
{
if (!icon)
{ {
GdkScreen* screen; GdkScreen* screen;
GtkIconTheme* icon_theme = NULL; GtkIconTheme* theme;
gchar** parts = NULL; gchar** parts = NULL;
gchar* icon_name;
if ((screen = gtk_widget_get_screen (GTK_WIDGET (view)))) if (icon)
{ {
icon_theme = gtk_icon_theme_get_for_screen (screen); midori_view_apply_icon (view, icon, NULL);
if ((parts = g_strsplit (view->mime_type, "/", 2))) return;
{
if (!(parts[0] && parts[1]))
katze_assign (parts, NULL);
}
} }
if (parts) if (!((screen = gtk_widget_get_screen (GTK_WIDGET (view)))
icon = midori_view_mime_icon (icon_theme, "%s-%s", && (theme = gtk_icon_theme_get_for_screen (screen))))
parts[0], parts[1], &icon_name); return;
if (!icon && parts)
icon = midori_view_mime_icon (icon_theme, "gnome-mime-%s-%s", if (!((parts = g_strsplit (view->mime_type, "/", 2)) && (*parts && parts[1])))
parts[0], parts[1], &icon_name); {
if (!icon && parts) g_strfreev (parts);
icon = midori_view_mime_icon (icon_theme, "%s-x-generic", /* This is a hack to have a Find icon in the location while the
parts[0], NULL, &icon_name); blank page has a File icon. */
if (!icon && parts) icon = gtk_widget_render_icon (GTK_WIDGET (view),
icon = midori_view_mime_icon (icon_theme, "gnome-mime-%s-x-generic", GTK_STOCK_FIND, GTK_ICON_SIZE_MENU, NULL);
parts[0], NULL, &icon_name); midori_view_apply_icon (view, icon, GTK_STOCK_FILE);
if (view->item) return;
katze_item_set_icon (view->item, icon ? icon_name : NULL); }
if (!icon)
if (midori_view_mime_icon (view, theme, "%s-%s", *parts, parts[1]))
return;
if (midori_view_mime_icon (view, theme, "gnome-mime-%s-%s", *parts, parts[1]))
return;
if (midori_view_mime_icon (view, theme, "%s-x-generic", *parts, NULL))
return;
if (midori_view_mime_icon (view, theme, "gnome-mime-%s-x-generic", *parts, NULL))
return;
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);
} midori_view_apply_icon (view, icon, NULL);
else if (view->item)
katze_item_set_icon (view->item, NULL);
katze_object_assign (view->icon, icon);
g_object_notify (G_OBJECT (view), "icon");
if (view->tab_icon)
katze_throbber_set_static_pixbuf (KATZE_THROBBER (view->tab_icon),
view->icon);
if (view->menu_item)
gtk_image_menu_item_set_image (
GTK_IMAGE_MENU_ITEM (view->menu_item),
gtk_image_new_from_pixbuf (view->icon));
} }
static void static void
@ -2409,9 +2437,8 @@ midori_view_init (MidoriView* view)
{ {
view->uri = NULL; view->uri = NULL;
view->title = NULL; view->title = NULL;
view->mime_type = g_strdup ("text/html"); view->mime_type = g_strdup ("");
view->icon = gtk_widget_render_icon (GTK_WIDGET (view), GTK_STOCK_FILE, view->icon = NULL;
GTK_ICON_SIZE_MENU, NULL);
view->progress = 0.0; view->progress = 0.0;
view->load_status = MIDORI_LOAD_FINISHED; view->load_status = MIDORI_LOAD_FINISHED;
view->minimized = FALSE; view->minimized = FALSE;