Fixing a bug with deny lists
[theonering] / hand_tests / dbus_signals.py
1 #!/usr/bin/env python
2
3 import gobject
4 import dbus
5 import dbus.mainloop.glib
6 import telepathy
7
8
9 DBUS_PROPERTIES = 'org.freedesktop.DBus.Properties'
10
11
12 class AutoAcceptCall(object):
13
14         def __init__(self):
15                 self._sessionBus = dbus.SessionBus()
16                 self._chan = None
17
18         def start(self):
19                 self._sessionBus.add_signal_receiver(
20                         self._on_new_channel,
21                         "NewChannel",
22                         "org.freedesktop.Telepathy.Connection",
23                         None,
24                         None
25                 )
26
27         def _on_new_channel(self, channelObjectPath, channelType, handleType, handle, supressHandler):
28                 if channelType != telepathy.interfaces.CHANNEL_TYPE_STREAMED_MEDIA:
29                         return
30
31                 serviceName = channelObjectPath.rsplit("/", 1)[0][1:].replace("/", ".")
32                 self._chan = telepathy.client.Channel(serviceName, channelObjectPath)
33                 if False:
34                         # @bug Unsure why this isn't working
35                         self._chan[DBUS_PROPERTIES].Get(
36                                 telepathy.interfaces.CHANNEL_INTERFACE_GROUP,
37                                 'LocalPendingMembers',
38                                 reply_handler = self._on_got_pending_members,
39                                 error_handler = self._on_nothing,
40                         )
41                 else:
42                         self._chan[telepathy.interfaces.CHANNEL_INTERFACE_GROUP].GetLocalPendingMembersWithInfo(
43                                 reply_handler = self._on_got_pending_members,
44                                 error_handler = self._on_nothing,
45                         )
46
47         def _on_got_pending_members(self, pendings):
48                 for pendingHandle, instigatorHandle, reason, message in pendings:
49                         print pendingHandle, instigatorHandle, reason, message
50
51                 # @bug does not distinguish between inbound and outbound channels
52                 # @bug does not distinguish between who the call is from for use for TOR auto-pickup
53                 pendingHandles = [pendingWithInfo[0] for pendingWithInfo in pendings]
54                 self._chan[telepathy.interfaces.CHANNEL_INTERFACE_GROUP].AddMembers(
55                         reply_handler = self._on_members_added,
56                         error_handler = self._on_nothing,
57                 )
58
59         def _on_members_added(self):
60                 print "Should be picked up now"
61
62         def _on_nothing(*args):
63                 print "ERROR", args
64
65
66 if __name__ == "__main__":
67         l = dbus.mainloop.glib.DBusGMainLoop(set_as_default=True)
68         autoaccept = AutoAcceptCall()
69
70         gobject.threads_init()
71         gobject.idle_add(autoaccept.start)
72
73         mainloop = gobject.MainLoop(is_running=True)
74         mainloop.run()