Adding function get_all to Plugin class
[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 __get_account(self):
34         return self.__acc
35     def __set_account(self, acc):
36         self.__acc = acc
37     account = property(__get_account, __set_account)
38
39     def __get_name(self):
40         return self.__name
41     def __set_name(self, name):
42         self.__name = name
43     name = property(__get_name, __set_name)
44
45     def initialize(self, acc, type, char *name):
46         self.__acc = acc
47         self.__name = name
48
49         if type == "UNKNOWN":
50             self.__conv =\
51             conversation.c_purple_conversation_new(conversation.PURPLE_CONV_TYPE_UNKNOWN,\
52                 <account.PurpleAccount*>self.__acc.c_account, self.__name)
53         elif type == "IM":
54             self.__conv =\
55             conversation.c_purple_conversation_new(conversation.PURPLE_CONV_TYPE_IM,\
56                 <account.PurpleAccount*>self.__acc.c_account, self.__name)
57         elif type == "CHAT":
58             self.__conv =\
59             conversation.c_purple_conversation_new(conversation.PURPLE_CONV_TYPE_CHAT,\
60                 <account.PurpleAccount*>self.__acc.c_account, self.__name)
61         elif type == "MISC":
62             self.__conv =\
63             conversation.c_purple_conversation_new(conversation.PURPLE_CONV_TYPE_MISC,\
64                 <account.PurpleAccount*>self.__acc.c_account, self.__name)
65         elif type == "ANY":
66             self.__conv =\
67             conversation.c_purple_conversation_new(conversation.PURPLE_CONV_TYPE_ANY,\
68                 <account.PurpleAccount*>self.__acc.c_account, self.__name)
69
70     def conversation_set_ui_ops(self):
71         cdef conversation.PurpleConversationUiOps c_conv_ui_ops
72         c_conv_ui_ops.create_conversation = NULL
73         c_conv_ui_ops.destroy_conversation = NULL
74         c_conv_ui_ops.write_chat = NULL
75         c_conv_ui_ops.write_im = NULL
76         c_conv_ui_ops.write_conv = NULL
77         c_conv_ui_ops.chat_add_users = NULL
78         c_conv_ui_ops.chat_rename_user = NULL
79         c_conv_ui_ops.chat_remove_users = NULL
80         c_conv_ui_ops.chat_update_user = NULL
81         c_conv_ui_ops.present = NULL
82         c_conv_ui_ops.has_focus = NULL
83         c_conv_ui_ops.custom_smiley_add = NULL
84         c_conv_ui_ops.custom_smiley_write = NULL
85         c_conv_ui_ops.custom_smiley_close = NULL
86         c_conv_ui_ops.send_confirm = NULL
87
88         conversation.c_purple_conversation_set_ui_ops(self.__conv, &c_conv_ui_ops)
89
90     def write(self, char *message):
91         conversation.c_purple_conv_im_send(conversation.c_purple_conversation_get_im_data(self.__conv), message)
92
93     def get_handle(self):
94         conversation.c_purple_conversations_get_handle()
95
96     def destroy(self):
97         print "[DEBUG]: Destroy conversation: %s" % self.__name
98         conversation.c_purple_conversation_destroy(self.__conv)