Added initial Debian packaging support.
[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_info("blist", "%s", "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_info("blist", "%s", "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_info("blist", "%s", "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_info("blist", "%s", "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_info("blist", "%s", "remove\n")
153     try:
154         if node.type == blist.PURPLE_BLIST_GROUP_NODE:
155             __group_node_cb(node, blist_cbs["remove"])
156         elif node.type == blist.PURPLE_BLIST_CONTACT_NODE:
157             __contact_node_cb(node, blist_cbs["remove"])
158         elif node.type == blist.PURPLE_BLIST_BUDDY_NODE:
159             __buddy_node_cb(node, blist_cbs["remove"])
160         elif node.type == blist.PURPLE_BLIST_CHAT_NODE:
161             __chat_node_cb(node, blist_cbs["remove"])
162         elif node.type == blist.PURPLE_BLIST_OTHER_NODE:
163             __other_node_cb(node, blist_cbs["remove"])
164     except KeyError:
165         pass
166
167 cdef void destroy (blist.PurpleBuddyList *list):
168     debug.c_purple_debug_info("blist", "%s", "destroy\n")
169     try:
170         (<object>blist_cbs["destroy"])("destroy: TODO")
171     except KeyError:
172         pass
173
174 cdef void set_visible (blist.PurpleBuddyList *list, glib.gboolean show):
175     debug.c_purple_debug_info("blist", "%s", "set-visible\n")
176     try:
177         (<object>blist_cbs["set_visible"])("set-visible: TODO")
178     except KeyError:
179         pass
180
181 cdef void request_add_buddy (account.PurpleAccount *acc,
182                              const_char *username, const_char *group,
183                              const_char *alias):
184     debug.c_purple_debug_info("blist", "%s", "request-add-buddy\n")
185     try:
186         (<object>blist_cbs["request-add-buddy"])("request-add-buddy: TODO")
187     except KeyError:
188         pass
189
190 cdef void request_add_chat (account.PurpleAccount *acc,
191                             blist.PurpleGroup *group, const_char *alias,
192                             const_char *name):
193     debug.c_purple_debug_info("blist", "%s", "request_add_chat\n")
194     try:
195         (<object>blist_cbs["request-add-chat"])("request-add-chat: TODO")
196     except KeyError:
197         pass
198
199 cdef void request_add_group ():
200     debug.c_purple_debug_info("blist", "%s", "request_add_group\n")
201     try:
202         (<object>blist_cbs["request-add-chat"])("request-add-group: TODO")
203     except KeyError:
204         pass