-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
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))
# -----------------------------------------------------------------------
except:
print "FAILED to get photo from URL %s" % url
return False
-
-
- # -----------------------------------------------------------------------
- def has_photo(self):
- # FIXME
- return False
# -----------------------------------------------------------------------
--- /dev/null
+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()
+"""
def get_matched_contacts(self):
- pass
+ return self._original_contacts
def _pre_process_contacts(self):
# -----------------------------------------------------------------------
def __init__(self, contacts):
- """Constructor. Passed a list of EContacts."""
+ """Constructor. Passed a list of Contacts."""
hildon.PannableArea.__init__(self)
self.contacts = contacts
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)
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
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()