Improves calls to set proxy's options of the Account
[python-purple] / nullclient.py
index 4953a1f..5fc826c 100644 (file)
@@ -8,6 +8,9 @@ acc_cbs = {}
 blist_cbs = {}
 conn_cbs = {}
 conv_cbs = {}
+notify_cbs = {}
+request_cbs = {}
+signal_cbs = {}
 
 def account_callback(name):
     print "---- account callback example: %s" % name
@@ -39,14 +42,30 @@ 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
 
@@ -71,9 +90,47 @@ conv_cbs["send_confirm"] = conv_callback
 
 cbs["conversation"] = conv_cbs
 
+def notify_callback(name):
+    print "----  notify callback example: %s" % name
+
+notify_cbs["notify_message"] = notify_callback
+notify_cbs["notify_email"] = notify_callback
+notify_cbs["notify_emails"] = notify_callback
+notify_cbs["notify_formatted"] = notify_callback
+notify_cbs["notify_searchresults"] = notify_callback
+notify_cbs["notify_searchresults_new_rows"] = notify_callback
+notify_cbs["notify_userinfo"] = notify_callback
+notify_cbs["notify_uri"] = notify_callback
+notify_cbs["close_notify"] = notify_callback
+
+cbs["notify"] = notify_cbs
+
+def request_callback(name):
+    print "---- request callback example: %s" % name
+
+request_cbs["request_input"] = request_callback
+request_cbs["request_choice"] = request_callback
+request_cbs["request_action"] = request_callback
+request_cbs["request_fields"] = request_callback
+request_cbs["request_file"] = request_callback
+request_cbs["close_request"] = request_callback
+request_cbs["request_folder"] = request_callback
+
+cbs["request"] = request_cbs
+
+def buddy_signed_off_cb(name):
+    print "---- sign off from buddy %s" % name
+
+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
+
 class NullClient:
     def __init__(self):
-        self.p = purple.Purple()
+        self.p = purple.Purple(debug_enabled=False)
         self.account = None
 
     def execute(self):
@@ -81,16 +138,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()
@@ -114,5 +178,6 @@ if __name__ == '__main__':
     client.new_account(username, client.protocol, password)
 
     client.p.connect()
+    client.p.attach_signals(signal_cbs)
     ecore.timer_add(20, client.get_buddies)
     ecore.main_loop_begin()