aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorNathan Sketch <sketchn98@gmail.com>2021-02-07 08:27:22 -0500
committerMichael Homer <mwh@mwh.geek.nz>2021-03-08 10:14:13 +1300
commit8aa3c661e1f795edad9d5c48ae73aaf3fd99a7f2 (patch)
tree666a040f9f8ac60b6e62d3c0048c664eaa828d21
parentAdd -I/--stdin option to read filenames from stdin (diff)
downloaddragon-8aa3c661e1f795edad9d5c48ae73aaf3fd99a7f2.tar.gz
dragon-8aa3c661e1f795edad9d5c48ae73aaf3fd99a7f2.tar.bz2
dragon-8aa3c661e1f795edad9d5c48ae73aaf3fd99a7f2.zip
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.
-rw-r--r--dragon.c40
1 files 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)
bgstack15