Replaced all 'dict.has_key(item)' with 'item in dict' expressions.
[python-purple] / account.pyx
index f70873e..5935ba9 100644 (file)
@@ -228,8 +228,8 @@ cdef class Account:
         cdef char *id = NULL
         cdef char *name = NULL
 
+        status_types = []
         if self.__exists:
-            status_types = []
             iter = account.purple_account_get_status_types(self._get_structure())
             while iter:
                 c_statustype = <status.PurpleStatusType *> iter.data
@@ -237,9 +237,8 @@ cdef class Account:
                 name = <char *> status.purple_status_type_get_name(c_statustype)
                 status_types.append((id, name))
                 iter = iter.next
-            return status_types
-        else:
-             return None
+
+        return status_types
 
     status_types = property(__get_status_types)
 
@@ -328,7 +327,7 @@ cdef class Account:
 
             sett = str(<char *> setting)
 
-            if not po.has_key(sett):
+            if sett not in po:
                 iter = iter.next
                 continue
 
@@ -552,11 +551,11 @@ cdef class Account:
         cdef blist.PurpleBuddy *c_buddy = NULL
         cdef char *c_alias = NULL
 
+        buddies_list = []
         if self.__exists and \
                 account.purple_account_is_connected(self._get_structure()):
             iter = blist.purple_find_buddies(self._get_structure(), NULL)
 
-            buddies_list = []
             while iter:
                 c_alias = NULL
                 c_buddy = <blist.PurpleBuddy *> iter.data
@@ -573,9 +572,36 @@ cdef class Account:
 
                     buddies_list.append(new_buddy)
                 iter = iter.next
-            return buddies_list
-        else:
-            return None
+
+        return buddies_list
+
+    def get_buddies(self):
+        """
+        @return Account's buddies list
+        """
+        cdef glib.GSList *iter = NULL
+        cdef blist.PurpleBuddy *c_buddy = NULL
+        cdef char *c_alias = NULL
+
+        buddies_list = []
+        if self.__exists:
+            iter = blist.purple_find_buddies(self._get_structure(), NULL)
+
+            while iter:
+                c_alias = NULL
+                c_buddy = <blist.PurpleBuddy *> iter.data
+
+                name = <char *> blist.purple_buddy_get_name(c_buddy)
+                new_buddy = Buddy(name, self)
+
+                c_alias = <char *> blist.purple_buddy_get_alias_only(c_buddy)
+                if c_alias:
+                    new_buddy.set_alias(c_alias)
+
+                buddies_list.append(new_buddy)
+                iter = iter.next
+
+        return buddies_list
 
     def request_add_buddy(self, buddy_username, buddy_alias):
         if buddy_alias:
@@ -587,6 +613,7 @@ cdef class Account:
 
     def set_active_status(self, type, msg=None):
         cdef status.PurpleStatusType *c_statustype = NULL
+        cdef savedstatuses.PurpleSavedStatus *c_savedstatus = NULL
 
         if self.__exists:
             if msg:
@@ -595,6 +622,22 @@ cdef class Account:
             else:
                 account.purple_account_set_status(self._get_structure(),
                         <char *> type, True, NULL)
+
+            # FIXME: We can create only a savedstatus for each statustype
+            c_savedstatus = savedstatuses.purple_savedstatus_find(type)
+            if c_savedstatus == NULL:
+                c_statustype = account.purple_account_get_status_type( \
+                        self._get_structure(), type)
+                c_savedstatus = savedstatuses.purple_savedstatus_new( \
+                        NULL, status.purple_status_type_get_primitive( \
+                                c_statustype))
+                savedstatuses.purple_savedstatus_set_title(c_savedstatus,
+                        type)
+
+            savedstatuses.purple_savedstatus_set_message(c_savedstatus, msg)
+            prefs.purple_prefs_set_int("/purple/savedstatus/idleaway",
+                    savedstatuses.purple_savedstatus_get_creation_time(c_savedstatus))
+
             return True
         else:
             return False
@@ -602,11 +645,27 @@ cdef class Account:
     def set_status_message(self, type, msg):
         cdef status.PurpleStatus* c_status = NULL
         cdef status.PurpleStatusType *c_statustype = NULL
+        cdef savedstatuses.PurpleSavedStatus *c_savedstatus = NULL
 
         if self.__exists and msg:
             c_status = account.purple_account_get_status(self._get_structure(),
                     type)
+            if c_status == NULL:
+                return False
             status.purple_status_set_attr_string(c_status, "message", msg)
+
+            # FIXME: We can create only a savedstatus for each statustype
+            c_savedstatus = savedstatuses.purple_savedstatus_find(type)
+            if c_savedstatus == NULL:
+                c_statustype = account.purple_account_get_status_type( \
+                        self._get_structure(), type)
+                c_savedstatus = savedstatuses.purple_savedstatus_new( \
+                        NULL, status.purple_status_type_get_primitive( \
+                                c_statustype))
+                savedstatuses.purple_savedstatus_set_title(c_savedstatus,
+                        type)
+
+            savedstatuses.purple_savedstatus_set_message(c_savedstatus, msg)
             return True
         else:
             return False