Add XdndDirectSave support to the clipboard.
I think it could be a little cleaner, but it would require refactoring, we can do that post Trial-3. Also we might have to figure out a way to get file saving progress feedback at some point.
This commit is contained in:
@@ -95,17 +95,21 @@ class ClipboardObject:
|
||||
|
||||
format = mime.choose_most_significant(self._formats.keys())
|
||||
|
||||
if format == 'text/uri-list':
|
||||
uri = None
|
||||
if format == 'XdndDirectSave0':
|
||||
uri = self._formats['XdndDirectSave0'].get_data()
|
||||
elif format == 'text/uri-list':
|
||||
data = self._formats['text/uri-list'].get_data()
|
||||
uris = data.split('\n')
|
||||
if len(uris) == 1 or not uris[1]:
|
||||
uri = urlparse.urlparse(uris[0], 'file')
|
||||
if uri.scheme == 'file':
|
||||
if os.path.exists(uri.path):
|
||||
format = mime.get_for_file(uri.path)
|
||||
else:
|
||||
format = mime.get_from_file_name(uri.path)
|
||||
logging.debug('Choosed %r!' % format)
|
||||
uri = data.split('\n')[0]
|
||||
|
||||
if uri:
|
||||
uri = urlparse.urlparse(uri, 'file')
|
||||
if uri.scheme == 'file':
|
||||
if os.path.exists(uri.path):
|
||||
format = mime.get_for_file(uri.path)
|
||||
else:
|
||||
format = mime.get_from_file_name(uri.path)
|
||||
logging.debug('Choosed %r!' % format)
|
||||
|
||||
return format
|
||||
|
||||
|
||||
@@ -75,7 +75,9 @@ class ClipboardService(dbus.service.Object):
|
||||
logging.debug('ClipboardService.add_object_format')
|
||||
cb_object = self._objects[str(object_path)]
|
||||
|
||||
if on_disk and cb_object.get_percent() == 100:
|
||||
if format_type == 'XdndDirectSave0':
|
||||
cb_object.add_format(Format(format_type, data, on_disk))
|
||||
elif on_disk and cb_object.get_percent() == 100:
|
||||
new_uri = self._copy_file(data)
|
||||
cb_object.add_format(Format(format_type, new_uri, on_disk))
|
||||
logging.debug('Added format of type ' + format_type + ' with path at ' + new_uri)
|
||||
@@ -114,7 +116,7 @@ class ClipboardService(dbus.service.Object):
|
||||
if percent == 100:
|
||||
formats = cb_object.get_formats()
|
||||
for format_name, format in formats.iteritems():
|
||||
if format.is_on_disk():
|
||||
if format.is_on_disk() and format_name != 'XdndDirectSave0':
|
||||
new_uri = self._copy_file(format.get_data())
|
||||
format.set_data(new_uri)
|
||||
|
||||
|
||||
Reference in New Issue
Block a user