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
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.
"""
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']
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)
{'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({
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] = \
""" 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):
"""
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):
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]
@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):
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):
self._password_flags &= ~removed
-from telepathy._generated.Channel_Interface_Call_State import ChannelInterfaceCallState
+from _generated.Channel_Interface_Call_State import ChannelInterfaceCallState