Updated changes made on python-purple branch.
[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     cdef account.PurpleAccount *acc = connection.c_purple_connection_get_account(gc)
27     cdef char *c_username = NULL
28     cdef char *c_protocol_id = NULL
29
30     c_username = <char *> account.c_purple_account_get_username(acc)
31     if c_username == NULL:
32         username = None
33     else:
34         username = c_username
35
36     c_protocol_id = <char *> account.c_purple_account_get_protocol_id(acc)
37     if c_protocol_id == NULL:
38         protocol_id = None
39     else:
40         protocol_id = c_protocol_id
41
42     try:
43         (<object> signal_cbs["signed-on"])(username, protocol_id)
44     except KeyError:
45         pass
46
47 cdef void signal_signed_off_cb (connection.PurpleConnection *gc, \
48                                glib.gpointer null):
49     cdef account.PurpleAccount *acc = connection.c_purple_connection_get_account(gc)
50     cdef char *c_username = NULL
51     cdef char *c_protocol_id = NULL
52
53     c_username = <char *> account.c_purple_account_get_username(acc)
54     if c_username == NULL:
55         username = None
56     else:
57         username = c_username
58
59     c_protocol_id = <char *> account.c_purple_account_get_protocol_id(acc)
60     if c_protocol_id == NULL:
61         protocol_id = None
62     else:
63         protocol_id = c_protocol_id
64
65     try:
66         (<object> signal_cbs["signed-off"])(username, protocol_id)
67     except KeyError:
68         pass
69
70 cdef void signal_connection_error_cb (connection.PurpleConnection *gc, \
71         connection.PurpleConnectionError err, char *c_desc):
72
73     short_desc = {
74         0: "Network error",
75         1: "Invalid username",
76         2: "Authentication failed",
77         3: "Authentication impossible",
78         4: "No SSL support",
79         5: "Encryption error",
80         6: "Name in use",
81         7: "Invalid settings",
82         8: "SSL certificate not provided",
83         9: "SSL certificate untrusted",
84         10: "SSL certificate expired",
85         11: "SSL certificate not activated",
86         12: "SSL certificate hostname mismatch",
87         13: "SSL certificate fingerprint mismatch",
88         14: "SSL certificate self signed",
89         15: "SSL certificate other error",
90         16: "Other error" }[<int>err]
91
92     if c_desc == NULL:
93         desc = None
94     else:
95         desc = c_desc
96
97     try:
98         (<object> signal_cbs["connection-error"])(short_desc, desc)
99     except KeyError:
100         pass
101
102 cdef void signal_buddy_signed_on_cb (blist.PurpleBuddy *buddy):
103     cdef char *c_name = NULL
104     cdef char *c_alias = NULL
105
106     c_name = <char *> blist.c_purple_buddy_get_name(buddy)
107     if c_name == NULL:
108         name = None
109     else:
110         name = c_name
111
112     c_alias = <char *> blist.c_purple_buddy_get_alias_only(buddy)
113     if c_alias == NULL:
114         alias = None
115     else:
116         alias = c_alias
117
118     try:
119         (<object> signal_cbs["buddy-signed-on"])(name, alias)
120     except KeyError:
121         pass
122
123 cdef void signal_buddy_signed_off_cb (blist.PurpleBuddy *buddy):
124     cdef char *c_name = NULL
125     cdef char *c_alias = NULL
126
127     c_name = <char *> blist.c_purple_buddy_get_name(buddy)
128     if c_name == NULL:
129         name = None
130     else:
131         name = c_name
132
133     c_alias = <char *> blist.c_purple_buddy_get_alias_only(buddy)
134     if c_alias == NULL:
135         alias = None
136     else:
137         alias = c_alias
138
139     try:
140         (<object> signal_cbs["buddy-signed-off"])(name, alias)
141     except KeyError:
142         pass
143
144 cdef glib.gboolean signal_receiving_im_msg_cb (account.PurpleAccount *account,
145         char **sender, char **message, conversation.PurpleConversation *conv,
146         conversation.PurpleMessageFlags *flags):
147     cdef blist.PurpleBuddy *buddy = blist.c_purple_find_buddy(account, sender[0])
148     cdef char *c_alias = NULL
149
150     c_alias = <char *> blist.c_purple_buddy_get_alias_only(buddy)
151     if c_alias == NULL:
152         alias = None
153     else:
154         alias = c_alias
155
156     stripped = util.c_purple_markup_strip_html(message[0])
157
158     try:
159         return (<object> signal_cbs["receiving-im-msg"])(sender[0], alias, stripped)
160     except KeyError:
161         return False
162
163 cdef void jabber_receiving_xmlnode_cb (connection.PurpleConnection *gc,
164         xmlnode.xmlnode **packet, glib.gpointer null):
165
166     message = xmlnode.xmlnode_to_str(packet[0], NULL)
167
168     try:
169         (<object> signal_cbs["jabber-receiving-xmlnode"])(message)
170     except KeyError:
171         pass