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:
+46
-5
@@ -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')
|
||||
activity = ActivityFactory.create(activity_type)
|
||||
activity.start()
|
||||
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)
|
||||
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):
|
||||
|
||||
@@ -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):
|
||||
|
||||
Reference in New Issue
Block a user