Added detection of missed calls. As part of this I moved some of the connections...
[theonering] / src / tp / properties.py
1 # telepathy-python - Base classes defining the interfaces of the Telepathy framework
2 #
3 # Copyright (C) 2005, 2006, 2008 Collabora Limited
4 # Copyright (C) 2005, 2006 Nokia Corporation
5 # Copyright (C) 2008 Olivier Le Thanh Duong <olivier@lethanh.be>
6 #
7 # This library is free software; you can redistribute it and/or
8 # modify it under the terms of the GNU Lesser General Public
9 # License as published by the Free Software Foundation; either
10 # version 2.1 of the License, or (at your option) any later version.
11 #
12 # This library is distributed in the hope that it will be useful,
13 # but WITHOUT ANY WARRANTY; without even the implied warranty of
14 # MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the GNU
15 # Lesser General Public License for more details.
16 #
17 # You should have received a copy of the GNU Lesser General Public
18 # License along with this library; if not, write to the Free Software
19 # Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA  02110-1301  USA
20
21 import dbus
22 import dbus.service
23
24 from telepathy.interfaces import PROPERTIES_INTERFACE
25 import telepathy.errors
26
27 from telepathy._generated.Properties_Interface import PropertiesInterface
28
29 class DBusProperties(dbus.service.Interface):
30     def __init__(self):
31         if not getattr(self, '_interfaces', None):
32             self._interfaces = set()
33
34         self._interfaces.add(dbus.PROPERTIES_IFACE)
35
36         if not getattr(self, '_prop_getters', None):
37             self._prop_getters = {}
38             self._prop_setters = {}
39
40     def _implement_property_get(self, iface, dict):
41         self._prop_getters.setdefault(iface, {}).update(dict)
42
43     def _implement_property_set(self, iface, dict):
44         self._prop_setters.setdefault(iface, {}).update(dict)
45
46     @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='ss', out_signature='v')
47     def Get(self, interface_name, property_name):
48         if interface_name in self._prop_getters \
49             and property_name in self._prop_getters[interface_name]:
50                 return self._prop_getters[interface_name][property_name]()
51         else:
52             raise telepathy.errors.InvalidArgument()
53
54     @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='ssv', out_signature='')
55     def Set(self, interface_name, property_name, value):
56         if interface_name in self._prop_setters \
57             and property_name in self._prop_setters[interface_name]:
58                 self._prop_setters[interface_name][property_name](value)
59         else:
60             raise telepathy.errors.PermissionDenied()
61
62     @dbus.service.method(dbus_interface=dbus.PROPERTIES_IFACE, in_signature='s', out_signature='a{sv}')
63     def GetAll(self, interface_name):
64         if interface_name in self._prop_getters:
65             r = {}
66             for k, v in self._prop_getters[interface_name].items():
67                 r[k] = v()
68             return r
69         else:
70             raise telepathy.errors.InvalidArgument()