comparison libpurple/protocols/msn/msn.c @ 25237:401f548e3544

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