Web   ·   Wiki   ·   Activities   ·   Blog   ·   Lists   ·   Chat   ·   Meeting   ·   Bugs   ·   Git   ·   Translate   ·   Archive   ·   People   ·   Donate
summaryrefslogtreecommitdiffstats
path: root/services
diff options
context:
space:
mode:
authorGuillaume Desmottes <guillaume.desmottes@collabora.co.uk>2007-03-15 09:54:21 (GMT)
committer Guillaume Desmottes <guillaume.desmottes@collabora.co.uk>2007-03-15 09:54:21 (GMT)
commit41bb49f6f66c437e906a515b950413e55208a60c (patch)
treea5c8939e2a9be5589ee31484d4e67e2d3d0b5126 /services
parenta16484bc7bc53d9a35317e395d7cc0a0e7574bea (diff)
parentb4e4b3875a5f31e79415dea17edf48744a5e4573 (diff)
Merge branch 'master' of git+ssh://guillaume@dev.laptop.org/git/sugar
Diffstat (limited to 'services')
-rw-r--r--services/clipboard/clipboardobject.py6
-rw-r--r--services/clipboard/clipboardservice.py41
2 files changed, 47 insertions, 0 deletions
diff --git a/services/clipboard/clipboardobject.py b/services/clipboard/clipboardobject.py
index af8ba5f..919acd0 100644
--- a/services/clipboard/clipboardobject.py
+++ b/services/clipboard/clipboardobject.py
@@ -54,3 +54,9 @@ class Format:
def get_data(self):
return self._data
+
+ def _set_data(self, data):
+ self._data = data
+
+ def get_on_disk(self):
+ return self._on_disk
diff --git a/services/clipboard/clipboardservice.py b/services/clipboard/clipboardservice.py
index 8fb0ff4..0ed423b 100644
--- a/services/clipboard/clipboardservice.py
+++ b/services/clipboard/clipboardservice.py
@@ -16,11 +16,14 @@
import logging
import gobject
+import os
+import shutil
import dbus
import dbus.service
from sugar import env
from sugar import util
from clipboardobject import ClipboardObject, Format
+import typeregistry
NAME_KEY = 'NAME'
PERCENT_KEY = 'PERCENT'
@@ -48,6 +51,34 @@ class ClipboardDBusServiceHelper(dbus.service.Object):
self._next_id += 1
return self._next_id
+ def _handle_file_completed(self, cb_object):
+ """If the object is an on-disk file, and it's at 100%, and we care about
+ it's file type, copy that file to $HOME and upate the clipboard object's
+ data to point to the new location"""
+ formats = cb_object.get_formats()
+ if not len(formats) or len(formats) > 1:
+ return
+
+ format = formats.values()[0]
+ if not format.get_on_disk():
+ return
+
+ if not len(cb_object.get_activity()):
+ # no activity to handle this, don't autosave it
+ return
+
+ # copy to homedir
+ src = format.get_data()
+ if not os.path.exists(src):
+ logging.debug("File %s doesn't appear to exist" % src)
+ return
+ dst = os.path.join(os.path.expanduser("~"), os.path.basename(src))
+ try:
+ shutil.move(src, dst)
+ format._set_data(dst)
+ except IOError, e:
+ logging.debug("Couldn't move file %s to %s: %s" % (src, dst, e))
+
# dbus methods
@dbus.service.method(_CLIPBOARD_DBUS_INTERFACE,
in_signature="s", out_signature="o")
@@ -88,7 +119,17 @@ class ClipboardDBusServiceHelper(dbus.service.Object):
cb_object = self._objects[str(object_path)]
if percent < 0 or percent > 100:
raise ValueError("invalid percentage")
+ if cb_object.get_percent() > percent:
+ raise ValueError("invalid percentage; less than current percent")
+ if cb_object.get_percent() == percent:
+ # ignore setting same percentage
+ return
+
cb_object.set_percent(percent)
+
+ if percent == 100:
+ self._handle_file_completed(cb_object)
+
self.object_state_changed(object_path, {NAME_KEY: cb_object.get_name(),
PERCENT_KEY: percent,
ICON_KEY: cb_object.get_icon(),