This commit is contained in:
Dan Williams 2006-06-16 15:25:21 -04:00
parent 0cae557ab5
commit c46d300c18

View File

@ -69,10 +69,10 @@ class Buddy(gobject.GObject):
return False return False
if service.get_type() in self._services.keys(): if service.get_type() in self._services.keys():
return False return False
self._services[service.get_type()] = service self._services[service.get_full_type()] = service
if self._valid: if self._valid:
self.emit("service-added", service) self.emit("service-added", service)
if service.get_type() == PRESENCE_SERVICE_TYPE: if service.get_full_type() == PRESENCE_SERVICE_TYPE:
# A buddy isn't valid until its official presence # A buddy isn't valid until its official presence
# service has been found and resolved # service has been found and resolved
self._valid = True self._valid = True
@ -87,18 +87,28 @@ class Buddy(gobject.GObject):
return return
if service.get_name() != self._nick_name: if service.get_name() != self._nick_name:
return return
if self._services.has_key(service.get_type()): if self._services.has_key(service.get_full_type()):
if self._valid: if self._valid:
self.emit("service-removed", service) self.emit("service-removed", service)
del self._services[service.get_type()] del self._services[service.get_full_type()]
if service.get_type() == PRESENCE_SERVICE_TYPE: if service.get_full_type() == PRESENCE_SERVICE_TYPE:
self._valid = False self._valid = False
def get_service_of_type(self, stype): def get_service_of_type(self, stype=None, activity=None):
"""Return a service of a certain type, or None if the buddy """Return a service of a certain type, or None if the buddy
doesn't provide that service.""" doesn't provide that service."""
if self._services.has_key(stype): short_stype = stype
return self._services[stype] if not short_stype:
raise RuntimeError("Need to specify a service type.")
uid = None
if activity:
uid = activity.get_id()
if self._services.has_key(short_stype):
return self._services[short_stype]
elif uid:
for service in self._services.values():
if service.get_type() == short_stype and service.get_activity_uid() == uid:
return service
return None return None
def is_valid(self): def is_valid(self):