From 573def76e068006d507f09ea1239fcd6d6adfae7 Mon Sep 17 00:00:00 2001 From: Ragner Magalhaes Date: Tue, 2 Dec 2008 20:40:33 +0000 Subject: [PATCH 1/1] Added initial support for new_node, update and remove callbacks from PurpleBlistUiOps. FIXES: - Added initial support for new_node, update and remove callbacks from PurpleBlistUiOps. Signed-off-by: Bruno Abinader git-svn-id: https://garage.maemo.org/svn/carman/branches/carman-0.7-beta2/python-purple@1336 596f6dd7-e928-0410-a184-9e12fd12cf7e --- blist_cbs.pxd | 127 +++++++++++++++++++++++++++++++++++++++++++++++++++------ nullclient.py | 57 ++++++++++++++++++++++++-- 2 files changed, 169 insertions(+), 15 deletions(-) diff --git a/blist_cbs.pxd b/blist_cbs.pxd index 803c0eb..96268a4 100644 --- a/blist_cbs.pxd +++ b/blist_cbs.pxd @@ -24,6 +24,73 @@ cdef extern from *: blist_cbs = {} +cdef void __group_node_cb(blist.PurpleBlistNode *node, object callback): + cdef blist.PurpleGroup *group = 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 = 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 = 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 = 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: @@ -33,10 +100,22 @@ cdef void new_list (blist.PurpleBuddyList *list): cdef void new_node (blist.PurpleBlistNode *node): debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "new_node\n") - try: - (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: + (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") @@ -47,17 +126,41 @@ cdef void show (blist.PurpleBuddyList *list): cdef void update (blist.PurpleBuddyList *list, blist.PurpleBlistNode *node): debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "update\n") - try: - (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: + (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: - (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: + (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") diff --git a/nullclient.py b/nullclient.py index 5fc826c..ecda1f6 100644 --- a/nullclient.py +++ b/nullclient.py @@ -27,16 +27,67 @@ def blist_callback(name): 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): -- 1.7.9.5