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