[Libreoffice-commits] online.git: Branch 'distro/collabora/collabora-online-2-0' - common/Session.cpp common/Session.hpp kit/ChildSession.cpp kit/ChildSession.hpp kit/Kit.cpp loleaflet/src test/WhiteBoxTests.cpp wsd/ClientSession.cpp wsd/protocol.txt

Jan Holesovsky kendy at collabora.com
Mon Mar 27 12:36:30 UTC 2017


 common/Session.cpp           |    6 ++++++
 common/Session.hpp           |   13 ++++++++-----
 kit/ChildSession.cpp         |    2 +-
 kit/ChildSession.hpp         |    4 ++--
 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(+), 15 deletions(-)

New commits:
commit c1fc9a8ed403c15871d9efa30000672f74604f4a
Author: Jan Holesovsky <kendy at 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 e1a3f364..ec251c9b 100644
--- a/common/Session.cpp
+++ b/common/Session.cpp
@@ -132,6 +132,7 @@ void LOOLSession::parseDocOptions(const StringTokenizer& tokens, int& part, std:
 
     for (size_t i = offset; i < tokens.count(); ++i)
     {
+        // FIXME use any kind of startsWith() instead of find(...) == 0
         if (tokens[i].find("url=") == 0)
         {
             _docURL = tokens[i].substr(strlen("url="));
@@ -165,6 +166,11 @@ void LOOLSession::parseDocOptions(const StringTokenizer& tokens, int& part, std:
             _haveDocPassword = true;
             ++offset;
         }
+        else if (tokens[i].find("lang=") == 0)
+        {
+            _lang = tokens[i].substr(strlen("lang="));
+            ++offset;
+        }
     }
 
     if (tokens.count() > offset)
diff --git a/common/Session.hpp b/common/Session.hpp
index 9873aad6..fb3029ec 100644
--- a/common/Session.hpp
+++ b/common/Session.hpp
@@ -161,19 +161,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).
@@ -184,6 +184,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;
 };
 
 template <typename charT, typename traits>
diff --git a/kit/ChildSession.cpp b/kit/ChildSession.cpp
index da6e67b7..871858fb 100644
--- a/kit/ChildSession.cpp
+++ b/kit/ChildSession.cpp
@@ -328,7 +328,7 @@ bool ChildSession::loadDocument(const char * /*buffer*/, int /*length*/, StringT
 
     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 c2fb09cb..47f667e7 100644
--- a/kit/ChildSession.hpp
+++ b/kit/ChildSession.hpp
@@ -36,8 +36,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 9d6ff445..1fa3bea9 100644
--- a/kit/Kit.cpp
+++ b/kit/Kit.cpp
@@ -904,7 +904,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);
 
@@ -922,7 +923,7 @@ private:
 
         try
         {
-            load(sessionId, uri, userName, docPassword, renderOpts, haveDocPassword);
+            load(sessionId, uri, userName, docPassword, renderOpts, haveDocPassword, lang);
             if (!_loKitDocument || !_loKitDocument->get())
             {
                 return false;
@@ -1107,7 +1108,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 auto it = _sessions.find(sessionId);
         if (it == _sessions.end() || !it->second)
@@ -1138,8 +1140,12 @@ private:
             _jailedUrl = uri;
             _isDocPasswordProtected = false;
 
-            LOG_DBG("Calling lokit::documentLoad.");
-            _loKitDocument.reset(_loKit->documentLoad(uri.c_str()));
+            std::string options;
+            if (!lang.empty())
+                options = "Language=" + lang;
+
+            LOG_DBG("Calling lokit::documentLoad(" << uri << ", \"" << options << "\").");
+            _loKitDocument.reset(_loKit->documentLoad(uri.c_str(), options.c_str()));
             LOG_DBG("Returned lokit::documentLoad.");
             std::unique_lock<std::mutex> l(_documentMutex);
             lockLokDoc.swap(l);
diff --git a/loleaflet/src/core/Socket.js b/loleaflet/src/core/Socket.js
index 64fdf16b..a08d7018 100644
--- a/loleaflet/src/core/Socket.js
+++ b/loleaflet/src/core/Socket.js
@@ -116,6 +116,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 75b9ec6f..eaf9abdb 100644
--- a/test/WhiteBoxTests.cpp
+++ b/test/WhiteBoxTests.cpp
@@ -268,7 +268,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 e7a81ab0..a6e94b9e 100644
--- a/wsd/ClientSession.cpp
+++ b/wsd/ClientSession.cpp
@@ -282,6 +282,11 @@ bool ClientSession::loadDocument(const char* /*buffer*/, int /*length*/, StringT
         if (_haveDocPassword)
             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 d20b5985..5c7242a2 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]>


More information about the Libreoffice-commits mailing list