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