Initial Buddy class reimplementation.
[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 object __acc
26
27     cdef object __name
28
29     def __init__(self):
30         conversation.purple_conversations_init()
31         self.__name = None
32         self.__acc = None
33
34     def __get_account(self):
35         return self.__acc
36     def __set_account(self, acc):
37         self.__acc = acc
38     account = property(__get_account, __set_account)
39
40     def __get_name(self):
41         return self.__name
42     def __set_name(self, name):
43         self.__name = name
44     name = property(__get_name, __set_name)
45
46     def initialize(self, acc, type, char *name):
47         cdef account.PurpleAccount *c_account
48         self.__acc = acc
49         self.__name = name
50
51         c_account = account.purple_accounts_find(<char *> acc[0], <char *> acc[1])
52         if not c_account:
53             return
54
55         if type == "UNKNOWN":
56             self.__conv =\
57             conversation.purple_conversation_new(conversation.PURPLE_CONV_TYPE_UNKNOWN,\
58                 c_account, self.__name)
59         elif type == "IM":
60             self.__conv =\
61             conversation.purple_conversation_new(conversation.PURPLE_CONV_TYPE_IM,\
62                 <account.PurpleAccount*> c_account, self.__name)
63         elif type == "CHAT":
64             self.__conv =\
65             conversation.purple_conversation_new(conversation.PURPLE_CONV_TYPE_CHAT,\
66                 c_account, self.__name)
67         elif type == "MISC":
68             self.__conv =\
69             conversation.purple_conversation_new(conversation.PURPLE_CONV_TYPE_MISC,\
70                 c_account, self.__name)
71         elif type == "ANY":
72             self.__conv =\
73             conversation.purple_conversation_new(conversation.PURPLE_CONV_TYPE_ANY,\
74                 c_account, self.__name)
75
76     def conversation_set_ui_ops(self):
77         cdef conversation.PurpleConversationUiOps c_conv_ui_ops
78         c_conv_ui_ops.create_conversation = NULL
79         c_conv_ui_ops.destroy_conversation = NULL
80         c_conv_ui_ops.write_chat = NULL
81         c_conv_ui_ops.write_im = NULL
82         c_conv_ui_ops.write_conv = NULL
83         c_conv_ui_ops.chat_add_users = NULL
84         c_conv_ui_ops.chat_rename_user = NULL
85         c_conv_ui_ops.chat_remove_users = NULL
86         c_conv_ui_ops.chat_update_user = NULL
87         c_conv_ui_ops.present = NULL
88         c_conv_ui_ops.has_focus = NULL
89         c_conv_ui_ops.custom_smiley_add = NULL
90         c_conv_ui_ops.custom_smiley_write = NULL
91         c_conv_ui_ops.custom_smiley_close = NULL
92         c_conv_ui_ops.send_confirm = NULL
93
94         conversation.purple_conversation_set_ui_ops(self.__conv, &c_conv_ui_ops)
95
96     def write(self, char *message):
97         if self.__conv:
98             conversation.purple_conv_im_send(conversation.purple_conversation_get_im_data(self.__conv), message)
99
100     def get_handle(self):
101         conversation.purple_conversations_get_handle()
102
103     def destroy(self):
104         print "[DEBUG]: Destroy conversation: %s" % self.__name
105         if self.__conv:
106             conversation.purple_conversation_destroy(self.__conv)