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 18:15:38 +0000 (19:15 +0100)
committerAndrew Flegg <andrew@bleb.org>
Wed, 9 Jun 2010 18:15:38 +0000 (19:15 +0100)
package/src/org/maemo/hermes/engine/contact.py
package/src/org/maemo/hermes/engine/hermes.py
package/src/org/maemo/hermes/engine/service.py
package/src/org/maemo/hermes/gui/contactview.py
package/src/org/maemo/hermes/gui/gtkui.py

index e9f36fe..b9a49d2 100644 (file)
@@ -78,7 +78,7 @@ class Contact:
     def get_econtact(self):
         """Return the EContact which backs this contact."""
         
-        return self._econtact
+        return self._contact
     
     
     # -----------------------------------------------------------------------
index fd19358..d60849e 100644 (file)
@@ -16,13 +16,13 @@ class Hermes:
 
     
     # -----------------------------------------------------------------------
-    def __init__(self, services, gui_progress):
-        """Constructor. Passed a list of services, and a callback method
-           which must implement the following API.
-                              
-             progress(i, j) - the application is currently processing friend 'i' of
-                              'j'. Should be used to provide the user a progress bar.
-        """
+    def __init__(self, services, gui_progress=None):
+        """Constructor. Passed a list of services, and a            
+           method which will be invoked with three arguments:
+                str    Name of current step
+                int    Current position
+                int    Maximum value of position."""
+
         
         # -- These fields are currently part of the API...
         #
@@ -35,7 +35,7 @@ class Hermes:
         # -- Other initialisation...
         #
         self._services = services
-        self._progress = gui_progress
+        self._progress = gui_progress or (lambda msg, i, j: None)
     
     
     # -----------------------------------------------------------------------
@@ -43,7 +43,7 @@ class Hermes:
         """Load information on the authenticated user's friends. Synchronise Facebook
            profiles to contact database. If resync is false, no existing information
            will be overwritten."""
-
+           
         class FakeContact():
             def get_name(self):
                 return "Fredrik Wendt"
@@ -65,20 +65,31 @@ class Hermes:
     
     # -----------------------------------------------------------------------
     def run_alt(self, overwrite_existing_fields=False):
+        self._progress("Reading contacts...", 1, 10000)
+        
         contacts = []
         self.addresses = evolution.ebook.open_addressbook('default')
         for contact in self.addresses.get_all_contacts():
             contacts.append(Contact(self.addresses, contact))
 
+        # work out progress bar info
+        total_contacts = len(contacts) * len(self._services)
+        total_ticks    = 6 * total_contacts # Number of distinct loops below
+
         # warm up
+        current_tick = 1
         for service in self._services:
             print "pre-process:", service.get_id()
             for contact in contacts:
+                self._progress("Pre-processing contacts...", current_tick, total_ticks)
+                current_tick += 1
                 service.pre_process_contact(contact)
                 
         # fetch data
         for service in self._services:
             print "process_friends:", service.get_id()
+            self._progress("Reading friends...", current_tick, total_ticks)
+            current_tick += len(contacts)
             service.process_friends()
         
         # combine results into one friend
@@ -86,6 +97,8 @@ class Hermes:
             result = Friend()
             for service in self._services:
                 print "process_contact:", service.get_id()
+                self._progress("Processing contacts...", current_tick, total_ticks)
+                current_tick += 1
                 friend = service.process_contact(contact)
                 if friend:
                     contact.add_mapping(service.get_id())
@@ -99,18 +112,31 @@ class Hermes:
         # give services a chance to create new contacts
         for service in self._services:
             print "create_contacts:", service.get_id()
-            for friend in service.create_contacts():
+            to_create = service.get_friends_to_create_contacts_for()
+            tick_increment = len(contacts) / (len(to_create) or 1)
+            print tick_increment, to_create
+            for friend in to_create:
+                self._progress("Creating contacts...", current_tick, total_ticks)
+                current_tick += tick_increment
                 self.create_contact_from_friend(friend)
                 
         # finalisation
         for service in self._services:
             print "finalize:", service.get_id()
+            self._progress("Finalising...", current_tick, total_ticks)
+            current_tick += len(contacts)
             service.finalise(self.updated, overwrite_existing_fields)
             
         # commit changes
+        tick_increment = total_contacts / (len(self.updated) or 1)
+        print tick_increment, self.updated
         for contact in self.updated:
             print "committing changes to:", contact.get_name(), contact
+            self._progress("Saving changes...", current_tick, total_ticks)
+            current_tick += tick_increment
             self.addresses.commit_contact(contact.get_econtact())
+            
+        self._progress('Finished', 1, -1)
         
 
     # -----------------------------------------------------------------------
@@ -132,7 +158,7 @@ class Hermes:
         econtact.props.family_name = friend['last_name']
         contact = Contact(self.addresses, econtact)
                 
-        self.addresses.add_contact(contact)
+        self.addresses.add_contact(contact.get_econtact())
         self.update_contact(contact, friend)
         
         print "Created [%s]" % (contact.get_name())
index f8bfee7..3d7d8bb 100644 (file)
@@ -61,14 +61,6 @@ class Service:
 
 
     # -----------------------------------------------------------------------
-    def create_contacts(self):
-        """Return a list of friends which should have contacts created. This
-           should expected by the user, and optional."""
-           
-        return []
-
-
-    # -----------------------------------------------------------------------
     def finalise(self, updated, overwrite=False):
         """Once all contacts have been processed, allows for any tidy-up/additional
            enrichment. If any contacts are updated at this stage, 'updated' should
index d9c50e5..f941cbb 100644 (file)
@@ -30,7 +30,7 @@ class ContactView(hildon.PannableArea):
         icons    = {}
         services = set([])
         for contact in self.contacts:
-            services |= contact.get_mapped_to()
+            services |= contact.get_mappings()
 
         for service in sorted(services):
             columns.append(gtk.gdk.Pixbuf)
@@ -67,7 +67,7 @@ class ContactView(hildon.PannableArea):
                 
             row = [pixbuf, contact.get_name(), ]
             for service in services:
-                row.append(service in contact.get_mapped_to() and icons[service] or None)
+                row.append(service in contact.get_mappings() and icons[service] or None)
                 
             row.append(contact)
             self.treestore.append(row)
index 6804d45..3c09a5f 100644 (file)
@@ -65,12 +65,15 @@ class HermesGUI(WimpWorks):
             saved = self.do_accounts()
             if saved == gtk.RESPONSE_DELETE_EVENT:
                 return
+            
+        print "doing sync", main
         
         if main:
             self.main_window.set_property('sensitive', False)
             thread.start_new_thread(self.sync, (widget, force, False))
         else:
             try:
+                self.progress('', 0, 0)
                 services = []
                 for provider in enabled:
                     services.append(provider.service(self))
@@ -207,31 +210,30 @@ class HermesGUI(WimpWorks):
                       
                         
     # -----------------------------------------------------------------------
-    def progress(self, i, j, main = False):
+    def progress(self, msg, i, j, main = False):
         """Part of the GUI callback API."""
 
         if main:
             if i == 0:
                 self.progressbar = gtk.ProgressBar()
-                self.progressnote = gtk.Dialog(_("Fetching friends' info"), self.main_window)
+                self.progressnote = gtk.Dialog(_("Initialising connections"), self.main_window)
                 self.progressnote.vbox.add(self.progressbar)
                 hildon.hildon_gtk_window_set_progress_indicator(self.progressnote, 1)
                
                 self.progressnote.show_all()
               
             elif i < j:
-                if i == 1:
-                    self.progressnote.set_title(_("Updating contacts"))
-                    hildon.hildon_gtk_window_set_progress_indicator(self.progressnote, 0)
+                self.progressnote.set_title(_(msg))
+                hildon.hildon_gtk_window_set_progress_indicator(self.progressnote, 0)
                 
                 self.progressbar.set_fraction(float(i) / float(j))
               
             else:
                 self.progressnote.destroy()
               
-            print i,j
+            print msg, i,j
         else:
-            gobject.idle_add(self.progress, i, j, True)
+            gobject.idle_add(self.progress, msg, i, j, True)
 
        
     # -----------------------------------------------------------------------

Terms of Use    Privacy Policy    Contribution Guidelines    Feedback

Powered By GForge Collaborative Development Environment