Start implementing invites...

This commit is contained in:
Marco Pesenti Gritti 2006-09-04 14:30:44 +02:00
parent 73b793472c
commit cdbd4e28b4
6 changed files with 35 additions and 9 deletions

View File

@ -5,6 +5,8 @@ from sugar import conf
from sugar.activity import Activity from sugar.activity import Activity
from sugar.presence import PresenceService from sugar.presence import PresenceService
from sugar.canvas.IconColor import IconColor from sugar.canvas.IconColor import IconColor
from sugar.p2p import Stream
from sugar.p2p import network
class ActivityHost: class ActivityHost:
def __init__(self, shell, window): def __init__(self, shell, window):
@ -42,6 +44,12 @@ class ActivityHost:
def share(self): def share(self):
self._activity.share() 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): def get_shared(self):
return self._activity.get_shared() return self._activity.get_shared()

View File

@ -4,6 +4,7 @@ from ConfigParser import ConfigParser
import gobject import gobject
from sugar.canvas.IconColor import IconColor from sugar.canvas.IconColor import IconColor
from sugar.presence import PresenceService
from sugar import env from sugar import env
class Friend: class Friend:
@ -17,6 +18,10 @@ class Friend:
def get_color(self): def get_color(self):
return IconColor(self._color) return IconColor(self._color)
def get_buddy(self):
pservice = PresenceService.get_instance()
return pservice.get_buddy_by_name(self._name)
class Friends(gobject.GObject): class Friends(gobject.GObject):
__gsignals__ = { __gsignals__ = {
'friend-added': (gobject.SIGNAL_RUN_FIRST, 'friend-added': (gobject.SIGNAL_RUN_FIRST,

View File

@ -44,9 +44,15 @@ class ShellOwner(object):
print "Owner '%s' using port %d" % (self._nick, self._service.get_port()) 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 = 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_buddy_icon_request, "get_buddy_icon")
self._icon_stream.register_reader_handler(self._handle_invite, "invite")
def _handle_buddy_icon_request(self): def _handle_buddy_icon_request(self):
"""XMLRPC method, return the owner's icon encoded with base64.""" """XMLRPC method, return the owner's icon encoded with base64."""
if self._icon: if self._icon:
return base64.b64encode(self._icon) return base64.b64encode(self._icon)
return "" return ""
def _handle_invite(self, activity_id):
"""XMLRPC method, called when the owner is invited to an activity."""
print '---------- invited to ' + activity_id
return ""

View File

@ -229,13 +229,11 @@ class Buddy(object):
raise RuntimeError("Activity is not yet valid.") raise RuntimeError("Activity is not yet valid.")
if activity: if activity:
actid = activity.get_id() key = (stype, activity.get_id())
for service in self._services.values(): else:
if service.get_type() == stype and service.get_activity_id() == actid: key = (stype, None)
return service if self._services.has_key(key):
return self._services[key]
if self._services.has_key(stype):
return self._services[stype]
return None return None
def is_valid(self): def is_valid(self):

View File

@ -18,9 +18,10 @@ class FriendsGroup(goocanvas.Group):
WIDTH = 1200.0 * 1.9 WIDTH = 1200.0 * 1.9
HEIGHT = 900.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) goocanvas.Group.__init__(self)
self._shell = shell
self._icon_layout = icon_layout self._icon_layout = icon_layout
self._friends = friends self._friends = friends
@ -43,8 +44,15 @@ class FriendsGroup(goocanvas.Group):
color = self._theme.get_home_friends_color() color = self._theme.get_home_friends_color()
self._friends_rect.set_property("fill-color", 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): def add_friend(self, friend):
icon = FriendIcon(friend) icon = FriendIcon(friend)
icon.connect('clicked', self.__friend_clicked_cb)
self.add_child(icon) self.add_child(icon)
self._icon_layout.add_icon(icon) self._icon_layout.add_icon(icon)

View File

@ -48,7 +48,8 @@ class HomeWindow(gtk.Window):
y2 = y1 + HomeGroup.HEIGHT y2 = y1 + HomeGroup.HEIGHT
icon_layout.set_bounds(x1, y1, x2, y2) 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._friends_group.translate((self._width - FriendsGroup.WIDTH) / 2,
(self._height - FriendsGroup.HEIGHT) / 2) (self._height - FriendsGroup.HEIGHT) / 2)
root.add_child(self._friends_group) root.add_child(self._friends_group)