X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fevo_backend.py;h=4487b660c09b1a5fa12cc90c87c4377bb8a0fca0;hb=043d160a574f6743a530c9d16f93c4338cfd340a;hp=96d921af47d488ac13c21f996a4b7be7eb85d93b;hpb=d2030f62d6d158c8f64f2741790ca24bc0a493b4;p=gc-dialer diff --git a/src/evo_backend.py b/src/evo_backend.py index 96d921a..4487b66 100644 --- a/src/evo_backend.py +++ b/src/evo_backend.py @@ -1,6 +1,6 @@ #!/usr/bin/python -# GC Dialer - Front end for Google's Grand Central service. +# DialCentral - Front end for Google's Grand Central service. # Copyright (C) 2008 Eric Warnke ericew AT gmail DOT com # # This library is free software; you can redistribute it and/or @@ -30,15 +30,28 @@ except ImportError: class EvolutionAddressBook(object): + """ + @note Combined the factory and the addressbook for "simplicity" and "cutting down" the number of allocations/deallocations + """ def __init__(self, bookId = None): if not self.is_supported(): return self._phoneTypes = None - self._bookId = bookId if bookId is not None else self.get_addressbooks().next()[1] - self._book = evolution.ebook.open_addressbook(self._bookId[1]) - + if bookId is not None: + self._bookId = bookId + else: + try: + self._bookId = [ + bookData[1] + for bookData in self.get_addressbooks() + ][0] + except IndexError: + global evolution + evolution = None + self._book = evolution.ebook.open_addressbook(self._bookId) + @classmethod def is_supported(cls): return evolution is not None @@ -50,14 +63,26 @@ class EvolutionAddressBook(object): if not self.is_supported(): return + if len(evolution.ebook.list_addressbooks()) == 0 and evolution.ebook.open_addressbook('default') is not None: + # It appears that Maemo's e-d-s does not always list the default addressbook, so we're faking it being listed + yield self, "default", "Maemo" + for bookId in evolution.ebook.list_addressbooks(): - yield self, bookId, bookId[0] - + yield self, bookId[1], bookId[0] + def open_addressbook(self, bookId): self._bookId = bookId - self._book = evolution.ebook.open_addressbook(self._bookId[1]) + self._book = evolution.ebook.open_addressbook(self._bookId) return self + @staticmethod + def contact_source_short_name(contactId): + return "Evo" + + @staticmethod + def factory_name(): + return "Evolution" + def get_contacts(self): """ @returns Iterable of (contact id, contact name) @@ -66,13 +91,13 @@ class EvolutionAddressBook(object): return for contact in self._book.get_all_contacts(): - yield contact.get_uid(), contact.props.full_name - + yield str(contact.get_uid()), contact.props.full_name + def get_contact_details(self, contactId): """ @returns Iterable of (Phone Type, Phone Number) """ - contact = self._book.get_contact(contactId) + contact = self._book.get_contact(int(contactId)) if self._phoneTypes is None and contact is not None: self._phoneTypes = [pt for pt in dir(contact.props) if "phone" in pt.lower()] @@ -82,7 +107,8 @@ class EvolutionAddressBook(object): if isinstance(phoneNumber, str): yield phoneType, phoneNumber -def print_addressbooks(): + +def print_evobooks(): """ Included here for debugging.