14a7434f1af712d04e5763ad80b655f046f9f6fc
[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_buddy_signed_on_cb (blist.PurpleBuddy *buddy):
71     cdef char *c_name = NULL
72     cdef char *c_alias = NULL
73
74     c_name = <char *> blist.c_purple_buddy_get_name(buddy)
75     if c_name == NULL:
76         name = None
77     else:
78         name = c_name
79
80     c_alias = <char *> blist.c_purple_buddy_get_alias_only(buddy)
81     if c_alias == NULL:
82         alias = None
83     else:
84         alias = c_alias
85
86     try:
87         (<object> signal_cbs["buddy-signed-on"])(name, alias)
88     except KeyError:
89         pass
90
91 cdef void signal_buddy_signed_off_cb (blist.PurpleBuddy *buddy):
92     cdef char *c_name = NULL
93     cdef char *c_alias = NULL
94
95     c_name = <char *> blist.c_purple_buddy_get_name(buddy)
96     if c_name == NULL:
97         name = None
98     else:
99         name = c_name
100
101     c_alias = <char *> blist.c_purple_buddy_get_alias_only(buddy)
102     if c_alias == NULL:
103         alias = None
104     else:
105         alias = c_alias
106
107     try:
108         (<object> signal_cbs["buddy-signed-off"])(name, alias)
109     except KeyError:
110         pass
111
112 cdef glib.gboolean signal_receiving_im_msg_cb (account.PurpleAccount *account,
113         char **sender, char **message, conversation.PurpleConversation *conv,
114         conversation.PurpleMessageFlags *flags):
115     cdef blist.PurpleBuddy *buddy = blist.c_purple_find_buddy(account, sender[0])
116     cdef char *c_alias = NULL
117
118     c_alias = <char *> blist.c_purple_buddy_get_alias_only(buddy)
119     if c_alias == NULL:
120         alias = None
121     else:
122         alias = c_alias
123
124     stripped = util.c_purple_markup_strip_html(message[0])
125
126     try:
127         return (<object> signal_cbs["receiving-im-msg"])(sender[0], alias, stripped)
128     except KeyError:
129         return False
130
131 cdef void jabber_receiving_xmlnode_cb (connection.PurpleConnection *gc,
132         xmlnode.xmlnode **packet, glib.gpointer null):
133
134     message = xmlnode.xmlnode_to_str(packet[0], NULL)
135
136     try:
137         (<object> signal_cbs["jabber-receiving-xmlnode"])(message)
138     except KeyError:
139         pass