A lot more cleanup and ground work being layed for phone calls
authorEd Page <eopage@byu.net>
Sun, 27 Sep 2009 02:39:34 +0000 (21:39 -0500)
committerEd Page <eopage@byu.net>
Sun, 27 Sep 2009 02:39:34 +0000 (21:39 -0500)
src/channel/call.py [new file with mode: 0644]
src/channel/contact_list.py
src/channel/text.py
src/channel_manager.py
src/connection.py

diff --git a/src/channel/call.py b/src/channel/call.py
new file mode 100644 (file)
index 0000000..f3aaef5
--- /dev/null
@@ -0,0 +1,59 @@
+import weakref
+import logging
+
+import telepathy
+
+
+class CallChannel(
+               telepathy.server.ChannelTypeStreamedMedia,
+               telepathy.server.ChannelInterfaceCallState,
+       ):
+
+       def __init__(self, connection, conversation):
+               self._recv_id = 0
+               self._conversation = conversation
+               self._connRef = weakref.ref(connection)
+
+               telepathy.server.ChannelTypeText.__init__(self, connection, None)
+               telepathy.server.ChannelInterfaceGroup.__init__(self)
+               telepathy.server.ChannelInterfaceChatState.__init__(self)
+
+               self.GroupFlagsChanged(telepathy.CHANNEL_GROUP_FLAG_CAN_ADD, 0)
+               self.__add_initial_participants()
+
+       def ListStreams(self):
+               """
+               For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
+               """
+               pass
+
+       def RemoveStreams(self, streams):
+               """
+               For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
+               """
+               pass
+
+       def RequestStreamDirection(self, stream, streamDirection):
+               """
+               For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
+
+               @note Since streams are short lived, not bothering to implement this
+               """
+               logging.info("A request was made to change the stream direction")
+
+       def RequestStreams(self, contact, streamType):
+               """
+               For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
+
+               @returns [(Stream ID, contact, stream type, stream state, stream direction, pending send flags)]
+               """
+               pass
+
+       def GetCallStates(self):
+               """
+               For org.freedesktop.Telepathy.Channel.Interface.CallState
+
+               Get the current call states for all contacts involved in this call. 
+               @returns {Contact: telepathy.constants.CHANNEL_CALL_STATE_*}
+               """
+               pass
index 62c2d67..ec390ff 100644 (file)
@@ -8,9 +8,9 @@ import handle
 
 def create_contact_list_channel(connection, h):
        if h.get_name() == 'subscribe':
-               channel_class = TheOneRingSubscribeListChannel
+               channel_class = SubscribeListChannel
        elif h.get_name() == 'publish':
-               channel_class = TheOneRingPublishListChannel
+               channel_class = PublishListChannel
        elif h.get_name() == 'hide':
                logging.warn("Unsuported type %s" % h.get_name())
        elif h.get_name() == 'allow':
@@ -22,7 +22,7 @@ def create_contact_list_channel(connection, h):
        return channel_class(connection, h)
 
 
-class TheOneRingListChannel(
+class AbstractListChannel(
                telepathy.server.ChannelTypeContactList,
                telepathy.server.ChannelInterfaceGroup,
        ):
@@ -38,7 +38,7 @@ class TheOneRingListChannel(
                return []
 
 
-class TheOneRingSubscribeListChannel(TheOneRingListChannel):
+class SubscribeListChannel(AbstractListChannel):
        """
        Subscribe List channel.
 
@@ -48,7 +48,7 @@ class TheOneRingSubscribeListChannel(TheOneRingListChannel):
        """
 
        def __init__(self, connection, h):
-               TheOneRingListChannel.__init__(self, connection, h)
+               AbstractListChannel.__init__(self, connection, h)
                self.GroupFlagsChanged(
                        telepathy.CHANNEL_GROUP_FLAG_CAN_ADD |
                        telepathy.CHANNEL_GROUP_FLAG_CAN_REMOVE,
@@ -78,10 +78,10 @@ class TheOneRingSubscribeListChannel(TheOneRingListChannel):
                        addressBook.delete_contact(contact)
 
 
-class TheOneRingPublishListChannel(TheOneRingListChannel):
+class PublishListChannel(AbstractListChannel):
 
        def __init__(self, connection, h):
-               TheOneRingListChannel.__init__(self, connection, h)
+               AbstractListChannel.__init__(self, connection, h)
                self.GroupFlagsChanged(0, 0)
 
        def AddMembers(self, contacts, message):
@@ -111,12 +111,12 @@ class TheOneRingPublishListChannel(TheOneRingListChannel):
                return result
 
 
-class TheOneRingGroupChannel(TheOneRingListChannel):
+class GroupChannel(AbstractListChannel):
 
        def __init__(self, connection, h):
                self.__pending_add = []
                self.__pending_remove = []
-               TheOneRingListChannel.__init__(self, connection, h)
+               AbstractListChannel.__init__(self, connection, h)
                self.GroupFlagsChanged(
                        telepathy.CHANNEL_GROUP_FLAG_CAN_ADD | telepathy.CHANNEL_GROUP_FLAG_CAN_REMOVE,
                        0,
index 16b6f40..8fe4a5f 100644 (file)
@@ -4,18 +4,17 @@ import weakref
 import telepathy
 
 
-class TheOneRingChannelText(
-               telepathy.server.ChannelTypeText,
-       ):
+class TextChannel(telepathy.server.ChannelTypeText):
+       """
+       Look into implementing ChannelInterfaceMessages for rich text formatting
+       """
 
        def __init__(self, connection, conversation):
                self._recv_id = 0
                self._conversation = conversation
-               self._conn_ref = weakref.ref(connection)
+               self._connRef = weakref.ref(connection)
 
                telepathy.server.ChannelTypeText.__init__(self, connection, None)
-               telepathy.server.ChannelInterfaceGroup.__init__(self)
-               telepathy.server.ChannelInterfaceChatState.__init__(self)
 
                self.GroupFlagsChanged(telepathy.CHANNEL_GROUP_FLAG_CAN_ADD, 0)
                self.__add_initial_participants()
index ba06957..ad6faed 100644 (file)
@@ -12,19 +12,22 @@ class ChannelManager(object):
                self._connRef = weakref.ref(connection)
                self._listChannels = weakref.WeakValueDictionary()
                self._textChannels = weakref.WeakValueDictionary()
+               self._callChannels = weakref.WeakValueDictionary()
 
        def close(self):
                for chan in self._listChannels.values():
                        chan.remove_from_connection()# so that dbus lets it die.
                for chan in self._textChannels.values():
                        chan.Close()
+               for chan in self._callChannels.values():
+                       chan.Close()
 
        def channel_for_list(self, handle, suppress_handler=False):
                if handle in self._listChannels:
                        chan = self._listChannels[handle]
                else:
                        if handle.get_type() == telepathy.HANDLE_TYPE_GROUP:
-                               chan = channel.group.GroupChannel(self._connRef(), handle)
+                               chan = channel.contact_list.GroupChannel(self._connRef(), handle)
                        elif handle.get_type() == telepathy.HANDLE_TYPE_CONTACT:
                                chan = channel.contact_list.creat_contact_list_channel(self._connRef(), handle)
                        else:
@@ -47,3 +50,18 @@ class ChannelManager(object):
                        self._textChannels[handle] = chan
                        self._connRef().add_channel(chan, handle, suppress_handler)
                return chan
+
+       def channel_forcall(self, handle, conversation=None, suppress_handler=False):
+               if handle in self._callChannels:
+                       chan = self._callChannels[handle]
+               else:
+                       logging.debug("Requesting new call channel")
+                       contact = handle.contact
+
+                       if conversation is None:
+                               client = self._connRef().msn_client
+                               conversation = None
+                       chan = channel.call.CallChannel(self._connRef(), conversation)
+                       self._callChannels[handle] = chan
+                       self._connRef().add_channel(chan, handle, suppress_handler)
+               return chan
index 3b17095..8c1be6b 100644 (file)
@@ -71,18 +71,20 @@ class TheOneRingConnection(telepathy.server.Connection, simple_presence.SimplePr
                For org.freedesktop.telepathy.Connection
                """
                try:
+                       self.StatusChanged(
+                               telepathy.CONNECTION_STATUS_CONNECTING,
+                               telepathy.CONNECTION_STATUS_REASON_REQUESTED
+                       )
                        self._backend.login(*self._credentials)
                        self.StatusChanged(
                                telepathy.CONNECTION_STATUS_CONNECTED,
                                telepathy.CONNECTION_STATUS_REASON_REQUESTED
                        )
-                       logging.info("Connected")
                except Exception:
                        self.StatusChanged(
                                telepathy.CONNECTION_STATUS_DISCONNECTED,
                                telepathy.CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED
                        )
-                       logging.exception("Connecting Failed")
 
        def Disconnect(self):
                """