Fix compilation error using python2.7
[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 cdef extern from *:
21     ctypedef char const_char "const char"
22
23 blist_cbs = {}
24
25 cdef void __group_node_cb(blist.PurpleBlistNode *node, object callback):
26     cdef blist.PurpleGroup *group = <blist.PurpleGroup *>node
27     cdef char *c_name = NULL
28
29     c_name = <char *> blist.purple_group_get_name(group)
30     if c_name == NULL:
31         name = None
32     else:
33         name = c_name
34
35     currentsize = blist.purple_blist_get_group_size(group, False)
36     totalsize = blist.purple_blist_get_group_size(group, True)
37     online = blist.purple_blist_get_group_online_count(group)
38
39     callback(node.type, name, totalsize, currentsize, online)
40
41 cdef void __contact_node_cb(blist.PurpleBlistNode *node, object callback):
42     cdef blist.PurpleContact *contact = <blist.PurpleContact *>node
43     cdef char *c_alias = NULL
44
45     c_alias = <char *> blist.purple_contact_get_alias(contact)
46     if c_alias == NULL:
47         alias = None
48     else:
49         alias = c_alias
50
51     callback(node.type, alias, contact.totalsize, contact.currentsize, \
52              contact.online)
53
54 cdef void __buddy_node_cb(blist.PurpleBlistNode *node, object callback):
55     cdef blist.PurpleBuddy *buddy = <blist.PurpleBuddy *>node
56     cdef char *c_name = NULL
57     cdef char *c_alias = NULL
58
59     c_name = <char *> blist.purple_buddy_get_name(buddy)
60     if c_name == NULL:
61         name = None
62     else:
63         name = c_name
64
65     c_alias = <char *> blist.purple_buddy_get_alias_only(buddy)
66     if c_alias == NULL:
67         alias = None
68     else:
69         alias = c_alias
70
71     callback(node.type, name, alias)
72
73 cdef void __chat_node_cb(blist.PurpleBlistNode *node, object callback):
74     cdef blist.PurpleChat *chat = <blist.PurpleChat *>node
75     cdef char *c_name = NULL
76
77     c_name = <char *> blist.purple_chat_get_name(chat)
78     if c_name == NULL:
79         name = None
80     else:
81         name = c_name
82
83     callback(node.type, name)
84
85 cdef void __other_node_cb(blist.PurpleBlistNode *node, object callback):
86     callback(node.type)
87
88 cdef void new_list(blist.PurpleBuddyList *list):
89     """
90     Sets UI-specific data on a buddy list.
91     """
92     debug.purple_debug_info("blist", "%s", "new-list\n")
93     if "new-list" in blist_cbs:
94         (<object> blist_cbs["new-list"])("new-list: TODO")
95
96 cdef void new_node(blist.PurpleBlistNode *node):
97     """
98     Sets UI-specific data on a node.
99     """
100     debug.purple_debug_info("blist", "%s", "new-node\n")
101     if "new-node" in blist_cbs:
102         if node.type == blist.PURPLE_BLIST_GROUP_NODE:
103             __group_node_cb(node, blist_cbs["new-node"])
104         elif node.type == blist.PURPLE_BLIST_CONTACT_NODE:
105             __contact_node_cb(node, blist_cbs["new-node"])
106         elif node.type == blist.PURPLE_BLIST_BUDDY_NODE:
107             __buddy_node_cb(node, blist_cbs["new-node"])
108         elif node.type == blist.PURPLE_BLIST_CHAT_NODE:
109             __chat_node_cb(node, blist_cbs["new-node"])
110         elif node.type == blist.PURPLE_BLIST_OTHER_NODE:
111             __other_node_cb(node, blist_cbs["new-node"])
112
113 cdef void show(blist.PurpleBuddyList *list):
114     """
115     The core will call this when it's finished doing its core stuff.
116     """
117     debug.purple_debug_info("blist", "%s", "show\n")
118     if "show" in blist_cbs:
119         (<object> blist_cbs["show"])("show: TODO")
120
121 cdef void update(blist.PurpleBuddyList *list, blist.PurpleBlistNode *node):
122     """
123     This will update a node in the buddy list.
124     """
125     debug.purple_debug_info("blist", "%s", "update\n")
126     if "update" in blist_cbs:
127         if node.type == blist.PURPLE_BLIST_GROUP_NODE:
128             __group_node_cb(node, blist_cbs["update"])
129         elif node.type == blist.PURPLE_BLIST_CONTACT_NODE:
130             __contact_node_cb(node, blist_cbs["update"])
131         elif node.type == blist.PURPLE_BLIST_BUDDY_NODE:
132             __buddy_node_cb(node, blist_cbs["update"])
133         elif node.type == blist.PURPLE_BLIST_CHAT_NODE:
134             __chat_node_cb(node, blist_cbs["update"])
135         elif node.type == blist.PURPLE_BLIST_OTHER_NODE:
136             __other_node_cb(node, blist_cbs["update"])
137
138 cdef void remove(blist.PurpleBuddyList *list, blist.PurpleBlistNode *node):
139     """
140     This removes a node from the list.
141     """
142     debug.purple_debug_info("blist", "%s", "remove\n")
143     if "remove" in blist_cbs:
144         if node.type == blist.PURPLE_BLIST_GROUP_NODE:
145             __group_node_cb(node, blist_cbs["remove"])
146         elif node.type == blist.PURPLE_BLIST_CONTACT_NODE:
147             __contact_node_cb(node, blist_cbs["remove"])
148         elif node.type == blist.PURPLE_BLIST_BUDDY_NODE:
149             __buddy_node_cb(node, blist_cbs["remove"])
150         elif node.type == blist.PURPLE_BLIST_CHAT_NODE:
151             __chat_node_cb(node, blist_cbs["remove"])
152         elif node.type == blist.PURPLE_BLIST_OTHER_NODE:
153             __other_node_cb(node, blist_cbs["remove"])
154
155 cdef void destroy(blist.PurpleBuddyList *list):
156     """
157     When the list gets destroyed, this gets called to destroy the UI.
158     """
159     debug.purple_debug_info("blist", "%s", "destroy\n")
160     if "destroy" in blist_cbs:
161         (<object> blist_cbs["destroy"])("destroy: TODO")
162
163 cdef void set_visible(blist.PurpleBuddyList *list, glib.gboolean show):
164     """
165     Hides or unhides the buddy list.
166     """
167     debug.purple_debug_info("blist", "%s", "set-visible\n")
168     if "set-visible" in blist_cbs:
169         (<object> blist_cbs["set-visible"])("set-visible: TODO")
170
171 cdef void request_add_buddy(account.PurpleAccount *c_account, \
172         const_char *c_buddy_username, const_char *c_buddy_group, \
173         const_char *c_buddy_alias):
174     """
175     Requests from the user information needed to add a buddy to the buddy
176     list.
177     """
178     debug.purple_debug_info("blist", "%s", "request-add-buddy\n")
179
180     username = account.purple_account_get_username(c_account)
181     protocol_id = account.purple_account_get_protocol_id(c_account)
182
183     if c_buddy_username:
184         buddy_username = <char *> c_buddy_username
185     else:
186         buddy_username = None
187
188     if c_buddy_group:
189         buddy_group = <char *> c_buddy_group
190     else:
191         buddy_group = None
192
193     if c_buddy_alias:
194         buddy_alias = <char *> c_buddy_alias
195     else:
196         buddy_alias = None
197
198     if "request-add-buddy" in blist_cbs:
199         (<object> blist_cbs["request-add-buddy"])( \
200             (username, protocol_id), buddy_username, buddy_group, buddy_alias)
201
202 cdef void request_add_chat(account.PurpleAccount *acc, \
203         blist.PurpleGroup *group, const_char *alias, const_char *name):
204     """
205     TODO
206     """
207     debug.purple_debug_info("blist", "%s", "request-add-chat\n")
208     if "request-add-chat" in blist_cbs:
209         (<object> blist_cbs["request-add-chat"])("request-add-chat: TODO")
210
211 cdef void request_add_group():
212     """
213     TODO
214     """
215     debug.purple_debug_info("blist", "%s", "request-add-group\n")
216     if "request-add-group" in blist_cbs:
217         (<object>blist_cbs["request-add-group"])("request-add-group: TODO")