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 RequestConnection(Action):
101 def __init__(self, cm, username, password, forward):
102 super(RequestConnection, 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 'account': self._username,
125 'password': self._password,
126 'forward': self._forward,
128 reply_handler = self._on_done,
129 error_handler = self._on_error,
132 def _on_done(self, busName, objectPath):
133 self._serviceName = busName
134 self._conn = telepathy.client.Connection(busName, objectPath)
135 super(RequestConnection, self)._on_done()
138 class Connect(Action):
140 def __init__(self, connAction):
141 super(Connect, self).__init__()
142 self._connAction = connAction
144 def queue_action(self):
145 self._connAction.conn[telepathy.server.CONNECTION].connect_to_signal(
149 self._connAction.conn[telepathy.server.CONNECTION].Connect(
150 reply_handler = self._on_generic_message,
151 error_handler = self._on_error,
155 super(Connect, self)._on_done()
157 def _on_change(self, status, reason):
158 if status == telepathy.constants.CONNECTION_STATUS_DISCONNECTED:
159 print "Disconnected!"
161 elif status == telepathy.constants.CONNECTION_STATUS_CONNECTED:
164 elif status == telepathy.constants.CONNECTION_STATUS_CONNECTING:
167 print "Status: %r" % status
170 class SimplePresenceOptions(Action):
172 def __init__(self, connAction):
173 super(SimplePresenceOptions, self).__init__()
174 self._connAction = connAction
176 def queue_action(self):
177 self._connAction.conn[DBUS_PROPERTIES].Get(
178 telepathy.server.CONNECTION_INTERFACE_SIMPLE_PRESENCE,
180 reply_handler = self._on_done,
181 error_handler = self._on_error,
184 def _on_done(self, statuses):
185 print "\tAvailable Statuses"
186 for (key, value) in statuses.iteritems():
187 print "\t\t - %s" % key
188 super(SimplePresenceOptions, self)._on_done()
191 class NullHandle(object):
202 class UserHandle(Action):
204 def __init__(self, connAction):
205 super(UserHandle, self).__init__()
206 self._connAction = connAction
215 return [self._handle]
217 def queue_action(self):
218 self._connAction.conn[telepathy.server.CONNECTION].GetSelfHandle(
219 reply_handler = self._on_done,
220 error_handler = self._on_error,
223 def _on_done(self, handle):
224 self._handle = handle
225 super(UserHandle, self)._on_done()
228 class RequestHandle(Action):
230 def __init__(self, connAction, handleType, handleNames):
231 super(RequestHandle, self).__init__()
232 self._connAction = connAction
234 self._handleType = handleType
235 self._handleNames = handleNames
243 return [self._handle]
245 def queue_action(self):
246 self._connAction.conn[telepathy.server.CONNECTION].RequestHandles(
249 reply_handler = self._on_done,
250 error_handler = self._on_error,
253 def _on_done(self, handles):
254 self._handle = handles[0]
255 super(RequestHandle, self)._on_done()
258 class RequestChannel(Action):
260 def __init__(self, connAction, handleAction, channelType, handleType):
261 super(RequestChannel, self).__init__()
262 self._connAction = connAction
263 self._handleAction = handleAction
265 self._channelType = channelType
266 self._handleType = handleType
272 def queue_action(self):
273 self._connAction.conn[telepathy.server.CONNECTION].RequestChannel(
276 self._handleAction.handle,
278 reply_handler = self._on_done,
279 error_handler = self._on_error,
282 def _on_done(self, channelObjectPath):
283 self._channel = telepathy.client.Channel(self._connAction.serviceName, channelObjectPath)
284 super(RequestChannel, self)._on_done()
287 class CloseChannel(Action):
289 def __init__(self, connAction, chanAction):
290 super(CloseChannel, self).__init__()
291 self._connAction = connAction
292 self._chanAction = chanAction
295 def queue_action(self):
296 self._chanAction.channel[telepathy.server.CHANNEL].Close(
297 reply_handler = self._on_done,
298 error_handler = self._on_error,
302 super(CloseChannel, self)._on_done()
305 class ContactHandles(Action):
307 def __init__(self, connAction, chanAction):
308 super(ContactHandles, self).__init__()
309 self._connAction = connAction
310 self._chanAction = chanAction
317 def queue_action(self):
318 self._chanAction.channel[DBUS_PROPERTIES].Get(
319 telepathy.server.CHANNEL_INTERFACE_GROUP,
321 reply_handler = self._on_done,
322 error_handler = self._on_error,
325 def _on_done(self, handles):
326 self._handles = list(handles)
327 super(ContactHandles, self)._on_done()
330 class SimplePresenceStatus(Action):
332 def __init__(self, connAction, handleAction):
333 super(SimplePresenceStatus, self).__init__()
334 self._connAction = connAction
335 self._handleAction = handleAction
337 def queue_action(self):
338 self._connAction.conn[telepathy.server.CONNECTION_INTERFACE_SIMPLE_PRESENCE].GetPresences(
339 self._handleAction.handles,
340 reply_handler = self._on_done,
341 error_handler = self._on_error,
344 def _on_done(self, aliases):
346 for hid, (presenceType, presence, presenceMessage) in aliases.iteritems():
347 print "\t\t%s:" % hid, presenceType, presence, presenceMessage
348 super(SimplePresenceStatus, self)._on_done()
351 class SetSimplePresence(Action):
353 def __init__(self, connAction, status, message):
354 super(SetSimplePresence, self).__init__()
355 self._connAction = connAction
356 self._status = status
357 self._message = message
359 def queue_action(self):
360 self._connAction.conn[telepathy.server.CONNECTION_INTERFACE_SIMPLE_PRESENCE].SetPresence(
363 reply_handler = self._on_done,
364 error_handler = self._on_error,
368 super(SetSimplePresence, self)._on_done()
371 class Aliases(Action):
373 def __init__(self, connAction, handleAction):
374 super(Aliases, self).__init__()
375 self._connAction = connAction
376 self._handleAction = handleAction
378 def queue_action(self):
379 self._connAction.conn[telepathy.server.CONNECTION_INTERFACE_ALIASING].RequestAliases(
380 self._handleAction.handles,
381 reply_handler = self._on_done,
382 error_handler = self._on_error,
385 def _on_done(self, aliases):
387 for h, alias in zip(self._handleAction.handles, aliases):
388 print "\t\t", h, alias
389 super(Aliases, self)._on_done()
394 def __init__(self, connAction, chanAction, handleAction):
395 super(Call, self).__init__()
396 self._connAction = connAction
397 self._chanAction = chanAction
398 self._handleAction = handleAction
400 def queue_action(self):
401 self._chanAction.channel[telepathy.server.CHANNEL_TYPE_STREAMED_MEDIA].RequestStreams(
402 self._handleAction.handle,
403 [telepathy.constants.MEDIA_STREAM_TYPE_AUDIO],
404 reply_handler = self._on_done,
405 error_handler = self._on_error,
408 def _on_done(self, handle):
410 super(Call, self)._on_done()
413 class SendText(Action):
415 def __init__(self, connAction, chanAction, handleAction, messageType, message):
416 super(SendText, self).__init__()
417 self._connAction = connAction
418 self._chanAction = chanAction
419 self._handleAction = handleAction
420 self._messageType = messageType
421 self._message = message
423 def queue_action(self):
424 self._chanAction.channel[telepathy.server.CHANNEL_TYPE_TEXT].Send(
427 reply_handler = self._on_done,
428 error_handler = self._on_error,
433 super(SendText, self)._on_done()
438 def __init__(self, length):
439 super(Sleep, self).__init__()
440 self._length = length
442 def queue_action(self):
443 gobject.timeout_add(self._length, self._on_done)
449 super(Block, self).__init__()
451 def queue_action(self):
455 #super(SendText, self)._on_done()
459 class Disconnect(Action):
461 def __init__(self, connAction):
462 super(Disconnect, self).__init__()
463 self._connAction = connAction
465 def queue_action(self):
466 self._connAction.conn[telepathy.server.CONNECTION].Disconnect(
467 reply_handler = self._on_done,
468 error_handler = self._on_error,
472 if __name__ == '__main__':
473 loop = gobject.MainLoop()
476 cm = get_connection_manager(reg)
478 nullHandle = NullHandle()
480 dummy = DummyAction()
485 dp = DisplayParams(cm)
486 lastAction.append_action(dp)
490 username = sys.argv[1]
491 password = sys.argv[2]
492 forward = sys.argv[3]
493 reqcon = RequestConnection(cm, username, password, forward)
494 lastAction.append_action(reqcon)
498 reqcon = RequestConnection(cm, username, password, forward)
499 lastAction.append_action(reqcon)
502 con = Connect(reqcon)
503 lastAction.append_action(con)
507 spo = SimplePresenceOptions(reqcon)
508 lastAction.append_action(spo)
512 uh = UserHandle(reqcon)
513 lastAction.append_action(uh)
516 ua = Aliases(reqcon, uh)
517 lastAction.append_action(ua)
520 sps = SimplePresenceStatus(reqcon, uh)
521 lastAction.append_action(sps)
525 setdnd = SetSimplePresence(reqcon, "dnd", "")
526 lastAction.append_action(setdnd)
529 sps = SimplePresenceStatus(reqcon, uh)
530 lastAction.append_action(sps)
533 setdnd = SetSimplePresence(reqcon, "available", "")
534 lastAction.append_action(setdnd)
537 sps = SimplePresenceStatus(reqcon, uh)
538 lastAction.append_action(sps)
542 sl = Sleep(10 * 1000)
543 lastAction.append_action(sl)
547 rclh = RequestHandle(reqcon, telepathy.HANDLE_TYPE_LIST, ["subscribe"])
548 lastAction.append_action(rclh)
551 rclc = RequestChannel(
554 telepathy.CHANNEL_TYPE_CONTACT_LIST,
555 telepathy.HANDLE_TYPE_LIST,
557 lastAction.append_action(rclc)
560 ch = ContactHandles(reqcon, rclc)
561 lastAction.append_action(ch)
564 ca = Aliases(reqcon, ch)
565 lastAction.append_action(ca)
569 rch = RequestHandle(reqcon, telepathy.HANDLE_TYPE_CONTACT, ["18005558355"]) #(1-800-555-TELL)
570 lastAction.append_action(rch)
573 # making a phone call
576 smHandleType = telepathy.HANDLE_TYPE_CONTACT
578 smHandle = nullHandle
579 smHandleType = telepathy.HANDLE_TYPE_NONE
580 rsmc = RequestChannel(
583 telepathy.CHANNEL_TYPE_STREAMED_MEDIA,
586 lastAction.append_action(rsmc)
590 call = Call(reqcon, rsmc, rch)
591 lastAction.append_action(call)
595 rtc = RequestChannel(
598 telepathy.CHANNEL_TYPE_TEXT,
601 lastAction.append_action(rtc)
605 closechan = CloseChannel(reqcon, rtc)
606 lastAction.append_action(closechan)
607 lastAction = closechan
609 rtc = RequestChannel(
612 telepathy.CHANNEL_TYPE_TEXT,
615 lastAction.append_action(rtc)
619 sendtext = SendText(reqcon, rtc, rch, telepathy.CHANNEL_TEXT_MESSAGE_TYPE_NORMAL, "Boo!")
620 lastAction.append_action(sendtext)
621 lastAction = sendtext
625 lastAction.append_action(bl)
629 sl = Sleep(30 * 1000)
630 lastAction.append_action(sl)
633 dis = Disconnect(reqcon)
634 lastAction.append_action(dis)
637 quitter = QuitLoop(loop)
638 lastAction.append_action(quitter)
641 firstAction.queue_action()