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
21 @bug On Maemo 5 this is being ignored
24 def __init__(self, connection, manager, props, listHandle):
25 tp.ChannelTypeContactList.__init__(self, connection, manager, props)
26 tp.ChannelInterfaceGroup.__init__(self)
28 self.__manager = manager
30 self.__session = connection.session
31 self.__listHandle = listHandle
33 self._callback = coroutines.func_sink(
34 coroutines.expand_positional(
35 self._on_contacts_refreshed
38 self.__session.addressbook.updateSignalHandler.register_sink(
42 self.GroupFlagsChanged(0, 0)
44 addressbook = connection.session.addressbook
45 contacts = addressbook.get_numbers()
46 self._process_refresh(addressbook, set(contacts), set())
49 @gtk_toolbox.log_exception(_moduleLogger)
54 _moduleLogger.debug("Closing contact list")
55 self.__session.addressbook.updateSignalHandler.unregister_sink(
60 tp.ChannelTypeContactList.Close(self)
61 self.remove_from_connection()
63 @gtk_toolbox.log_exception(_moduleLogger)
64 def GetLocalPendingMembersWithInfo(self):
67 @gtk_toolbox.log_exception(_moduleLogger)
68 def _on_contacts_refreshed(self, addressbook, added, removed, changed):
69 self._process_refresh(addressbook, added, removed)
71 def _process_refresh(self, addressbook, added, removed):
73 "%s Added: %r, Removed: %r" % (self.__listHandle.get_name(), len(added), len(removed))
75 connection = self._conn
77 handle.create_handle(connection, "contact", contactNumber)
78 for contactNumber in added
81 handle.create_handle(connection, "contact", contactNumber)
82 for contactNumber in removed
86 reason = telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE
89 handlesAdded, handlesRemoved,
97 # The group of contacts for whom you receive presence
98 'subscribe': AllContactsListChannel,
99 # The group of contacts who may receive your presence
100 'publish': AllContactsListChannel,
101 # A group of contacts who are on the publish list but are temporarily
102 # disallowed from receiving your presence
103 # This doesn't make sense to support
105 # A group of contacts who may send you messages
106 # @todo Allow-List would be cool to support
108 # A group of contacts who may not send you messages
109 # @todo Deny-List would be cool to support
111 # On protocols where the user's contacts are stored, this contact list
112 # contains all stored contacts regardless of subscription status.
113 'stored': AllContactsListChannel,
117 _SUPPORTED_LISTS = frozenset(
119 for name in _LIST_TO_FACTORY.iterkeys()
124 def create_contact_list_channel(connection, manager, props, h):
125 factory = _LIST_TO_FACTORY.get(h.get_name(), None)
127 raise telepathy.errors.NotCapable("Unsuported type %s" % h.get_name())
128 return factory(connection, manager, props, h)
131 def get_spported_lists():
132 return _SUPPORTED_LISTS