[gnome-documents/wip/rishi/onedrive: 7/11] documents: Implement downloadImpl for GoogleDocument



commit f432801ebcd9f8587a55d81a4839190c16b517a9
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 93c8e8f..399b62d 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]