filesystem: Add GIcon getters

We want to move away from surfaces, and instead pass
GIcons and GdkTextures around.
This commit is contained in:
Matthias Clasen 2017-11-08 20:53:49 -05:00
parent c06b1cc103
commit 4148795c8b
2 changed files with 50 additions and 6 deletions

View File

@ -745,14 +745,10 @@ get_surface_from_gicon (GIcon *icon,
return surface;
}
cairo_surface_t *
_gtk_file_system_volume_render_icon (GtkFileSystemVolume *volume,
GtkWidget *widget,
gint icon_size,
GError **error)
GIcon *
_gtk_file_system_volume_get_icon (GtkFileSystemVolume *volume)
{
GIcon *icon = NULL;
cairo_surface_t *surface;
if (IS_ROOT_VOLUME (volume))
icon = g_themed_icon_new ("drive-harddisk");
@ -763,6 +759,20 @@ _gtk_file_system_volume_render_icon (GtkFileSystemVolume *volume,
else if (G_IS_MOUNT (volume))
icon = g_mount_get_icon (G_MOUNT (volume));
return icon;
}
cairo_surface_t *
_gtk_file_system_volume_render_icon (GtkFileSystemVolume *volume,
GtkWidget *widget,
gint icon_size,
GError **error)
{
GIcon *icon = NULL;
cairo_surface_t *surface;
icon = _gtk_file_system_volume_get_icon (volume);
if (!icon)
return NULL;
@ -870,6 +880,36 @@ _gtk_file_info_render_icon_internal (GFileInfo *info,
return surface;
}
GIcon *
_gtk_file_info_get_icon (GFileInfo *info,
int icon_size,
int scale)
{
GIcon *icon;
GdkPixbuf *pixbuf;
const gchar *thumbnail_path;
thumbnail_path = g_file_info_get_attribute_byte_string (info, G_FILE_ATTRIBUTE_THUMBNAIL_PATH);
if (thumbnail_path)
{
pixbuf = gdk_pixbuf_new_from_file_at_size (thumbnail_path,
icon_size*scale, icon_size*scale,
NULL);
if (pixbuf != NULL)
return G_ICON (pixbuf);
}
icon = g_file_info_get_icon (info);
if (icon)
return g_object_ref (icon);
/* Use general fallback for all files without icon */
icon = g_themed_icon_new ("text-x-generic");
return icon;
}
cairo_surface_t *
_gtk_file_info_render_icon (GFileInfo *info,
GtkWidget *widget,

View File

@ -94,6 +94,7 @@ gchar * _gtk_file_system_volume_get_display_name (GtkFileSystemVol
gboolean _gtk_file_system_volume_is_mounted (GtkFileSystemVolume *volume);
GFile * _gtk_file_system_volume_get_root (GtkFileSystemVolume *volume);
GIcon * _gtk_file_system_volume_get_symbolic_icon (GtkFileSystemVolume *volume);
GIcon * _gtk_file_system_volume_get_icon (GtkFileSystemVolume *volume);
cairo_surface_t * _gtk_file_system_volume_render_icon (GtkFileSystemVolume *volume,
GtkWidget *widget,
gint icon_size,
@ -106,6 +107,9 @@ void _gtk_file_system_volume_unref (GtkFileSystemVol
cairo_surface_t * _gtk_file_info_render_icon (GFileInfo *info,
GtkWidget *widget,
gint icon_size);
GIcon * _gtk_file_info_get_icon (GFileInfo *info,
int icon_size,
int scale);
gboolean _gtk_file_info_consider_as_directory (GFileInfo *info);