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/>.
23 ctypedef char const_char "const char"
27 cdef account.PurpleAccountRequestAuthorizationCb c_request_authorize_authorize_cb = NULL
28 cdef account.PurpleAccountRequestAuthorizationCb c_request_authorize_deny_cb = NULL
29 cdef void *c_request_authorize_user_data = NULL
31 def call_authorize_cb():
32 global c_request_authorize_authorize_cb
33 global c_request_authorize_deny_cb
34 global c_request_authorize_user_data
36 if c_request_authorize_authorize_cb:
37 c_request_authorize_authorize_cb(c_request_authorize_user_data)
38 c_request_authorize_authorize_cb = NULL
39 c_request_authorize_deny_cb = NULL
40 c_request_authorize_user_data = NULL
43 global c_request_authorize_authorize_cb
44 global c_request_authorize_deny_cb
45 global c_request_authorize_user_data
47 if c_request_authorize_deny_cb:
48 c_request_authorize_deny_cb(c_request_authorize_user_data)
49 c_request_authorize_authorize_cb = NULL
50 c_request_authorize_deny_cb = NULL
51 c_request_authorize_user_data = NULL
53 cdef void notify_added(account.PurpleAccount *c_account, \
54 const_char *remote_user, const_char *id, const_char *alias, \
55 const_char *c_message):
57 A buddy who is already on this account's buddy list added this account to
60 cdef connection.PurpleConnection *gc = \
61 account.purple_account_get_connection(c_account)
63 debug.purple_debug_info("account", "%s", "notify-added\n")
66 remote_alias = <char *> alias
71 username = <char *> id
72 elif connection.purple_connection_get_display_name(gc) != NULL:
73 username = connection.purple_connection_get_display_name(gc)
75 username = account.purple_account_get_username(c_account)
77 protocol_id = account.purple_account_get_protocol_id(c_account)
80 message = <char *> c_message
84 if "notify-added" in account_cbs:
85 (<object> account_cbs["notify-added"])( \
86 (<char *> remote_user, remote_alias), \
87 (username, protocol_id), message)
89 cdef void status_changed(account.PurpleAccount *c_account, \
90 status.PurpleStatus *c_status):
92 This account's status changed.
94 debug.purple_debug_info("account", "%s", "status-changed\n")
96 username = account.purple_account_get_username(c_account)
97 protocol_id = account.purple_account_get_protocol_id(c_account)
99 status_id = status.purple_status_get_id(c_status)
100 status_name = status.purple_status_get_name(c_status)
102 if "status-changed" in account_cbs:
103 (<object> account_cbs["status-changed"])( \
104 (username, protocol_id), status_id, status_name)
106 cdef void request_add(account.PurpleAccount *c_account, \
107 const_char *remote_user, const_char *id, const_char *alias, \
108 const_char *c_message):
110 Someone we don't have on our list added us; prompt to add them.
112 cdef connection.PurpleConnection *gc = \
113 account.purple_account_get_connection(c_account)
115 debug.purple_debug_info("account", "%s", "request-add\n")
118 remote_alias = <char *> alias
123 username = <char *> id
124 elif connection.purple_connection_get_display_name(gc) != NULL:
125 username = connection.purple_connection_get_display_name(gc)
127 username = account.purple_account_get_username(c_account)
129 protocol_id = account.purple_account_get_protocol_id(c_account)
132 message = <char *> c_message
136 if "request-add" in account_cbs:
137 (<object> account_cbs["request-add"])( \
138 (<char *> remote_user, remote_alias), \
139 (username, protocol_id), message)
141 cdef void *request_authorize(account.PurpleAccount *c_account, \
142 const_char *remote_user, const_char *id, const_char *alias, \
143 const_char *c_message, glib.gboolean on_list, \
144 account.PurpleAccountRequestAuthorizationCb authorize_cb, \
145 account.PurpleAccountRequestAuthorizationCb deny_cb, \
148 Prompt for authorization when someone adds this account to their buddy
149 list. To authorize them to see this account's presence, call
150 authorize_cb(user_data) otherwise call deny_cb(user_data).
151 @return a UI-specific handle, as passed to #close_account_request.
153 cdef connection.PurpleConnection *gc = \
154 account.purple_account_get_connection(c_account)
156 debug.purple_debug_info("account", "%s", "request-authorize\n")
158 global c_request_authorize_authorize_cb
159 global c_request_authorize_deny_cb
160 global c_request_authorize_user_data
162 c_request_authorize_authorize_cb = authorize_cb
163 c_request_authorize_deny_cb = deny_cb
164 c_request_authorize_user_data = user_data
167 remote_alias = <char *> alias
172 username = <char *> id
173 elif connection.purple_connection_get_display_name(gc) != NULL:
174 username = connection.purple_connection_get_display_name(gc)
176 username = account.purple_account_get_username(c_account)
178 protocol_id = account.purple_account_get_protocol_id(c_account)
181 message = <char *> c_message
185 if "request-authorize" in account_cbs:
186 (<object> account_cbs["request-authorize"])( \
187 (<char *> remote_user, remote_alias), \
188 (username, protocol_id), \
190 call_authorize_cb, call_deny_cb)
192 cdef void close_account_request (void *ui_handle):
194 Close a pending request for authorization. ui_handle is a handle as
195 returned by request_authorize.
197 debug.purple_debug_info("account", "%s", "close-account-request\n")
199 request.purple_request_close(request.PURPLE_REQUEST_ACTION, ui_handle)
201 if "close-account-request" in account_cbs:
202 (<object> account_cbs["close-account-request"])()