X-Git-Url: http://git.maemo.org/git/?a=blobdiff_plain;f=src%2Fchannel%2Fcall.py;h=7e185fe163b9535b2cc3de5c0414cdc6b6e68c3e;hb=a137e9ca9ed2e829e2a3b22ba22f4119ee0e26c2;hp=ee5ba6f09c958cd925a42c5118c8885d2e8458c6;hpb=e6c57b49a1ed070762aa64ba005987e733f60c11;p=theonering diff --git a/src/channel/call.py b/src/channel/call.py index ee5ba6f..7e185fe 100644 --- a/src/channel/call.py +++ b/src/channel/call.py @@ -1,37 +1,30 @@ import logging +import gobject import telepathy +import tp import gtk_toolbox -import handle _moduleLogger = logging.getLogger("channel.call") class CallChannel( - telepathy.server.ChannelTypeStreamedMedia, - telepathy.server.ChannelInterfaceCallState, - telepathy.server.ChannelInterfaceGroup, + tp.ChannelTypeStreamedMedia, + tp.ChannelInterfaceCallState, + tp.ChannelInterfaceGroup, ): + # @bug On Maemo 5 this is having some kind of "General" error, possibly due to an issue with "GetAll" DBusProperties stuff def __init__(self, connection, manager, props, contactHandle): self.__manager = manager self.__props = props + self.__cancelId = None - try: - # HACK Older python-telepathy way - telepathy.server.ChannelTypeStreamedMedia.__init__(self, connection, None) - 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.ChannelTypeStreamedMedia.__init__(self, connection, manager, props) - telepathy.server.ChannelInterfaceCallState.__init__(self) - telepathy.server.ChannelInterfaceGroup.__init__(self) + tp.ChannelTypeStreamedMedia.__init__(self, connection, manager, props) + tp.ChannelInterfaceCallState.__init__(self) + tp.ChannelInterfaceGroup.__init__(self) self.__contactHandle = contactHandle self._implement_property_get( telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA, @@ -43,7 +36,7 @@ class CallChannel( self.GroupFlagsChanged(0, 0) self.MembersChanged( - '', [self._conn.GetSetHandle()], [], [], [contactHandle], + '', [self._conn.GetSelfHandle()], [], [], [contactHandle], 0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE ) @@ -53,32 +46,17 @@ class CallChannel( def initial_video(self): return False - 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): self.close() def close(self): - telepathy.server.ChannelTypeStreamedMedia.Close(self) - if self.__manager.channel_exists(self.__props): - # HACK Older python-telepathy requires doing this manually - self.__manager.remove_channel(self) + _moduleLogger.debug("Closing call") + tp.ChannelTypeStreamedMedia.Close(self) self.remove_from_connection() + if self.__cancelId is not None: + gobject.source_remove(self.__cancelId) + self.__cancelId = None @gtk_toolbox.log_exception(_moduleLogger) def ListStreams(self): @@ -111,13 +89,13 @@ class CallChannel( @returns [(Stream ID, contact, stream type, stream state, stream direction, pending send flags)] """ - contact = self._conn.handle(telepathy.constants.HANDLE_TYPE_CONTACT, contactId) + contact = self._conn.get_handle_by_id(telepathy.constants.HANDLE_TYPE_CONTACT, contactId) assert self.__contactHandle == contact, "%r != %r" % (self.__contactHandle, contact) - contactId, contactNumber = handle.ContactHandle.from_handle_name(contact.name) + contactNumber = contact.phoneNumber self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_RINGING) + self.__cancelId = gobject.idle_add(self._on_cancel) self._conn.session.backend.call(contactNumber) - self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_FORWARDED) streamId = 0 streamState = telepathy.constants.MEDIA_STREAM_STATE_DISCONNECTED @@ -134,3 +112,10 @@ class CallChannel( @returns {Contact: telepathy.constants.CHANNEL_CALL_STATE_*} """ return {self.__contactHandle: telepathy.constants.CHANNEL_CALL_STATE_FORWARDED} + + @gtk_toolbox.log_exception(_moduleLogger) + def _on_cancel(self, *args): + self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_FORWARDED) + self.close() + self.__cancelId = None + return False