2 # Copyright (c) 2008 INdT - Instituto Nokia de Tecnologia
4 # This file is part of python-purple.
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.
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.
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/>.
22 cdef class Conversation:
25 @param type UNKNOWN, IM, CHAT, MISC, ANY
26 @param account Your account
27 @param name Buddy name
35 def __init__(self, type, account, name):
37 "UNKNOWN": conversation.PURPLE_CONV_TYPE_UNKNOWN,
38 "IM": conversation.PURPLE_CONV_TYPE_IM,
39 "CHAT": conversation.PURPLE_CONV_TYPE_CHAT,
40 "MISC": conversation.PURPLE_CONV_TYPE_MISC,
41 "ANY": conversation.PURPLE_CONV_TYPE_ANY }[type]
42 self.__account = account
45 if self._get_structure() != NULL:
50 cdef conversation.PurpleConversation *_get_structure(self):
51 return conversation.purple_find_conversation_with_account( \
52 self.__type, self.__name, account.purple_accounts_find( \
53 self.__account.username, self.__account.protocol.id))
55 def __get_exists(self):
57 exists = property(__get_exists)
59 def __get_account(self):
64 account = property(__get_account)
68 return <char *> conversation.purple_conversation_get_name( \
69 self._get_structure())
72 name = property(__get_name)
76 Creates a new conversation.
78 @return True if successful, False if conversation already exists
83 conversation.purple_conversation_new(self.__type, \
84 account.purple_accounts_find(self.__account.username, \
85 self.__account.protocol.id), self.__name)
91 Destroys a conversation.
93 @return True if successful, False if conversation doesn't exists
96 conversation.purple_conversation_destroy(self._get_structure())
102 def set_ui_ops(self, cbs):
104 Sets UI operations for a conversation.
106 @return True if sucessful, False otherwise
108 # FIXME: We may need to create c-functions for each of these?
109 cdef conversation.PurpleConversationUiOps c_conv_ui_ops
111 c_conv_ui_ops.create_conversation = NULL
112 c_conv_ui_ops.destroy_conversation = NULL
113 c_conv_ui_ops.write_chat = NULL
114 c_conv_ui_ops.write_im = NULL
115 c_conv_ui_ops.write_conv = NULL
116 c_conv_ui_ops.chat_add_users = NULL
117 c_conv_ui_ops.chat_rename_user = NULL
118 c_conv_ui_ops.chat_remove_users = NULL
119 c_conv_ui_ops.chat_update_user = NULL
120 c_conv_ui_ops.present = NULL
121 c_conv_ui_ops.has_focus = NULL
122 c_conv_ui_ops.custom_smiley_add = NULL
123 c_conv_ui_ops.custom_smiley_write = NULL
124 c_conv_ui_ops.custom_smiley_close = NULL
125 c_conv_ui_ops.send_confirm = NULL
127 conversation.purple_conversation_set_ui_ops(self._get_structure(), \
131 def im_send(self, message):
133 Sends a message to this IM conversation.
135 @return True if successful, False if conversation is not IM or conversation doesn't exists
137 if self.__exists and self.__type == conversation.PURPLE_CONV_TYPE_IM:
138 conversation.purple_conv_im_send( \
139 conversation.purple_conversation_get_im_data( \
140 self._get_structure()), message)