aboutsummaryrefslogtreecommitdiff
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
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.
-rw-r--r--libindicator/indicator-image-helper.c24
-rw-r--r--libindicator/indicator-image-helper.h8
-rw-r--r--libindicator/indicator-ng.c3
-rw-r--r--tests/test-indicator-ng.c13
4 files changed, 28 insertions, 20 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);
diff --git a/libindicator/indicator-image-helper.h b/libindicator/indicator-image-helper.h
index 77e2f0a..290f4e2 100644
--- a/libindicator/indicator-image-helper.h
+++ b/libindicator/indicator-image-helper.h
@@ -26,8 +26,10 @@ License along with this library. If not, see
#include <gtk/gtk.h>
-GtkImage * indicator_image_helper (const gchar * name);
-void indicator_image_helper_update (GtkImage * image,
- const gchar * name);
+GtkImage * indicator_image_helper (const gchar * name);
+void indicator_image_helper_update (GtkImage * image,
+ const gchar * name);
+void indicator_image_helper_update_from_gicon (GtkImage * image,
+ GIcon * icon);
#endif /* __INDICATOR_IMAGE_HELPER_H__ */
diff --git a/libindicator/indicator-ng.c b/libindicator/indicator-ng.c
index f27fbf0..f4c98c6 100644
--- a/libindicator/indicator-ng.c
+++ b/libindicator/indicator-ng.c
@@ -1,5 +1,6 @@
#include "indicator-ng.h"
+#include "indicator-image-helper.h"
#include <string.h>
@@ -177,7 +178,7 @@ indicator_ng_set_icon_from_string (IndicatorNg *self,
icon = g_icon_new_for_string (str, &error);
if (icon)
{
- gtk_image_set_from_gicon (self->entry.image, icon, GTK_ICON_SIZE_LARGE_TOOLBAR);
+ indicator_image_helper_update_from_gicon (self->entry.image, icon);
g_object_unref (icon);
}
else
diff --git a/tests/test-indicator-ng.c b/tests/test-indicator-ng.c
index 185b3ee..150cc37 100644
--- a/tests/test-indicator-ng.c
+++ b/tests/test-indicator-ng.c
@@ -122,18 +122,7 @@ test_menu (void)
g_assert_cmpstr (entry->name_hint, ==, "indicator-test");
g_assert_cmpstr (entry->accessible_desc, ==, "Test indicator");
g_assert_cmpstr (gtk_label_get_label (entry->label), ==, "Test");
- {
- GIcon *icon;
- gchar *iconstr;
-
- gtk_image_get_gicon (entry->image, &icon, NULL);
- g_assert (icon);
-
- iconstr = g_icon_to_string (icon);
- g_assert_cmpstr (iconstr, ==, "indicator-test");
-
- g_free (iconstr);
- }
+ g_assert (gtk_image_get_storage_type (entry->image) == GTK_IMAGE_STOCK);
{
GList *children;
GtkMenuItem *item;