[gnome-documents/wip/lokdocview-rebase: 4/10] documents: Share the code between ownCloud and local backends



commit af94621c2963f764e3781ae578f3fa7d58d8c892
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Dec 4 19:06:32 2015 +0100

    documents: Share the code between ownCloud and local backends
    
    Because they both load files through GIO/gvfs mounted filesystems. This
    means that we should now be able to load LibreOffice documents from
    ownCloud.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=753686

 src/documents.js |   76 +++++++++++++++++++++++++----------------------------
 1 files changed, 36 insertions(+), 40 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index 16712c2..235ce92 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -592,6 +592,40 @@ const DocCommon = new Lang.Class({
         Application.searchCategoryManager.disconnect(this._filterId);
     },
 
+    loadLocal: function(passwd, cancellable, callback) {
+        if (this.mimeType == 'application/epub+zip' ||
+            this.mimeType == 'application/x-mobipocket-ebook' ||
+            this.mimeType == 'application/x-fictionbook+xml' ||
+            this.mimeType == 'application/x-zip-compressed-fb2') {
+            let exception = new GLib.Error(Gio.IOErrorEnum,
+                                           Gio.IOErrorEnum.NOT_SUPPORTED,
+                                           "Internal error: Ebooks preview isn't support yet");
+            callback(this, null, exception);
+            return;
+        }
+
+        if (LOKView.isOpenDocumentFormat(this.mimeType) && !Application.application.isBooks) {
+            let exception = null;
+            if (!LOKView.isAvailable()) {
+                exception = new GLib.Error(Gio.IOErrorEnum,
+                                           Gio.IOErrorEnum.NOT_SUPPORTED,
+                                           "Internal error: LibreOffice isn't available");
+            }
+            callback (this, null, exception);
+            return;
+        }
+
+        GdPrivate.pdf_loader_load_uri_async(this.uri, passwd, cancellable, Lang.bind(this,
+            function(source, res) {
+                try {
+                    let docModel = GdPrivate.pdf_loader_load_uri_finish(res);
+                    callback(this, docModel, null);
+                } catch (e) {
+                    callback(this, null, e);
+                }
+            }));
+    },
+
     open: function(screen, timestamp) {
         if (!this.defaultAppName)
             return;
@@ -743,37 +777,7 @@ const LocalDocument = new Lang.Class({
     },
 
     load: function(passwd, cancellable, callback) {
-        if (this.mimeType == 'application/epub+zip' ||
-            this.mimeType == 'application/x-mobipocket-ebook' ||
-            this.mimeType == 'application/x-fictionbook+xml' ||
-            this.mimeType == 'application/x-zip-compressed-fb2') {
-            let exception = new GLib.Error(Gio.IOErrorEnum,
-                                           Gio.IOErrorEnum.NOT_SUPPORTED,
-                                           "Internal error: Ebooks preview isn't support yet");
-            callback(this, null, exception);
-            return;
-        }
-
-        if (LOKView.isOpenDocumentFormat(this.mimeType) && !Application.application.isBooks) {
-            let exception = null;
-            if (!LOKView.isAvailable()) {
-                exception = new GLib.Error(Gio.IOErrorEnum,
-                                           Gio.IOErrorEnum.NOT_SUPPORTED,
-                                           "Internal error: LibreOffice isn't available");
-            }
-            callback (this, null, exception);
-            return;
-        }
-
-        GdPrivate.pdf_loader_load_uri_async(this.uri, passwd, cancellable, Lang.bind(this,
-            function(source, res) {
-                try {
-                    let docModel = GdPrivate.pdf_loader_load_uri_finish(res);
-                    callback(this, docModel, null);
-                } catch (e) {
-                    callback(this, null, e);
-                }
-            }));
+        this.loadLocal(passwd, cancellable, callback);
     },
 
     canEdit: function() {
@@ -1025,15 +1029,7 @@ const OwncloudDocument = new Lang.Class({
     },
 
     load: function(passwd, cancellable, callback) {
-        GdPrivate.pdf_loader_load_uri_async(this.uri, passwd, cancellable, Lang.bind(this,
-            function(source, res) {
-                try {
-                    let docModel = GdPrivate.pdf_loader_load_uri_finish(res);
-                    callback(this, docModel, null);
-                } catch (e) {
-                    callback(this, null, e);
-                }
-            }));
+        this.loadLocal(passwd, cancellable, callback);
     },
 
     canEdit: function() {


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