Join up GUI, by adding 'Hermes' as a wrapper around Syncjob. This will
authorAndrew Flegg <andrew@bleb.org>
Mon, 7 Jun 2010 22:26:57 +0000 (23:26 +0100)
committerAndrew Flegg <andrew@bleb.org>
Mon, 7 Jun 2010 22:26:57 +0000 (23:26 +0100)
be responsible for dealing with the address book, and will present the
old API to gtkui. This means that further GUI refactoring is minimised.

package/src/org/maemo/hermes/engine/__init__.py
package/src/org/maemo/hermes/engine/contact.py
package/src/org/maemo/hermes/engine/hermes.py [new file with mode: 0644]
package/src/org/maemo/hermes/engine/syncjob.py
package/src/org/maemo/hermes/gui/contactview.py
package/src/org/maemo/hermes/gui/gtkui.py

index d896b86..e69de29 100644 (file)
@@ -1,55 +0,0 @@
-class Hermes:
-    """Encapsulate the process of syncing online friends' information with the
-       Evolution contacts' database. This should be used as follows:
-       
-         * Initialise, passing in a GUI callback.
-         * Call initialise_services().
-         * Call sync_contacts().
-         * Retrieve information on changes effected.
-         * Call update_contact to enact manual mapping.
-         
-       Copyright (c) Andrew Flegg <andrew@bleb.org> 2009.
-       Released under the Artistic Licence."""
-    
-    
-    # -----------------------------------------------------------------------
-    def __init__(self, gui_callback):
-        """Constructor. Passed a callback which must implement three informational
-           methods:
-           
-             need_auth() - called to indicate an external login is about to occur.
-                           The user should be informed.
-                           
-             block_for_auth(prompt = False) - prompt the user to take some action
-                                once they have successfully logged in via the
-                                external login. If 'prompt' is true, a text entry
-                                box will be shown and the user-entered value returned.
-                                If the user cancels the dialogue, None is returned.
-                              
-             progress(i, j) - the application is currently processing friend 'i' of
-                              'j'. Should be used to provide the user a progress bar.
-        """
-        
-        pass
-"""        
- friends = ()
- for service in services:
-   for friend in service.get_friends():
-     friends.add(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)
-
- for service in something.get_services_by_prioritisation():
-   service.finalise(updated_contacts)
-
- for contact in updated_contacts:
-   contact.save()
-"""
\ No newline at end of file
index 0b8cbd4..9fee7b2 100644 (file)
@@ -71,6 +71,15 @@ class Contact:
            versions of identifiers for this contact."""
            
         return self._identifiers
+
+
+    # -----------------------------------------------------------------------
+    def get_photo(self):
+        """Return the photo property, or None. The result is of type
+        EContactPhoto."""
+        
+        photo = self._contact.get_property('photo')
+        return cast(c_void_p(hash(photo)), POINTER(EContactPhoto))
     
     
     # -----------------------------------------------------------------------
@@ -110,12 +119,6 @@ class Contact:
         except:
             print "FAILED to get photo from URL %s" % url
             return False
-    
-    
-    # -----------------------------------------------------------------------
-    def has_photo(self):
-        # FIXME
-        return False
       
       
     # -----------------------------------------------------------------------
diff --git a/package/src/org/maemo/hermes/engine/hermes.py b/package/src/org/maemo/hermes/engine/hermes.py
new file mode 100644 (file)
index 0000000..a37a9a8
--- /dev/null
@@ -0,0 +1,87 @@
+class Hermes:
+    """Encapsulate the process of syncing online friends' information with the
+       Evolution contacts' database. This should be used as follows:
+       
+         * Initialise, passing in a GUI callback.
+         * Call Syncjob.
+         * Retrieve information on changes effected.
+         * Call update_contact to enact manual mapping.
+         
+       Copyright (c) Andrew Flegg <andrew@bleb.org> 2010.
+       Released under the Artistic Licence."""
+
+    
+    # -----------------------------------------------------------------------
+    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.
+        """
+        
+        # -- These fields are currently part of the API...
+        #
+        self.updated   = []
+        self.matched   = []
+        self.unmatched = []
+        self.friends   = {}
+        self.addresses = None
+        
+        # -- Other initialisation...
+        #
+        self._services = services
+        self._progress = gui_progress
+    
+    
+    # -----------------------------------------------------------------------
+    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."""
+
+        class FakeContact():
+            def get_name(self):
+                return "Fredrik Wendt"
+            def get_emails(self):
+                return ["fredrik@wendt.se","maemohermes@wendt.se"]
+            def get_photo(self):
+                return None
+        self.matched = [FakeContact()]
+#        self._sync_job = SyncJob(services, [FakeContact()], self.progress)
+#        self._sync_job.run()
+#        self._sync_job.get_unmatched_friends()
+#        self._sync_job.get_updated_contacts()
+#        self._sync_job.get_matched_contacts()
+        pass
+
+
+    # -----------------------------------------------------------------------
+    def update_contact(self, contact, friend, resync = False):
+        """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)
+
+ 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)
+
+ for service in something.get_services_by_prioritisation():
+   service.finalise(updated_contacts)
+
+ for contact in updated_contacts:
+   contact.save()
+"""
index 4c3429f..f35ebe1 100644 (file)
@@ -34,7 +34,7 @@ class SyncJob():
     
     
     def get_matched_contacts(self):
-        pass    
+        return self._original_contacts    
     
     
     def _pre_process_contacts(self):
index 569bb91..7c7def3 100644 (file)
@@ -14,7 +14,7 @@ class ContactView(hildon.PannableArea):
     
     # -----------------------------------------------------------------------
     def __init__(self, contacts):
-        """Constructor. Passed a list of EContacts."""
+        """Constructor. Passed a list of Contacts."""
         
         hildon.PannableArea.__init__(self)
         self.contacts = contacts
@@ -23,16 +23,15 @@ class ContactView(hildon.PannableArea):
             if not contact.get_name():
                 continue
               
-            photo = contact.get_property('photo')
-            pi = cast(c_void_p(hash(photo)), POINTER(EContactPhoto))
+            pi = contact.get_photo()
             pixbuf = None
-            if pi.contents.data.uri.startswith("image/"):
+            if pi and pi.contents.data.uri.startswith("image/"):
                 data = string_at(pi.contents.data.inlined.data, pi.contents.data.inlined.length)
                 pixbuf_loader = gtk.gdk.PixbufLoader()
                 pixbuf_loader.write(data)
                 pixbuf_loader.close()
                 pixbuf = pixbuf_loader.get_pixbuf()
-            elif pi.contents.data.uri.startswith("file://"):
+            elif pi and pi.contents.data.uri.startswith("file://"):
                 filename = pi.contents.data.uri[7:]
                 pixbuf = gtk.gdk.pixbuf_new_from_file(filename)
                   
index 255ee10..0771554 100644 (file)
@@ -11,7 +11,7 @@ from org.maemo.hermes.gui.mapcontact import MapContact
 from org.maemo.hermes.gui.accountsdialogue import AccountsDialogue
 from org.bleb.wimpworks import HildonMainScreenLayout
 from org.maemo.hermes.engine.syncjob import SyncJob
-#from hermes import Hermes ### FIXME This needs to be new
+from org.maemo.hermes.engine.hermes import Hermes
 
 class HermesGUI(WimpWorks):
     """Provides the GUI for Hermes, allowing the syncing of Facebook and
@@ -76,17 +76,10 @@ class HermesGUI(WimpWorks):
                     services.append(provider.service(self))
                     
                 print services
-                class FakeContact():
-                    def get_name(self):
-                        return "Fredrik Wendt"
-                    def get_emails(self):
-                        return ["fredrik@wendt.se","maemohermes@wendt.se"]
-                self._sync_job = SyncJob(services, [FakeContact()], self.progress)
-                self._sync_job.run()
-                self._sync_job.get_unmatched_friends()
-                self._sync_job.get_updated_contacts()
-                self._sync_job.get_matched_contacts()
-                raise Exception("TODO - implement syncing")
+                
+                hermes = Hermes(services, self.progress)
+                hermes.run()
+                gobject.idle_add(self.open_summary, hermes)
         
             except urllib2.HTTPError, e:
                 traceback.print_exc()