Wed, 10 Jul 2013 00:49:03 +0530
Refactored finch to use the GObject BList API. Added purple_chat_get_name_only().
--- a/finch/gntblist.c Tue Jul 09 23:49:14 2013 +0530 +++ b/finch/gntblist.c Wed Jul 10 00:49:03 2013 +0530 @@ -72,15 +72,15 @@ GntWidget *tree; GntWidget *tooltip; - PurpleBListNode *tnode; /* Who is the tooltip being displayed for? */ - GList *tagged; /* A list of tagged blistnodes */ + PurpleBListNode *tnode; /* Who is the tooltip being displayed for? */ + GList *tagged; /* A list of tagged blistnodes */ GntWidget *context; PurpleBListNode *cnode; /* XXX: I am KISSing */ - GntWidget *status; /* Dropdown with the statuses */ - GntWidget *statustext; /* Status message */ + GntWidget *status; /* Dropdown with the statuses */ + GntWidget *statustext; /* Status message */ int typing; GntWidget *menu; @@ -101,8 +101,8 @@ typedef struct { - gpointer row; /* the row in the GntTree */ - guint signed_timer; /* used when 'recently' signed on/off */ + gpointer row; /* the row in the GntTree */ + guint signed_timer; /* used when 'recently' signed on/off */ } FinchBListNode; typedef enum @@ -215,17 +215,13 @@ static gpointer default_find_parent(PurpleBListNode *node) { gpointer ret = NULL; - switch (purple_blist_node_get_type(node)) { - case PURPLE_BLIST_BUDDY_NODE: - case PURPLE_BLIST_CONTACT_NODE: - case PURPLE_BLIST_CHAT_NODE: - ret = purple_blist_node_get_parent(node); - break; - default: - break; - } + + if (PURPLE_IS_BUDDY(node) || PURPLE_IS_CONTACT(node) || PURPLE_IS_CHAT(node)) + ret = purple_blist_node_get_parent(node); + if (ret) add_node(ret, ggblist); + return ret; } @@ -236,8 +232,8 @@ int lastseen = 0; char *title; - if (!node || - purple_blist_node_get_type(node) == PURPLE_BLIST_OTHER_NODE) + if (!node || !(PURPLE_IS_BUDDY(node) || PURPLE_IS_CONTACT(node) || + PURPLE_IS_GROUP(node) || PURPLE_IS_CHAT(node))) return FALSE; str = g_string_new(""); @@ -276,8 +272,8 @@ PurpleGroup *group = (PurpleGroup *)node; g_string_append_printf(str, _("Online: %d\nTotal: %d"), - purple_blist_get_group_online_count(group), - purple_blist_get_group_size(group, FALSE)); + purple_counting_node_get_online_count(PURPLE_COUNTING_NODE(group)), + purple_counting_node_get_current_size(PURPLE_COUNTING_NODE(group))); title = g_strdup(purple_group_get_name(group)); } else if (PURPLE_IS_CHAT(node)) { @@ -708,16 +704,9 @@ PurpleAccount *account = purple_chat_get_account(chat); const char *name; PurpleChatConversation *conv; - const char *alias; - - /* This hack here is to work around the fact that there's no good way of - * getting the actual name of a chat. I don't understand why we return - * the alias for a chat when all we want is the name. */ - alias = chat->alias; - chat->alias = NULL; - name = purple_chat_get_name(chat); + + name = purple_chat_get_name_only(chat); conv = purple_conversations_find_chat_with_account(name, account); - chat->alias = (char *)alias; if (!conv || purple_chat_conversation_has_left(conv)) { serv_join_chat(purple_account_get_connection(account), @@ -1512,7 +1501,7 @@ if (PURPLE_IS_CONTACT(node)) { PurpleContact *c = (PurpleContact*)node; name = purple_contact_get_alias(c); - if (purple_contact_get_contact_size(c, TRUE) > 1) + if (purple_counting_node_get_total_size(PURPLE_COUNTING_NODE(c)) > 1) sec = _("Removing this contact will also remove all the buddies in the contact"); } else if (PURPLE_IS_BUDDY(node)) { name = purple_buddy_get_name((PurpleBuddy*)node); @@ -1564,8 +1553,8 @@ PurpleGroup *tg = NULL; PurpleContact *tc = NULL; - if (target == NULL || - purple_blist_node_get_type(target) == PURPLE_BLIST_OTHER_NODE) + if (target == NULL || !(PURPLE_IS_BUDDY(target) || PURPLE_IS_CONTACT(target) || + PURPLE_IS_GROUP(target) || PURPLE_IS_CHAT(target))) return; if (PURPLE_IS_GROUP(target)) @@ -1649,7 +1638,8 @@ tree = GNT_TREE(ggblist->tree); node = gnt_tree_get_selection_data(tree); - if (node && purple_blist_node_get_type(node) == PURPLE_BLIST_OTHER_NODE) + if (node && !(PURPLE_IS_BUDDY(node) || PURPLE_IS_CONTACT(node) || + PURPLE_IS_GROUP(node) || PURPLE_IS_CHAT(node))) return; if (ggblist->tooltip) @@ -2355,25 +2345,20 @@ char *us1, *us2; int ret; - if (purple_blist_node_get_type(n1) != purple_blist_node_get_type(n2)) + if (G_OBJECT_TYPE(n1) != G_OBJECT_TYPE(n2)) return blist_node_compare_position(n1, n2); - switch (purple_blist_node_get_type(n1)) - { - case PURPLE_BLIST_CHAT_NODE: - s1 = purple_chat_get_name((PurpleChat*)n1); - s2 = purple_chat_get_name((PurpleChat*)n2); - break; - case PURPLE_BLIST_BUDDY_NODE: - return purple_presence_compare(purple_buddy_get_presence((PurpleBuddy*)n1), - purple_buddy_get_presence((PurpleBuddy*)n2)); - break; - case PURPLE_BLIST_CONTACT_NODE: - s1 = purple_contact_get_alias((PurpleContact*)n1); - s2 = purple_contact_get_alias((PurpleContact*)n2); - break; - default: - return blist_node_compare_position(n1, n2); + if (PURPLE_IS_CHAT(n1)) { + s1 = purple_chat_get_name((PurpleChat*)n1); + s2 = purple_chat_get_name((PurpleChat*)n2); + } else if (PURPLE_IS_BUDDY(n1)) { + return purple_presence_compare(purple_buddy_get_presence((PurpleBuddy*)n1), + purple_buddy_get_presence((PurpleBuddy*)n2)); + } else if (PURPLE_IS_CONTACT(n1)) { + s1 = purple_contact_get_alias((PurpleContact*)n1); + s2 = purple_contact_get_alias((PurpleContact*)n2); + } else { + return blist_node_compare_position(n1, n2); } us1 = g_utf8_strup(s1, -1); @@ -2390,23 +2375,21 @@ { int ret; - if (purple_blist_node_get_type(n1) != purple_blist_node_get_type(n2)) + if (G_OBJECT_TYPE(n1) != G_OBJECT_TYPE(n2)) return blist_node_compare_position(n1, n2); - switch (purple_blist_node_get_type(n1)) { - case PURPLE_BLIST_CONTACT_NODE: - n1 = PURPLE_BLIST_NODE(purple_contact_get_priority_buddy(PURPLE_CONTACT(n1))); - n2 = PURPLE_BLIST_NODE(purple_contact_get_priority_buddy(PURPLE_CONTACT(n2))); - /* now compare the presence of the priority buddies */ - case PURPLE_BLIST_BUDDY_NODE: - ret = purple_presence_compare(purple_buddy_get_presence((PurpleBuddy*)n1), - purple_buddy_get_presence((PurpleBuddy*)n2)); - if (ret != 0) - return ret; - break; - default: - return blist_node_compare_position(n1, n2); - break; + if (PURPLE_IS_CONTACT(n1) || PURPLE_IS_BUDDY(n1)) { + n1 = PURPLE_BLIST_NODE(purple_contact_get_priority_buddy(PURPLE_CONTACT(n1))); + n2 = PURPLE_BLIST_NODE(purple_contact_get_priority_buddy(PURPLE_CONTACT(n2))); + } + + if (PURPLE_IS_BUDDY(n1)) { + ret = purple_presence_compare(purple_buddy_get_presence((PurpleBuddy*)n1), + purple_buddy_get_presence((PurpleBuddy*)n2)); + if (ret != 0) + return ret; + } else { + return blist_node_compare_position(n1, n2); } /* Sort alphabetically if presence is not comparable */ @@ -2436,26 +2419,24 @@ int ret; PurpleBuddy *b1, *b2; - if (purple_blist_node_get_type(n1) != purple_blist_node_get_type(n2)) + if (G_OBJECT_TYPE(n1) != G_OBJECT_TYPE(n2)) return blist_node_compare_position(n1, n2); - switch (purple_blist_node_get_type(n1)) { - case PURPLE_BLIST_BUDDY_NODE: - b1 = (PurpleBuddy*)n1; - b2 = (PurpleBuddy*)n2; - ret = purple_log_get_total_size(PURPLE_LOG_IM, purple_buddy_get_name(b2), purple_buddy_get_account(b2)) - - purple_log_get_total_size(PURPLE_LOG_IM, purple_buddy_get_name(b1), purple_buddy_get_account(b1)); - if (ret != 0) - return ret; - break; - case PURPLE_BLIST_CONTACT_NODE: - ret = get_contact_log_size(n2) - get_contact_log_size(n1); - if (ret != 0) - return ret; - break; - default: - return blist_node_compare_position(n1, n2); + if (PURPLE_IS_BUDDY(n1)) { + b1 = (PurpleBuddy*)n1; + b2 = (PurpleBuddy*)n2; + ret = purple_log_get_total_size(PURPLE_LOG_IM, purple_buddy_get_name(b2), purple_buddy_get_account(b2)) - + purple_log_get_total_size(PURPLE_LOG_IM, purple_buddy_get_name(b1), purple_buddy_get_account(b1)); + if (ret != 0) + return ret; + } else if (PURPLE_IS_CONTACT(n1)) { + ret = get_contact_log_size(n2) - get_contact_log_size(n1); + if (ret != 0) + return ret; + } else { + return blist_node_compare_position(n1, n2); } + ret = blist_node_compare_text(n1, n2); return ret; }
--- a/libpurple/blistnodetypes.c Tue Jul 09 23:49:14 2013 +0530 +++ b/libpurple/blistnodetypes.c Wed Jul 10 00:49:03 2013 +0530 @@ -1097,6 +1097,18 @@ const char *purple_chat_get_name(PurpleChat *chat) { + PurpleChatPrivate *priv = PURPLE_CHAT_GET_PRIVATE(chat); + + g_return_val_if_fail(priv != NULL, NULL); + + if ((priv->alias != NULL) && (*priv->alias != '\0')) + return priv->alias; + + return purple_chat_get_name_only(chat); +} + +const char *purple_chat_get_name_only(PurpleChat *chat) +{ char *ret = NULL; PurplePlugin *prpl; PurplePluginProtocolInfo *prpl_info = NULL; @@ -1104,9 +1116,6 @@ g_return_val_if_fail(priv != NULL, NULL); - if ((priv->alias != NULL) && (*priv->alias != '\0')) - return priv->alias; - prpl = purple_find_prpl(purple_account_get_protocol_id(priv->account)); prpl_info = PURPLE_PLUGIN_PROTOCOL_INFO(prpl);
--- a/libpurple/blistnodetypes.h Tue Jul 09 23:49:14 2013 +0530 +++ b/libpurple/blistnodetypes.h Wed Jul 10 00:49:03 2013 +0530 @@ -501,6 +501,14 @@ const char *purple_chat_get_name(PurpleChat *chat); /** + * Returns the name of the chat + * + * @param chat The chat whose name will be returned. + * @return The first component value. + */ +const char *purple_chat_get_name_only(PurpleChat *chat); + +/** * Sets the alias for a blist chat. * * @param chat The chat
--- a/libpurple/plugins/perl/common/BuddyList.xs Tue Jul 09 23:49:14 2013 +0530 +++ b/libpurple/plugins/perl/common/BuddyList.xs Wed Jul 10 00:49:03 2013 +0530 @@ -298,6 +298,10 @@ purple_chat_get_name(chat) Purple::BuddyList::Chat chat +const char * +purple_chat_get_name_only(chat) + Purple::BuddyList::Chat chat + HV * purple_chat_get_components(chat) Purple::BuddyList::Chat chat