Fixes for cython 0.11-2.
[python-purple] / conversation_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     ctypedef glib.guchar const_guchar "const guchar"
25     ctypedef long int time_t
26
27 conversation_cbs = {}
28
29 cdef void create_conversation(conversation.PurpleConversation *conv):
30     """
31     Called when a conv is created (but before the conversation-created
32     signal is emitted).
33     """
34     debug.purple_debug_info("conversation", "%s", "create-conversation\n")
35     cdef char *c_name = NULL
36
37     c_name = <char *> conversation.purple_conversation_get_name(conv)
38     if c_name == NULL:
39         name = None
40     else:
41         name = c_name
42
43     type = conversation.purple_conversation_get_type(conv)
44
45     if "create-conversation" in conversation_cbs:
46         (<object> conversation_cbs["create-conversation"])(name, type)
47
48 cdef void destroy_conversation(conversation.PurpleConversation *conv):
49     """
50     Called just before a conv is freed.
51     """
52     debug.purple_debug_info("conversation", "%s", "destroy-conversation\n")
53     if "destroy-conversation" in conversation_cbs:
54         (<object> conversation_cbs["destroy-conversation"]) \
55             ("destroy-conversation: TODO")
56
57 cdef void write_chat(conversation.PurpleConversation *conv, const_char *who, \
58         const_char *message, conversation.PurpleMessageFlags flags, \
59         time_t mtime):
60     """
61     Write a message to a chat. If this field is NULL, libpurple will fall
62     back to using write_conv.
63     @see purple_conv_chat_write()
64     """
65     debug.purple_debug_info("conversation", "%s", "write-chat\n")
66     if "write-chat" in conversation_cbs:
67         (<object> conversation_cbs["write-chat"])("write-chat: TODO")
68
69 cdef void write_im(conversation.PurpleConversation *conv, const_char *who, \
70         const_char *c_message, conversation.PurpleMessageFlags flags, \
71         time_t mtime):
72     """
73     Write a message to an IM conversation. If this field is NULL, libpurple
74     will fall back to using write_conv.
75     @see purple_conv_im_write()
76     """
77     debug.purple_debug_info("conversation", "%s", "write-im\n")
78     cdef account.PurpleAccount *acc = \
79         conversation.purple_conversation_get_account(conv)
80     cdef blist.PurpleBuddy *buddy = NULL
81     cdef char *c_username = NULL
82     cdef char *c_sender_alias = NULL
83
84     c_username = <char *> account.purple_account_get_username(acc)
85     if c_username:
86         username = c_username
87     else:
88         username = None
89
90     if who == NULL:
91         who = conversation.purple_conversation_get_name(conv)
92
93     sender = <char *> who
94     buddy = blist.purple_find_buddy(acc, <char *> who)
95     if buddy:
96         c_sender_alias = <char *> blist.purple_buddy_get_alias_only(buddy)
97
98     if c_sender_alias:
99         sender_alias = unicode(c_sender_alias, 'utf-8')
100     else:
101         sender_alias = None
102
103     if c_message:
104         message = <char *> c_message
105     else:
106         message = None
107
108     # FIXME: Maybe we need add more purple flags in the future
109     if (<int>flags & conversation.PURPLE_MESSAGE_SEND):
110         flag = "SEND"
111     else:
112         flag = "RECV"
113
114     if "write-im" in conversation_cbs:
115         (<object> conversation_cbs["write-im"])(username, sender, \
116             sender_alias, message, flag)
117
118 cdef void write_conv(conversation.PurpleConversation *conv, const_char *name, \
119         const_char *alias, const_char *message, \
120         conversation.PurpleMessageFlags flags, time_t mtime):
121     """
122     Write a message to a conversation. This is used rather than the chat- or
123     im-specific ops for errors, system messages (such as "x is now known as
124     y"), and as the fallback if write_im and write_chat are not implemented.
125     It should be implemented, or the UI will miss conversation error messages
126     and your users will hate you.
127     @see purple_conversation_write()
128     """
129     debug.purple_debug_info("conversation", "%s", "write-conv\n")
130     if "write-conv" in conversation_cbs:
131         (<object> conversation_cbs["write-conv"])("write-conv: TODO")
132
133 cdef void chat_add_users(conversation.PurpleConversation *conv, \
134         glib.GList *cbuddies, glib.gboolean new_arrivals):
135     """
136     Add cbuddies to a chat.
137     @param cbuddies  A GList of PurpleConvChatBuddy structs.
138     @param new_arrivals  Wheter join notices should be shown.
139                          (Join notices are actually written to the
140                          conversation by purple_conv_chat_add_users().)
141     @see purple_conv_chat_add_users()
142     """
143     debug.purple_debug_info("conversation", "%s", "chat-add-users\n")
144     if "chat-add-users" in conversation_cbs:
145         (<object> conversation_cbs["chat-add-users"])("chat-add-users: TODO")
146
147 cdef void chat_rename_user(conversation.PurpleConversation *conv, \
148         const_char *old_name, const_char *new_name,
149         const_char *new_alias):
150     """
151     Rename the user in this chat name old_name to new_name. (The rename
152     message is written to the conversation by libpurple.)
153     @param new_alias  new_name's new_alias, if they have one.
154     @see purple_conv_chat_rename_user()
155     """
156     debug.purple_debug_info("conversation", "%s", "chat-rename-user\n")
157     if "chat-rename-user" in conversation_cbs:
158         (<object> conversation_cbs["chat-rename-user"]) \
159             ("chat-rename-user: TODO")
160
161 cdef void chat_remove_users(conversation.PurpleConversation *conv, \
162         glib.GList *users):
163     """
164     Remove users from a chat.
165     @param  users  A GList of const char *s.
166     """
167     debug.purple_debug_info("conversation", "%s", "chat-remove-users\n")
168     if "chat-remove-users" in conversation_cbs:
169         (<object> conversation_cbs["chat-remove-users"]) \
170             ("chat-remove-users: TODO")
171
172 cdef void chat_update_user(conversation.PurpleConversation *conv, \
173         const_char *user):
174     """
175     Called when a user's flags are changed.
176     @see purple_conv_chat_user_set_flags()
177     """
178     debug.purple_debug_info("conversation", "%s", "chat-update-user\n")
179     if "chat-update-user" in conversation_cbs:
180         (<object> conversation_cbs["chat-update-user"]) \
181             ("chat-update-user: TODO")
182
183 cdef void present(conversation.PurpleConversation *conv):
184     """
185     Present this conversation to the user; for example, by displaying the IM
186     dialog.
187     """
188     debug.purple_debug_info("conversation", "%s", "present\n")
189     if "present" in conversation_cbs:
190         (<object> conversation_cbs["present"])("present: TODO")
191
192 cdef glib.gboolean has_focus(conversation.PurpleConversation *conv):
193     """
194     If this UI has a concept of focus (as in a windowing system) and this
195     conversation has the focus, return TRUE; otherwise, return FALSE.
196     """
197     debug.purple_debug_info("conversation", "%s", "has-focus\n")
198     if "has-focus" in conversation_cbs:
199         (<object> conversation_cbs["has-focus"])("has-focus: TODO")
200     return False
201
202 cdef glib.gboolean custom_smiley_add(conversation.PurpleConversation *conv, \
203         const_char *smile, glib.gboolean remote):
204     """
205     Custom smileys (add).
206     """
207     debug.purple_debug_info("conversation", "%s", "custom-smiley-add\n")
208     if "custom-smiley-add" in conversation_cbs:
209         (<object> conversation_cbs["custom-smiley-add"]) \
210             ("custom-smiley-add: TODO")
211     return False
212
213 cdef void custom_smiley_write(conversation.PurpleConversation *conv, \
214         const_char *smile, const_guchar *data, glib.gsize size):
215     """
216     Custom smileys (write).
217     """
218     debug.purple_debug_info("conversation", "%s", "custom-smiley-write\n")
219     if "custom-smiley-write" in conversation_cbs:
220         (<object> conversation_cbs["custom-smiley-write"]) \
221             ("custom-smiley-write: TODO")
222
223 cdef void custom_smiley_close(conversation.PurpleConversation *conv, \
224         const_char *smile):
225     """
226     Custom smileys (close).
227     """
228     debug.purple_debug_info("conversation", "%s", "custom-smiley-close\n")
229     if "custom-smiley-close" in conversation_cbs:
230         (<object> conversation_cbs["custom-smiley-close"]) \
231             ("custom-smiley-close: TODO")
232
233 cdef void send_confirm(conversation.PurpleConversation *conv, \
234         const_char *message):
235     """
236     Prompt the user for confirmation to send mesage. This function should
237     arrange for the message to be sent if the user accepts. If this field
238     is NULL, libpurple will fall back to using purple_request_action().
239     """
240     debug.purple_debug_info("conversation", "%s", "send-confirm\n")
241     if "send-confirm" in conversation_cbs:
242         (<object> conversation_cbs["send-confirm"])("send-confirm: TODO")