Initial import
[fso-scripts.git] / fso-listen-for-calls.py
1 #!/usr/bin/env python
2
3 import dbus
4 import gobject
5
6 from dbus.mainloop.glib import DBusGMainLoop
7 DBusGMainLoop(set_as_default=True)
8
9 def onCallStatus(sender = "", *args, **kwargs):
10     status = str(args[0])
11     if (args[1].has_key("peer")):
12         caller = str(args[1]["peer"])
13     else:
14         caller = "unknown"
15
16     print "onCallStatus"
17     print sender
18     print status
19     print caller
20     print
21
22 def fso_listen_for_calls():
23     bus = dbus.SystemBus()
24
25     usage_obj = bus.get_object("org.freesmartphone.ousaged", "/org/freesmartphone/Usage")
26     usage_iface = dbus.Interface(usage_obj, "org.freesmartphone.Usage")
27     usage_iface.RequestResource("GSM")
28
29     gsm_device_obj = bus.get_object("org.freesmartphone.ogsmd", "/org/freesmartphone/GSM/Device")
30     gsm_call_iface = dbus.Interface(gsm_device_obj, "org.freesmartphone.GSM.Call")
31
32     print "Set Functionality: full"
33     gsm_network_iface.SetFunctionality("full", True, "")
34
35     gsm_call_iface.connect_to_signal('CallStatus', onCallStatus)
36
37     print "starting the main loop"
38     loop = gobject.MainLoop()
39     try:
40         loop.run()
41     except KeyboardInterrupt:
42         print "Interrupted"
43         loop.quit()
44
45     gsm_network_iface.SetFunctionality("minimal", True, "")
46     usage_iface.ReleaseResource("GSM")
47
48 if __name__ == "__main__":
49     fso_listen_for_calls()