fix file icon and fix crash if a list icon is NULL newapi

Sun, 06 Oct 2024 18:45:47 +0200

author
Olaf Wintermann <olaf.wintermann@gmail.com>
date
Sun, 06 Oct 2024 18:45:47 +0200
branch
newapi
changeset 327
216d8912714c
parent 326
3968180cdfb0
child 329
08ce6680d1cf

fix file icon and fix crash if a list icon is NULL

ui/gtk/image.c file | annotate | diff | comparison | revisions
ui/gtk/list.c file | annotate | diff | comparison | revisions
--- a/ui/gtk/image.c	Sun Oct 06 12:19:40 2024 +0200
+++ b/ui/gtk/image.c	Sun Oct 06 18:45:47 2024 +0200
@@ -117,7 +117,7 @@
 }
 
 UiIcon* ui_fileicon(size_t size) {
-    return ui_icon("application-x-generic", size);
+    return ui_icon("file", size);
 }
 
 UiIcon* ui_icon_unscaled(const char *name, int size) {
--- a/ui/gtk/list.c	Sun Oct 06 12:19:40 2024 +0200
+++ b/ui/gtk/list.c	Sun Oct 06 18:45:47 2024 +0200
@@ -114,20 +114,24 @@
                     case UI_ICON_TEXT_FREE: {
                         UiIcon *icon = data;
 #if GTK_MAJOR_VERSION >= 4
-                        GValue iconvalue = G_VALUE_INIT;
-                        g_value_init(&iconvalue, G_TYPE_OBJECT);
-                        g_value_set_object(&iconvalue, ui_icon_pixbuf(icon));
-                        gtk_list_store_set_value(store, &iter, c, &iconvalue);
+                        if(icon) {
+                            GValue iconvalue = G_VALUE_INIT;
+                            g_value_init(&iconvalue, G_TYPE_OBJECT);
+                            g_value_set_object(&iconvalue, ui_icon_pixbuf(icon));
+                            gtk_list_store_set_value(store, &iter, c, &iconvalue);
+                        }
 #else
                         GValue pixbufvalue = G_VALUE_INIT;
-                        if(!icon->pixbuf && icon->info) {
-                            GError *error = NULL;
-                            GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error);
-                            icon->pixbuf = pixbuf;
+                        if(icon) {
+                            if(!icon->pixbuf && icon->info) {
+                                GError *error = NULL;
+                                GdkPixbuf *pixbuf = gtk_icon_info_load_icon(icon->info, &error);
+                                icon->pixbuf = pixbuf;
+                            }
+                            g_value_init(&pixbufvalue, G_TYPE_OBJECT);
+                            g_value_set_object(&pixbufvalue, icon->pixbuf);
+                            gtk_list_store_set_value(store, &iter, c, &pixbufvalue);
                         }
-                        g_value_init(&pixbufvalue, G_TYPE_OBJECT);
-                        g_value_set_object(&pixbufvalue, icon->pixbuf);
-                        gtk_list_store_set_value(store, &iter, c, &pixbufvalue);
 #endif
                         c++;
                         

mercurial