2 """Encapsulate the process of syncing online friends' information with the
3 Evolution contacts' database. This should be used as follows:
5 * Initialise, passing in a GUI callback.
7 * Retrieve information on changes effected.
8 * Call update_contact to enact manual mapping.
10 Copyright (c) Andrew Flegg <andrew@bleb.org> 2010.
11 Released under the Artistic Licence."""
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.
19 progress(i, j) - the application is currently processing friend 'i' of
20 'j'. Should be used to provide the user a progress bar.
23 # -- These fields are currently part of the API...
31 # -- Other initialisation...
33 self._services = services
34 self._progress = gui_progress
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."""
45 return "Fredrik Wendt"
47 return ["fredrik@wendt.se","maemohermes@wendt.se"]
50 def get_mapped_to(self):
51 return set(["facebook", "gravatar"])
52 self.matched = [FakeContact()]
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()
62 # -----------------------------------------------------------------------
63 def update_contact(self, contact, friend, resync = False):
64 """Update the given contact with information from the given friend."""
66 friend.update_contact(contact, resync)
70 for service in services:
71 for friend in service.get_friends():
74 all_contacts = get_contacts_as_set()
76 updated_contacts = set()
77 for econtact in addressbook.get_all_contacts():
78 contact = Contact(addressbook, econtact)
80 for service in something.get_services_by_prioritisation():
81 if service.process_contact(contact):
82 updated_contacts.add(contact)
84 for service in something.get_services_by_prioritisation():
85 service.finalise(updated_contacts)
87 for contact in updated_contacts: