From b97edec4db98c0b01283e5e4ff944ca219dd3733 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 14 Mar 2007 10:06:45 -0400 Subject: [PATCH 1/8] Remove picture selection from intro screen for now --- shell/intro/intro.py | 28 +++++++++++++++++----------- 1 file changed, 17 insertions(+), 11 deletions(-) diff --git a/shell/intro/intro.py b/shell/intro/intro.py index cdcc2a3d..d32810b5 100644 --- a/shell/intro/intro.py +++ b/shell/intro/intro.py @@ -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,15 +250,21 @@ 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() name = self._entry_box.get_text() color = self._color_box.get_color() - if not pixbuf or not name or not color: - print "not one of pixbuf(%r), name(%r), or color(%r)" + #if not pixbuf or not name or not color: + # print "Missing a picture (%r), name (%r), or color (%r)" % (pixbuf, name, color) + if not name: + print "Please pick a nickname" + return + if not color: + print "Please pick a color" return - self.emit('ok', pixbuf, name, color) + #self.emit('ok', pixbuf, name, color) + self.emit('ok', None, name, color) class IntroWindow(gtk.Window): @@ -286,9 +292,9 @@ class IntroWindow(gtk.Window): def _create_profile(self, pixbuf, name, color): # Save the buddy icon - icon_path = os.path.join(env.get_profile_path(), "buddy-icon.jpg") - scaled = pixbuf.scale_simple(200, 200, gtk.gdk.INTERP_BILINEAR) - pixbuf.save(icon_path, "jpeg", {"quality":"85"}) + #icon_path = os.path.join(env.get_profile_path(), "buddy-icon.jpg") + #scaled = pixbuf.scale_simple(200, 200, gtk.gdk.INTERP_BILINEAR) + #pixbuf.save(icon_path, "jpeg", {"quality":"85"}) cp = ConfigParser() section = 'Buddy' From 6ab478c6cd91dea2127f0ec1608fc0dd0d49e00a Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 14 Mar 2007 10:09:41 -0400 Subject: [PATCH 2/8] Validate percentage before setting it --- services/clipboard/clipboardservice.py | 5 +++++ 1 file changed, 5 insertions(+) diff --git a/services/clipboard/clipboardservice.py b/services/clipboard/clipboardservice.py index 8fb0ff4f..bd932c5b 100644 --- a/services/clipboard/clipboardservice.py +++ b/services/clipboard/clipboardservice.py @@ -88,6 +88,11 @@ 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) self.object_state_changed(object_path, {NAME_KEY: cb_object.get_name(), PERCENT_KEY: percent, From ca5ff6974e05cee95ff32cfb3fb91a43bbec1a7a Mon Sep 17 00:00:00 2001 From: Tomeu Vizoso Date: Wed, 14 Mar 2007 16:42:07 +0100 Subject: [PATCH 3/8] Return TRUE on success. --- lib/src/sugar-browser.cpp | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/lib/src/sugar-browser.cpp b/lib/src/sugar-browser.cpp index 80efa683..8bf5878f 100644 --- a/lib/src/sugar-browser.cpp +++ b/lib/src/sugar-browser.cpp @@ -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 From 653191806fc3739819773df050b2682026524009 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 14 Mar 2007 13:04:10 -0400 Subject: [PATCH 4/8] Copy interesting files to /home/dcbw after download --- services/clipboard/clipboardobject.py | 6 +++++ services/clipboard/clipboardservice.py | 36 ++++++++++++++++++++++++++ 2 files changed, 42 insertions(+) diff --git a/services/clipboard/clipboardobject.py b/services/clipboard/clipboardobject.py index af8ba5f9..919acd00 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 bd932c5b..0ed423b5 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") @@ -93,7 +124,12 @@ class ClipboardDBusServiceHelper(dbus.service.Object): 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(), From b35e6b6f2bb6a65ee00e8fe32ace346ea056dc1f Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 14 Mar 2007 13:15:39 -0400 Subject: [PATCH 5/8] Respect suggested name when downloading files --- lib/src/GeckoContentHandler.cpp | 34 ++++++++++++++++++++++++++++----- 1 file changed, 29 insertions(+), 5 deletions(-) diff --git a/lib/src/GeckoContentHandler.cpp b/lib/src/GeckoContentHandler.cpp index c3785cfc..39031852 100644 --- a/lib/src/GeckoContentHandler.cpp +++ b/lib/src/GeckoContentHandler.cpp @@ -1,6 +1,10 @@ #include #include #include +#include +#include + +#include #include "GeckoContentHandler.h" @@ -30,15 +34,13 @@ NS_IMETHODIMP GeckoContentHandler::Show (nsIHelperAppLauncher *aLauncher, nsISupports *aContext, PRUint32 aReason) -{ - nsCOMPtr tmpFile; - aLauncher->GetTargetFile(getter_AddRefs(tmpFile)); - - aLauncher->SaveToDisk (tmpFile, PR_FALSE); +{ + aLauncher->SaveToDisk(NULL, PR_FALSE); return NS_OK; } +#include 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 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; } From 93e9d164c0ada98212a37da2c17bd640261561bb Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 14 Mar 2007 14:43:42 -0400 Subject: [PATCH 6/8] Auto-open some downloaded files --- shell/view/clipboardicon.py | 10 ++++++++-- 1 file changed, 8 insertions(+), 2 deletions(-) diff --git a/shell/view/clipboardicon.py b/shell/view/clipboardicon.py index 37329904..5e941f67 100644 --- a/shell/view/clipboardicon.py +++ b/shell/view/clipboardicon.py @@ -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) From f2dcadaff56142a6072fa1495a07d478bf7fc927 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 14 Mar 2007 14:43:53 -0400 Subject: [PATCH 7/8] Revert "Remove picture selection from intro screen for now" This reverts commit b97edec4db98c0b01283e5e4ff944ca219dd3733. --- shell/intro/intro.py | 28 +++++++++++----------------- 1 file changed, 11 insertions(+), 17 deletions(-) diff --git a/shell/intro/intro.py b/shell/intro/intro.py index d32810b5..cdcc2a3d 100644 --- a/shell/intro/intro.py +++ b/shell/intro/intro.py @@ -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,21 +250,15 @@ 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() name = self._entry_box.get_text() color = self._color_box.get_color() - #if not pixbuf or not name or not color: - # print "Missing a picture (%r), name (%r), or color (%r)" % (pixbuf, name, color) - if not name: - print "Please pick a nickname" - return - if not color: - print "Please pick a color" + if not pixbuf or not name or not color: + print "not one of pixbuf(%r), name(%r), or color(%r)" return - #self.emit('ok', pixbuf, name, color) - self.emit('ok', None, name, color) + self.emit('ok', pixbuf, name, color) class IntroWindow(gtk.Window): @@ -292,9 +286,9 @@ class IntroWindow(gtk.Window): def _create_profile(self, pixbuf, name, color): # Save the buddy icon - #icon_path = os.path.join(env.get_profile_path(), "buddy-icon.jpg") - #scaled = pixbuf.scale_simple(200, 200, gtk.gdk.INTERP_BILINEAR) - #pixbuf.save(icon_path, "jpeg", {"quality":"85"}) + icon_path = os.path.join(env.get_profile_path(), "buddy-icon.jpg") + scaled = pixbuf.scale_simple(200, 200, gtk.gdk.INTERP_BILINEAR) + pixbuf.save(icon_path, "jpeg", {"quality":"85"}) cp = ConfigParser() section = 'Buddy' From b4e4b3875a5f31e79415dea17edf48744a5e4573 Mon Sep 17 00:00:00 2001 From: Dan Williams Date: Wed, 14 Mar 2007 14:44:58 -0400 Subject: [PATCH 8/8] Better removal of intro video chooser --- shell/intro/intro.py | 13 ++++++++----- 1 file changed, 8 insertions(+), 5 deletions(-) diff --git a/shell/intro/intro.py b/shell/intro/intro.py index cdcc2a3d..5b45ec29 100644 --- a/shell/intro/intro.py +++ b/shell/intro/intro.py @@ -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()