From 176ea145dc5f0ee8cc7bff73ccda74d5b90c816e Mon Sep 17 00:00:00 2001 From: William Hua Date: Sun, 19 May 2013 12:47:01 -0400 Subject: Code clean-up. --- libindicator/indicator-image-helper.c | 58 ++++++++++++++++------------------- 1 file changed, 27 insertions(+), 31 deletions(-) (limited to 'libindicator/indicator-image-helper.c') diff --git a/libindicator/indicator-image-helper.c b/libindicator/indicator-image-helper.c index c9dbb05..aff9e39 100644 --- a/libindicator/indicator-image-helper.c +++ b/libindicator/indicator-image-helper.c @@ -70,58 +70,54 @@ refresh_image (GtkImage * image) } /* Build a pixbuf */ - GError * error = NULL; GdkPixbuf * pixbuf = NULL; if (icon_filename == NULL) { + GError * error = NULL; GInputStream * stream = g_loadable_icon_load (G_LOADABLE_ICON (icon_names), icon_size, NULL, NULL, &error); if (stream != NULL) { pixbuf = gdk_pixbuf_new_from_stream (stream, NULL, &error); g_input_stream_close (stream, NULL, NULL); g_object_unref (stream); + + if (pixbuf == NULL) { + g_warning ("Unable to load icon from data: %s", error->message); + g_error_free (error); + } + } else { + g_warning ("Unable to load icon from data: %s", error->message); + g_error_free (error); } } else { - pixbuf = gdk_pixbuf_new_from_file (icon_filename, &error); - } + GError * error = NULL; - if (pixbuf == NULL) { - const gchar *message = "I don't know"; + pixbuf = gdk_pixbuf_new_from_file (icon_filename, &error); - if (error != NULL && error->message != NULL) { - message = error->message; + if (pixbuf == NULL) { + g_warning ("Unable to load icon from file '%s': %s", icon_filename, error->message); + g_error_free (error); } + } - if (icon_filename != NULL) { - g_warning ("Unable to load icon from file '%s': %s", icon_filename, message); - } else { - g_warning ("Unable to load icon from data: %s", message); - } + if (pixbuf != NULL) { + /* Scale icon if all we get is something too big. */ + if (gdk_pixbuf_get_height(pixbuf) > icon_size) { + gfloat scale = (gfloat)icon_size / (gfloat)gdk_pixbuf_get_height(pixbuf); + gint width = round(gdk_pixbuf_get_width(pixbuf) * scale); - if (error != NULL) { - g_clear_error (&error); + GdkPixbuf * scaled = gdk_pixbuf_scale_simple(pixbuf, width, icon_size, GDK_INTERP_BILINEAR); + g_object_unref(G_OBJECT(pixbuf)); + pixbuf = scaled; } - gtk_image_set_from_stock (image, GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_LARGE_TOOLBAR); - - goto out; - } - - /* Scale icon if all we get is something too big. */ - if (gdk_pixbuf_get_height(pixbuf) > icon_size) { - gfloat scale = (gfloat)icon_size / (gfloat)gdk_pixbuf_get_height(pixbuf); - gint width = round(gdk_pixbuf_get_width(pixbuf) * scale); - - GdkPixbuf * scaled = gdk_pixbuf_scale_simple(pixbuf, width, icon_size, GDK_INTERP_BILINEAR); + /* Put the pixbuf on the image */ + gtk_image_set_from_pixbuf(image, pixbuf); g_object_unref(G_OBJECT(pixbuf)); - pixbuf = scaled; + } else { + gtk_image_set_from_stock (image, GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_LARGE_TOOLBAR); } - /* Put the pixbuf on the image */ - gtk_image_set_from_pixbuf(image, pixbuf); - g_object_unref(G_OBJECT(pixbuf)); - -out: if (icon_info != NULL) { gtk_icon_info_free (icon_info); } -- cgit v1.2.3