comparison libpurple/protocols/msn/msn.c @ 29268:9ea6842536ba

propagate from branch 'im.pidgin.pidgin' (head dd9cb9ed28311438c0cc3c2962f1c030fb282df3) to branch 'im.pidgin.cpw.attention_ui' (head a37bbe96365f1b9bea6638cd3a2a9d41310109b0)
author Marcus Lundblad <ml@update.uu.se>
date Thu, 01 Jan 2009 21:19:11 +0000
parents 558baf33197e f3950234b164
children af5c36fe8d6f
comparison
equal deleted inserted replaced
29267:58e1e1463b6e 29268:9ea6842536ba
647 const char *msg; 647 const char *msg;
648 648
649 presence = purple_buddy_get_presence(buddy); 649 presence = purple_buddy_get_presence(buddy);
650 status = purple_presence_get_active_status(presence); 650 status = purple_presence_get_active_status(presence);
651 651
652 /* I think status message should take precedence over media */ 652 if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_TUNE)) {
653 const char *title, *game, *office;
654 char *media, *esc;
655 status = purple_presence_get_status(presence, "tune");
656 title = purple_status_get_attr_string(status, PURPLE_TUNE_TITLE);
657
658 game = purple_status_get_attr_string(status, "game");
659 office = purple_status_get_attr_string(status, "office");
660
661 if (title && *title) {
662 const char *artist = purple_status_get_attr_string(status, PURPLE_TUNE_ARTIST);
663 const char *album = purple_status_get_attr_string(status, PURPLE_TUNE_ALBUM);
664 media = g_strdup_printf("%s%s%s%s%s%s", title,
665 (artist && *artist) ? " - " : "",
666 (artist && *artist) ? artist : "",
667 (album && *album) ? " (" : "",
668 (album && *album) ? album : "",
669 (album && *album) ? ")" : "");
670 }
671 else if (game && *game)
672 media = g_strdup_printf("Playing %s", game);
673 else if (office && *office)
674 media = g_strdup_printf("Editing %s", office);
675 else
676 return NULL;
677 esc = g_markup_escape_text(media, -1);
678 g_free(media);
679 return esc;
680 }
681
682 /* Official client says media takes precedence over message */
653 msg = purple_status_get_attr_string(status, "message"); 683 msg = purple_status_get_attr_string(status, "message");
654 if (msg && *msg) 684 if (msg && *msg)
655 return g_markup_escape_text(msg, -1); 685 return g_markup_escape_text(msg, -1);
656 686
657 if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_TUNE)) {
658 const char *title, *artist;
659 char *media, *esc;
660 status = purple_presence_get_status(presence, "tune");
661 title = purple_status_get_attr_string(status, PURPLE_TUNE_TITLE);
662 artist = purple_status_get_attr_string(status, PURPLE_TUNE_ARTIST);
663
664 media = g_strdup_printf("%s%s%s", title, artist ? " - " : "",
665 artist ? artist : "");
666 esc = g_markup_escape_text(media, -1);
667 g_free(media);
668 return esc;
669 }
670
671 return NULL; 687 return NULL;
672 } 688 }
673 689
674 static void 690 static void
675 msn_tooltip_text(PurpleBuddy *buddy, PurpleNotifyUserInfo *user_info, gboolean full) 691 msn_tooltip_text(PurpleBuddy *buddy, PurpleNotifyUserInfo *user_info, gboolean full)
681 user = buddy->proto_data; 697 user = buddy->proto_data;
682 698
683 if (purple_presence_is_online(presence)) 699 if (purple_presence_is_online(presence))
684 { 700 {
685 const char *psm, *name; 701 const char *psm, *name;
702 const char *mediatype = NULL;
686 char *currentmedia = NULL; 703 char *currentmedia = NULL;
687 char *tmp; 704 char *tmp;
688 705
689 psm = purple_status_get_attr_string(status, "message"); 706 psm = purple_status_get_attr_string(status, "message");
690 if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_TUNE)) { 707 if (purple_presence_is_status_primitive_active(presence, PURPLE_STATUS_TUNE)) {
691 PurpleStatus *tune = purple_presence_get_status(presence, "tune"); 708 PurpleStatus *tune = purple_presence_get_status(presence, "tune");
692 const char *title = purple_status_get_attr_string(tune, PURPLE_TUNE_TITLE); 709 const char *title = purple_status_get_attr_string(tune, PURPLE_TUNE_TITLE);
693 const char *artist = purple_status_get_attr_string(tune, PURPLE_TUNE_ARTIST); 710 const char *game = purple_status_get_attr_string(tune, "game");
694 const char *album = purple_status_get_attr_string(tune, PURPLE_TUNE_ALBUM); 711 const char *office = purple_status_get_attr_string(tune, "office");
695 currentmedia = purple_util_format_song_info(title, artist, album, NULL); 712 if (title && *title) {
696 /* We could probably just use user->media.title etc. here */ 713 const char *artist = purple_status_get_attr_string(tune, PURPLE_TUNE_ARTIST);
714 const char *album = purple_status_get_attr_string(tune, PURPLE_TUNE_ALBUM);
715 mediatype = _("Now Listening");
716 currentmedia = purple_util_format_song_info(title, artist, album, NULL);
717 } else if (game && *game) {
718 mediatype = _("Playing a game");
719 currentmedia = g_strdup(game);
720 } else if (office && *office) {
721 mediatype = _("Working");
722 currentmedia = g_strdup(office);
723 }
697 } 724 }
698 725
699 if (!purple_status_is_available(status)) { 726 if (!purple_status_is_available(status)) {
700 name = purple_status_get_name(status); 727 name = purple_status_get_name(status);
701 } else { 728 } else {
745 } 772 }
746 } 773 }
747 } 774 }
748 775
749 if (currentmedia) { 776 if (currentmedia) {
750 purple_notify_user_info_add_pair(user_info, _("Now Listening"), currentmedia); 777 purple_notify_user_info_add_pair(user_info, mediatype, currentmedia);
751 g_free(currentmedia); 778 g_free(currentmedia);
752 } 779 }
753 } 780 }
754 781
755 /* XXX: This is being shown in non-full tooltips because the 782 /* XXX: This is being shown in non-full tooltips because the
840 status = purple_status_type_new_with_attrs(PURPLE_STATUS_TUNE, 867 status = purple_status_type_new_with_attrs(PURPLE_STATUS_TUNE,
841 "tune", NULL, FALSE, TRUE, TRUE, 868 "tune", NULL, FALSE, TRUE, TRUE,
842 PURPLE_TUNE_ARTIST, _("Artist"), purple_value_new(PURPLE_TYPE_STRING), 869 PURPLE_TUNE_ARTIST, _("Artist"), purple_value_new(PURPLE_TYPE_STRING),
843 PURPLE_TUNE_ALBUM, _("Album"), purple_value_new(PURPLE_TYPE_STRING), 870 PURPLE_TUNE_ALBUM, _("Album"), purple_value_new(PURPLE_TYPE_STRING),
844 PURPLE_TUNE_TITLE, _("Title"), purple_value_new(PURPLE_TYPE_STRING), 871 PURPLE_TUNE_TITLE, _("Title"), purple_value_new(PURPLE_TYPE_STRING),
872 "game", _("Game Title"), purple_value_new(PURPLE_TYPE_STRING),
873 "office", _("Office Title"), purple_value_new(PURPLE_TYPE_STRING),
845 NULL); 874 NULL);
846 types = g_list_append(types, status); 875 types = g_list_append(types, status);
847 876
848 return types; 877 return types;
849 } 878 }
1389 msn_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) 1418 msn_add_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
1390 { 1419 {
1391 MsnSession *session; 1420 MsnSession *session;
1392 MsnUserList *userlist; 1421 MsnUserList *userlist;
1393 const char *who; 1422 const char *who;
1423 MsnUser *user;
1394 1424
1395 session = gc->proto_data; 1425 session = gc->proto_data;
1396 userlist = session->userlist; 1426 userlist = session->userlist;
1397 who = msn_normalize(gc->account, buddy->name); 1427 who = msn_normalize(gc->account, buddy->name);
1398 1428
1414 purple_debug_info("msn", "msn_add_buddy: %s, %s\n", who, group->name); 1444 purple_debug_info("msn", "msn_add_buddy: %s, %s\n", who, group->name);
1415 else 1445 else
1416 purple_debug_info("msn", "msn_add_buddy: %s\n", who); 1446 purple_debug_info("msn", "msn_add_buddy: %s\n", who);
1417 #endif 1447 #endif
1418 1448
1419 #if 0
1420 /* Which is the max? */
1421 if (session->fl_users_count >= 150)
1422 {
1423 purple_debug_info("msn", "Too many buddies\n");
1424 /* Buddy list full */
1425 /* TODO: purple should be notified of this */
1426 return;
1427 }
1428 #endif
1429
1430 /* XXX - Would group ever be NULL here? I don't think so... 1449 /* XXX - Would group ever be NULL here? I don't think so...
1431 * shx: Yes it should; MSN handles non-grouped buddies, and this is only 1450 * shx: Yes it should; MSN handles non-grouped buddies, and this is only
1432 * internal. */ 1451 * internal. */
1433 msn_userlist_add_buddy(userlist, who, group ? group->name : NULL); 1452 user = msn_userlist_find_user(userlist, who);
1453 if ((user != NULL) && (user->networkid != MSN_NETWORK_UNKNOWN)) {
1454 /* We already know this buddy and their network. This function knows
1455 what to do with users already in the list and stuff... */
1456 msn_userlist_add_buddy(userlist, who, group ? group->name : NULL);
1457 } else {
1458 /* We need to check the network for this buddy first */
1459 msn_userlist_save_pending_buddy(userlist, who, group ? group->name : NULL);
1460 msn_notification_send_fqy(session, who);
1461 }
1434 } 1462 }
1435 1463
1436 static void 1464 static void
1437 msn_rem_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group) 1465 msn_rem_buddy(PurpleConnection *gc, PurpleBuddy *buddy, PurpleGroup *group)
1438 { 1466 {
1811 } 1839 }
1812 1840
1813 if (b->server_alias) 1841 if (b->server_alias)
1814 { 1842 {
1815 char *nicktext = g_markup_escape_text(b->server_alias, -1); 1843 char *nicktext = g_markup_escape_text(b->server_alias, -1);
1816 tmp = g_strdup_printf("<font sml=\"msn\">%s</font><br>", nicktext); 1844 tmp = g_strdup_printf("<font sml=\"msn\">%s</font>", nicktext);
1817 purple_notify_user_info_add_pair(user_info, _("Nickname"), tmp); 1845 purple_notify_user_info_add_pair(user_info, _("Nickname"), tmp);
1818 g_free(tmp); 1846 g_free(tmp);
1819 g_free(nicktext); 1847 g_free(nicktext);
1820 } 1848 }
1821 1849
1917 user_info = purple_notify_user_info_new(); 1945 user_info = purple_notify_user_info_new();
1918 has_tooltip_text = msn_tooltip_extract_info_text(user_info, info_data); 1946 has_tooltip_text = msn_tooltip_extract_info_text(user_info, info_data);
1919 1947
1920 if (error_message != NULL || url_text == NULL || strcmp(url_text, "") == 0) 1948 if (error_message != NULL || url_text == NULL || strcmp(url_text, "") == 0)
1921 { 1949 {
1922 tmp = g_strdup_printf("<b>%s</b>", _("Error retrieving profile")); 1950 purple_notify_user_info_add_pair(user_info,
1923 purple_notify_user_info_add_pair(user_info, NULL, tmp); 1951 _("Error retrieving profile"), NULL);
1924 g_free(tmp);
1925 1952
1926 purple_notify_userinfo(info_data->gc, info_data->name, user_info, NULL, NULL); 1953 purple_notify_userinfo(info_data->gc, info_data->name, user_info, NULL, NULL);
1927 purple_notify_user_info_destroy(user_info); 1954 purple_notify_user_info_destroy(user_info);
1928 1955
1929 g_free(info_data->name); 1956 g_free(info_data->name);
2260 char *p = strstr(url_buffer, "form id=\"SpacesSearch\" name=\"SpacesSearch\""); 2287 char *p = strstr(url_buffer, "form id=\"SpacesSearch\" name=\"SpacesSearch\"");
2261 * Let's see how long this one holds out for ... */ 2288 * Let's see how long this one holds out for ... */
2262 char *p = strstr(url_buffer, "<form id=\"profile_form\" name=\"profile_form\" action=\"http&#58;&#47;&#47;spaces.live.com&#47;profile.aspx&#63;cid&#61;0\""); 2289 char *p = strstr(url_buffer, "<form id=\"profile_form\" name=\"profile_form\" action=\"http&#58;&#47;&#47;spaces.live.com&#47;profile.aspx&#63;cid&#61;0\"");
2263 PurpleBuddy *b = purple_find_buddy 2290 PurpleBuddy *b = purple_find_buddy
2264 (purple_connection_get_account(info_data->gc), info_data->name); 2291 (purple_connection_get_account(info_data->gc), info_data->name);
2265 purple_notify_user_info_add_pair(user_info, _("Error retrieving profile"), 2292 purple_notify_user_info_add_pair(user_info,
2266 ((p && b) ? _("The user has not created a public profile.") : 2293 _("Error retrieving profile"), NULL);
2267 (p ? _("MSN reported not being able to find the user's profile. " 2294 purple_notify_user_info_add_pair(user_info, NULL,
2268 "This either means that the user does not exist, " 2295 ((p && b) ? _("The user has not created a public profile.") :
2269 "or that the user exists " 2296 (p ? _("MSN reported not being able to find the user's profile. "
2270 "but has not created a public profile.") : 2297 "This either means that the user does not exist, "
2271 _("Could not find " /* This should never happen */ 2298 "or that the user exists "
2272 "any information in the user's profile. " 2299 "but has not created a public profile.") :
2273 "The user most likely does not exist.")))); 2300 _("Could not find " /* This should never happen */
2301 "any information in the user's profile. "
2302 "The user most likely does not exist."))));
2274 } 2303 }
2275 2304
2276 /* put a link to the actual profile URL */ 2305 /* put a link to the actual profile URL */
2277 tmp = g_strdup_printf("<a href=\"%s%s\">%s%s</a>", 2306 purple_notify_user_info_add_section_break(user_info);
2278 PROFILE_URL, info_data->name, PROFILE_URL, info_data->name); 2307 tmp = g_strdup_printf("<a href=\"%s%s\">%s</a>",
2279 purple_notify_user_info_add_pair(user_info, _("Profile URL"), tmp); 2308 PROFILE_URL, info_data->name, _("View web profile"));
2309 purple_notify_user_info_add_pair(user_info, NULL, tmp);
2280 g_free(tmp); 2310 g_free(tmp);
2281 2311
2282 #if PHOTO_SUPPORT 2312 #if PHOTO_SUPPORT
2283 /* Find the URL to the photo; must be before the marshalling [Bug 994207] */ 2313 /* Find the URL to the photo; must be before the marshalling [Bug 994207] */
2284 photo_url_text = msn_get_photo_url(url_text); 2314 photo_url_text = msn_get_photo_url(url_text);