From 8270a84e0955dffabdcd733a572cb2552e58d00a Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Fri, 7 Jul 2006 11:00:20 -0400 Subject: [PATCH] Fix activity double-join bug where opening a shared activity twice opened a blank tab --- shell/StartPage.py | 30 +++++++++++++++++++-------- shell/shell.py | 51 ++++++++++++++++++++++++++++++++++++---------- 2 files changed, 62 insertions(+), 19 deletions(-) diff --git a/shell/StartPage.py b/shell/StartPage.py index a43d8e1b..d2f7e447 100644 --- a/shell/StartPage.py +++ b/shell/StartPage.py @@ -8,6 +8,7 @@ import xml.sax.saxutils import gobject import socket +import dbus_bindings from google import google from sugar.presence.PresenceService import PresenceService @@ -101,11 +102,12 @@ class ActivitiesModel(gtk.ListStore): self.append([ title, address, subtitle, service ]) class ActivitiesView(gtk.TreeView): - def __init__(self, model): + def __init__(self, activity_controller, model): gtk.TreeView.__init__(self, model) self._owner = None - + self._activity_controller = activity_controller + self.set_headers_visible(False) theme = gtk.icon_theme_get_default() @@ -160,14 +162,26 @@ class ActivitiesView(gtk.TreeView): if service is None: browser_shell.open_browser(address) - else: - if not self._owner: - raise RuntimeError("We don't have an owner yet!") - serialized_service = service.serialize(self._owner) + return + + if not self._owner: + raise RuntimeError("We don't have an owner yet!") + + # If the activity is already started, switch to it + service_act_id = service.get_activity_id() + if service_act_id and self._activity_controller.have_activity(service_act_id): + self._activity_controller.switch_to_activity(service_act_id) + return + + # Start a new activity + serialized_service = service.serialize(self._owner) + try: browser_shell.open_browser(address, serialized_service) + except dbus_bindings.DBusException, exc: + pass class StartPage(gtk.HBox): - def __init__(self, ac_signal_object): + def __init__(self, activity_controller, ac_signal_object): gtk.HBox.__init__(self) self._ac_signal_object = ac_signal_object @@ -245,7 +259,7 @@ class StartPage(gtk.HBox): self._activities_model = ActivitiesModel() owner = self._pservice.get_owner() - self._activities = ActivitiesView(self._activities_model) + self._activities = ActivitiesView(activity_controller, self._activities_model) sw.add(self._activities) self._activities.show() diff --git a/shell/shell.py b/shell/shell.py index c293d5f2..a3f07c8f 100755 --- a/shell/shell.py +++ b/shell/shell.py @@ -106,7 +106,8 @@ class ActivityHost(dbus.service.Object): self.peer_service.got_focus() def lost_focus(self): - self.peer_service.lost_focus() + if self.peer_service != None: + self.peer_service.lost_focus() def get_chat(self): return self._activity_chat @@ -211,7 +212,7 @@ class ActivityHost(dbus.service.Object): in_signature="ayibiiii", \ out_signature="") def set_tab_icon(self, data, colorspace, has_alpha, bits_per_sample, width, height, rowstride): - #print "width=%d, height=%d"%(width, height) + #print "width=%d, height=%d"%(width, height) #print " data = ", data pixstr = "" for c in data: @@ -329,7 +330,7 @@ class ActivityContainer(dbus.service.Object): self.notebook.set_scrollable(True) tab_label = gtk.Label("Everyone") - self._start_page = StartPage(self._signal_helper) + self._start_page = StartPage(self, self._signal_helper) self.notebook.append_page(self._start_page, tab_label) self._start_page.show() @@ -376,6 +377,9 @@ class ActivityContainer(dbus.service.Object): self.window.show() def set_current_activity(self, activity): + if self.current_activity != None: + self.current_activity.lost_focus() + self.current_activity = activity self._presence_window.set_activity(activity) @@ -388,17 +392,36 @@ class ActivityContainer(dbus.service.Object): # For some reason the substitution screw up window position self._chat_wm.update() - def notebook_tab_changed(self, notebook, page, page_number): - new_activity = notebook.get_nth_page(page_number).get_data("sugar-activity") - - if self.current_activity != None: - self.current_activity.lost_focus() - - self.set_current_activity(new_activity) - if self.current_activity != None: self.current_activity.got_focus() + def notebook_tab_changed(self, notebook, page, page_number): + new_activity = notebook.get_nth_page(page_number).get_data("sugar-activity") + self.set_current_activity(new_activity) + + def switch_to_activity(self, activity_id): + found = False + for owner, activity in self.activities: + if activity.get_host_activity_id() == activity_id: + found = True + break + if not found: + return + + # Find the activity in the notebook + activity_page = None + npages = self.notebook.get_n_pages() + for pageno in range(1, npages): + activity = self.notebook.get_nth_page(pageno).get_data("sugar-activity") + if activity and activity.get_host_activity_id() == activity_id: + activity_page = pageno + break + if not activity_page: + return + + print "switching to activity page %d" % activity_page + self.notebook.set_current_page(activity_page) + def name_owner_changed(self, service_name, old_service_name, new_service_name): #print "in name_owner_changed: svc=%s oldsvc=%s newsvc=%s"%(service_name, old_service_name, new_service_name) for owner, activity in self.activities[:]: @@ -408,6 +431,12 @@ class ActivityContainer(dbus.service.Object): self.activities.remove((owner, activity)) #self.__print_activities() + def have_activity(self, activity_id): + for owner, activity in self.activities: + list_activity_id = activity.get_host_activity_id() + if activity_id == list_activity_id: + return True + return False @dbus.service.method("com.redhat.Sugar.Shell.ActivityContainer", \ in_signature="ss", \