comparison pidgin/gtkconv.c @ 16381:72dc611f3257

Fix the custom icon stuff, and various memory leaks. At this point, custom icons work properly, EXCEPT FOR A SERIOUS LEAK which I haven't fixed yet because I'm seeing weird memory allocation issues. Once I deal with that, it's just the account icon stuff that's left.
author Richard Laager <rlaager@wiktel.com>
date Tue, 24 Apr 2007 17:00:22 +0000
parents 391a79778f89
children 05033ae856b2
comparison
equal deleted inserted replaced
16380:6c97924af83b 16381:72dc611f3257
2480 return; 2480 return;
2481 } 2481 }
2482 fclose(fp); 2482 fclose(fp);
2483 } 2483 }
2484 2484
2485 static const char *
2486 custom_icon_pref_name(PidginConversation *gtkconv)
2487 {
2488 PurpleConversation *conv;
2489 PurpleAccount *account;
2490 PurpleBuddy *buddy;
2491
2492 conv = gtkconv->active_conv;
2493 account = purple_conversation_get_account(conv);
2494 buddy = purple_find_buddy(account, purple_conversation_get_name(conv));
2495 if (buddy) {
2496 PurpleContact *contact = purple_buddy_get_contact(buddy);
2497 return purple_blist_node_get_string((PurpleBlistNode*)contact, "custom_buddy_icon");
2498 }
2499 return NULL;
2500 }
2501
2502 static void 2485 static void
2503 custom_icon_sel_cb(const char *filename, gpointer data) 2486 custom_icon_sel_cb(const char *filename, gpointer data)
2504 { 2487 {
2505 if (filename) { 2488 if (filename) {
2506 PidginConversation *gtkconv = data; 2489 PidginConversation *gtkconv = data;
2572 2555
2573 static gboolean 2556 static gboolean
2574 icon_menu(GtkObject *obj, GdkEventButton *e, PidginConversation *gtkconv) 2557 icon_menu(GtkObject *obj, GdkEventButton *e, PidginConversation *gtkconv)
2575 { 2558 {
2576 static GtkWidget *menu = NULL; 2559 static GtkWidget *menu = NULL;
2577 const char *pref; 2560 PurpleConversation *conv;
2561 PurpleBuddy *buddy;
2578 2562
2579 if (e->button != 3 || e->type != GDK_BUTTON_PRESS) 2563 if (e->button != 3 || e->type != GDK_BUTTON_PRESS)
2580 return FALSE; 2564 return FALSE;
2581 2565
2582 /* 2566 /*
2606 pidgin_new_item_from_stock(menu, _("Set Custom Icon..."), NULL, 2590 pidgin_new_item_from_stock(menu, _("Set Custom Icon..."), NULL,
2607 G_CALLBACK(set_custom_icon_cb), gtkconv, 2591 G_CALLBACK(set_custom_icon_cb), gtkconv,
2608 0, 0, NULL); 2592 0, 0, NULL);
2609 2593
2610 /* Is there a custom icon for this person? */ 2594 /* Is there a custom icon for this person? */
2611 pref = custom_icon_pref_name(gtkconv); 2595 conv = gtkconv->active_conv;
2612 if (pref && *pref) { 2596 buddy = purple_find_buddy(purple_conversation_get_account(conv),
2613 pidgin_new_item_from_stock(menu, _("Remove Custom Icon"), NULL, 2597 purple_conversation_get_name(conv));
2614 G_CALLBACK(remove_custom_icon_cb), gtkconv, 2598 if (buddy)
2615 0, 0, NULL); 2599 {
2600 PurpleContact *contact = purple_buddy_get_contact(buddy);
2601 if (contact && purple_buddy_icons_has_custom_icon(contact))
2602 {
2603 pidgin_new_item_from_stock(menu, _("Remove Custom Icon"), NULL,
2604 G_CALLBACK(remove_custom_icon_cb), gtkconv,
2605 0, 0, NULL);
2606 }
2616 } 2607 }
2617 2608
2618 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, e->button, e->time); 2609 gtk_menu_popup(GTK_MENU(menu), NULL, NULL, NULL, NULL, e->button, e->time);
2619 2610
2620 return TRUE; 2611 return TRUE;
6173 pidgin_conv_update_buddy_icon(PurpleConversation *conv) 6164 pidgin_conv_update_buddy_icon(PurpleConversation *conv)
6174 { 6165 {
6175 PidginConversation *gtkconv; 6166 PidginConversation *gtkconv;
6176 PidginWindow *win; 6167 PidginWindow *win;
6177 6168
6169 PurpleBuddy *buddy;
6170
6178 GdkPixbufLoader *loader; 6171 GdkPixbufLoader *loader;
6179 GdkPixbufAnimation *anim; 6172 GdkPixbufAnimation *anim;
6180 GError *err = NULL; 6173 GError *err = NULL;
6181 6174
6182 const char *custom = NULL; 6175 PurpleStoredImage *custom_img = NULL;
6183 const void *data = NULL; 6176 gconstpointer data = NULL;
6184 size_t len; 6177 size_t len;
6185 6178
6186 GdkPixbuf *buf; 6179 GdkPixbuf *buf;
6187 6180
6188 GtkWidget *event; 6181 GtkWidget *event;
6235 return; 6228 return;
6236 6229
6237 if (purple_conversation_get_gc(conv) == NULL) 6230 if (purple_conversation_get_gc(conv) == NULL)
6238 return; 6231 return;
6239 6232
6240 custom = custom_icon_pref_name(gtkconv); 6233 buddy = purple_find_buddy(account, purple_conversation_get_name(conv));
6241 if (custom) { 6234 if (buddy)
6242 /* There is a custom icon for this user */ 6235 {
6243 char *contents = NULL; 6236 PurpleContact *contact = purple_buddy_get_contact(buddy);
6244 if (!g_file_get_contents(custom, &contents, &len, &err)) { 6237 if (contact) {
6245 purple_debug_warning("custom icon", "could not load custom icon %s for %s\n", 6238 custom_img = purple_buddy_icons_find_custom_icon(contact);
6246 custom, purple_conversation_get_name(conv)); 6239 if (custom_img) {
6247 g_error_free(err); 6240 /* There is a custom icon for this user */
6248 err = NULL; 6241 data = purple_imgstore_get_data(custom_img);
6249 } else 6242 len = purple_imgstore_get_size(custom_img);
6250 data = contents; 6243 }
6244 }
6251 } 6245 }
6252 6246
6253 if (data == NULL) { 6247 if (data == NULL) {
6254 icon = purple_conv_im_get_icon(PURPLE_CONV_IM(conv)); 6248 icon = purple_conv_im_get_icon(PURPLE_CONV_IM(conv));
6255 6249
6256 if (icon == NULL) 6250 if (icon == NULL)
6257 return; 6251 return;
6258 6252
6259 data = purple_buddy_icon_get_data(icon, &len); 6253 data = purple_buddy_icon_get_data(icon, &len);
6260 custom = NULL; 6254
6255 if (data == NULL)
6256 return;
6261 } 6257 }
6262 6258
6263 loader = gdk_pixbuf_loader_new(); 6259 loader = gdk_pixbuf_loader_new();
6264 gdk_pixbuf_loader_write(loader, data, len, NULL); 6260 gdk_pixbuf_loader_write(loader, data, len, NULL);
6265 gdk_pixbuf_loader_close(loader, &err); 6261 gdk_pixbuf_loader_close(loader, &err);
6266 anim = gdk_pixbuf_loader_get_animation(loader); 6262 anim = gdk_pixbuf_loader_get_animation(loader);
6267 if (anim) 6263 if (anim)
6268 g_object_ref(G_OBJECT(anim)); 6264 g_object_ref(G_OBJECT(anim));
6269 g_object_unref(loader); 6265 g_object_unref(loader);
6270 6266
6271 if (custom) 6267 // TODO: FIX THIS!!!
6272 g_free((void*)data); 6268 //purple_imgstore_unref(custom_img);
6273 6269
6274 if (!anim) 6270 if (!anim)
6275 return; 6271 return;
6276 gtkconv->u.im->anim = anim; 6272 gtkconv->u.im->anim = anim;
6277 6273
6278 if (err) { 6274 if (err) {
6279 purple_debug(PURPLE_DEBUG_ERROR, "gtkconv", 6275 purple_debug(PURPLE_DEBUG_ERROR, "gtkconv",
6280 "Buddy icon error: %s\n", err->message); 6276 "Buddy icon error: %s\n", err->message);
6281 g_error_free(err); 6277 g_error_free(err);
6282 } 6278 }
6283
6284 if (!gtkconv->u.im->anim)
6285 return;
6286 6279
6287 if (gdk_pixbuf_animation_is_static_image(gtkconv->u.im->anim)) { 6280 if (gdk_pixbuf_animation_is_static_image(gtkconv->u.im->anim)) {
6288 gtkconv->u.im->iter = NULL; 6281 gtkconv->u.im->iter = NULL;
6289 buf = gdk_pixbuf_animation_get_static_image(gtkconv->u.im->anim); 6282 buf = gdk_pixbuf_animation_get_static_image(gtkconv->u.im->anim);
6290 } else { 6283 } else {