Fix activity double-join bug where opening a shared activity twice opened a blank tab
This commit is contained in:
parent
679d92dac8
commit
8270a84e09
@ -8,6 +8,7 @@ import xml.sax.saxutils
|
|||||||
import gobject
|
import gobject
|
||||||
import socket
|
import socket
|
||||||
|
|
||||||
|
import dbus_bindings
|
||||||
from google import google
|
from google import google
|
||||||
from sugar.presence.PresenceService import PresenceService
|
from sugar.presence.PresenceService import PresenceService
|
||||||
|
|
||||||
@ -101,11 +102,12 @@ class ActivitiesModel(gtk.ListStore):
|
|||||||
self.append([ title, address, subtitle, service ])
|
self.append([ title, address, subtitle, service ])
|
||||||
|
|
||||||
class ActivitiesView(gtk.TreeView):
|
class ActivitiesView(gtk.TreeView):
|
||||||
def __init__(self, model):
|
def __init__(self, activity_controller, model):
|
||||||
gtk.TreeView.__init__(self, model)
|
gtk.TreeView.__init__(self, model)
|
||||||
|
|
||||||
self._owner = None
|
self._owner = None
|
||||||
|
self._activity_controller = activity_controller
|
||||||
|
|
||||||
self.set_headers_visible(False)
|
self.set_headers_visible(False)
|
||||||
|
|
||||||
theme = gtk.icon_theme_get_default()
|
theme = gtk.icon_theme_get_default()
|
||||||
@ -160,14 +162,26 @@ class ActivitiesView(gtk.TreeView):
|
|||||||
|
|
||||||
if service is None:
|
if service is None:
|
||||||
browser_shell.open_browser(address)
|
browser_shell.open_browser(address)
|
||||||
else:
|
return
|
||||||
if not self._owner:
|
|
||||||
raise RuntimeError("We don't have an owner yet!")
|
if not self._owner:
|
||||||
serialized_service = service.serialize(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)
|
browser_shell.open_browser(address, serialized_service)
|
||||||
|
except dbus_bindings.DBusException, exc:
|
||||||
|
pass
|
||||||
|
|
||||||
class StartPage(gtk.HBox):
|
class StartPage(gtk.HBox):
|
||||||
def __init__(self, ac_signal_object):
|
def __init__(self, activity_controller, ac_signal_object):
|
||||||
gtk.HBox.__init__(self)
|
gtk.HBox.__init__(self)
|
||||||
|
|
||||||
self._ac_signal_object = ac_signal_object
|
self._ac_signal_object = ac_signal_object
|
||||||
@ -245,7 +259,7 @@ class StartPage(gtk.HBox):
|
|||||||
self._activities_model = ActivitiesModel()
|
self._activities_model = ActivitiesModel()
|
||||||
|
|
||||||
owner = self._pservice.get_owner()
|
owner = self._pservice.get_owner()
|
||||||
self._activities = ActivitiesView(self._activities_model)
|
self._activities = ActivitiesView(activity_controller, self._activities_model)
|
||||||
sw.add(self._activities)
|
sw.add(self._activities)
|
||||||
self._activities.show()
|
self._activities.show()
|
||||||
|
|
||||||
|
@ -106,7 +106,8 @@ class ActivityHost(dbus.service.Object):
|
|||||||
self.peer_service.got_focus()
|
self.peer_service.got_focus()
|
||||||
|
|
||||||
def lost_focus(self):
|
def lost_focus(self):
|
||||||
self.peer_service.lost_focus()
|
if self.peer_service != None:
|
||||||
|
self.peer_service.lost_focus()
|
||||||
|
|
||||||
def get_chat(self):
|
def get_chat(self):
|
||||||
return self._activity_chat
|
return self._activity_chat
|
||||||
@ -211,7 +212,7 @@ class ActivityHost(dbus.service.Object):
|
|||||||
in_signature="ayibiiii", \
|
in_signature="ayibiiii", \
|
||||||
out_signature="")
|
out_signature="")
|
||||||
def set_tab_icon(self, data, colorspace, has_alpha, bits_per_sample, width, height, rowstride):
|
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
|
#print " data = ", data
|
||||||
pixstr = ""
|
pixstr = ""
|
||||||
for c in data:
|
for c in data:
|
||||||
@ -329,7 +330,7 @@ class ActivityContainer(dbus.service.Object):
|
|||||||
self.notebook.set_scrollable(True)
|
self.notebook.set_scrollable(True)
|
||||||
|
|
||||||
tab_label = gtk.Label("Everyone")
|
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.notebook.append_page(self._start_page, tab_label)
|
||||||
self._start_page.show()
|
self._start_page.show()
|
||||||
|
|
||||||
@ -376,6 +377,9 @@ class ActivityContainer(dbus.service.Object):
|
|||||||
self.window.show()
|
self.window.show()
|
||||||
|
|
||||||
def set_current_activity(self, activity):
|
def set_current_activity(self, activity):
|
||||||
|
if self.current_activity != None:
|
||||||
|
self.current_activity.lost_focus()
|
||||||
|
|
||||||
self.current_activity = activity
|
self.current_activity = activity
|
||||||
self._presence_window.set_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
|
# For some reason the substitution screw up window position
|
||||||
self._chat_wm.update()
|
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:
|
if self.current_activity != None:
|
||||||
self.current_activity.got_focus()
|
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):
|
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)
|
#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[:]:
|
for owner, activity in self.activities[:]:
|
||||||
@ -408,6 +431,12 @@ class ActivityContainer(dbus.service.Object):
|
|||||||
self.activities.remove((owner, activity))
|
self.activities.remove((owner, activity))
|
||||||
#self.__print_activities()
|
#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", \
|
@dbus.service.method("com.redhat.Sugar.Shell.ActivityContainer", \
|
||||||
in_signature="ss", \
|
in_signature="ss", \
|
||||||
|
Loading…
Reference in New Issue
Block a user