diff --git a/shell/ActivityHost.py b/shell/ActivityHost.py index 49e23d8f..9da0a4c6 100644 --- a/shell/ActivityHost.py +++ b/shell/ActivityHost.py @@ -5,6 +5,8 @@ from sugar import conf from sugar.activity import Activity from sugar.presence import PresenceService from sugar.canvas.IconColor import IconColor +from sugar.p2p import Stream +from sugar.p2p import network class ActivityHost: def __init__(self, shell, window): @@ -42,6 +44,12 @@ class ActivityHost: def share(self): self._activity.share() + def invite(self, buddy): + service = buddy.get_service_of_type("_presence_olpc._tcp") + stream = Stream.Stream.new_from_service(service, start_reader=False) + writer = stream.new_writer(service) + writer.custom_request("invite", None, None, self._id) + def get_shared(self): return self._activity.get_shared() diff --git a/shell/Friends.py b/shell/Friends.py index 456228fb..88189f54 100644 --- a/shell/Friends.py +++ b/shell/Friends.py @@ -4,6 +4,7 @@ from ConfigParser import ConfigParser import gobject from sugar.canvas.IconColor import IconColor +from sugar.presence import PresenceService from sugar import env class Friend: @@ -17,6 +18,10 @@ class Friend: def get_color(self): return IconColor(self._color) + def get_buddy(self): + pservice = PresenceService.get_instance() + return pservice.get_buddy_by_name(self._name) + class Friends(gobject.GObject): __gsignals__ = { 'friend-added': (gobject.SIGNAL_RUN_FIRST, diff --git a/shell/Owner.py b/shell/Owner.py index ea706d00..6b71d124 100644 --- a/shell/Owner.py +++ b/shell/Owner.py @@ -44,9 +44,15 @@ class ShellOwner(object): print "Owner '%s' using port %d" % (self._nick, self._service.get_port()) self._icon_stream = Stream.Stream.new_from_service(self._service) self._icon_stream.register_reader_handler(self._handle_buddy_icon_request, "get_buddy_icon") + self._icon_stream.register_reader_handler(self._handle_invite, "invite") def _handle_buddy_icon_request(self): """XMLRPC method, return the owner's icon encoded with base64.""" if self._icon: return base64.b64encode(self._icon) return "" + + def _handle_invite(self, activity_id): + """XMLRPC method, called when the owner is invited to an activity.""" + print '---------- invited to ' + activity_id + return "" diff --git a/shell/PresenceService/Buddy.py b/shell/PresenceService/Buddy.py index 1e27bc45..32fbd69c 100644 --- a/shell/PresenceService/Buddy.py +++ b/shell/PresenceService/Buddy.py @@ -229,13 +229,11 @@ class Buddy(object): raise RuntimeError("Activity is not yet valid.") if activity: - actid = activity.get_id() - for service in self._services.values(): - if service.get_type() == stype and service.get_activity_id() == actid: - return service - - if self._services.has_key(stype): - return self._services[stype] + key = (stype, activity.get_id()) + else: + key = (stype, None) + if self._services.has_key(key): + return self._services[key] return None def is_valid(self): diff --git a/shell/home/FriendsGroup.py b/shell/home/FriendsGroup.py index 48a55a07..52f2766c 100644 --- a/shell/home/FriendsGroup.py +++ b/shell/home/FriendsGroup.py @@ -18,9 +18,10 @@ class FriendsGroup(goocanvas.Group): WIDTH = 1200.0 * 1.9 HEIGHT = 900.0 * 1.9 - def __init__(self, friends, icon_layout): + def __init__(self, shell, friends, icon_layout): goocanvas.Group.__init__(self) + self._shell = shell self._icon_layout = icon_layout self._friends = friends @@ -43,8 +44,15 @@ class FriendsGroup(goocanvas.Group): color = self._theme.get_home_friends_color() self._friends_rect.set_property("fill-color", color) + def __friend_clicked_cb(self, icon): + activity = self._shell.get_current_activity() + buddy = icon.get_friend().get_buddy() + if buddy != None: + activity.invite(buddy) + def add_friend(self, friend): icon = FriendIcon(friend) + icon.connect('clicked', self.__friend_clicked_cb) self.add_child(icon) self._icon_layout.add_icon(icon) diff --git a/shell/home/HomeWindow.py b/shell/home/HomeWindow.py index b16e51fa..80db2954 100644 --- a/shell/home/HomeWindow.py +++ b/shell/home/HomeWindow.py @@ -48,7 +48,8 @@ class HomeWindow(gtk.Window): y2 = y1 + HomeGroup.HEIGHT icon_layout.set_bounds(x1, y1, x2, y2) - self._friends_group = FriendsGroup(owner.get_friends(), icon_layout) + self._friends_group = FriendsGroup(self._shell, owner.get_friends(), + icon_layout) self._friends_group.translate((self._width - FriendsGroup.WIDTH) / 2, (self._height - FriendsGroup.HEIGHT) / 2) root.add_child(self._friends_group)