Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Hermes
Summary Lists News SCM
authorFredrik Wendt <fredrik@wendt.se>
Sat, 5 Jun 2010 21:22:07 +0000 (23:22 +0200)
committerFredrik Wendt <fredrik@wendt.se>
Sat, 5 Jun 2010 21:22:07 +0000 (23:22 +0200)
Signed-off-by: Fredrik Wendt <fredrik@wendt.se>

package/src/org/maemo/hermes/engine/friend.py [new file with mode: 0644]

diff --git a/package/src/org/maemo/hermes/engine/friend.py b/package/src/org/maemo/hermes/engine/friend.py
new file mode 100644 (file)
index 0000000..736fae2
--- /dev/null
@@ -0,0 +1,100 @@
+class Friend():
+    
+    def __init__(self, name, source=None):
+        """ source is source service, such as LinkedIn """
+        self._attributes = { "fn": name }
+        self._multi_attributes = {}
+        self._source = source 
+        
+    def __unicode__(self):
+        return self.__repr__()
+    
+    def __repr__(self):
+        return "Friend %s" % self._attributes['fn']
+    
+    # public accessors -----------------
+    
+    def get_name(self):
+        return self._attributes['fn']
+    
+    def add_url(self, url):
+        self._add('url', url)
+        
+    def is_empty(self):
+        for a in self._attributes:
+            return False
+        for a in self._multi_attributes:
+            return False
+        return True
+    
+    def has_birthday_date(self):
+        return self._has('bday')
+    
+    def set_name(self, name):
+        self._set('fn', name)
+    
+    def set_nickname(self, nickname):
+        self._set('nickname', nickname)
+        
+    def set_birthday_date(self, date):
+        self._set('bday', date)
+        
+    def set_photo_url(self, url):
+        self._set('photo-url', url)
+    
+    def update(self, other_friend):
+        """
+        Overwrites any attributes in this friend, with attributes from other_friend
+        """
+        
+        self._attributes.update(other_friend._attributes)
+        
+        for key in other_friend._multi_attributes.keys():
+            for value in other_friend._multi_attributes[key]:
+                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.
+        """
+        
+        # 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)
+
+    # private helpers -----------------------
+    #
+    def _if_defined(self, key, callback):
+        if self._attributes.has_key(key):
+            callback(self._attributes[key])
+    
+    def _set(self, key, value):
+        if value is not None:
+#            print "%s SET %s to %s" % (self, key, value)
+            self._attributes[key] = value
+    
+    def _add(self, key, value):
+        if value is not None:
+            if not self._multi_attributes.has_key(key):
+                self._multi_attributes[key] = []
+#            print "%s ADD %s to %s" % (self, key, value)
+            self._multi_attributes[key].append(value)
+    
+    def _has(self, key):
+        return self._attributes.has_key(key) or self._multi_attributes.has_key(key)
+    
+    def _contains(self, key, value):
+        if self._attributes.has_key(key):
+            return value == self._attributes[key]
+        if self._multi_attributes.has_key(key):
+            return value in self._multi_attributes[key]
+        return False

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment