Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/shell
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@tomeuvizoso.net>2007-12-05 17:10:34 (GMT)
committer Tomeu Vizoso <tomeu@tomeuvizoso.net>2007-12-05 17:10:34 (GMT)
commitf0d194f3fba770807ac3bc7dbb3d5ff3fcfa4fce (patch)
treefd6f7cb7d06b4ed84a00283889e0dba4349ac2fe /shell
parentdc8809cdc6def6ea6a0bf1d1a01534fb980cbfbe (diff)
#5080: Clipboard fixes for sharing of URIs.
Diffstat (limited to 'shell')
-rw-r--r--shell/view/clipboardmenu.py31
-rw-r--r--shell/view/frame/clipboardpanelwindow.py20
2 files changed, 35 insertions, 16 deletions
diff --git a/shell/view/clipboardmenu.py b/shell/view/clipboardmenu.py
index 623de31..b847828 100644
--- a/shell/view/clipboardmenu.py
+++ b/shell/view/clipboardmenu.py
@@ -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)
diff --git a/shell/view/frame/clipboardpanelwindow.py b/shell/view/frame/clipboardpanelwindow.py
index b492e78..e579b8c 100644
--- a/shell/view/frame/clipboardpanelwindow.py
+++ b/shell/view/frame/clipboardpanelwindow.py
@@ -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)