-import weakref
import logging
import telepathy
import util.go_utils as gobject_utils
import util.coroutines as coroutines
+import gtk_toolbox
import handle
telepathy.server.ChannelTypeContactList.__init__(self, connection, h)
telepathy.server.ChannelInterfaceGroup.__init__(self)
- self._conn_ref = weakref.ref(connection)
- self._addessbook = connection.addressbook
+ self._session = connection.session
class AllContactsListChannel(AbstractListChannel):
def __init__(self, connection, h):
AbstractListChannel.__init__(self, connection, h)
- self._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
)
- @coroutines.func_sink
- @coroutines.expand_positional
+ self.GroupFlagsChanged(0, 0)
+
+ addressbook = connection.session.addressbook
+ contacts = addressbook.get_contacts()
+ self._process_refresh(addressbook, contacts, [])
+
+ @gtk_toolbox.log_exception(_moduleLogger)
+ def Close(self):
+ self.close()
+
+ def close(self):
+ self._session.addressbook.updateSignalHandler.unregister_sink(
+ self._callback
+ )
+ self._callback = None
+
+ telepathy.server.ChannelTypeContactList.Close(self)
+ self.remove_from_connection()
+ self._prop_getters = None # HACK to get around python-telepathy memory leaks
+
@gobject_utils.async
+ @gtk_toolbox.log_exception(_moduleLogger)
def _on_contacts_refreshed(self, addressbook, added, removed, changed):
- 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
+ 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
+ for (phoneType, phoneNumber) in addressbook.get_contact_details(contactId)
]
message = ""
actor = 0
_moduleLogger.warn("Unsuported type %s" % h.get_name())
elif h.get_name() == 'allow':
# A group of contacts who may send you messages
- # @todo This would be cool to support
+ # @todo Allow-List would be cool to support
_moduleLogger.warn("Unsuported type %s" % h.get_name())
elif h.get_name() == 'deny':
# A group of contacts who may not send you messages
- # @todo This would be cool to support
+ # @todo Deny-List would be cool to support
_moduleLogger.warn("Unsuported type %s" % h.get_name())
elif h.get_name() == 'stored':
# On protocols where the user's contacts are stored, this contact list