/soc/2013/ankitkv/gobjectification: 2d73192cdcf8: Started GObjec...
Ankit Vani
a at nevitus.org
Fri Jul 5 13:49:21 EDT 2013
Changeset: 2d73192cdcf82adb5d8c5f8f44b587e3ef9fac2d
Author: Ankit Vani <a at nevitus.org>
Date: 2013-07-05 23:19 +0530
Branch: soc.2013.gobjectification
URL: https://hg.pidgin.im/soc/2013/ankitkv/gobjectification/rev/2d73192cdcf8
Description:
Started GObjectification of the blist source
diffstat:
libpurple/blist.c | 913 +++++++++++++++++++++++++++++------------------------
libpurple/blist.h | 7 +-
2 files changed, 508 insertions(+), 412 deletions(-)
diffs (truncated from 1991 to 300 lines):
diff --git a/libpurple/blist.c b/libpurple/blist.c
--- a/libpurple/blist.c
+++ b/libpurple/blist.c
@@ -92,8 +92,7 @@ struct _PurpleChatPrivate {
/** Private data for the buddy list */
struct _PurpleBuddyListPrivate {
- PurpleBListNode *root; /**< The first node in the buddy list */
- GHashTable *buddies; /**< Every buddy (no pun intended) in this list */
+ GHashTable *buddies; /**< Every buddy (no pun intended) in this list */
};
static PurpleBlistUiOps *blist_ui_ops = NULL;
@@ -240,50 +239,47 @@ chat_component_to_xmlnode(gpointer key,
}
static xmlnode *
-buddy_to_xmlnode(PurpleBListNode *bnode)
+buddy_to_xmlnode(PurpleBuddy *buddy)
{
xmlnode *node, *child;
- PurpleBuddy *buddy;
-
- buddy = (PurpleBuddy *)bnode;
+ PurpleBuddyPrivate *priv = PURPLE_BUDDY_GET_PRIVATE(buddy);
node = xmlnode_new("buddy");
xmlnode_set_attrib(node, "account", purple_account_get_username(buddy->account));
xmlnode_set_attrib(node, "proto", purple_account_get_protocol_id(buddy->account));
child = xmlnode_new_child(node, "name");
- xmlnode_insert_data(child, buddy->name, -1);
-
- if (buddy->alias != NULL)
+ xmlnode_insert_data(child, priv->name, -1);
+
+ if (priv->alias != NULL)
{
child = xmlnode_new_child(node, "alias");
- xmlnode_insert_data(child, buddy->alias, -1);
+ xmlnode_insert_data(child, priv->alias, -1);
}
/* Write buddy settings */
- g_hash_table_foreach(buddy->node.settings, value_to_xmlnode, node);
+ g_hash_table_foreach(purple_blist_node_get_settings(PURPLE_BLIST_NODE(buddy)),
+ value_to_xmlnode, node);
return node;
}
static xmlnode *
-contact_to_xmlnode(PurpleBListNode *cnode)
+contact_to_xmlnode(PurpleContact *contact)
{
xmlnode *node, *child;
- PurpleContact *contact;
PurpleBListNode *bnode;
-
- contact = (PurpleContact *)cnode;
+ PurpleContactPrivate *priv = PURPLE_CONTACT_GET_PRIVATE(contact);
node = xmlnode_new("contact");
- if (contact->alias != NULL)
+ if (priv->alias != NULL)
{
- xmlnode_set_attrib(node, "alias", contact->alias);
+ xmlnode_set_attrib(node, "alias", priv->alias);
}
/* Write buddies */
- for (bnode = cnode->child; bnode != NULL; bnode = bnode->next)
+ for (bnode = PURPLE_BLIST_NODE(contact)->child; bnode != NULL; bnode = bnode->next)
{
if (!PURPLE_BLIST_NODE_SHOULD_SAVE(bnode))
continue;
@@ -295,55 +291,56 @@ contact_to_xmlnode(PurpleBListNode *cnod
}
/* Write contact settings */
- g_hash_table_foreach(cnode->settings, value_to_xmlnode, node);
+ g_hash_table_foreach(purple_blist_node_get_settings(PURPLE_BLIST_NODE(contact)),
+ value_to_xmlnode, node);
return node;
}
static xmlnode *
-chat_to_xmlnode(PurpleBListNode *cnode)
+chat_to_xmlnode(PurpleChat *chat)
{
xmlnode *node, *child;
- PurpleChat *chat;
+ PurpleChatPrivate *priv = PURPLE_CHAT_GET_PRIVATE(chat);
chat = (PurpleChat *)cnode;
node = xmlnode_new("chat");
- xmlnode_set_attrib(node, "proto", purple_account_get_protocol_id(chat->account));
- xmlnode_set_attrib(node, "account", purple_account_get_username(chat->account));
-
- if (chat->alias != NULL)
+ xmlnode_set_attrib(node, "proto", purple_account_get_protocol_id(priv->account));
+ xmlnode_set_attrib(node, "account", purple_account_get_username(priv->account));
+
+ if (priv->alias != NULL)
{
child = xmlnode_new_child(node, "alias");
- xmlnode_insert_data(child, chat->alias, -1);
+ xmlnode_insert_data(child, priv->alias, -1);
}
/* Write chat components */
- g_hash_table_foreach(chat->components, chat_component_to_xmlnode, node);
+ g_hash_table_foreach(priv->components, chat_component_to_xmlnode, node);
/* Write chat settings */
- g_hash_table_foreach(chat->node.settings, value_to_xmlnode, node);
+ g_hash_table_foreach(purple_blist_node_get_settings(PURPLE_BLIST_NODE(chat)),
+ value_to_xmlnode, node);
return node;
}
static xmlnode *
-group_to_xmlnode(PurpleBListNode *gnode)
+group_to_xmlnode(PurpleGroup *group)
{
xmlnode *node, *child;
- PurpleGroup *group;
PurpleBListNode *cnode;
-
- group = (PurpleGroup *)gnode;
+ PurpleGroupPrivate *priv = PURPLE_GROUP_GET_PRIVATE(group);
node = xmlnode_new("group");
- xmlnode_set_attrib(node, "name", group->name);
+ xmlnode_set_attrib(node, "name", priv->name);
/* Write settings */
- g_hash_table_foreach(group->node.settings, value_to_xmlnode, node);
+ g_hash_table_foreach(purple_blist_node_get_settings(PURPLE_BLIST_NODE(group)),
+ value_to_xmlnode, node);
/* Write contacts and chats */
- for (cnode = gnode->child; cnode != NULL; cnode = cnode->next)
+ for (cnode = PURPLE_BLIST_NODE(group)->child; cnode != NULL; cnode = cnode->next)
{
if (!PURPLE_BLIST_NODE_SHOULD_SAVE(cnode))
continue;
@@ -574,11 +571,11 @@ parse_contact(PurpleGroup *group, xmlnod
if (purple_strequal(x->name, "buddy"))
parse_buddy(group, contact, x);
else if (purple_strequal(x->name, "setting"))
- parse_setting((PurpleBListNode*)contact, x);
+ parse_setting(PURPLE_BLIST_NODE(contact), x);
}
/* if the contact is empty, don't keep it around. it causes problems */
- if (!((PurpleBListNode*)contact)->child)
+ if (!PURPLE_BLIST_NODE(contact)->child)
purple_blist_remove_contact(contact);
}
@@ -734,11 +731,12 @@ purple_contact_compute_priority_buddy(Pu
{
PurpleBListNode *bnode;
PurpleBuddy *new_priority = NULL;
-
- g_return_if_fail(contact != NULL);
-
- contact->priority = NULL;
- for (bnode = ((PurpleBListNode*)contact)->child;
+ PurpleContactPrivate *priv = PURPLE_CONTACT_GET_PRIVATE(contact);
+
+ g_return_if_fail(priv != NULL);
+
+ priv->priority = NULL;
+ for (bnode = PURPLE_BLIST_NODE(contact)->child;
bnode != NULL;
bnode = bnode->next)
{
@@ -747,17 +745,17 @@ purple_contact_compute_priority_buddy(Pu
if (!PURPLE_IS_BUDDY(bnode))
continue;
- buddy = (PurpleBuddy*)bnode;
+ buddy = PURPLE_BUDDY(bnode);
if (new_priority == NULL)
{
new_priority = buddy;
continue;
}
- if (purple_account_is_connected(buddy->account))
+ if (purple_account_is_connected(purple_buddy_get_account(buddy)))
{
int cmp = 1;
- if (purple_account_is_connected(new_priority->account))
+ if (purple_account_is_connected(purple_buddy_get_account(new_priority->account)))
cmp = purple_presence_compare(purple_buddy_get_presence(new_priority),
purple_buddy_get_presence(buddy));
@@ -769,8 +767,8 @@ purple_contact_compute_priority_buddy(Pu
}
}
- contact->priority = new_priority;
- contact->priority_valid = TRUE;
+ priv->priority = new_priority;
+ priv->priority_valid = TRUE;
}
@@ -779,16 +777,17 @@ purple_contact_compute_priority_buddy(Pu
*****************************************************************************/
void
-purple_blist_boot(void)
+purple_blist_boot(void) /* TODO init */
{
PurpleBlistUiOps *ui_ops;
GList *account;
- PurpleBuddyList *gbl = g_new0(PurpleBuddyList, 1);
+ PurpleBuddyList *gbl = g_object_new(PurpleBuddyList, 1);
PURPLE_DBUS_REGISTER_POINTER(gbl, PurpleBuddyList);
ui_ops = purple_blist_get_ui_ops();
- gbl->buddies = g_hash_table_new_full((GHashFunc)_purple_blist_hbuddy_hash,
+ PURPLE_BUDDY_LIST_GET_PRIVATE(gbl)->buddies = g_hash_table_new_full(
+ (GHashFunc)_purple_blist_hbuddy_hash,
(GEqualFunc)_purple_blist_hbuddy_equal,
(GDestroyNotify)_purple_blist_hbuddy_free_key, NULL);
@@ -839,7 +838,8 @@ purple_blist_get_buddies()
if (!purplebuddylist)
return NULL;
- g_hash_table_foreach(purplebuddylist->buddies, append_buddy, &buddies);
+ g_hash_table_foreach(PURPLE_BUDDY_LIST_GET_PRIVATE(purplebuddylist)->buddies,
+ append_buddy, &buddies);
return buddies;
}
@@ -952,32 +952,42 @@ purple_blist_update_buddy_status(PurpleB
PurplePresence *presence;
PurpleStatus *status;
PurpleBListNode *cnode;
-
- g_return_if_fail(buddy != NULL);
+ PurpleContact *contact;
+ PurpleBuddyPrivate *priv = PURPLE_BUDDY_GET_PRIVATE(buddy);
+
+ g_return_if_fail(priv != NULL);
presence = purple_buddy_get_presence(buddy);
status = purple_presence_get_active_status(presence);
purple_debug_info("blist", "Updating buddy status for %s (%s)\n",
- buddy->name, purple_account_get_protocol_name(buddy->account));
+ priv->name, purple_account_get_protocol_name(priv->account));
if (purple_status_is_online(status) &&
!purple_status_is_online(old_status)) {
purple_signal_emit(purple_blist_get_handle(), "buddy-signed-on", buddy);
- cnode = buddy->node.parent;
- if (++(PURPLE_CONTACT(cnode)->online) == 1)
- PURPLE_GROUP(cnode->parent)->online++;
+ cnode = PURPLE_BLIST_NODE(buddy)->parent;
+ contact = PURPLE_CONTACT(cnode);
+ purple_contact_set_online_count_relative(contact, +1);
+ if (purple_contact_get_online_count(contact) == 1) {
+ PurpleGroup *group = PURPLE_GROUP(cnode->parent);
+ purple_group_set_online_count_relative(group, +1);
+ }
} else if (!purple_status_is_online(status) &&
purple_status_is_online(old_status)) {
- purple_blist_node_set_int(&buddy->node, "last_seen", time(NULL));
+ purple_blist_node_set_int(&buddy, "last_seen", time(NULL));
purple_signal_emit(purple_blist_get_handle(), "buddy-signed-off", buddy);
- cnode = buddy->node.parent;
- if (--(PURPLE_CONTACT(cnode)->online) == 0)
- PURPLE_GROUP(cnode->parent)->online--;
+ cnode = PURPLE_BLIST_NODE(buddy)->parent;
+ contact = PURPLE_CONTACT(cnode);
+ purple_contact_set_online_count_relative(contact, -1);
+ if (purple_contact_get_online_count(contact) == 0) {
+ PurpleGroup *group = PURPLE_GROUP(cnode->parent);
+ purple_group_set_online_count_relative(group, -1);
+ }
} else {
purple_signal_emit(purple_blist_get_handle(),
"buddy-status-changed", buddy, old_status,
@@ -1019,36 +1029,37 @@ void purple_blist_rename_buddy(PurpleBud
More information about the Commits
mailing list