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