aboutsummaryrefslogtreecommitdiff
path: root/libindicator/indicator-image-helper.c
diff options
context:
space:
mode:
authorLars Uebernickel <lars.uebernickel@canonical.com>2013-01-25 11:11:59 +0100
committerLars Uebernickel <lars.uebernickel@canonical.com>2013-01-25 11:11:59 +0100
commit9c857a30aa23445708c7ed7f1d00a7d0986946bd (patch)
treeb1dfef7323e798a52857401480c5d8e33af6b3d8 /libindicator/indicator-image-helper.c
parent70480923e6151c8173032710beb99707bb5b9485 (diff)
downloadlibayatana-indicator-9c857a30aa23445708c7ed7f1d00a7d0986946bd.tar.gz
libayatana-indicator-9c857a30aa23445708c7ed7f1d00a7d0986946bd.tar.bz2
libayatana-indicator-9c857a30aa23445708c7ed7f1d00a7d0986946bd.zip
indicator-ng: use indicator_image_helper
gtk_icon_set_from_gicon doesn't scale rectangular icons correctly. This adds indicator_image_helper_update_from_gicon() and makes refresh_image() set a broken image instead of erroring out when an icon couldn't be found.
Diffstat (limited to 'libindicator/indicator-image-helper.c')
-rw-r--r--libindicator/indicator-image-helper.c24
1 files changed, 20 insertions, 4 deletions
diff --git a/libindicator/indicator-image-helper.c b/libindicator/indicator-image-helper.c
index 63488a1..382d0c9 100644
--- a/libindicator/indicator-image-helper.c
+++ b/libindicator/indicator-image-helper.c
@@ -62,7 +62,12 @@ refresh_image (GtkImage * image)
/* Grab the filename */
icon_filename = gtk_icon_info_get_filename(icon_info);
}
- g_return_if_fail(icon_filename != NULL); /* An error because we don't have a filename */
+
+ /* show a broken image if we don't have a filename */
+ if (icon_filename == NULL) {
+ gtk_image_set_from_stock (image, GTK_STOCK_MISSING_IMAGE, GTK_ICON_SIZE_LARGE_TOOLBAR);
+ return;
+ }
/* Build a pixbuf */
GError * error = NULL;
@@ -132,7 +137,8 @@ indicator_image_helper (const gchar * name)
/* Build us an image */
GtkImage * image = GTK_IMAGE(gtk_image_new());
- indicator_image_helper_update(image, name);
+ if (name)
+ indicator_image_helper_update(image, name);
return image;
}
@@ -144,17 +150,27 @@ indicator_image_helper_update (GtkImage * image, const gchar * name)
g_return_if_fail(name != NULL);
g_return_if_fail(name[0] != '\0');
g_return_if_fail(GTK_IS_IMAGE(image));
- gboolean seen_previously = FALSE;
/* Build us a GIcon */
GIcon * icon_names = g_themed_icon_new_with_default_fallbacks(name);
g_warn_if_fail(icon_names != NULL);
g_return_if_fail(icon_names != NULL);
+ indicator_image_helper_update_from_gicon (image, icon_names);
+
+ g_object_unref (icon_names);
+ return;
+}
+
+void
+indicator_image_helper_update_from_gicon (GtkImage *image, GIcon *icon)
+{
+ gboolean seen_previously = FALSE;
+
seen_previously = (g_object_get_data(G_OBJECT(image), INDICATOR_NAMES_DATA) != NULL);
/* Attach our names to the image */
- g_object_set_data_full(G_OBJECT(image), INDICATOR_NAMES_DATA, icon_names, g_object_unref);
+ g_object_set_data_full(G_OBJECT(image), INDICATOR_NAMES_DATA, g_object_ref (icon), g_object_unref);
/* Put the pixbuf in */
refresh_image(image);