X-Git-Url: http://git.maemo.org/git/?p=theonering;a=blobdiff_plain;f=src%2Ftp%2Fchannel.py;h=592b201f6a116621db6b279cfa1790765d7335f2;hp=55ac675156c7cb8651ba9902bfaa938113af5e6e;hb=4329f6e4cdab994dbe81ea03e1c36341be37d253;hpb=a840b976430685dbf23bee4e590d1ee23594728c diff --git a/src/tp/channel.py b/src/tp/channel.py index 55ac675..592b201 100644 --- a/src/tp/channel.py +++ b/src/tp/channel.py @@ -21,7 +21,8 @@ import dbus import dbus.service from telepathy.constants import (CONNECTION_HANDLE_TYPE_NONE, - CHANNEL_TEXT_MESSAGE_TYPE_NORMAL) + CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, + HANDLE_TYPE_NONE) from telepathy.errors import InvalidArgument @@ -38,13 +39,15 @@ from telepathy.interfaces import (CHANNEL_INTERFACE, MEDIA_SESSION_HANDLER, MEDIA_STREAM_HANDLER) -from telepathy._generated.Channel import Channel as _Channel +from _generated.Channel import Channel as _Channel from properties import DBusProperties +from handle import NoneHandle + class Channel(_Channel, DBusProperties): - def __init__(self, connection, manager, props): + def __init__(self, connection, manager, props, object_path=None): """ Initialise the base channel object. @@ -54,7 +57,8 @@ class Channel(_Channel, DBusProperties): """ self._conn = connection self._chan_manager = manager - object_path = self._conn.get_channel_path() + + object_path = self._conn.get_channel_path(object_path) _Channel.__init__(self, self._conn._name, object_path) self._type = props[CHANNEL_INTERFACE + '.ChannelType'] @@ -62,9 +66,15 @@ class Channel(_Channel, DBusProperties): self._immutable_properties = dict() - self._handle = self._conn.get_handle_by_id( - props[CHANNEL_INTERFACE + '.TargetHandleType'], - props[CHANNEL_INTERFACE + '.TargetHandle']) + tht = props.get(CHANNEL_INTERFACE + '.TargetHandleType', HANDLE_TYPE_NONE) + + if tht == HANDLE_TYPE_NONE: + self._handle = NoneHandle() + else: + self._handle = self._conn.get_handle_by_id( + props[CHANNEL_INTERFACE + '.TargetHandleType'], + props[CHANNEL_INTERFACE + '.TargetHandle']) + self._interfaces = set() DBusProperties.__init__(self) @@ -72,8 +82,8 @@ class Channel(_Channel, DBusProperties): {'ChannelType': lambda: dbus.String(self.GetChannelType()), 'Interfaces': lambda: dbus.Array(self.GetInterfaces(), signature='s'), 'TargetHandle': lambda: dbus.UInt32(self._handle.get_id()), - 'TargetHandleType': lambda: dbus.UInt32(self._get_handle_type()), - 'TargetID': lambda: dbus.String(self._get_target_id()), + 'TargetHandleType': lambda: dbus.UInt32(self._handle.get_type()), + 'TargetID': lambda: dbus.String(self._handle.get_name()), 'Requested': lambda: self._requested}) self._add_immutables({ @@ -88,19 +98,9 @@ class Channel(_Channel, DBusProperties): def _add_immutables(self, props): self._immutable_properties.update(props) - def _get_handle_type(self): - if self._handle: - return self._handle.get_type() - else: - return CONNECTION_HANDLE_TYPE_NONE - - def _get_target_id(self): - if self._handle: - return self._handle.get_name() - else: - return '' - def get_props(self): + """Despite its name, this function actually only returns immutable channel + properties.""" props = dict() for prop, iface in self._immutable_properties.items(): props[iface + '.' + prop] = \ @@ -123,10 +123,7 @@ class Channel(_Channel, DBusProperties): """ Returns the handle type and number if this channel represents a communication with a particular contact, room or server-stored list, or zero if it is transient and defined only by its contents. """ - if self._handle: - return self._handle.get_type(), self._handle - else: - return (CONNECTION_HANDLE_TYPE_NONE, 0) + return (self._handle.get_type(), self._handle.get_id()) @dbus.service.method(CHANNEL_INTERFACE, in_signature='', out_signature='as') def GetInterfaces(self): @@ -138,88 +135,76 @@ class Channel(_Channel, DBusProperties): """ return self._interfaces -from telepathy._generated.Channel_Type_Contact_List \ +from _generated.Channel_Type_Contact_List \ import ChannelTypeContactList as _ChannelTypeContactListIface class ChannelTypeContactList(Channel, _ChannelTypeContactListIface): __doc__ = _ChannelTypeContactListIface.__doc__ - def __init__(self, connection, manager, props): - """ - Initialise the channel. - - Parameters: - connection - the parent Telepathy Connection object - """ - Channel.__init__(self, connection, manager, props) - - -from telepathy._generated.Channel_Type_File_Transfer \ - import ChannelTypeFileTransfer as _ChannelTypeFileTransferIface - -class ChannelTypeFileTransfer(Channel, _ChannelTypeFileTransferIface): - __doc__ = _ChannelTypeFileTransferIface.__doc__ - - def __init__(self, connection, manager, props): + def __init__(self, connection, manager, props, object_path=None): """ Initialise the channel. Parameters: connection - the parent Telepathy Connection object """ - Channel.__init__(self, connection, manager, props) + Channel.__init__(self, connection, manager, props, + object_path=object_path) -from telepathy._generated.Channel_Type_File_Transfer \ +from _generated.Channel_Type_File_Transfer \ import ChannelTypeFileTransfer as _ChannelTypeFileTransferIface class ChannelTypeFileTransfer(Channel, _ChannelTypeFileTransferIface): __doc__ = _ChannelTypeFileTransferIface.__doc__ - def __init__(self, connection, manager, props): + def __init__(self, connection, manager, props, object_path=None): """ Initialise the channel. Parameters: connection - the parent Telepathy Connection object """ - Channel.__init__(self, connection, manager, props) + Channel.__init__(self, connection, manager, props, + object_path=object_path) -from telepathy._generated.Channel_Type_Streamed_Media \ +from _generated.Channel_Type_Streamed_Media \ import ChannelTypeStreamedMedia as _ChannelTypeStreamedMediaIface class ChannelTypeStreamedMedia(Channel, _ChannelTypeStreamedMediaIface): __doc__ = _ChannelTypeStreamedMediaIface.__doc__ - def __init__(self, connection, manager, props): + def __init__(self, connection, manager, props, object_path=None): """ Initialise the channel. Parameters: connection - the parent Telepathy Connection object """ - Channel.__init__(self, connection, manager, props) + Channel.__init__(self, connection, manager, props, + object_path=object_path) -from telepathy._generated.Channel_Type_Room_List \ +from _generated.Channel_Type_Room_List \ import ChannelTypeRoomList as _ChannelTypeRoomListIface class ChannelTypeRoomList(Channel, _ChannelTypeRoomListIface): __doc__ = _ChannelTypeRoomListIface.__doc__ - def __init__(self, connection, manager, props): + def __init__(self, connection, manager, props, object_path=None): """ Initialise the channel. Parameters: connection - the parent Telepathy Connection object """ - Channel.__init__(self, connection, manager, props) + Channel.__init__(self, connection, manager, props, + object_path=object_path) self._listing_rooms = False self._rooms = {} - self._add_immutables(self, {'Server': CHANNEL_TYPE_ROOM_LIST}) + self._add_immutables({'Server': CHANNEL_TYPE_ROOM_LIST}) @dbus.service.method(CHANNEL_TYPE_ROOM_LIST, in_signature='', out_signature='b') def GetListingRooms(self): @@ -230,20 +215,21 @@ class ChannelTypeRoomList(Channel, _ChannelTypeRoomListIface): self._listing_rooms = listing -from telepathy._generated.Channel_Type_Text \ +from _generated.Channel_Type_Text \ import ChannelTypeText as _ChannelTypeTextIface class ChannelTypeText(Channel, _ChannelTypeTextIface): __doc__ = _ChannelTypeTextIface.__doc__ - def __init__(self, connection, manager, props): + def __init__(self, connection, manager, props, object_path=None): """ Initialise the channel. Parameters: connection - the parent Telepathy Connection object """ - Channel.__init__(self, connection, manager, props) + Channel.__init__(self, connection, manager, props, + object_path=object_path) self._pending_messages = {} self._message_types = [CHANNEL_TEXT_MESSAGE_TYPE_NORMAL] @@ -308,17 +294,20 @@ class ChannelTypeText(Channel, _ChannelTypeTextIface): @dbus.service.signal(CHANNEL_TYPE_TEXT, signature='uuuuus') def Received(self, id, timestamp, sender, type, flags, text): - self._pending_messages[id] = (timestamp, sender, type, flags, text) + if id in self._pending_messages: + raise ValueError("You can't receive the same message twice.") + else: + self._pending_messages[id] = (timestamp, sender, type, flags, text) -from telepathy._generated.Channel_Interface_Chat_State \ +from _generated.Channel_Interface_Chat_State \ import ChannelInterfaceChatState -from telepathy._generated.Channel_Interface_DTMF import ChannelInterfaceDTMF +from _generated.Channel_Interface_DTMF import ChannelInterfaceDTMF -from telepathy._generated.Channel_Interface_Group \ +from _generated.Channel_Interface_Group \ import ChannelInterfaceGroup as _ChannelInterfaceGroup class ChannelInterfaceGroup(_ChannelInterfaceGroup, DBusProperties): @@ -388,13 +377,13 @@ class ChannelInterfaceGroup(_ChannelInterfaceGroup, DBusProperties): self._remote_pending.difference_update(removed) -from telepathy._generated.Channel_Interface_Hold import ChannelInterfaceHold +from _generated.Channel_Interface_Hold import ChannelInterfaceHold # ChannelInterfaceMediaSignalling is in telepathy.server.media -from telepathy._generated.Channel_Interface_Password \ +from _generated.Channel_Interface_Password \ import ChannelInterfacePassword as _ChannelInterfacePassword class ChannelInterfacePassword(_ChannelInterfacePassword): @@ -413,4 +402,4 @@ class ChannelInterfacePassword(_ChannelInterfacePassword): self._password_flags &= ~removed -from telepathy._generated.Channel_Interface_Call_State import ChannelInterfaceCallState +from _generated.Channel_Interface_Call_State import ChannelInterfaceCallState