Blame SOURCES/gnome-documents-skydrive-and-lok-fixes.patch

f41169
From 777c70d64c13e3a362a7f5516a9c1408a96999a8 Mon Sep 17 00:00:00 2001
f41169
From: Debarshi Ray <debarshir@gnome.org>
f41169
Date: Wed, 6 Jun 2018 13:04:47 +0200
f41169
Subject: [PATCH 1/2] documents: Thumbnail PDF SkydriveDocuments once loaded
f41169
MIME-Version: 1.0
f41169
Content-Type: text/plain; charset=UTF-8
f41169
Content-Transfer-Encoding: 8bit
f41169
f41169
Historically, unlike GoogleDocuments, we were unable to fetch
f41169
server-side thumbnails for SkydriveDocuments due to limitations of
f41169
OneDrive's REST API. Newer versions of the REST API do support it [1],
f41169
but it is not implemented in libzapojit.
f41169
f41169
To work around those limitations, we try to use a cached copy of the
f41169
document as source for the thumbnail. Since a cached copy is likely to
f41169
be present right after a document has been loaded, we retry the
f41169
thumbnailing if we hadn't succeeded before.
f41169
f41169
Even if we can fetch thumbnails from the server in future, these would
f41169
still be nice optimizations to have — reduces network consumption and
f41169
offers a cheap way to jump ahead in the thumbnailing queue.
f41169
f41169
[1] https://dev.onedrive.com/items/thumbnails.htm
f41169
f41169
https://bugzilla.gnome.org/show_bug.cgi?id=780613
f41169
---
f41169
 src/documents.js | 104 +++++++++++++++++++++++++++++++++++++++++++++++++++++--
f41169
 1 file changed, 102 insertions(+), 2 deletions(-)
f41169
f41169
diff --git a/src/documents.js b/src/documents.js
f41169
index a4a580f39d63..823cfabd74c3 100644
f41169
--- a/src/documents.js
f41169
+++ b/src/documents.js
f41169
@@ -447,7 +447,16 @@ const DocCommon = new Lang.Class({
f41169
                                             return;
f41169
                                         }
f41169
 
f41169
-                                        this.loadLocal(passwd, cancellable, callback);
f41169
+                                        this.loadLocal(passwd, cancellable, Lang.bind(this,
f41169
+                                            function(doc, docModel, error) {
f41169
+                                                if (error) {
f41169
+                                                    callback(this, null, error);
f41169
+                                                    return;
f41169
+                                                }
f41169
+
f41169
+                                                callback(this, docModel, null);
f41169
+                                                this.postLoad(docModel);
f41169
+                                            }));
f41169
                                     }));
f41169
                             } else {
f41169
                                 callback(this, null, error);
f41169
@@ -457,10 +466,14 @@ const DocCommon = new Lang.Class({
f41169
                         }
f41169
 
f41169
                         callback(this, docModel, null);
f41169
+                        this.postLoad(docModel);
f41169
                     }));
f41169
             }));
f41169
     },
f41169
 
f41169
+    postLoad: function(docModel) {
f41169
+    },
f41169
+
f41169
     canEdit: function() {
f41169
         throw(new Error('DocCommon implementations must override canEdit'));
f41169
     },
f41169
@@ -1299,7 +1312,7 @@ const SkydriveDocument = new Lang.Class({
f41169
     Extends: DocCommon,
f41169
 
f41169
     _init: function(cursor) {
f41169
-        this._failedThumbnailing = true;
f41169
+        this._failedThumbnailing = false;
f41169
 
f41169
         this.parent(cursor);
f41169
 
f41169
@@ -1323,6 +1336,54 @@ const SkydriveDocument = new Lang.Class({
f41169
         this.uriToLoad = localFile.get_uri();
f41169
     },
f41169
 
f41169
+    _createThumbnailFromEvDocument: function(evDoc, cancellable, callback) {
f41169
+        let thumbnailPath = GnomeDesktop.desktop_thumbnail_path_for_uri (this.uri,
f41169
+                                                                         GnomeDesktop.DesktopThumbnailSize.LARGE);
f41169
+        let thumbnailFile = Gio.File.new_for_path(thumbnailPath);
f41169
+
f41169
+        let thumbnailDir = GLib.path_get_dirname(thumbnailPath);
f41169
+        GLib.mkdir_with_parents(thumbnailDir, 448);
f41169
+
f41169
+        thumbnailFile.replace_async(null,
f41169
+                                    false,
f41169
+                                    Gio.FileCreateFlags.PRIVATE,
f41169
+                                    GLib.PRIORITY_DEFAULT,
f41169
+                                    cancellable,
f41169
+                                    Lang.bind(this,
f41169
+            function(source, res) {
f41169
+                let outputStream;
f41169
+
f41169
+                try {
f41169
+                    outputStream = thumbnailFile.replace_finish(res);
f41169
+                } catch (e) {
f41169
+                    callback(e);
f41169
+                    return;
f41169
+                }
f41169
+
f41169
+                let [width, height] = evDoc.get_page_size(0);
f41169
+                let maxDimension = Math.max(width, height);
f41169
+                let scale = Application.application.getScaleFactor();
f41169
+                let size = 128 * scale;
f41169
+                let zoom = size / maxDimension;
f41169
+
f41169
+                let page = evDoc.get_page(0);
f41169
+
f41169
+                let rc = EvDocument.RenderContext.new(page, 0, zoom);
f41169
+                let pixbuf = evDoc.get_thumbnail(rc);
f41169
+                pixbuf.save_to_streamv_async(outputStream, "png", [], [], cancellable, Lang.bind(this,
f41169
+                    function(source, res) {
f41169
+                        try {
f41169
+                            GdkPixbuf.Pixbuf.save_to_stream_finish(res);
f41169
+                        } catch (e) {
f41169
+                            callback(e);
f41169
+                            return;
f41169
+                        }
f41169
+
f41169
+                        callback(null);
f41169
+                    }));
f41169
+            }));
f41169
+    },
f41169
+
f41169
     _createZpjEntry: function(cancellable, callback) {
f41169
         let source = Application.sourceManager.getItemById(this.resourceUrn);
f41169
 
f41169
@@ -1405,6 +1466,45 @@ const SkydriveDocument = new Lang.Class({
f41169
             }));
f41169
     },
f41169
 
f41169
+    postLoad: function(docModel) {
f41169
+        if (this._thumbPath)
f41169
+            return;
f41169
+
f41169
+        this._failedThumbnailing = false;
f41169
+        this.refreshIcon();
f41169
+    },
f41169
+
f41169
+    createThumbnail: function(callback) {
f41169
+        // try loading from the most recent cache, if any
f41169
+        this.loadLocal(null, null, Lang.bind(this,
f41169
+            function(doc, docModel, error) {
f41169
+                if (error) {
f41169
+                    if (!error.matches(Gio.IOErrorEnum, Gio.IOErrorEnum.NOT_FOUND) &&
f41169
+                        !error.matches(EvDocument.DocumentError, EvDocument.DocumentError.ENCRYPTED)) {
f41169
+                        logError(error, 'Unable to load document from the cache');
f41169
+                        callback(false);
f41169
+                        return;
f41169
+                    }
f41169
+                }
f41169
+
f41169
+                if (!docModel) {
f41169
+                    callback(false);
f41169
+                    return;
f41169
+                }
f41169
+
f41169
+                this._createThumbnailFromEvDocument(docModel.document, null, Lang.bind(this,
f41169
+                    function(error) {
f41169
+                        if (error) {
f41169
+                            logError(error, 'Unable to create thumbnail from EvDocument');
f41169
+                            callback(false);
f41169
+                            return;
f41169
+                        }
f41169
+
f41169
+                        callback(true);
f41169
+                    }));
f41169
+            }));
f41169
+    },
f41169
+
f41169
     updateTypeDescription: function() {
f41169
         let description;
f41169
 
f41169
-- 
f41169
2.14.4
f41169
f41169
f41169
From 8591dcde011558c26c789c010f5b78cd806cf34b Mon Sep 17 00:00:00 2001
f41169
From: =?UTF-8?q?Caol=C3=A1n=20McNamara?= <caolanm@redhat.com>
f41169
Date: Mon, 8 May 2017 16:44:32 +0100
f41169
Subject: [PATCH 2/2] lokview: Fix crash on repeated open of presentations
f41169
f41169
Ensure prompt destruction of the LOKDocView widget when the view is
f41169
destroyed. This gives LOK a chance to shutdown at the right time.
f41169
f41169
https://bugzilla.gnome.org/show_bug.cgi?id=782508
f41169
---
f41169
 src/lokview.js | 12 ++++++++++--
f41169
 1 file changed, 10 insertions(+), 2 deletions(-)
f41169
f41169
diff --git a/src/lokview.js b/src/lokview.js
f41169
index dfa0b9628735..49bacabd28e7 100644
f41169
--- a/src/lokview.js
f41169
+++ b/src/lokview.js
f41169
@@ -139,11 +139,19 @@ var LOKView = new Lang.Class({
f41169
             this._lokview.connect('text-selection', Lang.bind(this, this._onTextSelection));
f41169
             this._lokview.connect('notify::can-zoom-in', Lang.bind(this, this._onCanZoomInChanged));
f41169
             this._lokview.connect('notify::can-zoom-out', Lang.bind(this, this._onCanZoomOutChanged));
f41169
+            this.connect('destroy', Lang.bind(this, this._destroyView));
f41169
         }
f41169
 
f41169
         return sw;
f41169
     },
f41169
 
f41169
+    _destroyView: function() {
f41169
+	if (this._lokview) {
f41169
+	    this._lokview.destroy();
f41169
+	    this._lokview = null;
f41169
+	}
f41169
+    },
f41169
+
f41169
     onLoadFinished: function(manager, doc) {
f41169
         this.parent(manager, doc);
f41169
 
f41169
@@ -239,10 +247,10 @@ var LOKView = new Lang.Class({
f41169
     },
f41169
 
f41169
     get page() {
f41169
-        return this._lokview.get_part();
f41169
+        return this._lokview ? this._lokview.get_part() : 0;
f41169
     },
f41169
 
f41169
     get numPages() {
f41169
-        return this._lokview.get_parts();
f41169
+        return this._lokview ? this._lokview.get_parts() : 0;
f41169
     }
f41169
 });
f41169
-- 
f41169
2.14.4
f41169