Merge branch 'master' of git+ssh://guillaume@dev.laptop.org/git/sugar
This commit is contained in:
commit
41bb49f6f6
@ -1,6 +1,10 @@
|
|||||||
#include <nsCExternalHandlerService.h>
|
#include <nsCExternalHandlerService.h>
|
||||||
#include <nsIFile.h>
|
#include <nsIFile.h>
|
||||||
#include <nsIFactory.h>
|
#include <nsIFactory.h>
|
||||||
|
#include <nsILocalFile.h>
|
||||||
|
#include <nsStringAPI.h>
|
||||||
|
|
||||||
|
#include <nsComponentManagerUtils.h>
|
||||||
|
|
||||||
#include "GeckoContentHandler.h"
|
#include "GeckoContentHandler.h"
|
||||||
|
|
||||||
@ -31,14 +35,12 @@ GeckoContentHandler::Show (nsIHelperAppLauncher *aLauncher,
|
|||||||
nsISupports *aContext,
|
nsISupports *aContext,
|
||||||
PRUint32 aReason)
|
PRUint32 aReason)
|
||||||
{
|
{
|
||||||
nsCOMPtr<nsIFile> tmpFile;
|
aLauncher->SaveToDisk(NULL, PR_FALSE);
|
||||||
aLauncher->GetTargetFile(getter_AddRefs(tmpFile));
|
|
||||||
|
|
||||||
aLauncher->SaveToDisk (tmpFile, PR_FALSE);
|
|
||||||
|
|
||||||
return NS_OK;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
#include <glib.h>
|
||||||
NS_IMETHODIMP
|
NS_IMETHODIMP
|
||||||
GeckoContentHandler::PromptForSaveToFile (nsIHelperAppLauncher *aLauncher,
|
GeckoContentHandler::PromptForSaveToFile (nsIHelperAppLauncher *aLauncher,
|
||||||
nsISupports *aWindowContext,
|
nsISupports *aWindowContext,
|
||||||
@ -46,6 +48,28 @@ GeckoContentHandler::PromptForSaveToFile (nsIHelperAppLauncher *aLauncher,
|
|||||||
const PRUnichar *aSuggestedFileExtension,
|
const PRUnichar *aSuggestedFileExtension,
|
||||||
nsILocalFile **_retval)
|
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;
|
return NS_OK;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
@ -534,6 +534,8 @@ sugar_browser_save_uri(SugarBrowser *browser,
|
|||||||
|
|
||||||
rv = webPersist->SaveURI(sourceURI, nsnull, nsnull, nsnull, nsnull, destFile);
|
rv = webPersist->SaveURI(sourceURI, nsnull, nsnull, nsnull, nsnull, destFile);
|
||||||
NS_ENSURE_SUCCESS(rv, FALSE);
|
NS_ENSURE_SUCCESS(rv, FALSE);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
#else
|
#else
|
||||||
return FALSE;
|
return FALSE;
|
||||||
#endif
|
#endif
|
||||||
@ -584,6 +586,8 @@ sugar_browser_save_document(SugarBrowser *browser,
|
|||||||
|
|
||||||
rv = webPersist->SaveDocument(DOMDocument, destFile, filesFolder, nsnull, 0, 0);
|
rv = webPersist->SaveDocument(DOMDocument, destFile, filesFolder, nsnull, 0, 0);
|
||||||
NS_ENSURE_SUCCESS(rv, FALSE);
|
NS_ENSURE_SUCCESS(rv, FALSE);
|
||||||
|
|
||||||
|
return TRUE;
|
||||||
#else
|
#else
|
||||||
return FALSE;
|
return FALSE;
|
||||||
#endif
|
#endif
|
||||||
|
@ -54,3 +54,9 @@ class Format:
|
|||||||
|
|
||||||
def get_data(self):
|
def get_data(self):
|
||||||
return self._data
|
return self._data
|
||||||
|
|
||||||
|
def _set_data(self, data):
|
||||||
|
self._data = data
|
||||||
|
|
||||||
|
def get_on_disk(self):
|
||||||
|
return self._on_disk
|
||||||
|
@ -16,11 +16,14 @@
|
|||||||
|
|
||||||
import logging
|
import logging
|
||||||
import gobject
|
import gobject
|
||||||
|
import os
|
||||||
|
import shutil
|
||||||
import dbus
|
import dbus
|
||||||
import dbus.service
|
import dbus.service
|
||||||
from sugar import env
|
from sugar import env
|
||||||
from sugar import util
|
from sugar import util
|
||||||
from clipboardobject import ClipboardObject, Format
|
from clipboardobject import ClipboardObject, Format
|
||||||
|
import typeregistry
|
||||||
|
|
||||||
NAME_KEY = 'NAME'
|
NAME_KEY = 'NAME'
|
||||||
PERCENT_KEY = 'PERCENT'
|
PERCENT_KEY = 'PERCENT'
|
||||||
@ -48,6 +51,34 @@ class ClipboardDBusServiceHelper(dbus.service.Object):
|
|||||||
self._next_id += 1
|
self._next_id += 1
|
||||||
return self._next_id
|
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 methods
|
||||||
@dbus.service.method(_CLIPBOARD_DBUS_INTERFACE,
|
@dbus.service.method(_CLIPBOARD_DBUS_INTERFACE,
|
||||||
in_signature="s", out_signature="o")
|
in_signature="s", out_signature="o")
|
||||||
@ -88,7 +119,17 @@ class ClipboardDBusServiceHelper(dbus.service.Object):
|
|||||||
cb_object = self._objects[str(object_path)]
|
cb_object = self._objects[str(object_path)]
|
||||||
if percent < 0 or percent > 100:
|
if percent < 0 or percent > 100:
|
||||||
raise ValueError("invalid percentage")
|
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)
|
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(),
|
self.object_state_changed(object_path, {NAME_KEY: cb_object.get_name(),
|
||||||
PERCENT_KEY: percent,
|
PERCENT_KEY: percent,
|
||||||
ICON_KEY: cb_object.get_icon(),
|
ICON_KEY: cb_object.get_icon(),
|
||||||
|
@ -231,10 +231,10 @@ class IntroBox(hippo.CanvasBox, hippo.CanvasItem):
|
|||||||
hippo.CanvasBox.__init__(self, **kwargs)
|
hippo.CanvasBox.__init__(self, **kwargs)
|
||||||
self._pixbuf = None
|
self._pixbuf = None
|
||||||
|
|
||||||
self._video_box = VideoBox(xalign=hippo.ALIGNMENT_CENTER,
|
#self._video_box = VideoBox(xalign=hippo.ALIGNMENT_CENTER,
|
||||||
yalign=hippo.ALIGNMENT_START,
|
# yalign=hippo.ALIGNMENT_START,
|
||||||
padding_bottom=units.grid_to_pixels(0.5))
|
# padding_bottom=units.grid_to_pixels(0.5))
|
||||||
self.append(self._video_box)
|
#self.append(self._video_box)
|
||||||
|
|
||||||
self._entry_box = EntryBox(xalign=hippo.ALIGNMENT_CENTER,
|
self._entry_box = EntryBox(xalign=hippo.ALIGNMENT_CENTER,
|
||||||
padding_bottom=units.grid_to_pixels(0.5))
|
padding_bottom=units.grid_to_pixels(0.5))
|
||||||
@ -250,7 +250,10 @@ class IntroBox(hippo.CanvasBox, hippo.CanvasItem):
|
|||||||
self.append(self._ok)
|
self.append(self._ok)
|
||||||
|
|
||||||
def _ok_activated(self, item):
|
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()
|
name = self._entry_box.get_text()
|
||||||
color = self._color_box.get_color()
|
color = self._color_box.get_color()
|
||||||
|
|
||||||
|
@ -96,12 +96,18 @@ class ClipboardIcon(CanvasIcon):
|
|||||||
else:
|
else:
|
||||||
self.props.xo_color = XoColor("#000000,#FFFFFF")
|
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):
|
def _open_file(self):
|
||||||
if self._percent < 100 or not self._activity:
|
if self._percent < 100 or not self._activity:
|
||||||
return
|
return
|
||||||
|
|
||||||
logging.debug("_open_file: " + self._object_id)
|
|
||||||
|
|
||||||
# Get the file path
|
# Get the file path
|
||||||
cb_service = clipboardservice.get_instance()
|
cb_service = clipboardservice.get_instance()
|
||||||
obj = cb_service.get_object(self._object_id)
|
obj = cb_service.get_object(self._object_id)
|
||||||
|
Loading…
Reference in New Issue
Block a user