common/Session.cpp | 6 ++++++ common/Session.hpp | 13 ++++++++----- kit/ChildSession.cpp | 2 +- kit/ChildSession.hpp | 3 ++- kit/Kit.cpp | 16 +++++++++++----- loleaflet/src/core/Socket.js | 3 +++ test/WhiteBoxTests.cpp | 3 ++- wsd/ClientSession.cpp | 5 +++++ wsd/protocol.txt | 5 ++++- 9 files changed, 42 insertions(+), 14 deletions(-)
New commits: commit 9f17050a7d4e1b5124a108dce3cce7001bf3deeb Author: Jan Holesovsky <ke...@collabora.com> Date: Fri Mar 24 12:34:32 2017 +0100 Pass the locale settings from loleaflet to wsd/kit. Change-Id: Ie530db73cfbdb62787f16eae0f4b07fbf8b8acb4 diff --git a/common/Session.cpp b/common/Session.cpp index 78161f11..4c5c40cb 100644 --- a/common/Session.cpp +++ b/common/Session.cpp @@ -87,6 +87,7 @@ void Session::parseDocOptions(const std::vector<std::string>& tokens, int& part, for (size_t i = offset; i < tokens.size(); ++i) { + // FIXME use any kind of startsWith() instead of find(...) == 0 if (tokens[i].find("url=") == 0) { _docURL = tokens[i].substr(strlen("url=")); @@ -120,6 +121,11 @@ void Session::parseDocOptions(const std::vector<std::string>& tokens, int& part, _haveDocPassword = true; ++offset; } + else if (tokens[i].find("lang=") == 0) + { + _lang = tokens[i].substr(strlen("lang=")); + ++offset; + } } if (tokens.size() > offset) diff --git a/common/Session.hpp b/common/Session.hpp index d12a7042..c8f2e63b 100644 --- a/common/Session.hpp +++ b/common/Session.hpp @@ -116,19 +116,19 @@ private: std::mutex _mutex; protected: - // The actual URL, also in the child, even if the child never accesses that. + /// The actual URL, also in the child, even if the child never accesses that. std::string _docURL; - // The Jailed document path. + /// The Jailed document path. std::string _jailedFilePath; - // Password provided, if any, to open the document + /// Password provided, if any, to open the document std::string _docPassword; - // If password is provided or not + /// If password is provided or not bool _haveDocPassword; - // Whether document is password protected + /// Whether document is password protected bool _isDocPasswordProtected; /// Document options: a JSON string, containing options (rendering, also possibly load in the future). @@ -139,6 +139,9 @@ protected: /// Name of the user to whom the session belongs to std::string _userName; + + /// Language for the document based on what the user has in the UI. + std::string _lang; }; #endif diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp index de84a398..f62fe306 100644 --- a/kit/ChildSession.cpp +++ b/kit/ChildSession.cpp @@ -326,7 +326,7 @@ bool ChildSession::loadDocument(const char * /*buffer*/, int /*length*/, const s std::unique_lock<std::recursive_mutex> lock(Mutex); - bool loaded = _docManager.onLoad(getId(), _jailedFilePath, _userName, _docPassword, renderOpts, _haveDocPassword); + bool loaded = _docManager.onLoad(getId(), _jailedFilePath, _userName, _docPassword, renderOpts, _haveDocPassword, _lang); if (!loaded || _viewId < 0) { LOG_ERR("Failed to get LoKitDocument instance."); diff --git a/kit/ChildSession.hpp b/kit/ChildSession.hpp index da609b58..ce47ed4c 100644 --- a/kit/ChildSession.hpp +++ b/kit/ChildSession.hpp @@ -35,7 +35,8 @@ public: const std::string& userName, const std::string& docPassword, const std::string& renderOpts, - const bool haveDocPassword) = 0; + const bool haveDocPassword, + const std::string& lang) = 0; /// Unload a client session, which unloads the document /// if it is the last and only. diff --git a/kit/Kit.cpp b/kit/Kit.cpp index 9886a8c5..58f79b28 100644 --- a/kit/Kit.cpp +++ b/kit/Kit.cpp @@ -907,7 +907,8 @@ private: const std::string& userName, const std::string& docPassword, const std::string& renderOpts, - const bool haveDocPassword) override + const bool haveDocPassword, + const std::string& lang) override { std::unique_lock<std::mutex> lock(_mutex); @@ -936,7 +937,7 @@ private: try { - if (!load(session, uri, userName, docPassword, renderOpts, haveDocPassword)) + if (!load(session, uri, userName, docPassword, renderOpts, haveDocPassword, lang)) { return false; } @@ -1126,7 +1127,8 @@ private: const std::string& userName, const std::string& docPassword, const std::string& renderOpts, - const bool haveDocPassword) + const bool haveDocPassword, + const std::string& lang) { const std::string sessionId = session->getId(); @@ -1151,9 +1153,13 @@ private: _jailedUrl = uri; _isDocPasswordProtected = false; - LOG_DBG("Calling lokit::documentLoad(" << uri << ")."); + std::string options; + if (!lang.empty()) + options = "Language=" + lang; + + LOG_DBG("Calling lokit::documentLoad(" << uri << ", \"" << options << "\")."); Timestamp timestamp; - _loKitDocument.reset(_loKit->documentLoad(uri.c_str())); + _loKitDocument.reset(_loKit->documentLoad(uri.c_str(), options.c_str())); LOG_DBG("Returned lokit::documentLoad(" << uri << ") in " << (timestamp.elapsed() / 1000.) << "ms."); if (!_loKitDocument || !_loKitDocument->get()) diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js index 477fb7b6..ea8f15e9 100644 --- a/loleaflet/src/core/Socket.js +++ b/loleaflet/src/core/Socket.js @@ -124,6 +124,9 @@ L.Socket = L.Class.extend({ if (this._map._docPassword) { msg += ' password=' + this._map._docPassword; } + if (String.locale) { + msg += ' lang=' + String.locale; + } if (this._map.options.renderingOptions) { var options = { 'rendering': this._map.options.renderingOptions diff --git a/test/WhiteBoxTests.cpp b/test/WhiteBoxTests.cpp index 27469d4c..7ddba7d2 100644 --- a/test/WhiteBoxTests.cpp +++ b/test/WhiteBoxTests.cpp @@ -310,7 +310,8 @@ public: const std::string& /*userName*/, const std::string& /*docPassword*/, const std::string& /*renderOpts*/, - const bool /*haveDocPassword*/) override + const bool /*haveDocPassword*/, + const std::string& /*lang*/) override { return false; } diff --git a/wsd/ClientSession.cpp b/wsd/ClientSession.cpp index 181fae67..73e4cb5b 100644 --- a/wsd/ClientSession.cpp +++ b/wsd/ClientSession.cpp @@ -268,6 +268,11 @@ bool ClientSession::loadDocument(const char* /*buffer*/, int /*length*/, oss << " password=" << _docPassword; } + if (!_lang.empty()) + { + oss << " lang=" << _lang; + } + if (!_docOptions.empty()) { oss << " options=" << _docOptions; diff --git a/wsd/protocol.txt b/wsd/protocol.txt index 867380b3..e686430b 100644 --- a/wsd/protocol.txt +++ b/wsd/protocol.txt @@ -65,13 +65,16 @@ load <pathname> Deprecated. -load [part=<partNumber>] url=<url> [timestamp=<time>] [options=<options>] +load [part=<partNumber>] url=<url> [timestamp=<time>] [lang=<locale>] [options=<options>] part is an optional parameter. <partNumber> is a number. timestamp is an optional parameter. <time> is provided in microseconds since the Unix epoch - midnight, January 1, 1970. + lang specifies the locale to which we should switch before loading the + document + options are the whole rest of the line, not URL-encoded, and must be valid JSON. loolclient <major.minor[-patch]> _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits