Fixed get account c-structure on Protocol class.
[python-purple] / purple.pyx
index e69a966..5d87af3 100644 (file)
@@ -75,30 +75,34 @@ cdef class Purple:
         if default_path is not __DEFAULT_PATH__:
             __DEFAULT_PATH__ = default_path
 
-        debug.c_purple_debug_set_enabled(debug_enabled)
-        util.c_purple_util_set_user_dir(default_path)
+        debug.purple_debug_set_enabled(debug_enabled)
+        util.purple_util_set_user_dir(default_path)
         plugin.c_purple_plugins_add_search_path(default_path)
 
         # adds glib iteration inside ecore main loop
         ecore.timer_add(0.001, self.__glib_iteration_when_idle)
 
+    def __get_ui_name(self):
+        return __APP_NAME__
+    ui_name = property(__get_ui_name)
+
     def destroy(self):
         core.c_purple_core_quit()
 
     cdef void __core_ui_ops_ui_prefs_init(self):
-        debug.c_purple_debug_info("core_ui_ops", "%s", "ui_prefs_init\n")
+        debug.purple_debug_info("core_ui_ops", "%s", "ui_prefs_init\n")
         prefs.c_purple_prefs_load()
 
         prefs.c_purple_prefs_add_none("/carman")
 
     cdef void __core_ui_ops_debug_init(self):
-        debug.c_purple_debug_info("core_ui_ops", "%s", "debug_ui_init\n")
+        debug.purple_debug_info("core_ui_ops", "%s", "debug_ui_init\n")
         pass
 
     cdef void __core_ui_ops_ui_init(self):
-        debug.c_purple_debug_info("core_ui_ops", "%s", "ui_init\n")
+        debug.purple_debug_info("core_ui_ops", "%s", "ui_init\n")
 
-        account.c_purple_accounts_set_ui_ops(&c_account_ui_ops)
+        account.purple_accounts_set_ui_ops(&c_account_ui_ops)
         connection.c_purple_connections_set_ui_ops(&c_conn_ui_ops)
         blist.c_purple_blist_set_ui_ops(&c_blist_ui_ops)
         conversation.c_purple_conversations_set_ui_ops(&c_conv_ui_ops)
@@ -109,11 +113,11 @@ cdef class Purple:
         #roomlist.c_purple_roomlist_set_ui_ops(&c_rlist_ui_ops)
 
     cdef void __core_ui_ops_quit(self):
-        debug.c_purple_debug_info("core_ui_ops", "%s", "quit\n")
+        debug.purple_debug_info("core_ui_ops", "%s", "quit\n")
 
         global c_ui_info
 
-        account.c_purple_accounts_set_ui_ops(NULL)
+        account.purple_accounts_set_ui_ops(NULL)
         connection.c_purple_connections_set_ui_ops(NULL)
         blist.c_purple_blist_set_ui_ops(NULL)
         conversation.c_purple_conversations_set_ui_ops(NULL)
@@ -222,13 +226,13 @@ cdef class Purple:
         # initialize purple core
         ret = core.c_purple_core_init(__APP_NAME__)
         if ret is False:
-            debug.c_purple_debug_fatal("main", "%s", "libpurple " \
+            debug.purple_debug_fatal("main", "%s", "libpurple " \
                                        "initialization failed.\n")
             return False
 
         # check if there is another instance of libpurple running
         if core.c_purple_core_ensure_single_instance() == False:
-            debug.c_purple_debug_fatal("main", "%s", "Another instance of " \
+            debug.purple_debug_fatal("main", "%s", "Another instance of " \
                                       "libpurple is already running.\n")
             core.c_purple_core_quit()
             return False
@@ -324,20 +328,21 @@ cdef class Purple:
     def load_accounts(self):
         cdef glib.GList *iter
         cdef account.PurpleAccount *acc
-        iter = account.c_purple_accounts_get_all()
+        iter = account.purple_accounts_get_all()
         while iter:
             acc = <account.PurpleAccount *> iter.data
             if <account.PurpleAccount *>acc:
-                username = account.c_purple_account_get_username(acc)
-                protocol_id = account.c_purple_account_get_protocol_id(acc)
-                self.account_add(username.split("/")[0], protocol_id, "172.18.216.211", 8080)
+                username = <char *> account.purple_account_get_username(acc)
+                protocol_id = <char *> account.purple_account_get_protocol_id(acc)
+                self.account_add(username.split("/")[0], protocol_id, \
+                        "172.18.216.211", 8080)
             iter = iter.next
 
     def account_add(self, username, protocol_id, host, port):
         if not self.account_verify(username):
             acc = purple.Account(username, protocol_id)
             self.__accounts[username] = acc
-            if not account.c_purple_accounts_find(username, protocol_id):
+            if not account.purple_accounts_find(username, protocol_id):
                 acc.proxy.set_type(purple.ProxyInfoType().HTTP)
                 acc.proxy.set_host(host)
                 acc.proxy.set_port(port)
@@ -351,9 +356,34 @@ cdef class Purple:
         else:
             return None
 
-include "plugin.pyx"
+    def accounts_get_all(self):
+        cdef glib.GList *iter
+        cdef account.PurpleAccount *acc
+        cdef char *username
+        cdef char *protocol_id
+
+        iter = account.purple_accounts_get_all()
+        account_list = []
+
+        while iter:
+            acc = <account.PurpleAccount *> iter.data
+
+            if <account.PurpleAccount *>acc:
+                username = <char *> account.purple_account_get_username(acc)
+                protocol_id = <char *> account.purple_account_get_protocol_id(acc)
+
+                if username != NULL and protocol_id != NULL:
+                    account_list.append(Account(self, username, protocol_id))
+            iter = iter.next
+
+        return account_list
+
+include "protocol.pyx"
+#include "plugin.pyx"
 include "proxy.pyx"
+#include "protocol.pyx"
 include "account.pyx"
 include "buddy.pyx"
 #include "connection.pyx"
 include "conversation.pyx"
+