Get activities sharing sort of working

master
Marco Pesenti Gritti 18 years ago
parent 20afcfa475
commit bdce0eb48c

@ -29,7 +29,7 @@ class BrowserActivity(activity.Activity):
self._pservice.track_service_type(_BROWSER_ACTIVITY_TYPE)
self._share_service = None
self._model = None
def _update_shared_location(self):
address = self.embed.get_address()
self._model.set_value('address', address)
@ -93,13 +93,10 @@ class BrowserActivity(activity.Activity):
self._setup_shared(self.uri)
def publish(self):
print 'Publish %s' % self.get_id()
def get_embed(self):
return self.embed
def share(self):
def publish(self):
escaped_title = urllib.quote(self.embed.get_title())
escaped_url = urllib.quote(self.embed.get_address())

@ -34,3 +34,9 @@ class BrowserShell(dbus.service.Object):
browser = BrowserActivity(uri)
self.__browsers.append(browser)
browser.connect_to_shell()
@dbus.service.method('com.redhat.Sugar.BrowserShell')
def open_browser_with_id(self, uri, activity_id):
browser = BrowserActivity(uri)
self.__browsers.append(browser)
browser.connect_to_shell(activity_id)

@ -30,17 +30,6 @@ class NavigationToolbar(gtk.Toolbar):
self.insert(self.reload, -1)
self.reload.show()
separator = gtk.SeparatorToolItem()
self.insert(separator, -1)
separator.show()
share = gtk.ToolButton(None, "Share")
share.set_icon_name('stock_shared-by-me')
share.set_is_important(True)
share.connect("clicked", self.__share_cb)
self.insert(share, -1)
share.show()
separator = gtk.SeparatorToolItem()
self.insert(separator, -1)
separator.show()
@ -66,9 +55,6 @@ class NavigationToolbar(gtk.Toolbar):
def __reload_cb(self, button):
self._embed.reload()
def __share_cb(self, button):
self._browser.share()
def __location_changed(self, embed):
self._update_sensitivity()

@ -4,6 +4,7 @@ import gtk
import pango
import dbus
import cgi
import urllib
import google
from sugar.presence.PresenceService import PresenceService
@ -12,14 +13,21 @@ from sugar.browser import BrowserActivity
class ActivitiesModel(gtk.ListStore):
def __init__(self):
gtk.ListStore.__init__(self, str, str)
gtk.ListStore.__init__(self, str, str, str, str)
def add_web_page(self, title, address):
self.append([ title, address ])
self.append([ title, address, None, None ])
def add_activity(self, buddy, service):
(uid, stype) = service.get_activity_uid()
title = service.get_one_property('Title')
address = urllib.unquote(service.get_one_property('URI'))
subtitle = 'Shared by %s' % buddy.get_nick_name()
self.append([ title, address, subtitle, uid ])
class ActivitiesView(gtk.TreeView):
def __init__(self):
gtk.TreeView.__init__(self)
gtk.TreeView.__init__(self, model = ActivitiesModel())
self.set_headers_visible(False)
@ -34,23 +42,32 @@ class ActivitiesView(gtk.TreeView):
def _cell_data_func(self, column, cell, model, it):
title = model.get_value(it, 0)
address = model.get_value(it, 1)
markup = '<big><b>' + title + '</b></big>' + '\n' + address
subtitle = model.get_value(it, 2)
if subtitle is None:
subtitle = model.get_value(it, 1)
markup = '<big><b>' + title + '</b></big>' + '\n' + subtitle
markup = cgi.escape(markup) # escape the markup
cell.set_property('markup', markup)
cell.set_property('ellipsize', pango.ELLIPSIZE_END)
def _row_activated_cb(self, treeview, path, column):
def _row_activated_cb(self, treeview, path, column):
bus = dbus.SessionBus()
proxy_obj = bus.get_object('com.redhat.Sugar.Browser', '/com/redhat/Sugar/Browser')
browser_shell = dbus.Interface(proxy_obj, 'com.redhat.Sugar.BrowserShell')
model = self.get_model()
address = model.get_value(model.get_iter(path), 1)
browser_shell.open_browser(address, ignore_reply=True)
activity_id = model.get_value(model.get_iter(path), 3)
print 'Activated row %s %s' % (address, activity_id)
if activity_id is None:
browser_shell.open_browser(address, ignore_reply=True)
else:
browser_shell.open_browser_with_id(address, activity_id, ignore_reply=True)
class StartPage(gtk.HBox):
def __init__(self):
gtk.HBox.__init__(self)
@ -104,8 +121,7 @@ class StartPage(gtk.HBox):
self._pservice.track_service_type(real_stype)
def _on_activity_announced_cb(self, pservice, service, buddy):
(activity_uid, activity_stype) = service.get_activity_uid()
print "::: %s announced activity UID %s of type %s" % (buddy.get_nick_name(), activity_uid, activity_stype)
self._activities.get_model().add_activity(buddy, service)
def _search_entry_activate_cb(self, entry):
self._search()

@ -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):
def connect_to_shell(self, activity_id = 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,7 +76,12 @@ class ActivityDbusService(dbus.service.Object):
self._activity_container = dbus.Interface(self._activity_container_object, \
SHELL_SERVICE_NAME + ".ActivityContainer")
self._activity_id = self._activity_container.add_activity("")
if activity_id is None:
self._activity_id = self._activity_container.add_activity("")
else:
self._activity_id = activity_id
self._activity_container.add_activity_with_id("", activity_id)
self._object_path = SHELL_SERVICE_PATH + "/Activities/%s" % self._activity_id
print "ActivityDbusService: object path is '%s'" % self._object_path
@ -172,10 +177,10 @@ class Activity(object):
"""Return whether or not this Activity is visible to the user."""
return self._has_focus
def connect_to_shell(self):
def connect_to_shell(self, activity_id = None):
"""Called by our controller to tell us to initialize and connect
to the shell."""
self._dbus_service.connect_to_shell()
self._dbus_service.connect_to_shell(activity_id)
def _internal_on_connected_to_shell_cb(self, activity_object, activity_id):
"""Callback when the dbus service object has connected to the shell."""

@ -16,13 +16,16 @@ from sugar.chat.GroupChat import GroupChat
class ActivityHost(dbus.service.Object):
def __init__(self, activity_container, activity_name):
def __init__(self, activity_container, activity_name, activity_id = None):
self.activity_name = activity_name
self.ellipsize_tab = False
self.activity_container = activity_container
self.activity_id = sugar.util.unique_id()
if activity_id is None:
self.activity_id = sugar.util.unique_id()
else:
self.activity_id = activity_id
self.dbus_object_name = "/com/redhat/Sugar/Shell/Activities/%s" % self.activity_id
@ -305,6 +308,15 @@ class ActivityContainer(dbus.service.Object):
#self.__print_activities()
return activity.get_host_activity_id()
@dbus.service.method("com.redhat.Sugar.Shell.ActivityContainer", \
in_signature="ss", \
out_signature="s", \
sender_keyword="sender")
def add_activity_with_id(self, activity_name, activity_id, sender):
activity = ActivityHost(self, activity_name, activity_id)
self.activities.append((sender, activity))
self.current_activity = activity
def __print_activities(self):
print "__print_activities: %d activities registered" % len(self.activities)
i = 0

Loading…
Cancel
Save