2010-07-12 17:54:21 +02:00
|
|
|
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):
|
2010-07-12 20:33:19 +02:00
|
|
|
self._connections_per_account = {}
|
2010-07-12 17:54:21 +02:00
|
|
|
|
|
|
|
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)
|
2010-07-12 20:33:19 +02:00
|
|
|
self._connections_per_account[account_path] = connection
|
2010-07-12 17:54:21 +02:00
|
|
|
|
|
|
|
def get_preferred_connection(self):
|
|
|
|
best_connection = None, None
|
2010-07-12 20:33:19 +02:00
|
|
|
for account_path, connection in self._connections_per_account.items():
|
2010-07-12 17:54:21 +02:00
|
|
|
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
|
|
|
|
|
2010-07-12 20:33:19 +02:00
|
|
|
def get_connection(self, account_path):
|
|
|
|
return self._connections_per_account[account_path]
|
|
|
|
|
2010-07-13 12:15:43 +02:00
|
|
|
def get_connections_per_account(self):
|
|
|
|
return self._connections_per_account
|
2010-07-12 20:33:19 +02:00
|
|
|
|
2010-07-12 17:54:21 +02:00
|
|
|
_connection_manager = None
|
|
|
|
|
|
|
|
def get_connection_manager():
|
|
|
|
global _connection_manager
|
|
|
|
if not _connection_manager:
|
|
|
|
_connection_manager = ConnectionManager()
|
|
|
|
return _connection_manager
|