6 import util.coroutines as coroutines
11 _moduleLogger = logging.getLogger("channel.contact_list")
14 class AllContactsListChannel(
15 tp.ChannelTypeContactList,
16 tp.ChannelInterfaceGroup,
19 The group of contacts for whom you receive presence
22 def __init__(self, connection, manager, props, listHandle):
23 tp.ChannelTypeContactList.__init__(self, connection, manager, props)
24 tp.ChannelInterfaceGroup.__init__(self)
26 self.__manager = manager
28 self.__session = connection.session
29 self.__listHandle = listHandle
31 self._callback = coroutines.func_sink(
32 coroutines.expand_positional(
33 self._on_contacts_refreshed
36 self.__session.addressbook.updateSignalHandler.register_sink(
40 self.GroupFlagsChanged(0, 0)
42 addressbook = connection.session.addressbook
43 contacts = addressbook.get_numbers()
44 self._process_refresh(addressbook, set(contacts), set())
47 @gtk_toolbox.log_exception(_moduleLogger)
52 _moduleLogger.debug("Closing contact list")
53 self.__session.addressbook.updateSignalHandler.unregister_sink(
58 tp.ChannelTypeContactList.Close(self)
59 self.remove_from_connection()
61 @gtk_toolbox.log_exception(_moduleLogger)
62 def GetLocalPendingMembersWithInfo(self):
65 @gtk_toolbox.log_exception(_moduleLogger)
66 def _on_contacts_refreshed(self, addressbook, added, removed, changed):
67 self._process_refresh(addressbook, added, removed)
69 def _process_refresh(self, addressbook, added, removed):
71 "%s Added: %r, Removed: %r" % (self.__listHandle.get_name(), len(added), len(removed))
73 connection = self._conn
75 handle.create_handle(connection, "contact", contactNumber)
76 for contactNumber in added
79 handle.create_handle(connection, "contact", contactNumber)
80 for contactNumber in removed
84 reason = telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE
87 handlesAdded, handlesRemoved,
95 # The group of contacts for whom you receive presence
96 'subscribe': AllContactsListChannel,
97 # The group of contacts who may receive your presence
98 'publish': AllContactsListChannel,
99 # A group of contacts who are on the publish list but are temporarily
100 # disallowed from receiving your presence
101 # This doesn't make sense to support
103 # A group of contacts who may send you messages
105 # A group of contacts who may not send you messages
107 # On protocols where the user's contacts are stored, this contact list
108 # contains all stored contacts regardless of subscription status.
109 'stored': AllContactsListChannel,
113 _SUPPORTED_LISTS = frozenset(
115 for name in _LIST_TO_FACTORY.iterkeys()
120 def create_contact_list_channel(connection, manager, props, h):
121 factory = _LIST_TO_FACTORY.get(h.get_name(), None)
123 raise telepathy.errors.NotCapable("Unsuported type %s" % h.get_name())
124 return factory(connection, manager, props, h)
127 def get_spported_lists():
128 return _SUPPORTED_LISTS