+class SimplePresenceOptions(Action):
+
+ def __init__(self, connAction):
+ super(SimplePresenceOptions, self).__init__()
+ self._connAction = connAction
+
+ def queue_action(self):
+ self._connAction.conn[DBUS_PROPERTIES].Get(
+ telepathy.server.CONNECTION_INTERFACE_SIMPLE_PRESENCE,
+ 'Statuses',
+ reply_handler = self._on_done,
+ error_handler = self._on_error,
+ )
+
+ def _on_done(self, statuses):
+ print "\tAvailable Statuses"
+ for (key, value) in statuses.iteritems():
+ print "\t\t - %s" % key
+ super(SimplePresenceOptions, self)._on_done()
+
+
+class NullHandle(object):
+
+ @property
+ def handle(self):
+ return 0
+
+ @property
+ def handles(self):
+ return []
+
+
+class UserHandle(Action):
+
+ def __init__(self, connAction):
+ super(UserHandle, self).__init__()
+ self._connAction = connAction
+ self._handle = None
+
+ @property
+ def handle(self):
+ return self._handle
+
+ @property
+ def handles(self):
+ return [self._handle]
+
+ def queue_action(self):
+ self._connAction.conn[telepathy.server.CONNECTION].GetSelfHandle(
+ reply_handler = self._on_done,
+ error_handler = self._on_error,
+ )
+
+ def _on_done(self, handle):
+ self._handle = handle
+ super(UserHandle, self)._on_done()
+
+
+class RequestHandle(Action):
+
+ def __init__(self, connAction, handleType, handleNames):
+ super(RequestHandle, self).__init__()
+ self._connAction = connAction
+ self._handle = None
+ self._handleType = handleType
+ self._handleNames = handleNames
+
+ @property
+ def handle(self):
+ return self._handle
+
+ @property
+ def handles(self):
+ return [self._handle]
+
+ def queue_action(self):
+ self._connAction.conn[telepathy.server.CONNECTION].RequestHandles(
+ self._handleType,
+ self._handleNames,
+ reply_handler = self._on_done,
+ error_handler = self._on_error,
+ )
+
+ def _on_done(self, handles):
+ self._handle = handles[0]
+ super(RequestHandle, self)._on_done()
+
+
+class RequestChannel(Action):
+
+ def __init__(self, connAction, handleAction, channelType, handleType):
+ super(RequestChannel, self).__init__()
+ self._connAction = connAction
+ self._handleAction = handleAction
+ self._channel = None
+ self._channelType = channelType
+ self._handleType = handleType
+
+ @property
+ def channel(self):
+ return self._channel
+
+ def queue_action(self):
+ self._connAction.conn[telepathy.server.CONNECTION].RequestChannel(
+ self._channelType,
+ self._handleType,
+ self._handleAction.handle,
+ True,
+ reply_handler = self._on_done,
+ error_handler = self._on_error,
+ )
+
+ def _on_done(self, channelObjectPath):
+ self._channel = telepathy.client.Channel(self._connAction.serviceName, channelObjectPath)
+ super(RequestChannel, self)._on_done()
+
+
+class EnsureChannel(Action):
+
+ def __init__(self, connAction, channelType, handleType, handleId):
+ super(EnsureChannel, self).__init__()
+ self._connAction = connAction
+ self._channel = None
+ self._channelType = channelType
+ self._handleType = handleType
+ self._handleId = handleId
+ self._handle = None
+
+ @property
+ def channel(self):
+ return self._channel
+
+ @property
+ def handle(self):
+ return self._handle
+
+ @property
+ def handles(self):
+ return [self._handle]
+
+ def queue_action(self):
+ properties = {
+ telepathy.server.CHANNEL_INTERFACE+".ChannelType": self._channelType,
+ telepathy.server.CHANNEL_INTERFACE+".TargetHandleType": self._handleType,
+ telepathy.server.CHANNEL_INTERFACE+".TargetID": self._handleId,
+ }
+ self._connAction.conn[telepathy.server.CONNECTION_INTERFACE_REQUESTS].EnsureChannel(
+ properties,
+ reply_handler = self._on_done,
+ error_handler = self._on_error,
+ )
+
+ def _on_done(self, yours, channelObjectPath, properties):
+ print "Create?", not not yours
+ print "Path:", channelObjectPath
+ print "Properties:", properties
+ self._channel = telepathy.client.Channel(self._connAction.serviceName, channelObjectPath)
+ self._handle = properties[telepathy.server.CHANNEL_INTERFACE+".TargetHandle"]
+ super(EnsureChannel, self)._on_done()
+
+
+class CloseChannel(Action):
+
+ def __init__(self, connAction, chanAction):
+ super(CloseChannel, self).__init__()
+ self._connAction = connAction
+ self._chanAction = chanAction
+ self._handles = []
+
+ def queue_action(self):
+ self._chanAction.channel[telepathy.server.CHANNEL].Close(
+ reply_handler = self._on_done,
+ error_handler = self._on_error,
+ )
+
+ def _on_done(self):
+ super(CloseChannel, self)._on_done()
+
+
+class ContactHandles(Action):
+
+ def __init__(self, connAction, chanAction):
+ super(ContactHandles, self).__init__()
+ self._connAction = connAction
+ self._chanAction = chanAction
+ self._handles = []
+
+ @property
+ def handles(self):
+ return self._handles
+
+ def queue_action(self):
+ self._chanAction.channel[DBUS_PROPERTIES].Get(
+ telepathy.server.CHANNEL_INTERFACE_GROUP,
+ 'Members',
+ reply_handler = self._on_done,
+ error_handler = self._on_error,
+ )
+
+ def _on_done(self, handles):
+ self._handles = list(handles)
+ super(ContactHandles, self)._on_done()
+
+
+class SimplePresenceStatus(Action):
+
+ def __init__(self, connAction, handleAction):
+ super(SimplePresenceStatus, self).__init__()
+ self._connAction = connAction
+ self._handleAction = handleAction
+
+ def queue_action(self):
+ self._connAction.conn[telepathy.server.CONNECTION_INTERFACE_SIMPLE_PRESENCE].GetPresences(
+ self._handleAction.handles,
+ reply_handler = self._on_done,
+ error_handler = self._on_error,
+ )
+
+ def _on_done(self, aliases):
+ print "\tPresences:"
+ for hid, (presenceType, presence, presenceMessage) in aliases.iteritems():
+ print "\t\t%s:" % hid, presenceType, presence, presenceMessage
+ super(SimplePresenceStatus, self)._on_done()
+
+
+class SetSimplePresence(Action):
+
+ def __init__(self, connAction, status, message):
+ super(SetSimplePresence, self).__init__()
+ self._connAction = connAction
+ self._status = status
+ self._message = message
+
+ def queue_action(self):
+ self._connAction.conn[telepathy.server.CONNECTION_INTERFACE_SIMPLE_PRESENCE].SetPresence(
+ self._status,
+ self._message,
+ reply_handler = self._on_done,
+ error_handler = self._on_error,
+ )
+
+ def _on_done(self):
+ super(SetSimplePresence, self)._on_done()
+
+
+class Aliases(Action):
+
+ def __init__(self, connAction, handleAction):
+ super(Aliases, self).__init__()
+ self._connAction = connAction
+ self._handleAction = handleAction
+
+ def queue_action(self):
+ self._connAction.conn[telepathy.server.CONNECTION_INTERFACE_ALIASING].RequestAliases(
+ self._handleAction.handles,
+ reply_handler = self._on_done,
+ error_handler = self._on_error,
+ )
+
+ def _on_done(self, aliases):
+ print "\tAliases:"
+ for h, alias in zip(self._handleAction.handles, aliases):
+ print "\t\t", h, alias
+ super(Aliases, self)._on_done()
+
+
+class Call(Action):
+
+ def __init__(self, connAction, chanAction, handleAction):
+ super(Call, self).__init__()
+ self._connAction = connAction
+ self._chanAction = chanAction
+ self._handleAction = handleAction
+
+ def queue_action(self):
+ self._chanAction.channel[telepathy.server.CHANNEL_TYPE_STREAMED_MEDIA].RequestStreams(
+ self._handleAction.handle,
+ [telepathy.constants.MEDIA_STREAM_TYPE_AUDIO],
+ reply_handler = self._on_done,
+ error_handler = self._on_error,
+ )
+
+ def _on_done(self, handle):
+ print "Call started"
+ super(Call, self)._on_done()
+
+
+class SendText(Action):
+
+ def __init__(self, connAction, chanAction, handleAction, messageType, message):
+ super(SendText, self).__init__()
+ self._connAction = connAction
+ self._chanAction = chanAction
+ self._handleAction = handleAction
+ self._messageType = messageType
+ self._message = message
+
+ def queue_action(self):
+ self._chanAction.channel[telepathy.server.CHANNEL_TYPE_TEXT].Send(
+ self._messageType,
+ self._message,
+ reply_handler = self._on_done,
+ error_handler = self._on_error,
+ )
+
+ def _on_done(self,):
+ print "Message sent"
+ super(SendText, self)._on_done()
+
+
+class Sleep(Action):
+
+ def __init__(self, length):
+ super(Sleep, self).__init__()
+ self._length = length
+
+ def queue_action(self):
+ gobject.timeout_add(self._length, self._on_done)
+
+
+class Block(Action):
+
+ def __init__(self):
+ super(Block, self).__init__()
+
+ def queue_action(self):
+ print "Blocking"
+
+ def _on_done(self):
+ #super(SendText, self)._on_done()
+ pass
+
+