loleaflet/dist/toolbar/toolbar.js | 23 ++++++++++++++++++++++- loolwsd/ChildSession.cpp | 2 +- loolwsd/ChildSession.hpp | 1 + loolwsd/ClientSession.cpp | 3 +++ loolwsd/ClientSession.hpp | 2 ++ loolwsd/LOOLKit.cpp | 34 ++++++++++++++++++++++++++++++++-- loolwsd/LOOLSession.cpp | 5 +++++ loolwsd/LOOLSession.hpp | 3 +++ loolwsd/LOOLWSD.cpp | 7 ++++++- 9 files changed, 75 insertions(+), 5 deletions(-)
New commits: commit 67444eeb80ad521edcab905217c4777cdeacb8c2 Author: Pranav Kant <pran...@collabora.co.uk> Date: Mon Aug 29 23:38:01 2016 +0530 loolwsd: Pass sessions' usernames to core Change-Id: I8c81c02fafd2cb9d0048729401e082bb422e299b Reviewed-on: https://gerrit.libreoffice.org/28481 Reviewed-by: pranavk <pran...@collabora.co.uk> Tested-by: pranavk <pran...@collabora.co.uk> diff --git a/loolwsd/ChildSession.cpp b/loolwsd/ChildSession.cpp index 3575fa9..67aae9c 100644 --- a/loolwsd/ChildSession.cpp +++ b/loolwsd/ChildSession.cpp @@ -317,7 +317,7 @@ bool ChildSession::loadDocument(const char * /*buffer*/, int /*length*/, StringT std::unique_lock<std::recursive_mutex> lock(Mutex); - _loKitDocument = _docManager.onLoad(getId(), _jailedFilePath, _docPassword, renderOpts, _haveDocPassword); + _loKitDocument = _docManager.onLoad(getId(), _jailedFilePath, _userName, _docPassword, renderOpts, _haveDocPassword); if (!_loKitDocument) { Log::error("Failed to get LoKitDocument instance."); diff --git a/loolwsd/ChildSession.hpp b/loolwsd/ChildSession.hpp index 93fc820..649a7d3 100644 --- a/loolwsd/ChildSession.hpp +++ b/loolwsd/ChildSession.hpp @@ -30,6 +30,7 @@ public: virtual std::shared_ptr<lok::Document> onLoad(const std::string& sessionId, const std::string& jailedFilePath, + const std::string& userName, const std::string& docPassword, const std::string& renderOpts, const bool haveDocPassword) = 0; diff --git a/loolwsd/ClientSession.cpp b/loolwsd/ClientSession.cpp index c0607a9..c4ac637 100644 --- a/loolwsd/ClientSession.cpp +++ b/loolwsd/ClientSession.cpp @@ -228,6 +228,9 @@ bool ClientSession::loadDocument(const char* /*buffer*/, int /*length*/, StringT oss << " url=" << _docBroker->getPublicUri().toString(); oss << " jail=" << _docBroker->getJailedUri().toString(); + if (!_userName.empty()) + oss << " author=" + _userName; + if (_loadPart >= 0) oss << " part=" + std::to_string(_loadPart); diff --git a/loolwsd/ClientSession.hpp b/loolwsd/ClientSession.hpp index b6126a5..dc531c8 100644 --- a/loolwsd/ClientSession.hpp +++ b/loolwsd/ClientSession.hpp @@ -36,6 +36,8 @@ public: void setPeer(const std::shared_ptr<PrisonerSession>& peer) { _peer = peer; } bool shutdownPeer(Poco::UInt16 statusCode, const std::string& message); + void setUserName(const std::string& userName) { _userName = userName; } + /** * Return the URL of the saved-as document when it's ready. If called * before it's ready, the call blocks till then. diff --git a/loolwsd/LOOLKit.cpp b/loolwsd/LOOLKit.cpp index 44b8b2c..6f4898d 100644 --- a/loolwsd/LOOLKit.cpp +++ b/loolwsd/LOOLKit.cpp @@ -26,11 +26,14 @@ #include <cstdlib> #include <iostream> #include <memory> +#include <sstream> #define LOK_USE_UNSTABLE_API #include <LibreOfficeKit/LibreOfficeKitInit.h> #include <Poco/Exception.h> +#include <Poco/JSON/Object.h> +#include <Poco/JSON/Parser.h> #include <Poco/Net/HTTPClientSession.h> #include <Poco/Net/HTTPRequest.h> #include <Poco/Net/HTTPResponse.h> @@ -66,6 +69,8 @@ typedef int (LokHookPreInit) (const char *install_path, const char *user_profil using Poco::AutoPtr; using Poco::Exception; using Poco::File; +using Poco::JSON::Object; +using Poco::JSON::Parser; using Poco::Net::HTTPClientSession; using Poco::Net::HTTPRequest; using Poco::Net::HTTPResponse; @@ -841,6 +846,7 @@ private: /// Load a document (or view) and register callbacks. std::shared_ptr<lok::Document> onLoad(const std::string& sessionId, const std::string& uri, + const std::string& userName, const std::string& docPassword, const std::string& renderOpts, const bool haveDocPassword) override @@ -859,7 +865,7 @@ private: try { - load(sessionId, uri, docPassword, renderOpts, haveDocPassword); + load(sessionId, uri, userName, docPassword, renderOpts, haveDocPassword); if (!_loKitDocument || !_loKitDocument->get()) { return nullptr; @@ -963,6 +969,7 @@ private: std::shared_ptr<lok::Document> load(const std::string& sessionId, const std::string& uri, + const std::string& userName, const std::string& docPassword, const std::string& renderOpts, const bool haveDocPassword) @@ -1064,9 +1071,32 @@ private: } } + Object::Ptr renderOptsObj = new Object(); + + // Fill the object with renderoptions, if any + if (!_renderOpts.empty()) { + Parser parser; + Poco::Dynamic::Var var = parser.parse(_renderOpts); + renderOptsObj = var.extract<Object::Ptr>(); + } + + // Append name of the user, if any, who opened the document to rendering options + if (!userName.empty()) + { + Object::Ptr authorContainer = new Object(); + Object::Ptr authorObj = new Object(); + authorObj->set("type", "string"); + authorObj->set("value", userName); + + renderOptsObj->set(".uno:Author", authorObj); + } + + std::ostringstream ossRenderOpts; + renderOptsObj->stringify(ossRenderOpts); + // initializeForRendering() should be called before // registerCallback(), as the previous creates a new view in Impress. - _loKitDocument->initializeForRendering(_renderOpts.c_str()); + _loKitDocument->initializeForRendering(ossRenderOpts.str().c_str()); if (_multiView) { diff --git a/loolwsd/LOOLSession.cpp b/loolwsd/LOOLSession.cpp index 091fd48..1e0686f 100644 --- a/loolwsd/LOOLSession.cpp +++ b/loolwsd/LOOLSession.cpp @@ -159,6 +159,11 @@ void LOOLSession::parseDocOptions(const StringTokenizer& tokens, int& part, std: _jailedFilePath = tokens[i].substr(strlen("jail=")); ++offset; } + else if (tokens[i].find("author=") == 0) + { + _userName = tokens[i].substr(strlen("author=")); + ++offset; + } else if (tokens[i].find("timestamp=") == 0) { timestamp = tokens[i].substr(strlen("timestamp=")); diff --git a/loolwsd/LOOLSession.hpp b/loolwsd/LOOLSession.hpp index 71d1e9f..0153339 100644 --- a/loolwsd/LOOLSession.hpp +++ b/loolwsd/LOOLSession.hpp @@ -175,6 +175,9 @@ protected: /// Document options: a JSON string, containing options (rendering, also possibly load in the future). std::string _docOptions; + + /// Name of the user to whom the session belongs to + std::string _userName; }; template<typename charT, typename traits> diff --git a/loolwsd/LOOLWSD.cpp b/loolwsd/LOOLWSD.cpp index 0de8e73..5749f9c 100644 --- a/loolwsd/LOOLWSD.cpp +++ b/loolwsd/LOOLWSD.cpp @@ -642,7 +642,7 @@ private: // Validate the URI and Storage before moving on. const auto fileinfo = docBroker->validate(uriPublic); - Log::debug("Validated [" + uriPublic.toString() + "] requested with userid [" + fileinfo._userId + "] and username [" + fileinfo._userName + "]"); + Log::debug("Validated [" + uriPublic.toString() + "]"); if (newDoc) { @@ -668,6 +668,11 @@ private: // thread to pump them. This is to empty the queue when we get a "canceltiles" message. auto queue = std::make_shared<BasicTileQueue>(); session = std::make_shared<ClientSession>(id, ws, docBroker, queue, isReadOnly); + if (!fileinfo._userName.empty()) + { + Log::debug(uriPublic.toString() + " requested with username [" + fileinfo._userName + "]"); + session->setUserName(fileinfo._userName); + } // Request the child to connect to us and add this session. auto sessionsCount = docBroker->addSession(session); commit 3d29df6f998df339896b1355b6fa9186dcc60892 Author: Pranav Kant <pran...@collabora.co.uk> Date: Mon Aug 29 16:58:38 2016 +0530 loleaflet: Show a user list in bottom toolbar Change-Id: I5aa87a6da3c6af9da0138bdfe51fbb707a47ba3e Reviewed-on: https://gerrit.libreoffice.org/28480 Reviewed-by: pranavk <pran...@collabora.co.uk> Tested-by: pranavk <pran...@collabora.co.uk> diff --git a/loleaflet/dist/toolbar/toolbar.js b/loleaflet/dist/toolbar/toolbar.js index a78d3fe..7637cf9 100644 --- a/loleaflet/dist/toolbar/toolbar.js +++ b/loleaflet/dist/toolbar/toolbar.js @@ -10,6 +10,17 @@ function onDelete(e) { } } +function onChangeUserList() { + var usernames = []; + for (var viewid in map._viewInfo) { + usernames.push(map._viewInfo[viewid]); + } + + $('#userlist').w2field('list', { + items: usernames + }); +} + function resizeToolbar() { var hasMoreItems = false; var toolbarUp = w2ui['toolbar-up']; @@ -467,6 +478,8 @@ $(function () { {type: 'html', id: 'right'}, {type: 'html', id: 'modifiedstatuslabel', html: '<div id="modifiedstatuslabel" class="loleaflet-font"></div>'}, {type: 'break'}, + {type: 'html', id: 'userlistcontainer', html: '<div><label>Users: </label><input id="userlist" type="list" /></div>'}, + {type: 'break'}, {type: 'button', id: 'prev', img: 'prev', hint: _('Previous page')}, {type: 'button', id: 'next', img: 'next', hint: _('Next page')}, {type: 'break', id: 'prevnextbreak'}, @@ -494,7 +507,6 @@ var formatButtons = { var takeEditPopupMessage = '<div>' + _('You are viewing now.') + '<br/>' + _('Click here to take edit.') + '</div>'; var takeEditPopupTimeout = null; - function toggleButton(toolbar, state, command) { var checked; @@ -1346,6 +1358,15 @@ map.on('statusindicator', function (e) { } }); +// TODO: Dynamically add/remove users from list +map.on('addview', function(e) { + onChangeUserList(); +}); + +map.on('removeview', function(e) { + onChangeUserList(); +}); + $(window).resize(function() { resizeToolbar(); }); _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits