[Libreoffice-commits] online.git: 3 commits - loleaflet/build loleaflet/dist loleaflet/src loolwsd/LOOLSession.cpp loolwsd/protocol.txt

Mihai Varga mihai.varga at collabora.com
Tue Oct 13 10:59:31 PDT 2015


 loleaflet/build/deps.js                   |    5 ++
 loleaflet/dist/images/presentation.png    |binary
 loleaflet/src/control/Control.Buttons.js  |    6 +-
 loleaflet/src/control/Control.Dialog.js   |   13 ++++++
 loleaflet/src/control/Toolbar.js          |    3 -
 loleaflet/src/layer/tile/TileLayer.js     |   15 ++++++-
 loleaflet/src/map/handler/Map.Keyboard.js |    3 +
 loleaflet/src/map/handler/Map.Print.js    |   62 ++++++++++++++++++++++++++++++
 loolwsd/LOOLSession.cpp                   |   20 ++++++---
 loolwsd/protocol.txt                      |    4 +
 10 files changed, 119 insertions(+), 12 deletions(-)

New commits:
commit 0708e4440fb57cb24ca096991f719f38e7a76584
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Tue Oct 13 20:56:42 2015 +0300

    added a part parameter to the 'downloadas' command
    
    We need it to export a specific slide to svg

diff --git a/loleaflet/src/control/Toolbar.js b/loleaflet/src/control/Toolbar.js
index 0beaf57..0e276f7 100644
--- a/loleaflet/src/control/Toolbar.js
+++ b/loleaflet/src/control/Toolbar.js
@@ -40,7 +40,8 @@ L.Map.include({
 		}
 		L.Socket.sendMessage('downloadas ' +
 			'name=' + name + ' ' +
-			'id=0 ' +
+			'id=-1 ' + // not a special download
+			'part=-1 ' + // we don't want to export just a single part
 			'format=' + format + ' ' +
 			'options=' + options);
 	},
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index c52daef..95de103 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -274,7 +274,7 @@ L.TileLayer = L.GridLayer.extend({
 		var url = window.location.protocol + '//' + parser.hostname + ':' + command.port + '/' +
 			command.jail + '/' + command.dir + '/' + command.name;
 
-		if (command.id !== '0') {
+		if (command.id !== '-1') {
 			var isFirefox = typeof InstallTrigger !== 'undefined' || navigator.userAgent.search('Firefox') >= 0;
 			if (isFirefox) {
 				// the print dialog doesn't work well on firefox
diff --git a/loleaflet/src/map/handler/Map.Keyboard.js b/loleaflet/src/map/handler/Map.Keyboard.js
index c674240..37820b8 100644
--- a/loleaflet/src/map/handler/Map.Keyboard.js
+++ b/loleaflet/src/map/handler/Map.Keyboard.js
@@ -284,7 +284,7 @@ L.Map.Keyboard = L.Handler.extend({
 				L.Socket.sendMessage('uno .uno:LeftPara');
 				break;
 			case 80: // p
-				L.Socket.sendMessage('downloadas name=print.pdf id=print format=pdf options=');
+				L.Socket.sendMessage('downloadas name=print.pdf id=print part=-1 format=pdf options=');
 				break;
 			case 82: // r
 				L.Socket.sendMessage('uno .uno:RightPara');
diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp
index cf7e3a3..53a0873 100644
--- a/loolwsd/LOOLSession.cpp
+++ b/loolwsd/LOOLSession.cpp
@@ -999,20 +999,22 @@ void ChildProcessSession::sendTile(const char *buffer, int length, StringTokeniz
 bool ChildProcessSession::downloadAs(const char *buffer, int length, StringTokenizer& tokens)
 {
     std::string name, id, format, filterOptions;
+    int part;
 
-    if (tokens.count() < 5 ||
+    if (tokens.count() < 6 ||
         !getTokenString(tokens[1], "name", name) ||
-        !getTokenString(tokens[2], "id", id))
+        !getTokenString(tokens[2], "id", id),
+        !getTokenInteger(tokens[3], "part", part))
     {
-        sendTextFrame("error: cmd=saveas kind=syntax");
+        sendTextFrame("error: cmd=downloadas kind=syntax");
         return false;
     }
 
-    getTokenString(tokens[3], "format", format);
+    getTokenString(tokens[4], "format", format);
 
-    if (getTokenString(tokens[4], "options", filterOptions)) {
-        if (tokens.count() > 5) {
-            filterOptions += Poco::cat(std::string(" "), tokens.begin() + 4, tokens.end());
+    if (getTokenString(tokens[5], "options", filterOptions)) {
+        if (tokens.count() > 6) {
+            filterOptions += Poco::cat(std::string(" "), tokens.begin() + 6, tokens.end());
         }
     }
 
@@ -1030,6 +1032,10 @@ bool ChildProcessSession::downloadAs(const char *buffer, int length, StringToken
     } while (file->exists());
     delete file;
 
+    if (part != -1) {
+        // we need this to export a slide to svg
+        _loKitDocument->pClass->setPart(_loKitDocument, part);
+    }
     _loKitDocument->pClass->saveAs(_loKitDocument, url.c_str(),
             format.size() == 0 ? NULL :format.c_str(),
             filterOptions.size() == 0 ? NULL : filterOptions.c_str());
diff --git a/loolwsd/protocol.txt b/loolwsd/protocol.txt
index d16d38c..dbe89fb 100644
--- a/loolwsd/protocol.txt
+++ b/loolwsd/protocol.txt
@@ -17,9 +17,11 @@ canceltiles
     dropped and will not be handled. There is no guarantee of exactly
     which tile: messages might still be sent back to the client.
 
-downloadas downloadas name=<fileName> id=<id> format=<document format> options=<SkipImages, etc>
+downloadas downloadas name=<fileName> id=<id> part=<part> format=<document format> options=<SkipImages, etc>
 
     Exports the current document to the desired format and returns a download URL
+    The id identifies the request on the client.
+    The part parameter is used to export a specific part, for example when we need to export a slide to svg
 
 gettextselection mimetype=<mimeType>
 
commit 5f655a7555cd836933dc14395495561f5f8cd04e
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Tue Oct 13 19:26:16 2015 +0300

    loleaflet: print handler tdf#94607
    
    In a browser != Firefox we use a hidden iframe to load the exported pdf
    document and call print on that iframe.
    For Firefox where the PDFjs script has some permission problems, we
    can't do that so we just notify the user that they can download a pdf
    version of the document

diff --git a/loleaflet/build/deps.js b/loleaflet/build/deps.js
index dae1e80..7913747 100644
--- a/loleaflet/build/deps.js
+++ b/loleaflet/build/deps.js
@@ -225,6 +225,11 @@ var deps = {
 		desc: 'Handles mouse interaction with the document.'
 	},
 
+	Print: {
+		src: ['map/handler/Map.Print.js'],
+		desc: 'Handles the print action (ctrl + P).'
+	},
+
 	MarkerDrag: {
 		src: ['layer/marker/Marker.Drag.js'],
 		deps: ['Marker'],
diff --git a/loleaflet/src/control/Control.Dialog.js b/loleaflet/src/control/Control.Dialog.js
index 31f9654..cb84d53 100644
--- a/loleaflet/src/control/Control.Dialog.js
+++ b/loleaflet/src/control/Control.Dialog.js
@@ -5,6 +5,7 @@
 L.Control.Dialog = L.Control.extend({
 	onAdd: function (map) {
 		map.on('error', this._onError, this);
+		map.on('print', this._onPrint, this);
 		return document.createElement('div');
 	},
 
@@ -17,6 +18,18 @@ L.Control.Dialog = L.Control.extend({
 						' parsing the \'' + e.cmd + '\' command.';
 			vex.dialog.alert(msg);
 		}
+	},
+
+	_onPrint: function (e) {
+		var url = e.url;
+		vex.dialog.confirm({
+			message: 'Download PDF export?',
+			callback: L.bind(function (value) {
+				if (value) {
+					this._map._fileDownloader.src = url;
+				}
+			}, this)
+		});
 	}
 });
 
diff --git a/loleaflet/src/layer/tile/TileLayer.js b/loleaflet/src/layer/tile/TileLayer.js
index e5c2ba3..c52daef 100644
--- a/loleaflet/src/layer/tile/TileLayer.js
+++ b/loleaflet/src/layer/tile/TileLayer.js
@@ -273,7 +273,20 @@ L.TileLayer = L.GridLayer.extend({
 		parser.href = this._map.options.server;
 		var url = window.location.protocol + '//' + parser.hostname + ':' + command.port + '/' +
 			command.jail + '/' + command.dir + '/' + command.name;
-		this._map._fileDownloader.src = url;
+
+		if (command.id !== '0') {
+			var isFirefox = typeof InstallTrigger !== 'undefined' || navigator.userAgent.search('Firefox') >= 0;
+			if (isFirefox) {
+				// the print dialog doesn't work well on firefox
+				this._map.fire('print', {url: url});
+			}
+			else {
+				this._map.fire('filedownloadready', {url: url, name: name, id: command.id});
+			}
+		}
+		else {
+			this._map._fileDownloader.src = url;
+		}
 	},
 
 	_onErrorMsg: function (textMsg) {
diff --git a/loleaflet/src/map/handler/Map.Keyboard.js b/loleaflet/src/map/handler/Map.Keyboard.js
index 93490e4..c674240 100644
--- a/loleaflet/src/map/handler/Map.Keyboard.js
+++ b/loleaflet/src/map/handler/Map.Keyboard.js
@@ -283,6 +283,9 @@ L.Map.Keyboard = L.Handler.extend({
 			case 76: // l
 				L.Socket.sendMessage('uno .uno:LeftPara');
 				break;
+			case 80: // p
+				L.Socket.sendMessage('downloadas name=print.pdf id=print format=pdf options=');
+				break;
 			case 82: // r
 				L.Socket.sendMessage('uno .uno:RightPara');
 				break;
diff --git a/loleaflet/src/map/handler/Map.Print.js b/loleaflet/src/map/handler/Map.Print.js
new file mode 100644
index 0000000..1a92c8b
--- /dev/null
+++ b/loleaflet/src/map/handler/Map.Print.js
@@ -0,0 +1,62 @@
+/*
+ * L.Map.Print is handling the print action
+ */
+
+L.Map.mergeOptions({
+	print: true
+});
+
+L.Map.Print = L.Handler.extend({
+
+	initialize: function (map) {
+		this._map = map;
+	},
+
+	addHooks: function () {
+		this._map.on('filedownloadready', this._onFileReady, this);
+	},
+
+	removeHooks: function () {
+		this._map.off('filedownloadready', this._onFileReady, this);
+	},
+
+	_onFileReady: function (e) {
+		// we need to load the pdf document and pass it to the iframe as an
+		// object URL, because else we might have cross origin security problems
+		var xmlHttp = new XMLHttpRequest();
+		xmlHttp.onreadystatechange = L.bind(function () {
+			if (xmlHttp.readyState == 4 && xmlHttp.status == 200) {
+				this._onInitPrint(xmlHttp);
+			}
+		}, this);
+		xmlHttp.open('GET', e.url, true);
+		xmlHttp.responseType = 'blob';
+		xmlHttp.send();
+	},
+
+	_onInitPrint: function (e) {
+		var blob = new Blob([e.response], {type: 'application/pdf'});
+		var url = URL.createObjectURL(blob);
+		this._printIframe = L.DomUtil.create('iframe', '', document.body);
+		this._printIframe.onload = L.bind(this._onIframeLoaded, this);
+		L.DomUtil.setStyle(this._printIframe, 'visibility', 'hidden');
+		L.DomUtil.setStyle(this._printIframe, 'position', 'fixed');
+		L.DomUtil.setStyle(this._printIframe, 'right', '0');
+		L.DomUtil.setStyle(this._printIframe, 'bottom', '0');
+		this._printIframe.src = url;
+	},
+
+	_onIframeLoaded: function () {
+		this._printIframe.contentWindow.focus(); // Required for IE
+		this._printIframe.contentWindow.print();
+		// couldn't find another way to remove it
+		setTimeout(L.bind(this._closePrintDialog, this), 1000);
+	},
+
+	_closePrintDialog: function () {
+		L.DomUtil.remove(this._printIframe);
+		this._map.focus();
+	}
+});
+
+L.Map.addInitHook('addHandler', 'print', L.Map.Print);
commit ee3687d7388b7b3c7d1b86e8653f44164327b829
Author: Mihai Varga <mihai.varga at collabora.com>
Date:   Tue Oct 13 13:48:34 2015 +0300

    loleaflet: presentation button

diff --git a/loleaflet/dist/images/presentation.png b/loleaflet/dist/images/presentation.png
new file mode 100644
index 0000000..49f1ada
Binary files /dev/null and b/loleaflet/dist/images/presentation.png differ
diff --git a/loleaflet/src/control/Control.Buttons.js b/loleaflet/src/control/Control.Buttons.js
index eaacf6d..463e2e5 100644
--- a/loleaflet/src/control/Control.Buttons.js
+++ b/loleaflet/src/control/Control.Buttons.js
@@ -27,11 +27,13 @@ L.Control.Buttons = L.Control.extend({
 			'save':          {title: 'Save',               uno: 'Save',             iconName: 'save.png'},
 			'saveas':        {title: 'Save As',                                     iconName: 'saveas.png'},
 			'edit':          {title: 'Enable editing',                              iconName: 'edit.png'},
-			'selection':     {title: 'Enable selection',                            iconName: 'selection.png'}
+			'selection':     {title: 'Enable selection',                            iconName: 'selection.png'},
+			'presentation':  {title: 'Present',                                     iconName: 'presentation.png'}
 		};
+		var separator = ['alignleft', 'save', 'bullet', 'edit', 'presentation'];
 		for (var key in this._buttons) {
 			var button = this._buttons[key];
-			if (key === 'alignleft' || key === 'save' || key === 'bullet' || key === 'edit') {
+			if (separator.indexOf(key) >= 0) {
 				// add a separator
 				L.DomUtil.create('span', 'leaflet-control-button-separator', container);
 			}


More information about the Libreoffice-commits mailing list