aboutsummaryrefslogtreecommitdiff
diff options
context:
space:
mode:
authorCharles Kerr <charles.kerr@canonical.com>2013-07-01 11:11:26 -0500
committerCharles Kerr <charles.kerr@canonical.com>2013-07-01 11:11:26 -0500
commite31ab7b930c33f13d9f123e17032ba37b7bbbdcf (patch)
tree48997fa2c9312cbf9d8258e4c9e789347a67f9ec
parent5c6e761872518193c0bfa6f392cc6207abc4c058 (diff)
downloadayatana-ido-e31ab7b930c33f13d9f123e17032ba37b7bbbdcf.tar.gz
ayatana-ido-e31ab7b930c33f13d9f123e17032ba37b7bbbdcf.tar.bz2
ayatana-ido-e31ab7b930c33f13d9f123e17032ba37b7bbbdcf.zip
if a user's avatar icon file doesn't exist or isn't readable, fall back to the default avatar
-rw-r--r--src/idousermenuitem.c50
1 files changed, 49 insertions, 1 deletions
diff --git a/src/idousermenuitem.c b/src/idousermenuitem.c
index 07aeade..d0fdb09 100644
--- a/src/idousermenuitem.c
+++ b/src/idousermenuitem.c
@@ -285,6 +285,48 @@ ido_user_menu_item_primitive_draw_cb_gtk_3 (GtkWidget * widget,
return FALSE;
}
+/* Tests for basic icon errors such as missing or unreadable icon files. */
+static gboolean
+icon_is_loadable (GtkWidget * self, GIcon * icon, GError ** error)
+{
+ gint width;
+ gint height;
+ GtkIconInfo * info;
+ GdkPixbuf * pixbuf;
+ GtkStyleContext * style_context;
+ gboolean is_loadable;
+
+ style_context = gtk_widget_get_style_context (self);
+
+ if (!gtk_icon_size_lookup_for_settings (gtk_settings_get_default(),
+ GTK_ICON_SIZE_MENU,
+ &width,
+ &height))
+ {
+ /* arbitrary default size in case _size_lookup fails */
+ width = 12;
+ height = 12;
+ }
+
+ info = gtk_icon_theme_lookup_by_gicon (gtk_icon_theme_get_default(),
+ icon,
+ MIN (width, height),
+ GTK_ICON_LOOKUP_USE_BUILTIN |
+ GTK_ICON_LOOKUP_GENERIC_FALLBACK |
+ GTK_ICON_LOOKUP_FORCE_SIZE);
+
+ pixbuf = gtk_icon_info_load_symbolic_for_context (info,
+ style_context,
+ NULL,
+ error);
+
+ is_loadable = pixbuf != NULL;
+
+ g_clear_object (&pixbuf);
+ g_clear_object (&info);
+ return is_loadable;
+}
+
/***
**** PUBLIC API
***/
@@ -294,8 +336,14 @@ ido_user_menu_item_set_icon (IdoUserMenuItem * self, GIcon * icon)
{
IdoUserMenuItemPrivate * p = self->priv;
GtkImage * image = GTK_IMAGE (p->user_image);
+ GError * error = NULL;
- g_clear_object (&p->icon);
+ if (icon && !icon_is_loadable (GTK_WIDGET(self), icon, &error))
+ {
+ g_warning ("Can't load user avatar icon: %s", error->message);
+ g_error_free (error);
+ icon = NULL;
+ }
if (icon != NULL)
g_object_ref (icon);