From ec8bb2193673847dace2ac49170c5961a032b056 Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Fri, 20 Apr 2007 20:12:49 +0200 Subject: [PATCH] Implement installation of downloaded activities. --- shell/view/clipboardicon.py | 56 +++++++++++++++++++++++++++---------- shell/view/clipboardmenu.py | 14 +++++----- 2 files changed, 49 insertions(+), 21 deletions(-) diff --git a/shell/view/clipboardicon.py b/shell/view/clipboardicon.py index ef0de29e..143d016e 100644 --- a/shell/view/clipboardicon.py +++ b/shell/view/clipboardicon.py @@ -17,6 +17,7 @@ import logging import os +import urlparse import gobject @@ -74,8 +75,13 @@ class ClipboardIcon(CanvasIcon): self.props.background_color = color.TOOLBAR_BACKGROUND.get_int() def get_popup(self): + cb_service = clipboardservice.get_instance() + obj = cb_service.get_object(self._object_id) + formats = obj['FORMATS'] + self._menu = ClipboardMenu(self._name, self._percent, self._preview, - self._activity) + self._activity, + formats[0] == 'application/vnd.olpc-x-sugar') self._menu.connect('action', self._popup_action_cb) return self._menu @@ -83,15 +89,19 @@ class ClipboardIcon(CanvasIcon): return self._popup_context def set_state(self, name, percent, icon_name, preview, activity): + cb_service = clipboardservice.get_instance() + obj = cb_service.get_object(self._object_id) + installable = (obj['FORMATS'][0] == 'application/vnd.olpc-x-sugar') + self._name = name self._percent = percent self._preview = preview self._activity = activity self.set_property("icon_name", icon_name) if self._menu: - self._menu.set_state(name, percent, preview, activity) + self._menu.set_state(name, percent, preview, activity, installable) - if activity and percent < 100: + if (activity or installable) and percent < 100: self.props.xo_color = XoColor("#000000,#424242") else: self.props.xo_color = XoColor("#000000,#FFFFFF") @@ -107,27 +117,39 @@ class ClipboardIcon(CanvasIcon): self._open_file() def _open_file(self): - if self._percent < 100 or not self._activity: + if self._percent < 100: return # Get the file path cb_service = clipboardservice.get_instance() obj = cb_service.get_object(self._object_id) formats = obj['FORMATS'] - if len(formats) > 0: - path = cb_service.get_object_data(self._object_id, formats[0]) + if len(formats) == 0: + return - # FIXME: would be better to check for format.onDisk - try: - path_exists = os.path.exists(path) - except TypeError: - path_exists = False + if not self._activity and \ + not formats[0] == 'application/vnd.olpc-x-sugar': + return - if path_exists: - uri = 'file://' + path + uri = cb_service.get_object_data(self._object_id, formats[0]) + if not uri.startswith('file://'): + return + + path = urlparse.urlparse(uri).path + + # FIXME: would be better to check for format.onDisk + try: + path_exists = os.path.exists(path) + except TypeError: + path_exists = False + + if path_exists: + if self._activity: activityfactory.create_with_uri(self._activity, uri) else: - logging.debug("Clipboard item file path %s didn't exist" % path) + self._install_xo(path) + else: + logging.debug("Clipboard item file path %s didn't exist" % path) def _popup_action_cb(self, popup, menu_item): action = menu_item.props.action_id @@ -153,3 +175,9 @@ class ClipboardIcon(CanvasIcon): self.props.background_color = color.DESKTOP_BACKGROUND.get_int() else: self.props.background_color = color.TOOLBAR_BACKGROUND.get_int() + + def _install_xo(self, path): + logging.debug('mec') + if os.spawnlp(os.P_WAIT, 'sugar-install-bundle', 'sugar-install-bundle', + path): + raise RuntimeError, 'An error occurred while extracting the .xo contents.' diff --git a/shell/view/clipboardmenu.py b/shell/view/clipboardmenu.py index 3e8239d6..9db69223 100644 --- a/shell/view/clipboardmenu.py +++ b/shell/view/clipboardmenu.py @@ -33,7 +33,7 @@ class ClipboardMenu(Menu): ACTION_OPEN = 1 ACTION_STOP_DOWNLOAD = 2 - def __init__(self, name, percent, preview, activity): + def __init__(self, name, percent, preview, activity, installable): Menu.__init__(self, name) self.props.border = 0 @@ -54,10 +54,10 @@ class ClipboardMenu(Menu): self._preview_text.props.font_desc = font.DEFAULT.get_pango_desc() self.append(self._preview_text) - self._update_icons(percent, activity) + self._update_icons(percent, activity, installable) - def _update_icons(self, percent, activity): - if percent == 100 and activity: + def _update_icons(self, percent, activity, installable): + if percent == 100 and (activity or installable): if not self._remove_item: self._remove_item = MenuItem(ClipboardMenu.ACTION_DELETE, _('Remove'), @@ -73,7 +73,7 @@ class ClipboardMenu(Menu): if self._stop_item: self.remove_item(self._stop_item) self._stop_item = None - elif percent == 100 and not activity: + elif percent == 100 and (not activity and not installable): if not self._remove_item: self._remove_item = MenuItem(ClipboardMenu.ACTION_DELETE, _('Remove'), @@ -102,8 +102,8 @@ class ClipboardMenu(Menu): self.remove_item(self._open_item) self._open_item = None - def set_state(self, name, percent, preview, activity): + def set_state(self, name, percent, preview, activity, installable): self.set_title(name) if self._progress_bar: self._progress_bar.set_property('percent', percent) - self._update_icons(percent, activity) + self._update_icons(percent, activity, installable)