[gnome-documents/wip/lokdocview-rebase: 11/29] Make the LOKView optional at run-time



commit 595553a81ea309d4ccb884cdce480e7da2c979ad
Author: Bastien Nocera <hadess hadess net>
Date:   Fri Dec 4 18:03:51 2015 +0100

    Make the LOKView optional at run-time
    
    When LOK isn't available, show an error about contacting the sysadmin.

 src/documents.js |   13 +++++++++++--
 src/lokview.js   |   29 +++++++++++++++++++++++++----
 2 files changed, 36 insertions(+), 6 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index 7f335ee..8ddba8e 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -21,6 +21,7 @@
 
 const EvDocument = imports.gi.EvinceDocument;
 const EvView = imports.gi.EvinceView;
+const LOKView = imports.lokview;
 const GdkPixbuf = imports.gi.GdkPixbuf;
 const Gio = imports.gi.Gio;
 const Gd = imports.gi.Gd;
@@ -776,8 +777,14 @@ const LocalDocument = new Lang.Class({
             return;
         }
 
-        if (this.isOpenDocumentFormat()) {
-            callback (this, null, null);
+        if (this.isOpenDocumentFormat() && !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;
         }
 
@@ -1353,6 +1360,8 @@ const DocumentManager = new Lang.Class({
             case Gio.IOErrorEnum.NOT_SUPPORTED:
                 if (Application.application.isBooks)
                     message = _("You are using a preview of Books. Full viewing capabilities are coming 
soon!");
+                else
+                    message = _("LibreOffice support is not available on your system. Please contact your 
system administrator.");
                 break;
             default:
                 break;
diff --git a/src/lokview.js b/src/lokview.js
index 99a6b09..671100e 100644
--- a/src/lokview.js
+++ b/src/lokview.js
@@ -19,7 +19,13 @@
  *
  */
 
-const LOKDocView = imports.gi.LOKDocView;
+try {
+       const LOKDocView = imports.gi.LOKDocView;
+} catch(e) {
+       // LOKDocView will be undefined, and we'll
+       // use this to warn when LO files can't be opened
+}
+
 const Soup = imports.gi.Soup;
 const Gd = imports.gi.Gd;
 const GdPrivate = imports.gi.GdPrivate;
@@ -93,6 +99,8 @@ const LOKView = new Lang.Class({
 
         Application.documentManager.connect('load-started',
                                             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));
 
@@ -104,7 +112,11 @@ const LOKView = new Lang.Class({
     },
 
     _onLoadStarted: function() {
+    },
 
+    _onLoadError: function(manager, doc, message, exception) {
+        //FIXME we should hide controls
+        this._setError(message, exception.message);
     },
 
     open_document_cb: function(res, doc) {
@@ -131,13 +143,17 @@ const LOKView = new Lang.Class({
     },
 
     reset: function () {
+        if (!this.view)
+            return;
         this.view.hide()
     },
 
     _createView: function() {
-        this.view = LOKDocView.View.new(LO_PATH, null, null);
-        this._sw.add(this.view);
-        this.view.connect('load-changed', Lang.bind(this, this._onProgressChanged));
+        if (isAvailable()) {
+            this.view = LOKDocView.View.new(LO_PATH, null, null);
+            this._sw.add(this.view);
+            this.view.connect('load-changed', Lang.bind(this, this._onProgressChanged));
+        }
 
         this._navControls = new LOKViewNavControls(this, this._overlay);
         this.set_visible_child_full('view', Gtk.StackTransitionType.NONE);
@@ -146,6 +162,11 @@ const LOKView = new Lang.Class({
     _onProgressChanged: function() {
         this._progressBar.fraction = this.view.load_progress;
     },
+
+    _setError: function(primary, secondary) {
+        this._errorBox.update(primary, secondary);
+        this.set_visible_child_name('error');
+    },
 });
 Signals.addSignalMethods(LOKView.prototype);
 


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