Add get/set proxyinfo methods to Account class
[python-purple] / account.pyx
index cafdf07..5a9ecf7 100644 (file)
 #  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
-class ProxyType:
-    def __init__(self):
-        self.PROXY_USE_GLOBAL = -1
-        self.PROXY_NONE = 0
-        self.PROXY_HTTP = 1
-        self.PROXY_SOCKS4 = 2
-        self.PROXY_SOCKS5 = 3
-        self.PROXY_USE_ENVVAR = 4
-
-
-class StatusPrimitive:
-    def __init__(self):
-        self.STAUTS_UNSET = 0
-        self.STATUS_OFFLINE = 1
-        self.STATUS_AVAILABLE = 2
-        self.STATUS_UNAVAILABLE = 3
-        self.STATUS_INVISIBLE = 4
-        self.STATUS_AWAY = 5
-        self.STATUS_EXTENDED_AWAY = 6
-        self.STATUS_MOBILE = 7
-        self.STATUS_TUNE = 8
-        self.STATUS_NUN_PRIMITIVE = 9
+cimport purple
+cimport proxy
 
 cdef class Account:
     """ Account class """
-    cdef PurpleAccount *__account
-    cdef PurpleSavedStatus *__sstatus
+    cdef account.PurpleAccount *__account
+    cdef savedstatuses.PurpleSavedStatus *__sstatus
 
-    def __cinit__(self, const_char_ptr username, const_char_ptr protocol_id):
-        self.__account = c_purple_account_new(username, protocol_id)
+    def __init__(self, char *username, char *protocol_id):
+        self.__account = account.c_purple_account_new(username, protocol_id)
 
     def set_password(self, password):
-        c_purple_account_set_password(self.__account, password)
+        account.c_purple_account_set_password(self.__account, password)
 
     def set_enabled(self, ui, value):
-        c_purple_account_set_enabled(self.__account, ui, value)
+        account.c_purple_account_set_enabled(self.__account, ui, value)
 
     def get_acc_username(self):
         if self.__account:
-            return c_purple_account_get_username(self.__account)
+            return account.c_purple_account_get_username(self.__account)
 
     def get_password(self):
         if self.__account:
-            return c_purple_account_get_password(self.__account)
+            return account.c_purple_account_get_password(self.__account)
 
     def set_status(self):
-        self.__sstatus = c_purple_savedstatus_new(NULL, StatusPrimitive().STATUS_AVAILABLE)
-        c_purple_savedstatus_activate(self.__sstatus)
+        self.__sstatus = savedstatuses.c_purple_savedstatus_new(NULL, status.PURPLE_STATUS_AVAILABLE)
+        savedstatuses.c_purple_savedstatus_activate(self.__sstatus)
+
+    def get_buddies_online(self):
+        cdef glib.GSList *iter
+        cdef blist.PurpleBuddy *buddy
+        buddies = []
+        iter = blist.c_purple_find_buddies(self.__account, NULL)
+        while iter:
+            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]
+            iter = iter.next
+        return buddies
+
+    def get_proxyinfo(self):
+        cdef proxy.PurpleProxyInfo *c_proxyinfo
+        c_proxyinfo = account.c_purple_account_get_proxy_info(self.__account)
+        if c_proxyinfo == NULL:
+            return None
+        cdef ProxyInfo proxyinfo
+        proxyinfo = proxy.ProxyInfo()
+        proxyinfo.c_proxyinfo = c_proxyinfo
+        return proxyinfo
 
+    def set_proxyinfo(self, ProxyInfo proxyinf):
+        account.c_purple_account_set_proxy_info(self.__account, proxyinf.c_proxyinfo)