diff options
author | Sascha Silbe <silbe@activitycentral.com> | 2011-03-12 17:34:25 (GMT) |
---|---|---|
committer | Sascha Silbe <silbe@activitycentral.com> | 2011-03-12 17:34:25 (GMT) |
commit | 53291e463f572e04cd34b945a5616de2c0e9862a (patch) | |
tree | 339ab3540b6afbffbc9b75cfdf571c85240ccc74 /src/jarabe/journal/misc.py | |
parent | 2dde0582b4355eb163babeb36ea6884838ce4968 (diff) | |
parent | a89f365d901a76f499ff80698891cd02b64a7de4 (diff) |
Merge commit 'refs/top-bases/t/versions' into t/versions
* commit 'refs/top-bases/t/versions': (87 commits)
Fix up style issues introduced by commit 3f8a1e1
Don't set default timezone
Restore setting a language with the command line OLPC #10681
battery frame device: replace HAL with UPower
use ConsoleKit instead of HAL for shutdown/reboot
fix recognition of JEBs outside of data store
Adjust the year in the licence visible in the control panel
Handle activities that cycle through windows dlo#10695
Speaker frame device: pop up palette on left-click instead of toggling mute
recognise translations using pgettext
Remove last few pieces of buddy-icon.jpg handling
fix whitespace error introduced by 4b6a534 (revert of 4a3416b)
Commit from Sugar Labs: Translation System by user RafaelOrtiz.: 374 of 374 messages translated (0 fuzzy).
Intro: Fall back to user name if GECOS real name field is empty
Sugar Ad-hoc icons show in search results when connect/disconnect to AP OLPC #10412
Show busy cursor during session shutdown
Show free space for the Journal in the Journal volumes toolbar (SL#2318)
Fix incorrect logging level for warning about missing GSM configuration
simplify extension loading exception error
Revert "Add cpu and memory resource indicator to frame" as agreed on with erikos. Scheduling for inclusion in 0.94 after potential artwork changes based on feedback from the Design Team.
...
Conflicts:
src/jarabe/journal/journalactivity.py
src/jarabe/journal/journalentrybundle.py
src/jarabe/journal/journaltoolbox.py
src/jarabe/journal/listmodel.py
src/jarabe/journal/listview.py
src/jarabe/journal/misc.py
src/jarabe/journal/model.py
src/jarabe/journal/palettes.py
src/jarabe/journal/volumestoolbar.py
Diffstat (limited to 'src/jarabe/journal/misc.py')
-rw-r--r-- | src/jarabe/journal/misc.py | 95 |
1 files changed, 74 insertions, 21 deletions
diff --git a/src/jarabe/journal/misc.py b/src/jarabe/journal/misc.py index c64dbfa..2c78d81 100644 --- a/src/jarabe/journal/misc.py +++ b/src/jarabe/journal/misc.py @@ -27,8 +27,10 @@ from sugar.activity import activityfactory from sugar.activity.activityhandle import ActivityHandle from sugar.graphics.icon import get_icon_file_name from sugar.graphics.xocolor import XoColor +from sugar.graphics.alert import ConfirmationAlert from sugar import mime from sugar.bundle.activitybundle import ActivityBundle +from sugar.bundle.bundle import AlreadyInstalledException from sugar.bundle.contentbundle import ContentBundle from sugar import util @@ -36,6 +38,8 @@ from jarabe.view import launcher from jarabe.model import bundleregistry, shell from jarabe.journal.journalentrybundle import JournalEntryBundle from jarabe.journal import model +from jarabe.journal import journalwindow + def _get_icon_for_mime(mime_type): generic_types = mime.get_all_generic_types() @@ -52,6 +56,7 @@ def _get_icon_for_mime(mime_type): if file_name is not None: return file_name + def get_icon_name(metadata): file_name = None @@ -81,35 +86,46 @@ def get_icon_name(metadata): return file_name + def get_date(metadata): """ Convert from a string in iso format to a more human-like format. """ - if metadata.has_key('timestamp'): - timestamp = float(metadata['timestamp']) - return util.timestamp_to_elapsed_string(timestamp) - elif metadata.has_key('mtime'): - ti = time.strptime(metadata['mtime'], "%Y-%m-%dT%H:%M:%S") - return util.timestamp_to_elapsed_string(time.mktime(ti)) - else: - return _('No date') + if 'timestamp' in metadata: + try: + timestamp = float(metadata['timestamp']) + except (TypeError, ValueError): + logging.warning('Invalid timestamp: %r', metadata['timestamp']) + else: + return util.timestamp_to_elapsed_string(timestamp) + + if 'mtime' in metadata: + try: + ti = time.strptime(metadata['mtime'], '%Y-%m-%dT%H:%M:%S') + except (TypeError, ValueError): + logging.warning('Invalid mtime: %r', metadata['mtime']) + else: + return util.timestamp_to_elapsed_string(time.mktime(ti)) + + return _('No date') + def get_bundle(metadata): try: if is_activity_bundle(metadata): - file_path = util.TempFilePath(model.get_file((metadata['tree_id'], metadata['version_id']))) + file_path = model.get_file((metadata['tree_id'], metadata['version_id'])) if not os.path.exists(file_path): logging.warning('Invalid path: %r', file_path) return None return ActivityBundle(file_path) elif is_content_bundle(metadata): - file_path = util.TempFilePath(model.get_file((metadata['tree_id'], metadata['version_id']))) + file_path = model.get_file((metadata['tree_id'], metadata['version_id'])) if not os.path.exists(file_path): logging.warning('Invalid path: %r', file_path) return None return ContentBundle(file_path) elif is_journal_bundle(metadata): - file_path = util.TempFilePath(model.get_file((metadata['tree_id'], metadata['version_id']))) + file_path = model.get_file((metadata['tree_id'], metadata['version_id'])) if not os.path.exists(file_path): logging.warning('Invalid path: %r', file_path) return None @@ -120,6 +136,7 @@ def get_bundle(metadata): logging.exception('Incorrect bundle') return None + def _get_activities_for_mime(mime_type): registry = bundleregistry.get_registry() result = registry.get_activities_for_type(mime_type) @@ -130,6 +147,7 @@ def _get_activities_for_mime(mime_type): result.append(activity) return result + def get_activities(metadata): activities = [] @@ -148,6 +166,7 @@ def get_activities(metadata): return activities + def resume(metadata, bundle_id=None): registry = bundleregistry.get_registry() @@ -159,19 +178,16 @@ def resume(metadata, bundle_id=None): bundle = ActivityBundle(file_path) if not registry.is_installed(bundle): logging.debug('Installing activity bundle') - registry.install(bundle) + try: + registry.install(bundle) + except AlreadyInstalledException: + _downgrade_option_alert(bundle) + return else: logging.debug('Upgrading activity bundle') registry.upgrade(bundle) - logging.debug('activityfactory.creating bundle with id %r', - bundle.get_bundle_id()) - installed_bundle = registry.get_bundle(bundle.get_bundle_id()) - if installed_bundle: - launch(installed_bundle) - else: - logging.error('Bundle %r is not installed.', - bundle.get_bundle_id()) + _launch_bundle(bundle) elif is_content_bundle(metadata) and bundle_id is None: @@ -206,7 +222,6 @@ def resume(metadata, bundle_id=None): bundle = registry.get_bundle(bundle_id) - if metadata.get('mountpoint', '/') == '/': object_id = (metadata['tree_id'], metadata['version_id']) else: @@ -215,6 +230,19 @@ def resume(metadata, bundle_id=None): launch(bundle, activity_id=activity_id, object_id=object_id, color=get_icon_color(metadata)) + +def _launch_bundle(bundle): + registry = bundleregistry.get_registry() + logging.debug('activityfactory.creating bundle with id %r', + bundle.get_bundle_id()) + installed_bundle = registry.get_bundle(bundle.get_bundle_id()) + if installed_bundle: + launch(installed_bundle) + else: + logging.error('Bundle %r is not installed.', + bundle.get_bundle_id()) + + def launch(bundle, activity_id=None, object_id=None, uri=None, color=None, invited=False): if activity_id is None or not activity_id: @@ -239,21 +267,46 @@ def launch(bundle, activity_id=None, object_id=None, uri=None, color=None, object_id=object_id, uri=uri, invited=invited) activityfactory.create(bundle, activity_handle) + +def _downgrade_option_alert(bundle): + alert = ConfirmationAlert() + alert.props.title = _('Older Version Of %s Activity') % (bundle.get_name()) + alert.props.msg = _('Do you want to downgrade to version %s') % \ + bundle.get_activity_version() + alert.connect('response', _downgrade_alert_response_cb, bundle) + journalwindow.get_journal_window().add_alert(alert) + alert.show() + + +def _downgrade_alert_response_cb(alert, response_id, bundle): + if response_id is gtk.RESPONSE_OK: + journalwindow.get_journal_window().remove_alert(alert) + registry = bundleregistry.get_registry() + registry.install(bundle, force_downgrade=True) + _launch_bundle(bundle) + elif response_id is gtk.RESPONSE_CANCEL: + journalwindow.get_journal_window().remove_alert(alert) + + def is_activity_bundle(metadata): mime_type = metadata.get('mime_type', '') return mime_type == ActivityBundle.MIME_TYPE or \ mime_type == ActivityBundle.DEPRECATED_MIME_TYPE + def is_content_bundle(metadata): return metadata.get('mime_type', '') == ContentBundle.MIME_TYPE + def is_journal_bundle(metadata): return metadata.get('mime_type', '') == JournalEntryBundle.MIME_TYPE + def is_bundle(metadata): return is_activity_bundle(metadata) or is_content_bundle(metadata) or \ is_journal_bundle(metadata) + def get_icon_color(metadata): if metadata is None or not 'icon-color' in metadata: client = gconf.client_get_default() |