#5080: Clipboard fixes for sharing of URIs.
This commit is contained in:
parent
dc8809cdc6
commit
f0d194f3fb
@ -44,7 +44,6 @@ class ClipboardMenu(Palette):
|
|||||||
self.set_group_id('frame')
|
self.set_group_id('frame')
|
||||||
|
|
||||||
self._progress_bar = None
|
self._progress_bar = None
|
||||||
self._update_progress_bar
|
|
||||||
|
|
||||||
"""
|
"""
|
||||||
if preview:
|
if preview:
|
||||||
@ -174,6 +173,14 @@ class ClipboardMenu(Palette):
|
|||||||
jobject = self._copy_to_journal()
|
jobject = self._copy_to_journal()
|
||||||
jobject.destroy()
|
jobject.destroy()
|
||||||
|
|
||||||
|
def _write_to_temp_file(self, data):
|
||||||
|
f, file_path = tempfile.mkstemp()
|
||||||
|
try:
|
||||||
|
os.write(f, data)
|
||||||
|
finally:
|
||||||
|
os.close(f)
|
||||||
|
return file_path
|
||||||
|
|
||||||
def _copy_to_journal(self):
|
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)
|
||||||
@ -183,18 +190,24 @@ class ClipboardMenu(Palette):
|
|||||||
|
|
||||||
transfer_ownership = False
|
transfer_ownership = False
|
||||||
if format == 'text/uri-list':
|
if format == 'text/uri-list':
|
||||||
uri = mime.split_uri_list(data['DATA'])[0]
|
uris = mime.split_uri_list(data['DATA'])
|
||||||
file_path = urlparse.urlparse(uri).path
|
if len(uris) == 1 and uris[0].startswith('file://'):
|
||||||
|
file_path = urlparse.urlparse(uris[0]).path
|
||||||
|
transfer_ownership = False
|
||||||
|
mime_type = mime.get_for_file(file_path)
|
||||||
|
else:
|
||||||
|
file_path = self._write_to_temp_file(data['DATA'])
|
||||||
|
transfer_ownership = True
|
||||||
|
mime_type = 'text/uri-list'
|
||||||
else:
|
else:
|
||||||
if data['ON_DISK']:
|
if data['ON_DISK']:
|
||||||
file_path = urlparse.urlparse(data['DATA']).path
|
file_path = urlparse.urlparse(data['DATA']).path
|
||||||
|
transfer_ownership = False
|
||||||
|
mime_type = mime.get_for_file(file_path)
|
||||||
else:
|
else:
|
||||||
f, file_path = tempfile.mkstemp()
|
file_path = self._write_to_temp_file(data['DATA'])
|
||||||
try:
|
|
||||||
os.write(f, data['DATA'])
|
|
||||||
finally:
|
|
||||||
os.close(f)
|
|
||||||
transfer_ownership = True
|
transfer_ownership = True
|
||||||
|
mime_type = mime.get_for_file(file_path)
|
||||||
|
|
||||||
jobject = datastore.create()
|
jobject = datastore.create()
|
||||||
jobject.metadata['title'] = _('Clipboard object: %s.') % obj['NAME']
|
jobject.metadata['title'] = _('Clipboard object: %s.') % obj['NAME']
|
||||||
@ -202,7 +215,7 @@ class ClipboardMenu(Palette):
|
|||||||
jobject.metadata['buddies'] = ''
|
jobject.metadata['buddies'] = ''
|
||||||
jobject.metadata['preview'] = ''
|
jobject.metadata['preview'] = ''
|
||||||
jobject.metadata['icon-color'] = profile.get_color().to_string()
|
jobject.metadata['icon-color'] = profile.get_color().to_string()
|
||||||
jobject.metadata['mime_type'] = mime.get_for_file(file_path)
|
jobject.metadata['mime_type'] = mime_type
|
||||||
jobject.file_path = file_path
|
jobject.file_path = file_path
|
||||||
datastore.write(jobject, transfer_ownership=transfer_ownership)
|
datastore.write(jobject, transfer_ownership=transfer_ownership)
|
||||||
|
|
||||||
|
@ -15,6 +15,7 @@
|
|||||||
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
|
||||||
|
|
||||||
import logging
|
import logging
|
||||||
|
import urlparse
|
||||||
|
|
||||||
import gtk
|
import gtk
|
||||||
import hippo
|
import hippo
|
||||||
@ -77,17 +78,22 @@ class ClipboardPanelWindow(FrameWindow):
|
|||||||
|
|
||||||
cb_service = clipboardservice.get_instance()
|
cb_service = clipboardservice.get_instance()
|
||||||
if selection.type == 'text/uri-list':
|
if selection.type == 'text/uri-list':
|
||||||
uris = selection.data.split('\n')
|
uris = selection.get_uris()
|
||||||
|
|
||||||
if len(uris) > 1:
|
if len(uris) > 1:
|
||||||
raise NotImplementedError('Multiple uris in text/uri-list still not supported.')
|
raise NotImplementedError('Multiple uris in text/uri-list still not supported.')
|
||||||
|
uri = uris[0]
|
||||||
|
|
||||||
|
scheme, netloc, path, parameters, query, fragment = urlparse.urlparse(uri)
|
||||||
|
on_disk = (scheme == 'file')
|
||||||
|
|
||||||
cb_service.add_object_format(key,
|
cb_service.add_object_format(key,
|
||||||
selection.type,
|
selection.type,
|
||||||
uris[0],
|
uri,
|
||||||
on_disk=True)
|
on_disk)
|
||||||
else:
|
else:
|
||||||
cb_service.add_object_format(key,
|
cb_service.add_object_format(key,
|
||||||
selection.type,
|
selection.type,
|
||||||
selection.data,
|
selection.data,
|
||||||
on_disk=False)
|
on_disk=False)
|
||||||
|
|
||||||
|
Loading…
Reference in New Issue
Block a user