Make shell responsible for activity ID generation

Enables tracking of activity launch throughout the whole process, so that
the shell can be aware of the activity ID from the moment the activity
is started by the shell, until the activity becomes active.  Previously,
the activity itself generated its own ID and told the shell what it was.
This commit is contained in:
Dan Williams 2007-01-06 16:29:13 -05:00
parent f50d9f5f9a
commit b27257fadb
4 changed files with 56 additions and 13 deletions

View File

@ -21,6 +21,7 @@ import os
from sugar.activity import ActivityFactory
from sugar import env
from sugar import util
ppath = env.get_profile_path()
bus_file = os.path.join(ppath, "session_bus_address")
@ -30,4 +31,4 @@ f.close()
os.environ['DBUS_SESSION_BUS_ADDRESS'] = bus_name
activity = ActivityFactory.create(sys.argv[1])
activity.start()
activity.start(util.unique_id())

View File

@ -68,6 +68,8 @@ class Shell(gobject.GObject):
self._frame = Frame(self)
self._frame.show_and_hide(3)
self._pservice = PresenceService.get_instance()
#self.start_activity('org.laptop.JournalActivity')
def _handle_camera_key(self):
@ -190,13 +192,11 @@ class Shell(gobject.GObject):
return self._model
def join_activity(self, bundle_id, activity_id):
pservice = PresenceService.get_instance()
activity = self.get_activity(activity_id)
if activity:
activity.present()
else:
activity_ps = pservice.get_activity(activity_id)
activity_ps = self._pservice.get_activity(activity_id)
if activity_ps:
# Get the service name for this activity, if
@ -218,10 +218,51 @@ class Shell(gobject.GObject):
else:
logging.error('Cannot start activity.')
def _find_unique_activity_id(self):
# create a new unique activity ID
i = 0
act_id = None
while i < 10:
act_id = sugar.util.unique_id()
i += 1
# check through existing activities
found = False
for xid, act_host in self._hosts.items():
if act_host.get_id() == act_id:
found = True
break
if found:
act_id = None
continue
# check through network activities
activities = self._pservice.get_activities()
for act in activities:
if act_id == act.get_id():
found = True
break
if found:
act_id = None
continue
return act_id
def start_activity(self, activity_type):
logging.debug('Shell.start_activity')
act_id = self._find_unique_activity_id()
if not act_id:
logging.error("Couldn't find available activity ID.")
return None
try:
logging.debug("Shell.start_activity will start %s:%s" % (activity_type, act_id))
activity = ActivityFactory.create(activity_type)
activity.start()
except dbus.DBusException, e:
logging.debug("Couldn't start activity '%s':\n %s" % (activity_type, e))
return None
activity.start(act_id)
return activity
def set_zoom_level(self, level):

View File

@ -4,6 +4,7 @@ from sugar.graphics.menuicon import MenuIcon
from view.clipboardmenu import ClipboardMenu
from sugar.activity import ActivityFactory
from sugar.clipboard import clipboardservice
from sugar import util
class ClipboardIcon(MenuIcon):
@ -53,7 +54,7 @@ class ClipboardIcon(MenuIcon):
if activity_id:
activity = ActivityFactory.create(activity_id)
activity.start()
activity.start(util.unique_id())
activity.execute("open_document", [self._object_id])
def _popup_action_cb(self, popup, action):

View File

@ -62,9 +62,9 @@ class ActivityDbusService(dbus.service.Object):
self._pservice = PresenceService.get_instance()
@dbus.service.method(ACTIVITY_INTERFACE)
def start(self):
"""Start the activity."""
self._activity.start()
def start(self, activity_id):
"""Start the activity in unshared mode."""
self._activity.start(activity_id)
@dbus.service.method(ACTIVITY_INTERFACE)
def join(self, activity_ps_path):
@ -120,13 +120,13 @@ class Activity(gtk.Window):
self._bus = ActivityDbusService(self)
def start(self):
def start(self, activity_id):
"""Start the activity."""
if self._activity_id != None:
logging.warning('The activity has been already started.')
return
self._activity_id = sugar.util.unique_id()
self._activity_id = activity_id
#ds = datastore.get_instance()
#self._journal_object = ds.create('', {}, self._activity_id)
@ -162,9 +162,9 @@ class Activity(gtk.Window):
if self._activity_id != None:
logging.warning('The activity has been already started.')
return
self._activity_id = activity_ps.get_id()
self._shared = True
self._activity_id = activity_ps.get_id()
# Publish the default service, it's a copy of
# one of those we found on the network.