Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Hermes
Summary Lists News SCM
authorAndrew Flegg <andrew@bleb.org>
Wed, 9 Jun 2010 21:38:54 +0000 (22:38 +0100)
committerAndrew Flegg <andrew@bleb.org>
Wed, 9 Jun 2010 21:38:54 +0000 (22:38 +0100)
1  2 
package/src/org/maemo/hermes/engine/friend.py
package/src/org/maemo/hermes/engine/hermes.py

@@@ -5,12 -5,15 +5,15 @@@ class Friend()
         Released under the Artistic Licence."""
  
      
-     def __init__(self, name=None, source=None):
+     def __init__(self, name=None, source=None, props=None):
          """ source is source service, such as LinkedIn """
          self._attributes = {};
          if name: self._set('fn', name)
          self._multi_attributes = {}
-         self._source = source 
+         self._source = source
+         if props:
+             for key in props:
+                 self._set(key, props[key])
          
      def __getitem__(self, key):
          return self._safe_get(key)
@@@ -38,9 -41,6 +41,9 @@@
      def get_source(self):
          return self._source
      
 +    def set_source(self, source):
 +        self._source = source
 +    
      def get_nickname(self):
          return self._safe_get("nickname")
      
@@@ -44,8 -44,8 +44,8 @@@ class Hermes
          
          contacts = []
          self.address_book = self._get_address_book()
-         for contact in self.address_book.get_all_contacts():
-             contacts.append(Contact(self.address_book, contact))
+         for econtact in self.address_book.get_all_contacts():
+             contacts.append(self._create_contact_wrapper(econtact))
  
          # work out progress bar info
          total_contacts = len(contacts) * len(self._services)
              self._progress("Finalising...", current_tick, total_ticks)
              current_tick += len(contacts)
              service.finalise(self.updated, overwrite_existing_fields)
 -            self.friends[service.get_id] = service.get_unmatched_friends()
 +            for friend in service.get_unmatched_friends():
 +                friend.set_source(service.get_id())
 +                key = unicode(friend['name']).encode('trans') + "_" + service.get_id()
 +                self.friends[key] = friend
              
          # commit changes
          tick_increment = total_contacts / (len(self.updated) or 1)
  
      # -----------------------------------------------------------------------
      def create_contact_from_friend(self, friend):
-         econtact = evolution.ebook.EContact()
-         econtact.props.full_name = friend['name']
-         econtact.props.given_name = friend['first_name']
-         econtact.props.family_name = friend['last_name']
-         contact = Contact(self.address_book, econtact)
+         econtact = self._create_empty_contact(friend)
+         contact = self._create_contact_wrapper(econtact)
                  
          self.address_book.add_contact(contact.get_econtact())
          self.update_contact(contact, friend)
      # -----------------------------------------------------------------------
      def _get_address_book(self):
          return evolution.ebook.open_addressbook('default')
+     # -----------------------------------------------------------------------
+     def _create_empty_contact(self, friend):
+         econtact = evolution.ebook.EContact()
+         econtact.props.full_name = friend['name']
+         econtact.props.given_name = friend['first_name']
+         econtact.props.family_name = friend['last_name']
+     
+     # -----------------------------------------------------------------------
+     def _create_contact_wrapper(self, econtact):
+         return Contact(self.address_book, econtact)

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment