[gnome-documents/lokdocview] WIP/working with lokdocview



commit de6ee4b9b483463b3f9c9a9f651f8f46a6cbb20f
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     |   20 +++++++++++++-------
 src/preview.js   |   23 ++++++++++++++++++++---
 3 files changed, 59 insertions(+), 11 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index 2c95d34..13fb7ae 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -45,6 +45,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
@@ -728,6 +744,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 {
@@ -1306,7 +1327,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);
@@ -1422,6 +1444,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 f65927b..e0aa8e2 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -364,13 +364,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);
+        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);
+            log ("this time not");
+            this._toolbar.setModel(docModel);
+            this._preview.setModel(docModel);
+        } else {
+            this._preview.setDoc(doc);
+        }
+
         this._preview.widget.grab_focus();
 
         this._clearLoadTimer();
diff --git a/src/preview.js b/src/preview.js
index 6b5bb54..69b50dc 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,6 +80,10 @@ const PreviewView = new Lang.Class({
         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.widget.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();
 
@@ -167,6 +171,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;
@@ -379,7 +387,7 @@ const PreviewView = new Lang.Class({
                 this._fsToolbar.hide();
         }
     },
-
+    
     _onWindowModeChanged: function() {
         let windowMode = Application.modeController.getWindowMode();
         if (windowMode != WindowMode.WindowMode.PREVIEW) {
@@ -538,6 +546,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;
@@ -995,7 +1012,7 @@ const PreviewSearchbar = new Lang.Class({
     },
 
     hide: function() {
-        this._previewView.view.find_set_highlight_search(false);
+        //this._previewView.view.find_set_highlight_search(false);
 
         this.searchChangeBlocked = true;
         this.parent();


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