[gnome-documents/wip/pranavk/lokdocview: 24/24] WIP/working with lokdocview



commit 19af21a0b91afa70c78c77e739ee30556e65f8bb
Author: Pranav Kant <pranavk gnome org>
Date:   Fri Jun 19 21:08:44 2015 +0530

    WIP/working with lokdocview

 src/documents.js |   27 ++++++++++++++++++++++++++-
 src/embed.js     |   21 +++++++++++++--------
 src/preview.js   |   22 ++++++++++++++++++++--
 3 files changed, 59 insertions(+), 11 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index e5e34b7..a87ae9b 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -44,6 +44,22 @@ const Search = imports.search;
 const TrackerUtils = imports.trackerUtils;
 const Utils = imports.utils;
 
+const openofficeFormats = ['application/vnd.oasis.opendocument.text',
+                           'application/vnd.oasis.opendocument.text-template',
+                           'application/vnd.oasis.opendocument.text-web',
+                           'application/vnd.oasis.opendocument.text-master',
+                           'application/vnd.oasis.opendocument.graphics',
+                           'application/vnd.oasis.opendocument.graphics-template',
+                           'application/vnd.oasis.opendocument.presentation',
+                           'application/vnd.oasis.opendocument.presentation-template',
+                           'application/vnd.oasis.opendocument.spreadsheet',
+                           'application/vnd.oasis.opendocument.spreadsheet-template',
+                           'application/vnd.oasis.opendocument.chart',
+                           'application/vnd.oasis.opendocument.formula',
+                           'application/vnd.oasis.opendocument.database',
+                           'application/vnd.oasis.opendocument.image',
+                           'application/vnd.openofficeorg.extension'];
+
 const DeleteItemJob = new Lang.Class({
     Name: 'DeleteItemJob',
 // deletes the given resource
@@ -727,6 +743,11 @@ const LocalDocument = new Lang.Class({
             return;
         }
 
+        if (openofficeFormats.indexOf(this.mimeType) != -1) {
+            callback (this, null, null);
+            return;
+        }
+
         GdPrivate.pdf_loader_load_uri_async(this.uri, passwd, cancellable, Lang.bind(this,
             function(source, res) {
                 try {
@@ -1305,7 +1326,8 @@ const DocumentManager = new Lang.Class({
 
         // save loaded model and signal
         this._activeDocModel = docModel;
-        this._activeDocModel.set_continuous(false);
+        if (this._activeDocModel)
+            this._activeDocModel.set_continuous(false);
 
         // load metadata
         this._connectMetadata(docModel);
@@ -1421,6 +1443,9 @@ const DocumentManager = new Lang.Class({
     },
 
     _connectMetadata: function(docModel) {
+        if (!docModel)
+            return;
+
         let evDoc = docModel.get_document();
         let file = Gio.File.new_for_uri(evDoc.get_uri());
         if (!GdPrivate.is_metadata_supported_for_file(file))
diff --git a/src/embed.js b/src/embed.js
index b9d5e8e..6218494 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -365,14 +365,19 @@ const Embed = new Lang.Class({
     },
 
     _onLoadFinished: function(manager, doc, docModel) {
-        if (!Application.application.isBooks)
-            docModel.set_sizing_mode(EvView.SizingMode.AUTOMATIC);
-        else
-            docModel.set_sizing_mode(EvView.SizingMode.FIT_PAGE);
-        docModel.set_page_layout(EvView.PageLayout.AUTOMATIC);
-        this._toolbar.setModel(docModel);
-        this._preview.setModel(docModel);
-        this._preview.grab_focus();
+        if(docModel) {
+            if (!Application.application.isBooks)
+                docModel.set_sizing_mode(EvView.SizingMode.AUTOMATIC);
+            else
+                docModel.set_sizing_mode(EvView.SizingMode.FIT_PAGE);
+            docModel.set_page_layout(EvView.PageLayout.AUTOMATIC);
+            this._toolbar.setModel(docModel);
+            this._preview.setModel(docModel);
+        } else {
+            this._preview.setDoc(doc);
+        }
+
+        this._preview.widget.grab_focus();
 
         this._clearLoadTimer();
         this._spinnerBox.stop();
diff --git a/src/preview.js b/src/preview.js
index 1e78b86..9ac41cf 100644
--- a/src/preview.js
+++ b/src/preview.js
@@ -27,6 +27,7 @@ const Gdk = imports.gi.Gdk;
 const Gio = imports.gi.Gio;
 const GLib = imports.gi.GLib;
 const Gtk = imports.gi.Gtk;
+const LOKDocView = imports.gi.LOKDocView;
 const _ = imports.gettext.gettext;
 
 const Lang = imports.lang;
@@ -43,7 +44,6 @@ const Utils = imports.utils;
 const View = imports.view;
 const WindowMode = imports.windowMode;
 const Presentation = imports.presentation;
-
 const _FULLSCREEN_TOOLBAR_TIMEOUT = 2; // seconds
 
 const PreviewView = new Lang.Class({
@@ -80,7 +80,12 @@ const PreviewView = new Lang.Class({
         this._sw.get_vscrollbar().connect('button-press-event', Lang.bind(this, this._onScrollbarClick));
         this._sw.get_hadjustment().connect('value-changed', Lang.bind(this, this._onAdjustmentChanged));
         this._sw.get_vadjustment().connect('value-changed', Lang.bind(this, this._onAdjustmentChanged));
+
         this.add_named(this._sw, 'view');
+        this._sw.connect ('key-press-event', Lang.bind(this, this._onKeyPress));
+        this._sw.connect ('key-release-event', Lang.bind(this, this._onKeyPress));
+        
+        this.LOKView = LOKDocView.View.new ('/opt/libreoffice/instdir/program', null, null);
 
         this._createView();
 
@@ -168,6 +173,10 @@ const PreviewView = new Lang.Class({
             }));
     },
 
+    _onKeyPress: function (widget, event) {
+        this.LOKView.post_key (event);
+    },
+
     _onLoadStarted: function() {
         this._bookmarkPage.enabled = false;
         this._showPlaces.enabled = false;
@@ -380,7 +389,7 @@ const PreviewView = new Lang.Class({
                 this._fsToolbar.conceal();
         }
     },
-
+    
     _onWindowModeChanged: function() {
         let windowMode = Application.modeController.getWindowMode();
         if (windowMode != WindowMode.WindowMode.PREVIEW) {
@@ -539,6 +548,15 @@ const PreviewView = new Lang.Class({
         this._createView();
     },
 
+    setDoc: function (doc) {
+        let location = doc.uri.replace ('file://', '');
+        this.setModel(null);
+        this.view.destroy();
+        this._sw.add (this.LOKView);
+        this.LOKView.open_document (location);
+        this.LOKView.show();
+    },
+
     setModel: function(model) {
         if (this._model == model)
             return;


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