Implement installation of downloaded activities.
This commit is contained in:
parent
d450ea2dd6
commit
ec8bb21936
@ -17,6 +17,7 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import os
|
import os
|
||||||
|
import urlparse
|
||||||
|
|
||||||
import gobject
|
import gobject
|
||||||
|
|
||||||
@ -74,8 +75,13 @@ class ClipboardIcon(CanvasIcon):
|
|||||||
self.props.background_color = color.TOOLBAR_BACKGROUND.get_int()
|
self.props.background_color = color.TOOLBAR_BACKGROUND.get_int()
|
||||||
|
|
||||||
def get_popup(self):
|
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._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)
|
self._menu.connect('action', self._popup_action_cb)
|
||||||
return self._menu
|
return self._menu
|
||||||
|
|
||||||
@ -83,15 +89,19 @@ class ClipboardIcon(CanvasIcon):
|
|||||||
return self._popup_context
|
return self._popup_context
|
||||||
|
|
||||||
def set_state(self, name, percent, icon_name, preview, activity):
|
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._name = name
|
||||||
self._percent = percent
|
self._percent = percent
|
||||||
self._preview = preview
|
self._preview = preview
|
||||||
self._activity = activity
|
self._activity = activity
|
||||||
self.set_property("icon_name", icon_name)
|
self.set_property("icon_name", icon_name)
|
||||||
if self._menu:
|
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")
|
self.props.xo_color = XoColor("#000000,#424242")
|
||||||
else:
|
else:
|
||||||
self.props.xo_color = XoColor("#000000,#FFFFFF")
|
self.props.xo_color = XoColor("#000000,#FFFFFF")
|
||||||
@ -107,15 +117,25 @@ class ClipboardIcon(CanvasIcon):
|
|||||||
self._open_file()
|
self._open_file()
|
||||||
|
|
||||||
def _open_file(self):
|
def _open_file(self):
|
||||||
if self._percent < 100 or not self._activity:
|
if self._percent < 100:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Get the file path
|
# Get the file path
|
||||||
cb_service = clipboardservice.get_instance()
|
cb_service = clipboardservice.get_instance()
|
||||||
obj = cb_service.get_object(self._object_id)
|
obj = cb_service.get_object(self._object_id)
|
||||||
formats = obj['FORMATS']
|
formats = obj['FORMATS']
|
||||||
if len(formats) > 0:
|
if len(formats) == 0:
|
||||||
path = cb_service.get_object_data(self._object_id, formats[0])
|
return
|
||||||
|
|
||||||
|
if not self._activity and \
|
||||||
|
not formats[0] == 'application/vnd.olpc-x-sugar':
|
||||||
|
return
|
||||||
|
|
||||||
|
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
|
# FIXME: would be better to check for format.onDisk
|
||||||
try:
|
try:
|
||||||
@ -124,8 +144,10 @@ class ClipboardIcon(CanvasIcon):
|
|||||||
path_exists = False
|
path_exists = False
|
||||||
|
|
||||||
if path_exists:
|
if path_exists:
|
||||||
uri = 'file://' + path
|
if self._activity:
|
||||||
activityfactory.create_with_uri(self._activity, uri)
|
activityfactory.create_with_uri(self._activity, uri)
|
||||||
|
else:
|
||||||
|
self._install_xo(path)
|
||||||
else:
|
else:
|
||||||
logging.debug("Clipboard item file path %s didn't exist" % path)
|
logging.debug("Clipboard item file path %s didn't exist" % path)
|
||||||
|
|
||||||
@ -153,3 +175,9 @@ class ClipboardIcon(CanvasIcon):
|
|||||||
self.props.background_color = color.DESKTOP_BACKGROUND.get_int()
|
self.props.background_color = color.DESKTOP_BACKGROUND.get_int()
|
||||||
else:
|
else:
|
||||||
self.props.background_color = color.TOOLBAR_BACKGROUND.get_int()
|
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.'
|
||||||
|
@ -33,7 +33,7 @@ class ClipboardMenu(Menu):
|
|||||||
ACTION_OPEN = 1
|
ACTION_OPEN = 1
|
||||||
ACTION_STOP_DOWNLOAD = 2
|
ACTION_STOP_DOWNLOAD = 2
|
||||||
|
|
||||||
def __init__(self, name, percent, preview, activity):
|
def __init__(self, name, percent, preview, activity, installable):
|
||||||
Menu.__init__(self, name)
|
Menu.__init__(self, name)
|
||||||
self.props.border = 0
|
self.props.border = 0
|
||||||
|
|
||||||
@ -54,10 +54,10 @@ class ClipboardMenu(Menu):
|
|||||||
self._preview_text.props.font_desc = font.DEFAULT.get_pango_desc()
|
self._preview_text.props.font_desc = font.DEFAULT.get_pango_desc()
|
||||||
self.append(self._preview_text)
|
self.append(self._preview_text)
|
||||||
|
|
||||||
self._update_icons(percent, activity)
|
self._update_icons(percent, activity, installable)
|
||||||
|
|
||||||
def _update_icons(self, percent, activity):
|
def _update_icons(self, percent, activity, installable):
|
||||||
if percent == 100 and activity:
|
if percent == 100 and (activity or installable):
|
||||||
if not self._remove_item:
|
if not self._remove_item:
|
||||||
self._remove_item = MenuItem(ClipboardMenu.ACTION_DELETE,
|
self._remove_item = MenuItem(ClipboardMenu.ACTION_DELETE,
|
||||||
_('Remove'),
|
_('Remove'),
|
||||||
@ -73,7 +73,7 @@ class ClipboardMenu(Menu):
|
|||||||
if self._stop_item:
|
if self._stop_item:
|
||||||
self.remove_item(self._stop_item)
|
self.remove_item(self._stop_item)
|
||||||
self._stop_item = None
|
self._stop_item = None
|
||||||
elif percent == 100 and not activity:
|
elif percent == 100 and (not activity and not installable):
|
||||||
if not self._remove_item:
|
if not self._remove_item:
|
||||||
self._remove_item = MenuItem(ClipboardMenu.ACTION_DELETE,
|
self._remove_item = MenuItem(ClipboardMenu.ACTION_DELETE,
|
||||||
_('Remove'),
|
_('Remove'),
|
||||||
@ -102,8 +102,8 @@ class ClipboardMenu(Menu):
|
|||||||
self.remove_item(self._open_item)
|
self.remove_item(self._open_item)
|
||||||
self._open_item = None
|
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)
|
self.set_title(name)
|
||||||
if self._progress_bar:
|
if self._progress_bar:
|
||||||
self._progress_bar.set_property('percent', percent)
|
self._progress_bar.set_property('percent', percent)
|
||||||
self._update_icons(percent, activity)
|
self._update_icons(percent, activity, installable)
|
||||||
|
Loading…
Reference in New Issue
Block a user