[gnome-documents/gnome-3-24] documents: Implement the downloadImpl vfunc for SkydriveDocument



commit c6cc61e3c0f01a560869672a4f84c54632c0f897
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Mar 30 18:23:27 2017 +0200

    documents: Implement the downloadImpl vfunc for SkydriveDocument
    
    https://bugzilla.gnome.org/show_bug.cgi?id=774937

 src/documents.js |   56 ++++++++++++++++++++++++++++++++++++++++++++++++++++++
 1 files changed, 56 insertions(+), 0 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index 687772f..aed8368 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -1163,6 +1163,62 @@ const SkydriveDocument = new Lang.Class({
                  }));
     },
 
+    downloadImpl: function(localFile, cancellable, callback) {
+        this._createZpjEntry(cancellable, Lang.bind(this,
+            function(entry, service, error) {
+                if (error) {
+                    callback(false, error);
+                    return;
+                }
+
+                service.download_file_to_stream_async(entry, cancellable, Lang.bind(this,
+                    function(object, res) {
+                        let inputStream;
+
+                        try {
+                            inputStream = object.download_file_to_stream_finish(res);
+                        } 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._createZpjEntry(cancellable, Lang.bind(this,
             function(entry, service, exception) {


[Date Prev][Date Next]   [Thread Prev][Thread Next]   [Thread Index] [Date Index] [Author Index]