From 9db404afb927f5a9b7752e8d5509e13e4330d6a5 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 16 Jun 2006 15:13:39 -0400 Subject: [PATCH 1/2] Filter presence by activity --- sugar/browser/BrowserActivity.py | 3 +++ sugar/shell/PresenceWindow.py | 27 ++++++++++++++++++++++----- sugar/shell/shell.py | 25 ++++++++++++++----------- 3 files changed, 39 insertions(+), 16 deletions(-) diff --git a/sugar/browser/BrowserActivity.py b/sugar/browser/BrowserActivity.py index 01019738..bc8ce27c 100644 --- a/sugar/browser/BrowserActivity.py +++ b/sugar/browser/BrowserActivity.py @@ -31,6 +31,9 @@ class BrowserActivity(activity.Activity): self._share_service = None self._model = None + def get_default_type(self): + return _BROWSER_ACTIVITY_TYPE + def _update_shared_location(self): address = self.embed.get_address() self._model.set_value('address', address) diff --git a/sugar/shell/PresenceWindow.py b/sugar/shell/PresenceWindow.py index 35f06a3e..c6acd4e1 100644 --- a/sugar/shell/PresenceWindow.py +++ b/sugar/shell/PresenceWindow.py @@ -9,7 +9,8 @@ class PresenceWindow(gtk.Window): _MODEL_COL_NICK = 0 _MODEL_COL_ICON = 1 _MODEL_COL_BUDDY = 2 - + _MODEL_COL_VISIBLE = 3 + def __init__(self, activity_container): gtk.Window.__init__(self, gtk.WINDOW_POPUP) @@ -23,6 +24,18 @@ class PresenceWindow(gtk.Window): self._setup_ui() + def _is_buddy_visible(self, buddy): + activity_type = self._activity.get_default_type() + buddy.get_service_of_type(activity, activity_type) + + def _update_buddies_visibility(self): + for row in self._buddy_store: + row[_MODEL_COL_VISIBLE] = self._is_buddy_visible(row[_MODEL_COL_BUDDY]) + + def set_activity(self, activity): + self._activity = activity + self._update_buddies_visibility() + def _setup_ui(self): vbox = gtk.VBox(False, 6) vbox.set_border_width(12) @@ -32,9 +45,12 @@ class PresenceWindow(gtk.Window): vbox.pack_start(label, False) label.show() - self._buddy_list_model = gtk.ListStore(gobject.TYPE_STRING, - gtk.gdk.Pixbuf, - gobject.TYPE_PYOBJECT) + self._buddy_store = gtk.ListStore(gobject.TYPE_STRING, + gtk.gdk.Pixbuf, + gobject.TYPE_PYOBJECT, + bool) + self._buddy_list_model = self._buddy_store.filter_new() + self._buddy_list_model.set_visible_column(self._MODEL_COL_VISIBLE) sw = gtk.ScrolledWindow() sw.set_shadow_type(gtk.SHADOW_IN) @@ -107,7 +123,8 @@ class PresenceWindow(gtk.Window): aniter = self._buddy_list_model.append(None) self._buddy_list_model.set(aniter, self._MODEL_COL_NICK, buddy.get_nick_name(), - self._MODEL_COL_BUDDY, buddy) + self._MODEL_COL_BUDDY, buddy, + self._MODEL_COL_VISIBLE, self._is_buddy_visible(buddy)) buddy.connect('icon-changed', self.__buddy_icon_changed_cb) def _on_buddy_disappeared_cb(self, pservice, buddy): diff --git a/sugar/shell/shell.py b/sugar/shell/shell.py index 21b433e1..b20744aa 100755 --- a/sugar/shell/shell.py +++ b/sugar/shell/shell.py @@ -250,6 +250,16 @@ class ActivityContainer(dbus.service.Object): # Create our owner service self._owner = ShellOwner() + self._presence_window = PresenceWindow(self) + self._presence_window.set_transient_for(self.window) + + wm = WindowManager(self._presence_window) + + wm.set_width(0.15, WindowManager.SCREEN_RELATIVE) + wm.set_height(1.0, WindowManager.SCREEN_RELATIVE) + wm.set_position(WindowManager.LEFT) + wm.manage() + def show(self): self.window.show() @@ -259,6 +269,9 @@ class ActivityContainer(dbus.service.Object): def __focus_error_cb(self, error): pass + def set_current_activity(self, activity): + self.current_activity = activity + self._presence_window.set_activity(activity) def notebook_tab_changed(self, notebook, page, page_number): #print "in notebook_tab_changed" @@ -272,7 +285,7 @@ class ActivityContainer(dbus.service.Object): self.current_activity.peer_service.lost_focus(reply_handler = self.__focus_reply_cb, error_handler = self.__focus_error_cb) if self.has_activity(new_activity): - self.current_activity = new_activity + self.set_current_activity(new_activity) if self.current_activity != None: if self.has_activity(self.current_activity): @@ -405,16 +418,6 @@ def main(): wm.show() wm.manage() - presence_window = PresenceWindow(activity_container) - presence_window.set_transient_for(activity_container.window) - - wm = WindowManager(presence_window) - - wm.set_width(0.15, WindowManager.SCREEN_RELATIVE) - wm.set_height(1.0, WindowManager.SCREEN_RELATIVE) - wm.set_position(WindowManager.LEFT) - wm.manage() - group_chat = GroupChat() group_chat.set_transient_for(activity_container.window) group_chat.set_decorated(False) From 29a730e0a47b952855b7bd7f84073461729578a1 Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Fri, 16 Jun 2006 15:21:09 -0400 Subject: [PATCH 2/2] Monitor service addition and update buddy list on these. --- sugar/presence/Buddy.py | 1 - sugar/shell/PresenceWindow.py | 8 ++++++++ 2 files changed, 8 insertions(+), 1 deletion(-) diff --git a/sugar/presence/Buddy.py b/sugar/presence/Buddy.py index 9b5e3584..f132c055 100644 --- a/sugar/presence/Buddy.py +++ b/sugar/presence/Buddy.py @@ -9,7 +9,6 @@ from sugar.p2p import network PRESENCE_SERVICE_TYPE = "_presence_olpc._tcp" - class Buddy(gobject.GObject): """Represents another person on the network and keeps track of the activities and resources they make available for sharing.""" diff --git a/sugar/shell/PresenceWindow.py b/sugar/shell/PresenceWindow.py index c6acd4e1..b0ed11ae 100644 --- a/sugar/shell/PresenceWindow.py +++ b/sugar/shell/PresenceWindow.py @@ -126,7 +126,15 @@ class PresenceWindow(gtk.Window): self._MODEL_COL_BUDDY, buddy, self._MODEL_COL_VISIBLE, self._is_buddy_visible(buddy)) buddy.connect('icon-changed', self.__buddy_icon_changed_cb) + buddy.connect('service-added', self.__buddy_service_added_cb) + buddy.connect('service-removed', self.__buddy_service_removed_cb) + def __buddy_service_added_cb(self, buddy, service): + self._update_buddies_visibility() + + def __buddy_service_remove_cb(self, buddy, service): + self._update_buddies_visibility() + def _on_buddy_disappeared_cb(self, pservice, buddy): aniter = self._get_iter_for_buddy(buddy) if aniter: