From f460d7c2414c7eea4cbc4af4fa1e4534781f0fe5 Mon Sep 17 00:00:00 2001 From: djcb Date: Sun, 14 Oct 2012 17:01:28 +0300 Subject: [PATCH] * mu-widget-util.c: improve error reporting --- toys/mug/mu-widget-util.c | 31 ++++++++++++++++++------------- 1 file changed, 18 insertions(+), 13 deletions(-) diff --git a/toys/mug/mu-widget-util.c b/toys/mug/mu-widget-util.c index 32e527dc..7af476a3 100644 --- a/toys/mug/mu-widget-util.c +++ b/toys/mug/mu-widget-util.c @@ -1,5 +1,5 @@ /* -** Copyright (C) 2011 Dirk-Jan C. Binnema +** Copyright (C) 2011-2012 Dirk-Jan C. Binnema ** ** This program is free software; you can redistribute it and/or modify it ** under the terms of the GNU General Public License as published by the @@ -30,7 +30,7 @@ second_guess_content_type (const char *ctype) const char *orig, *subst; } substtable [] = { {"text", "text/plain"}, - {"image/pjpeg", "image/jpeg" } + {"image/pjpeg", "image/jpeg" } }; for (i = 0; i != G_N_ELEMENTS(substtable); ++i) @@ -45,27 +45,34 @@ get_icon_pixbuf_for_content_type (const char *ctype, size_t size) { GIcon *icon; GdkPixbuf *pixbuf; - + GError *err; + icon = g_content_type_get_icon (ctype); pixbuf = NULL; - + err = NULL; + /* based on a snippet from http://www.gtkforums.com/about4721.html */ if (G_IS_THEMED_ICON(icon)) { gchar const * const *names; names = g_themed_icon_get_names (G_THEMED_ICON(icon)); pixbuf = gtk_icon_theme_load_icon (gtk_icon_theme_get_default(), - *names, size, 0, NULL); + *names, size, 0, &err); } else if (G_IS_FILE_ICON(icon)) { GFile *icon_file; - gchar *path; + gchar *path; icon_file = g_file_icon_get_file (G_FILE_ICON(icon)); path = g_file_get_path (icon_file); - pixbuf = gdk_pixbuf_new_from_file_at_size (path, size, size, NULL); + pixbuf = gdk_pixbuf_new_from_file_at_size (path, size, size, &err); g_free (path); g_object_unref(icon_file); } g_object_unref(icon); - + + if (err) { + g_warning ("error: %s\n", err->message); + g_clear_error (&err); + } + return pixbuf; } @@ -79,11 +86,9 @@ mu_widget_util_get_icon_pixbuf_for_content_type (const char *ctype, size_t size) g_return_val_if_fail (size > 0, NULL); pixbuf = get_icon_pixbuf_for_content_type (ctype, size); - if (!pixbuf) + if (!pixbuf) pixbuf = get_icon_pixbuf_for_content_type - (second_guess_content_type (ctype), size); - + (second_guess_content_type (ctype), size); + return pixbuf; } - -