PS fixes; use correct type on public keys and hide invalid buddies

This commit is contained in:
Dan Williams 2007-04-10 10:59:35 -04:00
parent c9310c2220
commit 48cab08b33
4 changed files with 21 additions and 17 deletions

View File

@ -13,6 +13,7 @@ sugar_PYTHON = \
buddyiconcache.py \
linklocal_plugin.py \
presenceservice.py \
psutils.py \
server_plugin.py
bin_SCRIPTS = sugar-presence-service

View File

@ -170,7 +170,10 @@ class Buddy(DBusGObject):
props['owner'] = self.props.owner
props['key'] = self.props.key
props['color'] = self.props.color
if self.props.current_activity:
props['current-activity'] = self.props.current_activity
else:
props['current-activity'] = ""
return props
# methods

View File

@ -89,8 +89,7 @@ class PresenceService(dbus.service.Object):
def _contact_online(self, tp, handle, props):
new_buddy = False
key = props['key']
buddy = self._buddies.get(key)
buddy = self._buddies.get(props["key"])
if not buddy:
# we don't know yet this buddy
objid = self._get_next_object_id()
@ -253,26 +252,33 @@ class PresenceService(dbus.service.Object):
def GetActivities(self):
ret = []
for act in self._activities.values():
if act.props.valid:
ret.append(act.object_path())
return ret
@dbus.service.method(_PRESENCE_INTERFACE, in_signature="s", out_signature="o")
def GetActivityById(self, actid):
if self._activities.has_key(actid):
return self._activities[actid].object_path()
act = self._activities[actid]
if act.props.valid:
return act.object_path()
raise NotFoundError("The activity was not found.")
@dbus.service.method(_PRESENCE_INTERFACE, out_signature="ao")
def GetBuddies(self):
ret = []
for buddy in self._buddies.values():
if buddy.props.valid:
ret.append(buddy.object_path())
return ret
@dbus.service.method(_PRESENCE_INTERFACE, in_signature="ay", out_signature="o")
def GetBuddyByPublicKey(self, key):
key = psutils.bytes_to_string(key)
if self._buddies.has_key(key):
return self._buddies[key].object_path()
buddy = self._buddies[key]
if buddy.props.valid:
return buddy.object_path()
raise NotFoundError("The buddy was not found.")
@dbus.service.method(_PRESENCE_INTERFACE, out_signature="o")

View File

@ -25,6 +25,7 @@ from buddyiconcache import BuddyIconCache
import logging
import os
import hashlib
import psutils
from telepathy.client import ConnectionManager, ManagerRegistry, Connection, Channel
from telepathy.interfaces import (
@ -304,7 +305,7 @@ class ServerPlugin(gobject.GObject):
# Set our OLPC buddy properties
props = {}
props['color'] = self._owner.props.color
props['key'] = self._owner.props.key
props['key'] = dbus.ByteArray(self._owner.props.key)
try:
self._conn[CONN_INTERFACE_BUDDY_INFO].SetProperties(props)
except dbus.DBusException, e:
@ -405,15 +406,8 @@ class ServerPlugin(gobject.GObject):
if not props.has_key('key'):
raise InvalidBuddyError("no key")
# Convert from D-Bus array types to a standard python byte array
key = ""
for item in props["key"]:
try:
# int type
key = key + "%s" % chr(item)
except TypeError:
# string type
key = key + str(item)
# Convert key from dbus byte array to python string
props["key"] = psutils.bytes_to_string(props["key"])
jid = self._conn[CONN_INTERFACE].InspectHandles(CONNECTION_HANDLE_TYPE_CONTACT, [handle])[0]
nick = self._conn[CONN_INTERFACE_ALIASING].RequestAliases([handle])[0]