3
Example of how to discover exisiting Telepathy connections on the bus, and be
4
notified when connections appear and disappear.
11
from telepathy.interfaces import CONN_INTERFACE
12
from telepathy.client import Connection
14
conn_prefix = 'org.freedesktop.Telepathy.Connection.'
15
connection_status = ['Connected', 'Connecting', 'Disconnected']
18
def __init__(self, bus):
20
connections = Connection.get_connections()
22
for conn in connections:
23
self._watch_conn(conn)
24
status = connection_status[conn[CONN_INTERFACE].GetStatus()]
25
print 'found connection: %s (%s)' % (conn.service_name, status)
27
dbus = bus.get_object('org.freedesktop.DBus', '/org/freedesktop/DBus')
28
dbus.connect_to_signal('NameOwnerChanged', self._name_owner_changed_cb)
30
def _watch_conn(self, conn):
31
name = conn.service_name[len(conn_prefix):]
32
conn[CONN_INTERFACE].connect_to_signal('StatusChanged',
33
lambda status, reason:
34
self._status_changed_cb(name, status, reason))
36
def _name_owner_changed_cb(self, service, old, new):
37
if service.startswith(conn_prefix):
38
name = service[len(conn_prefix):]
41
conn = Connection(service)
42
self._watch_conn(conn)
43
status = connection_status[conn[CONN_INTERFACE].GetStatus()]
44
print 'new connection: %s (%s)' % (name, status)
46
print 'connection gone: %s' % name
48
def _status_changed_cb(self, name, status, reason):
49
print 'status changed: %s: %s' % (
50
name, connection_status[status])
52
if __name__ == '__main__':
54
loop = gobject.MainLoop()
58
except KeyboardInterrupt: