| 51 /****************************************************************************** |
51 /****************************************************************************** |
| 52 * Helpers |
52 * Helpers |
| 53 *****************************************************************************/ |
53 *****************************************************************************/ |
| 54 static void |
54 static void |
| 55 pidgin_avatar_update(PidginAvatar *avatar) { |
55 pidgin_avatar_update(PidginAvatar *avatar) { |
| 56 PurpleAvatar *purple_avatar = NULL; |
56 PurpleImage *purple_avatar = NULL; |
| 57 GdkPixbufAnimation *animation = NULL; |
|
| 58 GdkPixbuf *pixbuf = NULL; |
|
| 59 GdkTexture *texture = NULL; |
57 GdkTexture *texture = NULL; |
| 60 |
58 |
| 61 if(PURPLE_IS_CONTACT_INFO(avatar->info)) { |
59 if(PURPLE_IS_CONTACT_INFO(avatar->info)) { |
| 62 purple_avatar = purple_contact_info_get_avatar(avatar->info); |
60 purple_avatar = purple_contact_info_get_avatar(avatar->info); |
| 63 } else if(PURPLE_IS_CONVERSATION(avatar->conversation)) { |
61 } else if(PURPLE_IS_CONVERSATION(avatar->conversation)) { |
| 64 purple_avatar = purple_conversation_get_avatar(avatar->conversation); |
62 purple_avatar = purple_conversation_get_avatar(avatar->conversation); |
| 65 } |
63 } |
| 66 |
64 |
| 67 if(PURPLE_IS_AVATAR(purple_avatar)) { |
65 if(PURPLE_IS_IMAGE(purple_avatar)) { |
| 68 animation = purple_avatar_get_animation(purple_avatar); |
66 GBytes *contents = NULL; |
| 69 } |
67 GError *error = NULL; |
| 70 |
68 |
| 71 g_set_object(&avatar->animation, animation); |
69 contents = purple_image_get_contents(purple_avatar); |
| 72 |
70 texture = gdk_texture_new_from_bytes(contents, &error); |
| 73 if(GDK_IS_PIXBUF_ANIMATION(avatar->animation)) { |
71 if(error != NULL) { |
| 74 if(avatar->animate && |
72 g_warning("failed to create texture from bytes: %s", |
| 75 !gdk_pixbuf_animation_is_static_image(avatar->animation)) { |
73 error->message); |
| 76 pixbuf = GDK_PIXBUF(avatar->animation); |
74 g_clear_error(&error); |
| 77 } else { |
75 texture = NULL; |
| 78 pixbuf = gdk_pixbuf_animation_get_static_image(avatar->animation); |
|
| 79 } |
76 } |
| 80 } |
77 } |
| 81 |
78 |
| 82 texture = gdk_texture_new_for_pixbuf(pixbuf); |
|
| 83 gtk_picture_set_paintable(GTK_PICTURE(avatar->icon), |
79 gtk_picture_set_paintable(GTK_PICTURE(avatar->icon), |
| 84 GDK_PAINTABLE(texture)); |
80 GDK_PAINTABLE(texture)); |
| 85 |
81 |
| 86 g_clear_object(&texture); |
82 g_clear_object(&texture); |
| 87 g_clear_object(&animation); |
|
| 88 } |
83 } |
| 89 |
84 |
| 90 /****************************************************************************** |
85 /****************************************************************************** |
| 91 * Actions |
86 * Actions |
| 92 *****************************************************************************/ |
87 *****************************************************************************/ |