aboutsummaryrefslogtreecommitdiff
path: root/libindicator/indicator-image-helper.c
diff options
context:
space:
mode:
Diffstat (limited to 'libindicator/indicator-image-helper.c')
-rw-r--r--libindicator/indicator-image-helper.c68
1 files changed, 45 insertions, 23 deletions
diff --git a/libindicator/indicator-image-helper.c b/libindicator/indicator-image-helper.c
index 382d0c9..aff9e39 100644
--- a/libindicator/indicator-image-helper.c
+++ b/libindicator/indicator-image-helper.c
@@ -63,42 +63,64 @@ refresh_image (GtkImage * image)
icon_filename = gtk_icon_info_get_filename(icon_info);
}
- /* show a broken image if we don't have a filename */
- if (icon_filename == NULL) {
+ if (icon_filename == NULL && !G_IS_BYTES_ICON (icon_names)) {
+ /* show a broken image if we don't have a filename or image data */
gtk_image_set_from_stock (image, GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_LARGE_TOOLBAR);
return;
}
/* Build a pixbuf */
- GError * error = NULL;
- GdkPixbuf * pixbuf = gdk_pixbuf_new_from_file(icon_filename, &error);
+ GdkPixbuf * pixbuf = NULL;
- if (icon_info != NULL) {
- gtk_icon_info_free(icon_info);
- }
+ 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 {
+ GError * error = NULL;
- if (pixbuf == NULL) {
- g_warning("Unable to load icon from file '%s' because: %s", icon_filename, error == NULL ? "I don't know" : error->message);
- g_clear_error (&error);
- gtk_image_clear(image);
- return;
+ pixbuf = gdk_pixbuf_new_from_file (icon_filename, &error);
+
+ if (pixbuf == NULL) {
+ g_warning ("Unable to load icon from file '%s': %s", icon_filename, error->message);
+ g_error_free (error);
+ }
}
- /* 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 (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);
+
+ GdkPixbuf * scaled = gdk_pixbuf_scale_simple(pixbuf, width, icon_size, GDK_INTERP_BILINEAR);
+ g_object_unref(G_OBJECT(pixbuf));
+ pixbuf = scaled;
+ }
- 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));
-
- return;
+ if (icon_info != NULL) {
+ gtk_icon_info_free (icon_info);
+ }
}
/* Handles the theme changed signal to refresh the icon to make