diff options
author | Tomeu Vizoso <tomeu.vizoso@collabora.co.uk> | 2010-07-12 15:54:21 (GMT) |
---|---|---|
committer | Tomeu Vizoso <tomeu.vizoso@collabora.co.uk> | 2010-08-20 13:33:53 (GMT) |
commit | cc8ecd81e7eb5ee77d76b3752492cdbd6165625e (patch) | |
tree | 293297bedccae7db07a0b9623c626f5d1900c274 | |
parent | bd3a4ca747721f39eb8abf749a22f20c4ced115d (diff) |
Add src/sugar/presence/util.py
-rw-r--r-- | src/sugar/presence/util.py | 53 |
1 files changed, 53 insertions, 0 deletions
diff --git a/src/sugar/presence/util.py b/src/sugar/presence/util.py new file mode 100644 index 0000000..265e390 --- /dev/null +++ b/src/sugar/presence/util.py @@ -0,0 +1,53 @@ +import logging + +import dbus +from dbus import PROPERTIES_IFACE +from telepathy.interfaces import ACCOUNT, \ + ACCOUNT_MANAGER + +ACCOUNT_MANAGER_SERVICE = 'org.freedesktop.Telepathy.AccountManager' +ACCOUNT_MANAGER_PATH = '/org/freedesktop/Telepathy/AccountManager' + +class ConnectionManager(object): + def __init__(self): + self.connections_per_account = [] + + bus = dbus.SessionBus() + obj = bus.get_object(ACCOUNT_MANAGER_SERVICE, ACCOUNT_MANAGER_PATH) + account_manager = dbus.Interface(obj, ACCOUNT_MANAGER) + + logging.info('KILL_PS listen for accounts coming and going') + #account_manager.connect_to_signal('AccountValidityChanged', + # self.__account_validity_changed_cb) + + account_paths = account_manager.Get(ACCOUNT_MANAGER, 'ValidAccounts', + dbus_interface=PROPERTIES_IFACE) + for account_path in account_paths: + obj = bus.get_object(ACCOUNT_MANAGER_SERVICE, account_path) + #obj.connect_to_signal('AccountPropertyChanged', + # self.__account_property_changed_cb) + connection_path = obj.Get(ACCOUNT, 'Connection') + if connection_path == '/': + continue + + connection_name = connection_path.replace('/', '.')[1:] + connection = bus.get_object(connection_name, connection_path) + self.connections[account_path] = connection + + def get_preferred_connection(self): + best_connection = None, None + for account_path, connection in self.connections.items(): + if 'salut' in connection.object_path: + best_connection = account_path, connection + elif 'gabble' in connection.object_path: + best_connection = account_path, connection + break + return best_connection + +_connection_manager = None + +def get_connection_manager(): + global _connection_manager + if not _connection_manager: + _connection_manager = ConnectionManager() + return _connection_manager |