[gnome-documents] documents: Implement downloadImpl for GoogleDocument



commit f873026160b083bc709ff55cc0c921b284edb33c
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.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=781032

 src/documents.js |   53 +++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 53 insertions(+), 0 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index eb4d41b..4e88acd 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -922,6 +922,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]