Merge branch 'master' of git+ssh://dev.laptop.org/git/sugar

This commit is contained in:
Marco Pesenti Gritti 2007-04-10 17:00:20 +02:00
commit 615bb50ab8
5 changed files with 47 additions and 17 deletions

View File

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

View File

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

View File

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

View File

@ -0,0 +1,26 @@
# Copyright (C) 2007, Red Hat, Inc.
#
# This program is free software; you can redistribute it and/or modify
# it under the terms of the GNU General Public License as published by
# the Free Software Foundation; either version 2 of the License, or
# (at your option) any later version.
#
# This program is distributed in the hope that it will be useful,
# but WITHOUT ANY WARRANTY; without even the implied warranty of
# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
# GNU General Public License for more details.
#
# You should have received a copy of the GNU General Public License
# along with this program; if not, write to the Free Software
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
def bytes_to_string(bytes):
# Handle both DBus byte arrays and strings
try:
# DBus Byte array
ret = ''.join([chr(item) for item in bytes])
except TypeError:
# Python string
ret = ''.join([str(item) for item in bytes])
return ret

View File

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