X-Git-Url: http://git.maemo.org/git/?p=theonering;a=blobdiff_plain;f=src%2Fchannel%2Fcall.py;h=7bcc83413e37af8299e8407ec2c658b72340eb11;hp=fd6cb9421741c782f1240b2dae675c213aea22ff;hb=2bcd7b94d276c3f6ff4441e3bf05e7598177f251;hpb=ef732138bc3958985b1041e5f5005f6947851ced diff --git a/src/channel/call.py b/src/channel/call.py index fd6cb94..7bcc834 100644 --- a/src/channel/call.py +++ b/src/channel/call.py @@ -1,24 +1,62 @@ import logging +import gobject import telepathy +import tp import gtk_toolbox -import handle _moduleLogger = logging.getLogger("channel.call") -# @todo Test Calls class CallChannel( - telepathy.server.ChannelTypeStreamedMedia, - telepathy.server.ChannelInterfaceCallState, + 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 + + 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, + { + "InitialAudio": self.initial_audio, + "InitialVideo": self.initial_video, + }, + ) + + self.GroupFlagsChanged(0, 0) + self.MembersChanged( + '', [self._conn.GetSelfHandle()], [], [], [contactHandle], + 0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE + ) + + def initial_audio(self): + return False + + def initial_video(self): + return False - def __init__(self, connection): - telepathy.server.ChannelTypeStreamedMedia.__init__(self, connection, None) - telepathy.server.ChannelInterfaceGroup.__init__(self) - telepathy.server.ChannelInterfaceChatState.__init__(self) + @gtk_toolbox.log_exception(_moduleLogger) + def Close(self): + self.close() + + def close(self): + _moduleLogger.info("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): @@ -45,18 +83,18 @@ class CallChannel( raise telepathy.errors.NotImplemented("Cannot change directions") @gtk_toolbox.log_exception(_moduleLogger) - def RequestStreams(self, contact, streamTypes): + def RequestStreams(self, contactId, streamTypes): """ For org.freedesktop.Telepathy.Channel.Type.StreamedMedia @returns [(Stream ID, contact, stream type, stream state, stream direction, pending send flags)] """ - for streamType in streamTypes: - if streamType != telepathy.constants.MEDIA_STREAM_TYPE_AUDIO: - raise telepathy.errors.NotImplemented("Audio is the only stream type supported") - - contactId, contactNumber = handle.ContactHandle.from_handle_name(contact.name) + contact = self._conn.get_handle_by_id(telepathy.constants.HANDLE_TYPE_CONTACT, contactId) + assert self.__contactHandle == contact, "%r != %r" % (self.__contactHandle, contact) + 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) streamId = 0 @@ -73,4 +111,11 @@ class CallChannel( Get the current call states for all contacts involved in this call. @returns {Contact: telepathy.constants.CHANNEL_CALL_STATE_*} """ - return {} + 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