Removed unused/duplicated/deprecated includes.
[python-purple] / signal_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 signal_cbs = {}
21
22 cdef extern from *:
23     ctypedef char const_gchar "const gchar"
24
25 cdef void signal_signed_on_cb(connection.PurpleConnection *gc, \
26         glib.gpointer null):
27     """
28     Emitted when a connection has signed on.
29     @params gc  The connection that has signed on.
30     """
31     cdef account.PurpleAccount *acc = connection.purple_connection_get_account(gc)
32     cdef char *c_username = NULL
33     cdef char *c_protocol_id = NULL
34
35     c_username = <char *> account.purple_account_get_username(acc)
36     if c_username == NULL:
37         username = None
38     else:
39         username = c_username
40
41     c_protocol_id = <char *> account.purple_account_get_protocol_id(acc)
42     if c_protocol_id == NULL:
43         protocol_id = None
44     else:
45         protocol_id = c_protocol_id
46
47     if "signed-on" in signal_cbs:
48         (<object> signal_cbs["signed-on"])(username, protocol_id)
49
50 cdef void signal_signed_off_cb(connection.PurpleConnection *gc, \
51         glib.gpointer null):
52     """
53     Emitted when a connection has signed off.
54     @params gc  The connection that has signed off.
55     """
56     cdef account.PurpleAccount *acc = connection.purple_connection_get_account(gc)
57     cdef char *c_username = NULL
58     cdef char *c_protocol_id = NULL
59
60     c_username = <char *> account.purple_account_get_username(acc)
61     if c_username == NULL:
62         username = None
63     else:
64         username = c_username
65
66     c_protocol_id = <char *> account.purple_account_get_protocol_id(acc)
67     if c_protocol_id == NULL:
68         protocol_id = None
69     else:
70         protocol_id = c_protocol_id
71
72     if "signed-off" in signal_cbs:
73         (<object> signal_cbs["signed-off"])(username, protocol_id)
74
75 cdef void signal_connection_error_cb(connection.PurpleConnection *gc, \
76         connection.PurpleConnectionError err, const_gchar *c_desc):
77     """
78     Emitted when a connection error occurs, before signed-off.
79     @params gc   The connection on which the error has occured
80     @params err  The error that occured
81     @params desc A description of the error, giving more information
82     """
83     cdef account.PurpleAccount *acc = connection.purple_connection_get_account(gc)
84     cdef char *c_username = NULL
85     cdef char *c_protocol_id = NULL
86
87     c_username = <char *> account.purple_account_get_username(acc)
88     if c_username:
89         username = <char *> c_username
90     else:
91         username = None
92
93     c_protocol_id = <char *> account.purple_account_get_protocol_id(acc)
94     if c_protocol_id:
95         protocol_id = <char *> c_protocol_id
96     else:
97         protocol_id = None
98
99     short_desc = {
100         0: "Network error",
101         1: "Invalid username",
102         2: "Authentication failed",
103         3: "Authentication impossible",
104         4: "No SSL support",
105         5: "Encryption error",
106         6: "Name in use",
107         7: "Invalid settings",
108         8: "SSL certificate not provided",
109         9: "SSL certificate untrusted",
110         10: "SSL certificate expired",
111         11: "SSL certificate not activated",
112         12: "SSL certificate hostname mismatch",
113         13: "SSL certificate fingerprint mismatch",
114         14: "SSL certificate self signed",
115         15: "SSL certificate other error",
116         16: "Other error" }[<int> err]
117
118     if c_desc:
119         desc = str(<char *> c_desc)
120     else:
121         desc = None
122
123     if "connection-error" in signal_cbs:
124         (<object> signal_cbs["connection-error"])(username, protocol_id, \
125                 short_desc, desc)
126
127 cdef void signal_buddy_signed_on_cb(blist.PurpleBuddy *buddy):
128     """
129     Emitted when a buddy on your buddy list signs on.
130     @params buddy  The buddy that signed on.
131     """
132     cdef char *c_name = NULL
133     cdef char *c_alias = NULL
134
135     c_name = <char *> blist.purple_buddy_get_name(buddy)
136     if c_name == NULL:
137         name = None
138     else:
139         name = c_name
140
141     c_alias = <char *> blist.purple_buddy_get_alias_only(buddy)
142     if c_alias == NULL:
143         alias = None
144     else:
145         alias = c_alias
146
147     if "buddy-signed-on" in signal_cbs:
148         (<object> signal_cbs["buddy-signed-on"])(name, alias)
149
150 cdef void signal_buddy_signed_off_cb(blist.PurpleBuddy *buddy):
151     """
152     Emitted when a buddy on your buddy list signs off.
153     @params buddy  The buddy that signed off.
154     """
155     cdef char *c_name = NULL
156     cdef char *c_alias = NULL
157
158     c_name = <char *> blist.purple_buddy_get_name(buddy)
159     if c_name == NULL:
160         name = None
161     else:
162         name = c_name
163
164     c_alias = <char *> blist.purple_buddy_get_alias_only(buddy)
165     if c_alias == NULL:
166         alias = None
167     else:
168         alias = c_alias
169
170     if "buddy-signed-off" in signal_cbs:
171         (<object> signal_cbs["buddy-signed-off"])(name, alias)
172
173 cdef glib.gboolean signal_receiving_im_msg_cb(account.PurpleAccount *account, \
174         char **sender, char **message, conversation.PurpleConversation *conv, \
175         conversation.PurpleMessageFlags *flags):
176     """
177     Emitted when an IM is received. The callback can replace the name of the
178     sender, the message, or the flags by modifying the pointer to the strings
179     and integer. This can also be used to cancel a message by returning TRUE.
180     @note Make sure to free *sender and *message before you replace them!
181     @returns TRUE if the message should be canceled, or FALSE otherwise.
182     @params account  The account the message was received on.
183     @params sender   A pointer to the username of the sender.
184     @params message  A pointer to the message that was sent.
185     @params conv     The IM conversation.
186     @params flags    A pointer to the IM message flags.
187     """
188     cdef blist.PurpleBuddy *buddy = blist.purple_find_buddy(account, sender[0])
189     cdef char *c_alias = NULL
190
191     c_alias = <char *> blist.purple_buddy_get_alias_only(buddy)
192     if c_alias == NULL:
193         alias = None
194     else:
195         alias = c_alias
196
197     stripped = util.purple_markup_strip_html(message[0])
198
199     if "receiving-im-msg" in signal_cbs:
200         return (<object> signal_cbs["receiving-im-msg"])(sender[0], alias, stripped)
201
202 cdef void jabber_receiving_xmlnode_cb(connection.PurpleConnection *gc, \
203         xmlnode.xmlnode **packet, glib.gpointer null):
204     """
205     Emitted when jabber receives a XML node.
206     """
207     message = xmlnode.xmlnode_to_str(packet[0], NULL)
208
209     if "jabber-receiving-xmlnode" in signal_cbs:
210         (<object> signal_cbs["jabber-receiving-xmlnode"])(message)