From 7e85c5160ec0a04cb7434cd53368a7c5ba8ce0fa Mon Sep 17 00:00:00 2001 From: Marco Pesenti Gritti Date: Wed, 09 Aug 2006 10:57:42 +0000 Subject: Setup the activity from the shell process, through dbus, this simplifies things a lot... --- (limited to 'shell') diff --git a/shell/ActivityHost.py b/shell/ActivityHost.py index 540d1e2..f2287c4 100644 --- a/shell/ActivityHost.py +++ b/shell/ActivityHost.py @@ -10,11 +10,10 @@ class ActivityHost: self._xid = xid bus = dbus.SessionBus() - service = Activity.ACTIVITY_SERVICE_NAME + "%s" % xid path = Activity.ACTIVITY_SERVICE_PATH + "/%s" % xid - proxy_obj = bus.get_object(service, path) + proxy_obj = bus.get_object(Activity.ACTIVITY_SERVICE_NAME, path) - self._activity = dbus.Interface(proxy_obj, 'com.redhat.Sugar.Activity') + self._activity = dbus.Interface(proxy_obj, Activity.ACTIVITY_INTERFACE) self._id = self._activity.get_id() self._default_type = self._activity.get_default_type() self._window = gtk.gdk.window_foreign_new(xid) diff --git a/shell/ActivityRegistry.py b/shell/ActivityRegistry.py index 3ac8a4f..acf379c 100644 --- a/shell/ActivityRegistry.py +++ b/shell/ActivityRegistry.py @@ -45,6 +45,13 @@ class ActivityRegistry: def __init__(self): self._activities = [] + + def get_activity_from_id(self, activity_id): + """Returns an activity given his identifier""" + for activity in self._activities: + if activity.get_id() == activity_id: + return activity + return None def get_activity(self, default_type): """Returns an activity given his default type""" diff --git a/shell/HomeWindow.py b/shell/HomeWindow.py index ef44f61..886068c 100644 --- a/shell/HomeWindow.py +++ b/shell/HomeWindow.py @@ -72,16 +72,7 @@ class ActivitiesGrid(gtk.VBox): self._buttons[activity.get_id()] = button def __button_clicked_cb(self, button, info): - activity = self._shell.get_registry().get_activity(info.get_type()) - - activity_id = info.get_service().get_activity_id() - pservice = PresenceService() - activity_ps = pservice.get_activity(activity_id) - - if activity_ps: - ActivityFactory.create(activity.get_id(), activity_ps) - else: - print 'Cannot start activity.' + self._shell.join_activity(info.get_service()) class TasksGrid(gtk.VBox): def __init__(self, home): @@ -168,7 +159,7 @@ class HomeWindow(gtk.Window): return self._shell.get_registry().list_activities() def create(self, activity_name): - ActivityFactory.create(activity_name) + self._shell.start_activity(activity_name) def activate(self, activity_window): activity_window.activate(gtk.get_current_event_time()) diff --git a/shell/Shell.py b/shell/Shell.py index 2860ed0..f08d724 100755 --- a/shell/Shell.py +++ b/shell/Shell.py @@ -1,4 +1,5 @@ import os +import logging import dbus import dbus.glib @@ -12,9 +13,10 @@ from HomeWindow import HomeWindow from sugar import env from ConsoleWindow import ConsoleWindow from Owner import ShellOwner -from PresenceService import PresenceService +from sugar.presence.PresenceService import PresenceService from ActivityHost import ActivityHost from ChatListener import ChatListener +from sugar.activity import ActivityFactory class ShellDbusService(dbus.service.Object): def __init__(self, shell, bus_name): @@ -106,6 +108,30 @@ class Shell: module = self._registry.get_activity(activity.get_default_type()) console = self.get_console(module.get_id()) activity.show_dialog(console) + + def join_activity(self, service): + info = self._registry.get_activity(service.get_type()) + + activity_id = service.get_activity_id() + pservice = PresenceService() + activity_ps = pservice.get_activity(activity_id) + + if activity_ps: + activity = ActivityFactory.create(info.get_id()) + activity.set_default_type(service.get_type()) + activity.join(activity_ps.object_path()) + else: + logging.error('Cannot start activity.') + + def start_activity(self, activity_name): + activity = ActivityFactory.create(activity_name) + info = self._registry.get_activity_from_id(activity_name) + if info: + activity.set_default_type(info.get_default_type()) + return activity + else: + logging.error('No such activity in the directory') + return None def log(self, module_id, message): console = self.get_console(module_id) -- cgit v0.9.1