diff --git a/shell/model/Owner.py b/shell/model/Owner.py index c49810e9..3e77d616 100644 --- a/shell/model/Owner.py +++ b/shell/model/Owner.py @@ -16,7 +16,7 @@ class ShellOwner(object): """Class representing the owner of this machine/instance. This class runs in the shell and serves up the buddy icon and other stuff. It's the server portion of the Owner, paired with the client portion in Buddy.py.""" - def __init__(self, shell): + def __init__(self): profile = conf.get_profile() self._nick = profile.get_nick_name() @@ -35,8 +35,6 @@ class ShellOwner(object): self._invites = Invites() - self._shell = shell - self._shell.connect('activity-changed', self.__activity_changed_cb) self._last_activity_update = time.time() self._pending_activity_update_timer = None self._pending_activity_update = None @@ -51,10 +49,6 @@ class ShellOwner(object): # Create and announce our presence color = conf.get_profile().get_color() props = {'color':color.to_string()} - activity = self._shell.get_current_activity() - if activity is not None: - props['cur_activity':activity.get_id()] - self._last_activity_update = time.time() self._service = self._pservice.register_service(self._nick, PRESENCE_SERVICE_TYPE, properties=props) logging.debug("Owner '%s' using port %d" % (self._nick, self._service.get_port())) @@ -79,10 +73,10 @@ class ShellOwner(object): logging.debug("*** Updating current activity to %s" % self._pending_activity_update) return False - def __activity_changed_cb(self, shell, activity): + def set_current_activity(self, activity_id): """Update our presence service with the latest activity, but no more frequently than every 30 seconds""" - self._pending_activity_update = activity.get_id() + self._pending_activity_update = activity_id # If there's no pending update, we must not have updated it in the # last 30 seconds (except for the initial update, hence we also check # for the last update) diff --git a/shell/model/ShellModel.py b/shell/model/ShellModel.py index 0820b443..5872b027 100644 --- a/shell/model/ShellModel.py +++ b/shell/model/ShellModel.py @@ -1,29 +1,15 @@ -import gobject - from sugar.presence import PresenceService from model.Friends import Friends from model.Owner import ShellOwner -class ShellModel(gobject.GObject): - __gsignals__ = { - 'activity-opened': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])), - 'activity-changed': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])), - 'activity-closed': (gobject.SIGNAL_RUN_FIRST, - gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])) - } - +class ShellModel: def __init__(self): - gobject.GObject.__init__(self) - - self._hosts = {} self._current_activity = None PresenceService.start() self._pservice = PresenceService.get_instance() - self._owner = ShellOwner(self) + self._owner = ShellOwner() self._owner.announce() self._friends = Friends() @@ -36,29 +22,9 @@ class ShellModel(gobject.GObject): def get_owner(self): return self._owner - def add_activity(self, activity_host): - self._hosts[activity_host.get_xid()] = activity_host - self.emit('activity-opened', activity_host) - - def set_current_activity(self, activity_xid): - activity_host = self._hosts[activity_xid] - if self._current_activity == activity_host: - return - - self._current_activity = activity_host - self.emit('activity-changed', activity_host) - - def remove_activity(self, activity_xid): - if self._hosts.has_key(activity_xid): - host = self._hosts[activity_xid] - self.emit('activity-closed', host) - del self._hosts[activity_xid] - - def get_activity(self, activity_id): - for host in self._hosts.values(): - if host.get_id() == activity_id: - return host - return None + def set_current_activity(self, activity_id): + self._current_activity = activity_id + self._owner.set_current_activity(activity_id) def get_current_activity(self): return self._current_activity diff --git a/shell/view/Shell.py b/shell/view/Shell.py index 74f03b4e..f56f62df 100644 --- a/shell/view/Shell.py +++ b/shell/view/Shell.py @@ -13,10 +13,20 @@ from globalkeys import KeyGrabber import sugar class Shell(gobject.GObject): + __gsignals__ = { + 'activity-opened': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])), + 'activity-changed': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])), + 'activity-closed': (gobject.SIGNAL_RUN_FIRST, + gobject.TYPE_NONE, ([gobject.TYPE_PYOBJECT])) + } + def __init__(self, model): gobject.GObject.__init__(self) self._model = model + self._hosts = {} self._screen = wnck.screen_get_default() self._grid = Grid() @@ -57,16 +67,33 @@ class Shell(gobject.GObject): def __window_opened_cb(self, screen, window): if window.get_window_type() == wnck.WINDOW_NORMAL: - self._model.add_activity(ActivityHost(self, window)) + activity_host = ActivityHost(self, window) + self._hosts[activity_host.get_xid()] = activity_host + self.emit('activity-opened', activity_host) def __active_window_changed_cb(self, screen): window = screen.get_active_window() - if window and window.get_window_type() == wnck.WINDOW_NORMAL: - self._model.set_current_activity(window.get_xid()) + + if window == None: + self._model.set_current_activity(None) + self.emit('activity-changed', None) + + if window.get_window_type() == wnck.WINDOW_NORMAL: + activity_host = self._hosts[window.get_xid()] + + current = self._model.get_current_activity() + if activity_host.get_id() == current: + return + + self._model.set_current_activity(activity_host.get_id()) + self.emit('activity-changed', activity_host) def __window_closed_cb(self, screen, window): if window.get_window_type() == wnck.WINDOW_NORMAL: - self._model.remove_activity(window.get_xid()) + if self._hosts.has_key(window.get_xid()): + host = self._hosts[window.get_xid()] + self.emit('activity-closed', host) + del self._hosts[window.get_xid()] def get_model(self): return self._model @@ -100,3 +127,16 @@ class Shell(gobject.GObject): else: self._screen.toggle_showing_desktop(True) self._home_window.set_zoom_level(level) + + def get_current_activity(self): + activity_id = self._model.get_current_activity() + if activity_id: + return self._get_activity(activity_id) + else: + return None + + def _get_activity(self, activity_id): + for host in self._hosts.values(): + if host.get_id() == activity_id: + return host + return None diff --git a/shell/view/frame/RightPanel.py b/shell/view/frame/RightPanel.py index d2387611..14120590 100644 --- a/shell/view/frame/RightPanel.py +++ b/shell/view/frame/RightPanel.py @@ -21,8 +21,7 @@ class RightPanel(CanvasBox): self._pservice.connect('activity-appeared', self.__activity_appeared_cb) - shell.get_model().connect('activity-changed', - self.__activity_changed_cb) + shell.connect('activity-changed', self.__activity_changed_cb) def add(self, buddy): icon = BuddyIcon(self._shell, BuddyInfo(buddy)) @@ -42,7 +41,7 @@ class RightPanel(CanvasBox): self._buddies = {} def __activity_appeared_cb(self, pservice, activity_ps): - activity = self._shell.get_model().get_current_activity() + activity = self._shell.get_current_activity() if activity and activity_ps.get_id() == activity.get_id(): self._set_activity_ps(activity_ps) diff --git a/shell/view/frame/TopPanel.py b/shell/view/frame/TopPanel.py index af07ad4c..188a7d7e 100644 --- a/shell/view/frame/TopPanel.py +++ b/shell/view/frame/TopPanel.py @@ -37,8 +37,7 @@ class ActivityIcon(MenuIcon): def _action_cb(self, menu, action): if action == ActivityMenu.ACTION_SHARE: - shell_model = self._shell.get_model() - activity = shell_model.get_current_activity() + activity = shell.get_current_activity() if activity != None: activity.share() @@ -77,9 +76,8 @@ class TopPanel(goocanvas.Group): self._box = box - shell_model = shell.get_model() - shell_model.connect('activity-changed', self._activity_changed_cb) - self._set_current_activity(shell_model.get_current_activity()) + shell.connect('activity-changed', self._activity_changed_cb) + self._set_current_activity(shell.get_current_activity()) def _set_current_activity(self, activity): if self._activity_icon: diff --git a/shell/view/home/HomeGroup.py b/shell/view/home/HomeGroup.py index d01ba167..f01823ef 100644 --- a/shell/view/home/HomeGroup.py +++ b/shell/view/home/HomeGroup.py @@ -9,9 +9,8 @@ class TasksItem(DonutItem): self._items = {} - shell_model = shell.get_model() - shell_model.connect('activity_opened', self.__activity_opened_cb) - shell_model.connect('activity_closed', self.__activity_closed_cb) + shell.connect('activity_opened', self.__activity_opened_cb) + shell.connect('activity_closed', self.__activity_closed_cb) def __activity_opened_cb(self, model, activity): self._add(activity)