From: Ed Page Date: Thu, 26 Nov 2009 02:00:35 +0000 (-0600) Subject: Overall, got sending a text to an arbitrary number working X-Git-Url: http://git.maemo.org/git/?p=theonering;a=commitdiff_plain;h=acafb5b1bf5449a0886f74a81542e920fa1d30f2 Overall, got sending a text to an arbitrary number working 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 --- diff --git a/.gitignore b/.gitignore new file mode 100644 index 0000000..0d20b64 --- /dev/null +++ b/.gitignore @@ -0,0 +1 @@ +*.pyc diff --git a/src/channel/call.py b/src/channel/call.py index d8ab0a1..313a7cc 100644 --- a/src/channel/call.py +++ b/src/channel/call.py @@ -2,6 +2,9 @@ import logging import telepathy +import gtk_toolbox +import handle + _moduleLogger = logging.getLogger("channel.call") @@ -16,18 +19,21 @@ class CallChannel( 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 () + @gtk_toolbox.log_exception(_moduleLogger) 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 @@ -37,6 +43,7 @@ class CallChannel( _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 @@ -47,12 +54,9 @@ class CallChannel( 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 @@ -60,6 +64,7 @@ class CallChannel( 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 diff --git a/src/channel/text.py b/src/channel/text.py index 380fcf3..3daacf0 100644 --- a/src/channel/text.py +++ b/src/channel/text.py @@ -3,6 +3,7 @@ import logging import telepathy +import gtk_toolbox import handle @@ -18,17 +19,21 @@ class TextChannel(telepathy.server.ChannelTypeText): 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: - 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) + @gtk_toolbox.log_exception(_moduleLogger) def Close(self): telepathy.server.ChannelTypeText.Close(self) self.remove_from_connection() diff --git a/src/channel_manager.py b/src/channel_manager.py index c513b11..c06288d 100644 --- a/src/channel_manager.py +++ b/src/channel_manager.py @@ -46,7 +46,7 @@ class ChannelManager(object): 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 @@ -59,7 +59,7 @@ class ChannelManager(object): 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 diff --git a/src/connection.py b/src/connection.py index 063d2c9..2c2b8e2 100644 --- a/src/connection.py +++ b/src/connection.py @@ -4,6 +4,7 @@ import logging import telepathy import constants +import gtk_toolbox 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] + @gtk_toolbox.log_exception(_moduleLogger) def Connect(self): """ For org.freedesktop.telepathy.Connection @@ -103,6 +105,7 @@ class TheOneRingConnection(telepathy.server.Connection): telepathy.CONNECTION_STATUS_REASON_REQUESTED ) + @gtk_toolbox.log_exception(_moduleLogger) def Disconnect(self): """ For org.freedesktop.telepathy.Connection @@ -119,6 +122,7 @@ class TheOneRingConnection(telepathy.server.Connection): telepathy.CONNECTION_STATUS_REASON_REQUESTED ) + @gtk_toolbox.log_exception(_moduleLogger) 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_text(handle, None, suppressHandler) + channel = channelManager.channel_for_text(handle, suppressHandler) 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 + @gtk_toolbox.log_exception(_moduleLogger) 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 """ - requestedContactId, requestedContactName = handle.ContactHandle.from_handle_name( + requestedContactId, requestedContactNumber = handle.ContactHandle.from_handle_name( 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): diff --git a/src/connection_manager.py b/src/connection_manager.py index f169789..42153ac 100644 --- a/src/connection_manager.py +++ b/src/connection_manager.py @@ -4,6 +4,7 @@ import gobject import telepathy import constants +import gtk_toolbox import connection @@ -20,6 +21,7 @@ class TheOneRingConnectionManager(telepathy.server.ConnectionManager): self._on_shutdown = shutdown_func _moduleLogger.info("Connection manager created") + @gtk_toolbox.log_exception(_moduleLogger) def GetParameters(self, proto): """ For org.freedesktop.telepathy.ConnectionManager diff --git a/src/gtk_toolbox.py b/src/gtk_toolbox.py index 9ef914f..c4203b0 100644 --- a/src/gtk_toolbox.py +++ b/src/gtk_toolbox.py @@ -231,7 +231,8 @@ def log_exception(logger): return func(*args, **kwds) except Exception: logger.exception(func.__name__) + raise return wrapper - return log_exception_decorator \ No newline at end of file + return log_exception_decorator diff --git a/src/handle.py b/src/handle.py index ff405bf..55f36fb 100644 --- a/src/handle.py +++ b/src/handle.py @@ -61,9 +61,15 @@ class ContactHandle(TheOneRingHandle): @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 @@ -76,6 +82,10 @@ class ContactHandle(TheOneRingHandle): return self._contactId @property + def phoneNumber(self): + return self._phoneNumber + + @property def contactDetails(self): return self._conn.addressbook.get_contact_details(self._id) diff --git a/src/simple_presence.py b/src/simple_presence.py index b95c2ea..56b81af 100644 --- a/src/simple_presence.py +++ b/src/simple_presence.py @@ -2,6 +2,8 @@ import logging import telepathy +import gtk_toolbox + _moduleLogger = logging.getLogger("simple_presence") @@ -32,6 +34,7 @@ class SimplePresenceMixin(telepathy.server.ConnectionInterfaceSimplePresence): """ 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 @@ -49,6 +52,7 @@ class SimplePresenceMixin(telepathy.server.ConnectionInterfaceSimplePresence): presences[handle] = (presenceType, presence, personalMessage) return presences + @gtk_toolbox.log_exception(_moduleLogger) def SetPresence(self, status, message): if message: raise telepathy.errors.InvalidArgument