X-Git-Url: http://git.maemo.org/git/?p=python-purple;a=blobdiff_plain;f=nullclient.py;h=ecda1f630afdb39aaf5cf72128d7051bfdcd432f;hp=81a5ac2cda5b779110f28315634ed5878471baa8;hb=23bbccf4aeb7b092ae26a90f05c1ced78b512295;hpb=3ac088be4b86dfb87718586f7a095f88b566ce42 diff --git a/nullclient.py b/nullclient.py index 81a5ac2..ecda1f6 100644 --- a/nullclient.py +++ b/nullclient.py @@ -27,29 +27,96 @@ 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): print "---- connection callback example: %s" % name -conn_cbs["connect_progress"] = conn_callback -conn_cbs["connected"] = conn_callback -conn_cbs["disconnected"] = conn_callback conn_cbs["notice"] = conn_callback -conn_cbs["report_disconnect"] = conn_callback conn_cbs["network_connected"] = conn_callback conn_cbs["network_disconnected"] = conn_callback -conn_cbs["report_disconnect_reason"] = conn_callback + +def connect_progress_cb(text, step, step_count): + print "---- connection status: %s [%s/%s]" % (text, step, step_count) + +def connected_cb(): + print "---- connection status: Connected" + +def disconnected_cb(): + print "---- connection status: Disconnected" + +def report_disconnect_cb(text): + print "---- %s" % text + +def report_disconnect_reason_cb(reason, text): + print "---- %s (%s)" % (text, reason) + +conn_cbs["connect_progress"] = connect_progress_cb +conn_cbs["connected"] = connected_cb +conn_cbs["disconnected"] = disconnected_cb +conn_cbs["report_disconnect"] = report_disconnect_cb +conn_cbs["report_disconnect_reason"] = report_disconnect_reason_cb cbs["connection"] = conn_cbs @@ -103,11 +170,11 @@ request_cbs["request_folder"] = request_callback cbs["request"] = request_cbs def buddy_signed_off_cb(name): - print "---- signal callback example: sign off from buddy %s" % name + print "---- sign off from buddy %s" % name -def receiving_im_msg_cb(sender, message): - print "---- signal callback example: receiving im message from %s" % sender - print "---- message: %s" % message +def receiving_im_msg_cb(sender, name, message): + print "---- receiving IM message from %s: %s" % (name, message) + return False signal_cbs["buddy_signed_off"] = buddy_signed_off_cb signal_cbs["receiving_im_msg"] = receiving_im_msg_cb @@ -122,16 +189,23 @@ class NullClient: self.p.purple_init(cbs) def set_protocol(self, protocol): - for i in self.p.get_protocols(): - if i[1] == protocol: + for p in self.p.get_protocols(): + if p.get_name() == protocol: print "-- NULLCLIENT --: Choosing %s as protocol" % protocol - self.protocol = i[0] - print "-- NULLCLIENT --: Protocol successfully chosen: %s" % i[0] + self.protocol = p + print "-- NULLCLIENT --: Protocol successfully chosen: %s" % p.get_id() return def new_account(self, username, protocol, password): - self.account = purple.Account(username, protocol) + self.account = purple.Account(username, protocol.get_id()) self.account.set_password(password) + + self.account.proxy.set_type(purple.ProxyInfoType().HTTP) + self.account.proxy.set_host("172.18.216.211") + self.account.proxy.set_port(8080) + + self.account.get_protocol_options() + self.account.set_enabled("carman-purple-python", True) def get_buddies(self): buddies = self.account.get_buddies_online()