comparison pidgin/gtkconv.c @ 16478:0fa041c66957

propagate from branch 'im.pidgin.pidgin' (head 4d02676110c034e401f4d42ed7304a7507d96929) to branch 'im.pidgin.rlaager.gaim_migration' (head cdf5792eae6b63870cd030ae85774d5385b7d428)
author Richard Laager <rlaager@wiktel.com>
date Wed, 25 Apr 2007 05:26:12 +0000
parents 8e163086a171 05033ae856b2
children 5e47b3427b28
comparison
equal deleted inserted replaced
16411:58a097859388 16478:0fa041c66957
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;
2536 const gchar *ext; 2519 const gchar *ext;
2537 gchar *buf; 2520 gchar *buf;
2538 2521
2539 g_return_if_fail(conv != NULL); 2522 g_return_if_fail(conv != NULL);
2540 2523
2541 ext = purple_buddy_icon_get_type(purple_conv_im_get_icon(PURPLE_CONV_IM(conv))); 2524 ext = purple_buddy_icon_get_extension(purple_conv_im_get_icon(PURPLE_CONV_IM(conv)));
2542 if (ext == NULL)
2543 ext = "icon";
2544 2525
2545 buf = g_strdup_printf("%s.%s", purple_normalize(conv->account, conv->name), ext); 2526 buf = g_strdup_printf("%s.%s", purple_normalize(conv->account, conv->name), ext);
2546 2527
2547 purple_request_file(gtkconv, _("Save Icon"), buf, TRUE, 2528 purple_request_file(gtkconv, _("Save Icon"), buf, TRUE,
2548 G_CALLBACK(saveicon_writefile_cb), NULL, gtkconv); 2529 G_CALLBACK(saveicon_writefile_cb), NULL, gtkconv);
2574 2555
2575 static gboolean 2556 static gboolean
2576 icon_menu(GtkObject *obj, GdkEventButton *e, PidginConversation *gtkconv) 2557 icon_menu(GtkObject *obj, GdkEventButton *e, PidginConversation *gtkconv)
2577 { 2558 {
2578 static GtkWidget *menu = NULL; 2559 static GtkWidget *menu = NULL;
2579 const char *pref; 2560 PurpleConversation *conv;
2561 PurpleBuddy *buddy;
2580 2562
2581 if (e->button != 3 || e->type != GDK_BUTTON_PRESS) 2563 if (e->button != 3 || e->type != GDK_BUTTON_PRESS)
2582 return FALSE; 2564 return FALSE;
2583 2565
2584 /* 2566 /*
2608 pidgin_new_item_from_stock(menu, _("Set Custom Icon..."), NULL, 2590 pidgin_new_item_from_stock(menu, _("Set Custom Icon..."), NULL,
2609 G_CALLBACK(set_custom_icon_cb), gtkconv, 2591 G_CALLBACK(set_custom_icon_cb), gtkconv,
2610 0, 0, NULL); 2592 0, 0, NULL);
2611 2593
2612 /* Is there a custom icon for this person? */ 2594 /* Is there a custom icon for this person? */
2613 pref = custom_icon_pref_name(gtkconv); 2595 conv = gtkconv->active_conv;
2614 if (pref && *pref) { 2596 buddy = purple_find_buddy(purple_conversation_get_account(conv),
2615 pidgin_new_item_from_stock(menu, _("Remove Custom Icon"), NULL, 2597 purple_conversation_get_name(conv));
2616 G_CALLBACK(remove_custom_icon_cb), gtkconv, 2598 if (buddy)
2617 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 }
2618 } 2607 }
2619 2608
2620 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);
2621 2610
2622 return TRUE; 2611 return TRUE;
6175 pidgin_conv_update_buddy_icon(PurpleConversation *conv) 6164 pidgin_conv_update_buddy_icon(PurpleConversation *conv)
6176 { 6165 {
6177 PidginConversation *gtkconv; 6166 PidginConversation *gtkconv;
6178 PidginWindow *win; 6167 PidginWindow *win;
6179 6168
6169 PurpleBuddy *buddy;
6170
6180 GdkPixbufLoader *loader; 6171 GdkPixbufLoader *loader;
6181 GdkPixbufAnimation *anim; 6172 GdkPixbufAnimation *anim;
6182 GError *err = NULL; 6173 GError *err = NULL;
6183 6174
6184 const char *custom = NULL; 6175 PurpleStoredImage *custom_img = NULL;
6185 const void *data = NULL; 6176 gconstpointer data = NULL;
6186 size_t len; 6177 size_t len;
6187 6178
6188 GdkPixbuf *buf; 6179 GdkPixbuf *buf;
6189 6180
6190 GtkWidget *event; 6181 GtkWidget *event;
6237 return; 6228 return;
6238 6229
6239 if (purple_conversation_get_gc(conv) == NULL) 6230 if (purple_conversation_get_gc(conv) == NULL)
6240 return; 6231 return;
6241 6232
6242 custom = custom_icon_pref_name(gtkconv); 6233 buddy = purple_find_buddy(account, purple_conversation_get_name(conv));
6243 if (custom) { 6234 if (buddy)
6244 /* There is a custom icon for this user */ 6235 {
6245 char *contents = NULL; 6236 PurpleContact *contact = purple_buddy_get_contact(buddy);
6246 if (!g_file_get_contents(custom, &contents, &len, &err)) { 6237 if (contact) {
6247 purple_debug_warning("custom icon", "could not load custom icon %s for %s\n", 6238 custom_img = purple_buddy_icons_find_custom_icon(contact);
6248 custom, purple_conversation_get_name(conv)); 6239 if (custom_img) {
6249 g_error_free(err); 6240 /* There is a custom icon for this user */
6250 err = NULL; 6241 data = purple_imgstore_get_data(custom_img);
6251 } else 6242 len = purple_imgstore_get_size(custom_img);
6252 data = contents; 6243 }
6244 }
6253 } 6245 }
6254 6246
6255 if (data == NULL) { 6247 if (data == NULL) {
6256 icon = purple_conv_im_get_icon(PURPLE_CONV_IM(conv)); 6248 icon = purple_conv_im_get_icon(PURPLE_CONV_IM(conv));
6257 6249
6258 if (icon == NULL) 6250 if (icon == NULL)
6259 return; 6251 return;
6260 6252
6261 data = purple_buddy_icon_get_data(icon, &len); 6253 data = purple_buddy_icon_get_data(icon, &len);
6262 custom = NULL; 6254
6255 if (data == NULL)
6256 return;
6263 } 6257 }
6264 6258
6265 loader = gdk_pixbuf_loader_new(); 6259 loader = gdk_pixbuf_loader_new();
6266 gdk_pixbuf_loader_write(loader, data, len, NULL); 6260 gdk_pixbuf_loader_write(loader, data, len, NULL);
6267 gdk_pixbuf_loader_close(loader, &err); 6261 gdk_pixbuf_loader_close(loader, &err);
6262
6263 purple_imgstore_unref(custom_img);
6264
6268 anim = gdk_pixbuf_loader_get_animation(loader); 6265 anim = gdk_pixbuf_loader_get_animation(loader);
6269 if (anim) 6266 if (anim)
6270 g_object_ref(G_OBJECT(anim)); 6267 g_object_ref(G_OBJECT(anim));
6271 g_object_unref(loader); 6268 g_object_unref(loader);
6272 6269
6273 if (custom)
6274 g_free((void*)data);
6275
6276 if (!anim) 6270 if (!anim)
6277 return; 6271 return;
6278 gtkconv->u.im->anim = anim; 6272 gtkconv->u.im->anim = anim;
6279 6273
6280 if (err) { 6274 if (err) {
6281 purple_debug(PURPLE_DEBUG_ERROR, "gtkconv", 6275 purple_debug(PURPLE_DEBUG_ERROR, "gtkconv",
6282 "Buddy icon error: %s\n", err->message); 6276 "Buddy icon error: %s\n", err->message);
6283 g_error_free(err); 6277 g_error_free(err);
6284 } 6278 }
6285
6286 if (!gtkconv->u.im->anim)
6287 return;
6288 6279
6289 if (gdk_pixbuf_animation_is_static_image(gtkconv->u.im->anim)) { 6280 if (gdk_pixbuf_animation_is_static_image(gtkconv->u.im->anim)) {
6290 gtkconv->u.im->iter = NULL; 6281 gtkconv->u.im->iter = NULL;
6291 buf = gdk_pixbuf_animation_get_static_image(gtkconv->u.im->anim); 6282 buf = gdk_pixbuf_animation_get_static_image(gtkconv->u.im->anim);
6292 } else { 6283 } else {