minor connection setup cleanups
This commit is contained in:
parent
de902c41fd
commit
ca8f3a0484
@ -31,6 +31,7 @@ from telepathy.constants import (
|
|||||||
CONNECTION_HANDLE_TYPE_LIST, CONNECTION_HANDLE_TYPE_CONTACT,
|
CONNECTION_HANDLE_TYPE_LIST, CONNECTION_HANDLE_TYPE_CONTACT,
|
||||||
CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED)
|
CONNECTION_STATUS_REASON_AUTHENTICATION_FAILED)
|
||||||
|
|
||||||
|
_PROTOCOL = "jabber"
|
||||||
|
|
||||||
class ServerPlugin(gobject.GObject):
|
class ServerPlugin(gobject.GObject):
|
||||||
__gsignals__ = {
|
__gsignals__ = {
|
||||||
@ -49,7 +50,7 @@ class ServerPlugin(gobject.GObject):
|
|||||||
|
|
||||||
self._icon_cache = BuddyIconCache()
|
self._icon_cache = BuddyIconCache()
|
||||||
|
|
||||||
self._registry = registry
|
self._gabble_mgr = registry.GetManager('gabble')
|
||||||
self._online_contacts = set() # handles of online contacts
|
self._online_contacts = set() # handles of online contacts
|
||||||
self._account = self._get_account_info()
|
self._account = self._get_account_info()
|
||||||
|
|
||||||
@ -66,10 +67,8 @@ class ServerPlugin(gobject.GObject):
|
|||||||
account_info['password'] = profile.get_private_key_hash()
|
account_info['password'] = profile.get_private_key_hash()
|
||||||
return account_info
|
return account_info
|
||||||
|
|
||||||
def _init_connection(self, register=False):
|
def _find_existing_connection(self):
|
||||||
protocol = 'jabber'
|
our_name = self._account['account']
|
||||||
|
|
||||||
mgr = self._registry.GetManager('gabble')
|
|
||||||
|
|
||||||
# Search existing connections, if any, that we might be able to use
|
# Search existing connections, if any, that we might be able to use
|
||||||
connections = Connection.get_connections()
|
connections = Connection.get_connections()
|
||||||
@ -77,19 +76,17 @@ class ServerPlugin(gobject.GObject):
|
|||||||
for item in connections:
|
for item in connections:
|
||||||
if not item.object_path.startswith("/org/freedesktop/Telepathy/Connection/gabble/jabber/"):
|
if not item.object_path.startswith("/org/freedesktop/Telepathy/Connection/gabble/jabber/"):
|
||||||
continue
|
continue
|
||||||
if item[CONN_INTERFACE].GetStatus() == CONNECTION_STATUS_DISCONNECTED:
|
if item[CONN_INTERFACE].GetProtocol() != _PROTOCOL:
|
||||||
item[CONN_INTERFACE].Disconnect()
|
|
||||||
continue
|
|
||||||
if item[CONN_INTERFACE].GetProtocol() != protocol:
|
|
||||||
continue
|
continue
|
||||||
if item[CONN_INTERFACE].GetStatus() == CONNECTION_STATUS_CONNECTED:
|
if item[CONN_INTERFACE].GetStatus() == CONNECTION_STATUS_CONNECTED:
|
||||||
self_name = self._account['account']
|
test_handle = item[CONN_INTERFACE].RequestHandles(CONNECTION_HANDLE_TYPE_CONTACT, [our_name])[0]
|
||||||
test_handle = item[CONN_INTERFACE].RequestHandles(CONNECTION_HANDLE_TYPE_CONTACT, [self_name])[0]
|
|
||||||
if item[CONN_INTERFACE].GetSelfHandle() != test_handle:
|
if item[CONN_INTERFACE].GetSelfHandle() != test_handle:
|
||||||
continue
|
continue
|
||||||
conn = item
|
return item
|
||||||
break
|
return None
|
||||||
|
|
||||||
|
def _init_connection(self, register=False):
|
||||||
|
conn = self._find_existing_connection()
|
||||||
if not conn:
|
if not conn:
|
||||||
acct = self._account.copy()
|
acct = self._account.copy()
|
||||||
if register:
|
if register:
|
||||||
@ -97,8 +94,9 @@ class ServerPlugin(gobject.GObject):
|
|||||||
|
|
||||||
# Create a new connection
|
# Create a new connection
|
||||||
print acct
|
print acct
|
||||||
name, path = mgr[CONN_MGR_INTERFACE].RequestConnection(protocol, acct)
|
name, path = self._gabble_mgr[CONN_MGR_INTERFACE].RequestConnection(_PROTOCOL, acct)
|
||||||
conn = Connection(name, path)
|
conn = Connection(name, path)
|
||||||
|
del acct
|
||||||
|
|
||||||
conn[CONN_INTERFACE].connect_to_signal('StatusChanged', self._status_changed_cb)
|
conn[CONN_INTERFACE].connect_to_signal('StatusChanged', self._status_changed_cb)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user