From: Ed Page Date: Wed, 30 Sep 2009 02:57:39 +0000 (-0500) Subject: Adding a contacts cache manager with callbacks X-Git-Url: http://git.maemo.org/git/?p=theonering;a=commitdiff_plain;h=c56dadd27b0672e8929b39d9a7f5de7f9f76c40d Adding a contacts cache manager with callbacks --- diff --git a/src/gvoice/addressbook.py b/src/gvoice/addressbook.py new file mode 100644 index 0000000..e796583 --- /dev/null +++ b/src/gvoice/addressbook.py @@ -0,0 +1,38 @@ +#!/usr/bin/python + + +import logging + + +_moduleLogger = logging.getLogger("gvoice.addressbook") + + +class Addressbook(object): + + def __init__(self, backend): + self._backend = backend + self._contacts = {} + + def clear_cache(self): + self._contacts.clear() + + def get_contacts(self): + self._populate_contacts() + return self._contacts.iterkeys() + + def get_contact_details(self, contactId): + self._populate_contacts() + self._populate_contact_details(contactId) + return self._contacts[contactId] + + def _populate_contacts(self): + if self._contacts: + return + contacts = self._backend.get_contacts() + for contactId, contactName in contacts: + self._contacts[contactId] = None + + def _populate_contact_details(self, contactId): + if self._contacts[contactId] is not None: + return + self._contacts[contactId] = self._backend.get_contact_details(contactId)