create buddy when connecting

This commit is contained in:
Guillaume Desmottes 2007-02-23 14:15:51 +01:00
parent 6756c00917
commit 5ae3e292ca
3 changed files with 60 additions and 30 deletions

View File

@ -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

View File

@ -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):
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

View File

@ -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()