static GdkPixbuf * theme_boxes_get_avatar_pixbuf_with_cache (EmpathyContact *contact) { AvatarData *data; EmpathyAvatar *avatar; GdkPixbuf *tmp_pixbuf; GdkPixbuf *pixbuf = NULL; /* Check if avatar is in cache and if it's up to date */ avatar = empathy_contact_get_avatar (contact); data = g_object_get_data (G_OBJECT (contact), "chat-view-avatar-cache"); if (data) { if (avatar && !tp_strdiff (avatar->filename, data->filename)) { /* We have the avatar in cache */ return data->pixbuf; } } /* Avatar not in cache, create pixbuf */ tmp_pixbuf = empathy_pixbuf_avatar_from_contact_scaled (contact, 32, 32); if (tmp_pixbuf) { pixbuf = theme_boxes_pad_to_size (tmp_pixbuf, 32, 32, 6); g_object_unref (tmp_pixbuf); } if (!pixbuf) { return NULL; } /* Insert new pixbuf in cache. We store the filename as it's unique * for each version of an avatar, so we can use it to perform change * detection (as above). */ data = g_slice_new0 (AvatarData); data->filename = g_strdup (avatar->filename); data->pixbuf = pixbuf; g_object_set_data_full (G_OBJECT (contact), "chat-view-avatar-cache", data, theme_boxes_avatar_cache_data_free); return data->pixbuf; }
static GdkPixbuf * theme_boxes_get_avatar_pixbuf_with_cache (EmpathyContact *contact) { AvatarData *data; EmpathyAvatar *avatar; GdkPixbuf *tmp_pixbuf; GdkPixbuf *pixbuf = NULL; /* Check if avatar is in cache and if it's up to date */ avatar = empathy_contact_get_avatar (contact); data = g_object_get_data (G_OBJECT (contact), "chat-view-avatar-cache"); if (data) { if (avatar && !tp_strdiff (avatar->token, data->token)) { /* We have the avatar in cache */ return data->pixbuf; } } /* Avatar not in cache, create pixbuf */ tmp_pixbuf = empathy_pixbuf_avatar_from_contact_scaled (contact, 32, 32); if (tmp_pixbuf) { pixbuf = theme_boxes_pad_to_size (tmp_pixbuf, 32, 32, 6); g_object_unref (tmp_pixbuf); } if (!pixbuf) { return NULL; } /* Insert new pixbuf in cache */ data = g_slice_new0 (AvatarData); data->token = g_strdup (avatar->token); data->pixbuf = pixbuf; g_object_set_data_full (G_OBJECT (contact), "chat-view-avatar-cache", data, theme_boxes_avatar_cache_data_free); return data->pixbuf; }