Fix compilation error using python2.7
[python-purple] / account_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 cdef extern from *:
21     ctypedef char const_char "const char"
22
23 account_cbs = {}
24
25 cdef account.PurpleAccountRequestAuthorizationCb c_request_authorize_authorize_cb = NULL
26 cdef account.PurpleAccountRequestAuthorizationCb c_request_authorize_deny_cb = NULL
27 cdef void *c_request_authorize_user_data = NULL
28
29 def call_authorize_cb():
30     global c_request_authorize_authorize_cb
31     global c_request_authorize_deny_cb
32     global c_request_authorize_user_data
33
34     if c_request_authorize_authorize_cb:
35         c_request_authorize_authorize_cb(c_request_authorize_user_data)
36     c_request_authorize_authorize_cb = NULL
37     c_request_authorize_deny_cb = NULL
38     c_request_authorize_user_data = NULL
39
40 def call_deny_cb():
41     global c_request_authorize_authorize_cb
42     global c_request_authorize_deny_cb
43     global c_request_authorize_user_data
44
45     if c_request_authorize_deny_cb:
46         c_request_authorize_deny_cb(c_request_authorize_user_data)
47     c_request_authorize_authorize_cb = NULL
48     c_request_authorize_deny_cb = NULL
49     c_request_authorize_user_data = NULL
50
51 cdef void notify_added(account.PurpleAccount *c_account, \
52         const_char *remote_user, const_char *id, const_char *alias, \
53         const_char *c_message):
54     """
55     A buddy who is already on this account's buddy list added this account to
56     their buddy list.
57     """
58     cdef connection.PurpleConnection *gc = \
59         account.purple_account_get_connection(c_account)
60
61     debug.purple_debug_info("account", "%s", "notify-added\n")
62
63     if alias:
64         remote_alias = <char *> alias
65     else:
66         remote_alias = None
67
68     if id:
69         username = <char *> id
70     elif connection.purple_connection_get_display_name(gc) != NULL:
71         username = connection.purple_connection_get_display_name(gc)
72     else:
73         username = account.purple_account_get_username(c_account)
74
75     protocol_id = account.purple_account_get_protocol_id(c_account)
76
77     if c_message:
78         message = <char *> c_message
79     else:
80         message = None
81
82     if "notify-added" in account_cbs:
83         (<object> account_cbs["notify-added"])( \
84             (<char *> remote_user, remote_alias), \
85             (username, protocol_id), message)
86
87 cdef void status_changed(account.PurpleAccount *c_account, \
88         status.PurpleStatus *c_status):
89     """
90     This account's status changed.
91     """
92     debug.purple_debug_info("account", "%s", "status-changed\n")
93
94     username = account.purple_account_get_username(c_account)
95     protocol_id = account.purple_account_get_protocol_id(c_account)
96
97     status_id = status.purple_status_get_id(c_status)
98     status_name = status.purple_status_get_name(c_status)
99
100     if "status-changed" in account_cbs:
101         (<object> account_cbs["status-changed"])( \
102             (username, protocol_id), status_id, status_name)
103
104 cdef void request_add(account.PurpleAccount *c_account, \
105         const_char *remote_user, const_char *id, const_char *alias, \
106         const_char *c_message):
107     """
108     Someone we don't have on our list added us; prompt to add them.
109     """
110     cdef connection.PurpleConnection *gc = \
111             account.purple_account_get_connection(c_account)
112
113     debug.purple_debug_info("account", "%s", "request-add\n")
114
115     if alias:
116         remote_alias = <char *> alias
117     else:
118         remote_alias = None
119
120     if id:
121         username = <char *> id
122     elif connection.purple_connection_get_display_name(gc) != NULL:
123         username = connection.purple_connection_get_display_name(gc)
124     else:
125         username = account.purple_account_get_username(c_account)
126
127     protocol_id = account.purple_account_get_protocol_id(c_account)
128
129     if c_message:
130         message = <char *> c_message
131     else:
132         message = None
133
134     if "request-add" in account_cbs:
135         (<object> account_cbs["request-add"])( \
136             (<char *> remote_user, remote_alias), \
137             (username, protocol_id), message)
138
139 cdef void *request_authorize(account.PurpleAccount *c_account, \
140         const_char *remote_user, const_char *id, const_char *alias, \
141         const_char *c_message, glib.gboolean on_list, \
142         account.PurpleAccountRequestAuthorizationCb authorize_cb, \
143         account.PurpleAccountRequestAuthorizationCb deny_cb, \
144         void *user_data):
145     """
146     Prompt for authorization when someone adds this account to their buddy
147     list. To authorize them to see this account's presence, call
148     authorize_cb(user_data) otherwise call deny_cb(user_data).
149     @return a UI-specific handle, as passed to #close_account_request.
150     """
151     cdef connection.PurpleConnection *gc = \
152             account.purple_account_get_connection(c_account)
153
154     debug.purple_debug_info("account", "%s", "request-authorize\n")
155
156     global c_request_authorize_authorize_cb
157     global c_request_authorize_deny_cb
158     global c_request_authorize_user_data
159
160     c_request_authorize_authorize_cb = authorize_cb
161     c_request_authorize_deny_cb = deny_cb
162     c_request_authorize_user_data = user_data
163
164     if alias:
165         remote_alias = <char *> alias
166     else:
167         remote_alias = None
168
169     if id:
170         username = <char *> id
171     elif connection.purple_connection_get_display_name(gc) != NULL:
172         username = connection.purple_connection_get_display_name(gc)
173     else:
174         username = account.purple_account_get_username(c_account)
175
176     protocol_id = account.purple_account_get_protocol_id(c_account)
177
178     if c_message:
179         message = <char *> c_message
180     else:
181         message = None
182
183     if "request-authorize" in account_cbs:
184         (<object> account_cbs["request-authorize"])( \
185             (<char *> remote_user, remote_alias), \
186             (username, protocol_id), \
187             message, on_list, \
188             call_authorize_cb, call_deny_cb)
189
190 cdef void close_account_request (void *ui_handle):
191     """
192     Close a pending request for authorization. ui_handle is a handle as
193     returned by request_authorize.
194     """
195     debug.purple_debug_info("account", "%s", "close-account-request\n")
196
197     request.purple_request_close(request.PURPLE_REQUEST_ACTION, ui_handle)
198
199     if "close-account-request" in account_cbs:
200         (<object> account_cbs["close-account-request"])()