From 8aa3c661e1f795edad9d5c48ae73aaf3fd99a7f2 Mon Sep 17 00:00:00 2001 From: Nathan Sketch Date: Sun, 7 Feb 2021 08:27:22 -0500 Subject: Show thumbnails for images supported by GTK Thumbnail images will be displayed when icons are enabled, with the standard mime-type icons used for all non-image files. Thumbnails are generated internally by GTK. --- dragon.c | 40 ++++++++++++++++++++++++---------------- 1 file changed, 24 insertions(+), 16 deletions(-) diff --git a/dragon.c b/dragon.c index f81a39c..b096a92 100644 --- a/dragon.c +++ b/dragon.c @@ -204,24 +204,32 @@ void add_file_button(GFile *file) { dragdata->uri = uri; GtkButton *button = add_button(filename, dragdata, TARGET_TYPE_URI); - GFileInfo *fileinfo = g_file_query_info(file, "*", 0, NULL, NULL); - GIcon *icon = g_file_info_get_icon(fileinfo); - GtkIconInfo *icon_info = gtk_icon_theme_lookup_by_gicon(icon_theme, - icon, 48, 0); - - // Try a few fallback mimetypes if no icon can be found - if (!icon_info) - icon_info = icon_info_from_content_type("application/octet-stream"); - if (!icon_info) - icon_info = icon_info_from_content_type("text/x-generic"); - if (!icon_info) - icon_info = icon_info_from_content_type("text/plain"); - - if (icon_info) { - GtkWidget *image = gtk_image_new_from_pixbuf( - gtk_icon_info_load_icon(icon_info, NULL)); + GdkPixbuf *pb = gdk_pixbuf_new_from_file_at_size(filename, 96, 96, NULL); + if (pb) { + GtkWidget *image = gtk_image_new_from_pixbuf(pb); + gtk_button_set_always_show_image(button, true); gtk_button_set_image(button, image); gtk_button_set_always_show_image(button, true); + } else { + GFileInfo *fileinfo = g_file_query_info(file, "*", 0, NULL, NULL); + GIcon *icon = g_file_info_get_icon(fileinfo); + GtkIconInfo *icon_info = gtk_icon_theme_lookup_by_gicon(icon_theme, + icon, 48, 0); + + // Try a few fallback mimetypes if no icon can be found + if (!icon_info) + icon_info = icon_info_from_content_type("application/octet-stream"); + if (!icon_info) + icon_info = icon_info_from_content_type("text/x-generic"); + if (!icon_info) + icon_info = icon_info_from_content_type("text/plain"); + + if (icon_info) { + GtkWidget *image = gtk_image_new_from_pixbuf( + gtk_icon_info_load_icon(icon_info, NULL)); + gtk_button_set_image(button, image); + gtk_button_set_always_show_image(button, true); + } } if (!icons_only) -- cgit