Initial Buddy class reimplementation.
[python-purple] / conversation.pyx
index f743e41..04da1b4 100644 (file)
@@ -22,37 +22,56 @@ cimport purple
 cdef class Conversation:
     """ Conversation class """
     cdef conversation.PurpleConversation *__conv
-    cdef Account __acc
+    cdef object __acc
 
-    cdef object name
+    cdef object __name
 
     def __init__(self):
-        conversation.c_purple_conversations_init()
-        self.name = None
+        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 __get_name(self):
+        return self.__name
+    def __set_name(self, name):
+        self.__name = name
+    name = property(__get_name, __set_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.c_purple_conversation_new(conversation.PURPLE_CONV_TYPE_UNKNOWN,\
-                <account.PurpleAccount*>self.__acc.c_account, name)
+            conversation.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*>self.__acc.c_account, name)
+            conversation.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,\
-                <account.PurpleAccount*>self.__acc.c_account, name)
+            conversation.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,\
-                <account.PurpleAccount*>self.__acc.c_account, name)
+            conversation.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,\
-                <account.PurpleAccount*>self.__acc.c_account, name)
-        self.name = name
+            conversation.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
@@ -72,13 +91,16 @@ cdef class Conversation:
         c_conv_ui_ops.custom_smiley_close = NULL
         c_conv_ui_ops.send_confirm = NULL
 
-        conversation.c_purple_conversation_set_ui_ops(self.__conv, &c_conv_ui_ops)
+        conversation.purple_conversation_set_ui_ops(self.__conv, &c_conv_ui_ops)
 
     def write(self, char *message):
-        conversation.c_purple_conv_im_send(conversation.c_purple_conversation_get_im_data(self.__conv), message)
+        if self.__conv:
+            conversation.purple_conv_im_send(conversation.purple_conversation_get_im_data(self.__conv), message)
 
     def get_handle(self):
-        conversation.c_purple_conversations_get_handle()
+        conversation.purple_conversations_get_handle()
 
     def destroy(self):
-        conversation.c_purple_conversation_destroy(self.__conv)
+        print "[DEBUG]: Destroy conversation: %s" % self.__name
+        if self.__conv:
+            conversation.purple_conversation_destroy(self.__conv)