diff --git a/shell/Shell.py b/shell/Shell.py index 86e9a5f7..8d03a7d2 100755 --- a/shell/Shell.py +++ b/shell/Shell.py @@ -48,6 +48,10 @@ class Shell(gobject.GObject): def __init__(self): gobject.GObject.__init__(self) + self._screen = wnck.screen_get_default() + self._hosts = {} + self._current_window = None + self._key_grabber = KeyGrabber() self._key_grabber.connect('key-pressed', self.__global_key_pressed_cb) self._key_grabber.grab('F1') @@ -56,9 +60,6 @@ class Shell(gobject.GObject): self._key_grabber.grab('F4') self._key_grabber.grab('F5') - self._screen = wnck.screen_get_default() - self._hosts = {} - self._home_window = HomeWindow(self) self._home_window.show() @@ -133,7 +134,9 @@ class Shell(gobject.GObject): def __active_window_changed_cb(self, screen): window = screen.get_active_window() if window and window.get_window_type() == wnck.WINDOW_NORMAL: - self.emit('activity-changed', self.get_current_activity()) + if self._current_window != window: + self._current_window = window + self.emit('activity-changed', self.get_current_activity()) def __window_closed_cb(self, screen, window): if window.get_window_type() == wnck.WINDOW_NORMAL: @@ -151,21 +154,11 @@ class Shell(gobject.GObject): return None def get_current_activity(self): - window = self._screen.get_active_window() - if window: - xid = None - - if window.get_window_type() == wnck.WINDOW_NORMAL: - xid = window.get_xid() - elif window.get_window_type() == wnck.WINDOW_DIALOG: - parent = window.get_transient() - if not parent is None: - xid = parent.get_xid() - - if xid != None: - return self._hosts[xid] - - return None + if self._current_window != None: + xid = self._current_window.get_xid() + return self._hosts[xid] + else: + return None def show_console(self): self._console.show() diff --git a/shell/panel/FriendsPanel.py b/shell/panel/FriendsPanel.py index c4b29d11..e4191b74 100644 --- a/shell/panel/FriendsPanel.py +++ b/shell/panel/FriendsPanel.py @@ -10,8 +10,15 @@ class FriendsGroup(goocanvas.Group): def __init__(self, shell, width): goocanvas.Group.__init__(self) - self._pservice = PresenceService.get_instance() + self._shell = shell self._width = width + self._activity_ps = None + self._joined_hid = -1 + self._left_hid = -1 + + self._pservice = PresenceService.get_instance() + self._pservice.connect('activity-appeared', + self.__activity_appeared_cb) self._buddies = [] i = 0 @@ -26,7 +33,7 @@ class FriendsGroup(goocanvas.Group): i = 0 while i < FriendsGroup.N_BUDDIES: if self._buddies[i] == None: - self._add_buddy(i) + self._add_buddy(buddy, i) break i += 1 @@ -34,14 +41,15 @@ class FriendsGroup(goocanvas.Group): i = 0 while i < FriendsGroup.N_BUDDIES: if self._buddies[i] == buddy.get_name(): - self._remove_buddy(i) + self._remove_buddy(buddy, i) break i += 1 def clear(self): i = 0 while i < FriendsGroup.N_BUDDIES: - self._remove_buddy(i) + if self._buddies[i] != None: + self._remove_buddy(i) i += 1 def _get_y(self, i): @@ -49,12 +57,12 @@ class FriendsGroup(goocanvas.Group): def _add_buddy(self, buddy, i): self.remove_child(i) - icon = IconItem(icon_name='stock-buddy', y=self._get_y(i), - color=buddy.get_color(), size=self._width) + icon = IconItem(icon_name='stock-buddy', + color=IconColor(buddy.get_color()), + size=self._width, y=self._get_y(i)) self.add_child(icon, i) self._buddies[i] = buddy.get_name() - def _create_placeholder(self, i): icon = IconItem(icon_name='stock-buddy', color=IconColor('white'), y=self._get_y(i), size=self._width) @@ -65,14 +73,38 @@ class FriendsGroup(goocanvas.Group): self.add_child(self._create_placeholder(i), i) self._buddies[i] = None - def __activity_changed_cb(self, group, activity): + def __activity_appeared_cb(self, pservice, activity_ps): + activity = self._shell.get_current_activity() + if activity_ps.get_id() == activity.get_id(): + self._set_activity_ps(activity_ps) + + def _set_activity_ps(self, activity_ps): + if self._activity_ps == activity_ps: + return + + self._activity_ps = activity_ps + self.clear() - activity_ps = self._pservice.get_activity(activity.get_id()) - if activity_ps: + + if self._joined_hid > 0: + self.disconnect(self._joined_hid) + self._joined_hid = -1 + if self._left_hid > 0: + self.disconnect(self._left_hid) + self._left_hid = -1 + + if activity_ps != None: for buddy in activity_ps.get_joined_buddies(): self.add(buddy) - activity_ps.connect('buddy-joined', self.__buddy_joined_cb) - activity_ps.connect('buddy-left', self.__buddy_left_cb) + + self._joined_hid = activity_ps.connect( + 'buddy-joined', self.__buddy_joined_cb) + self._left_hid = activity_ps.connect( + 'buddy-left', self.__buddy_left_cb) + + def __activity_changed_cb(self, group, activity): + activity_ps = self._pservice.get_activity(activity.get_id()) + self._set_activity_ps(activity_ps) def __buddy_joined_cb(self, activity, buddy): self.add(buddy)