Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/services/presence2/presenceservice.py
diff options
context:
space:
mode:
authorDan Williams <dcbw@redhat.com>2007-02-23 17:04:16 (GMT)
committer Dan Williams <dcbw@redhat.com>2007-02-23 17:04:16 (GMT)
commit03747e2c6c228fe1be706e85f40fb0bcb5ce433b (patch)
tree138788186b4bcfb299c04bf337bc9084eff80e42 /services/presence2/presenceservice.py
parentb9fb0f73f10bd598ebbc5d7e5f117b0711bc3a1c (diff)
Find and use an existing gabble connection, if any
Diffstat (limited to 'services/presence2/presenceservice.py')
-rw-r--r--services/presence2/presenceservice.py50
1 files changed, 36 insertions, 14 deletions
diff --git a/services/presence2/presenceservice.py b/services/presence2/presenceservice.py
index af70969..109fd0f 100644
--- a/services/presence2/presenceservice.py
+++ b/services/presence2/presenceservice.py
@@ -17,7 +17,9 @@
import gobject
import dbus, dbus.service, dbus.glib
from telepathy.client import ManagerRegistry, Connection
-from telepathy.interfaces import CONN_MGR_INTERFACE
+from telepathy.interfaces import (CONN_MGR_INTERFACE, CONN_INTERFACE)
+from telepathy.constants import (CONNECTION_STATUS_CONNECTING, CONNECTION_STATUS_CONNECTED,
+ CONNECTION_STATUS_DISCONNECTED, CONNECTION_HANDLE_TYPE_CONTACT)
import telepathyclient
from buddy import Buddy, Owner
@@ -58,19 +60,7 @@ class PresenceService(dbus.service.Object):
self._registry = ManagerRegistry()
self._registry.LoadManagers()
- # Telepathy connection to the server
- mgr = self._registry.GetManager('gabble')
- protocol = 'jabber'
- account = {
- 'account': 'olpc@collabora.co.uk',
- 'password': 'learn',
- 'server': 'light.bluelinux.co.uk'
- }
- conn_bus_name, conn_object_path = \
- mgr[CONN_MGR_INTERFACE].RequestConnection(protocol, account)
- conn = Connection(conn_bus_name, conn_object_path)
- self._server_client = telepathyclient.TelepathyClient(conn)
-
+ self._server_client = self._connect_to_server()
self._handles[self._server_client] = {}
# Telepathy link local connection
@@ -82,6 +72,38 @@ class PresenceService(dbus.service.Object):
dbus.service.Object.__init__(self, self._bus_name, _PRESENCE_PATH)
+ def _connect_to_server(self):
+ protocol = 'jabber'
+ account = {
+ 'account': 'olpc@collabora.co.uk',
+ 'password': 'learn',
+ 'server': 'light.bluelinux.co.uk'
+ }
+
+ mgr = self._registry.GetManager('gabble')
+ conn = None
+
+ # Search existing connections, if any, that we might be able to use
+ connections = Connection.get_connections()
+ for item in connections:
+ if item[CONN_INTERFACE].GetProtocol() != protocol:
+ continue
+ if not item.object_path.startswith("/org/freedesktop/Telepathy/Connection/gabble/jabber/"):
+ continue
+ if item[CONN_INTERFACE].GetStatus() == CONNECTION_STATUS_CONNECTED:
+ self_name = account['account']
+ test_handle = item[CONN_INTERFACE].RequestHandles(CONNECTION_HANDLE_TYPE_CONTACT, [self_name])[0]
+ if item[CONN_INTERFACE].GetSelfHandle() != test_handle:
+ continue
+ conn = item
+
+ if not conn:
+ conn_bus_name, conn_object_path = \
+ mgr[CONN_MGR_INTERFACE].RequestConnection(protocol, account)
+ conn = Connection(conn_bus_name, conn_object_path)
+
+ return telepathyclient.TelepathyClient(conn)
+
def _contact_online(self, tp, handle, key):
buddy = self._buddies.get(key)