[gtk+/wip/matthiasc/file-icons: 1/2] filesystem: Add GIcon getters
- From: Matthias Clasen <matthiasc src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gtk+/wip/matthiasc/file-icons: 1/2] filesystem: Add GIcon getters
- Date: Thu, 9 Nov 2017 01:55:41 +0000 (UTC)
commit 9f40c22b8c5535c3a776ee62ce044065c3585698
Author: Matthias Clasen <mclasen redhat com>
Date: Wed Nov 8 20:53:49 2017 -0500
filesystem: Add GIcon getters
We want to move away from surfaces, and instead pass
GIcons and GdkTextures around.
gtk/gtkfilesystem.c | 53 +++++++++++++++++++++++++++++++++++++++++++++-----
gtk/gtkfilesystem.h | 4 +++
2 files changed, 51 insertions(+), 6 deletions(-)
---
diff --git a/gtk/gtkfilesystem.c b/gtk/gtkfilesystem.c
index f6edb4e..62066c4 100644
--- a/gtk/gtkfilesystem.c
+++ b/gtk/gtkfilesystem.c
@@ -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,37 @@ _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 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,
diff --git a/gtk/gtkfilesystem.h b/gtk/gtkfilesystem.h
index a2b144c..0a3db1a 100644
--- a/gtk/gtkfilesystem.h
+++ b/gtk/gtkfilesystem.h
@@ -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);
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]