Log In
New Account
  
Home My Page Project Cloud Code Snippets Project Openings Hermes
Summary Lists News SCM
authorFredrik Wendt <fredrik@wendt.se>
Tue, 8 Jun 2010 20:12:33 +0000 (21:12 +0100)
committerFredrik Wendt <fredrik@wendt.se>
Tue, 8 Jun 2010 20:12:33 +0000 (21:12 +0100)
Signed-off-by: Fredrik Wendt <fredrik@wendt.se>

package/src/org/maemo/hermes/engine/hermes.py
package/src/org/maemo/hermes/gui/gtkui.py

index a37a9a8..50271cd 100644 (file)
@@ -1,3 +1,6 @@
+from org.maemo.hermes.engine.friend import Friend
+import evolution
+
 class Hermes:
     """Encapsulate the process of syncing online friends' information with the
        Evolution contacts' database. This should be used as follows:
 class Hermes:
     """Encapsulate the process of syncing online friends' information with the
        Evolution contacts' database. This should be used as follows:
@@ -22,10 +25,10 @@ class Hermes:
         
         # -- These fields are currently part of the API...
         #
         
         # -- These fields are currently part of the API...
         #
-        self.updated   = []
-        self.matched   = []
+        self.updated = []
+        self.matched = []
         self.unmatched = []
         self.unmatched = []
-        self.friends   = {}
+        self.friends = {}
         self.addresses = None
         
         # -- Other initialisation...
         self.addresses = None
         
         # -- Other initialisation...
@@ -35,7 +38,7 @@ class Hermes:
     
     
     # -----------------------------------------------------------------------
     
     
     # -----------------------------------------------------------------------
-    def run(self, resync = False):
+    def run(self, resync=False):
         """Load information on the authenticated user's friends. Synchronise Facebook
            profiles to contact database. If resync is false, no existing information
            will be overwritten."""
         """Load information on the authenticated user's friends. Synchronise Facebook
            profiles to contact database. If resync is false, no existing information
            will be overwritten."""
@@ -44,7 +47,7 @@ class Hermes:
             def get_name(self):
                 return "Fredrik Wendt"
             def get_emails(self):
             def get_name(self):
                 return "Fredrik Wendt"
             def get_emails(self):
-                return ["fredrik@wendt.se","maemohermes@wendt.se"]
+                return ["fredrik@wendt.se", "maemohermes@wendt.se"]
             def get_photo(self):
                 return None
         self.matched = [FakeContact()]
             def get_photo(self):
                 return None
         self.matched = [FakeContact()]
@@ -55,33 +58,57 @@ class Hermes:
 #        self._sync_job.get_updated_contacts()
 #        self._sync_job.get_matched_contacts()
         pass
 #        self._sync_job.get_updated_contacts()
 #        self._sync_job.get_matched_contacts()
         pass
+    
+    
+    # -----------------------------------------------------------------------
+    def run_alt(self, overwrite_existing_fields=False):
+        print "+++ Syncing contacts..."
+        self.addresses = evolution.ebook.open_addressbook('default')
+        print "+++ Contact store created..."
+        contacts = self.addresses.get_all_contacts()
 
 
+        # warm up
+        for service in self._services:
+            for contact in contacts:
+                service.pre_process_contact(contact)
+                
+        # fetch data
+        for service in self._services:
+            service.process_friends()
+        
+        # combine results into one friend
+        for contact in contacts:
+            result = Friend()
+            for service in self._services:
+                friend = service.process_contact(contact)
+                if (friend):
+                    friend.decorate(result)
+            
+            self.update_contact(friend, overwrite_existing_fields)
+        
 
     # -----------------------------------------------------------------------
 
     # -----------------------------------------------------------------------
-    def update_contact(self, contact, friend, resync = False):
+    def update_contact(self, contact, friend, resync=False):
         """Update the given contact with information from the given friend."""
         
         """Update the given contact with information from the given friend."""
         
-        pass
-    
-"""        
- friends = ()
- for service in services:
-   for friend in service.get_friends():
-     friends.add(friend)
+        print "updating contact ", contact, " with friend ", friend
+
 
 
- all_contacts = get_contacts_as_set()
- contacts = set()
- updated_contacts = set()
- for econtact in addressbook.get_all_contacts():
-   contact = Contact(addressbook, econtact)
-   contacts.add(contact)
-   for service in something.get_services_by_prioritisation():
-     if service.process_contact(contact):
-       updated_contacts.add(contact)
+    def create_contact_from_friend(self, friend):
+        contact = evolution.ebook.EContact()
+        contact.props.full_name = friend['name']
+        contact.props.given_name = friend['first_name']
+        contact.props.family_name = friend['last_name']
+        
+        self.update_contact(contact, friend)
+        
+        self.addresses.add_contact(contact)
+        self.updated.append(contact)
+        self.addresses.commit_contact(contact)
+        
+        print "Created [%s]" % (contact.get_name())
+        self.matched.append(contact)
 
 
- for service in something.get_services_by_prioritisation():
-   service.finalise(updated_contacts)
 
 
- for contact in updated_contacts:
-   contact.save()
-"""
+    def commit(self):
+        self.store.close()
index 0771554..90bdd30 100644 (file)
@@ -78,7 +78,7 @@ class HermesGUI(WimpWorks):
                 print services
                 
                 hermes = Hermes(services, self.progress)
                 print services
                 
                 hermes = Hermes(services, self.progress)
-                hermes.run()
+                hermes.run_alt(force)
                 gobject.idle_add(self.open_summary, hermes)
         
             except urllib2.HTTPError, e:
                 gobject.idle_add(self.open_summary, hermes)
         
             except urllib2.HTTPError, e:

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment