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