Fixing Account to get protocol class as parameter
[python-purple] / protocol.pyx
index e8d8999..ed335e2 100644 (file)
@@ -25,18 +25,32 @@ cdef class Protocol:
     @param protocol_id
     """
 
     @param protocol_id
     """
 
-    def __init__(self, account, protocol_id):
-        self.__account = account
-        self.__protocol_id = protocol_id
+    def __init__(self, id):
+        self.__id = id
 
 
-    def __get_protocol_id(self):
-        return self.__protocol_id.protocol_id
-    protocol_id = property(__get_protocol_id)
+        if self._get_structure() != NULL:
+            self.__exists = True
+        else:
+            self.__exists = False
 
 
-    def __get_account(self):
-        return self.__account
-    account = property(__get_account)
+    cdef plugin.PurplePlugin *_get_structure(self):
+        return plugin.purple_plugins_find_with_id(self.__protocol_id)
 
 
-    def _set_protocol_id(self, protocol_id):
-        account.purple_account_set_protocol_id( \
-                self.__account._get_structure(), protocol_id)
+    def __get_exists(self):
+        return self.__exists
+    exists = property(__get_exists)
+
+    def __get_id(self):
+        return self.__id
+    id = property(__get_id)
+
+    def __get_name(self):
+        cdef char *name = NULL
+        if self.__exists:
+            name = <char *> plugin.purple_plugin_get_name(self._get_structure())
+            if name != NULL:
+                return name
+            else:
+                return None
+        return None
+    name = property(__get_name)