Initial Buddy class reimplementation.
[python-purple] / conversation.pyx
index ecb00bc..04da1b4 100644 (file)
 #  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
+cimport purple
+
 cdef class Conversation:
     """ Conversation class """
-    cdef PurpleConversation *__conv
+    cdef conversation.PurpleConversation *__conv
+    cdef object __acc
+
+    cdef object __name
+
+    def __init__(self):
+        conversation.purple_conversations_init()
+        self.__name = None
+        self.__acc = None
+
+    def __get_account(self):
+        return self.__acc
+    def __set_account(self, acc):
+        self.__acc = acc
+    account = property(__get_account, __set_account)
 
-    def __cinit__(self):
-        purple_conversations_init()
+    def __get_name(self):
+        return self.__name
+    def __set_name(self, name):
+        self.__name = name
+    name = property(__get_name, __set_name)
 
-    def conversation_new(self, type, acc, const_char_ptr name):
-        self.__conv = purple_conversation_new(type, <PurpleAccount*>acc.__account, name)
+    def initialize(self, acc, type, char *name):
+        cdef account.PurpleAccount *c_account
+        self.__acc = acc
+        self.__name = name
+
+        c_account = account.purple_accounts_find(<char *> acc[0], <char *> acc[1])
+        if not c_account:
+            return
+
+        if type == "UNKNOWN":
+            self.__conv =\
+            conversation.purple_conversation_new(conversation.PURPLE_CONV_TYPE_UNKNOWN,\
+                c_account, self.__name)
+        elif type == "IM":
+            self.__conv =\
+            conversation.purple_conversation_new(conversation.PURPLE_CONV_TYPE_IM,\
+                <account.PurpleAccount*> c_account, self.__name)
+        elif type == "CHAT":
+            self.__conv =\
+            conversation.purple_conversation_new(conversation.PURPLE_CONV_TYPE_CHAT,\
+                c_account, self.__name)
+        elif type == "MISC":
+            self.__conv =\
+            conversation.purple_conversation_new(conversation.PURPLE_CONV_TYPE_MISC,\
+                c_account, self.__name)
+        elif type == "ANY":
+            self.__conv =\
+            conversation.purple_conversation_new(conversation.PURPLE_CONV_TYPE_ANY,\
+                c_account, self.__name)
 
     def conversation_set_ui_ops(self):
-        cdef PurpleConversationUiOps c_conv_ui_ops
+        cdef conversation.PurpleConversationUiOps c_conv_ui_ops
         c_conv_ui_ops.create_conversation = NULL
         c_conv_ui_ops.destroy_conversation = NULL
         c_conv_ui_ops.write_chat = NULL
@@ -45,18 +91,16 @@ cdef class Conversation:
         c_conv_ui_ops.custom_smiley_close = NULL
         c_conv_ui_ops.send_confirm = NULL
 
-        purple_conversation_set_ui_ops(self.__conv, &c_conv_ui_ops)
-
-    def conversation_write(self, const_char_ptr message):
-        purple_conv_im_send(purple_conversation_get_im_data(self.__conv), message)
+        conversation.purple_conversation_set_ui_ops(self.__conv, &c_conv_ui_ops)
 
-    def conversation_destroy(self):
-        purple_conversation_destroy(self.__conv)
+    def write(self, char *message):
+        if self.__conv:
+            conversation.purple_conv_im_send(conversation.purple_conversation_get_im_data(self.__conv), message)
 
-    def conversation_get_handle(self):
-        purple_conversations_get_handle()
+    def get_handle(self):
+        conversation.purple_conversations_get_handle()
 
-    def send_message(self, buddy, const_char_ptr message):
-        self.conversation_new(1, buddy.account, buddy.name)
-        self.conversation_set_ui_ops()
-        self.conversation_write(message)
+    def destroy(self):
+        print "[DEBUG]: Destroy conversation: %s" % self.__name
+        if self.__conv:
+            conversation.purple_conversation_destroy(self.__conv)