5 import util.go_utils as gobject_utils
6 import util.coroutines as coroutines
11 _moduleLogger = logging.getLogger("channel.contact_list")
14 class AbstractListChannel(
15 telepathy.server.ChannelTypeContactList,
16 telepathy.server.ChannelInterfaceGroup,
18 "Abstract Contact List channels"
20 def __init__(self, connection, h):
21 telepathy.server.ChannelTypeContactList.__init__(self, connection, h)
22 telepathy.server.ChannelInterfaceGroup.__init__(self)
24 self._session = connection.session
27 class AllContactsListChannel(AbstractListChannel):
29 The group of contacts for whom you receive presence
32 def __init__(self, connection, h):
33 AbstractListChannel.__init__(self, connection, h)
35 self._callback = coroutines.func_sink(
36 coroutines.expand_positional(
37 self._on_contacts_refreshed
40 self._session.addressbook.updateSignalHandler.register_sink(
44 self.GroupFlagsChanged(0, 0)
46 addressbook = connection.session.addressbook
47 contacts = addressbook.get_contacts()
48 self._process_refresh(addressbook, contacts, [])
50 @gtk_toolbox.log_exception(_moduleLogger)
55 self._session.addressbook.updateSignalHandler.unregister_sink(
60 telepathy.server.ChannelTypeContactList.Close(self)
61 self.remove_from_connection()
62 self._prop_getters = None # HACK to get around python-telepathy memory leaks
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):
70 connection = self._conn
72 handle.create_handle(connection, "contact", contactId, phoneNumber)
73 for contactId in added
74 for (phoneType, phoneNumber) in addressbook.get_contact_details(contactId)
77 handle.create_handle(connection, "contact", contactId, phoneNumber)
78 for contactId in removed
79 for (phoneType, phoneNumber) in addressbook.get_contact_details(contactId)
83 reason = telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE
86 handlesAdded, handlesRemoved,
93 def create_contact_list_channel(connection, h):
94 if h.get_name() == 'subscribe':
95 # The group of contacts for whom you receive presence
96 ChannelClass = AllContactsListChannel
97 elif h.get_name() == 'publish':
98 # The group of contacts who may receive your presence
99 ChannelClass = AllContactsListChannel
100 elif h.get_name() == 'hide':
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
104 _moduleLogger.warn("Unsuported type %s" % h.get_name())
105 elif h.get_name() == 'allow':
106 # A group of contacts who may send you messages
107 # @todo Allow-List would be cool to support
108 _moduleLogger.warn("Unsuported type %s" % h.get_name())
109 elif h.get_name() == 'deny':
110 # A group of contacts who may not send you messages
111 # @todo Deny-List would be cool to support
112 _moduleLogger.warn("Unsuported type %s" % h.get_name())
113 elif h.get_name() == 'stored':
114 # On protocols where the user's contacts are stored, this contact list
115 # contains all stored contacts regardless of subscription status.
116 ChannelClass = AllContactsListChannel
118 raise TypeError("Unknown list type : " + h.get_name())
119 return ChannelClass(connection, h)