Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
-rwxr-xr-xshell/sugar-activity3
-rw-r--r--shell/view/Shell.py51
-rw-r--r--shell/view/clipboardicon.py3
-rw-r--r--sugar/activity/Activity.py12
4 files changed, 56 insertions, 13 deletions
diff --git a/shell/sugar-activity b/shell/sugar-activity
index bb6cf30..464eaf6 100755
--- a/shell/sugar-activity
+++ b/shell/sugar-activity
@@ -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())
diff --git a/shell/view/Shell.py b/shell/view/Shell.py
index f3f6ca0..169ee35 100644
--- a/shell/view/Shell.py
+++ b/shell/view/Shell.py
@@ -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):
diff --git a/shell/view/clipboardicon.py b/shell/view/clipboardicon.py
index ade37bd..4e702d3 100644
--- a/shell/view/clipboardicon.py
+++ b/shell/view/clipboardicon.py
@@ -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):
diff --git a/sugar/activity/Activity.py b/sugar/activity/Activity.py
index c0023ab..7926dae 100644
--- a/sugar/activity/Activity.py
+++ b/sugar/activity/Activity.py
@@ -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.