Update contactview to show photo, name and then the set of icons
[hermes] / package / src / org / maemo / hermes / engine / hermes.py
1 class Hermes:
2     """Encapsulate the process of syncing online friends' information with the
3        Evolution contacts' database. This should be used as follows:
4        
5          * Initialise, passing in a GUI callback.
6          * Call Syncjob.
7          * Retrieve information on changes effected.
8          * Call update_contact to enact manual mapping.
9          
10        Copyright (c) Andrew Flegg <andrew@bleb.org> 2010.
11        Released under the Artistic Licence."""
12
13     
14     # -----------------------------------------------------------------------
15     def __init__(self, services, gui_progress):
16         """Constructor. Passed a list of services, and a callback method
17            which must implement the following API.
18                               
19              progress(i, j) - the application is currently processing friend 'i' of
20                               'j'. Should be used to provide the user a progress bar.
21         """
22         
23         # -- These fields are currently part of the API...
24         #
25         self.updated   = []
26         self.matched   = []
27         self.unmatched = []
28         self.friends   = {}
29         self.addresses = None
30         
31         # -- Other initialisation...
32         #
33         self._services = services
34         self._progress = gui_progress
35     
36     
37     # -----------------------------------------------------------------------
38     def run(self, resync = False):
39         """Load information on the authenticated user's friends. Synchronise Facebook
40            profiles to contact database. If resync is false, no existing information
41            will be overwritten."""
42
43         class FakeContact():
44             def get_name(self):
45                 return "Fredrik Wendt"
46             def get_emails(self):
47                 return ["fredrik@wendt.se","maemohermes@wendt.se"]
48             def get_photo(self):
49                 return None
50             def get_mapped_to(self):
51                 return set(["facebook", "gravatar"])
52         self.matched = [FakeContact()]
53  
54 #        self._sync_job = SyncJob(services, [FakeContact()], self.progress)
55 #        self._sync_job.run()
56 #        self._sync_job.get_unmatched_friends()
57 #        self._sync_job.get_updated_contacts()
58 #        self._sync_job.get_matched_contacts()
59         pass
60
61
62     # -----------------------------------------------------------------------
63     def update_contact(self, contact, friend, resync = False):
64         """Update the given contact with information from the given friend."""
65         
66         friend.update_contact(contact, resync)
67     
68 """        
69  friends = ()
70  for service in services:
71    for friend in service.get_friends():
72      friends.add(friend)
73
74  all_contacts = get_contacts_as_set()
75  contacts = set()
76  updated_contacts = set()
77  for econtact in addressbook.get_all_contacts():
78    contact = Contact(addressbook, econtact)
79    contacts.add(contact)
80    for service in something.get_services_by_prioritisation():
81      if service.process_contact(contact):
82        updated_contacts.add(contact)
83
84  for service in something.get_services_by_prioritisation():
85    service.finalise(updated_contacts)
86
87  for contact in updated_contacts:
88    contact.save()
89 """