Deleting plugin.pyx
[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 = None
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 = None
48
49     try:
50         callback(node.type, alias, contact.totalsize, contact.currentsize, \
51                  contact.online)
52     except KeyError:
53         pass
54
55 cdef void __buddy_node_cb(blist.PurpleBlistNode *node, object callback):
56     cdef blist.PurpleBuddy *buddy = <blist.PurpleBuddy *>node
57
58     if buddy.server_alias:
59         alias = buddy.server_alias
60     elif buddy.alias:
61         alias = buddy.alias
62     else:
63         alias = None
64
65     if buddy.name:
66         name = buddy.name
67     else:
68         name = None
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
78     if chat.alias:
79         alias = chat.alias
80     else:
81         alias = None
82
83     try:
84         callback(node.type, alias)
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
104     try:
105         if node.type == blist.PURPLE_BLIST_GROUP_NODE:
106             __group_node_cb(node, blist_cbs["new_node"])
107         elif node.type == blist.PURPLE_BLIST_CONTACT_NODE:
108             __contact_node_cb(node, blist_cbs["new_node"])
109         elif node.type == blist.PURPLE_BLIST_BUDDY_NODE:
110             __buddy_node_cb(node, blist_cbs["new_node"])
111         elif node.type == blist.PURPLE_BLIST_CHAT_NODE:
112             __chat_node_cb(node, blist_cbs["new_node"])
113         elif node.type == blist.PURPLE_BLIST_OTHER_NODE:
114             __other_node_cb(node, blist_cbs["new_node"])
115         else:
116             (<object>blist_cbs["new_node"])(node.type)
117     except KeyError:
118         pass
119
120 cdef void show (blist.PurpleBuddyList *list):
121     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "show\n")
122     try:
123         (<object>blist_cbs["show"])("show")
124     except KeyError:
125         pass
126
127 cdef void update (blist.PurpleBuddyList *list, blist.PurpleBlistNode *node):
128     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "update\n")
129
130     try:
131         if node.type == blist.PURPLE_BLIST_GROUP_NODE:
132             __group_node_cb(node, blist_cbs["update"])
133         elif node.type == blist.PURPLE_BLIST_CONTACT_NODE:
134             __contact_node_cb(node, blist_cbs["update"])
135         elif node.type == blist.PURPLE_BLIST_BUDDY_NODE:
136             __buddy_node_cb(node, blist_cbs["update"])
137         elif node.type == blist.PURPLE_BLIST_CHAT_NODE:
138             __chat_node_cb(node, blist_cbs["update"])
139         elif node.type == blist.PURPLE_BLIST_OTHER_NODE:
140             __other_node_cb(node, blist_cbs["update"])
141         else:
142             (<object>blist_cbs["update"])(node.type)
143     except KeyError:
144         pass
145
146 cdef void remove (blist.PurpleBuddyList *list, blist.PurpleBlistNode *node):
147     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "remove\n")
148
149     try:
150         if node.type == blist.PURPLE_BLIST_GROUP_NODE:
151             __group_node_cb(node, blist_cbs["remove"])
152         elif node.type == blist.PURPLE_BLIST_CONTACT_NODE:
153             __contact_node_cb(node, blist_cbs["remove"])
154         elif node.type == blist.PURPLE_BLIST_BUDDY_NODE:
155             __buddy_node_cb(node, blist_cbs["remove"])
156         elif node.type == blist.PURPLE_BLIST_CHAT_NODE:
157             __chat_node_cb(node, blist_cbs["remove"])
158         elif node.type == blist.PURPLE_BLIST_OTHER_NODE:
159             __other_node_cb(node, blist_cbs["remove"])
160         else:
161             (<object>blist_cbs["remove"])(node.type)
162     except KeyError:
163         pass
164
165 cdef void destroy (blist.PurpleBuddyList *list):
166     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "destroy\n")
167     try:
168         (<object>blist_cbs["destroy"])("destroy")
169     except KeyError:
170         pass
171
172 cdef void set_visible (blist.PurpleBuddyList *list, glib.gboolean show):
173     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "set_visible\n")
174     try:
175         (<object>blist_cbs["set_visible"])("set_visible")
176     except KeyError:
177         pass
178
179 cdef void request_add_buddy (account.PurpleAccount *account,
180                              const_char *username, const_char *group,
181                              const_char *alias):
182     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "request_add_buddy\n")
183     try:
184         (<object>blist_cbs["request_add_buddy"])("request_add_buddy")
185     except KeyError:
186         pass
187
188 cdef void request_add_chat (account.PurpleAccount *account,
189                             blist.PurpleGroup *group, const_char *alias,
190                             const_char *name):
191     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "request_add_chat\n")
192     try:
193         (<object>blist_cbs["request_add_chat"])("request_add_chat")
194     except KeyError:
195         pass
196
197 cdef void request_add_group ():
198     debug.c_purple_debug(debug.PURPLE_DEBUG_INFO, "blist", "request_add_group\n")
199     try:
200         (<object>blist_cbs["request_add_chat"])("request_add_group")
201     except KeyError:
202         pass