[gnome-documents/wip/pranavk/lokdocview: 1/7] Add new class, LOKView, for LOKDocView widget
- From: Pranav Kant <pranavk src gnome org>
- To: commits-list gnome org
- Cc:
- Subject: [gnome-documents/wip/pranavk/lokdocview: 1/7] Add new class, LOKView, for LOKDocView widget
- Date: Wed, 19 Aug 2015 18:58:14 +0000 (UTC)
commit 5475ab596feda85c140121f5984824737151db28
Author: Pranav Kant <pranavk gnome org>
Date: Tue Aug 11 21:11:11 2015 +0530
Add new class, LOKView, for LOKDocView widget
Use this widget, now, to open 'open document' format documents.
src/documents.js | 27 +++++++-
src/embed.js | 29 +++++---
src/lokview.js | 110 +++++++++++++++++++++++++++++
src/org.gnome.Documents.src.gresource.xml | 1 +
4 files changed, 157 insertions(+), 10 deletions(-)
---
diff --git a/src/documents.js b/src/documents.js
index e5e34b7..52dba53 100644
--- a/src/documents.js
+++ b/src/documents.js
@@ -44,6 +44,23 @@ const Search = imports.search;
const TrackerUtils = imports.trackerUtils;
const Utils = imports.utils;
+const openDocumentFormats = ['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 +744,11 @@ const LocalDocument = new Lang.Class({
return;
}
+ if (openDocumentFormats.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 +1327,8 @@ const DocumentManager = new Lang.Class({
// save loaded model and signal
this._activeDocModel = docModel;
- this._activeDocModel.set_continuous(false);
+ if (this._activeModel)
+ this._activeDocModel.set_continuous(false);
// load metadata
this._connectMetadata(docModel);
@@ -1421,6 +1444,8 @@ 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..8ca5521 100644
--- a/src/embed.js
+++ b/src/embed.js
@@ -33,6 +33,7 @@ const Selections = imports.selections;
const View = imports.view;
const WindowMode = imports.windowMode;
const Documents = imports.documents;
+const LOKView = imports.lokview;
const EvView = imports.gi.EvinceView;
const Gd = imports.gi.Gd;
@@ -118,6 +119,9 @@ const Embed = new Lang.Class({
this._preview = new Preview.PreviewView(this._stackOverlay);
this._stack.add_named(this._preview, 'preview');
+ this._lokview = new LOKView.LOKView(this._stackOverlay);
+ this._stack.add_named(this._lokview, 'lokview');
+
this._edit = new Edit.EditView();
this._stack.add_named(this._edit, 'edit');
@@ -365,18 +369,23 @@ 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 (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();
+ }
this._clearLoadTimer();
this._spinnerBox.stop();
- this._stack.set_visible_child_name('preview');
+ if (doc != null && docModel == null)
+ this._stack.set_visible_child_name('lokview');
+ else
+ this._stack.set_visible_child_name('preview');
},
_onLoadError: function(manager, doc, message, exception) {
@@ -421,6 +430,8 @@ const Embed = new Lang.Class({
if (this._preview)
this._preview.reset();
+ if (this._lokview)
+ this._lokview.reset();
if (this._edit)
this._edit.setUri(null);
diff --git a/src/lokview.js b/src/lokview.js
new file mode 100644
index 0000000..ec798d0
--- /dev/null
+++ b/src/lokview.js
@@ -0,0 +1,110 @@
+/*
+ * Copyright (c) 2015 Pranav Kant
+ *
+ * Gnome Documents is free software; you can redistribute it and/or modify
+ * it under the terms of the GNU General Public License as published by the
+ * Free Software Foundation; either version 2 of the License, or (at your
+ * option) any later version.
+ *
+ * Gnome Documents is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty of MERCHANTABILITY
+ * or FITNESS FOR A PARTICULAR PURPOSE. See the GNU General Public License
+ * for more details.
+ *
+ * You should have received a copy of the GNU General Public License along
+ * with Gnome Documents; if not, write to the Free Software Foundation,
+ * Inc., 51 Franklin St, Fifth Floor, Boston, MA 02110-1301 USA
+ *
+ * Author: Pranav Kant <pranavk gnome org>
+ *
+ */
+
+const LOKDocView = imports.gi.LOKDocView;
+const WebKit = imports.gi.WebKit2;
+const Soup = imports.gi.Soup;
+const Gd = imports.gi.Gd;
+const GdPrivate = imports.gi.GdPrivate;
+const Gdk = imports.gi.Gdk;
+const Gio = imports.gi.Gio;
+const GLib = imports.gi.GLib;
+const Gtk = imports.gi.Gtk;
+const _ = imports.gettext.gettext;
+
+const Lang = imports.lang;
+const Mainloop = imports.mainloop;
+const Signals = imports.signals;
+
+const Application = imports.application;
+const MainToolbar = imports.mainToolbar;
+const Searchbar = imports.searchbar;
+const Utils = imports.utils;
+const View = imports.view;
+const WindowMode = imports.windowMode;
+const Documents = imports.documents;
+
+// FIXME: Find this path dynamically
+const LO_PATH = '/opt/libreoffice/instdir/program'
+
+const LOKView = new Lang.Class({
+ Name: 'LOKView',
+ Extends: Gtk.Overlay,
+
+ _init: function() {
+ this._uri = null;
+
+ this.parent();
+ this.get_style_context().add_class('documents-scrolledwin');
+
+ this._sw = new Gtk.ScrolledWindow({hexpand: true,
+ vexpand: true});
+
+ this._progressBar = new Gtk.ProgressBar({ halign: Gtk.Align.FILL,
+ valign: Gtk.Align.START });
+ this._progressBar.get_style_context().add_class('osd');
+ this.add_overlay(this._progressBar);
+
+ this.add(this._sw);
+ this._createView();
+
+ this.show_all();
+
+ Application.documentManager.connect('load-started',
+ Lang.bind(this, this._onLoadStarted));
+ Application.documentManager.connect('load-finished',
+ Lang.bind(this, this._onLoadFinished));
+
+ },
+
+ _onLoadStarted: function() {
+
+ },
+
+ open_document_cb: function() {
+ // TODO: Call _finish and check failure
+ this._progressBar.hide();
+ this.view.show();
+ },
+
+ _onLoadFinished: function(manager, doc, docModel) {
+ if (docModel == null && doc != null) {
+ let location = doc.uri.replace ('file://', '');
+ this.view.open_document(location, null, Lang.bind(this, this.open_document_cb), null);
+ this._progressBar.show();
+ }
+ },
+
+ reset: function () {
+ 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));
+ },
+
+ _onProgressChanged: function() {
+ this._progressBar.fraction = this.view.load_progress;
+ },
+});
+Signals.addSignalMethods(LOKView.prototype);
diff --git a/src/org.gnome.Documents.src.gresource.xml b/src/org.gnome.Documents.src.gresource.xml
index a2baba3..a3b26db 100644
--- a/src/org.gnome.Documents.src.gresource.xml
+++ b/src/org.gnome.Documents.src.gresource.xml
@@ -5,6 +5,7 @@
<file>changeMonitor.js</file>
<file>documents.js</file>
<file>edit.js</file>
+ <file>lokview.js</file>
<file>embed.js</file>
<file>errorBox.js</file>
<file>main.js</file>
[
Date Prev][
Date Next] [
Thread Prev][
Thread Next]
[
Thread Index]
[
Date Index]
[
Author Index]