* Purple is the legal property of its developers, whose names are too numerous * to list here. Please refer to the COPYRIGHT file distributed with this * This program is free software; you can redistribute it and/or modify * it under the terms of the GNU General Public License as published by * the Free Software Foundation; either version 2 of the License, or * (at your option) any later version. * This program is distributed in the hope that it will be useful, * but WITHOUT ANY WARRANTY; without even the implied warranty of * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the * GNU General Public License for more details. * You should have received a copy of the GNU General Public License * along with this program; if not, write to the Free Software * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02111-1301 USA #include "conversation.h" /* Private data for a buddy list. */ GHashTable *buddies; /* Every buddy in this list */ } PurpleBuddyListPrivate; static GType buddy_list_type = G_TYPE_INVALID; static PurpleBuddyList *purplebuddylist = NULL; G_DEFINE_TYPE_WITH_PRIVATE(PurpleBuddyList, purple_buddy_list, G_TYPE_OBJECT); * A hash table used for efficient lookups of buddies by name. * PurpleAccount* => GHashTable*, with the inner hash table being * struct _purple_hbuddy => PurpleBuddy* static GHashTable *buddies_cache = NULL; * A hash table used for efficient lookups of groups by name. * UTF-8 collate-key => PurpleGroup*. static GHashTable *groups_cache = NULL; static guint save_timer = 0; static gboolean blist_loaded = FALSE; static gchar *localized_default_group_name = NULL; /********************************************************************* * Private utility functions * *********************************************************************/ purple_blist_fold_name(const gchar *name) tmp = g_utf8_casefold(name, -1); res = g_utf8_collate_key(tmp, -1); static PurpleBlistNode *purple_blist_get_last_sibling(PurpleBlistNode *node) PurpleBlistNode *n = node; PurpleBlistNode *_purple_blist_get_last_child(PurpleBlistNode *node) return purple_blist_get_last_sibling(node->child); struct _list_account_buddies { /* This function must not use purple_normalize */ static guint _purple_blist_hbuddy_hash(struct _purple_hbuddy *hb) return g_str_hash(hb->name) ^ g_direct_hash(hb->group) ^ g_direct_hash(hb->account); /* This function must not use purple_normalize */ static guint _purple_blist_hbuddy_equal(struct _purple_hbuddy *hb1, struct _purple_hbuddy *hb2) return (hb1->group == hb2->group && hb1->account == hb2->account && purple_strequal(hb1->name, hb2->name)); static void _purple_blist_hbuddy_free_key(struct _purple_hbuddy *hb) purple_blist_buddies_cache_add_account(PurpleAccount *account) GHashTable *account_buddies = g_hash_table_new_full((GHashFunc)_purple_blist_hbuddy_hash, (GEqualFunc)_purple_blist_hbuddy_equal, (GDestroyNotify)_purple_blist_hbuddy_free_key, NULL); g_hash_table_insert(buddies_cache, account, account_buddies); purple_blist_buddies_cache_remove_account(const PurpleAccount *account) g_hash_table_remove(buddies_cache, account); /********************************************************************* *********************************************************************/ value_to_xmlnode(gpointer key, gpointer hvalue, gpointer user_data) PurpleXmlNode *node, *child; name = (const char *)key; value = (GValue *)hvalue; node = (PurpleXmlNode *)user_data; g_return_if_fail(value != NULL); child = purple_xmlnode_new_child(node, "setting"); purple_xmlnode_set_attrib(child, "name", name); if (G_VALUE_HOLDS_INT(value)) { purple_xmlnode_set_attrib(child, "type", "int"); g_snprintf(buf, sizeof(buf), "%d", g_value_get_int(value)); purple_xmlnode_insert_data(child, buf, -1); else if (G_VALUE_HOLDS_STRING(value)) { purple_xmlnode_set_attrib(child, "type", "string"); purple_xmlnode_insert_data(child, g_value_get_string(value), -1); else if (G_VALUE_HOLDS_BOOLEAN(value)) { purple_xmlnode_set_attrib(child, "type", "bool"); g_snprintf(buf, sizeof(buf), "%d", g_value_get_boolean(value)); purple_xmlnode_insert_data(child, buf, -1); chat_component_to_xmlnode(gpointer key, gpointer value, gpointer user_data) PurpleXmlNode *node, *child; name = (const char *)key; data = (const char *)value; node = (PurpleXmlNode *)user_data; g_return_if_fail(data != NULL); child = purple_xmlnode_new_child(node, "component"); purple_xmlnode_set_attrib(child, "name", name); purple_xmlnode_insert_data(child, data, -1); buddy_to_xmlnode(PurpleBuddy *buddy) PurpleXmlNode *node, *child; PurpleAccount *account = purple_buddy_get_account(buddy); const char *alias = purple_buddy_get_local_alias(buddy); node = purple_xmlnode_new("buddy"); purple_xmlnode_set_attrib(node, "account", purple_account_get_username(account)); purple_xmlnode_set_attrib(node, "proto", purple_account_get_protocol_id(account)); child = purple_xmlnode_new_child(node, "name"); purple_xmlnode_insert_data(child, purple_buddy_get_name(buddy), -1); child = purple_xmlnode_new_child(node, "alias"); purple_xmlnode_insert_data(child, alias, -1); /* Write buddy settings */ g_hash_table_foreach(purple_blist_node_get_settings(PURPLE_BLIST_NODE(buddy)), contact_to_xmlnode(PurpleContact *contact) PurpleXmlNode *node, *child; node = purple_xmlnode_new("contact"); g_object_get(contact, "alias", &alias, NULL); purple_xmlnode_set_attrib(node, "alias", alias); for (bnode = PURPLE_BLIST_NODE(contact)->child; bnode != NULL; bnode = bnode->next) if (purple_blist_node_is_transient(bnode)) if (PURPLE_IS_BUDDY(bnode)) child = buddy_to_xmlnode(PURPLE_BUDDY(bnode)); purple_xmlnode_insert_child(node, child); /* Write contact settings */ g_hash_table_foreach(purple_blist_node_get_settings(PURPLE_BLIST_NODE(contact)), chat_to_xmlnode(PurpleChat *chat) PurpleXmlNode *node, *child; PurpleAccount *account = purple_chat_get_account(chat); g_object_get(chat, "alias", &alias, NULL); node = purple_xmlnode_new("chat"); purple_xmlnode_set_attrib(node, "proto", purple_account_get_protocol_id(account)); purple_xmlnode_set_attrib(node, "account", purple_account_get_username(account)); child = purple_xmlnode_new_child(node, "alias"); purple_xmlnode_insert_data(child, alias, -1); /* Write chat components */ g_hash_table_foreach(purple_chat_get_components(chat), chat_component_to_xmlnode, node); /* Write chat settings */ g_hash_table_foreach(purple_blist_node_get_settings(PURPLE_BLIST_NODE(chat)), group_to_xmlnode(PurpleGroup *group) PurpleXmlNode *node, *child; node = purple_xmlnode_new("group"); if (group != purple_blist_get_default_group()) purple_xmlnode_set_attrib(node, "name", purple_group_get_name(group)); g_hash_table_foreach(purple_blist_node_get_settings(PURPLE_BLIST_NODE(group)), /* Write contacts and chats */ for (cnode = PURPLE_BLIST_NODE(group)->child; cnode != NULL; cnode = cnode->next) if (purple_blist_node_is_transient(cnode)) if (PURPLE_IS_CONTACT(cnode)) child = contact_to_xmlnode(PURPLE_CONTACT(cnode)); purple_xmlnode_insert_child(node, child); else if (PURPLE_IS_CHAT(cnode)) child = chat_to_xmlnode(PURPLE_CHAT(cnode)); purple_xmlnode_insert_child(node, child); accountprivacy_to_xmlnode(PurpleAccount *account) PurpleXmlNode *node, *child; node = purple_xmlnode_new("account"); purple_xmlnode_set_attrib(node, "proto", purple_account_get_protocol_id(account)); purple_xmlnode_set_attrib(node, "name", purple_account_get_username(account)); g_snprintf(buf, sizeof(buf), "%d", purple_account_get_privacy_type(account)); purple_xmlnode_set_attrib(node, "mode", buf); for (cur = purple_account_privacy_get_permitted(account); cur; cur = cur->next) child = purple_xmlnode_new_child(node, "permit"); purple_xmlnode_insert_data(child, cur->data, -1); for (cur = purple_account_privacy_get_denied(account); cur; cur = cur->next) child = purple_xmlnode_new_child(node, "block"); purple_xmlnode_insert_data(child, cur->data, -1); PurpleXmlNode *node, *child, *grandchild; const gchar *localized_default; node = purple_xmlnode_new("purple"); purple_xmlnode_set_attrib(node, "version", "1.0"); child = purple_xmlnode_new_child(node, "blist"); localized_default = localized_default_group_name; if (!purple_strequal(_("Buddies"), "Buddies")) localized_default = _("Buddies"); if (localized_default != NULL) { purple_xmlnode_set_attrib(child, "localized-default-group", localized_default); for (gnode = purple_blist_get_default_root(); gnode != NULL; if (purple_blist_node_is_transient(gnode)) if (PURPLE_IS_GROUP(gnode)) grandchild = group_to_xmlnode(PURPLE_GROUP(gnode)); purple_xmlnode_insert_child(child, grandchild); /* Write privacy settings */ child = purple_xmlnode_new_child(node, "privacy"); for (cur = purple_accounts_get_all(); cur != NULL; cur = cur->next) grandchild = accountprivacy_to_xmlnode(cur->data); purple_xmlnode_insert_child(child, grandchild); purple_debug_error("buddylist", "Attempted to save buddy list before it " node = blist_to_xmlnode(); data = purple_xmlnode_to_formatted_str(node, NULL); purple_util_write_data_to_config_file("blist.xml", data, -1); purple_xmlnode_free(node); purple_blist_real_schedule_save(void) save_timer = g_timeout_add_seconds(5, save_cb, NULL); purple_blist_real_save_account(PurpleBuddyList *list, PurpleAccount *account) purple_blist_real_schedule_save(); /* Save the buddies and privacy data for this account */ /* Save all buddies and privacy data */ purple_blist_real_save_node(PurpleBuddyList *list, PurpleBlistNode *node) purple_blist_real_schedule_save(); void purple_blist_schedule_save() PurpleBuddyListClass *klass = NULL; g_return_if_fail(PURPLE_IS_BUDDY_LIST(purplebuddylist)); klass = PURPLE_BUDDY_LIST_GET_CLASS(purplebuddylist); if (klass && klass->save_account) { klass->save_account(purplebuddylist, NULL); /********************************************************************* *********************************************************************/ parse_setting(PurpleBlistNode *node, PurpleXmlNode *setting) const char *name = purple_xmlnode_get_attrib(setting, "name"); const char *type = purple_xmlnode_get_attrib(setting, "type"); char *value = purple_xmlnode_get_data(setting); if (!type || purple_strequal(type, "string")) purple_blist_node_set_string(node, name, value); else if (purple_strequal(type, "bool")) purple_blist_node_set_bool(node, name, atoi(value)); else if (purple_strequal(type, "int")) purple_blist_node_set_int(node, name, atoi(value)); parse_buddy(PurpleGroup *group, PurpleContact *contact, PurpleXmlNode *bnode) char *name = NULL, *alias = NULL; const char *acct_name, *proto; acct_name = purple_xmlnode_get_attrib(bnode, "account"); proto = purple_xmlnode_get_attrib(bnode, "proto"); if (!acct_name || !proto) account = purple_accounts_find(acct_name, proto); if ((x = purple_xmlnode_get_child(bnode, "name"))) name = purple_xmlnode_get_data(x); if ((x = purple_xmlnode_get_child(bnode, "alias"))) alias = purple_xmlnode_get_data(x); buddy = purple_buddy_new(account, name, alias); purple_blist_add_buddy(buddy, contact, group, _purple_blist_get_last_child((PurpleBlistNode*)contact)); for (x = purple_xmlnode_get_child(bnode, "setting"); x; x = purple_xmlnode_get_next_twin(x)) { parse_setting((PurpleBlistNode*)buddy, x); parse_contact(PurpleGroup *group, PurpleXmlNode *cnode) PurpleContact *contact = purple_contact_new(); purple_blist_add_contact(contact, group, _purple_blist_get_last_child((PurpleBlistNode*)group)); if ((alias = purple_xmlnode_get_attrib(cnode, "alias"))) { purple_contact_set_alias(contact, alias); for (x = cnode->child; x; x = x->next) { if (x->type != PURPLE_XMLNODE_TYPE_TAG) if (purple_strequal(x->name, "buddy")) parse_buddy(group, contact, x); else if (purple_strequal(x->name, "setting")) parse_setting(PURPLE_BLIST_NODE(contact), x); /* if the contact is empty, don't keep it around. it causes problems */ if (!PURPLE_BLIST_NODE(contact)->child) purple_blist_remove_contact(contact); parse_chat(PurpleGroup *group, PurpleXmlNode *cnode) const char *acct_name, *proto; acct_name = purple_xmlnode_get_attrib(cnode, "account"); proto = purple_xmlnode_get_attrib(cnode, "proto"); if (!acct_name || !proto) account = purple_accounts_find(acct_name, proto); if ((x = purple_xmlnode_get_child(cnode, "alias"))) alias = purple_xmlnode_get_data(x); components = g_hash_table_new_full(g_str_hash, g_str_equal, g_free, g_free); for (x = purple_xmlnode_get_child(cnode, "component"); x; x = purple_xmlnode_get_next_twin(x)) { name = purple_xmlnode_get_attrib(x, "name"); value = purple_xmlnode_get_data(x); g_hash_table_replace(components, g_strdup(name), value); chat = purple_chat_new(account, alias, components); purple_blist_add_chat(chat, group, _purple_blist_get_last_child((PurpleBlistNode*)group)); for (x = purple_xmlnode_get_child(cnode, "setting"); x; x = purple_xmlnode_get_next_twin(x)) { parse_setting((PurpleBlistNode*)chat, x); parse_group(PurpleXmlNode *groupnode) const char *name = purple_xmlnode_get_attrib(groupnode, "name"); group = purple_group_new(name); purple_blist_add_group(group, purple_blist_get_last_sibling( purple_blist_get_default_root())); for (cnode = groupnode->child; cnode; cnode = cnode->next) { if (cnode->type != PURPLE_XMLNODE_TYPE_TAG) if (purple_strequal(cnode->name, "setting")) parse_setting((PurpleBlistNode*)group, cnode); else if (purple_strequal(cnode->name, "contact") || purple_strequal(cnode->name, "person")) parse_contact(group, cnode); else if (purple_strequal(cnode->name, "chat")) parse_chat(group, cnode); PurpleXmlNode *purple, *blist, *privacy; purple = purple_util_read_xml_from_config_file("blist.xml", _("buddy list")); blist = purple_xmlnode_get_child(purple, "blist"); PurpleXmlNode *groupnode; localized_default_group_name = g_strdup( purple_xmlnode_get_attrib(blist, "localized-default-group")); for (groupnode = purple_xmlnode_get_child(blist, "group"); groupnode != NULL; groupnode = purple_xmlnode_get_next_twin(groupnode)) { g_free(localized_default_group_name); localized_default_group_name = NULL; privacy = purple_xmlnode_get_child(purple, "privacy"); for (anode = privacy->child; anode; anode = anode->next) { const char *acct_name, *proto, *mode; acct_name = purple_xmlnode_get_attrib(anode, "name"); proto = purple_xmlnode_get_attrib(anode, "proto"); mode = purple_xmlnode_get_attrib(anode, "mode"); if (!acct_name || !proto || !mode) account = purple_accounts_find(acct_name, proto); purple_account_set_privacy_type(account, (imode != 0 ? imode : PURPLE_ACCOUNT_PRIVACY_ALLOW_ALL)); for (x = anode->child; x; x = x->next) { if (x->type != PURPLE_XMLNODE_TYPE_TAG) if (purple_strequal(x->name, "permit")) { name = purple_xmlnode_get_data(x); purple_account_privacy_permit_add(account, name, TRUE); } else if (purple_strequal(x->name, "block")) { name = purple_xmlnode_get_data(x); purple_account_privacy_deny_add(account, name, TRUE); purple_xmlnode_free(purple); /* This tells the buddy icon code to do its thing. */ _purple_buddy_icons_blist_loaded_cb(); /***************************************************************************** *****************************************************************************/ purple_blist_set_ui(GType type) g_return_if_fail(g_type_is_a(type, PURPLE_TYPE_BUDDY_LIST) || PurpleBuddyList *gbl = g_object_new(buddy_list_type, NULL); buddies_cache = g_hash_table_new_full(g_direct_hash, g_direct_equal, NULL, (GDestroyNotify)g_hash_table_destroy); groups_cache = g_hash_table_new_full((GHashFunc)g_str_hash, (GDestroyNotify)g_free, NULL); for (account = purple_accounts_get_all(); account != NULL; account = account->next) purple_blist_buddies_cache_add_account(account->data); purple_blist_get_default(void) purple_blist_get_default_root(void) PurpleBuddyListPrivate *priv = purple_buddy_list_get_instance_private(purplebuddylist); purple_blist_get_root(PurpleBuddyList *list) PurpleBuddyListPrivate *priv = NULL; g_return_val_if_fail(PURPLE_IS_BUDDY_LIST(list), NULL); priv = purple_buddy_list_get_instance_private(list); append_buddy(gpointer key, gpointer value, gpointer user_data) GSList **list = user_data; *list = g_slist_prepend(*list, value); purple_blist_get_buddies() PurpleBuddyListPrivate *priv; priv = purple_buddy_list_get_instance_private(purplebuddylist); g_hash_table_foreach(priv->buddies, append_buddy, &buddies); PurpleBuddyListClass *klass = NULL; g_return_if_fail(PURPLE_IS_BUDDY_LIST(purplebuddylist)); klass = PURPLE_BUDDY_LIST_GET_CLASS(purplebuddylist); if (klass && klass->show) { klass->show(purplebuddylist); void purple_blist_set_visible(gboolean show) PurpleBuddyListClass *klass = NULL; g_return_if_fail(PURPLE_IS_BUDDY_LIST(purplebuddylist)); klass = PURPLE_BUDDY_LIST_GET_CLASS(purplebuddylist); if (klass && klass->set_visible) { klass->set_visible(purplebuddylist, show); void purple_blist_update_buddies_cache(PurpleBuddy *buddy, const char *new_name) struct _purple_hbuddy *hb, *hb2; GHashTable *account_buddies; PurpleBuddyListPrivate *priv = purple_buddy_list_get_instance_private(purplebuddylist); g_return_if_fail(PURPLE_IS_BUDDY(buddy)); account = purple_buddy_get_account(buddy); name = (gchar *)purple_buddy_get_name(buddy); hb = g_new(struct _purple_hbuddy, 1); hb->name = (gchar *)purple_normalize(account, name); hb->group = PURPLE_BLIST_NODE(buddy)->parent->parent; g_hash_table_remove(priv->buddies, hb); account_buddies = g_hash_table_lookup(buddies_cache, account); g_hash_table_remove(account_buddies, hb); hb->name = g_strdup(purple_normalize(account, new_name)); g_hash_table_replace(priv->buddies, hb, buddy); hb2 = g_new(struct _purple_hbuddy, 1); hb2->name = g_strdup(hb->name); hb2->group = PURPLE_BLIST_NODE(buddy)->parent->parent; g_hash_table_replace(account_buddies, hb2, buddy); void purple_blist_update_groups_cache(PurpleGroup *group, const char *new_name) key = purple_blist_fold_name(purple_group_get_name(group)); g_hash_table_remove(groups_cache, key); g_hash_table_insert(groups_cache, purple_blist_fold_name(new_name), group); void purple_blist_add_chat(PurpleChat *chat, PurpleGroup *group, PurpleBlistNode *node) PurpleBlistNode *cnode = PURPLE_BLIST_NODE(chat); PurpleBuddyListClass *klass = NULL; PurpleCountingNode *group_counter; g_return_if_fail(PURPLE_IS_CHAT(chat)); g_return_if_fail(PURPLE_IS_BUDDY_LIST(purplebuddylist)); klass = PURPLE_BUDDY_LIST_GET_CLASS(purplebuddylist); group = purple_group_new(_("Chats")); /* Add group to blist if isn't already on it. Fixes #2752. */ if (!purple_blist_find_group(purple_group_get_name(group))) { purple_blist_get_last_sibling( purple_blist_get_default_root())); group = PURPLE_GROUP(node->parent); /* if we're moving to overtop of ourselves, do nothing */ /* This chat was already in the list and is group_counter = PURPLE_COUNTING_NODE(cnode->parent); purple_counting_node_change_total_size(group_counter, -1); if (purple_account_is_connected(purple_chat_get_account(chat))) { purple_counting_node_change_online_count(group_counter, -1); purple_counting_node_change_current_size(group_counter, -1); cnode->next->prev = cnode->prev; cnode->prev->next = cnode->next; if (cnode->parent->child == cnode) cnode->parent->child = cnode->next; if (klass && klass->remove) { klass->remove(purplebuddylist, cnode); /* ops->remove() cleaned up the cnode's ui_data, so we need to if (klass && klass->new_node) { klass->new_node(purplebuddylist, cnode); node->next->prev = cnode; cnode->next = node->next; cnode->parent = node->parent; group_counter = PURPLE_COUNTING_NODE(node->parent); purple_counting_node_change_total_size(group_counter, +1); if (purple_account_is_connected(purple_chat_get_account(chat))) { purple_counting_node_change_online_count(group_counter, +1); purple_counting_node_change_current_size(group_counter, +1); if (((PurpleBlistNode *)group)->child) ((PurpleBlistNode *)group)->child->prev = cnode; cnode->next = ((PurpleBlistNode *)group)->child; ((PurpleBlistNode *)group)->child = cnode; cnode->parent = PURPLE_BLIST_NODE(group); group_counter = PURPLE_COUNTING_NODE(group); purple_counting_node_change_total_size(group_counter, +1); if (purple_account_is_connected(purple_chat_get_account(chat))) { purple_counting_node_change_online_count(group_counter, +1); purple_counting_node_change_current_size(group_counter, +1); klass->save_node(purplebuddylist, cnode); klass->update(purplebuddylist, PURPLE_BLIST_NODE(cnode)); purple_signal_emit(purple_blist_get_handle(), "blist-node-added", void purple_blist_add_buddy(PurpleBuddy *buddy, PurpleContact *contact, PurpleGroup *group, PurpleBlistNode *node) PurpleBuddyListClass *klass = NULL; PurpleBuddyListPrivate *priv = NULL; PurpleBlistNode *cnode, *bnode; PurpleCountingNode *contact_counter, *group_counter; struct _purple_hbuddy *hb, *hb2; GHashTable *account_buddies; g_return_if_fail(PURPLE_IS_BUDDY_LIST(purplebuddylist)); g_return_if_fail(PURPLE_IS_BUDDY(buddy)); klass = PURPLE_BUDDY_LIST_GET_CLASS(purplebuddylist); priv = purple_buddy_list_get_instance_private(purplebuddylist); bnode = PURPLE_BLIST_NODE(buddy); account = purple_buddy_get_account(buddy); /* if we're moving to overtop of ourselves, do nothing */ if (bnode == node || (!node && bnode->parent && contact && bnode->parent == (PurpleBlistNode*)contact && bnode == bnode->parent->child)) if (node && PURPLE_IS_BUDDY(node)) { c = (PurpleContact*)node->parent; g = (PurpleGroup*)node->parent->parent; g = PURPLE_GROUP(PURPLE_BLIST_NODE(c)->parent); g = purple_blist_get_default_group(); /* Add group to blist if isn't already on it. Fixes #2752. */ if (!purple_blist_find_group(purple_group_get_name(g))) { g, purple_blist_get_last_sibling(priv->root)); c = purple_contact_new(); purple_blist_add_contact(c, g, _purple_blist_get_last_child((PurpleBlistNode*)g)); cnode = PURPLE_BLIST_NODE(c); contact_counter = PURPLE_COUNTING_NODE(bnode->parent); group_counter = PURPLE_COUNTING_NODE(bnode->parent->parent); if (PURPLE_BUDDY_IS_ONLINE(buddy)) { purple_counting_node_change_online_count(contact_counter, -1); if (purple_counting_node_get_online_count(contact_counter) == 0) purple_counting_node_change_online_count(group_counter, -1); if (purple_account_is_connected(account)) { purple_counting_node_change_current_size(contact_counter, -1); if (purple_counting_node_get_current_size(contact_counter) == 0) purple_counting_node_change_current_size(group_counter, -1); purple_counting_node_change_total_size(contact_counter, -1); /* the group totalsize will be taken care of by remove_contact below */ if (bnode->parent->parent != (PurpleBlistNode*)g) { purple_signal_emit(purple_blist_get_handle(), "buddy-removed-from-group", buddy); purple_serv_move_buddy(buddy, (PurpleGroup *)bnode->parent->parent, g); bnode->next->prev = bnode->prev; bnode->prev->next = bnode->next; if (bnode->parent->child == bnode) bnode->parent->child = bnode->next; if (klass && klass->remove) { klass->remove(purplebuddylist, bnode); if (bnode->parent->parent != (PurpleBlistNode*)g) { struct _purple_hbuddy hb; hb.name = (gchar *)purple_normalize(account, purple_buddy_get_name(buddy)); hb.group = bnode->parent->parent; g_hash_table_remove(priv->buddies, &hb); account_buddies = g_hash_table_lookup(buddies_cache, account); g_hash_table_remove(account_buddies, &hb); if (!bnode->parent->child) { purple_blist_remove_contact((PurpleContact*)bnode->parent); purple_contact_invalidate_priority_buddy((PurpleContact*)bnode->parent); if (klass && klass->update) { klass->update(purplebuddylist, bnode->parent); if (node && PURPLE_IS_BUDDY(node)) { node->next->prev = bnode; bnode->next = node->next; bnode->parent = node->parent; cnode->child->prev = bnode; bnode->next = cnode->child; contact_counter = PURPLE_COUNTING_NODE(bnode->parent); group_counter = PURPLE_COUNTING_NODE(bnode->parent->parent); if (PURPLE_BUDDY_IS_ONLINE(buddy)) { purple_counting_node_change_online_count(contact_counter, +1); if (purple_counting_node_get_online_count(contact_counter) == 1) purple_counting_node_change_online_count(group_counter, +1); if (purple_account_is_connected(account)) { purple_counting_node_change_current_size(contact_counter, +1); if (purple_counting_node_get_current_size(contact_counter) == 1) purple_counting_node_change_current_size(group_counter, +1); purple_counting_node_change_total_size(contact_counter, +1); hb = g_new(struct _purple_hbuddy, 1); hb->name = g_strdup(purple_normalize(account, purple_buddy_get_name(buddy))); hb->group = PURPLE_BLIST_NODE(buddy)->parent->parent; g_hash_table_replace(priv->buddies, hb, buddy); account_buddies = g_hash_table_lookup(buddies_cache, account); hb2 = g_new(struct _purple_hbuddy, 1); hb2->name = g_strdup(hb->name); hb2->group = ((PurpleBlistNode*)buddy)->parent->parent; g_hash_table_replace(account_buddies, hb2, buddy); purple_contact_invalidate_priority_buddy(purple_buddy_get_contact(buddy)); klass->save_node(purplebuddylist, (PurpleBlistNode *)buddy); klass->update(purplebuddylist, PURPLE_BLIST_NODE(buddy)); /* Signal that the buddy has been added */ purple_signal_emit(purple_blist_get_handle(), "blist-node-added", PURPLE_BLIST_NODE(buddy)); void purple_blist_add_contact(PurpleContact *contact, PurpleGroup *group, PurpleBlistNode *node) PurpleBuddyListClass *klass = NULL; PurpleBuddyListPrivate *priv = NULL; PurpleBlistNode *gnode, *cnode, *bnode; PurpleCountingNode *contact_counter, *group_counter; g_return_if_fail(PURPLE_IS_CONTACT(contact)); g_return_if_fail(PURPLE_IS_BUDDY_LIST(purplebuddylist)); if (PURPLE_BLIST_NODE(contact) == node) klass = PURPLE_BUDDY_LIST_GET_CLASS(purplebuddylist); priv = purple_buddy_list_get_instance_private(purplebuddylist); if (node && (PURPLE_IS_CONTACT(node) || g = PURPLE_GROUP(node->parent); g = purple_blist_get_default_group(); gnode = (PurpleBlistNode*)g; cnode = (PurpleBlistNode*)contact; if (cnode->parent->child == cnode) cnode->parent->child = cnode->next; cnode->prev->next = cnode->next; cnode->next->prev = cnode->prev; if (cnode->parent != gnode) { PurpleBlistNode *next_bnode = bnode->next; PurpleBuddy *b = PURPLE_BUDDY(bnode); PurpleAccount *account = purple_buddy_get_account(b); GHashTable *account_buddies; struct _purple_hbuddy *hb, *hb2; hb = g_new(struct _purple_hbuddy, 1); hb->name = g_strdup(purple_normalize(account, purple_buddy_get_name(b))); hb->group = cnode->parent; g_hash_table_remove(priv->buddies, hb); account_buddies = g_hash_table_lookup(buddies_cache, account); g_hash_table_remove(account_buddies, hb); if (!purple_blist_find_buddy_in_group(account, purple_buddy_get_name(b), g)) { g_hash_table_replace(priv->buddies, hb, b); hb2 = g_new(struct _purple_hbuddy, 1); hb2->name = g_strdup(hb->name); g_hash_table_replace(account_buddies, hb2, b); if (purple_account_get_connection(account)) purple_serv_move_buddy(b, (PurpleGroup *)cnode->parent, g); gboolean empty_contact = FALSE; /* this buddy already exists in the group, so we're * gonna delete it instead */ if (purple_account_get_connection(account)) purple_account_remove_buddy(account, b, PURPLE_GROUP(cnode->parent)); purple_blist_remove_buddy(b); /* in purple_blist_remove_buddy(), if the last buddy in a * contact is removed, the contact is cleaned up and * g_free'd, so we mustn't try to reference bnode->next */ contact_counter = PURPLE_COUNTING_NODE(contact); group_counter = PURPLE_COUNTING_NODE(cnode->parent); if (purple_counting_node_get_online_count(contact_counter) > 0) purple_counting_node_change_online_count(group_counter, -1); if (purple_counting_node_get_current_size(contact_counter) > 0) purple_counting_node_change_current_size(group_counter, -1); purple_counting_node_change_total_size(group_counter, -1); if (klass && klass->remove) { klass->remove(purplebuddylist, cnode); if (klass && klass->remove_node) { klass->remove_node(purplebuddylist, cnode); if (node && (PURPLE_IS_CONTACT(node) || node->next->prev = cnode; cnode->next = node->next; cnode->parent = node->parent; gnode->child->prev = cnode; cnode->next = gnode->child; contact_counter = PURPLE_COUNTING_NODE(contact); group_counter = PURPLE_COUNTING_NODE(g); if (purple_counting_node_get_online_count(contact_counter) > 0) purple_counting_node_change_online_count(group_counter, +1); if (purple_counting_node_get_current_size(contact_counter) > 0) purple_counting_node_change_current_size(group_counter, +1); purple_counting_node_change_total_size(group_counter, +1); if (klass && klass->save_node) { klass->save_node(purplebuddylist, cnode); for (bnode = cnode->child; bnode; bnode = bnode->next) { klass->save_node(purplebuddylist, bnode); if (klass && klass->update) { klass->update(purplebuddylist, cnode); for (bnode = cnode->child; bnode; bnode = bnode->next) { klass->update(purplebuddylist, bnode); void purple_blist_add_group(PurpleGroup *group, PurpleBlistNode *node) PurpleBuddyListClass *klass = NULL; PurpleBuddyListPrivate *priv = NULL; PurpleBlistNode *gnode = (PurpleBlistNode*)group; g_return_if_fail(PURPLE_IS_BUDDY_LIST(purplebuddylist)); g_return_if_fail(PURPLE_IS_GROUP(group)); klass = PURPLE_BUDDY_LIST_GET_CLASS(purplebuddylist); priv = purple_buddy_list_get_instance_private(purplebuddylist); /* if we're moving to overtop of ourselves, do nothing */ if (purple_blist_find_group(purple_group_get_name(group))) { /* This is just being moved */ if (klass && klass->remove) { klass->remove(purplebuddylist, (PurpleBlistNode *)group); if (gnode == priv->root) { priv->root = gnode->next; gnode->prev->next = gnode->next; gnode->next->prev = gnode->prev; key = purple_blist_fold_name(purple_group_get_name(group)); g_hash_table_insert(groups_cache, key, group); if (node && PURPLE_IS_GROUP(node)) { gnode->next = node->next; node->next->prev = gnode; priv->root->prev = gnode; gnode->next = priv->root; if (klass && klass->save_node) { klass->save_node(purplebuddylist, gnode); for (node = gnode->child; node; node = node->next) { klass->save_node(purplebuddylist, node); if (klass && klass->update) { klass->update(purplebuddylist, gnode); for (node = gnode->child; node; node = node->next) { klass->update(purplebuddylist, node); purple_signal_emit(purple_blist_get_handle(), "blist-node-added", void purple_blist_remove_contact(PurpleContact *contact) PurpleBuddyListClass *klass = NULL; PurpleBlistNode *node, *gnode; g_return_if_fail(PURPLE_IS_BUDDY_LIST(purplebuddylist)); g_return_if_fail(PURPLE_IS_CONTACT(contact)); klass = PURPLE_BUDDY_LIST_GET_CLASS(purplebuddylist); node = (PurpleBlistNode *)contact; group = PURPLE_GROUP(gnode); * If this contact has children then remove them. When the last * buddy is removed from the contact, the contact is automatically while (node->child->next) { purple_blist_remove_buddy((PurpleBuddy*)node->child); * Remove the last buddy and trigger the deletion of the contact. * It would probably be cleaner if contact-deletion was done after * a timeout? Or if it had to be done manually, like below? purple_blist_remove_buddy((PurpleBuddy*)node->child); /* Remove the node from its parent */ if (gnode->child == node) gnode->child = node->next; node->prev->next = node->next; node->next->prev = node->prev; purple_counting_node_change_total_size(PURPLE_COUNTING_NODE(group), -1); if (klass && klass->remove) { klass->remove(purplebuddylist, node); if (klass && klass->remove_node) { klass->remove_node(purplebuddylist, node); purple_signal_emit(purple_blist_get_handle(), "blist-node-removed", PURPLE_BLIST_NODE(contact)); void purple_blist_remove_buddy(PurpleBuddy *buddy) PurpleBuddyListClass *klass = NULL; PurpleBuddyListPrivate *priv = NULL; PurpleBlistNode *node, *cnode, *gnode; PurpleCountingNode *contact_counter, *group_counter; struct _purple_hbuddy hb; GHashTable *account_buddies; g_return_if_fail(PURPLE_IS_BUDDY_LIST(purplebuddylist)); g_return_if_fail(PURPLE_IS_BUDDY(buddy)); klass = PURPLE_BUDDY_LIST_GET_CLASS(purplebuddylist); priv = purple_buddy_list_get_instance_private(purplebuddylist); account = purple_buddy_get_account(buddy); node = PURPLE_BLIST_NODE(buddy); gnode = (cnode != NULL) ? cnode->parent : NULL; contact = (PurpleContact *)cnode; group = (PurpleGroup *)gnode; /* Remove the node from its parent */ node->prev->next = node->next; node->next->prev = node->prev; if ((cnode != NULL) && (cnode->child == node)) cnode->child = node->next; contact_counter = PURPLE_COUNTING_NODE(contact); group_counter = PURPLE_COUNTING_NODE(group); if (PURPLE_BUDDY_IS_ONLINE(buddy)) { purple_counting_node_change_online_count(contact_counter, -1); if (purple_counting_node_get_online_count(contact_counter) == 0) purple_counting_node_change_online_count(group_counter, -1); if (purple_account_is_connected(account)) { purple_counting_node_change_current_size(contact_counter, -1); if (purple_counting_node_get_current_size(contact_counter) == 0) purple_counting_node_change_current_size(group_counter, -1); purple_counting_node_change_total_size(contact_counter, -1); /* Re-sort the contact */ if (cnode->child && purple_contact_get_priority_buddy(contact) == buddy) { purple_contact_invalidate_priority_buddy(contact); if (klass && klass->update) { klass->update(purplebuddylist, cnode); /* Remove this buddy from the buddies hash table */ hb.name = (gchar *)purple_normalize(account, purple_buddy_get_name(buddy)); g_hash_table_remove(priv->buddies, &hb); account_buddies = g_hash_table_lookup(buddies_cache, account); g_hash_table_remove(account_buddies, &hb); if (klass && klass->remove) { klass->remove(purplebuddylist, node); if (klass && klass->remove_node) { klass->remove_node(purplebuddylist, node); /* Remove this buddy's pounces */ purple_pounce_destroy_all_by_buddy(buddy); /* Signal that the buddy has been removed before freeing the memory for it */ purple_signal_emit(purple_blist_get_handle(), "blist-node-removed", PURPLE_BLIST_NODE(buddy)); /* If the contact is empty then remove it */ if ((contact != NULL) && !cnode->child) purple_blist_remove_contact(contact); void purple_blist_remove_chat(PurpleChat *chat) PurpleBuddyListClass *klass = NULL; PurpleBlistNode *node, *gnode; PurpleCountingNode *group_counter; g_return_if_fail(PURPLE_IS_BUDDY_LIST(purplebuddylist)); g_return_if_fail(PURPLE_IS_CHAT(chat)); klass = PURPLE_BUDDY_LIST_GET_CLASS(purplebuddylist); node = (PurpleBlistNode *)chat; group = (PurpleGroup *)gnode; /* Remove the node from its parent */ if (gnode->child == node) gnode->child = node->next; node->prev->next = node->next; node->next->prev = node->prev; group_counter = PURPLE_COUNTING_NODE(group); if (purple_account_is_connected(purple_chat_get_account(chat))) { purple_counting_node_change_online_count(group_counter, -1); purple_counting_node_change_current_size(group_counter, -1); purple_counting_node_change_total_size(group_counter, -1); if (klass && klass->remove) { klass->remove(purplebuddylist, node); if (klass && klass->remove_node) { klass->remove_node(purplebuddylist, node); purple_signal_emit(purple_blist_get_handle(), "blist-node-removed", PURPLE_BLIST_NODE(chat)); void purple_blist_remove_group(PurpleGroup *group) PurpleBuddyListClass *klass = NULL; PurpleBuddyListPrivate *priv = NULL; g_return_if_fail(PURPLE_IS_BUDDY_LIST(purplebuddylist)); g_return_if_fail(PURPLE_IS_GROUP(group)); if (group == purple_blist_get_default_group()) purple_debug_warning("buddylist", "cannot remove default group"); klass = PURPLE_BUDDY_LIST_GET_CLASS(purplebuddylist); priv = purple_buddy_list_get_instance_private(purplebuddylist); node = (PurpleBlistNode *)group; /* Make sure the group is empty */ /* Remove the node from its parent */ if (priv->root == node) { node->prev->next = node->next; node->next->prev = node->prev; key = purple_blist_fold_name(purple_group_get_name(group)); g_hash_table_remove(groups_cache, key); if (klass && klass->remove) { klass->remove(purplebuddylist, node); if (klass && klass->remove_node) { klass->remove_node(purplebuddylist, node); purple_signal_emit(purple_blist_get_handle(), "blist-node-removed", PURPLE_BLIST_NODE(group)); /* Remove the group from all accounts that are online */ for (l = purple_connections_get_all(); l != NULL; l = l->next) PurpleConnection *gc = (PurpleConnection *)l->data; if (purple_connection_get_state(gc) == PURPLE_CONNECTION_CONNECTED) purple_account_remove_group(purple_connection_get_account(gc), group); PurpleBuddy *purple_blist_find_buddy(PurpleAccount *account, const char *name) PurpleBuddyListPrivate *priv = purple_buddy_list_get_instance_private(purplebuddylist); struct _purple_hbuddy hb; g_return_val_if_fail(PURPLE_IS_BUDDY_LIST(purplebuddylist), NULL); g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL); g_return_val_if_fail((name != NULL) && (*name != '\0'), NULL); hb.name = (gchar *)purple_normalize(account, name); for (group = priv->root; group; group = group->next) { if ((buddy = g_hash_table_lookup(priv->buddies, &hb))) { PurpleBuddy *purple_blist_find_buddy_in_group(PurpleAccount *account, const char *name, PurpleBuddyListPrivate *priv = purple_buddy_list_get_instance_private(purplebuddylist); struct _purple_hbuddy hb; g_return_val_if_fail(PURPLE_IS_BUDDY_LIST(purplebuddylist), NULL); g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL); g_return_val_if_fail((name != NULL) && (*name != '\0'), NULL); hb.name = (gchar *)purple_normalize(account, name); hb.group = (PurpleBlistNode*)group; return g_hash_table_lookup(priv->buddies, &hb); static void find_acct_buddies(gpointer key, gpointer value, gpointer data) PurpleBuddy *buddy = value; *list = g_slist_prepend(*list, buddy); GSList *purple_blist_find_buddies(PurpleAccount *account, const char *name) PurpleBuddyListPrivate *priv = purple_buddy_list_get_instance_private(purplebuddylist); g_return_val_if_fail(PURPLE_IS_BUDDY_LIST(purplebuddylist), NULL); g_return_val_if_fail(PURPLE_IS_ACCOUNT(account), NULL); if ((name != NULL) && (*name != '\0')) { struct _purple_hbuddy hb; hb.name = (gchar *)purple_normalize(account, name); for (node = priv->root; node != NULL; node = node->next) { if ((buddy = g_hash_table_lookup(priv->buddies, ret = g_slist_prepend(ret, buddy); GHashTable *buddies = g_hash_table_lookup(buddies_cache, account); g_hash_table_foreach(buddies, find_acct_buddies, &list); PurpleGroup *purple_blist_find_group(const char *name) g_return_val_if_fail(PURPLE_IS_BUDDY_LIST(purplebuddylist), NULL); if (name == NULL || name[0] == '\0') name = PURPLE_BLIST_DEFAULT_GROUP_NAME; if (purple_strequal(name, "Buddies")) name = PURPLE_BLIST_DEFAULT_GROUP_NAME; if (purple_strequal(name, localized_default_group_name)) name = PURPLE_BLIST_DEFAULT_GROUP_NAME; key = purple_blist_fold_name(name); group = g_hash_table_lookup(groups_cache, key); purple_blist_get_default_group(void) group = purple_blist_find_group(PURPLE_BLIST_DEFAULT_GROUP_NAME); group = purple_group_new(PURPLE_BLIST_DEFAULT_GROUP_NAME); purple_blist_add_group(group, NULL); purple_blist_find_chat(PurpleAccount *account, const char *name) PurpleProtocol *protocol = NULL; PurpleProtocolChatEntry *pce; PurpleBlistNode *node, *group; g_return_val_if_fail(PURPLE_IS_BUDDY_LIST(purplebuddylist), NULL); g_return_val_if_fail((name != NULL) && (*name != '\0'), NULL); if (!purple_account_is_connected(account)) protocol = purple_protocols_find(purple_account_get_protocol_id(account)); if (PURPLE_PROTOCOL_IMPLEMENTS(protocol, CLIENT, find_blist_chat)) return purple_protocol_client_iface_find_blist_chat(protocol, account, name); normname = g_strdup(purple_normalize(account, name)); for (group = purple_blist_get_default_root(); group != NULL; for (node = group->child; node != NULL; node = node->next) { if (PURPLE_IS_CHAT(node)) { chat = (PurpleChat*)node; if (account != purple_chat_get_account(chat)) parts = purple_protocol_chat_iface_info(protocol, purple_account_get_connection(purple_chat_get_account(chat))); chat_name = g_hash_table_lookup(purple_chat_get_components(chat), g_list_free_full(parts, g_free); if (purple_chat_get_account(chat) == account && chat_name != NULL && purple_strequal(purple_normalize(account, chat_name), normname)) { void purple_blist_add_account(PurpleAccount *account) PurpleBuddyListClass *klass = NULL; PurpleBlistNode *gnode, *cnode, *bnode; PurpleCountingNode *contact_counter, *group_counter; g_return_if_fail(PURPLE_IS_BUDDY_LIST(purplebuddylist)); klass = PURPLE_BUDDY_LIST_GET_CLASS(purplebuddylist); if (!klass || !klass->update) { for (gnode = purple_blist_get_default_root(); gnode; if (!PURPLE_IS_GROUP(gnode)) for (cnode = gnode->child; cnode; cnode = cnode->next) { if (PURPLE_IS_CONTACT(cnode)) { gboolean recompute = FALSE; for (bnode = cnode->child; bnode; bnode = bnode->next) { if (PURPLE_IS_BUDDY(bnode) && purple_buddy_get_account(PURPLE_BUDDY(bnode)) == account) { contact_counter = PURPLE_COUNTING_NODE(cnode); group_counter = PURPLE_COUNTING_NODE(gnode); purple_counting_node_change_current_size(contact_counter, +1); if (purple_counting_node_get_current_size(contact_counter) == 1) purple_counting_node_change_current_size(group_counter, +1); purple_blist_node_get_bool( cnode, "show_offline")) { purple_contact_invalidate_priority_buddy( klass->update(purplebuddylist, } else if (PURPLE_IS_CHAT(cnode) && purple_chat_get_account(PURPLE_CHAT(cnode)) == account) { group_counter = PURPLE_COUNTING_NODE(gnode); purple_counting_node_change_online_count(group_counter, +1); purple_counting_node_change_current_size(group_counter, +1); klass->update(purplebuddylist, cnode); klass->update(purplebuddylist, gnode); void purple_blist_remove_account(PurpleAccount *account) PurpleBuddyListClass *klass = NULL; PurpleBlistNode *gnode, *cnode, *bnode; PurpleCountingNode *contact_counter, *group_counter; GList *list = NULL, *iter = NULL; g_return_if_fail(PURPLE_IS_BUDDY_LIST(purplebuddylist)); klass = PURPLE_BUDDY_LIST_GET_CLASS(purplebuddylist); for (gnode = purple_blist_get_default_root(); gnode; if (!PURPLE_IS_GROUP(gnode)) group = (PurpleGroup *)gnode; for (cnode = gnode->child; cnode; cnode = cnode->next) { if (PURPLE_IS_CONTACT(cnode)) { gboolean recompute = FALSE; contact = (PurpleContact *)cnode; for (bnode = cnode->child; bnode; bnode = bnode->next) { if (!PURPLE_IS_BUDDY(bnode)) buddy = (PurpleBuddy *)bnode; if (account == purple_buddy_get_account(buddy)) { PurplePresence *presence; presence = purple_buddy_get_presence(buddy); contact_counter = PURPLE_COUNTING_NODE(contact); group_counter = PURPLE_COUNTING_NODE(group); if(purple_presence_is_online(presence)) { purple_counting_node_change_online_count(contact_counter, -1); if (purple_counting_node_get_online_count(contact_counter) == 0) purple_counting_node_change_online_count(group_counter, -1); purple_blist_node_set_int(PURPLE_BLIST_NODE(buddy), "last_seen", time(NULL)); purple_counting_node_change_current_size(contact_counter, -1); if (purple_counting_node_get_current_size(contact_counter) == 0) purple_counting_node_change_current_size(group_counter, -1); if (!g_list_find(list, presence)) list = g_list_prepend(list, presence); if (purple_contact_get_priority_buddy(contact) == buddy) purple_contact_invalidate_priority_buddy(contact); if (klass && klass->remove) { purple_contact_invalidate_priority_buddy(contact); if (klass && klass->update) { klass->update(purplebuddylist, } else if (PURPLE_IS_CHAT(cnode)) { chat = PURPLE_CHAT(cnode); if(purple_chat_get_account(chat) == account) { group_counter = PURPLE_COUNTING_NODE(group); purple_counting_node_change_current_size(group_counter, -1); purple_counting_node_change_online_count(group_counter, -1); if (klass && klass->remove) { klass->remove(purplebuddylist, for (iter = list; iter; iter = iter->next) purple_presence_set_status_active(iter->data, "offline", TRUE); purple_blist_walk(PurpleBlistWalkFunc group_func, PurpleBlistWalkFunc chat_func, PurpleBlistWalkFunc meta_contact_func, PurpleBlistWalkFunc contact_func, PurpleBlistNode *group = NULL, *meta_contact = NULL, *contact = NULL; for (group = purple_blist_get_default_root(); group != NULL; for(meta_contact = group->child; meta_contact != NULL; meta_contact = meta_contact->next) { if(PURPLE_IS_CONTACT(meta_contact)) { if(meta_contact_func != NULL) { meta_contact_func(meta_contact, data); if(contact_func != NULL) { for(contact = meta_contact->child; contact != NULL; contact = contact->next) { contact_func(contact, data); if(PURPLE_IS_CHAT(meta_contact) && chat_func != NULL) { chat_func(meta_contact, data); purple_blist_request_add_buddy(PurpleAccount *account, const char *username, const char *group, const char *alias) PurpleBuddyListClass *klass = NULL; g_return_if_fail(PURPLE_IS_BUDDY_LIST(purplebuddylist)); klass = PURPLE_BUDDY_LIST_GET_CLASS(purplebuddylist); if (klass != NULL && klass->request_add_buddy != NULL) { klass->request_add_buddy(purplebuddylist, account, username, purple_blist_request_add_chat(PurpleAccount *account, PurpleGroup *group, const char *alias, const char *name) PurpleBuddyListClass *klass = NULL; g_return_if_fail(PURPLE_IS_BUDDY_LIST(purplebuddylist)); klass = PURPLE_BUDDY_LIST_GET_CLASS(purplebuddylist); if (klass != NULL && klass->request_add_chat != NULL) { klass->request_add_chat(purplebuddylist, account, group, alias, purple_blist_request_add_group(void) PurpleBuddyListClass *klass = NULL; g_return_if_fail(PURPLE_IS_BUDDY_LIST(purplebuddylist)); klass = PURPLE_BUDDY_LIST_GET_CLASS(purplebuddylist); if (klass != NULL && klass->request_add_group != NULL) { klass->request_add_group(purplebuddylist); purple_blist_new_node(PurpleBuddyList *list, PurpleBlistNode *node) PurpleBuddyListClass *klass = NULL; g_return_if_fail(PURPLE_IS_BUDDY_LIST(list)); klass = PURPLE_BUDDY_LIST_GET_CLASS(list); if (klass && klass->new_node) { klass->new_node(list, node); purple_blist_update_node(PurpleBuddyList *list, PurpleBlistNode *node) PurpleBuddyListClass *klass = NULL; g_return_if_fail(PURPLE_IS_BUDDY_LIST(list)); klass = PURPLE_BUDDY_LIST_GET_CLASS(list); if (klass && klass->update) { klass->update(list, node); purple_blist_save_node(PurpleBuddyList *list, PurpleBlistNode *node) PurpleBuddyListClass *klass = NULL; g_return_if_fail(PURPLE_IS_BUDDY_LIST(list)); klass = PURPLE_BUDDY_LIST_GET_CLASS(list); if (klass && klass->save_node) { klass->save_node(list, node); purple_blist_save_account(PurpleBuddyList *list, PurpleAccount *account) PurpleBuddyListClass *klass = NULL; /* XXX: There's a chicken and egg problem with the accounts api, where * it'll call this function before purple_blist_init is called, this will * cause the following g_return_if_fail to fail, and muck up the logs. We * need to find a better fix for this, but this gets rid of it for now. if(G_UNLIKELY(list == NULL && purplebuddylist == NULL)) { g_return_if_fail(PURPLE_IS_BUDDY_LIST(list)); klass = PURPLE_BUDDY_LIST_GET_CLASS(list); if (klass && klass->save_account) { klass->save_account(list, account); _purple_blist_get_localized_default_group_name(void) return localized_default_group_name; purple_blist_get_handle(void) void *handle = purple_blist_get_handle(); /* Set a default, which can't be done as a static initializer. */ buddy_list_type = PURPLE_TYPE_BUDDY_LIST; purple_signal_register(handle, "buddy-status-changed", purple_marshal_VOID__POINTER_POINTER_POINTER, G_TYPE_NONE, 3, PURPLE_TYPE_BUDDY, PURPLE_TYPE_STATUS, purple_signal_register(handle, "buddy-privacy-changed", purple_marshal_VOID__POINTER, G_TYPE_NONE, purple_signal_register(handle, "buddy-idle-changed", purple_marshal_VOID__POINTER_INT_INT, G_TYPE_NONE, 3, PURPLE_TYPE_BUDDY, G_TYPE_INT, G_TYPE_INT); purple_signal_register(handle, "buddy-signed-on", purple_marshal_VOID__POINTER, G_TYPE_NONE, 1, purple_signal_register(handle, "buddy-signed-off", purple_marshal_VOID__POINTER, G_TYPE_NONE, 1, purple_signal_register(handle, "buddy-got-login-time", purple_marshal_VOID__POINTER, G_TYPE_NONE, 1, purple_signal_register(handle, "blist-node-added", purple_marshal_VOID__POINTER, G_TYPE_NONE, 1, purple_signal_register(handle, "blist-node-removed", purple_marshal_VOID__POINTER, G_TYPE_NONE, 1, purple_signal_register(handle, "buddy-removed-from-group", purple_marshal_VOID__POINTER, G_TYPE_NONE, 1, purple_signal_register(handle, "buddy-icon-changed", purple_marshal_VOID__POINTER, G_TYPE_NONE, 1, purple_signal_register(handle, "update-idle", purple_marshal_VOID, purple_signal_register(handle, "blist-node-extended-menu", purple_marshal_VOID__POINTER_POINTER, G_TYPE_NONE, 2, G_TYPE_POINTER); /* (GList **) */ purple_signal_register(handle, "blist-node-aliased", purple_marshal_VOID__POINTER_POINTER, G_TYPE_NONE, 2, PURPLE_TYPE_BLIST_NODE, G_TYPE_STRING); purple_signal_register(handle, "buddy-caps-changed", purple_marshal_VOID__POINTER_INT_INT, G_TYPE_NONE, 3, PURPLE_TYPE_BUDDY, G_TYPE_INT, G_TYPE_INT); purple_signal_connect(purple_accounts_get_handle(), "account-created", PURPLE_CALLBACK(purple_blist_buddies_cache_add_account), purple_signal_connect(purple_accounts_get_handle(), "account-destroying", PURPLE_CALLBACK(purple_blist_buddies_cache_remove_account), blist_node_destroy(PurpleBuddyListClass *klass, PurpleBuddyList *list, PurpleBlistNode *child, *next_child; next_child = child->next; blist_node_destroy(klass, list, child); /* Allow the UI to free data */ if (klass && klass->remove) { klass->remove(list, node); purple_blist_uninit(void) /* This happens if we quit before purple_set_blist is called. */ if (purplebuddylist == NULL) g_source_remove(save_timer); purple_debug(PURPLE_DEBUG_INFO, "buddylist", "Destroying\n"); g_hash_table_destroy(buddies_cache); g_hash_table_destroy(groups_cache); g_clear_object(&purplebuddylist); g_free(localized_default_group_name); localized_default_group_name = NULL; purple_signals_disconnect_by_handle(purple_blist_get_handle()); purple_signals_unregister_by_instance(purple_blist_get_handle()); /************************************************************************** **************************************************************************/ /* GObject initialization function */ purple_buddy_list_init(PurpleBuddyList *blist) PurpleBuddyListPrivate *priv = purple_buddy_list_get_instance_private(blist); priv->buddies = g_hash_table_new_full( (GHashFunc)_purple_blist_hbuddy_hash, (GEqualFunc)_purple_blist_hbuddy_equal, (GDestroyNotify)_purple_blist_hbuddy_free_key, NULL); /* GObject finalize function */ purple_buddy_list_finalize(GObject *object) PurpleBuddyList *list = PURPLE_BUDDY_LIST(object); PurpleBuddyListClass *klass = PURPLE_BUDDY_LIST_GET_CLASS(list); PurpleBuddyListPrivate *priv = purple_buddy_list_get_instance_private(list); PurpleBlistNode *node, *next_node; g_hash_table_destroy(priv->buddies); blist_node_destroy(klass, list, node); G_OBJECT_CLASS(purple_buddy_list_parent_class)->finalize(object); /* Class initializer function */ static void purple_buddy_list_class_init(PurpleBuddyListClass *klass) GObjectClass *obj_class = G_OBJECT_CLASS(klass); obj_class->finalize = purple_buddy_list_finalize; klass->save_node = purple_blist_real_save_node; klass->remove_node = purple_blist_real_save_node; klass->save_account = purple_blist_real_save_account;