Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorTomeu Vizoso <tomeu@tomeuvizoso.net>2007-06-21 11:07:11 (GMT)
committer Tomeu Vizoso <tomeu@tomeuvizoso.net>2007-06-21 11:07:11 (GMT)
commit427e9a00d739452482f4e53bd0744702933c0d1a (patch)
tree6a56f2af11f1a1aed08f8e73a4935e8a9e788458
parent3ebb8f129193dfe1bd6e5fa7edd4d5a78d650423 (diff)
Add extension to files that come into the clipboard without one.
-rw-r--r--services/clipboard/clipboardobject.py10
-rw-r--r--shell/view/frame/clipboardbox.py6
-rw-r--r--sugar/objects/mime.py18
3 files changed, 29 insertions, 5 deletions
diff --git a/services/clipboard/clipboardobject.py b/services/clipboard/clipboardobject.py
index faca452..f4e6617 100644
--- a/services/clipboard/clipboardobject.py
+++ b/services/clipboard/clipboardobject.py
@@ -97,11 +97,11 @@ class ClipboardObject:
if 'text/uri-list' in self._formats.keys():
data = self._formats['text/uri-list'].get_data()
uris = data.split('\n')
- # TODO: could we do better when there are several uris?
- uri = urlparse.urlparse(uris[0], 'file')
- if uri.scheme == 'file':
- logging.debug('Choosed %r!' % mime.get_for_file(uri.path))
- return mime.get_for_file(uri.path)
+ if len(uris) == 1 or not uris[1]:
+ uri = urlparse.urlparse(uris[0], 'file')
+ if uri.scheme == 'file':
+ logging.debug('Choosed %r!' % mime.get_for_file(uri.path))
+ return mime.get_for_file(uri.path)
for mime_category in ['image/', 'text/', 'application/']:
for mime_type in self._formats.keys():
diff --git a/shell/view/frame/clipboardbox.py b/shell/view/frame/clipboardbox.py
index 1eb1684..3bef447 100644
--- a/shell/view/frame/clipboardbox.py
+++ b/shell/view/frame/clipboardbox.py
@@ -22,6 +22,7 @@ import hippo
import gtk
from sugar import util
+from sugar.objects import mime
from view.clipboardicon import ClipboardIcon
from sugar.clipboard import clipboardservice
@@ -104,6 +105,11 @@ class ClipboardBox(hippo.CanvasBox):
uri = urlparse.urlparse(uris[0])
path, file_name = os.path.split(uri.path)
+ root, ext = os.path.splitext(file_name)
+ if not ext or ext == '.':
+ mime_type = mime.get_for_file(uri.path)
+ file_name = root + '.' + mime.get_primary_extension(mime_type)
+
# Copy the file, as it will be deleted when the dnd operation finishes.
new_file_path = os.path.join(path, 'cb' + file_name)
shutil.copyfile(uri.path, new_file_path)
diff --git a/sugar/objects/mime.py b/sugar/objects/mime.py
index b50ada4..0030e53 100644
--- a/sugar/objects/mime.py
+++ b/sugar/objects/mime.py
@@ -9,3 +9,21 @@ def get_for_file(file_name):
def get_from_file_name(file_name):
return _sugarext.get_mime_type_from_file_name(file_name)
+
+_extensions_cache = {}
+def get_primary_extension(mime_type):
+ if _extensions_cache.has_key(mime_type):
+ return _extensions_cache[mime_type]
+
+ f = open('/etc/mime.types')
+ while True:
+ line = f.readline()
+ cols = line.replace('\t', ' ').split(' ')
+ if mime_type == cols[0]:
+ for col in cols[1:]:
+ if col:
+ _extensions_cache[mime_type] = col
+ return col
+
+ _extensions_cache[mime_type] = None
+ return None