Overall, got sending a text to an arbitrary number working
authorEd Page <eopage@byu.net>
Thu, 26 Nov 2009 02:00:35 +0000 (20:00 -0600)
committerEd Page <eopage@byu.net>
Thu, 26 Nov 2009 02:00:35 +0000 (20:00 -0600)
Got sending a text to work
Added support for arbitrary phone numbers in addition to addressbook contacts
Added logging of all exceptions passed back to dbus
Added .gitignore file

.gitignore [new file with mode: 0644]
src/channel/call.py
src/channel/text.py
src/channel_manager.py
src/connection.py
src/connection_manager.py
src/gtk_toolbox.py
src/handle.py
src/simple_presence.py

diff --git a/.gitignore b/.gitignore
new file mode 100644 (file)
index 0000000..0d20b64
--- /dev/null
@@ -0,0 +1 @@
+*.pyc
index d8ab0a1..313a7cc 100644 (file)
@@ -2,6 +2,9 @@ import logging
 
 import telepathy
 
 
 import telepathy
 
+import gtk_toolbox
+import handle
+
 
 _moduleLogger = logging.getLogger("channel.call")
 
 
 _moduleLogger = logging.getLogger("channel.call")
 
@@ -16,18 +19,21 @@ class CallChannel(
                telepathy.server.ChannelInterfaceGroup.__init__(self)
                telepathy.server.ChannelInterfaceChatState.__init__(self)
 
                telepathy.server.ChannelInterfaceGroup.__init__(self)
                telepathy.server.ChannelInterfaceChatState.__init__(self)
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def ListStreams(self):
                """
                For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
                """
                return ()
 
        def ListStreams(self):
                """
                For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
                """
                return ()
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def RemoveStreams(self, streams):
                """
                For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
                """
                raise telepathy.NotImplemented("Cannot remove a stream")
 
        def RemoveStreams(self, streams):
                """
                For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
                """
                raise telepathy.NotImplemented("Cannot remove a stream")
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def RequestStreamDirection(self, stream, streamDirection):
                """
                For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
        def RequestStreamDirection(self, stream, streamDirection):
                """
                For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
@@ -37,6 +43,7 @@ class CallChannel(
                _moduleLogger.info("A request was made to change the stream direction")
                raise telepathy.NotImplemented("Cannot change directions")
 
                _moduleLogger.info("A request was made to change the stream direction")
                raise telepathy.NotImplemented("Cannot change directions")
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def RequestStreams(self, contact, streamTypes):
                """
                For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
        def RequestStreams(self, contact, streamTypes):
                """
                For org.freedesktop.Telepathy.Channel.Type.StreamedMedia
@@ -47,12 +54,9 @@ class CallChannel(
                        if streamType != telepathy.constants.MEDIA_STREAM_TYPE_AUDIO:
                                raise telepathy.NotImplemented("Audio is the only stream type supported")
 
                        if streamType != telepathy.constants.MEDIA_STREAM_TYPE_AUDIO:
                                raise telepathy.NotImplemented("Audio is the only stream type supported")
 
-               contactId = contact.name
+               contactId, contactNumber = handle.ContactHandle.from_handle_name(contact.name)
 
 
-               addressbook = self._conn.session.addressbook
-               phones = addressbook.get_contact_details(contactId)
-               firstNumber = phones.next()
-               self._conn.session.backend.dial(firstNumber)
+               self._conn.session.backend.dial(contactNumber)
 
                streamId = 0
                streamState = telepathy.constants.MEDIA_STREAM_STATE_DISCONNECTED
 
                streamId = 0
                streamState = telepathy.constants.MEDIA_STREAM_STATE_DISCONNECTED
@@ -60,6 +64,7 @@ class CallChannel(
                pendingSendFlags = telepathy.constants.MEDIA_STREAM_PENDING_REMOTE_SEND
                return [(streamId, contact, streamTypes[0], streamState, streamDirection, pendingSendFlags)]
 
                pendingSendFlags = telepathy.constants.MEDIA_STREAM_PENDING_REMOTE_SEND
                return [(streamId, contact, streamTypes[0], streamState, streamDirection, pendingSendFlags)]
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def GetCallStates(self):
                """
                For org.freedesktop.Telepathy.Channel.Interface.CallState
        def GetCallStates(self):
                """
                For org.freedesktop.Telepathy.Channel.Interface.CallState
index 380fcf3..3daacf0 100644 (file)
@@ -3,6 +3,7 @@ import logging
 
 import telepathy
 
 
 import telepathy
 
+import gtk_toolbox
 import handle
 
 
 import handle
 
 
@@ -18,17 +19,21 @@ class TextChannel(telepathy.server.ChannelTypeText):
                telepathy.server.ChannelTypeText.__init__(self, connection, h)
                self._nextRecievedId = 0
 
                telepathy.server.ChannelTypeText.__init__(self, connection, h)
                self._nextRecievedId = 0
 
-               handles = []
-               # @todo Populate participants
-               self.MembersChanged('', handles, [], [], [],
-                               0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
+               self._otherHandle = h
+               handles = [h]
+               #self.MembersChanged('', handles, [], [], [],
+               #               0, telepathy.CHANNEL_GROUP_CHANGE_REASON_NONE)
 
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def Send(self, messageType, text):
                if messageType != telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL:
        def Send(self, messageType, text):
                if messageType != telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL:
-                       raise telepathy.NotImplemented("Unhandled message type")
-               # @todo implement sending message
+                       raise telepathy.NotImplemented("Unhandled message type: %r" % messageType)
+
+               self._conn.session.backend.send_sms(self._otherHandle.phoneNumber, text)
+
                self.Sent(int(time.time()), messageType, text)
 
                self.Sent(int(time.time()), messageType, text)
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def Close(self):
                telepathy.server.ChannelTypeText.Close(self)
                self.remove_from_connection()
        def Close(self):
                telepathy.server.ChannelTypeText.Close(self)
                self.remove_from_connection()
index c513b11..c06288d 100644 (file)
@@ -46,7 +46,7 @@ class ChannelManager(object):
                                raise telepathy.NotImplemented("Only Contacts are allowed")
                        _moduleLogger.debug("Requesting new text channel")
 
                                raise telepathy.NotImplemented("Only Contacts are allowed")
                        _moduleLogger.debug("Requesting new text channel")
 
-                       chan = channel.text.TextChannel(self._connRef(), None)
+                       chan = channel.text.TextChannel(self._connRef(), handle)
                        self._textChannels[handle] = chan
                        self._connRef().add_channel(chan, handle, suppress_handler)
                return chan
                        self._textChannels[handle] = chan
                        self._connRef().add_channel(chan, handle, suppress_handler)
                return chan
@@ -59,7 +59,7 @@ class ChannelManager(object):
                                raise telepathy.NotImplemented("Using deprecated means to create a call")
                        _moduleLogger.debug("Requesting new call channel")
 
                                raise telepathy.NotImplemented("Using deprecated means to create a call")
                        _moduleLogger.debug("Requesting new call channel")
 
-                       chan = channel.call.CallChannel(self._connRef())
+                       chan = channel.call.CallChannel(self._connRef(), handle)
                        self._callChannels[handle] = chan
                        self._connRef().add_channel(chan, handle, suppress_handler)
                return chan
                        self._callChannels[handle] = chan
                        self._connRef().add_channel(chan, handle, suppress_handler)
                return chan
index 063d2c9..2c2b8e2 100644 (file)
@@ -4,6 +4,7 @@ import logging
 import telepathy
 
 import constants
 import telepathy
 
 import constants
+import gtk_toolbox
 import gvoice
 import handle
 import channel_manager
 import gvoice
 import handle
 import channel_manager
@@ -72,6 +73,7 @@ class TheOneRingConnection(telepathy.server.Connection):
                self.check_handle(handleType, handleId)
                return self._handles[handleType, handleId]
 
                self.check_handle(handleType, handleId)
                return self._handles[handleType, handleId]
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def Connect(self):
                """
                For org.freedesktop.telepathy.Connection
        def Connect(self):
                """
                For org.freedesktop.telepathy.Connection
@@ -103,6 +105,7 @@ class TheOneRingConnection(telepathy.server.Connection):
                                telepathy.CONNECTION_STATUS_REASON_REQUESTED
                        )
 
                                telepathy.CONNECTION_STATUS_REASON_REQUESTED
                        )
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def Disconnect(self):
                """
                For org.freedesktop.telepathy.Connection
        def Disconnect(self):
                """
                For org.freedesktop.telepathy.Connection
@@ -119,6 +122,7 @@ class TheOneRingConnection(telepathy.server.Connection):
                        telepathy.CONNECTION_STATUS_REASON_REQUESTED
                )
 
                        telepathy.CONNECTION_STATUS_REASON_REQUESTED
                )
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def RequestChannel(self, type, handleType, handleId, suppressHandler):
                """
                For org.freedesktop.telepathy.Connection
        def RequestChannel(self, type, handleType, handleId, suppressHandler):
                """
                For org.freedesktop.telepathy.Connection
@@ -140,16 +144,17 @@ class TheOneRingConnection(telepathy.server.Connection):
                        channel = channelManager.channel_for_list(handle, suppressHandler)
                elif type == telepathy.CHANNEL_TYPE_TEXT:
                        _moduleLogger.info("RequestChannel Text")
                        channel = channelManager.channel_for_list(handle, suppressHandler)
                elif type == telepathy.CHANNEL_TYPE_TEXT:
                        _moduleLogger.info("RequestChannel Text")
-                       channel = channelManager.channel_for_text(handle, None, suppressHandler)
+                       channel = channelManager.channel_for_text(handle, suppressHandler)
                elif type == telepathy.CHANNEL_TYPE_STREAMED_MEDIA:
                        _moduleLogger.info("RequestChannel Media")
                elif type == telepathy.CHANNEL_TYPE_STREAMED_MEDIA:
                        _moduleLogger.info("RequestChannel Media")
-                       channel = channelManager.channel_for_text(handle, None, suppressHandler)
+                       channel = channelManager.channel_for_call(handle, suppressHandler)
                else:
                        raise telepathy.NotImplemented("unknown channel type %s" % type)
 
                _moduleLogger.info("RequestChannel Object Path: %s" % channel._object_path)
                return channel._object_path
 
                else:
                        raise telepathy.NotImplemented("unknown channel type %s" % type)
 
                _moduleLogger.info("RequestChannel Object Path: %s" % channel._object_path)
                return channel._object_path
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def RequestHandles(self, handleType, names, sender):
                """
                For org.freedesktop.telepathy.Connection
        def RequestHandles(self, handleType, names, sender):
                """
                For org.freedesktop.telepathy.Connection
@@ -178,10 +183,10 @@ class TheOneRingConnection(telepathy.server.Connection):
                """
                @todo Determine if nay of this is really needed
                """
                """
                @todo Determine if nay of this is really needed
                """
-               requestedContactId, requestedContactName = handle.ContactHandle.from_handle_name(
+               requestedContactId, requestedContactNumber = handle.ContactHandle.from_handle_name(
                        requestedHandleName
                )
                        requestedHandleName
                )
-               h = handle.create_handle(self, 'contact', requestedContactId, requestedHandleName)
+               h = handle.create_handle(self, 'contact', requestedContactId, requestedContactNumber)
                return h
 
        def _on_invite_text(self, contactId):
                return h
 
        def _on_invite_text(self, contactId):
index f169789..42153ac 100644 (file)
@@ -4,6 +4,7 @@ import gobject
 import telepathy
 
 import constants
 import telepathy
 
 import constants
+import gtk_toolbox
 import connection
 
 
 import connection
 
 
@@ -20,6 +21,7 @@ class TheOneRingConnectionManager(telepathy.server.ConnectionManager):
                self._on_shutdown = shutdown_func
                _moduleLogger.info("Connection manager created")
 
                self._on_shutdown = shutdown_func
                _moduleLogger.info("Connection manager created")
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def GetParameters(self, proto):
                """
                For org.freedesktop.telepathy.ConnectionManager
        def GetParameters(self, proto):
                """
                For org.freedesktop.telepathy.ConnectionManager
index 9ef914f..c4203b0 100644 (file)
@@ -231,7 +231,8 @@ def log_exception(logger):
                                return func(*args, **kwds)
                        except Exception:
                                logger.exception(func.__name__)
                                return func(*args, **kwds)
                        except Exception:
                                logger.exception(func.__name__)
+                               raise
 
                return wrapper
 
 
                return wrapper
 
-       return log_exception_decorator
\ No newline at end of file
+       return log_exception_decorator
index ff405bf..55f36fb 100644 (file)
@@ -61,9 +61,15 @@ class ContactHandle(TheOneRingHandle):
 
        @staticmethod
        def from_handle_name(handleName):
 
        @staticmethod
        def from_handle_name(handleName):
-               parts = handleName.split("#")
-               assert len(parts) == 2
-               contactId, contactNumber = parts[0:2]
+               parts = handleName.split("#", 1)
+               if len(parts) == 2:
+                       contactId, contactNumber = parts[0:2]
+               elif len(parts) == 1:
+                       contactId, contactNumber = "", handleName
+               else:
+                       raise RuntimeError("Invalid handle: %s" % handleName)
+
+               contactNumber = strip_number(contactNumber)
                return contactId, contactNumber
 
        @staticmethod
                return contactId, contactNumber
 
        @staticmethod
@@ -76,6 +82,10 @@ class ContactHandle(TheOneRingHandle):
                return self._contactId
 
        @property
                return self._contactId
 
        @property
+       def phoneNumber(self):
+               return self._phoneNumber
+
+       @property
        def contactDetails(self):
                return self._conn.addressbook.get_contact_details(self._id)
 
        def contactDetails(self):
                return self._conn.addressbook.get_contact_details(self._id)
 
index b95c2ea..56b81af 100644 (file)
@@ -2,6 +2,8 @@ import logging
 
 import telepathy
 
 
 import telepathy
 
+import gtk_toolbox
+
 
 _moduleLogger = logging.getLogger("simple_presence")
 
 
 _moduleLogger = logging.getLogger("simple_presence")
 
@@ -32,6 +34,7 @@ class SimplePresenceMixin(telepathy.server.ConnectionInterfaceSimplePresence):
                """
                raise NotImplementedError()
 
                """
                raise NotImplementedError()
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def GetPresences(self, contacts):
                """
                @todo Figure out how to know when its self and get whether busy or not
        def GetPresences(self, contacts):
                """
                @todo Figure out how to know when its self and get whether busy or not
@@ -49,6 +52,7 @@ class SimplePresenceMixin(telepathy.server.ConnectionInterfaceSimplePresence):
                        presences[handle] = (presenceType, presence, personalMessage)
                return presences
 
                        presences[handle] = (presenceType, presence, personalMessage)
                return presences
 
+       @gtk_toolbox.log_exception(_moduleLogger)
        def SetPresence(self, status, message):
                if message:
                        raise telepathy.errors.InvalidArgument
        def SetPresence(self, status, message):
                if message:
                        raise telepathy.errors.InvalidArgument