Merge branch 'master' of git+ssh://guillaume@dev.laptop.org/git/sugar

This commit is contained in:
Guillaume Desmottes 2007-03-15 10:54:21 +01:00
commit 41bb49f6f6
6 changed files with 96 additions and 12 deletions

View File

@ -1,6 +1,10 @@
#include <nsCExternalHandlerService.h>
#include <nsIFile.h>
#include <nsIFactory.h>
#include <nsILocalFile.h>
#include <nsStringAPI.h>
#include <nsComponentManagerUtils.h>
#include "GeckoContentHandler.h"
@ -30,15 +34,13 @@ NS_IMETHODIMP
GeckoContentHandler::Show (nsIHelperAppLauncher *aLauncher,
nsISupports *aContext,
PRUint32 aReason)
{
nsCOMPtr<nsIFile> tmpFile;
aLauncher->GetTargetFile(getter_AddRefs(tmpFile));
aLauncher->SaveToDisk (tmpFile, PR_FALSE);
{
aLauncher->SaveToDisk(NULL, PR_FALSE);
return NS_OK;
}
#include <glib.h>
NS_IMETHODIMP
GeckoContentHandler::PromptForSaveToFile (nsIHelperAppLauncher *aLauncher,
nsISupports *aWindowContext,
@ -46,6 +48,28 @@ GeckoContentHandler::PromptForSaveToFile (nsIHelperAppLauncher *aLauncher,
const PRUnichar *aSuggestedFileExtension,
nsILocalFile **_retval)
{
char *filename = NULL;
nsCString defaultFile;
NS_UTF16ToCString(nsString(aDefaultFile), NS_CSTRING_ENCODING_UTF8, defaultFile);
nsCOMPtr <nsILocalFile> destFile(do_CreateInstance(NS_LOCAL_FILE_CONTRACTID));
NS_ENSURE_TRUE(destFile, NS_ERROR_FAILURE);
const char * suggested = defaultFile.get();
if (strlen(suggested) > 0) {
filename = g_build_path("/", g_get_tmp_dir (), suggested, NULL);
} else {
filename = tempnam(NULL, NULL);
}
if (filename == NULL)
return NS_ERROR_OUT_OF_MEMORY;
destFile->InitWithNativePath(nsCString(filename));
g_free(filename);
NS_IF_ADDREF(*_retval = destFile);
return NS_OK;
}

View File

@ -534,6 +534,8 @@ sugar_browser_save_uri(SugarBrowser *browser,
rv = webPersist->SaveURI(sourceURI, nsnull, nsnull, nsnull, nsnull, destFile);
NS_ENSURE_SUCCESS(rv, FALSE);
return TRUE;
#else
return FALSE;
#endif
@ -584,6 +586,8 @@ sugar_browser_save_document(SugarBrowser *browser,
rv = webPersist->SaveDocument(DOMDocument, destFile, filesFolder, nsnull, 0, 0);
NS_ENSURE_SUCCESS(rv, FALSE);
return TRUE;
#else
return FALSE;
#endif

View File

@ -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

View File

@ -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(),

View File

@ -231,10 +231,10 @@ class IntroBox(hippo.CanvasBox, hippo.CanvasItem):
hippo.CanvasBox.__init__(self, **kwargs)
self._pixbuf = None
self._video_box = VideoBox(xalign=hippo.ALIGNMENT_CENTER,
yalign=hippo.ALIGNMENT_START,
padding_bottom=units.grid_to_pixels(0.5))
self.append(self._video_box)
#self._video_box = VideoBox(xalign=hippo.ALIGNMENT_CENTER,
# yalign=hippo.ALIGNMENT_START,
# padding_bottom=units.grid_to_pixels(0.5))
#self.append(self._video_box)
self._entry_box = EntryBox(xalign=hippo.ALIGNMENT_CENTER,
padding_bottom=units.grid_to_pixels(0.5))
@ -250,7 +250,10 @@ class IntroBox(hippo.CanvasBox, hippo.CanvasItem):
self.append(self._ok)
def _ok_activated(self, item):
pixbuf = self._video_box.get_pixbuf()
#pixbuf = self._video_box.get_pixbuf()
path = os.path.join(os.path.dirname(__file__),
'default-picture.png')
pixbuf = gtk.gdk.pixbuf_new_from_file(path)
name = self._entry_box.get_text()
color = self._color_box.get_color()

View File

@ -96,12 +96,18 @@ class ClipboardIcon(CanvasIcon):
else:
self.props.xo_color = XoColor("#000000,#FFFFFF")
if activity and percent == 100:
# FIXME: restrict based on file type rather than activity once
# we have a better type registry
# restrict auto-open to a specific set of activities
allowed = ["org.laptop.AbiWordActivity", "org.laptop.sugar.Xbook"]
if activity in allowed:
self._open_file()
def _open_file(self):
if self._percent < 100 or not self._activity:
return
logging.debug("_open_file: " + self._object_id)
# Get the file path
cb_service = clipboardservice.get_instance()
obj = cb_service.get_object(self._object_id)