Fixed wrong assertion when sender name is NULL.
[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     cdef char *c_name = NULL
30
31     c_name = <char *> blist.c_purple_group_get_name(group)
32     if c_name == NULL:
33         name = None
34     else:
35         name = c_name
36
37     currentsize = blist.c_purple_blist_get_group_size(group, False)
38     totalsize = blist.c_purple_blist_get_group_size(group, True)
39     online = blist.c_purple_blist_get_group_online_count(group)
40
41     try:
42         callback(node.type, name, totalsize, currentsize, online)
43     except KeyError:
44         pass
45
46 cdef void __contact_node_cb(blist.PurpleBlistNode *node, object callback):
47     cdef blist.PurpleContact *contact = <blist.PurpleContact *>node
48     cdef char *c_alias = NULL
49
50     c_alias = <char *> blist.c_purple_contact_get_alias(contact)
51     if c_alias == NULL:
52         alias = None
53     else:
54         alias = c_alias
55
56     try:
57         callback(node.type, alias, contact.totalsize, contact.currentsize, \
58                  contact.online)
59     except KeyError:
60         pass
61
62 cdef void __buddy_node_cb(blist.PurpleBlistNode *node, object callback):
63     cdef blist.PurpleBuddy *buddy = <blist.PurpleBuddy *>node
64     cdef char *c_name = NULL
65     cdef char *c_alias = NULL
66
67     c_name = <char *> blist.c_purple_buddy_get_name(buddy)
68     if c_name == NULL:
69         name = None
70     else:
71         name = c_name
72
73     c_alias = <char *> blist.c_purple_buddy_get_alias_only(buddy)
74     if c_alias == NULL:
75         alias = None
76     else:
77         alias = c_alias
78
79     try:
80         callback(node.type, name, alias)
81     except KeyError:
82         pass
83
84 cdef void __chat_node_cb(blist.PurpleBlistNode *node, object callback):
85     cdef blist.PurpleChat *chat = <blist.PurpleChat *>node
86     cdef char *c_name = NULL
87
88     c_name = <char *> blist.c_purple_chat_get_name(chat)
89     if c_name == NULL:
90         name = None
91     else:
92         name = c_name
93
94     try:
95         callback(node.type, name)
96     except KeyError:
97         pass
98
99 cdef void __other_node_cb(blist.PurpleBlistNode *node, object callback):
100     try:
101         callback(node.type)
102     except KeyError:
103         pass
104
105 cdef void new_list (blist.PurpleBuddyList *list):
106     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "new_list\n")
107     try:
108         (<object>blist_cbs["new_list"])("new_list")
109     except KeyError:
110         pass
111
112 cdef void new_node (blist.PurpleBlistNode *node):
113     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "new_node\n")
114     try:
115         if node.type == blist.PURPLE_BLIST_GROUP_NODE:
116             __group_node_cb(node, blist_cbs["new_node"])
117         elif node.type == blist.PURPLE_BLIST_CONTACT_NODE:
118             __contact_node_cb(node, blist_cbs["new_node"])
119         elif node.type == blist.PURPLE_BLIST_BUDDY_NODE:
120             __buddy_node_cb(node, blist_cbs["new_node"])
121         elif node.type == blist.PURPLE_BLIST_CHAT_NODE:
122             __chat_node_cb(node, blist_cbs["new_node"])
123         elif node.type == blist.PURPLE_BLIST_OTHER_NODE:
124             __other_node_cb(node, blist_cbs["new_node"])
125     except KeyError:
126         pass
127
128 cdef void show (blist.PurpleBuddyList *list):
129     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "show\n")
130     try:
131         (<object>blist_cbs["show"])("show: TODO")
132     except KeyError:
133         pass
134
135 cdef void update (blist.PurpleBuddyList *list, blist.PurpleBlistNode *node):
136     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "update\n")
137     try:
138         if node.type == blist.PURPLE_BLIST_GROUP_NODE:
139             __group_node_cb(node, blist_cbs["update"])
140         elif node.type == blist.PURPLE_BLIST_CONTACT_NODE:
141             __contact_node_cb(node, blist_cbs["update"])
142         elif node.type == blist.PURPLE_BLIST_BUDDY_NODE:
143             __buddy_node_cb(node, blist_cbs["update"])
144         elif node.type == blist.PURPLE_BLIST_CHAT_NODE:
145             __chat_node_cb(node, blist_cbs["update"])
146         elif node.type == blist.PURPLE_BLIST_OTHER_NODE:
147             __other_node_cb(node, blist_cbs["update"])
148     except KeyError:
149         pass
150
151 cdef void remove (blist.PurpleBuddyList *list, blist.PurpleBlistNode *node):
152     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "remove\n")
153
154     try:
155         if node.type == blist.PURPLE_BLIST_GROUP_NODE:
156             __group_node_cb(node, blist_cbs["remove"])
157         elif node.type == blist.PURPLE_BLIST_CONTACT_NODE:
158             __contact_node_cb(node, blist_cbs["remove"])
159         elif node.type == blist.PURPLE_BLIST_BUDDY_NODE:
160             __buddy_node_cb(node, blist_cbs["remove"])
161         elif node.type == blist.PURPLE_BLIST_CHAT_NODE:
162             __chat_node_cb(node, blist_cbs["remove"])
163         elif node.type == blist.PURPLE_BLIST_OTHER_NODE:
164             __other_node_cb(node, blist_cbs["remove"])
165     except KeyError:
166         pass
167
168 cdef void destroy (blist.PurpleBuddyList *list):
169     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "destroy\n")
170     try:
171         (<object>blist_cbs["destroy"])("destroy: TODO")
172     except KeyError:
173         pass
174
175 cdef void set_visible (blist.PurpleBuddyList *list, glib.gboolean show):
176     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "set-visible\n")
177     try:
178         (<object>blist_cbs["set_visible"])("set-visible: TODO")
179     except KeyError:
180         pass
181
182 cdef void request_add_buddy (account.PurpleAccount *acc,
183                              const_char *username, const_char *group,
184                              const_char *alias):
185     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "request-add-buddy\n")
186     try:
187         (<object>blist_cbs["request-add-buddy"])("request-add-buddy: TODO")
188     except KeyError:
189         pass
190
191 cdef void request_add_chat (account.PurpleAccount *acc,
192                             blist.PurpleGroup *group, const_char *alias,
193                             const_char *name):
194     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "request_add_chat\n")
195     try:
196         (<object>blist_cbs["request-add-chat"])("request-add-chat: TODO")
197     except KeyError:
198         pass
199
200 cdef void request_add_group ():
201     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "request_add_group\n")
202     try:
203         (<object>blist_cbs["request-add-chat"])("request-add-group: TODO")
204     except KeyError:
205         pass