Updated changes made on python-purple branch.
[python-purple] / conversation.pyx
index c13578a..5d5b3c3 100644 (file)
@@ -22,12 +22,56 @@ cimport purple
 cdef class Conversation:
     """ Conversation class """
     cdef conversation.PurpleConversation *__conv
+    cdef object __acc
+
+    cdef object __name
 
     def __init__(self):
         conversation.c_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 __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, char *name):
-        self.__conv = conversation.c_purple_conversation_new(type, <account.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.c_purple_accounts_find(acc[0], acc[1])
+        if not c_account:
+            return
+
+        if type == "UNKNOWN":
+            self.__conv =\
+            conversation.c_purple_conversation_new(conversation.PURPLE_CONV_TYPE_UNKNOWN,\
+                c_account, self.__name)
+        elif type == "IM":
+            self.__conv =\
+            conversation.c_purple_conversation_new(conversation.PURPLE_CONV_TYPE_IM,\
+                <account.PurpleAccount*> c_account, self.__name)
+        elif type == "CHAT":
+            self.__conv =\
+            conversation.c_purple_conversation_new(conversation.PURPLE_CONV_TYPE_CHAT,\
+                c_account, self.__name)
+        elif type == "MISC":
+            self.__conv =\
+            conversation.c_purple_conversation_new(conversation.PURPLE_CONV_TYPE_MISC,\
+                c_account, self.__name)
+        elif type == "ANY":
+            self.__conv =\
+            conversation.c_purple_conversation_new(conversation.PURPLE_CONV_TYPE_ANY,\
+                c_account, self.__name)
 
     def conversation_set_ui_ops(self):
         cdef conversation.PurpleConversationUiOps c_conv_ui_ops
@@ -49,16 +93,14 @@ cdef class Conversation:
 
         conversation.c_purple_conversation_set_ui_ops(self.__conv, &c_conv_ui_ops)
 
-    def conversation_write(self, char *message):
-        conversation.c_purple_conv_im_send(conversation.c_purple_conversation_get_im_data(self.__conv), message)
-
-    def conversation_destroy(self):
-        conversation.c_purple_conversation_destroy(self.__conv)
+    def write(self, char *message):
+        if self.__conv:
+            conversation.c_purple_conv_im_send(conversation.c_purple_conversation_get_im_data(self.__conv), message)
 
-    def conversation_get_handle(self):
+    def get_handle(self):
         conversation.c_purple_conversations_get_handle()
 
-    def send_message(self, buddy, char *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.c_purple_conversation_destroy(self.__conv)