2 # Copyright (c) 2008 INdT - Instituto Nokia de Tecnologia
4 # This file is part of python-purple.
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.
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.
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/>.
21 ctypedef char const_char "const char"
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
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
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
41 global c_request_authorize_authorize_cb
42 global c_request_authorize_deny_cb
43 global c_request_authorize_user_data
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
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):
55 A buddy who is already on this account's buddy list added this account to
58 cdef connection.PurpleConnection *gc = \
59 account.purple_account_get_connection(c_account)
61 debug.purple_debug_info("account", "%s", "notify-added\n")
64 remote_alias = <char *> alias
69 username = <char *> id
70 elif connection.purple_connection_get_display_name(gc) != NULL:
71 username = connection.purple_connection_get_display_name(gc)
73 username = account.purple_account_get_username(c_account)
75 protocol_id = account.purple_account_get_protocol_id(c_account)
78 message = <char *> c_message
82 if "notify-added" in account_cbs:
83 (<object> account_cbs["notify-added"])( \
84 (<char *> remote_user, remote_alias), \
85 (username, protocol_id), message)
87 cdef void status_changed(account.PurpleAccount *c_account, \
88 status.PurpleStatus *c_status):
90 This account's status changed.
92 debug.purple_debug_info("account", "%s", "status-changed\n")
94 username = account.purple_account_get_username(c_account)
95 protocol_id = account.purple_account_get_protocol_id(c_account)
97 status_id = status.purple_status_get_id(c_status)
98 status_name = status.purple_status_get_name(c_status)
100 if "status-changed" in account_cbs:
101 (<object> account_cbs["status-changed"])( \
102 (username, protocol_id), status_id, status_name)
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):
108 Someone we don't have on our list added us; prompt to add them.
110 cdef connection.PurpleConnection *gc = \
111 account.purple_account_get_connection(c_account)
113 debug.purple_debug_info("account", "%s", "request-add\n")
116 remote_alias = <char *> alias
121 username = <char *> id
122 elif connection.purple_connection_get_display_name(gc) != NULL:
123 username = connection.purple_connection_get_display_name(gc)
125 username = account.purple_account_get_username(c_account)
127 protocol_id = account.purple_account_get_protocol_id(c_account)
130 message = <char *> c_message
134 if "request-add" in account_cbs:
135 (<object> account_cbs["request-add"])( \
136 (<char *> remote_user, remote_alias), \
137 (username, protocol_id), message)
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, \
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.
151 cdef connection.PurpleConnection *gc = \
152 account.purple_account_get_connection(c_account)
154 debug.purple_debug_info("account", "%s", "request-authorize\n")
156 global c_request_authorize_authorize_cb
157 global c_request_authorize_deny_cb
158 global c_request_authorize_user_data
160 c_request_authorize_authorize_cb = authorize_cb
161 c_request_authorize_deny_cb = deny_cb
162 c_request_authorize_user_data = user_data
165 remote_alias = <char *> alias
170 username = <char *> id
171 elif connection.purple_connection_get_display_name(gc) != NULL:
172 username = connection.purple_connection_get_display_name(gc)
174 username = account.purple_account_get_username(c_account)
176 protocol_id = account.purple_account_get_protocol_id(c_account)
179 message = <char *> c_message
183 if "request-authorize" in account_cbs:
184 (<object> account_cbs["request-authorize"])( \
185 (<char *> remote_user, remote_alias), \
186 (username, protocol_id), \
188 call_authorize_cb, call_deny_cb)
190 cdef void close_account_request (void *ui_handle):
192 Close a pending request for authorization. ui_handle is a handle as
193 returned by request_authorize.
195 debug.purple_debug_info("account", "%s", "close-account-request\n")
197 request.purple_request_close(request.PURPLE_REQUEST_ACTION, ui_handle)
199 if "close-account-request" in account_cbs:
200 (<object> account_cbs["close-account-request"])()