Fix get_buddies_online
[python-purple] / account.pyx
index cafdf07..a3f996b 100644 (file)
 #  along with this program.  If not, see <http://www.gnu.org/licenses/>.
 #
 
 #  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
+cimport glib
 
 
-
-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 account
+cimport blist
+cimport savedstatuses
+cimport status
 
 cdef class Account:
     """ Account class """
 
 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 __cinit__(self, char *username, char *protocol_id):
+        self.__account = account.c_purple_account_new(username, protocol_id)
 
     def set_password(self, password):
 
     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):
 
     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:
 
     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:
 
     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):
 
     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