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