Skip to content

Commit

Permalink
android: Make the LOK document accessible from the JNI.
Browse files Browse the repository at this point in the history
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
  • Loading branch information
kendy committed May 31, 2019
1 parent 7aac228 commit ea2b77c
Show file tree
Hide file tree
Showing 3 changed files with 25 additions and 2 deletions.
9 changes: 9 additions & 0 deletions android/app/src/main/cpp/androidapp.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -15,6 +15,7 @@
#include <thread>

#include <FakeSocket.hpp>
#include <Kit.hpp>
#include <Log.hpp>
#include <LOOLWSD.hpp>
#include <Protocol.hpp>
Expand Down Expand Up @@ -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
Expand Down
12 changes: 10 additions & 2 deletions kit/Kit.cpp
Original file line number Diff line number Diff line change
Expand Up @@ -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>
Expand Down Expand Up @@ -2159,7 +2158,7 @@ class Document : public DocumentManagerInterface
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;

Expand Down Expand Up @@ -2200,8 +2199,17 @@ class Document : public DocumentManagerInterface
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;
Expand Down
6 changes: 6 additions & 0 deletions kit/Kit.hpp
Original file line number Diff line number Diff line change
Expand Up @@ -14,6 +14,9 @@

#include <common/Util.hpp>

#define LOK_USE_UNSTABLE_API
#include <LibreOfficeKit/LibreOfficeKit.hxx>

#if MOBILEAPP

#include "ClientSession.hpp"
Expand Down Expand Up @@ -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: */

0 comments on commit ea2b77c

Please sign in to comment.