diff options
author | William Hua <william.hua@canonical.com> | 2013-05-19 12:47:01 -0400 |
---|---|---|
committer | William Hua <william.hua@canonical.com> | 2013-05-19 12:47:01 -0400 |
commit | 176ea145dc5f0ee8cc7bff73ccda74d5b90c816e (patch) | |
tree | 6409a025b504ff6cf0b2b9e5cf41e1e7c2495f59 | |
parent | bab64c460d9671cfad38d77c4dcb40cd139201bc (diff) | |
download | libayatana-indicator-176ea145dc5f0ee8cc7bff73ccda74d5b90c816e.tar.gz libayatana-indicator-176ea145dc5f0ee8cc7bff73ccda74d5b90c816e.tar.bz2 libayatana-indicator-176ea145dc5f0ee8cc7bff73ccda74d5b90c816e.zip |
Code clean-up.
-rw-r--r-- | libindicator/indicator-image-helper.c | 58 |
1 files changed, 27 insertions, 31 deletions
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); } |