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



commit 95a2d932db9da05ea1cc4bae53b6efb7518a4211
Author: Bastien Nocera <hadess hadess net>
Date:   Mon Jan 4 18:07:13 2016 +0100

    Make the LOKView optional at run-time
    
    When LOK isn't available, show an error about contacting the sysadmin.
    
    https://bugzilla.gnome.org/show_bug.cgi?id=753686

 src/documents.js |   13 +++++++++++--
 src/lokview.js   |   33 +++++++++++++++++++++++++++++----
 2 files changed, 40 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 d6a9374..4dbb66c 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;
@@ -43,6 +49,10 @@ const View = imports.view;
 const WindowMode = imports.windowMode;
 const Documents = imports.documents;
 
+function isAvailable() {
+    return (LOKDocView != undefined);
+}
+
 const LOKView = new Lang.Class({
     Name: 'LOKView',
     Extends: Gtk.Stack,
@@ -87,6 +97,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));
 
@@ -98,7 +110,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) {
@@ -126,13 +142,17 @@ const LOKView = new Lang.Class({
     },
 
     reset: function () {
+        if (!this.view)
+            return;
         this.view.hide()
     },
 
     _createView: function() {
-        this.view = LOKDocView.View.new(null, null, null);
-        this._sw.add(this.view);
-        this.view.connect('load-changed', Lang.bind(this, this._onProgressChanged));
+        if (isAvailable()) {
+            this.view = LOKDocView.View.new(null, 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);
@@ -141,6 +161,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]