[gnome-documents/wip/lokdocview-rebase: 3/7] Start loading LO documents when load-started is emitted



commit 94a3368499919b19865588af3e4f711672a81ca2
Author: Bastien Nocera <hadess hadess net>
Date:   Sun Dec 6 15:36:06 2015 +0100

    Start loading LO documents when load-started is emitted
    
    ... and make sure that each view only reacts to signals for documents
    that they are meant to handle.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=753686

 src/documents.js |   18 ++++++++++++++++++
 src/embed.js     |   36 ++++++++++++++++++++++--------------
 src/lokview.js   |   23 ++++++++++-------------
 src/preview.js   |    7 ++++++-
 4 files changed, 56 insertions(+), 28 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index 235ce92..faac2cb 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -45,6 +45,13 @@ const Search = imports.search;
 const TrackerUtils = imports.trackerUtils;
 const Utils = imports.utils;
 
+// Those are the per-document-type views
+const ViewType = {
+    NONE: 0,
+    EV: 1,
+    LOK: 2
+};
+
 const DeleteItemJob = new Lang.Class({
     Name: 'DeleteItemJob',
 // deletes the given resource
@@ -234,6 +241,7 @@ const DocCommon = new Lang.Class({
         this.origPixbuf = null;
         this.defaultApp = null;
         this.defaultAppName = null;
+        this.viewType = ViewType.NONE;
 
         this.mimeType = null;
         this.rdfType = null;
@@ -693,6 +701,14 @@ const DocCommon = new Lang.Class({
         log('Error: DocCommon implementations must override getSourceLink');
     },
 
+    updateViewType: function() {
+        if (LOKView.isOpenDocumentFormat(this.mimeType) && !Application.application.isBooks) {
+            this.viewType = ViewType.LOK;
+        } else {
+            this.viewType = ViewType.EV;
+        }
+    },
+
     getWhere: function() {
         let retval = '';
 
@@ -1392,6 +1408,7 @@ const DocumentManager = new Lang.Class({
         this._clearActiveDocModel();
 
         this._loaderCancellable = new Gio.Cancellable();
+        doc.updateViewType();
         this.emit('load-started', doc);
         doc.load(passwd, this._loaderCancellable, Lang.bind(this, this._onDocumentLoaded));
     },
@@ -1450,6 +1467,7 @@ const DocumentManager = new Lang.Class({
             recentManager.add_item(doc.uri);
 
             this._loaderCancellable = new Gio.Cancellable();
+            doc.updateViewType();
             this.emit('load-started', doc);
             doc.load(null, this._loaderCancellable, Lang.bind(this, this._onDocumentLoaded));
         }
diff --git a/src/embed.js b/src/embed.js
index 772e632..e1f3226 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -358,23 +358,31 @@ const Embed = new Lang.Class({
     },
 
     _onLoadFinished: function(manager, doc, docModel) {
-        if (doc && docModel) {
-            if (Application.application.isBooks)
-                docModel.set_sizing_mode(EvView.SizingMode.FIT_PAGE);
-            else
-                docModel.set_sizing_mode(EvView.SizingMode.AUTOMATIC);
-            docModel.set_page_layout(EvView.PageLayout.AUTOMATIC);
-            this._toolbar.setModel(docModel);
-            this._previewEv.setModel(docModel);
-            this._previewEv.grab_focus();
-        }
-
         this._clearLoadTimer();
         this._spinner.stop();
-        if (doc != null && docModel == null)
-            this._stack.set_visible_child_name('preview-lok');
-        else
+
+        switch (doc.viewType) {
+        case Documents.ViewType.EV:
+            if (docModel) {
+                if (Application.application.isBooks)
+                    docModel.set_sizing_mode(EvView.SizingMode.FIT_PAGE);
+                else
+                    docModel.set_sizing_mode(EvView.SizingMode.AUTOMATIC);
+                docModel.set_page_layout(EvView.PageLayout.AUTOMATIC);
+                this._toolbar.setModel(docModel);
+                this._previewEv.setModel(docModel);
+                this._previewEv.grab_focus();
+            }
             this._stack.set_visible_child_name('preview-ev');
+            break;
+        case Documents.ViewType.LOK:
+            this._stack.set_visible_child_name('preview-lok');
+            break;
+        case Documents.ViewType.NONE:
+        default:
+            log('Something bad happened and the document type is unset');
+            break;
+        }
     },
 
     _onLoadError: function(manager, doc, message, exception) {
diff --git a/src/lokview.js b/src/lokview.js
index 7f02909..4c4baef 100644
--- a/src/lokview.js
+++ b/src/lokview.js
@@ -133,8 +133,6 @@ const LOKView = new Lang.Class({
                                             Lang.bind(this, this._onLoadStarted));
         Application.documentManager.connect('load-error',
                                             Lang.bind(this, this._onLoadError));
-        Application.documentManager.connect('load-finished',
-                                            Lang.bind(this, this._onLoadFinished));
 
         this.connect('destroy', Lang.bind(this,
            function() {
@@ -143,10 +141,19 @@ const LOKView = new Lang.Class({
            }));
     },
 
-    _onLoadStarted: function() {
+    _onLoadStarted: function(manager, doc) {
+        if (doc.viewType != Documents.ViewType.LOK)
+            return;
+        let file = Gio.File.new_for_uri (doc.uri);
+        let location = file.get_path();
+        this._doc = doc;
+        this.view.open_document(location, "{}", null, Lang.bind(this, this.open_document_cb));
+        this._progressBar.show();
     },
 
     _onLoadError: function(manager, doc, message, exception) {
+        if (doc.viewType != Documents.ViewType.LOK)
+            return;
         //FIXME we should hide controls
         this._setError(message, exception.message);
     },
@@ -166,16 +173,6 @@ const LOKView = new Lang.Class({
         this.view.set_edit(false);
     },
 
-    _onLoadFinished: function(manager, doc, docModel) {
-        if (docModel == null && doc != null) {
-            let file = Gio.File.new_for_uri (doc.uri);
-            let location = file.get_path();
-            this._doc = doc;
-            this.view.open_document(location, "{}", null, Lang.bind(this, this.open_document_cb));
-            this._progressBar.show();
-        }
-    },
-
     reset: function () {
         if (!this.view)
             return;
diff --git a/src/preview.js b/src/preview.js
index 12ebecb..c7804bc 100644
--- a/src/preview.js
+++ b/src/preview.js
@@ -43,6 +43,7 @@ const Utils = imports.utils;
 const View = imports.view;
 const WindowMode = imports.windowMode;
 const Presentation = imports.presentation;
+const Documents = imports.documents;
 
 const _FULLSCREEN_TOOLBAR_TIMEOUT = 2; // seconds
 
@@ -172,13 +173,17 @@ const PreviewView = new Lang.Class({
             }));
     },
 
-    _onLoadStarted: function() {
+    _onLoadStarted: function(manager, doc) {
+        if (doc.viewType != Documents.ViewType.EV)
+            return;
         this._bookmarkPage.enabled = false;
         this._places.enabled = false;
         this._copy.enabled = false;
     },
 
     _onLoadError: function(manager, doc, message, exception) {
+        if (doc.viewType != Documents.ViewType.EV)
+            return;
         this._controlsVisible = true;
         this._syncControlsVisible();
         this._setError(message, exception.message);


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