[gnome-documents/wip/rishi/onedrive-lo: 6/10] documents: Add property to denote the URI to be loaded by the preview



commit 28ce23ad437261092989d46c4d192ce74f511686
Author: Debarshi Ray <debarshir gnome org>
Date:   Thu Mar 30 17:25:44 2017 +0200

    documents: Add property to denote the URI to be loaded by the preview
    
    We want to open ODFs and OOXMLs from OneDrive using LOKDocView, not
    EvView. Therefore, the logic to convert a remote document into
    something that can be loaded by the different preview widgets can no
    longer be hidden inside GdPdfLoader. LOKDocView needs to know the URI
    it can load without hitting the network.
    
    For local and ownCloud this is the same as the actual URI because they
    are natively handled by GIO. The property is not defined for Google
    because it is still handled entirely by GdPdfLoader.
    
    This changes the caching for SkydriveDocuments. The old scheme was:
      ~/.cache/gnome-documents/gnome-documents-<g_str_hash(id)>.pdf
    The new structure is:
      ~/.cache/gnome-documents/skydrive/<SHA1(id)>.<original-extension>
    
    The new scheme namespaces each document type and uses a hash function
    that can be easily replicated by other tools for debugging. This is a
    good time to change this because we are about to invalidate existing
    caches by not using the ".pdf" extension for all SkydriveDocuments.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=774937

 src/documents.js |   24 +++++++++++++++++++++++-
 src/epubview.js  |    2 +-
 src/lokview.js   |    2 +-
 3 files changed, 25 insertions(+), 3 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index d31827a..d4c55d1 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -234,6 +234,7 @@ const DocCommon = new Lang.Class({
     _init: function(cursor) {
         this.id = null;
         this.uri = null;
+        this.uriToLoad = null;
         this.filename = null;
         this.name = null;
         this.author = null;
@@ -625,7 +626,7 @@ const DocCommon = new Lang.Class({
             return;
         }
 
-        GdPrivate.pdf_loader_load_uri_async(this.uri, passwd, cancellable, Lang.bind(this,
+        GdPrivate.pdf_loader_load_uri_async(this.uriToLoad, passwd, cancellable, Lang.bind(this,
             function(source, res) {
                 try {
                     let docModel = GdPrivate.pdf_loader_load_uri_finish(res);
@@ -751,6 +752,7 @@ const LocalDocument = new Lang.Class({
 
     populateFromCursor: function(cursor) {
         this.parent(cursor);
+        this.uriToLoad = this.uri;
 
         if (!Application.application.gettingStartedLocation)
             return;
@@ -1015,6 +1017,11 @@ const OwncloudDocument = new Lang.Class({
             this.defaultAppName = this.defaultApp.get_name();
     },
 
+    populateFromCursor: function(cursor) {
+        this.parent(cursor);
+        this.uriToLoad = this.uri;
+    },
+
     createThumbnail: function(callback) {
         GdPrivate.queue_thumbnail_job_for_file_async(this._file, Lang.bind(this,
             function(object, res) {
@@ -1075,6 +1082,21 @@ const SkydriveDocument = new Lang.Class({
         this.sourceName = _("OneDrive");
     },
 
+    populateFromCursor: function(cursor) {
+        this.parent(cursor);
+
+        let localDir = GLib.build_filenamev([GLib.get_user_cache_dir(), "gnome-documents", "skydrive"]);
+
+        let identifierHash = GLib.compute_checksum_for_string(GLib.ChecksumType.SHA1, this.identifier, -1);
+        let filenameStripped = GdPrivate.filename_strip_extension(this.filename);
+        let extension = this.filename.substring(filenameStripped.length);
+        let localFilename = identifierHash + extension;
+
+        let localPath = GLib.build_filenamev([localDir, localFilename]);
+        let localFile = Gio.File.new_for_path(localPath);
+        this.uriToLoad = localFile.get_uri();
+    },
+
     _createZpjEntry: function(cancellable, callback) {
         let source = Application.sourceManager.getItemById(this.resourceUrn);
 
diff --git a/src/epubview.js b/src/epubview.js
index c469b2d..8d2154c 100644
--- a/src/epubview.js
+++ b/src/epubview.js
@@ -82,7 +82,7 @@ const EPUBView = new Lang.Class({
     onLoadFinished: function(manager, doc) {
         this.parent(manager, doc);
 
-        let f = Gio.File.new_for_uri(doc.uri);
+        let f = Gio.File.new_for_uri(doc.uriToLoad);
         this._epubdoc = new Gepub.Doc({ path: f.get_path() });
         this._epubdoc.init(null);
 
diff --git a/src/lokview.js b/src/lokview.js
index 092adc5..988db96 100644
--- a/src/lokview.js
+++ b/src/lokview.js
@@ -148,7 +148,7 @@ const LOKView = new Lang.Class({
         if (!isAvailable())
             return;
         this._doc = doc;
-        this._lokview.open_document(doc.uri, '{}', null, Lang.bind(this, this._onDocumentOpened));
+        this._lokview.open_document(doc.uriToLoad, '{}', null, Lang.bind(this, this._onDocumentOpened));
         this._progressBar.show();
     },
 


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