diff --git a/activities/browser/BrowserActivity.py b/activities/browser/BrowserActivity.py index 86b61bc8..45923a92 100644 --- a/activities/browser/BrowserActivity.py +++ b/activities/browser/BrowserActivity.py @@ -77,7 +77,7 @@ class BrowserActivity(Activity): if service.get_activity_id() != self._activity_id: return - if service.get_type() == _BROWSER_ACTIVITY_TYPE: + if service.get_type() == self._default_type: self._notif_service = service elif service.get_type() == LocalModel.SERVICE_TYPE: if self._mode != BrowserActivity.LEADING: @@ -102,7 +102,6 @@ class BrowserActivity(Activity): self._update_shared_location() elif action_id == 'goto_shared_location': address = self._model.get_value("address") - print address self.embed.load_address(address) self._notif_bar.hide() diff --git a/shell/ActivitiesModel.py b/shell/ActivitiesModel.py index 6ed2eb4b..9b1a9559 100644 --- a/shell/ActivitiesModel.py +++ b/shell/ActivitiesModel.py @@ -1,3 +1,5 @@ +import xml.sax.saxutils + import gobject from sugar.presence.PresenceService import PresenceService @@ -7,11 +9,18 @@ class ActivityInfo: self._service = service def get_id(self): - activity_id = service.get_one_property('activity_id') + activity_id = self._service.get_one_property('activity_id') + + def get_type(self): + return self._service.get_type() def get_title(self): - escaped_title = service.get_one_property('Title') + escaped_title = self._service.get_one_property('Title') title = xml.sax.saxutils.unescape(escaped_title) + return title + + def get_service(self): + return self._service class ActivitiesModel(gobject.GObject): __gsignals__ = { @@ -44,4 +53,6 @@ class ActivitiesModel(gobject.GObject): self._pservice.track_service_type(short_stype) def _on_activity_announced_cb(self, pservice, service, buddy): - self.add_activity(buddy, service) + # FIXME We should not hard code activity types here + if service.get_type() == "_web_olpc._udp": + self.add_activity(service) diff --git a/shell/ActivityRegistry.py b/shell/ActivityRegistry.py index 6d296bbb..70a502f6 100644 --- a/shell/ActivityRegistry.py +++ b/shell/ActivityRegistry.py @@ -44,6 +44,13 @@ class ActivityRegistry: def __init__(self): self._activities = [] + def get_activity(self, default_type): + """Returns an activity given his default type""" + for activity in self._activities: + if activity.get_default_type() == default_type: + return activity + return None + def scan_directory(self, path): """Scan a directory for activities and add them to the registry.""" if os.path.isdir(path): diff --git a/shell/HomeWindow.py b/shell/HomeWindow.py index a88e18ff..8f2618a0 100644 --- a/shell/HomeWindow.py +++ b/shell/HomeWindow.py @@ -39,9 +39,10 @@ class Toolbar(gtk.Toolbar): new_activity_button.show() class ActivitiesGrid(gtk.VBox): - def __init__(self, model): - gtk.VBox.__init__(self) + def __init__(self, shell, model): + gtk.VBox.__init__(self, shell) + self._shell = shell self._buttons = {} for activity in model: @@ -60,15 +61,16 @@ class ActivitiesGrid(gtk.VBox): self.remove(button) def _add(self, activity): - button = gtk.Button(window.get_title()) - button.connect('clicked', self.__button_clicked_cb, window) + button = gtk.Button(activity.get_title()) + button.connect('clicked', self.__button_clicked_cb, activity) self.pack_start(button, False) button.show() self._buttons[activity.get_id()] = button - def __button_clicked_cb(self, button, window): - self._home.activate(window) + def __button_clicked_cb(self, button, info): + activity = self._shell.get_registry().get_activity(info.get_type()) + Activity.create(activity.get_id(), info.get_service()) class TasksGrid(gtk.VBox): def __init__(self, home): @@ -137,7 +139,7 @@ class HomeWindow(gtk.Window): label.show() model = ActivitiesModel() - grid = ActivitiesGrid(model) + grid = ActivitiesGrid(shell, model) vbox.pack_start(grid) grid.show() diff --git a/sugar/activity/Activity.py b/sugar/activity/Activity.py index 9adf0c6b..9cc6e8ff 100644 --- a/sugar/activity/Activity.py +++ b/sugar/activity/Activity.py @@ -4,17 +4,13 @@ import imp import dbus import dbus.service import dbus.glib -import pygtk -pygtk.require('2.0') -import gtk, gobject +import gtk +import gobject from sugar.LogWriter import LogWriter from sugar import keybindings import sugar.util -SHELL_SERVICE_NAME = "caom.redhat.Sugar.Shell" -SHELL_SERVICE_PATH = "/com/redhat/Sugar/Shell" - ACTIVITY_SERVICE_NAME = "com.redhat.Sugar.Activity" ACTIVITY_SERVICE_PATH = "/com/redhat/Sugar/Activity" @@ -84,7 +80,6 @@ def create(activity_name, service = None, args = None): def register_factory(name, activity_class, default_type=None): """Register the activity factory.""" factory = ActivityFactory(name, activity_class, default_type) - gtk.main() class ActivityDbusService(dbus.service.Object): @@ -186,6 +181,7 @@ class Activity(gtk.Window): def set_default_type(self, default_type): self._default_type = default_type + print self._default_type def get_default_type(self): return self._default_type @@ -194,7 +190,6 @@ class Activity(gtk.Window): """Mark the activity as 'shared'.""" if not self._shared: self._shared = True - self._dbus_service.ActivityShared() def get_shared(self): return self._shared diff --git a/sugar/presence/PresenceService.py b/sugar/presence/PresenceService.py index e6345cbf..bda8fa9f 100644 --- a/sugar/presence/PresenceService.py +++ b/sugar/presence/PresenceService.py @@ -489,7 +489,7 @@ class PresenceService(gobject.GObject): port = random.randint(5000, 65535) # Mark the activity as shared - if stype == activity.default_type(): + if stype == activity.get_default_type(): activity.set_shared() logging.debug('Share activity %s, type %s, address %s, port %d, properties %s' % (actid, stype, address, port, properties))