Switching to a fremantle specific profile file
[theonering] / src / gvoice / addressbook.py
index aeb8de5..f9f713b 100644 (file)
@@ -20,7 +20,9 @@ class Addressbook(object):
 
                self.updateSignalHandler = coroutines.CoTee()
 
-       def update(self):
+       def update(self, force=False):
+               if not force and self._contacts:
+                       return
                oldContacts = self._contacts
                oldContactIds = set(self.get_contacts())
 
@@ -36,8 +38,9 @@ class Addressbook(object):
                        if self._has_contact_changed(contactId, oldContacts)
                )
 
-               message = self, self._addedContacts, self._removedContacts, self._changedContacts
-               self.updateSignalHandler.send(message)
+               if self._addedContacts or self._removedContacts or self._changedContacts:
+                       message = self, self._addedContacts, self._removedContacts, self._changedContacts
+                       self.updateSignalHandler.stage.send(message)
 
        def get_contacts(self):
                return self._contacts.iterkeys()
@@ -53,13 +56,18 @@ class Addressbook(object):
                if self._contacts:
                        return
                contacts = self._backend.get_contacts()
-               for contactId, contactName in contacts:
-                       self._contacts[contactId] = (contactName, {})
+               for contactId, contactDetails in contacts:
+                       contactName = contactDetails["name"]
+                       contactNumbers = [
+                               (numberDetails.get("phoneType", "Mobile"), numberDetails["phoneNumber"])
+                               for numberDetails in contactDetails["numbers"]
+                       ]
+                       self._contacts[contactId] = (contactName, contactNumbers)
 
        def _populate_contact_details(self, contactId):
                if self._get_contact_details(contactId):
                        return
-               self._get_contact_details(contactId).update(
+               self._get_contact_details(contactId).extend(
                        self._backend.get_contact_details(contactId)
                )
 
@@ -72,7 +80,7 @@ class Addressbook(object):
                oldContactDetails = oldContact[1]
                if oldContactName != self.get_contact_name(contactId):
                        return True
-               if not oldContactDetails[1]:
+               if not oldContactDetails:
                        return False
                # if its already in the old cache, purposefully add it into the new cache
                return oldContactDetails != self.get_contact_details(contactId)