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

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