diff --git a/shell/Shell.py b/shell/Shell.py index 98c4cbfe..5bbaa191 100755 --- a/shell/Shell.py +++ b/shell/Shell.py @@ -8,8 +8,6 @@ import gobject import wnck from home.HomeWindow import HomeWindow -from home.HomeModel import HomeModel -from sugar import env from Owner import ShellOwner from sugar.presence import PresenceService from ActivityHost import ActivityHost @@ -19,8 +17,9 @@ from sugar.activity import Activity from FirstTimeDialog import FirstTimeDialog from panel.PanelManager import PanelManager from globalkeys import KeyGrabber -import sugar from sugar import conf +from sugar import env +import sugar import sugar.logger class ShellDbusService(dbus.service.Object): @@ -105,17 +104,17 @@ class Shell(gobject.GObject): self._owner = ShellOwner() self._owner.announce() + self._pservice = PresenceService.get_instance() + self._home_window.set_presence_service(self._pservice) + self._chat_controller = ChatController(self) self._chat_controller.listen() - self.set_zoom_level(sugar.ZOOM_HOME) - - home_model = HomeModel() - self._home_window.set_model(home_model) - self._panel_manager = PanelManager(self) self._panel_manager.show_and_hide(10) + self.set_zoom_level(sugar.ZOOM_HOME) + def set_console(self, console): self._console = console @@ -177,8 +176,7 @@ class Shell(gobject.GObject): if activity: activity.present() else: - pservice = PresenceService.get_instance() - activity_ps = pservice.get_activity(activity_id) + activity_ps = self._pservice.get_activity(activity_id) if activity_ps: activity = ActivityFactory.create(info.get_id()) diff --git a/shell/home/FriendsGroup.py b/shell/home/FriendsGroup.py index 5a875b26..72add7d0 100644 --- a/shell/home/FriendsGroup.py +++ b/shell/home/FriendsGroup.py @@ -18,7 +18,7 @@ class FriendsGroup(goocanvas.Group): WIDTH = 1200.0 * 1.9 HEIGHT = 900.0 * 1.9 - def __init__(self, icon_layout, data_model): + def __init__(self, icon_layout): goocanvas.Group.__init__(self) self._friend_to_child = {} @@ -34,11 +34,11 @@ class FriendsGroup(goocanvas.Group): radius_x=60, radius_y=60) self.add_child(self._friends_rect) - for friend in data_model: - self.add_friend(friend) +# for friend in data_model: +# self.add_friend(friend) - data_model.connect('friend-added', self.__friend_added_cb) - data_model.connect('friend-removed', self.__friend_removed_cb) +# data_model.connect('friend-added', self.__friend_added_cb) +# data_model.connect('friend-removed', self.__friend_removed_cb) def __theme_changed_cb(self, theme): color = self._theme.get_home_friends_color() diff --git a/shell/home/FriendsModel.py b/shell/home/FriendsModel.py deleted file mode 100644 index 87f2625e..00000000 --- a/shell/home/FriendsModel.py +++ /dev/null @@ -1,60 +0,0 @@ -import gobject - -from sugar.presence import PresenceService -from sugar.canvas.IconColor import IconColor -import logging - -class Friend: - def __init__(self, buddy): - self._buddy = buddy - - def get_name(self): - return self._buddy.get_name() - - def get_color(self): - color = self._buddy.get_color() - try: - icolor = IconColor(color) - except RuntimeError: - icolor = IconColor() - logging.info("Buddy %s doesn't have an allowed color; \ - using a random color instead." % self.get_name()) - return icolor - -class FriendsModel(gobject.GObject): - __gsignals__ = { - 'friend-added': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - ([gobject.TYPE_PYOBJECT])), - 'friend-removed': (gobject.SIGNAL_RUN_FIRST, gobject.TYPE_NONE, - ([gobject.TYPE_PYOBJECT])) - } - - def __init__(self): - gobject.GObject.__init__(self) - - self._friends = {} - - self._pservice = PresenceService.get_instance() - self._pservice.connect("buddy-appeared", self.__buddy_appeared_cb) - self._pservice.connect("buddy-disappeared", self.__buddy_disappeared_cb) - - for buddy in self._pservice.get_buddies(): - self.add_friend(buddy) - - def add_friend(self, buddy): - friend = Friend(buddy) - self._friends[buddy.get_name()] = friend - self.emit('friend-added', friend) - - def remove_friend(self, buddy): - self.emit('friend-removed', self._friends[buddy.get_name()]) - del self._friends[buddy.get_name()] - - def __iter__(self): - return self._friends.values().__iter__() - - def __buddy_appeared_cb(self, pservice, buddy): - self.add_friend(buddy) - - def __buddy_disappeared_cb(self, pservice, buddy): - self.remove_friend(buddy) diff --git a/shell/home/HomeModel.py b/shell/home/HomeModel.py deleted file mode 100644 index cd67694d..00000000 --- a/shell/home/HomeModel.py +++ /dev/null @@ -1,8 +0,0 @@ -from home.FriendsModel import FriendsModel - -class HomeModel: - def __init__(self): - self._friends = FriendsModel() - - def get_friends(self): - return self._friends diff --git a/shell/home/HomeWindow.py b/shell/home/HomeWindow.py index 917e904c..fe493fc8 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_model(self, model): + def set_presence_service(self, pservice): 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) + self._mesh_group = MeshGroup(self._shell, icon_layout, pservice) root.add_child(self._mesh_group) icon_layout = IconLayout(FriendsGroup.WIDTH, FriendsGroup.HEIGHT) @@ -48,8 +48,7 @@ class HomeWindow(gtk.Window): y2 = y1 + HomeGroup.HEIGHT icon_layout.set_bounds(x1, y1, x2, y2) - data_model = model.get_friends() - self._friends_group = FriendsGroup(icon_layout, data_model) + self._friends_group = FriendsGroup(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/Makefile.am b/shell/home/Makefile.am index 8e25d58b..b91b9d5b 100644 --- a/shell/home/Makefile.am +++ b/shell/home/Makefile.am @@ -2,12 +2,9 @@ sugardir = $(pkgdatadir)/shell/home sugar_PYTHON = \ __init__.py \ DonutItem.py \ - FriendsModel.py \ FriendsGroup.py \ IconLayout.py \ - MeshModel.py \ MeshGroup.py \ HomeGroup.py \ HomeWindow.py \ - HomeModel.py \ Theme.py diff --git a/shell/home/MeshGroup.py b/shell/home/MeshGroup.py index 18b6bc5d..cd381a3d 100644 --- a/shell/home/MeshGroup.py +++ b/shell/home/MeshGroup.py @@ -30,14 +30,11 @@ class ActivityItem(IconItem): activity = pservice.get_activity(self.get_id()) return IconColor(activity.get_color()) - def get_service(self): - return self._service - class MeshGroup(goocanvas.Group): WIDTH = 1200.0 * 3.5 HEIGHT = 900.0 * 3.5 - def __init__(self, shell, icon_layout): + def __init__(self, shell, icon_layout, pservice): goocanvas.Group.__init__(self) self._shell = shell self._icon_layout = icon_layout @@ -51,10 +48,9 @@ class MeshGroup(goocanvas.Group): fill_color=color) self.add_child(self._mesh_rect) - self._pservice = PresenceService.get_instance() - self._pservice.connect("service-appeared", self.__service_appeared_cb) + pservice.connect("service-appeared", self.__service_appeared_cb) - for service in self._pservice.get_services(): + for service in pservice.get_services(): self.__check_service(service) def __service_appeared_cb(self, pservice, service):