Prefixing more hacks with HACK to make it easier to remove later
[theonering] / src / channel / call.py
index 9de629e..abe820f 100644 (file)
@@ -9,16 +9,38 @@ import handle
 _moduleLogger = logging.getLogger("channel.call")
 
 
-# @todo Test Calls
 class CallChannel(
                telepathy.server.ChannelTypeStreamedMedia,
                telepathy.server.ChannelInterfaceCallState,
+               telepathy.server.ChannelInterfaceGroup,
        ):
 
-       def __init__(self, connection, contactHandle):
-               telepathy.server.ChannelTypeStreamedMedia.__init__(self, connection, None)
+       def __init__(self, connection, manager, props, contactHandle):
+               self._manager = manager
+               self._props = props
+
+               try:
+                       # HACK Older python-telepathy way
+                       telepathy.server.ChannelTypeStreamedMedia.__init__(self, connection, None)
+               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)
                self._contactHandle = contactHandle
+               self._implement_property_get(
+                       telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA,
+                       {
+                               "InitialAudio": self.initial_audio,
+                               "InitialVideo": self.initial_video,
+                       },
+               )
+
+       def initial_audio(self):
+               return False
+
+       def initial_video(self):
+               return False
 
        @gtk_toolbox.log_exception(_moduleLogger)
        def Close(self):
@@ -26,8 +48,10 @@ class CallChannel(
 
        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)
                self.remove_from_connection()
-               self._prop_getters = None # HACK to get around python-telepathy memory leaks
 
        @gtk_toolbox.log_exception(_moduleLogger)
        def ListStreams(self):
@@ -60,15 +84,13 @@ class CallChannel(
 
                @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")
-
                contact = self._conn.handle(telepathy.constants.HANDLE_TYPE_CONTACT, contactId)
                assert self._contactHandle == contact, "%r != %r" % (self._contactHandle, contact)
                contactId, contactNumber = handle.ContactHandle.from_handle_name(contact.name)
 
+               self.CallStateChanged(self._contactHandle, telepathy.constants.CHANNEL_CALL_STATE_RINGING)
                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
@@ -84,4 +106,4 @@ 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}