[gnome-documents/wip/rishi/onedrive: 9/11] documents: Implement downloadImpl for GoogleDocument
- From: Debarshi Ray <debarshir src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents/wip/rishi/onedrive: 9/11] documents: Implement downloadImpl for GoogleDocument
- Date: Wed, 5 Apr 2017 15:26:30 +0000 (UTC)
commit 6085ebd2875cf352dd8d539136d3c5b4421c94c5
Author: Debarshi Ray <debarshir gnome org>
Date: Wed Apr 5 17:17:59 2017 +0200
documents: Implement downloadImpl for GoogleDocument
This will let us use the new JavaScript-based download and caching
implementation and reduce our reliance on GdPdfLoader.
src/documents.js | 53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
1 files changed, 53 insertions(+), 0 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index c95abeb..d2fed31 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -930,6 +930,59 @@ const GoogleDocument = new Lang.Class({
}));
},
+ downloadImpl: function(localFile, cancellable, callback) {
+ this.createGDataEntry(cancellable, Lang.bind(this,
+ function(entry, service, error) {
+ if (error) {
+ callback(false, error);
+ return;
+ }
+
+ let inputStream;
+
+ try {
+ inputStream = entry.download(service, "pdf", cancellable);
+ } catch(e) {
+ callback(false, e);
+ return;
+ }
+
+ localFile.replace_async(null,
+ false,
+ Gio.FileCreateFlags.PRIVATE,
+ GLib.PRIORITY_DEFAULT,
+ cancellable,
+ Lang.bind(this,
+ function(object, res) {
+ let outputStream;
+
+ try {
+ outputStream = object.replace_finish(res);
+ } catch (e) {
+ callback(false, e);
+ return;
+ }
+
+ outputStream.splice_async(inputStream,
+ Gio.OutputStreamSpliceFlags.CLOSE_SOURCE |
+ Gio.OutputStreamSpliceFlags.CLOSE_TARGET,
+ GLib.PRIORITY_DEFAULT,
+ cancellable,
+ Lang.bind(this,
+ function(object, res) {
+ try {
+ object.splice_finish(res);
+ } catch (e) {
+ callback(false, e);
+ return;
+ }
+
+ callback(false, null);
+ }));
+ }));
+ }))
+ },
+
load: function(passwd, cancellable, callback) {
this.createGDataEntry(cancellable, Lang.bind(this,
function(entry, service, exception) {
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]