[Libreoffice-commits] online.git: android/app kit/Kit.cpp kit/Kit.hpp

Libreoffice Gerrit user logerrit at kemper.freedesktop.org
Fri May 31 07:21:21 UTC 2019


 android/app/src/main/cpp/androidapp.cpp |    9 +++++++++
 kit/Kit.cpp                             |   12 ++++++++++--
 kit/Kit.hpp                             |    6 ++++++
 3 files changed, 25 insertions(+), 2 deletions(-)

New commits:
commit ea2b77ce07d615e72c29b7016b464a9147373805
Author:     Jan Holesovsky <kendy at collabora.com>
AuthorDate: Wed May 29 11:39:46 2019 +0200
Commit:     Jan Holesovsky <kendy at collabora.com>
CommitDate: Fri May 31 09:20:34 2019 +0200

    android: Make the LOK document accessible from the JNI.
    
    For some operations like printing to PDF, we need to have access to the
    LOK API to perform eg. saveAs().  iOS is using an extern for that, but
    given that it is needed for Android too, let's introduce a proper getter
    for that.
    
    Change-Id: Ie2340a4ee0bdf9dc46e799e2567a828172d9a67d

diff --git a/android/app/src/main/cpp/androidapp.cpp b/android/app/src/main/cpp/androidapp.cpp
index e10639eba..26828e6e1 100644
--- a/android/app/src/main/cpp/androidapp.cpp
+++ b/android/app/src/main/cpp/androidapp.cpp
@@ -15,6 +15,7 @@
 #include <thread>
 
 #include <FakeSocket.hpp>
+#include <Kit.hpp>
 #include <Log.hpp>
 #include <LOOLWSD.hpp>
 #include <Protocol.hpp>
@@ -218,6 +219,14 @@ Java_org_libreoffice_androidapp_MainActivity_postMobileMessageNative(JNIEnv *env
 
             // ???
         }
+        else if (strcmp(string_value, "PRINT") == 0 && false /* FIXME disabled so far */)
+        {
+            // TODO this is just a sketch to check this compiles
+            std::string printFile = Util::createRandomTmpDir() + "/print.pdf";
+            getLOKDocument()->saveAs(printFile.c_str(), "pdf", nullptr);
+
+            // TODO more stuff here...
+        }
         else
         {
             // As above
diff --git a/kit/Kit.cpp b/kit/Kit.cpp
index fefa3da0b..892289f23 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -38,7 +38,6 @@
 
 #define LOK_USE_UNSTABLE_API
 #include <LibreOfficeKit/LibreOfficeKitInit.h>
-#include <LibreOfficeKit/LibreOfficeKit.hxx>
 
 #include <Poco/Exception.h>
 #include <Poco/JSON/Object.h>
@@ -2159,7 +2158,7 @@ private:
     std::string _jailedUrl;
     std::string _renderOpts;
 
-    std::shared_ptr<lok::Document> _loKitDocument;
+    static std::shared_ptr<lok::Document> _loKitDocument;
     std::shared_ptr<TileQueue> _tileQueue;
     std::shared_ptr<WebSocketHandler> _websocketHandler;
 
@@ -2200,8 +2199,17 @@ private:
     std::map<int, UserInfo> _sessionUserInfo;
     std::chrono::steady_clock::time_point _lastMemStatsTime;
     Poco::Thread _callbackThread;
+
+    friend std::shared_ptr<lok::Document> getLOKDocument();
 };
 
+std::shared_ptr<lok::Document> Document::_loKitDocument = std::shared_ptr<lok::Document>();
+
+std::shared_ptr<lok::Document> getLOKDocument()
+{
+    return Document::_loKitDocument;
+}
+
 class KitWebSocketHandler final : public WebSocketHandler, public std::enable_shared_from_this<KitWebSocketHandler>
 {
     std::shared_ptr<TileQueue> _queue;
diff --git a/kit/Kit.hpp b/kit/Kit.hpp
index 58dfd9e55..0f8d90d6c 100644
--- a/kit/Kit.hpp
+++ b/kit/Kit.hpp
@@ -14,6 +14,9 @@
 
 #include <common/Util.hpp>
 
+#define LOK_USE_UNSTABLE_API
+#include <LibreOfficeKit/LibreOfficeKit.hxx>
+
 #if MOBILEAPP
 
 #include "ClientSession.hpp"
@@ -132,6 +135,9 @@ std::string anonymizeUrl(const std::string& url);
 /// Anonymize usernames.
 std::string anonymizeUsername(const std::string& username);
 
+/// For the mobile, we need access to the document to perform eg. saveAs() for printing.
+std::shared_ptr<lok::Document> getLOKDocument();
+
 #endif
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list