Add code which actually updates contacts, don't overwrite unless user
authorAndrew Flegg <andrew@bleb.org>
Wed, 9 Jun 2010 21:59:47 +0000 (22:59 +0100)
committerAndrew Flegg <andrew@bleb.org>
Wed, 9 Jun 2010 21:59:47 +0000 (22:59 +0100)
asked to and ensure "updated" list is maintained.

package/src/org/maemo/hermes/engine/contact.py
package/src/org/maemo/hermes/engine/friend.py
package/src/org/maemo/hermes/engine/hermes.py

index b9a49d2..8281d18 100644 (file)
@@ -162,6 +162,12 @@ class Contact:
     
     
     # -----------------------------------------------------------------------
+    def get_birthday(self):
+        photo = self._contact.get_property('birth-date')
+        return cast(c_void_p(hash(photo)), POINTER(EContactDate))
+        
+    
+    # -----------------------------------------------------------------------
     def set_nickname(self, nickname):
         """Set the nickname for this contact to the given nickname."""
         
@@ -171,6 +177,13 @@ class Contact:
     
     
     # -----------------------------------------------------------------------
+    def get_nickname(self):
+        """Get the nickname for this contact."""
+        
+        return self._contact.get_property('nickname')
+    
+    
+    # -----------------------------------------------------------------------
     def get_emails(self):
         """Return the email addresses associated with this contact."""
         
index 5ed9d21..4f90ae9 100644 (file)
@@ -91,22 +91,24 @@ class Friend():
                 self._add(key, value)
      
     def update_contact(self, contact, overwrite=False):
-        """
-        Updates the contact with information from this object,
-        without overwriting unless overwrite is set to True.
-        """
+        """Updates the contact with information from this object,
+           without overwriting unless overwrite is set to True.
+           Returns flag indicating if anything *was* changed."""
         
-        # FIXME: currently we overwrite everything 
-        self._if_defined('photo-url', contact.set_photo)
-        self._if_defined('nickname', contact.set_nickname)
-        if self._multi_attributes.has_key('url'):
-            for url in self._multi_attributes['url']:
-                contact.add_url(url)
-
         def fixme(arg):
             pass
             #print "FIXME - birthday date needs to be parsed/fixed %s before calling contact.set_birthday" % arg
-        self._if_defined('bday', fixme)
+
+        updated = False
+        if overwrite or contact.get_photo() is None:    updated += self._if_defined('photo-url', contact.set_photo)
+        if overwrite or contact.get_nickname() is None: updated += self._if_defined('nickname', contact.set_nickname)
+        if overwrite or contact.get_birthday() is None: updated += self._if_defined('bday', fixme)
+        if self._multi_attributes.has_key('url'):
+            for url in self._multi_attributes['url']:
+                updated += contact.add_url(url)
+                
+        return updated
+
 
     # private helpers -----------------------
     #
@@ -125,8 +127,7 @@ class Friend():
         return False
     
     def _if_defined(self, key, callback):
-        if self._attributes.has_key(key):
-            callback(self._attributes[key])
+        return self._attributes.has_key(key) and callback(self._attributes[key]) or False
     
     def _has(self, key):
         return self._attributes.has_key(key) or self._multi_attributes.has_key(key)
index 804f1be..9197b52 100644 (file)
@@ -123,7 +123,9 @@ class Hermes:
         """Update the given contact with information from the given friend."""
         
         print "updating contact ", contact, " with friend ", friend
-        self.updated.append(contact)
+        if friend.update_contact(contact, resync):
+            self.updated.append(contact)
+
         self.matched.append(contact)
         if friend.get_source() is not None:
             contact.add_mapping(friend.get_source())