Mercurial > pidgin.yaz
changeset 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 | 47e49e3c00f4 |
children | cdb4acfe777f |
files | src/blist.c src/blist.h |
diffstat | 2 files changed, 73 insertions(+), 11 deletions(-) [+] |
line wrap: on
line diff
--- a/src/blist.c Fri Sep 05 16:53:18 2003 +0000 +++ b/src/blist.c Fri Sep 05 17:04:39 2003 +0000 @@ -665,6 +665,21 @@ return c; } +void gaim_contact_set_alias(GaimContact* contact, const char *alias) +{ + g_return_if_fail(contact != NULL); + + if(contact->alias) + g_free(contact->alias); + + contact->alias = g_strdup(alias); +} + +const char *gaim_contact_get_alias(GaimContact* contact) +{ + return contact ? contact->alias : NULL; +} + GaimGroup *gaim_group_new(const char *name) { GaimGroup *g = gaim_find_group(name); @@ -894,10 +909,9 @@ node->next->prev = node->prev; if(cnode->child == node) { cnode->child = node->next; - if(!cnode->child) - gaim_blist_remove_contact((GaimContact*)cnode); } + hb.name = normalize(buddy->name); hb.account = buddy->account; hb.group = ((GaimBlistNode*)buddy)->parent->parent; @@ -911,6 +925,9 @@ g_free(buddy->name); g_free(buddy->alias); g_free(buddy); + + if(!cnode->child) + gaim_blist_remove_contact((GaimContact*)cnode); } void gaim_blist_remove_chat (GaimBlistChat *chat) @@ -1029,12 +1046,20 @@ const char * gaim_get_buddy_alias (GaimBuddy *buddy) { - const char *ret = gaim_get_buddy_alias_only(buddy); + GaimContact *contact; + const char *ret; + + if(!buddy) + return _("Unknown"); - if(!ret) - return buddy ? buddy->name : _("Unknown"); + contact = (GaimContact*)((GaimBlistNode*)buddy)->parent; - return ret; + if(contact && contact->alias) + return contact->alias; + + ret= gaim_get_buddy_alias_only(buddy); + + return ret ? ret : buddy->name; } const char *gaim_blist_chat_get_name(GaimBlistChat *chat) @@ -1758,12 +1783,25 @@ gaim_blist_get_last_sibling(gaimbuddylist->root)); } } else if(!strcmp(element_name, "contact")) { + char *alias = NULL; tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_CONTACT)); + for(i=0; attribute_names[i]; i++) { + if(!strcmp(attribute_names[i], "alias")) { + g_free(alias); + alias = g_strdup(attribute_values[i]); + } + } + blist_parser_contact = gaim_contact_new(); gaim_blist_add_contact(blist_parser_contact, blist_parser_group, gaim_blist_get_last_sibling(((GaimBlistNode*)blist_parser_group)->child)); + + if(alias) { + gaim_contact_set_alias(blist_parser_contact, alias); + g_free(alias); + } } else if(!strcmp(element_name, "chat")) { tag_stack = g_list_prepend(tag_stack, GINT_TO_POINTER(BLIST_TAG_CHAT)); for(i=0; attribute_names[i]; i++) { @@ -2210,7 +2248,14 @@ g_hash_table_foreach(group->settings, blist_print_group_settings, file); for(cnode = gnode->child; cnode; cnode = cnode->next) { if(GAIM_BLIST_NODE_IS_CONTACT(cnode)) { - fprintf(file, "\t\t\t<contact>\n"); + GaimContact *contact = (GaimContact*)cnode; + fprintf(file, "\t\t\t<contact"); + if(contact->alias) { + char *alias = g_markup_escape_text(contact->alias, -1); + fprintf(file, " alias=\"%s\"", alias); + g_free(alias); + } + fprintf(file, ">\n"); for(bnode = cnode->child; bnode; bnode = bnode->next) { if(GAIM_BLIST_NODE_IS_BUDDY(bnode)) {
--- a/src/blist.h Fri Sep 05 16:53:18 2003 +0000 +++ b/src/blist.h Fri Sep 05 17:04:39 2003 +0000 @@ -105,10 +105,11 @@ * A contact. This contains everything Gaim will ever need to know about a contact. */ struct _GaimContact { - GaimBlistNode node; /**< The node that this contact inherits from. */ - int totalsize; /**< The number of buddies in this contact */ - int currentsize; /**< The number of buddies in this contact corresponding to online accounts */ - int online; /**< The number of buddies in this contact who are currently online */ + GaimBlistNode node; /**< The node that this contact inherits from. */ + char *alias; /**< The user-set alias of the contact */ + int totalsize; /**< The number of buddies in this contact */ + int currentsize; /**< The number of buddies in this contact corresponding to online accounts */ + int online; /**< The number of buddies in this contact who are currently online */ }; @@ -408,6 +409,22 @@ GaimBuddy *gaim_contact_get_priority_buddy(GaimContact *contact); /** + * Sets the alias for a contact. + * + * @param contact The contact + * @param alias The alias to set, or NULL to unset + */ +void gaim_contact_set_alias(GaimContact *contact, const char *alias); + +/** + * Gets the alias for a contact. + * + * @param contact The contact + * @return The alias, or NULL if it is not set. + */ +const char *gaim_contact_get_alias(GaimContact *contact); + +/** * Removes a buddy from the buddy list and frees the memory allocated to it. * * @param buddy The buddy to be removed