#1888 Fix opening items from the clipboard.
This commit is contained in:
parent
bbbea6167d
commit
bb71cd61cf
1
NEWS
1
NEWS
@ -1,3 +1,4 @@
|
|||||||
|
* #1888 Fix opening items from the clipboard. (tomeu)
|
||||||
* #1984 Fix removing items from the clipboard. (tomeu)
|
* #1984 Fix removing items from the clipboard. (tomeu)
|
||||||
|
|
||||||
Snapshot b83a9ec27d
|
Snapshot b83a9ec27d
|
||||||
|
@ -27,8 +27,6 @@ from sugar.graphics.palette import Palette
|
|||||||
from sugar.graphics.canvasicon import CanvasIcon
|
from sugar.graphics.canvasicon import CanvasIcon
|
||||||
from sugar.graphics import color
|
from sugar.graphics import color
|
||||||
from sugar.graphics import style
|
from sugar.graphics import style
|
||||||
from sugar.activity import activityfactory
|
|
||||||
from sugar.activity.bundle import Bundle
|
|
||||||
from sugar.clipboard import clipboardservice
|
from sugar.clipboard import clipboardservice
|
||||||
from sugar.datastore import datastore
|
from sugar.datastore import datastore
|
||||||
from sugar.objects import mime
|
from sugar.objects import mime
|
||||||
@ -118,44 +116,43 @@ class ClipboardMenu(Palette):
|
|||||||
if self._percent < 100:
|
if self._percent < 100:
|
||||||
return
|
return
|
||||||
|
|
||||||
# Get the file path
|
jobject = self._copy_to_journal()
|
||||||
cb_service = clipboardservice.get_instance()
|
# TODO: we cannot simply call resume() right now because we would lock
|
||||||
obj = cb_service.get_object(self._object_id)
|
# the shell as we are sharing the same loop as the shell service.
|
||||||
formats = obj['FORMATS']
|
#jobject.resume()
|
||||||
if len(formats) == 0:
|
|
||||||
logging.warning('ClipboardMenu._open_item_activate_cb: Object without data.')
|
# TODO: take this out when we fix the mess that is the shell/shellservice.
|
||||||
return
|
from shell.model import bundleregistry
|
||||||
|
from sugar.activity.bundle import Bundle
|
||||||
|
from sugar.activity import activityfactory
|
||||||
|
if jobject.is_bundle():
|
||||||
|
bundle = Bundle(jobject.file_path)
|
||||||
|
if not bundle.is_installed():
|
||||||
|
bundle.install()
|
||||||
|
|
||||||
if not self._activity and \
|
activityfactory.create(bundle.get_service_name())
|
||||||
not formats[0] == 'application/vnd.olpc-x-sugar':
|
|
||||||
logging.warning('ClipboardMenu._open_item_activate_cb: Object without activity.')
|
|
||||||
return
|
|
||||||
|
|
||||||
uri = cb_service.get_object_data(self._object_id, formats[0])['DATA']
|
|
||||||
if not uri.startswith('file://'):
|
|
||||||
return
|
|
||||||
|
|
||||||
(scheme, netloc, path, params, query, fragment) = urlparse.urlparse(uri)
|
|
||||||
|
|
||||||
# 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:
|
|
||||||
self._install_xo(path)
|
|
||||||
else:
|
else:
|
||||||
logging.debug("Clipboard item file path %s didn't exist" % path)
|
service_name = None
|
||||||
|
if jobject.metadata.has_key('activity') and jobject.metadata['activity']:
|
||||||
|
service_name = self.metadata['activity']
|
||||||
|
elif jobject.metadata.has_key('mime_type') and jobject.metadata['mime_type']:
|
||||||
|
mime_type = jobject.metadata['mime_type']
|
||||||
|
for bundle in bundleregistry.get_registry():
|
||||||
|
if bundle.get_mime_types() and mime_type in bundle.get_mime_types():
|
||||||
|
service_name = bundle.get_service_name()
|
||||||
|
break
|
||||||
|
if service_name:
|
||||||
|
activityfactory.create_with_object_id(service_name,
|
||||||
|
jobject.object_id)
|
||||||
|
|
||||||
def _remove_item_activate_cb(self, menu_item):
|
def _remove_item_activate_cb(self, menu_item):
|
||||||
cb_service = clipboardservice.get_instance()
|
cb_service = clipboardservice.get_instance()
|
||||||
cb_service.delete_object(self._object_id)
|
cb_service.delete_object(self._object_id)
|
||||||
|
|
||||||
def _journal_item_activate_cb(self, menu_item):
|
def _journal_item_activate_cb(self, menu_item):
|
||||||
|
self._copy_to_journal()
|
||||||
|
|
||||||
|
def _copy_to_journal(self):
|
||||||
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)
|
||||||
|
|
||||||
@ -185,9 +182,6 @@ class ClipboardMenu(Palette):
|
|||||||
jobject.metadata['mime_type'] = mime_type
|
jobject.metadata['mime_type'] = mime_type
|
||||||
jobject.file_path = file_path
|
jobject.file_path = file_path
|
||||||
datastore.write(jobject)
|
datastore.write(jobject)
|
||||||
|
|
||||||
def _install_xo(self, path):
|
return jobject
|
||||||
bundle = Bundle(path)
|
|
||||||
if not bundle.is_installed():
|
|
||||||
bundle.install()
|
|
||||||
|
|
||||||
|
@ -20,6 +20,9 @@ import logging
|
|||||||
import gobject
|
import gobject
|
||||||
|
|
||||||
from sugar.datastore import dbus_helpers
|
from sugar.datastore import dbus_helpers
|
||||||
|
from sugar import activity
|
||||||
|
from sugar.activity.bundle import Bundle
|
||||||
|
from sugar.activity import activityfactory
|
||||||
|
|
||||||
class DSMetadata(gobject.GObject):
|
class DSMetadata(gobject.GObject):
|
||||||
__gsignals__ = {
|
__gsignals__ = {
|
||||||
@ -85,6 +88,37 @@ class DSObject:
|
|||||||
|
|
||||||
file_path = property(get_file_path, set_file_path)
|
file_path = property(get_file_path, set_file_path)
|
||||||
|
|
||||||
|
def get_activities(self):
|
||||||
|
activities = []
|
||||||
|
|
||||||
|
if self.metadata['activity']:
|
||||||
|
activity_info = activity.get_registry().get_activity(self.metadata['activity'])
|
||||||
|
activities.append(activity_info)
|
||||||
|
|
||||||
|
mime_type = self.metadata['mime_type']
|
||||||
|
if mime_type:
|
||||||
|
activities_info = activity.get_registry().get_activities_for_type(mime_type)
|
||||||
|
for activity_info in activities_info:
|
||||||
|
if activity_info.service_name != self.metadata['activity']:
|
||||||
|
activities.append(activity_info)
|
||||||
|
|
||||||
|
return activities
|
||||||
|
|
||||||
|
def is_bundle(self):
|
||||||
|
return self.metadata['mime_type'] == 'application/vnd.olpc-x-sugar'
|
||||||
|
|
||||||
|
def resume(self):
|
||||||
|
if self.is_bundle():
|
||||||
|
bundle = Bundle(self.file_path)
|
||||||
|
if not bundle.is_installed():
|
||||||
|
bundle.install()
|
||||||
|
|
||||||
|
activityfactory.create(bundle.get_service_name())
|
||||||
|
else:
|
||||||
|
activity_info = self.get_activities()[0]
|
||||||
|
activityfactory.create_with_object_id(activity_info.service_name,
|
||||||
|
self.object_id)
|
||||||
|
|
||||||
def get(object_id):
|
def get(object_id):
|
||||||
logging.debug('datastore.get')
|
logging.debug('datastore.get')
|
||||||
metadata = dbus_helpers.get_properties(object_id)
|
metadata = dbus_helpers.get_properties(object_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user