import telepathy
-import util.go_utils as gobject_utils
import util.coroutines as coroutines
import gtk_toolbox
import handle
_moduleLogger = logging.getLogger("channel.contact_list")
-class AbstractListChannel(
+class AllContactsListChannel(
telepathy.server.ChannelTypeContactList,
telepathy.server.ChannelInterfaceGroup,
):
- "Abstract Contact List channels"
-
- def __init__(self, connection, h):
- telepathy.server.ChannelTypeContactList.__init__(self, connection, h)
- telepathy.server.ChannelInterfaceGroup.__init__(self)
-
- self._session = connection.session
-
-
-class AllContactsListChannel(AbstractListChannel):
"""
The group of contacts for whom you receive presence
"""
- def __init__(self, connection, h):
- AbstractListChannel.__init__(self, connection, h)
+ def __init__(self, connection, manager, props, h):
+ try:
+ # HACK Older python-telepathy way
+ telepathy.server.ChannelTypeContactList.__init__(self, connection, h)
+ self._requested = props[telepathy.interfaces.CHANNEL_INTERFACE + '.Requested']
+ self._implement_property_get(
+ telepathy.interfaces.CHANNEL_INTERFACE,
+ {"Requested": lambda: self._requested}
+ )
+ except TypeError:
+ # HACK Newer python-telepathy way
+ telepathy.server.ChannelTypeContactList.__init__(self, connection, manager, props)
+ telepathy.server.ChannelInterfaceGroup.__init__(self)
+
+ self.__manager = manager
+ self.__props = props
+ self.__session = connection.session
+
self._callback = coroutines.func_sink(
coroutines.expand_positional(
self._on_contacts_refreshed
)
)
- self._session.addressbook.updateSignalHandler.register_sink(
+ self.__session.addressbook.updateSignalHandler.register_sink(
self._callback
)
+
self.GroupFlagsChanged(0, 0)
addressbook = connection.session.addressbook
contacts = addressbook.get_contacts()
self._process_refresh(addressbook, contacts, [])
+ def get_props(self):
+ # HACK Older python-telepathy doesn't provide this
+ _immutable_properties = {
+ 'ChannelType': telepathy.server.interfaces.CHANNEL_INTERFACE,
+ 'TargetHandle': telepathy.server.interfaces.CHANNEL_INTERFACE,
+ 'Interfaces': telepathy.server.interfaces.CHANNEL_INTERFACE,
+ 'TargetHandleType': telepathy.server.interfaces.CHANNEL_INTERFACE,
+ 'TargetID': telepathy.server.interfaces.CHANNEL_INTERFACE,
+ 'Requested': telepathy.server.interfaces.CHANNEL_INTERFACE
+ }
+ props = dict()
+ for prop, iface in _immutable_properties.items():
+ props[iface + '.' + prop] = \
+ self._prop_getters[iface][prop]()
+ return props
+
@gtk_toolbox.log_exception(_moduleLogger)
def Close(self):
- telepathy.server.ChannelTypeContactList.Close(self)
- self.remove_from_connection()
- self._session.addressbook.updateSignalHandler.unregister_sink(
+ self.close()
+
+ def close(self):
+ self.__session.addressbook.updateSignalHandler.unregister_sink(
self._callback
)
+ self._callback = None
+
+ telepathy.server.ChannelTypeContactList.Close(self)
+ if self.__manager.channel_exists(self.__props):
+ # HACK Older python-telepathy requires doing this manually
+ self.__manager.remove_channel(self)
+ self.remove_from_connection()
- @gobject_utils.async
@gtk_toolbox.log_exception(_moduleLogger)
def _on_contacts_refreshed(self, addressbook, added, removed, changed):
self._process_refresh(addressbook, added, removed)
)
-def create_contact_list_channel(connection, h):
+def create_contact_list_channel(connection, manager, props, h):
if h.get_name() == 'subscribe':
# The group of contacts for whom you receive presence
ChannelClass = AllContactsListChannel
ChannelClass = AllContactsListChannel
else:
raise TypeError("Unknown list type : " + h.get_name())
- return ChannelClass(connection, h)
+ return ChannelClass(connection, manager, props, h)