Added binds for functions from libpurple which return structure attributes.
[python-purple] / conversation.pyx
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 class Conversation:
23     """ Conversation class """
24     cdef conversation.PurpleConversation *__conv
25     cdef Account __acc
26
27     cdef object name
28
29     def __init__(self):
30         conversation.c_purple_conversations_init()
31         self.name = None
32
33     def initialize(self, acc, type, char *name):
34         self.__acc = acc
35         if type == "UNKNOWN":
36             self.__conv =\
37             conversation.c_purple_conversation_new(conversation.PURPLE_CONV_TYPE_UNKNOWN,\
38                 <account.PurpleAccount*>self.__acc.c_account, name)
39         elif type == "IM":
40             self.__conv =\
41             conversation.c_purple_conversation_new(conversation.PURPLE_CONV_TYPE_IM,\
42                 <account.PurpleAccount*>self.__acc.c_account, name)
43         elif type == "CHAT":
44             self.__conv =\
45             conversation.c_purple_conversation_new(conversation.PURPLE_CONV_TYPE_CHAT,\
46                 <account.PurpleAccount*>self.__acc.c_account, name)
47         elif type == "MISC":
48             self.__conv =\
49             conversation.c_purple_conversation_new(conversation.PURPLE_CONV_TYPE_MISC,\
50                 <account.PurpleAccount*>self.__acc.c_account, name)
51         elif type == "ANY":
52             self.__conv =\
53             conversation.c_purple_conversation_new(conversation.PURPLE_CONV_TYPE_ANY,\
54                 <account.PurpleAccount*>self.__acc.c_account, name)
55         self.name = name
56
57     def conversation_set_ui_ops(self):
58         cdef conversation.PurpleConversationUiOps c_conv_ui_ops
59         c_conv_ui_ops.create_conversation = NULL
60         c_conv_ui_ops.destroy_conversation = NULL
61         c_conv_ui_ops.write_chat = NULL
62         c_conv_ui_ops.write_im = NULL
63         c_conv_ui_ops.write_conv = NULL
64         c_conv_ui_ops.chat_add_users = NULL
65         c_conv_ui_ops.chat_rename_user = NULL
66         c_conv_ui_ops.chat_remove_users = NULL
67         c_conv_ui_ops.chat_update_user = NULL
68         c_conv_ui_ops.present = NULL
69         c_conv_ui_ops.has_focus = NULL
70         c_conv_ui_ops.custom_smiley_add = NULL
71         c_conv_ui_ops.custom_smiley_write = NULL
72         c_conv_ui_ops.custom_smiley_close = NULL
73         c_conv_ui_ops.send_confirm = NULL
74
75         conversation.c_purple_conversation_set_ui_ops(self.__conv, &c_conv_ui_ops)
76
77     def write(self, char *message):
78         conversation.c_purple_conv_im_send(conversation.c_purple_conversation_get_im_data(self.__conv), message)
79
80     def get_handle(self):
81         conversation.c_purple_conversations_get_handle()
82
83     def destroy(self):
84         print "[DEBUG]: Destroy conversation: %s" % self.name
85         conversation.c_purple_conversation_destroy(self.__conv)