GktFileSystem: Support rendering symbolic icons

This commit is contained in:
Matthias Clasen 2014-07-23 13:39:23 -04:00
parent 386e59683a
commit d26a84889b
2 changed files with 80 additions and 13 deletions

View File

@ -713,6 +713,7 @@ get_surface_from_gicon (GIcon *icon,
GdkScreen *screen;
GtkIconTheme *icon_theme;
GtkIconInfo *icon_info;
GdkPixbuf *pixbuf;
cairo_surface_t *surface;
screen = gtk_widget_get_screen (GTK_WIDGET (widget));
@ -727,11 +728,21 @@ get_surface_from_gicon (GIcon *icon,
if (!icon_info)
return NULL;
surface = gtk_icon_info_load_surface (icon_info,
gtk_widget_get_window (widget), error);
pixbuf = gtk_icon_info_load_symbolic_for_context (icon_info,
gtk_widget_get_style_context (widget),
NULL,
error);
g_object_unref (icon_info);
if (pixbuf == NULL)
return NULL;
surface = gdk_cairo_surface_create_from_pixbuf (pixbuf,
gtk_widget_get_scale_factor (widget),
gtk_widget_get_window (widget));
g_object_unref (pixbuf);
return surface;
}
@ -744,8 +755,6 @@ _gtk_file_system_volume_render_icon (GtkFileSystemVolume *volume,
GIcon *icon = NULL;
cairo_surface_t *surface;
DEBUG ("volume_get_icon_name");
if (IS_ROOT_VOLUME (volume))
icon = g_themed_icon_new ("drive-harddisk");
else if (G_IS_DRIVE (volume))
@ -765,6 +774,34 @@ _gtk_file_system_volume_render_icon (GtkFileSystemVolume *volume,
return surface;
}
cairo_surface_t *
_gtk_file_system_volume_render_symbolic_icon (GtkFileSystemVolume *volume,
GtkWidget *widget,
gint icon_size,
GError **error)
{
GIcon *icon = NULL;
cairo_surface_t *surface;
if (IS_ROOT_VOLUME (volume))
icon = g_themed_icon_new ("drive-harddisk-symbolic");
else if (G_IS_DRIVE (volume))
icon = g_drive_get_symbolic_icon (G_DRIVE (volume));
else if (G_IS_VOLUME (volume))
icon = g_volume_get_symbolic_icon (G_VOLUME (volume));
else if (G_IS_MOUNT (volume))
icon = g_mount_get_symbolic_icon (G_MOUNT (volume));
if (!icon)
return NULL;
surface = get_surface_from_gicon (icon, widget, icon_size, error);
g_object_unref (icon);
return surface;
}
GtkFileSystemVolume *
_gtk_file_system_volume_ref (GtkFileSystemVolume *volume)
{
@ -794,9 +831,10 @@ _gtk_file_system_volume_unref (GtkFileSystemVolume *volume)
/* GFileInfo helper functions */
cairo_surface_t *
_gtk_file_info_render_icon (GFileInfo *info,
_gtk_file_info_render_icon_internal (GFileInfo *info,
GtkWidget *widget,
gint icon_size)
gint icon_size,
gboolean symbolic)
{
GIcon *icon;
GdkPixbuf *pixbuf;
@ -823,6 +861,9 @@ _gtk_file_info_render_icon (GFileInfo *info,
if (!surface)
{
if (symbolic)
icon = g_file_info_get_symbolic_icon (info);
else
icon = g_file_info_get_icon (info);
if (icon)
@ -831,6 +872,9 @@ _gtk_file_info_render_icon (GFileInfo *info,
if (!surface)
{
/* Use general fallback for all files without icon */
if (symbolic)
icon = g_themed_icon_new ("text-x-generic-symbolic");
else
icon = g_themed_icon_new ("text-x-generic");
surface = get_surface_from_gicon (icon, widget, icon_size, NULL);
g_object_unref (icon);
@ -840,6 +884,22 @@ _gtk_file_info_render_icon (GFileInfo *info,
return surface;
}
cairo_surface_t *
_gtk_file_info_render_icon (GFileInfo *info,
GtkWidget *widget,
gint icon_size)
{
return _gtk_file_info_render_icon_internal (info, widget, icon_size, FALSE);
}
cairo_surface_t *
_gtk_file_info_render_symbolic_icon (GFileInfo *info,
GtkWidget *widget,
gint icon_size)
{
return _gtk_file_info_render_icon_internal (info, widget, icon_size, TRUE);
}
gboolean
_gtk_file_info_consider_as_directory (GFileInfo *info)
{

View File

@ -97,6 +97,10 @@ cairo_surface_t * _gtk_file_system_volume_render_icon (GtkFileSystemVol
GtkWidget *widget,
gint icon_size,
GError **error);
cairo_surface_t * _gtk_file_system_volume_render_symbolic_icon (GtkFileSystemVolume *volume,
GtkWidget *widget,
gint icon_size,
GError **error);
GtkFileSystemVolume *_gtk_file_system_volume_ref (GtkFileSystemVolume *volume);
void _gtk_file_system_volume_unref (GtkFileSystemVolume *volume);
@ -105,6 +109,9 @@ void _gtk_file_system_volume_unref (GtkFileSystemVol
cairo_surface_t * _gtk_file_info_render_icon (GFileInfo *info,
GtkWidget *widget,
gint icon_size);
cairo_surface_t * _gtk_file_info_render_symbolic_icon (GFileInfo *info,
GtkWidget *widget,
gint icon_size);
gboolean _gtk_file_info_consider_as_directory (GFileInfo *info);