Docmenting a mixin binding point
[theonering] / src / channel / call.py
1 import logging
2
3 import gobject
4 import telepathy
5
6 import tp
7 import gtk_toolbox
8
9
10 _moduleLogger = logging.getLogger("channel.call")
11
12
13 class CallChannel(
14                 tp.ChannelTypeStreamedMedia,
15                 tp.ChannelInterfaceCallState,
16                 tp.ChannelInterfaceGroup,
17         ):
18         # @bug On Maemo 5 this is having some kind of "General" error, possibly due to an issue with "GetAll" DBusProperties stuff
19         # @bug broke again on Empathy
20
21         def __init__(self, connection, manager, props, contactHandle):
22                 self.__manager = manager
23                 self.__props = props
24                 self.__cancelId = None
25
26                 tp.ChannelTypeStreamedMedia.__init__(self, connection, manager, props)
27                 tp.ChannelInterfaceCallState.__init__(self)
28                 tp.ChannelInterfaceGroup.__init__(self)
29                 self.__contactHandle = contactHandle
30                 self._implement_property_get(
31                         telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA,
32                         {
33                                 "InitialAudio": self.initial_audio,
34                                 "InitialVideo": self.initial_video,
35                         },
36                 )
37
38                 self.GroupFlagsChanged(0, 0)
39                 self.MembersChanged(
40                         '', [self._conn.GetSelfHandle()], [], [], [contactHandle],
41                         0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE
42                 )
43
44         def initial_audio(self):
45                 return False
46
47         def initial_video(self):
48                 return False
49
50         @gtk_toolbox.log_exception(_moduleLogger)
51         def Close(self):
52                 self.close()
53
54         def close(self):
55                 tp.ChannelTypeStreamedMedia.Close(self)
56                 self.remove_from_connection()
57                 if self.__cancelId is not None:
58                         gobject.source_remove(self.__cancelId)
59                         self.__cancelId = None
60
61         @gtk_toolbox.log_exception(_moduleLogger)
62         def ListStreams(self):
63                 """
64                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
65                 """
66                 return ()
67
68         @gtk_toolbox.log_exception(_moduleLogger)
69         def RemoveStreams(self, streams):
70                 """
71                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
72                 """
73                 raise telepathy.errors.NotImplemented("Cannot remove a stream")
74
75         @gtk_toolbox.log_exception(_moduleLogger)
76         def RequestStreamDirection(self, stream, streamDirection):
77                 """
78                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
79
80                 @note Since streams are short lived, not bothering to implement this
81                 """
82                 _moduleLogger.info("A request was made to change the stream direction")
83                 raise telepathy.errors.NotImplemented("Cannot change directions")
84
85         @gtk_toolbox.log_exception(_moduleLogger)
86         def RequestStreams(self, contactId, streamTypes):
87                 """
88                 For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
89
90                 @returns [(Stream ID, contact, stream type, stream state, stream direction, pending send flags)]
91                 """
92                 contact = self._conn.get_handle_by_id(telepathy.constants.HANDLE_TYPE_CONTACT, contactId)
93                 assert self.__contactHandle == contact, "%r != %r" % (self.__contactHandle, contact)
94                 contactNumber = contact.phoneNumber
95
96                 self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_RINGING)
97                 self.__cancelId = gobject.idle_add(self._on_cancel)
98                 self._conn.session.backend.call(contactNumber)
99
100                 streamId = 0
101                 streamState = telepathy.constants.MEDIA_STREAM_STATE_DISCONNECTED
102                 streamDirection = telepathy.constants.MEDIA_STREAM_DIRECTION_BIDIRECTIONAL
103                 pendingSendFlags = telepathy.constants.MEDIA_STREAM_PENDING_REMOTE_SEND
104                 return [(streamId, contact, streamTypes[0], streamState, streamDirection, pendingSendFlags)]
105
106         @gtk_toolbox.log_exception(_moduleLogger)
107         def GetCallStates(self):
108                 """
109                 For org.freedesktop.Telepathy.Channel.Interface.CallState
110
111                 Get the current call states for all contacts involved in this call. 
112                 @returns {Contact: telepathy.constants.CHANNEL_CALL_STATE_*}
113                 """
114                 return {self.__contactHandle: telepathy.constants.CHANNEL_CALL_STATE_FORWARDED}
115
116         @gtk_toolbox.log_exception(_moduleLogger)
117         def _on_cancel(self, *args):
118                 self.CallStateChanged(self.__contactHandle, telepathy.constants.CHANNEL_CALL_STATE_FORWARDED)
119                 self.close()
120                 self.__cancelId = None
121                 return False