#5080: Clipboard fixes for sharing of URIs.

This commit is contained in:
Tomeu Vizoso 2007-12-05 18:10:34 +01:00
parent dc8809cdc6
commit f0d194f3fb
2 changed files with 35 additions and 16 deletions

View File

@ -44,7 +44,6 @@ class ClipboardMenu(Palette):
self.set_group_id('frame')
self._progress_bar = None
self._update_progress_bar
"""
if preview:
@ -174,6 +173,14 @@ class ClipboardMenu(Palette):
jobject = self._copy_to_journal()
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):
cb_service = clipboardservice.get_instance()
obj = cb_service.get_object(self._object_id)
@ -183,18 +190,24 @@ class ClipboardMenu(Palette):
transfer_ownership = False
if format == 'text/uri-list':
uri = mime.split_uri_list(data['DATA'])[0]
file_path = urlparse.urlparse(uri).path
uris = mime.split_uri_list(data['DATA'])
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:
if data['ON_DISK']:
file_path = urlparse.urlparse(data['DATA']).path
transfer_ownership = False
mime_type = mime.get_for_file(file_path)
else:
f, file_path = tempfile.mkstemp()
try:
os.write(f, data['DATA'])
finally:
os.close(f)
file_path = self._write_to_temp_file(data['DATA'])
transfer_ownership = True
mime_type = mime.get_for_file(file_path)
jobject = datastore.create()
jobject.metadata['title'] = _('Clipboard object: %s.') % obj['NAME']
@ -202,7 +215,7 @@ class ClipboardMenu(Palette):
jobject.metadata['buddies'] = ''
jobject.metadata['preview'] = ''
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
datastore.write(jobject, transfer_ownership=transfer_ownership)

View File

@ -15,6 +15,7 @@
# Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
import logging
import urlparse
import gtk
import hippo
@ -77,17 +78,22 @@ class ClipboardPanelWindow(FrameWindow):
cb_service = clipboardservice.get_instance()
if selection.type == 'text/uri-list':
uris = selection.data.split('\n')
uris = selection.get_uris()
if len(uris) > 1:
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,
selection.type,
uris[0],
on_disk=True)
selection.type,
uri,
on_disk)
else:
cb_service.add_object_format(key,
selection.type,
selection.data,
on_disk=False)
selection.type,
selection.data,
on_disk=False)