Pass a serialized Service object through when joining an activity
This commit is contained in:
parent
9f1c77a55a
commit
4e6cbab48e
@ -111,9 +111,10 @@ class BrowserActivity(activity.Activity):
|
|||||||
|
|
||||||
vbox.show()
|
vbox.show()
|
||||||
|
|
||||||
# FIXME remove, when we join the activity this will happen automatically
|
# Join the shared activity if we were started from one
|
||||||
self._pservice.track_activity(self.get_id())
|
if self._initial_service:
|
||||||
|
self._pservice.join_shared_activity(self._initial_service)
|
||||||
|
|
||||||
def get_embed(self):
|
def get_embed(self):
|
||||||
return self.embed
|
return self.embed
|
||||||
|
|
||||||
|
@ -8,6 +8,7 @@ import gobject
|
|||||||
import sugar.env
|
import sugar.env
|
||||||
|
|
||||||
from sugar.browser.BrowserActivity import BrowserActivity
|
from sugar.browser.BrowserActivity import BrowserActivity
|
||||||
|
from sugar.presence import Service
|
||||||
|
|
||||||
class BrowserShell(dbus.service.Object):
|
class BrowserShell(dbus.service.Object):
|
||||||
def __init__(self, bus_name, object_path = '/com/redhat/Sugar/Browser'):
|
def __init__(self, bus_name, object_path = '/com/redhat/Sugar/Browser'):
|
||||||
@ -30,20 +31,21 @@ class BrowserShell(dbus.service.Object):
|
|||||||
links.append(link)
|
links.append(link)
|
||||||
return links
|
return links
|
||||||
|
|
||||||
def _start_browser_cb(self, browser, activity_id):
|
def _start_browser_cb(self, browser, service):
|
||||||
if activity_id:
|
browser.connect_to_shell(service)
|
||||||
browser.connect_to_shell(activity_id)
|
|
||||||
else:
|
|
||||||
browser.connect_to_shell()
|
|
||||||
|
|
||||||
@dbus.service.method('com.redhat.Sugar.BrowserShell')
|
@dbus.service.method('com.redhat.Sugar.BrowserShell')
|
||||||
def open_browser(self, uri):
|
def open_browser(self, uri, serialized_service=None):
|
||||||
|
service = None
|
||||||
|
if serialized_service is not None:
|
||||||
|
serivce = Service.deserialize(serialized_service)
|
||||||
browser = BrowserActivity(uri)
|
browser = BrowserActivity(uri)
|
||||||
self.__browsers.append(browser)
|
self.__browsers.append(browser)
|
||||||
gobject.idle_add(self._start_browser_cb, browser, None)
|
gobject.idle_add(self._start_browser_cb, browser, service)
|
||||||
|
|
||||||
@dbus.service.method('com.redhat.Sugar.BrowserShell')
|
@dbus.service.method('com.redhat.Sugar.BrowserShell')
|
||||||
def open_browser_with_id(self, uri, activity_id):
|
def open_browser_from_service_foobar(self, uri, serialized_service):
|
||||||
|
serivce = Service.deserialize(serialized_service)
|
||||||
browser = BrowserActivity(uri)
|
browser = BrowserActivity(uri)
|
||||||
self.__browsers.append(browser)
|
self.__browsers.append(browser)
|
||||||
gobject.idle_add(self._start_browser_cb, browser, activity_id)
|
gobject.idle_add(self._start_browser_cb, browser, service)
|
||||||
|
@ -6,21 +6,27 @@ import dbus
|
|||||||
import cgi
|
import cgi
|
||||||
import xml.sax.saxutils
|
import xml.sax.saxutils
|
||||||
import re
|
import re
|
||||||
|
import gobject
|
||||||
|
|
||||||
import google
|
import google
|
||||||
from sugar.presence.PresenceService import PresenceService
|
from sugar.presence.PresenceService import PresenceService
|
||||||
from sugar.presence import Service
|
from sugar.presence import Service
|
||||||
from sugar.browser import BrowserActivity
|
from sugar.browser import BrowserActivity
|
||||||
|
|
||||||
|
_COLUMN_TITLE = 0
|
||||||
|
_COLUMN_ADDRESS = 1
|
||||||
|
_COLUMN_SUBTITLE = 2
|
||||||
|
_COLUMN_SERVICE = 3
|
||||||
|
|
||||||
class ActivitiesModel(gtk.ListStore):
|
class ActivitiesModel(gtk.ListStore):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
gtk.ListStore.__init__(self, str, str, str, str)
|
gtk.ListStore.__init__(self, gobject.TYPE_STRING, gobject.TYPE_STRING,
|
||||||
|
gobject.TYPE_STRING, gobject.TYPE_PYOBJECT)
|
||||||
|
|
||||||
def add_web_page(self, title, address):
|
def add_web_page(self, title, address):
|
||||||
self.append([ title, address, None, None ])
|
self.append([ title, address, None, None ])
|
||||||
|
|
||||||
def add_activity(self, buddy, service):
|
def add_activity(self, buddy, service):
|
||||||
uid = service.get_activity_uid()
|
|
||||||
# Web Activity check
|
# Web Activity check
|
||||||
if service.get_type() == BrowserActivity._BROWSER_ACTIVITY_TYPE:
|
if service.get_type() == BrowserActivity._BROWSER_ACTIVITY_TYPE:
|
||||||
escaped_title = service.get_one_property('Title')
|
escaped_title = service.get_one_property('Title')
|
||||||
@ -29,7 +35,7 @@ class ActivitiesModel(gtk.ListStore):
|
|||||||
title = xml.sax.saxutils.unescape(escaped_title)
|
title = xml.sax.saxutils.unescape(escaped_title)
|
||||||
address = xml.sax.saxutils.unescape(escaped_uri)
|
address = xml.sax.saxutils.unescape(escaped_uri)
|
||||||
subtitle = 'Shared by %s' % buddy.get_nick_name()
|
subtitle = 'Shared by %s' % buddy.get_nick_name()
|
||||||
self.append([ title, address, subtitle, uid ])
|
self.append([ title, address, subtitle, service ])
|
||||||
|
|
||||||
class ActivitiesView(gtk.TreeView):
|
class ActivitiesView(gtk.TreeView):
|
||||||
def __init__(self):
|
def __init__(self):
|
||||||
@ -47,11 +53,11 @@ class ActivitiesView(gtk.TreeView):
|
|||||||
self.connect('row-activated', self._row_activated_cb)
|
self.connect('row-activated', self._row_activated_cb)
|
||||||
|
|
||||||
def _cell_data_func(self, column, cell, model, it):
|
def _cell_data_func(self, column, cell, model, it):
|
||||||
title = model.get_value(it, 0)
|
title = model.get_value(it, _COLUMN_TITLE)
|
||||||
subtitle = model.get_value(it, 2)
|
subtitle = model.get_value(it, _COLUMN_SUBTITLE)
|
||||||
if subtitle is None:
|
if subtitle is None:
|
||||||
subtitle = model.get_value(it, 1)
|
subtitle = model.get_value(it, _COLUMN_ADDRESS)
|
||||||
|
|
||||||
markup = '<big><b>' + cgi.escape(title) + '</b></big>'
|
markup = '<big><b>' + cgi.escape(title) + '</b></big>'
|
||||||
markup += '\n' + cgi.escape(subtitle)
|
markup += '\n' + cgi.escape(subtitle)
|
||||||
|
|
||||||
@ -64,15 +70,16 @@ class ActivitiesView(gtk.TreeView):
|
|||||||
browser_shell = dbus.Interface(proxy_obj, 'com.redhat.Sugar.BrowserShell')
|
browser_shell = dbus.Interface(proxy_obj, 'com.redhat.Sugar.BrowserShell')
|
||||||
|
|
||||||
model = self.get_model()
|
model = self.get_model()
|
||||||
address = model.get_value(model.get_iter(path), 1)
|
address = model.get_value(model.get_iter(path), _COLUMN_ADDRESS)
|
||||||
activity_id = model.get_value(model.get_iter(path), 3)
|
service = model.get_value(model.get_iter(path), _COLUMN_SERVICE)
|
||||||
|
|
||||||
print 'Activated row %s %s' % (address, activity_id)
|
print 'Activated row %s' % address
|
||||||
|
|
||||||
if activity_id is None:
|
if service is None:
|
||||||
browser_shell.open_browser(address)
|
browser_shell.open_browser(address)
|
||||||
else:
|
else:
|
||||||
browser_shell.open_browser_with_id(address, activity_id)
|
serialized_service = service.serialize()
|
||||||
|
browser_shell.open_browser(address, serialized_service)
|
||||||
|
|
||||||
class StartPage(gtk.HBox):
|
class StartPage(gtk.HBox):
|
||||||
def __init__(self, ac_signal_object):
|
def __init__(self, ac_signal_object):
|
||||||
|
@ -68,7 +68,7 @@ class ActivityDbusService(dbus.service.Object):
|
|||||||
if name in self._ALLOWED_CALLBACKS and self._callbacks[name]:
|
if name in self._ALLOWED_CALLBACKS and self._callbacks[name]:
|
||||||
gobject.idle_add(self._call_callback_cb, self._callbacks[name], *args)
|
gobject.idle_add(self._call_callback_cb, self._callbacks[name], *args)
|
||||||
|
|
||||||
def connect_to_shell(self, activity_id = None):
|
def connect_to_shell(self, service=None):
|
||||||
"""Register with the shell via dbus, getting an activity ID and
|
"""Register with the shell via dbus, getting an activity ID and
|
||||||
and XEMBED window ID in which to display the Activity."""
|
and XEMBED window ID in which to display the Activity."""
|
||||||
self._activity_container_object = self._bus.get_object(SHELL_SERVICE_NAME, \
|
self._activity_container_object = self._bus.get_object(SHELL_SERVICE_NAME, \
|
||||||
@ -76,10 +76,10 @@ class ActivityDbusService(dbus.service.Object):
|
|||||||
self._activity_container = dbus.Interface(self._activity_container_object, \
|
self._activity_container = dbus.Interface(self._activity_container_object, \
|
||||||
SHELL_SERVICE_NAME + ".ActivityContainer")
|
SHELL_SERVICE_NAME + ".ActivityContainer")
|
||||||
|
|
||||||
if activity_id is None:
|
if service is None:
|
||||||
self._activity_id = self._activity_container.add_activity("", self._activity.default_type())
|
self._activity_id = self._activity_container.add_activity("", self._activity.default_type())
|
||||||
else:
|
else:
|
||||||
self._activity_id = activity_id
|
self._activity_id = serivce.get_activity_uid()
|
||||||
self._activity_container.add_activity_with_id("", self._activity.default_type(), activity_id)
|
self._activity_container.add_activity_with_id("", self._activity.default_type(), activity_id)
|
||||||
|
|
||||||
self._object_path = SHELL_SERVICE_PATH + "/Activities/%s" % self._activity_id
|
self._object_path = SHELL_SERVICE_PATH + "/Activities/%s" % self._activity_id
|
||||||
@ -97,7 +97,7 @@ class ActivityDbusService(dbus.service.Object):
|
|||||||
|
|
||||||
self._activity_object.set_peer_service_name(self._peer_service_name, self._peer_object_path)
|
self._activity_object.set_peer_service_name(self._peer_service_name, self._peer_object_path)
|
||||||
|
|
||||||
self._call_callback(ON_CONNECTED_TO_SHELL_CB, self._activity_object, self._activity_id)
|
self._call_callback(ON_CONNECTED_TO_SHELL_CB, self._activity_object, self._activity_id, service)
|
||||||
|
|
||||||
def _shutdown_reply_cb(self):
|
def _shutdown_reply_cb(self):
|
||||||
"""Shutdown was successful, tell the Activity that we're disconnected."""
|
"""Shutdown was successful, tell the Activity that we're disconnected."""
|
||||||
@ -155,6 +155,7 @@ class Activity(object):
|
|||||||
self._dbus_service.register_callback(ON_GOT_FOCUS_CB, self._internal_on_got_focus_cb)
|
self._dbus_service.register_callback(ON_GOT_FOCUS_CB, self._internal_on_got_focus_cb)
|
||||||
self._has_focus = False
|
self._has_focus = False
|
||||||
self._plug = None
|
self._plug = None
|
||||||
|
self._initial_service = None
|
||||||
self._activity_object = None
|
self._activity_object = None
|
||||||
if type(default_type) != type("") or not len(default_type):
|
if type(default_type) != type("") or not len(default_type):
|
||||||
raise ValueError("Default type must be a valid string.")
|
raise ValueError("Default type must be a valid string.")
|
||||||
@ -183,18 +184,19 @@ class Activity(object):
|
|||||||
"""Return whether or not this Activity is visible to the user."""
|
"""Return whether or not this Activity is visible to the user."""
|
||||||
return self._has_focus
|
return self._has_focus
|
||||||
|
|
||||||
def connect_to_shell(self, activity_id = None):
|
def connect_to_shell(self, service = None):
|
||||||
"""Called by our controller to tell us to initialize and connect
|
"""Called by our controller to tell us to initialize and connect
|
||||||
to the shell."""
|
to the shell."""
|
||||||
self._dbus_service.connect_to_shell(activity_id)
|
self._dbus_service.connect_to_shell(service)
|
||||||
|
|
||||||
def _internal_on_connected_to_shell_cb(self, activity_object, activity_id):
|
def _internal_on_connected_to_shell_cb(self, activity_object, activity_id, service=None):
|
||||||
"""Callback when the dbus service object has connected to the shell."""
|
"""Callback when the dbus service object has connected to the shell."""
|
||||||
self._activity_object = activity_object
|
self._activity_object = activity_object
|
||||||
self._activity_id = activity_id
|
self._activity_id = activity_id
|
||||||
self._window_id = self._activity_object.get_host_xembed_id()
|
self._window_id = self._activity_object.get_host_xembed_id()
|
||||||
print "Activity: XEMBED window ID is %s" % self._window_id
|
print "Activity: XEMBED window ID is %s" % self._window_id
|
||||||
self._plug = gtk.Plug(self._window_id)
|
self._plug = gtk.Plug(self._window_id)
|
||||||
|
self._initial_service = service
|
||||||
self.on_connected_to_shell()
|
self.on_connected_to_shell()
|
||||||
|
|
||||||
def _internal_on_disconnected_from_shell_cb(self):
|
def _internal_on_disconnected_from_shell_cb(self):
|
||||||
|
Loading…
Reference in New Issue
Block a user