diff --git a/shell/ActivityHost.py b/shell/ActivityHost.py new file mode 100644 index 00000000..c9d6dcb4 --- /dev/null +++ b/shell/ActivityHost.py @@ -0,0 +1,30 @@ +import gtk +import dbus + +from sugar.activity import Activity + +class ActivityHost: + def __init__(self, xid): + self._xid = xid + + bus = dbus.SessionBus() + service = Activity.ACTIVITY_SERVICE_NAME + "%s" % xid + path = Activity.ACTIVITY_SERVICE_PATH + "/%s" % xid + proxy_obj = bus.get_object(service, path) + + self._activity = dbus.Interface(proxy_obj, 'com.redhat.Sugar.Activity') + self._id = self._activity.get_id() + self._window = gtk.gdk.window_foreign_new(xid) + + def get_id(self): + return self._id + + def publish(self): + self._activity.publish() + + def get_shared(self): + return self._activity.get_shared() + + def show_dialog(self, dialog): + dialog.show() + dialog.window.set_transient_for(self._window) diff --git a/shell/PresenceView.py b/shell/PresenceView.py index 41205495..fafd5778 100644 --- a/shell/PresenceView.py +++ b/shell/PresenceView.py @@ -20,12 +20,9 @@ class PresenceView(gtk.VBox): self._activity = None self._shell = shell - self._pservice = PresenceService.get_instance() - self._pservice.connect("buddy-appeared", self._on_buddy_appeared_cb) - self._pservice.connect("buddy-disappeared", self._on_buddy_disappeared_cb) - self._pservice.start() - - self._pservice.track_service_type(BuddyChat.SERVICE_TYPE) + self._pservice = PresenceService() + self._pservice.connect("BuddyAppeared", self._on_buddy_appeared_cb) + self._pservice.connect("BuddyDisappeared", self._on_buddy_disappeared_cb) self._setup_ui() diff --git a/shell/Shell.py b/shell/Shell.py index 1e532ad8..89ac5493 100755 --- a/shell/Shell.py +++ b/shell/Shell.py @@ -11,10 +11,10 @@ from ActivityRegistry import ActivityRegistry from HomeWindow import HomeWindow from sugar import keybindings from sugar import env -from sugar.activity import Activity from PeopleWindow import PeopleWindow from Owner import ShellOwner from PresenceService import PresenceService +from ActivityHost import ActivityHost class ShellDbusService(dbus.service.Object): def __init__(self, shell, bus_name): @@ -66,40 +66,29 @@ class Shell: else: window.show() - def get_activity_from_xid(self, xid): - bus = dbus.SessionBus() - service = Activity.ACTIVITY_SERVICE_NAME + "%s" % xid - path = Activity.ACTIVITY_SERVICE_PATH + "/%s" % xid - proxy_obj = bus.get_object(service, path) + def get_current_activity(self): + window = self._screen.get_active_window() + if window and window.get_window_type() == wnck.WINDOW_NORMAL: + return ActivityHost(window.get_xid()) + else: + return None - return dbus.Interface(proxy_obj, 'com.redhat.Sugar.Activity') - - def get_activity_window(self): - return self._screen.get_active_window() - - def __people_window_delete_cb(self, window, event): + def __people_dialog_delete_cb(self, window, event): window.hide() return True def show_people(self): - activity_window = self.get_activity_window() - if activity_window: - xid = activity_window.get_xid() - activity = self.get_activity_from_xid(xid) - activity_id = activity.get_id() - - if not self._people_windows.has_key(activity_id): - window = PeopleWindow(self, activity) - window.connect('delete-event', self.__people_window_delete_cb) - keybindings.setup_global_keys(window, self) - self._people_windows[activity_id] = window + activity = self.get_current_activity() + if activity: + if not self._people_windows.has_key(activity.get_id()): + dialog = PeopleWindow(self, activity) + dialog.connect('delete-event', self.__people_dialog_delete_cb) + keybindings.setup_global_keys(dialog, self) + self._people_windows[activity.get_id()] = dialog else: - window = self._people_windows[activity_id] + dialog = self._people_windows[activity.get_id()] - window.show() - - foreign_activity_win = gtk.gdk.window_foreign_new(xid) - window.window.set_transient_for(foreign_activity_win) + activity.show_dialog(dialog) def toggle_console(self): self._toggle_window_visibility(self._console.get_window()) diff --git a/sugar/chat/ActivityChat.py b/sugar/chat/ActivityChat.py index 9edee835..ff5c057f 100644 --- a/sugar/chat/ActivityChat.py +++ b/sugar/chat/ActivityChat.py @@ -10,13 +10,13 @@ class ActivityChat(GroupChat): self._chat_service = None self._activity = activity - self._pservice.connect('service-appeared', self._service_appeared_cb) - self._pservice.track_service_type(ActivityChat.SERVICE_TYPE) + self._pservice.connect('ServiceAppeared', self._service_appeared_cb) # Find an existing activity chat to latch onto - service = self._pservice.get_activity_service(activity, ActivityChat.SERVICE_TYPE) - if service is not None: - self._service_appeared_cb(self._pservice, None, service) + #activity_ps = self._pservice.getActivity(activity.get_id()) + #service = activity.getServiceOfType(ActivityChat.SERVICE_TYPE) + #if service is not None: + # self._service_appeared_cb(self._pservice, None, service) def _service_appeared_cb(self, pservice, buddy, service): if service.get_activity_id() != self._activity.get_id(): diff --git a/sugar/chat/Chat.py b/sugar/chat/Chat.py index f510fde5..20c566e4 100644 --- a/sugar/chat/Chat.py +++ b/sugar/chat/Chat.py @@ -28,8 +28,7 @@ class Chat(gtk.VBox): def __init__(self): gtk.VBox.__init__(self, False, 6) - self._pservice = PresenceService.get_instance() - self._pservice.start() + self._pservice = PresenceService() self._stream_writer = None self.set_border_width(12)