Added initial support for new_node, update and remove callbacks from PurpleBlistUiOps.
authorRagner Magalhaes <ragner.magalhaes@openbossa.org>
Tue, 2 Dec 2008 20:40:33 +0000 (20:40 +0000)
committerAnderson Briglia <anderson.briglia@openbossa.org>
Sat, 28 Feb 2009 21:11:12 +0000 (17:11 -0400)
FIXES:
 - Added initial support for new_node, update and remove callbacks from PurpleBlistUiOps.

Signed-off-by: Bruno Abinader <bruno.abinader@indt.org.br>

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
nullclient.py

index 803c0eb..96268a4 100644 (file)
@@ -24,6 +24,73 @@ cdef extern from *:
 
 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:
@@ -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:
-        (<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")
@@ -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:
-        (<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")
index 5fc826c..ecda1f6 100644 (file)
@@ -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):