Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/services/presence2
diff options
context:
space:
mode:
authorGuillaume Desmottes <cassidy@cass-wks.(none)>2007-02-23 13:15:51 (GMT)
committer Guillaume Desmottes <cassidy@cass-wks.(none)>2007-02-23 13:15:51 (GMT)
commit5ae3e292ca9beddd8a13c3dffe8751839d23e09b (patch)
treeee1da6be98f95689704f670d4f648dcd930cf0f2 /services/presence2
parent6756c00917fec4892444fa8dfd70dee99c99f291 (diff)
create buddy when connecting
Diffstat (limited to 'services/presence2')
-rw-r--r--services/presence2/buddy.py26
-rw-r--r--services/presence2/presenceservice.py42
-rw-r--r--services/presence2/telepathyclient.py22
3 files changed, 60 insertions, 30 deletions
diff --git a/services/presence2/buddy.py b/services/presence2/buddy.py
index 984bf94..035a130 100644
--- a/services/presence2/buddy.py
+++ b/services/presence2/buddy.py
@@ -155,6 +155,19 @@ class Buddy(dbus.service.Object):
self._icon = icon
self.IconChanged(icon)
+ def _set_name(self, name):
+ self._nick_name = name
+
+ def _set_color(self, color):
+ self._color = color
+
+ def set_properties(self, prop):
+ if "name" in properties.keys():
+ self._set_name(properties["name"])
+ if "color" in properties.keys():
+ self._set_color(properties["color"])
+ self.PropertyChanged(properties)
+
def is_owner(self):
return False
@@ -180,12 +193,8 @@ class Owner(Buddy):
@dbus.service.method(_OWNER_INTERFACE,
in_signature="a{sv}", out_signature="")
- def SetProperties(self, properties):
- if "name" in properties.keys():
- self.set_name(properties["name"])
- if "color" in properties.keys():
- self.set_color(properties["color"])
- self.PropertyChanged(properties)
+ def SetProperties(self, prop):
+ self.set_properties(self, prop)
# methods
def is_owner(self):
@@ -194,8 +203,3 @@ class Owner(Buddy):
def set_icon(self, icon):
self._icon = icon
- def set_name(self, name):
- self._nick_name = name
-
- def set_color(self, color):
- self._color = color
diff --git a/services/presence2/presenceservice.py b/services/presence2/presenceservice.py
index 659c389..fffb7c5 100644
--- a/services/presence2/presenceservice.py
+++ b/services/presence2/presenceservice.py
@@ -42,6 +42,7 @@ class PresenceService(dbus.service.Object):
self._next_object_id = 0
self._buddies = {} # key -> Buddy
+ self._buddies_handle = {} # tp handle -> Buddy
self._activities = {} # activity id -> Activity
self._icon_cache = buddyiconcache.BuddyIconCache()
@@ -56,21 +57,8 @@ class PresenceService(dbus.service.Object):
self._registry = ManagerRegistry()
self._registry.LoadManagers()
- # Telepathy connection to the server
- self._server_client = None
- # Telepathy link local connection
- self._ll_client = None
-
- self._connect_server ()
-
- dbus.service.Object.__init__(self, self._bus_name, _PRESENCE_PATH)
-
- def _get_next_object_id(self):
- """Increment and return the object ID counter."""
- self._next_object_id = self._next_object_id + 1
- return self._next_object_id
- def _connect_server (self):
+ # Telepathy connection to the server
mgr = self._registry.GetManager('gabble')
protocol = 'jabber'
account = {
@@ -83,6 +71,32 @@ class PresenceService(dbus.service.Object):
conn = Connection(conn_bus_name, conn_object_path)
self._server_client = telepathyclient.TelepathyClient(conn)
+ # Telepathy link local connection
+ self._ll_client = None
+
+ self._server_client.connect('contact-appeared', self._contact_appeared)
+ self._server_client.run()
+
+ dbus.service.Object.__init__(self, self._bus_name, _PRESENCE_PATH)
+
+ def _contact_appeared(self, tp, handle, key):
+ if self._buddies.has_key(key):
+ # We already know this buddy
+ return
+
+ objid = self._get_next_object_id()
+ new_buddy = buddy.Buddy(self._bus_name, objid, self._icon_cache)
+ self._buddies[key] = new_buddy
+ self._buddies_handle[handle] = new_buddy
+
+ self.BuddyAppeared(new_buddy.object_path())
+
+
+ def _get_next_object_id(self):
+ """Increment and return the object ID counter."""
+ self._next_object_id = self._next_object_id + 1
+ return self._next_object_id
+
@dbus.service.signal(_PRESENCE_INTERFACE, signature="o")
def ActivityAppeared(self, activity):
pass
diff --git a/services/presence2/telepathyclient.py b/services/presence2/telepathyclient.py
index 8a7a71d..4ade31e 100644
--- a/services/presence2/telepathyclient.py
+++ b/services/presence2/telepathyclient.py
@@ -15,14 +15,19 @@ loop = None
import buddy
-class TelepathyClient:
+class TelepathyClient(gobject.GObject):
+ __gsignals__ = {
+ 'contact-appeared':(gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE,
+ ([gobject.TYPE_PYOBJECT, gobject.TYPE_PYOBJECT])),
+ }
+
def __init__(self, conn):
+ gobject.GObject.__init__(self)
+
conn[CONN_INTERFACE].connect_to_signal('StatusChanged',
self._status_changed_cb)
- conn[CONN_INTERFACE].Connect()
self.conn = conn
- self.buddies = {}
def _request_list_channel(self, name):
handle = self.conn[CONN_INTERFACE].RequestHandles(
@@ -59,8 +64,8 @@ class TelepathyClient:
# hack
self.conn._valid_interfaces.add(CONN_INTERFACE_ALIASING)
- #for handle in subscribe_handles:
- # self.buddies[handle] = buddy.Buddy()
+ for handle in subscribe_handles:
+ self._contact_appeared(handle);
if CONN_INTERFACE_ALIASING in self.conn:
aliases = self.conn[CONN_INTERFACE_ALIASING].RequestAliases(subscribe_handles)
@@ -104,9 +109,16 @@ class TelepathyClient:
print 'disconnected'
loop.quit()
+ def run(self):
+ self.conn[CONN_INTERFACE].Connect()
+
def disconnect(self):
self.conn[CONN_INTERFACE].Disconnect()
+ def _contact_appeared(self, handle):
+ key = "1111111"
+ self.emit("contact-appeared", handle, key)
+
if __name__ == '__main__':
import logging
logging.basicConfig()