From 8399ef2d7ca518f154580e37458f93e476a71e47 Mon Sep 17 00:00:00 2001 From: Benedikt Heine Date: Thu, 5 Jul 2018 17:50:07 +0200 Subject: [PATCH] Better warnings for failed icons As the get_pixbuf_from_file should retrieve a file's content, it shouldn't fail silently, if the file isn't there. For codepaths, which don't use the `icon_path` to search for a given icon, it gives a clearer error message. --- src/icon.c | 21 ++++++++++----------- 1 file changed, 10 insertions(+), 11 deletions(-) diff --git a/src/icon.c b/src/icon.c index 1dbf0f2..9721961 100644 --- a/src/icon.c +++ b/src/icon.c @@ -60,16 +60,14 @@ cairo_surface_t *gdk_pixbuf_to_cairo_surface(GdkPixbuf *pixbuf) GdkPixbuf *get_pixbuf_from_file(const char *filename) { - GdkPixbuf *pixbuf = NULL; char *path = string_to_path(g_strdup(filename)); + GError *error = NULL; - if (is_readable_file(path)) { - GError *error = NULL; - pixbuf = gdk_pixbuf_new_from_file(path, &error); - if (!pixbuf) { - LOG_W("%s", error->message); - g_error_free(error); - } + GdkPixbuf *pixbuf = gdk_pixbuf_new_from_file(path, &error); + + if (error) { + LOG_W("%s", error->message); + g_error_free(error); } g_free(path); @@ -106,7 +104,8 @@ GdkPixbuf *get_pixbuf_from_icon(const char *iconname) for (const char **suf = suffixes; *suf; suf++) { maybe_icon_path = g_strconcat(current_folder, "/", iconname, *suf, NULL); - pixbuf = get_pixbuf_from_file(maybe_icon_path); + if (is_readable_file(maybe_icon_path)) + pixbuf = get_pixbuf_from_file(maybe_icon_path); g_free(maybe_icon_path); if (pixbuf) @@ -119,9 +118,9 @@ GdkPixbuf *get_pixbuf_from_icon(const char *iconname) start = end + 1; } while (*(end) != '\0'); + if (!pixbuf) + LOG_W("No icon found in path: '%s'", iconname); } - if (!pixbuf) - LOG_W("No icon found for: '%s'", iconname); g_free(uri_path); return pixbuf;