Mercurial > pidgin
changeset 22212:6bb29f94862c
Add API so Finch doesn't need to touch the internals of PurpleBlistNode.
author | Sadrul Habib Chowdhury <imadil@gmail.com> |
---|---|
date | Sat, 26 Jan 2008 20:32:26 +0000 |
parents | eddcf0f2da51 |
children | 16ff37f64e29 |
files | ChangeLog.API finch/gntblist.c finch/gntconv.c finch/gntrequest.c finch/plugins/gnthistory.c libpurple/blist.c libpurple/blist.h |
diffstat | 7 files changed, 59 insertions(+), 36 deletions(-) [+] |
line wrap: on
line diff
--- a/ChangeLog.API Sat Jan 26 20:28:35 2008 +0000 +++ b/ChangeLog.API Sat Jan 26 20:32:26 2008 +0000 @@ -34,6 +34,7 @@ * purple_blist_node_get_parent * purple_blist_node_get_first_child * purple_blist_node_get_sibling_next + * purple_blist_node_get_sibling_prev * purple_chat_get_account * Added last_received to PurpleConnection, the time_t of the last received packet.
--- a/finch/gntblist.c Sat Jan 26 20:28:35 2008 +0000 +++ b/finch/gntblist.c Sat Jan 26 20:32:26 2008 +0000 @@ -2158,7 +2158,7 @@ static int blist_node_compare_position(PurpleBlistNode *n1, PurpleBlistNode *n2) { - while ((n1 = n1->prev) != NULL) + while ((n1 = purple_blist_node_get_sibling_prev(n1)) != NULL) if (n1 == n2) return 1; return -1; @@ -2171,10 +2171,10 @@ char *us1, *us2; int ret; - if (n1->type != n2->type) + if (purple_blist_node_get_type(n1) != purple_blist_node_get_type(n2)) return blist_node_compare_position(n1, n2); - switch (n1->type) + switch (purple_blist_node_get_type(n1)) { case PURPLE_BLIST_CHAT_NODE: s1 = purple_chat_get_name((PurpleChat*)n1); @@ -2206,10 +2206,10 @@ { int ret; - if (n1->type != n2->type) + if (purple_blist_node_get_type(n1) != purple_blist_node_get_type(n2)) return blist_node_compare_position(n1, n2); - switch (n1->type) { + switch (purple_blist_node_get_type(n1)) { case PURPLE_BLIST_CONTACT_NODE: n1 = (PurpleBlistNode*)purple_contact_get_priority_buddy((PurpleContact*)n1); n2 = (PurpleBlistNode*)purple_contact_get_priority_buddy((PurpleContact*)n2); @@ -2251,10 +2251,10 @@ int ret; PurpleBuddy *b1, *b2; - if (n1->type != n2->type) + if (purple_blist_node_get_type(n1) != purple_blist_node_get_type(n2)) return blist_node_compare_position(n1, n2); - switch (n1->type) { + switch (purple_blist_node_get_type(n1)) { case PURPLE_BLIST_BUDDY_NODE: b1 = (PurpleBuddy*)n1; b2 = (PurpleBuddy*)n2;
--- a/finch/gntconv.c Sat Jan 26 20:28:35 2008 +0000 +++ b/finch/gntconv.c Sat Jan 26 20:32:26 2008 +0000 @@ -79,7 +79,7 @@ switch (purple_conversation_get_type(conv)) { case PURPLE_CONV_TYPE_IM: node = (PurpleBlistNode*)purple_find_buddy(conv->account, conv->name); - node = node ? node->parent : NULL; + node = node ? purple_blist_node_get_parent(node) : NULL; break; case PURPLE_CONV_TYPE_CHAT: node = (PurpleBlistNode*)purple_blist_find_chat(conv->account, conv->name); @@ -236,7 +236,8 @@ if (!buddy) return NULL; - for (node = ((PurpleBlistNode*)buddy)->parent->child; node; node = node->next) { + for (node = purple_blist_node_get_first_child(purple_blist_node_get_parent((PurpleBlistNode*)buddy)); + node; node = purple_blist_node_get_sibling_next(node)) { if (node == (PurpleBlistNode*)buddy) continue; if ((ret = purple_find_conversation_with_account(PURPLE_CONV_TYPE_IM, @@ -476,7 +477,8 @@ for (; buds; buds = g_slist_delete_link(buds, buds)) { PurpleBlistNode *node = (PurpleBlistNode *)purple_buddy_get_contact((PurpleBuddy *)buds->data); - for (node = node->child; node != NULL; node = node->next) { + for (node = purple_blist_node_get_first_child(node); node != NULL; + node = purple_blist_node_get_sibling_next(node)) { PurpleBuddy *buddy = (PurpleBuddy *)node; PurpleAccount *account = purple_buddy_get_account(buddy); if (purple_account_is_connected(account)) {
--- a/finch/gntrequest.c Sat Jan 26 20:28:35 2008 +0000 +++ b/finch/gntrequest.c Sat Jan 26 20:32:26 2008 +0000 @@ -424,7 +424,8 @@ *screenname = entry; } else if (hint && !strcmp(hint, "group")) { PurpleBlistNode *node; - for (node = purple_blist_get_root(); node; node = node->next) { + for (node = purple_blist_get_root(); node; + node = purple_blist_node_get_sibling_next(node)) { if (PURPLE_BLIST_NODE_IS_GROUP(node)) gnt_entry_add_suggest(GNT_ENTRY(entry), ((PurpleGroup *)node)->name); }
--- a/finch/plugins/gnthistory.c Sat Jan 26 20:28:35 2008 +0000 +++ b/finch/plugins/gnthistory.c Sat Jan 26 20:32:26 2008 +0000 @@ -51,8 +51,7 @@ PurpleMessageFlags mflag; convtype = purple_conversation_get_type(c); - if (convtype == PURPLE_CONV_TYPE_IM) - { + if (convtype == PURPLE_CONV_TYPE_IM) { GSList *buddies; GSList *cur; @@ -62,17 +61,17 @@ return; /* Find buddies for this conversation. */ - buddies = purple_find_buddies(account, name); + buddies = purple_find_buddies(account, name); /* If we found at least one buddy, save the first buddy's alias. */ if (buddies != NULL) alias = purple_buddy_get_contact_alias((PurpleBuddy *)buddies->data); - for (cur = buddies; cur != NULL; cur = cur->next) - { - PurpleBlistNode *node = cur->data; - if ((node != NULL) && ((node->prev != NULL) || (node->next != NULL))) - { + for (cur = buddies; cur != NULL; cur = cur->next) { + PurpleBlistNode *node = cur->data; + if ((node != NULL) && + ((purple_blist_node_get_sibling_prev(node) != NULL) || + (purple_blist_node_get_sibling_next(node) != NULL))) { PurpleBlistNode *node2; alias = purple_buddy_get_contact_alias((PurpleBuddy *)node); @@ -80,26 +79,24 @@ /* We've found a buddy that matches this conversation. It's part of a * PurpleContact with more than one PurpleBuddy. Loop through the PurpleBuddies * in the contact and get all the logs. */ - for (node2 = node->parent->child ; node2 != NULL ; node2 = node2->next) - { + for (node2 = purple_blist_node_get_first_child(purple_blist_node_get_parent(node)); + node2 != NULL ; node2 = purple_blist_node_get_sibling_next(node2)) { logs = g_list_concat( - purple_log_get_logs(PURPLE_LOG_IM, - purple_buddy_get_name((PurpleBuddy *)node2), - purple_buddy_get_account((PurpleBuddy *)node2)), - logs); + purple_log_get_logs(PURPLE_LOG_IM, + purple_buddy_get_name((PurpleBuddy *)node2), + purple_buddy_get_account((PurpleBuddy *)node2)), + logs); } break; - } - } - g_slist_free(buddies); + } + } + g_slist_free(buddies); if (logs == NULL) logs = purple_log_get_logs(PURPLE_LOG_IM, name, account); else logs = g_list_sort(logs, purple_log_compare); - } - else if (convtype == PURPLE_CONV_TYPE_CHAT) - { + } else if (convtype == PURPLE_CONV_TYPE_CHAT) { /* If we're not logging, don't show anything. * Otherwise, we might show a very old log. */ if (!purple_prefs_get_bool("/purple/logging/log_chats")) @@ -115,7 +112,7 @@ history = purple_log_read((PurpleLog*)logs->data, &flags); header = g_strdup_printf(_("<b>Conversation with %s on %s:</b><br>"), alias, - purple_date_format_full(localtime(&((PurpleLog *)logs->data)->time))); + purple_date_format_full(localtime(&((PurpleLog *)logs->data)->time))); purple_conversation_write(c, "", header, mflag, time(NULL)); g_free(header);
--- a/libpurple/blist.c Sat Jan 26 20:28:35 2008 +0000 +++ b/libpurple/blist.c Sat Jan 26 20:32:26 2008 +0000 @@ -768,6 +768,11 @@ return node? node->next : NULL; } +PurpleBlistNode *purple_blist_node_get_sibling_prev(PurpleBlistNode *node) +{ + return node? node->prev : NULL; +} + void purple_blist_update_buddy_status(PurpleBuddy *buddy, PurpleStatus *old_status) {
--- a/libpurple/blist.h Sat Jan 26 20:28:35 2008 +0000 +++ b/libpurple/blist.h Sat Jan 26 20:32:26 2008 +0000 @@ -53,10 +53,10 @@ } PurpleBlistNodeType; -#define PURPLE_BLIST_NODE_IS_CHAT(n) ((n)->type == PURPLE_BLIST_CHAT_NODE) -#define PURPLE_BLIST_NODE_IS_BUDDY(n) ((n)->type == PURPLE_BLIST_BUDDY_NODE) -#define PURPLE_BLIST_NODE_IS_CONTACT(n) ((n)->type == PURPLE_BLIST_CONTACT_NODE) -#define PURPLE_BLIST_NODE_IS_GROUP(n) ((n)->type == PURPLE_BLIST_GROUP_NODE) +#define PURPLE_BLIST_NODE_IS_CHAT(n) (purple_blist_node_get_type(n) == PURPLE_BLIST_CHAT_NODE) +#define PURPLE_BLIST_NODE_IS_BUDDY(n) (purple_blist_node_get_type(n) == PURPLE_BLIST_BUDDY_NODE) +#define PURPLE_BLIST_NODE_IS_CONTACT(n) (purple_blist_node_get_type(n) == PURPLE_BLIST_CONTACT_NODE) +#define PURPLE_BLIST_NODE_IS_GROUP(n) (purple_blist_node_get_type(n) == PURPLE_BLIST_GROUP_NODE) #define PURPLE_BUDDY_IS_ONLINE(b) \ ((b) != NULL && purple_account_is_connected((b)->account) && \ @@ -234,6 +234,7 @@ * @see purple_blist_node_get_parent * @see purple_blist_node_get_first_child * @see purple_blist_node_get_sibling_next + * @see purple_blist_node_get_sibling_prev */ PurpleBlistNode *purple_blist_node_next(PurpleBlistNode *node, gboolean offline); @@ -245,6 +246,7 @@ * @since 2.4.0 * @see purple_blist_node_get_first_child * @see purple_blist_node_get_sibling_next + * @see purple_blist_node_get_sibling_prev * @see purple_blist_node_next */ PurpleBlistNode *purple_blist_node_get_parent(PurpleBlistNode *node); @@ -257,6 +259,7 @@ * @since 2.4.0 * @see purple_blist_node_get_parent * @see purple_blist_node_get_sibling_next + * @see purple_blist_node_get_sibling_prev * @see purple_blist_node_next */ PurpleBlistNode *purple_blist_node_get_first_child(PurpleBlistNode *node); @@ -269,11 +272,25 @@ * @since 2.4.0 * @see purple_blist_node_get_parent * @see purple_blist_node_get_first_child + * @see purple_blist_node_get_sibling_prev * @see purple_blist_node_next */ PurpleBlistNode *purple_blist_node_get_sibling_next(PurpleBlistNode *node); /** + * Returns the previous sibling node of a given node. + * + * @param node A node. + * @return The sibling node. + * @since 2.4.0 + * @see purple_blist_node_get_parent + * @see purple_blist_node_get_first_child + * @see purple_blist_node_get_sibling_next + * @see purple_blist_node_next + */ +PurpleBlistNode *purple_blist_node_get_sibling_prev(PurpleBlistNode *node); + +/** * Shows the buddy list, creating a new one if necessary. */ void purple_blist_show(void);