libpurple/protocols/myspace/myspace.c

branch
soc.2007.msimprpl
changeset 17933
03228b5c78b5
parent 17931
122a102e2399
child 17934
d163dde3aff1
equal deleted inserted replaced
17932:0d1fa8f1bf22 17933:03228b5c78b5
978 */ 978 */
979 void msim_status_cb(MsimSession *session, MsimMessage *userinfo, gpointer data) 979 void msim_status_cb(MsimSession *session, MsimMessage *userinfo, gpointer data)
980 { 980 {
981 PurpleBuddyList *blist; 981 PurpleBuddyList *blist;
982 PurpleBuddy *buddy; 982 PurpleBuddy *buddy;
983 PurplePresence *presence;
984 GHashTable *body; 983 GHashTable *body;
985 gchar *body_str; 984 gchar *body_str;
986 //PurpleStatus *status; 985 //PurpleStatus *status;
987 gchar **status_array; 986 gchar **status_array;
988 GList *list; 987 GList *list;
989 gchar *status_text, *status_code; 988 gchar *status_headline;
990 gchar *status_str; 989 gchar *status_str;
991 gint i; 990 gint i, status_code, purple_status_code;
992 gchar *username; 991 gchar *username;
993 992
994 g_return_if_fail(MSIM_SESSION_VALID(session)); 993 g_return_if_fail(MSIM_SESSION_VALID(session));
995 g_return_if_fail(userinfo != NULL); 994 g_return_if_fail(userinfo != NULL);
996 995
1013 1012
1014 purple_debug_info("msim", 1013 purple_debug_info("msim",
1015 "msim_status_cb: updating status for <%s> to <%s>\n", 1014 "msim_status_cb: updating status for <%s> to <%s>\n",
1016 username, status_str); 1015 username, status_str);
1017 1016
1018 /* TODO: generic functions to split into a GList */ 1017 /* TODO: generic functions to split into a GList, part of MsimMessage */
1019 status_array = g_strsplit(status_str, "|", 0); 1018 status_array = g_strsplit(status_str, "|", 0);
1020 for (list = NULL, i = 0; 1019 for (list = NULL, i = 0;
1021 status_array[i]; 1020 status_array[i];
1022 i++) 1021 i++)
1023 { 1022 {
1023 /* Note: this adds the 0th ordinal too, which might not be a value
1024 * at all (the 0 in the 0|1|2|3... status fields, but 0 always appears blank).
1025 */
1024 list = g_list_append(list, status_array[i]); 1026 list = g_list_append(list, status_array[i]);
1025 } 1027 }
1026 1028
1027 /* Example fields: |s|0|ss|Offline */ 1029 /* Example fields:
1028 status_code = g_list_nth_data(list, 2); 1030 * |s|0|ss|Offline
1029 status_text = g_list_nth_data(list, 4); 1031 * |s|1|ss|:-)|ls||ip|0|p|0
1032 *
1033 * TODO: write list support in MsimMessage, and use it here.
1034 */
1035
1036 status_code = atoi(g_list_nth_data(list, MSIM_STATUS_ORDINAL_ONLINE));
1037 purple_debug_info("msim", "msim_status_cb: %s's status code = %d\n", username, status_code);
1038 status_headline = g_list_nth_data(list, MSIM_STATUS_ORDINAL_HEADLINE);
1030 1039
1031 blist = purple_get_blist(); 1040 blist = purple_get_blist();
1032 1041
1033 /* Add buddy if not found */ 1042 /* Add buddy if not found */
1034 buddy = purple_find_buddy(session->account, username); 1043 buddy = purple_find_buddy(session->account, username);
1043 purple_blist_add_buddy(buddy, NULL, NULL, NULL); 1052 purple_blist_add_buddy(buddy, NULL, NULL, NULL);
1044 } else { 1053 } else {
1045 purple_debug_info("msim", "msim_status: found buddy %s\n", username); 1054 purple_debug_info("msim", "msim_status: found buddy %s\n", username);
1046 } 1055 }
1047 1056
1048 /* For now, always set status to online. 1057 /* TODO: show headline */
1049 * TODO: make status reflect reality 1058
1050 * TODO: show headline */ 1059 /* Set user status */
1051 presence = purple_presence_new_for_buddy(buddy); 1060 switch (status_code)
1052 /* purple_presence_set_status_active(presence, PURPLE_STATUS_AVAILABLE, TRUE); */ 1061 {
1062 case 1: purple_status_code = PURPLE_STATUS_AVAILABLE;
1063 break;
1064 case 0: purple_status_code = PURPLE_STATUS_OFFLINE;
1065 break;
1066 default:
1067 purple_debug_info("msim", "msim_status_cb for %s, unknown status code %d\n",
1068 username, status_code);
1069 purple_status_code = PURPLE_STATUS_AVAILABLE;
1070 }
1071 purple_prpl_got_user_status(session->account, username, purple_primitive_get_id_from_type(purple_status_code), NULL);
1053 1072
1054 g_strfreev(status_array); 1073 g_strfreev(status_array);
1055 g_list_free(list); 1074 g_list_free(list);
1056 g_hash_table_destroy(body); 1075 g_hash_table_destroy(body);
1057 /* msim_msg_free(userinfo); TODO: right? */ 1076 /* msim_msg_free(userinfo); TODO: right? */
1536 NULL, /* send_typing */ 1555 NULL, /* send_typing */
1537 NULL, /* get_info */ 1556 NULL, /* get_info */
1538 NULL, /* set_away */ 1557 NULL, /* set_away */
1539 NULL, /* set_idle */ 1558 NULL, /* set_idle */
1540 NULL, /* change_passwd */ 1559 NULL, /* change_passwd */
1541 NULL, /* add_buddy */ 1560 NULL, /* add_buddy TODO */
1542 NULL, /* add_buddies */ 1561 NULL, /* add_buddies */
1543 NULL, /* remove_buddy */ 1562 NULL, /* remove_buddy TODO */
1544 NULL, /* remove_buddies */ 1563 NULL, /* remove_buddies */
1545 NULL, /* add_permit */ 1564 NULL, /* add_permit */
1546 NULL, /* add_deny */ 1565 NULL, /* add_deny */
1547 NULL, /* rem_permit */ 1566 NULL, /* rem_permit */
1548 NULL, /* rem_deny */ 1567 NULL, /* rem_deny */
1591 PurplePluginInfo info = 1610 PurplePluginInfo info =
1592 { 1611 {
1593 PURPLE_PLUGIN_MAGIC, 1612 PURPLE_PLUGIN_MAGIC,
1594 PURPLE_MAJOR_VERSION, 1613 PURPLE_MAJOR_VERSION,
1595 PURPLE_MINOR_VERSION, 1614 PURPLE_MINOR_VERSION,
1596 PURPLE_PLUGIN_PROTOCOL, /**< type */ 1615 PURPLE_PLUGIN_PROTOCOL, /**< type */
1597 NULL, /**< ui_requirement */ 1616 NULL, /**< ui_requirement */
1598 0, /**< flags */ 1617 0, /**< flags */
1599 NULL, /**< dependencies */ 1618 NULL, /**< dependencies */
1600 PURPLE_PRIORITY_DEFAULT, /**< priority */ 1619 PURPLE_PRIORITY_DEFAULT, /**< priority */
1601 1620
1602 "prpl-myspace", /**< id */ 1621 "prpl-myspace", /**< id */
1603 "MySpaceIM", /**< name */ 1622 "MySpaceIM", /**< name */
1604 "0.6" /**< version */ 1623 "0.6", /**< version */
1605 /** summary */ 1624 /** summary */
1606 "MySpaceIM Protocol Plugin", 1625 "MySpaceIM Protocol Plugin",
1607 /** description */ 1626 /** description */
1608 "MySpaceIM Protocol Plugin", 1627 "MySpaceIM Protocol Plugin",
1609 "Jeff Connelly <myspaceim@xyzzy.cjb.net>", /**< author */ 1628 "Jeff Connelly <myspaceim@xyzzy.cjb.net>", /**< author */

mercurial