blist_cbs = {}
+cdef void __group_node_cb(blist.PurpleBlistNode *node, object callback):
+ cdef blist.PurpleGroup *group = <blist.PurpleGroup *>node
+
+ if group.name:
+ name = group.name
+ else:
+ name = None
+
+ try:
+ callback(node.type, name, group.totalsize, group.currentsize, \
+ group.online)
+ except KeyError:
+ pass
+
+cdef void __contact_node_cb(blist.PurpleBlistNode *node, object callback):
+ cdef blist.PurpleContact *contact = <blist.PurpleContact *>node
+
+ if contact.alias:
+ alias = contact.alias
+ else:
+ alias = None
+
+ try:
+ callback(node.type, alias, contact.totalsize, contact.currentsize, \
+ contact.online)
+ except KeyError:
+ pass
+
+cdef void __buddy_node_cb(blist.PurpleBlistNode *node, object callback):
+ cdef blist.PurpleBuddy *buddy = <blist.PurpleBuddy *>node
+
+ if buddy.server_alias:
+ alias = buddy.server_alias
+ elif buddy.alias:
+ alias = buddy.alias
+ else:
+ alias = None
+
+ if buddy.name:
+ name = buddy.name
+ else:
+ name = None
+
+ try:
+ callback(node.type, name, alias)
+ except KeyError:
+ pass
+
+cdef void __chat_node_cb(blist.PurpleBlistNode *node, object callback):
+ cdef blist.PurpleChat *chat = <blist.PurpleChat *>node
+
+ if chat.alias:
+ alias = chat.alias
+ else:
+ alias = None
+
+ try:
+ callback(node.type, alias)
+ except KeyError:
+ pass
+
+cdef void __other_node_cb(blist.PurpleBlistNode *node, object callback):
+ try:
+ callback(node.type)
+ except KeyError:
+ pass
+
cdef void new_list (blist.PurpleBuddyList *list):
debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "new_list\n")
try:
cdef void new_node (blist.PurpleBlistNode *node):
debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "new_node\n")
- try:
- (<object>blist_cbs["new_node"])("new_node")
- except KeyError:
- pass
+
+ if node.type == blist.PURPLE_BLIST_GROUP_NODE:
+ __group_node_cb(node, blist_cbs["new_node"])
+ elif node.type == blist.PURPLE_BLIST_CONTACT_NODE:
+ __contact_node_cb(node, blist_cbs["new_node"])
+ elif node.type == blist.PURPLE_BLIST_BUDDY_NODE:
+ __buddy_node_cb(node, blist_cbs["new_node"])
+ elif node.type == blist.PURPLE_BLIST_CHAT_NODE:
+ __chat_node_cb(node, blist_cbs["new_node"])
+ elif node.type == blist.PURPLE_BLIST_OTHER_NODE:
+ __other_node_cb(node, blist_cbs["new_node"])
+ else:
+ try:
+ (<object>blist_cbs["new_node"])(node.type)
+ except KeyError:
+ pass
cdef void show (blist.PurpleBuddyList *list):
debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "show\n")
cdef void update (blist.PurpleBuddyList *list, blist.PurpleBlistNode *node):
debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "update\n")
- try:
- (<object>blist_cbs["update"])("update")
- except KeyError:
- pass
+
+ if node.type == blist.PURPLE_BLIST_GROUP_NODE:
+ __group_node_cb(node, blist_cbs["update"])
+ elif node.type == blist.PURPLE_BLIST_CONTACT_NODE:
+ __contact_node_cb(node, blist_cbs["update"])
+ elif node.type == blist.PURPLE_BLIST_BUDDY_NODE:
+ __buddy_node_cb(node, blist_cbs["update"])
+ elif node.type == blist.PURPLE_BLIST_CHAT_NODE:
+ __chat_node_cb(node, blist_cbs["update"])
+ elif node.type == blist.PURPLE_BLIST_OTHER_NODE:
+ __other_node_cb(node, blist_cbs["update"])
+ else:
+ try:
+ (<object>blist_cbs["update"])(node.type)
+ except KeyError:
+ pass
cdef void remove (blist.PurpleBuddyList *list, blist.PurpleBlistNode *node):
debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "remove\n")
- try:
- (<object>blist_cbs["remove"])("remove")
- except KeyError:
- pass
+
+ if node.type == blist.PURPLE_BLIST_GROUP_NODE:
+ __group_node_cb(node, blist_cbs["remove"])
+ elif node.type == blist.PURPLE_BLIST_CONTACT_NODE:
+ __contact_node_cb(node, blist_cbs["remove"])
+ elif node.type == blist.PURPLE_BLIST_BUDDY_NODE:
+ __buddy_node_cb(node, blist_cbs["remove"])
+ elif node.type == blist.PURPLE_BLIST_CHAT_NODE:
+ __chat_node_cb(node, blist_cbs["remove"])
+ elif node.type == blist.PURPLE_BLIST_OTHER_NODE:
+ __other_node_cb(node, blist_cbs["remove"])
+ else:
+ try:
+ (<object>blist_cbs["remove"])(node.type)
+ except KeyError:
+ pass
cdef void destroy (blist.PurpleBuddyList *list):
debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "destroy\n")
print "---- blist callback example: %s" % name
blist_cbs["new_list"] = blist_callback
-blist_cbs["new_node"] = blist_callback
blist_cbs["show"] = blist_callback
-blist_cbs["update"] = blist_callback
-blist_cbs["remove"] = blist_callback
blist_cbs["destroy"] = blist_callback
blist_cbs["set_visible"] = blist_callback
blist_cbs["request_add_buddy"] = blist_callback
blist_cbs["request_add_chat"] = blist_callback
blist_cbs["request_add_group"] = blist_callback
+def new_node_cb(type, name=None, totalsize=None, currentsize=None, online=None):
+ if type == 0:
+ print "---- blist callback: new node (group): %s (%s/%s) (%s online)" % \
+ (name, totalsize, currentsize, online)
+ elif type == 1:
+ print "---- blist callback: new node (contact): %s (%s/%s) (%s online)" % \
+ (name, totalsize, currentsize, online)
+ elif type == 2: # totalsize = alias
+ print "---- blist callback: new node (buddy): %s (%s)" % (name, totalsize)
+ elif type == 3:
+ print "---- blist callback: new node (chat): %s" % alias
+ elif type == 4:
+ print "---- blist callback: new node (other type)"
+ else:
+ print "---- blist callback: new node (unknown type %s)" % type
+
+def update_cb(type, name=None, totalsize=None, currentsize=None, online=None):
+ if type == 0:
+ print "---- blist callback: update (group): %s (%s/%s) (%s online)" % \
+ (name, totalsize, currentsize, online)
+ elif type == 1:
+ print "---- blist callback: update (contact): %s (%s/%s) (%s online)" % \
+ (name, totalsize, currentsize, online)
+ elif type == 2: # totalsize = alias
+ print "---- blist callback: update (buddy): %s (%s)" % \
+ (name, totalsize)
+ elif type == 3:
+ print "---- blist callback: update (chat): %s" % alias
+ elif type == 4:
+ print "---- blist callback: update (other type)"
+ else:
+ print "---- blist callback: update (unknown type %s)" % type
+
+def remove_cb(type, name=None, totalsize=None, currentsize=None, online=None):
+ if type == 0:
+ print "---- blist callback: remove (group): %s (%s/%s) (%s online)" % \
+ (name, totalsize, currentsize, online)
+ elif type == 1:
+ print "---- blist callback: remove (contact): %s (%s/%s) (%s online)" % \
+ (name, totalsize, currentsize, online)
+ elif type == 2: # totalsize = alias
+ print "---- blist callback: remove (buddy): %s (%s)" % \
+ (name, totalsize)
+ elif type == 3:
+ print "---- blist callback: remove (chat): %s" % alias
+ elif type == 4:
+ print "---- blist callback: remove (other type)"
+ else:
+ print "---- blist callback: remove (unknown type %s)" % type
+
+blist_cbs["new_node"] = new_node_cb
+blist_cbs["update"] = update_cb
+blist_cbs["remove"] = remove_cb
+
cbs["blist"] = blist_cbs
def conn_callback(name):