Added missing structures on conversation.pxd.
[python-purple] / nullclient.py
1 import purple
2 import ecore
3 import getpass
4 import sys
5
6 cbs = {}
7 acc_cbs = {}
8 blist_cbs = {}
9 conn_cbs = {}
10 conv_cbs = {}
11 notify_cbs = {}
12 request_cbs = {}
13 signal_cbs = {}
14
15 def account_callback(name):
16     print "---- account callback example: %s" % name
17
18 acc_cbs["notify_added"] = account_callback
19 acc_cbs["status_changed"] = account_callback
20 acc_cbs["request_add"] = account_callback
21 acc_cbs["request_authorize"] = account_callback
22 acc_cbs["close_account_request"] = account_callback
23
24 cbs["account"] = acc_cbs
25
26 def blist_callback(name):
27     print "---- blist callback example: %s" % name
28
29 blist_cbs["new_list"] = blist_callback
30 blist_cbs["new_node"] = blist_callback
31 blist_cbs["show"] = blist_callback
32 blist_cbs["update"] = blist_callback
33 blist_cbs["remove"] = blist_callback
34 blist_cbs["destroy"] = blist_callback
35 blist_cbs["set_visible"] = blist_callback
36 blist_cbs["request_add_buddy"] = blist_callback
37 blist_cbs["request_add_chat"] = blist_callback
38 blist_cbs["request_add_group"] = blist_callback
39
40 cbs["blist"] = blist_cbs
41
42 def conn_callback(name):
43     print "---- connection callback example: %s" % name
44
45 conn_cbs["connect_progress"] = conn_callback
46 conn_cbs["connected"] = conn_callback
47 conn_cbs["disconnected"] = conn_callback
48 conn_cbs["notice"] = conn_callback
49 conn_cbs["report_disconnect"] = conn_callback
50 conn_cbs["network_connected"] = conn_callback
51 conn_cbs["network_disconnected"] = conn_callback
52 conn_cbs["report_disconnect_reason"] = conn_callback
53
54 cbs["connection"] = conn_cbs
55
56 def conv_callback(name):
57     print "---- conversation callback example: %s" % name
58
59 conv_cbs["create_conversation"] = conv_callback
60 conv_cbs["destroy_conversation"] = conv_callback
61 conv_cbs["write_chat"] = conv_callback
62 conv_cbs["write_im"] = conv_callback
63 conv_cbs["write_conv"] = conv_callback
64 conv_cbs["chat_add_users"] = conv_callback
65 conv_cbs["chat_rename_user"] = conv_callback
66 conv_cbs["chat_remove_users"] = conv_callback
67 conv_cbs["chat_update_user"] = conv_callback
68 conv_cbs["present"] = conv_callback
69 conv_cbs["has_focus"] = conv_callback
70 conv_cbs["custom_smiley_add"] = conv_callback
71 conv_cbs["custom_smiley_write"] = conv_callback
72 conv_cbs["custom_smiley_close"] = conv_callback
73 conv_cbs["send_confirm"] = conv_callback
74
75 cbs["conversation"] = conv_cbs
76
77 def notify_callback(name):
78     print "----  notify callback example: %s" % name
79
80 notify_cbs["notify_message"] = notify_callback
81 notify_cbs["notify_email"] = notify_callback
82 notify_cbs["notify_emails"] = notify_callback
83 notify_cbs["notify_formatted"] = notify_callback
84 notify_cbs["notify_searchresults"] = notify_callback
85 notify_cbs["notify_searchresults_new_rows"] = notify_callback
86 notify_cbs["notify_userinfo"] = notify_callback
87 notify_cbs["notify_uri"] = notify_callback
88 notify_cbs["close_notify"] = notify_callback
89
90 cbs["notify"] = notify_cbs
91
92 def request_callback(name):
93     print "---- request callback example: %s" % name
94
95 request_cbs["request_input"] = request_callback
96 request_cbs["request_choice"] = request_callback
97 request_cbs["request_action"] = request_callback
98 request_cbs["request_fields"] = request_callback
99 request_cbs["request_file"] = request_callback
100 request_cbs["close_request"] = request_callback
101 request_cbs["request_folder"] = request_callback
102
103 cbs["request"] = request_cbs
104
105 def buddy_signed_off_cb(name):
106     print "---- signal callback example: sign off from buddy %s" % name
107
108 def receiving_im_msg_cb(sender, message):
109     print "---- signal callback example: receiving im message from %s" % sender
110     print "---- message: %s" % message
111
112 signal_cbs["buddy_signed_off"] = buddy_signed_off_cb
113 signal_cbs["receiving_im_msg"] = receiving_im_msg_cb
114
115 class NullClient:
116     def __init__(self):
117         self.p = purple.Purple(debug_enabled=False)
118         self.account = None
119
120     def execute(self):
121         global cbs
122         self.p.purple_init(cbs)
123
124     def set_protocol(self, protocol):
125         for i in self.p.get_protocols():
126             if i[1] == protocol:
127                 print "-- NULLCLIENT --: Choosing %s as protocol" % protocol
128                 self.protocol = i[0]
129                 print "-- NULLCLIENT --: Protocol successfully chosen: %s" % i[0]
130                 return
131
132     def new_account(self, username, protocol, password):
133         self.account = purple.Account(username, protocol)
134         self.account.set_password(password)
135         self.account.set_enabled("carman-purple-python", True)
136     def get_buddies(self):
137         buddies = self.account.get_buddies_online()
138         print buddies
139
140 def getuser():
141     sys.stdout.write("GTalk account: ")
142     username = sys.stdin.readline()
143     return username[:-1]
144
145 def getpassword():
146     return getpass.getpass()
147
148 if __name__ == '__main__':
149
150     client = NullClient()
151     client.execute()
152     client.set_protocol("XMPP")
153     username = getuser()
154     password = getpassword()
155     client.new_account(username, client.protocol, password)
156
157     client.p.connect()
158     client.p.attach_signals(signal_cbs)
159     ecore.timer_add(20, client.get_buddies)
160     ecore.main_loop_begin()