From 6865148c901079b5fccb33e0f3d148b9d6e42bea Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 30 Aug 2006 11:46:14 +0200 Subject: [PATCH] More refactoring. Start implementing friends. --- shell/Friends.py | 19 +++++++++++++++++++ shell/Owner.py | 5 +++++ shell/Shell.py | 4 ++-- shell/home/FriendsGroup.py | 4 ++-- shell/home/HomeWindow.py | 6 +++--- shell/home/MeshGroup.py | 3 ++- 6 files changed, 33 insertions(+), 8 deletions(-) create mode 100644 shell/Friends.py diff --git a/shell/Friends.py b/shell/Friends.py new file mode 100644 index 00000000..261074a5 --- /dev/null +++ b/shell/Friends.py @@ -0,0 +1,19 @@ +from sugar.canvas.IconColor import IconColor + +class Friend: + def __init__(self, name, color): + self._name = name + self._color = color + + def get_name(self): + return name + + def get_color(self): + return IconColor(self._color) + +class Friends(list): + def __init__(self): + list.__init__(self) + + def add_buddy(self, buddy): + self.add(Friend(buddy.get_name(), buddy.get_color())) diff --git a/shell/Owner.py b/shell/Owner.py index fe9682a8..ea706d00 100644 --- a/shell/Owner.py +++ b/shell/Owner.py @@ -6,6 +6,7 @@ from sugar import env from sugar.p2p import Stream from sugar.presence import PresenceService from sugar import conf +from Friends import Friends PRESENCE_SERVICE_TYPE = "_presence_olpc._tcp" @@ -29,6 +30,10 @@ class ShellOwner(object): break self._pservice = PresenceService.get_instance() + self._friends = Friends() + + def get_friends(self): + return self._friends def announce(self): # Create and announce our presence diff --git a/shell/Shell.py b/shell/Shell.py index 5bbaa191..2d239fd9 100755 --- a/shell/Shell.py +++ b/shell/Shell.py @@ -100,12 +100,12 @@ class Shell(gobject.GObject): ShellDbusService(self, bus_name) PresenceService.start() + self._pservice = PresenceService.get_instance() self._owner = ShellOwner() self._owner.announce() - self._pservice = PresenceService.get_instance() - self._home_window.set_presence_service(self._pservice) + self._home_window.set_owner(self._owner) self._chat_controller = ChatController(self) self._chat_controller.listen() diff --git a/shell/home/FriendsGroup.py b/shell/home/FriendsGroup.py index 72add7d0..15feffdc 100644 --- a/shell/home/FriendsGroup.py +++ b/shell/home/FriendsGroup.py @@ -18,11 +18,11 @@ class FriendsGroup(goocanvas.Group): WIDTH = 1200.0 * 1.9 HEIGHT = 900.0 * 1.9 - def __init__(self, icon_layout): + def __init__(self, friends, icon_layout): goocanvas.Group.__init__(self) - self._friend_to_child = {} self._icon_layout = icon_layout + self._friends = friends self._theme = Theme.get_instance() self._theme.connect("theme-changed", self.__theme_changed_cb) diff --git a/shell/home/HomeWindow.py b/shell/home/HomeWindow.py index fe493fc8..f1d444d4 100644 --- a/shell/home/HomeWindow.py +++ b/shell/home/HomeWindow.py @@ -28,7 +28,7 @@ class HomeWindow(gtk.Window): self.realize() self.window.set_type_hint(gtk.gdk.WINDOW_TYPE_HINT_DESKTOP) - def set_presence_service(self, pservice): + def set_owner(self, owner): root = self._view.get_model().get_root_item() icon_layout = IconLayout(MeshGroup.WIDTH, MeshGroup.HEIGHT) @@ -38,7 +38,7 @@ class HomeWindow(gtk.Window): y2 = y1 + FriendsGroup.HEIGHT icon_layout.set_bounds(x1, y1, x2, y2) - self._mesh_group = MeshGroup(self._shell, icon_layout, pservice) + self._mesh_group = MeshGroup(self._shell, owner, icon_layout) root.add_child(self._mesh_group) icon_layout = IconLayout(FriendsGroup.WIDTH, FriendsGroup.HEIGHT) @@ -48,7 +48,7 @@ class HomeWindow(gtk.Window): y2 = y1 + HomeGroup.HEIGHT icon_layout.set_bounds(x1, y1, x2, y2) - self._friends_group = FriendsGroup(icon_layout) + self._friends_group = FriendsGroup(owner, icon_layout) self._friends_group.translate((self._width - FriendsGroup.WIDTH) / 2, (self._height - FriendsGroup.HEIGHT) / 2) root.add_child(self._friends_group) diff --git a/shell/home/MeshGroup.py b/shell/home/MeshGroup.py index cd381a3d..3bb9747d 100644 --- a/shell/home/MeshGroup.py +++ b/shell/home/MeshGroup.py @@ -34,7 +34,7 @@ class MeshGroup(goocanvas.Group): WIDTH = 1200.0 * 3.5 HEIGHT = 900.0 * 3.5 - def __init__(self, shell, icon_layout, pservice): + def __init__(self, shell, owner, icon_layout): goocanvas.Group.__init__(self) self._shell = shell self._icon_layout = icon_layout @@ -48,6 +48,7 @@ class MeshGroup(goocanvas.Group): fill_color=color) self.add_child(self._mesh_rect) + pservice = PresenceService.get_instance() pservice.connect("service-appeared", self.__service_appeared_cb) for service in pservice.get_services():