Mercurial > pidgin
comparison src/blist.c @ 6755:ea289c6f2382
[gaim-migrate @ 7287]
fix a bug with removing buddies, and the start of support for aliasing contacts
committer: Tailor Script <tailor@pidgin.im>
author | Nathan Walp <nwalp@pidgin.im> |
---|---|
date | Fri, 05 Sep 2003 17:04:39 +0000 |
parents | a781689ca455 |
children | c4e3cc0693ab |
comparison
equal
deleted
inserted
replaced
6754:47e49e3c00f4 | 6755:ea289c6f2382 |
---|---|
663 ops->new_node((GaimBlistNode *)c); | 663 ops->new_node((GaimBlistNode *)c); |
664 | 664 |
665 return c; | 665 return c; |
666 } | 666 } |
667 | 667 |
668 void gaim_contact_set_alias(GaimContact* contact, const char *alias) | |
669 { | |
670 g_return_if_fail(contact != NULL); | |
671 | |
672 if(contact->alias) | |
673 g_free(contact->alias); | |
674 | |
675 contact->alias = g_strdup(alias); | |
676 } | |
677 | |
678 const char *gaim_contact_get_alias(GaimContact* contact) | |
679 { | |
680 return contact ? contact->alias : NULL; | |
681 } | |
682 | |
668 GaimGroup *gaim_group_new(const char *name) | 683 GaimGroup *gaim_group_new(const char *name) |
669 { | 684 { |
670 GaimGroup *g = gaim_find_group(name); | 685 GaimGroup *g = gaim_find_group(name); |
671 | 686 |
672 if (!g) { | 687 if (!g) { |
892 node->prev->next = node->next; | 907 node->prev->next = node->next; |
893 if (node->next) | 908 if (node->next) |
894 node->next->prev = node->prev; | 909 node->next->prev = node->prev; |
895 if(cnode->child == node) { | 910 if(cnode->child == node) { |
896 cnode->child = node->next; | 911 cnode->child = node->next; |
897 if(!cnode->child) | 912 } |
898 gaim_blist_remove_contact((GaimContact*)cnode); | 913 |
899 } | |
900 | 914 |
901 hb.name = normalize(buddy->name); | 915 hb.name = normalize(buddy->name); |
902 hb.account = buddy->account; | 916 hb.account = buddy->account; |
903 hb.group = ((GaimBlistNode*)buddy)->parent->parent; | 917 hb.group = ((GaimBlistNode*)buddy)->parent->parent; |
904 g_hash_table_remove(gaimbuddylist->buddies, &hb); | 918 g_hash_table_remove(gaimbuddylist->buddies, &hb); |
909 ops->remove(gaimbuddylist, node); | 923 ops->remove(gaimbuddylist, node); |
910 g_hash_table_destroy(buddy->settings); | 924 g_hash_table_destroy(buddy->settings); |
911 g_free(buddy->name); | 925 g_free(buddy->name); |
912 g_free(buddy->alias); | 926 g_free(buddy->alias); |
913 g_free(buddy); | 927 g_free(buddy); |
928 | |
929 if(!cnode->child) | |
930 gaim_blist_remove_contact((GaimContact*)cnode); | |
914 } | 931 } |
915 | 932 |
916 void gaim_blist_remove_chat (GaimBlistChat *chat) | 933 void gaim_blist_remove_chat (GaimBlistChat *chat) |
917 { | 934 { |
918 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; | 935 struct gaim_blist_ui_ops *ops = gaimbuddylist->ui_ops; |
1027 return NULL; | 1044 return NULL; |
1028 } | 1045 } |
1029 | 1046 |
1030 const char * gaim_get_buddy_alias (GaimBuddy *buddy) | 1047 const char * gaim_get_buddy_alias (GaimBuddy *buddy) |
1031 { | 1048 { |
1032 const char *ret = gaim_get_buddy_alias_only(buddy); | 1049 GaimContact *contact; |
1033 | 1050 const char *ret; |
1034 if(!ret) | 1051 |
1035 return buddy ? buddy->name : _("Unknown"); | 1052 if(!buddy) |
1036 | 1053 return _("Unknown"); |
1037 return ret; | 1054 |
1055 contact = (GaimContact*)((GaimBlistNode*)buddy)->parent; | |
1056 | |
1057 if(contact && contact->alias) | |
1058 return contact->alias; | |
1059 | |
1060 ret= gaim_get_buddy_alias_only(buddy); | |
1061 | |
1062 return ret ? ret : buddy->name; | |
1038 } | 1063 } |
1039 | 1064 |
1040 const char *gaim_blist_chat_get_name(GaimBlistChat *chat) | 1065 const char *gaim_blist_chat_get_name(GaimBlistChat *chat) |
1041 { | 1066 { |
1042 if(chat->alias && *chat->alias) { | 1067 if(chat->alias && *chat->alias) { |
1756 blist_parser_group = gaim_group_new(blist_parser_group_name); | 1781 blist_parser_group = gaim_group_new(blist_parser_group_name); |
1757 gaim_blist_add_group(blist_parser_group, | 1782 gaim_blist_add_group(blist_parser_group, |
1758 gaim_blist_get_last_sibling(gaimbuddylist->root)); | 1783 gaim_blist_get_last_sibling(gaimbuddylist->root)); |
1759 } | 1784 } |
1760 } else if(!strcmp(element_name, "contact")) { | 1785 } else if(!strcmp(element_name, "contact")) { |
1786 char *alias = NULL; | |
1761 tag_stack = g_list_prepend(tag_stack, | 1787 tag_stack = g_list_prepend(tag_stack, |
1762 GINT_TO_POINTER(BLIST_TAG_CONTACT)); | 1788 GINT_TO_POINTER(BLIST_TAG_CONTACT)); |
1789 | |
1790 for(i=0; attribute_names[i]; i++) { | |
1791 if(!strcmp(attribute_names[i], "alias")) { | |
1792 g_free(alias); | |
1793 alias = g_strdup(attribute_values[i]); | |
1794 } | |
1795 } | |
1763 | 1796 |
1764 blist_parser_contact = gaim_contact_new(); | 1797 blist_parser_contact = gaim_contact_new(); |
1765 gaim_blist_add_contact(blist_parser_contact, blist_parser_group, | 1798 gaim_blist_add_contact(blist_parser_contact, blist_parser_group, |
1766 gaim_blist_get_last_sibling(((GaimBlistNode*)blist_parser_group)->child)); | 1799 gaim_blist_get_last_sibling(((GaimBlistNode*)blist_parser_group)->child)); |
1800 | |
1801 if(alias) { | |
1802 gaim_contact_set_alias(blist_parser_contact, alias); | |
1803 g_free(alias); | |
1804 } | |
1767 } else if(!strcmp(element_name, "chat")) { | 1805 } else if(!strcmp(element_name, "chat")) { |
1768 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_CHAT)); | 1806 tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_CHAT)); |
1769 for(i=0; attribute_names[i]; i++) { | 1807 for(i=0; attribute_names[i]; i++) { |
1770 if(!strcmp(attribute_names[i], "account")) { | 1808 if(!strcmp(attribute_names[i], "account")) { |
1771 g_free(blist_parser_account_name); | 1809 g_free(blist_parser_account_name); |
2208 char *group_name = g_markup_escape_text(group->name, -1); | 2246 char *group_name = g_markup_escape_text(group->name, -1); |
2209 fprintf(file, "\t\t<group name=\"%s\">\n", group_name); | 2247 fprintf(file, "\t\t<group name=\"%s\">\n", group_name); |
2210 g_hash_table_foreach(group->settings, blist_print_group_settings, file); | 2248 g_hash_table_foreach(group->settings, blist_print_group_settings, file); |
2211 for(cnode = gnode->child; cnode; cnode = cnode->next) { | 2249 for(cnode = gnode->child; cnode; cnode = cnode->next) { |
2212 if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { | 2250 if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { |
2213 fprintf(file, "\t\t\t<contact>\n"); | 2251 GaimContact *contact = (GaimContact*)cnode; |
2252 fprintf(file, "\t\t\t<contact"); | |
2253 if(contact->alias) { | |
2254 char *alias = g_markup_escape_text(contact->alias, -1); | |
2255 fprintf(file, " alias=\"%s\"", alias); | |
2256 g_free(alias); | |
2257 } | |
2258 fprintf(file, ">\n"); | |
2214 | 2259 |
2215 for(bnode = cnode->child; bnode; bnode = bnode->next) { | 2260 for(bnode = cnode->child; bnode; bnode = bnode->next) { |
2216 if(GAIM_BLIST_NODE_IS_BUDDY(bnode)) { | 2261 if(GAIM_BLIST_NODE_IS_BUDDY(bnode)) { |
2217 GaimBuddy *buddy = (GaimBuddy *)bnode; | 2262 GaimBuddy *buddy = (GaimBuddy *)bnode; |
2218 if(!exp_acct || buddy->account == exp_acct) { | 2263 if(!exp_acct || buddy->account == exp_acct) { |