X-Git-Url: http://git.maemo.org/git/?p=theonering;a=blobdiff_plain;f=src%2Fchannel%2Fcontact_list.py;h=f82c090d899f625549591b25ef53c843941fb996;hp=a385fbcd3c351060ecdab08abea356fae6ae1c1e;hb=cd56d4ab7a3beaa59e8ef4a5d6c2624419038fee;hpb=c70897618016a59403600936620448b35d0a9df2 diff --git a/src/channel/contact_list.py b/src/channel/contact_list.py index a385fbc..f82c090 100644 --- a/src/channel/contact_list.py +++ b/src/channel/contact_list.py @@ -1,10 +1,10 @@ -import weakref import logging import telepathy import util.go_utils as gobject_utils import util.coroutines as coroutines +import gtk_toolbox import handle @@ -21,7 +21,6 @@ class AbstractListChannel( telepathy.server.ChannelTypeContactList.__init__(self, connection, h) telepathy.server.ChannelInterfaceGroup.__init__(self) - self._conn_ref = weakref.ref(connection) self._session = connection.session @@ -32,31 +31,44 @@ class AllContactsListChannel(AbstractListChannel): def __init__(self, connection, h): AbstractListChannel.__init__(self, connection, h) - self._session.addressbook.updateSignalHandle.register_sink( - self._on_contacts_refreshed + self._callback = coroutines.func_sink( + coroutines.expand_positional( + self._on_contacts_refreshed + ) + ) + self._session.addressbook.updateSignalHandler.register_sink( + self._callback ) self.GroupFlagsChanged(0, 0) - @coroutines.func_sink - @coroutines.expand_positional + addressbook = connection.session.addressbook + contacts = addressbook.get_contacts() + self._process_refresh(addressbook, contacts, []) + + @gtk_toolbox.log_exception(_moduleLogger) + def Close(self): + telepathy.server.ChannelTypeContactList.Close(self) + self.remove_from_connection() + self._session.addressbook.updateSignalHandler.unregister_sink( + self._callback + ) + @gobject_utils.async + @gtk_toolbox.log_exception(_moduleLogger) def _on_contacts_refreshed(self, addressbook, added, removed, changed): - """ - @todo This currently filters out people not yet added to the contact - list. Something needs to be done about those - @todo This currently does not handle people with multiple phone - numbers, yay that'll be annoying to resolve - """ - connection = self._conn_ref() + self._process_refresh(addressbook, added, removed) + + def _process_refresh(self, addressbook, added, removed): + connection = self._conn handlesAdded = [ - handle.create_handle(connection, "contact", contactId) + handle.create_handle(connection, "contact", contactId, phoneNumber) for contactId in added - if contactId + for (phoneType, phoneNumber) in addressbook.get_contact_details(contactId) ] handlesRemoved = [ - handle.create_handle(connection, "contact", contactId) + handle.create_handle(connection, "contact", contactId, phoneNumber) for contactId in removed - if contactId + for (phoneType, phoneNumber) in addressbook.get_contact_details(contactId) ] message = "" actor = 0