add file icon name fallback (GTK) newapi

Sun, 13 Oct 2024 14:02:43 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 13 Oct 2024 14:02:43 +0200
branch
newapi
changeset 334
00be546d3b38
parent 333
634e3ce80afe
child 335
91d4f0391282

add file icon name fallback (GTK)

ui/gtk/image.c file | annotate | diff | comparison | revisions
--- a/ui/gtk/image.c	Sun Oct 13 11:05:38 2024 +0200
+++ b/ui/gtk/image.c	Sun Oct 13 14:02:43 2024 +0200
@@ -117,7 +117,15 @@
 }
 
 UiIcon* ui_fileicon(size_t size) {
-    return ui_icon("file", size);
+    UiIcon *icon = ui_icon("file", size);
+#if GTK_MAJOR_VERSION >= 4
+    GFile *file = gtk_icon_paintable_get_file(icon->info);
+    char *path = g_file_get_path(file);
+    if(!path) {
+        icon = ui_icon("application-x-generic", size);
+    }
+#endif
+    return icon;
 }
 
 UiIcon* ui_icon_unscaled(const char *name, int size) {
@@ -129,7 +137,8 @@
     if(!icon->pixbuf) {
         GFile *file = gtk_icon_paintable_get_file(icon->info);
         GError *error = NULL;
-        icon->pixbuf = gdk_pixbuf_new_from_file(g_file_get_path(file), &error);
+        char *path = g_file_get_path(file);
+        icon->pixbuf = gdk_pixbuf_new_from_file(path, &error);
     }
     return icon->pixbuf;
 }

mercurial