create buddy when connecting
This commit is contained in:
parent
6756c00917
commit
5ae3e292ca
@ -155,6 +155,19 @@ class Buddy(dbus.service.Object):
|
|||||||
self._icon = icon
|
self._icon = icon
|
||||||
self.IconChanged(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):
|
def is_owner(self):
|
||||||
return False
|
return False
|
||||||
|
|
||||||
@ -180,12 +193,8 @@ class Owner(Buddy):
|
|||||||
|
|
||||||
@dbus.service.method(_OWNER_INTERFACE,
|
@dbus.service.method(_OWNER_INTERFACE,
|
||||||
in_signature="a{sv}", out_signature="")
|
in_signature="a{sv}", out_signature="")
|
||||||
def SetProperties(self, properties):
|
def SetProperties(self, prop):
|
||||||
if "name" in properties.keys():
|
self.set_properties(self, prop)
|
||||||
self.set_name(properties["name"])
|
|
||||||
if "color" in properties.keys():
|
|
||||||
self.set_color(properties["color"])
|
|
||||||
self.PropertyChanged(properties)
|
|
||||||
|
|
||||||
# methods
|
# methods
|
||||||
def is_owner(self):
|
def is_owner(self):
|
||||||
@ -194,8 +203,3 @@ class Owner(Buddy):
|
|||||||
def set_icon(self, icon):
|
def set_icon(self, icon):
|
||||||
self._icon = icon
|
self._icon = icon
|
||||||
|
|
||||||
def set_name(self, name):
|
|
||||||
self._nick_name = name
|
|
||||||
|
|
||||||
def set_color(self, color):
|
|
||||||
self._color = color
|
|
||||||
|
@ -42,6 +42,7 @@ class PresenceService(dbus.service.Object):
|
|||||||
self._next_object_id = 0
|
self._next_object_id = 0
|
||||||
|
|
||||||
self._buddies = {} # key -> Buddy
|
self._buddies = {} # key -> Buddy
|
||||||
|
self._buddies_handle = {} # tp handle -> Buddy
|
||||||
self._activities = {} # activity id -> Activity
|
self._activities = {} # activity id -> Activity
|
||||||
|
|
||||||
self._icon_cache = buddyiconcache.BuddyIconCache()
|
self._icon_cache = buddyiconcache.BuddyIconCache()
|
||||||
@ -56,21 +57,8 @@ class PresenceService(dbus.service.Object):
|
|||||||
|
|
||||||
self._registry = ManagerRegistry()
|
self._registry = ManagerRegistry()
|
||||||
self._registry.LoadManagers()
|
self._registry.LoadManagers()
|
||||||
|
|
||||||
# Telepathy connection to the server
|
# 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')
|
mgr = self._registry.GetManager('gabble')
|
||||||
protocol = 'jabber'
|
protocol = 'jabber'
|
||||||
account = {
|
account = {
|
||||||
@ -83,6 +71,32 @@ class PresenceService(dbus.service.Object):
|
|||||||
conn = Connection(conn_bus_name, conn_object_path)
|
conn = Connection(conn_bus_name, conn_object_path)
|
||||||
self._server_client = telepathyclient.TelepathyClient(conn)
|
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")
|
@dbus.service.signal(_PRESENCE_INTERFACE, signature="o")
|
||||||
def ActivityAppeared(self, activity):
|
def ActivityAppeared(self, activity):
|
||||||
pass
|
pass
|
||||||
|
@ -15,14 +15,19 @@ loop = None
|
|||||||
|
|
||||||
import buddy
|
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):
|
def __init__(self, conn):
|
||||||
|
gobject.GObject.__init__(self)
|
||||||
|
|
||||||
conn[CONN_INTERFACE].connect_to_signal('StatusChanged',
|
conn[CONN_INTERFACE].connect_to_signal('StatusChanged',
|
||||||
self._status_changed_cb)
|
self._status_changed_cb)
|
||||||
conn[CONN_INTERFACE].Connect()
|
|
||||||
|
|
||||||
self.conn = conn
|
self.conn = conn
|
||||||
self.buddies = {}
|
|
||||||
|
|
||||||
def _request_list_channel(self, name):
|
def _request_list_channel(self, name):
|
||||||
handle = self.conn[CONN_INTERFACE].RequestHandles(
|
handle = self.conn[CONN_INTERFACE].RequestHandles(
|
||||||
@ -59,8 +64,8 @@ class TelepathyClient:
|
|||||||
# hack
|
# hack
|
||||||
self.conn._valid_interfaces.add(CONN_INTERFACE_ALIASING)
|
self.conn._valid_interfaces.add(CONN_INTERFACE_ALIASING)
|
||||||
|
|
||||||
#for handle in subscribe_handles:
|
for handle in subscribe_handles:
|
||||||
# self.buddies[handle] = buddy.Buddy()
|
self._contact_appeared(handle);
|
||||||
|
|
||||||
if CONN_INTERFACE_ALIASING in self.conn:
|
if CONN_INTERFACE_ALIASING in self.conn:
|
||||||
aliases = self.conn[CONN_INTERFACE_ALIASING].RequestAliases(subscribe_handles)
|
aliases = self.conn[CONN_INTERFACE_ALIASING].RequestAliases(subscribe_handles)
|
||||||
@ -104,9 +109,16 @@ class TelepathyClient:
|
|||||||
print 'disconnected'
|
print 'disconnected'
|
||||||
loop.quit()
|
loop.quit()
|
||||||
|
|
||||||
|
def run(self):
|
||||||
|
self.conn[CONN_INTERFACE].Connect()
|
||||||
|
|
||||||
def disconnect(self):
|
def disconnect(self):
|
||||||
self.conn[CONN_INTERFACE].Disconnect()
|
self.conn[CONN_INTERFACE].Disconnect()
|
||||||
|
|
||||||
|
def _contact_appeared(self, handle):
|
||||||
|
key = "1111111"
|
||||||
|
self.emit("contact-appeared", handle, key)
|
||||||
|
|
||||||
if __name__ == '__main__':
|
if __name__ == '__main__':
|
||||||
import logging
|
import logging
|
||||||
logging.basicConfig()
|
logging.basicConfig()
|
||||||
|
Loading…
Reference in New Issue
Block a user