Added "connection-error" signal callback.
[python-purple] / account.pyx
index e569c52..7dd484f 100644 (file)
@@ -33,17 +33,25 @@ cdef class Account:
 
     def __init__(self, char *username, char *protocol_id):
         cdef proxy.PurpleProxyInfo *c_proxyinfo
-        self.c_account = account.c_purple_account_new(username, protocol_id)
-        self.c_plugin = plugin.c_purple_plugins_find_with_id(protocol_id)
-        self.c_prpl_info = plugin.c_PURPLE_PLUGIN_PROTOCOL_INFO(self.c_plugin)
+        cdef account.PurpleAccount *acc = NULL
 
-        c_proxyinfo = account.c_purple_account_get_proxy_info(self.c_account)
-        if c_proxyinfo == NULL:
-            c_proxyinfo = proxy.c_purple_proxy_info_new()
-            proxy.c_purple_proxy_info_set_type(c_proxyinfo, proxy.PURPLE_PROXY_NONE)
-        account.c_purple_account_set_proxy_info(self.c_account, c_proxyinfo)
+        acc = account.c_purple_accounts_find(username, protocol_id)
+        if acc:
+            self.c_account = acc
+            c_proxyinfo = account.c_purple_account_get_proxy_info(self.c_account)
+        else:
+            self.c_account = account.c_purple_account_new(username, protocol_id)
+            c_proxyinfo = account.c_purple_account_get_proxy_info(self.c_account)
+            if c_proxyinfo == NULL:
+                c_proxyinfo = proxy.c_purple_proxy_info_new()
+                proxy.c_purple_proxy_info_set_type(c_proxyinfo, proxy.PURPLE_PROXY_NONE)
+                account.c_purple_account_set_proxy_info(self.c_account, c_proxyinfo)
         self.__proxy = ProxyInfo()
         self.__proxy.c_proxyinfo = c_proxyinfo
+        acc = NULL
+
+        self.c_plugin = plugin.c_purple_plugins_find_with_id(protocol_id)
+        self.c_prpl_info = plugin.c_PURPLE_PLUGIN_PROTOCOL_INFO(self.c_plugin)
 
     def __get_username(self):
         if self.c_account:
@@ -132,14 +140,28 @@ cdef class Account:
     def get_buddies_online(self):
         cdef glib.GSList *iter
         cdef blist.PurpleBuddy *buddy
+        cdef char *c_name = NULL
+        cdef char *c_alias = NULL
         buddies = []
         iter = blist.c_purple_find_buddies(self.c_account, NULL)
         while iter:
+            c_name = NULL
+            c_alias = NULL
             buddy = <blist.PurpleBuddy *> iter.data
             if <blist.PurpleBuddy *>buddy and \
                 account.c_purple_account_is_connected(blist.c_purple_buddy_get_account(buddy)) and \
                 status.c_purple_presence_is_online(blist.c_purple_buddy_get_presence(buddy)):
-                buddies += [buddy.name]
+                c_name = <char *> blist.c_purple_buddy_get_name(buddy)
+                if c_name == NULL:
+                    name = None
+                else:
+                    name = c_name
+                c_alias = <char *> blist.c_purple_buddy_get_alias_only(buddy)
+                if c_alias == NULL:
+                    alias = None
+                else:
+                    alias = c_alias
+                buddies.append((name, alias))
             iter = iter.next
         return buddies
 
@@ -190,3 +212,6 @@ cdef class Account:
                     str_value = account.c_purple_account_get_string(self.c_account, setting, str_value)
 
             iter = iter.next
+
+    def save_into_xml(self):
+        account.c_purple_accounts_add(self.c_account)