Pass a serialized Service object through when joining an activity

This commit is contained in:
Dan Williams 2006-06-18 01:31:55 -04:00
parent 9f1c77a55a
commit 4e6cbab48e
4 changed files with 43 additions and 31 deletions

View File

@ -111,9 +111,10 @@ class BrowserActivity(activity.Activity):
vbox.show()
# FIXME remove, when we join the activity this will happen automatically
self._pservice.track_activity(self.get_id())
# Join the shared activity if we were started from one
if self._initial_service:
self._pservice.join_shared_activity(self._initial_service)
def get_embed(self):
return self.embed

View File

@ -8,6 +8,7 @@ import gobject
import sugar.env
from sugar.browser.BrowserActivity import BrowserActivity
from sugar.presence import Service
class BrowserShell(dbus.service.Object):
def __init__(self, bus_name, object_path = '/com/redhat/Sugar/Browser'):
@ -30,20 +31,21 @@ class BrowserShell(dbus.service.Object):
links.append(link)
return links
def _start_browser_cb(self, browser, activity_id):
if activity_id:
browser.connect_to_shell(activity_id)
else:
browser.connect_to_shell()
def _start_browser_cb(self, browser, service):
browser.connect_to_shell(service)
@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)
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')
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)
self.__browsers.append(browser)
gobject.idle_add(self._start_browser_cb, browser, activity_id)
gobject.idle_add(self._start_browser_cb, browser, service)

View File

@ -6,21 +6,27 @@ import dbus
import cgi
import xml.sax.saxutils
import re
import gobject
import google
from sugar.presence.PresenceService import PresenceService
from sugar.presence import Service
from sugar.browser import BrowserActivity
_COLUMN_TITLE = 0
_COLUMN_ADDRESS = 1
_COLUMN_SUBTITLE = 2
_COLUMN_SERVICE = 3
class ActivitiesModel(gtk.ListStore):
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):
self.append([ title, address, None, None ])
def add_activity(self, buddy, service):
uid = service.get_activity_uid()
# Web Activity check
if service.get_type() == BrowserActivity._BROWSER_ACTIVITY_TYPE:
escaped_title = service.get_one_property('Title')
@ -29,7 +35,7 @@ class ActivitiesModel(gtk.ListStore):
title = xml.sax.saxutils.unescape(escaped_title)
address = xml.sax.saxutils.unescape(escaped_uri)
subtitle = 'Shared by %s' % buddy.get_nick_name()
self.append([ title, address, subtitle, uid ])
self.append([ title, address, subtitle, service ])
class ActivitiesView(gtk.TreeView):
def __init__(self):
@ -47,11 +53,11 @@ class ActivitiesView(gtk.TreeView):
self.connect('row-activated', self._row_activated_cb)
def _cell_data_func(self, column, cell, model, it):
title = model.get_value(it, 0)
subtitle = model.get_value(it, 2)
title = model.get_value(it, _COLUMN_TITLE)
subtitle = model.get_value(it, _COLUMN_SUBTITLE)
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 += '\n' + cgi.escape(subtitle)
@ -64,15 +70,16 @@ class ActivitiesView(gtk.TreeView):
browser_shell = dbus.Interface(proxy_obj, 'com.redhat.Sugar.BrowserShell')
model = self.get_model()
address = model.get_value(model.get_iter(path), 1)
activity_id = model.get_value(model.get_iter(path), 3)
address = model.get_value(model.get_iter(path), _COLUMN_ADDRESS)
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)
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):
def __init__(self, ac_signal_object):

View File

@ -68,7 +68,7 @@ class ActivityDbusService(dbus.service.Object):
if name in self._ALLOWED_CALLBACKS and self._callbacks[name]:
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
and XEMBED window ID in which to display the Activity."""
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, \
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())
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._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._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):
"""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._has_focus = False
self._plug = None
self._initial_service = None
self._activity_object = None
if type(default_type) != type("") or not len(default_type):
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 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
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."""
self._activity_object = activity_object
self._activity_id = activity_id
self._window_id = self._activity_object.get_host_xembed_id()
print "Activity: XEMBED window ID is %s" % self._window_id
self._plug = gtk.Plug(self._window_id)
self._initial_service = service
self.on_connected_to_shell()
def _internal_on_disconnected_from_shell_cb(self):