Add support to new callback class
[python-purple] / blist_cbs.pxd
1 #
2 #  Copyright (c) 2008 INdT - Instituto Nokia de Tecnologia
3 #
4 #  This file is part of python-purple.
5 #
6 #  python-purple is free software: you can redistribute it and/or modify
7 #  it under the terms of the GNU General Public License as published by
8 #  the Free Software Foundation, either version 3 of the License, or
9 #  (at your option) any later version.
10 #
11 #  python-purple is distributed in the hope that it will be useful,
12 #  but WITHOUT ANY WARRANTY; without even the implied warranty of
13 #  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
14 #  GNU General Public License for more details.
15 #
16 #  You should have received a copy of the GNU General Public License
17 #  along with this program.  If not, see <http://www.gnu.org/licenses/>.
18 #
19
20 cimport purple
21
22 cdef extern from *:
23     ctypedef char const_char "const char"
24
25 blist_cbs = {}
26
27 cdef void __group_node_cb(blist.PurpleBlistNode *node, object callback):
28     cdef blist.PurpleGroup *group = <blist.PurpleGroup *>node
29
30     if group.name:
31         name = group.name
32     else:
33         name = ""
34
35     try:
36         callback(node.type, name, group.totalsize, group.currentsize, \
37                  group.online)
38     except KeyError:
39         pass
40
41 cdef void __contact_node_cb(blist.PurpleBlistNode *node, object callback):
42     cdef blist.PurpleContact *contact = <blist.PurpleContact *>node
43
44     if contact.alias:
45         alias = contact.alias
46     else:
47         alias = ""
48
49     name = ""
50
51     try:
52         callback(node.type, name, alias, contact.totalsize, contact.currentsize, \
53                  contact.online)
54     except KeyError:
55         pass
56
57 cdef void __buddy_node_cb(blist.PurpleBlistNode *node, object callback):
58     cdef blist.PurpleBuddy *buddy = <blist.PurpleBuddy *>node
59
60     if buddy.server_alias:
61         alias = buddy.server_alias
62     elif buddy.alias:
63         alias = buddy.alias
64     else:
65         alias = ""
66
67     if buddy.name:
68         name = buddy.name
69     else:
70         name = ""
71
72     try:
73         callback(node.type, name, alias)
74     except KeyError:
75         pass
76
77 cdef void __chat_node_cb(blist.PurpleBlistNode *node, object callback):
78     cdef blist.PurpleChat *chat = <blist.PurpleChat *>node
79
80     if chat.alias:
81         alias = chat.alias
82     else:
83         alias = ""
84
85     try:
86         callback(node.type, alias)
87     except KeyError:
88         pass
89
90 cdef void __other_node_cb(blist.PurpleBlistNode *node, object callback):
91     try:
92         callback(node.type)
93     except KeyError:
94         pass
95
96 cdef void new_list (blist.PurpleBuddyList *list):
97     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "new_list\n")
98     try:
99         (<object>blist_cbs["new_list"])("new_list")
100     except KeyError:
101         pass
102
103 cdef void new_node (blist.PurpleBlistNode *node):
104     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "new_node\n")
105
106     try:
107         if node.type == blist.PURPLE_BLIST_GROUP_NODE:
108             __group_node_cb(node, blist_cbs["new_node"])
109         elif node.type == blist.PURPLE_BLIST_CONTACT_NODE:
110             __contact_node_cb(node, blist_cbs["new_node"])
111         elif node.type == blist.PURPLE_BLIST_BUDDY_NODE:
112             __buddy_node_cb(node, blist_cbs["new_node"])
113         elif node.type == blist.PURPLE_BLIST_CHAT_NODE:
114             __chat_node_cb(node, blist_cbs["new_node"])
115         elif node.type == blist.PURPLE_BLIST_OTHER_NODE:
116             __other_node_cb(node, blist_cbs["new_node"])
117         else:
118             (<object>blist_cbs["new_node"])(node.type)
119     except KeyError:
120         pass
121
122 cdef void show (blist.PurpleBuddyList *list):
123     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "show\n")
124     try:
125         (<object>blist_cbs["show"])("show")
126     except KeyError:
127         pass
128
129 cdef void update (blist.PurpleBuddyList *list, blist.PurpleBlistNode *node):
130     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "update\n")
131
132     try:
133         if node.type == blist.PURPLE_BLIST_GROUP_NODE:
134             __group_node_cb(node, blist_cbs["update"])
135         elif node.type == blist.PURPLE_BLIST_CONTACT_NODE:
136             __contact_node_cb(node, blist_cbs["update"])
137         elif node.type == blist.PURPLE_BLIST_BUDDY_NODE:
138             __buddy_node_cb(node, blist_cbs["update"])
139         elif node.type == blist.PURPLE_BLIST_CHAT_NODE:
140             __chat_node_cb(node, blist_cbs["update"])
141         elif node.type == blist.PURPLE_BLIST_OTHER_NODE:
142             __other_node_cb(node, blist_cbs["update"])
143         else:
144             (<object>blist_cbs["update"])(node.type)
145     except KeyError:
146         pass
147
148 cdef void remove (blist.PurpleBuddyList *list, blist.PurpleBlistNode *node):
149     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "remove\n")
150
151     try:
152         if node.type == blist.PURPLE_BLIST_GROUP_NODE:
153             __group_node_cb(node, blist_cbs["remove"])
154         elif node.type == blist.PURPLE_BLIST_CONTACT_NODE:
155             __contact_node_cb(node, blist_cbs["remove"])
156         elif node.type == blist.PURPLE_BLIST_BUDDY_NODE:
157             __buddy_node_cb(node, blist_cbs["remove"])
158         elif node.type == blist.PURPLE_BLIST_CHAT_NODE:
159             __chat_node_cb(node, blist_cbs["remove"])
160         elif node.type == blist.PURPLE_BLIST_OTHER_NODE:
161             __other_node_cb(node, blist_cbs["remove"])
162         else:
163             (<object>blist_cbs["remove"])(node.type)
164     except KeyError:
165         pass
166
167 cdef void destroy (blist.PurpleBuddyList *list):
168     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "destroy\n")
169     try:
170         (<object>blist_cbs["destroy"])("destroy")
171     except KeyError:
172         pass
173
174 cdef void set_visible (blist.PurpleBuddyList *list, glib.gboolean show):
175     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "set_visible\n")
176     try:
177         (<object>blist_cbs["set_visible"])("set_visible")
178     except KeyError:
179         pass
180
181 cdef void request_add_buddy (account.PurpleAccount *account,
182                              const_char *username, const_char *group,
183                              const_char *alias):
184     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "request_add_buddy\n")
185     try:
186         (<object>blist_cbs["request_add_buddy"])("request_add_buddy")
187     except KeyError:
188         pass
189
190 cdef void request_add_chat (account.PurpleAccount *account,
191                             blist.PurpleGroup *group, const_char *alias,
192                             const_char *name):
193     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "request_add_chat\n")
194     try:
195         (<object>blist_cbs["request_add_chat"])("request_add_chat")
196     except KeyError:
197         pass
198
199 cdef void request_add_group ():
200     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "request_add_group\n")
201     try:
202         (<object>blist_cbs["request_add_chat"])("request_add_group")
203     except KeyError:
204         pass