Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/src
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@tomeuvizoso.net>2008-09-16 14:03:49 (GMT)
committer Tomeu Vizoso <tomeu@tomeuvizoso.net>2008-09-16 14:03:49 (GMT)
commita93992eedc32d43b5d1bfd5bef04f87170729f5a (patch)
tree7809218fc344b6ef14bcebb90888eb6a9c11b8a6 /src
parentbe32d3fb6705ad238adbe5629a5c267e851e3e36 (diff)
Revert "Move DSObject.resume() from sugar-toolkit to the shell"
This reverts commit 13682dd1b4458899e7044e1e917e5bc7a905fee4.
Diffstat (limited to 'src')
-rw-r--r--src/sugar/datastore/datastore.py81
1 files changed, 81 insertions, 0 deletions
diff --git a/src/sugar/datastore/datastore.py b/src/sugar/datastore/datastore.py
index 9cd22bf..81c00e4 100644
--- a/src/sugar/datastore/datastore.py
+++ b/src/sugar/datastore/datastore.py
@@ -23,6 +23,8 @@ import os
import gobject
from sugar.datastore import dbus_helpers
+from sugar import activity
+from sugar.activity.activityhandle import ActivityHandle
from sugar.bundle.contentbundle import ContentBundle
from sugar.bundle.activitybundle import ActivityBundle
from sugar import mime
@@ -114,6 +116,32 @@ class DSObject(object):
file_path = property(get_file_path, set_file_path)
+ def _get_activities_for_mime(self, mime_type):
+ registry = activity.get_registry()
+ result = registry.get_activities_for_type(mime_type)
+ if not result:
+ for parent_mime in mime.get_mime_parents(mime_type):
+ result.extend(registry.get_activities_for_type(parent_mime))
+ return result
+
+ def get_activities(self):
+ activities = []
+
+ bundle_id = self.metadata.get('activity', '')
+ if bundle_id:
+ activity_info = activity.get_registry().get_activity(bundle_id)
+ if activity_info:
+ activities.append(activity_info)
+
+ mime_type = self.metadata.get('mime_type', '')
+ if mime_type:
+ activities_info = self._get_activities_for_mime(mime_type)
+ for activity_info in activities_info:
+ if activity_info.bundle_id != bundle_id:
+ activities.append(activity_info)
+
+ return activities
+
def is_activity_bundle(self):
return self.metadata['mime_type'] in \
[ActivityBundle.MIME_TYPE, ActivityBundle.DEPRECATED_MIME_TYPE]
@@ -124,6 +152,59 @@ class DSObject(object):
def is_bundle(self):
return self.is_activity_bundle() or self.is_content_bundle()
+ def resume(self, bundle_id=None):
+ from sugar.activity import activityfactory
+
+ if self.is_activity_bundle() and not bundle_id:
+
+ logging.debug('Creating activity bundle')
+ bundle = ActivityBundle(self.file_path)
+ if not bundle.is_installed():
+ logging.debug('Installing activity bundle')
+ bundle.install()
+ elif bundle.need_upgrade():
+ logging.debug('Upgrading activity bundle')
+ bundle.upgrade()
+
+ logging.debug('activityfactory.creating bundle with id %r',
+ bundle.get_bundle_id())
+ activityfactory.create(bundle.get_bundle_id())
+
+ elif self.is_content_bundle() and not bundle_id:
+
+ logging.debug('Creating content bundle')
+ bundle = ContentBundle(self.file_path)
+ if not bundle.is_installed():
+ logging.debug('Installing content bundle')
+ bundle.install()
+
+ activities = self._get_activities_for_mime('text/html')
+ if len(activities) == 0:
+ logging.warning('No activity can open HTML content bundles')
+ return
+
+ uri = bundle.get_start_uri()
+ logging.debug('activityfactory.creating with uri %s', uri)
+ activityfactory.create_with_uri(activities[0].bundle_id,
+ bundle.get_start_uri())
+ else:
+ if not self.get_activities() and bundle_id is None:
+ logging.warning('No activity can open this object, %s.' %
+ self.metadata.get('mime_type', None))
+ return
+ if bundle_id is None:
+ bundle_id = self.get_activities()[0].bundle_id
+
+ activity_id = self.metadata['activity_id']
+ object_id = self.object_id
+
+ if activity_id:
+ handle = ActivityHandle(object_id=object_id,
+ activity_id=activity_id)
+ activityfactory.create(bundle_id, handle)
+ else:
+ activityfactory.create_with_object_id(bundle_id, object_id)
+
def destroy(self):
if self._destroyed:
logging.warning('This DSObject has already been destroyed!.')