6 import dbus.mainloop.glib
7 dbus.mainloop.glib.DBusGMainLoop(set_as_default = True)
12 DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties'
16 reg = telepathy.client.ManagerRegistry()
21 def get_connection_manager(reg):
22 cm = reg.GetManager('theonering')
31 def queue_action(self):
34 def append_action(self, action):
35 assert self._action is None
39 if self._action is None:
41 self._action.queue_action()
43 def _on_error(self, error):
46 def _on_generic_message(self, *args):
50 class DummyAction(Action):
52 def queue_action(self):
53 gobject.idle_add(self._on_done)
56 class QuitLoop(Action):
58 def __init__(self, loop):
59 super(QuitLoop, self).__init__()
62 def queue_action(self):
66 class DisplayParams(Action):
68 def __init__(self, cm):
69 super(DisplayParams, self).__init__()
72 def queue_action(self):
73 self._cm[telepathy.interfaces.CONN_MGR_INTERFACE].GetParameters(
75 reply_handler = self._on_done,
76 error_handler = self._on_error,
79 def _on_done(self, params):
80 print "Connection Parameters:"
81 for name, flags, signature, default in params:
82 print "\t%s (%s)" % (name, signature),
84 if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_REQUIRED:
86 if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_REGISTER:
88 if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_SECRET:
90 if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_DBUS_PROPERTY:
91 print "dbus-property",
92 if flags & telepathy.constants.CONN_MGR_PARAM_FLAG_HAS_DEFAULT:
93 print "has-default(%s)" % default,
96 super(DisplayParams, self)._on_done()
99 class Connect(Action):
101 def __init__(self, cm, username, password, forward):
102 super(Connect, self).__init__()
106 self._serviceName = None
108 self._username = username
109 self._password = password
110 self._forward = forward
117 def serviceName(self):
118 return self._serviceName
120 def queue_action(self):
121 self._cm[telepathy.server.CONNECTION_MANAGER].RequestConnection(
124 'username': self._username,
125 'password': self._password,
126 'forward': self._forward,
128 reply_handler = self._on_connection_requested,
129 error_handler = self._on_error,
132 def _on_connection_requested(self, busName, objectPath):
133 self._serviceName = busName
134 self._conn = telepathy.client.Connection(busName, objectPath)
135 self._conn[telepathy.server.CONNECTION].connect_to_signal(
139 self._conn[telepathy.server.CONNECTION].Connect(
140 reply_handler = self._on_generic_message,
141 error_handler = self._on_error,
145 super(Connect, self)._on_done()
147 def _on_change(self, status, reason):
148 if status == telepathy.constants.CONNECTION_STATUS_DISCONNECTED:
149 print "Disconnected!"
151 elif status == telepathy.constants.CONNECTION_STATUS_CONNECTED:
154 elif status == telepathy.constants.CONNECTION_STATUS_CONNECTING:
157 print "Status: %r" % status
160 class SimplePresenceOptions(Action):
162 def __init__(self, connAction):
163 super(SimplePresenceOptions, self).__init__()
164 self._connAction = connAction
166 def queue_action(self):
167 self._connAction.conn[DBUS_PROPERTIES].Get(
168 telepathy.server.CONNECTION_INTERFACE_SIMPLE_PRESENCE,
170 reply_handler = self._on_done,
171 error_handler = self._on_error,
174 def _on_done(self, statuses):
175 print "\tAvailable Statuses"
176 for (key, value) in statuses.iteritems():
177 print "\t\t - %s" % key
178 super(SimplePresenceOptions, self)._on_done()
181 class NullHandle(object):
192 class UserHandle(Action):
194 def __init__(self, connAction):
195 super(UserHandle, self).__init__()
196 self._connAction = connAction
205 return [self._handle]
207 def queue_action(self):
208 self._connAction.conn[telepathy.server.CONNECTION].GetSelfHandle(
209 reply_handler = self._on_done,
210 error_handler = self._on_error,
213 def _on_done(self, handle):
214 self._handle = handle
215 super(UserHandle, self)._on_done()
218 class RequestHandle(Action):
220 def __init__(self, connAction, handleType, handleNames):
221 super(RequestHandle, self).__init__()
222 self._connAction = connAction
224 self._handleType = handleType
225 self._handleNames = handleNames
233 return [self._handle]
235 def queue_action(self):
236 self._connAction.conn[telepathy.server.CONNECTION].RequestHandles(
239 reply_handler = self._on_done,
240 error_handler = self._on_error,
243 def _on_done(self, handles):
244 self._handle = handles[0]
245 super(RequestHandle, self)._on_done()
248 class RequestChannel(Action):
250 def __init__(self, connAction, handleAction, channelType, handleType):
251 super(RequestChannel, self).__init__()
252 self._connAction = connAction
253 self._handleAction = handleAction
255 self._channelType = channelType
256 self._handleType = handleType
262 def queue_action(self):
263 self._connAction.conn[telepathy.server.CONNECTION].RequestChannel(
266 self._handleAction.handle,
268 reply_handler = self._on_done,
269 error_handler = self._on_error,
272 def _on_done(self, channelObjectPath):
273 self._channel = telepathy.client.Channel(self._connAction.serviceName, channelObjectPath)
274 super(RequestChannel, self)._on_done()
277 class ContactHandles(Action):
279 def __init__(self, connAction, chanAction):
280 super(ContactHandles, self).__init__()
281 self._connAction = connAction
282 self._chanAction = chanAction
289 def queue_action(self):
292 def _on_done(self, handle):
293 super(ContactHandles, self)._on_done()
296 class SimplePresenceStatus(Action):
298 def __init__(self, connAction, handleAction):
299 super(SimplePresenceStatus, self).__init__()
300 self._connAction = connAction
301 self._handleAction = handleAction
303 def queue_action(self):
304 self._connAction.conn[telepathy.server.CONNECTION_INTERFACE_SIMPLE_PRESENCE].GetPresences(
305 self._handleAction.handles,
306 reply_handler = self._on_done,
307 error_handler = self._on_error,
310 def _on_done(self, aliases):
312 for hid, (presenceType, presence, presenceMessage) in aliases.iteritems():
313 print "\t\t%s:" % hid, presenceType, presence, presenceMessage
314 super(SimplePresenceStatus, self)._on_done()
317 class SetSimplePresence(Action):
319 def __init__(self, connAction, status, message):
320 super(SetSimplePresence, self).__init__()
321 self._connAction = connAction
322 self._status = status
323 self._message = message
325 def queue_action(self):
326 self._connAction.conn[telepathy.server.CONNECTION_INTERFACE_SIMPLE_PRESENCE].SetPresence(
329 reply_handler = self._on_done,
330 error_handler = self._on_error,
334 super(SetSimplePresence, self)._on_done()
337 class Aliases(Action):
339 def __init__(self, connAction, handleAction):
340 super(Aliases, self).__init__()
341 self._connAction = connAction
342 self._handleAction = handleAction
344 def queue_action(self):
345 self._connAction.conn[telepathy.server.CONNECTION_INTERFACE_ALIASING].RequestAliases(
346 self._handleAction.handles,
347 reply_handler = self._on_done,
348 error_handler = self._on_error,
351 def _on_done(self, aliases):
353 for alias in aliases:
355 super(Aliases, self)._on_done()
360 def __init__(self, connAction, chanAction, handleAction):
361 super(Call, self).__init__()
362 self._connAction = connAction
363 self._chanAction = chanAction
364 self._handleAction = handleAction
366 def queue_action(self):
367 self._chanAction.channel[telepathy.server.CHANNEL_TYPE_STREAMED_MEDIA].RequestStreams(
368 self._handleAction.handle,
369 [telepathy.constants.MEDIA_STREAM_TYPE_AUDIO],
370 reply_handler = self._on_done,
371 error_handler = self._on_error,
374 def _on_done(self, handle):
376 super(Call, self)._on_done()
379 class SendText(Action):
381 def __init__(self, connAction, chanAction, handleAction, messageType, message):
382 super(SendText, self).__init__()
383 self._connAction = connAction
384 self._chanAction = chanAction
385 self._handleAction = handleAction
386 self._messageType = messageType
387 self._message = message
389 def queue_action(self):
390 self._chanAction.channel[telepathy.server.CHANNEL_TYPE_TEXT].Send(
393 reply_handler = self._on_done,
394 error_handler = self._on_error,
399 super(SendText, self)._on_done()
405 super(Block, self).__init__()
407 def queue_action(self):
411 #super(SendText, self)._on_done()
415 class Disconnect(Action):
417 def __init__(self, connAction):
418 super(Disconnect, self).__init__()
419 self._connAction = connAction
421 def queue_action(self):
422 self._connAction.conn[telepathy.server.CONNECTION].Disconnect(
423 reply_handler = self._on_done,
424 error_handler = self._on_error,
428 if __name__ == '__main__':
429 loop = gobject.MainLoop()
432 cm = get_connection_manager(reg)
434 nullHandle = NullHandle()
436 dummy = DummyAction()
441 dp = DisplayParams(cm)
442 lastAction.append_action(dp)
446 username = sys.argv[1]
447 password = sys.argv[2]
448 forward = sys.argv[3]
449 con = Connect(cm, username, password, forward)
450 lastAction.append_action(con)
454 spo = SimplePresenceOptions(con)
455 lastAction.append_action(spo)
460 lastAction.append_action(uh)
463 ua = Aliases(con, uh)
464 lastAction.append_action(ua)
467 sps = SimplePresenceStatus(con, uh)
468 lastAction.append_action(sps)
472 setdnd = SetSimplePresence(con, "dnd", "")
473 lastAction.append_action(setdnd)
476 sps = SimplePresenceStatus(con, uh)
477 lastAction.append_action(sps)
480 setdnd = SetSimplePresence(con, "available", "")
481 lastAction.append_action(setdnd)
484 sps = SimplePresenceStatus(con, uh)
485 lastAction.append_action(sps)
489 rclh = RequestHandle(con, telepathy.HANDLE_TYPE_LIST, ["subscribe"])
490 lastAction.append_action(rclh)
493 rclc = RequestChannel(
496 telepathy.CHANNEL_TYPE_CONTACT_LIST,
497 telepathy.HANDLE_TYPE_LIST,
499 lastAction.append_action(rclc)
502 # @todo get aliases for contacts
505 rch = RequestHandle(con, telepathy.HANDLE_TYPE_CONTACT, ["18005558355"]) #(1-800-555-TELL)
506 lastAction.append_action(rch)
509 # making a phone call
512 smHandleType = telepathy.HANDLE_TYPE_CONTACT
514 smHandle = nullHandle
515 smHandleType = telepathy.HANDLE_TYPE_NONE
516 rsmc = RequestChannel(
519 telepathy.CHANNEL_TYPE_STREAMED_MEDIA,
522 lastAction.append_action(rsmc)
526 call = Call(con, rsmc, rch)
527 lastAction.append_action(call)
531 rtc = RequestChannel(
534 telepathy.CHANNEL_TYPE_TEXT,
537 lastAction.append_action(rtc)
541 sendtext = SendText(con, rtc, rch, telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, "Boo!")
542 lastAction.append_action(sendtext)
543 lastAction = sendtext
547 lastAction.append_action(bl)
550 dis = Disconnect(con)
551 lastAction.append_action(dis)
554 quitter = QuitLoop(loop)
555 lastAction.append_action(quitter)
558 firstAction.queue_action()