[Libreoffice-commits] online.git: loolwsd/ChildProcessSession.cpp loolwsd/LOKitHelper.hpp
Ashod Nakashian
ashod.nakashian at collabora.co.uk
Sun May 8 04:28:37 UTC 2016
loolwsd/ChildProcessSession.cpp | 9 +++-----
loolwsd/LOKitHelper.hpp | 42 ++++++++++++++++++++++++----------------
2 files changed, 30 insertions(+), 21 deletions(-)
New commits:
commit 1a896de0a771e7bba3ceaf919490ac34d7a4da62
Author: Ashod Nakashian <ashod.nakashian at collabora.co.uk>
Date: Sat May 7 23:27:15 2016 -0400
loolwsd: getStatus and status formatting cleanup
Change-Id: Ifd842d7ded1be1f4c89d8371790f19a3909c9729
Reviewed-on: https://gerrit.libreoffice.org/24744
Reviewed-by: Ashod Nakashian <ashnakash at gmail.com>
Tested-by: Ashod Nakashian <ashnakash at gmail.com>
diff --git a/loolwsd/ChildProcessSession.cpp b/loolwsd/ChildProcessSession.cpp
index 42dc2a6..cb4b16c 100644
--- a/loolwsd/ChildProcessSession.cpp
+++ b/loolwsd/ChildProcessSession.cpp
@@ -654,15 +654,14 @@ bool ChildProcessSession::getStatus(const char* /*buffer*/, int /*length*/)
if (_multiView)
_loKitDocument->pClass->setView(_loKitDocument, _viewId);
- const std::string status = "status: " + LOKitHelper::documentStatus(_loKitDocument);
- StringTokenizer tokens(status, " ", StringTokenizer::TOK_IGNORE_EMPTY | StringTokenizer::TOK_TRIM);
- if (!getTokenString(tokens[1], "type", _docType))
+ const auto status = LOKitHelper::documentStatus(_loKitDocument);
+ if (status.empty())
{
- Log::error("failed to get document type from status [" + status + "].");
+ Log::error("Failed to get document status.");
return false;
}
- sendTextFrame(status);
+ sendTextFrame("status: " + status);
return true;
}
diff --git a/loolwsd/LOKitHelper.hpp b/loolwsd/LOKitHelper.hpp
index 84b0e61..e621e67 100644
--- a/loolwsd/LOKitHelper.hpp
+++ b/loolwsd/LOKitHelper.hpp
@@ -11,6 +11,7 @@
#define INCLUDED_LOKITHELPER_HPP
#include <string>
+#include <sstream>
#define LOK_USE_UNSTABLE_API
#include <LibreOfficeKit/LibreOfficeKit.h>
@@ -98,27 +99,36 @@ namespace LOKitHelper
inline
std::string documentStatus(LibreOfficeKitDocument *loKitDocument)
{
- std::string typeString(documentTypeToString(static_cast<LibreOfficeKitDocumentType>(loKitDocument->pClass->getDocumentType(loKitDocument))));
- long width, height, parts;
+ const auto type = static_cast<LibreOfficeKitDocumentType>(loKitDocument->pClass->getDocumentType(loKitDocument));
+
+ const auto parts = loKitDocument->pClass->getParts(loKitDocument);
+ std::ostringstream oss;
+ oss << " type=" << documentTypeToString(type)
+ << " parts=" << parts
+ << " current=" << loKitDocument->pClass->getPart(loKitDocument);
+
+ long width, height;
loKitDocument->pClass->getDocumentSize(loKitDocument, &width, &height);
- parts = loKitDocument->pClass->getParts(loKitDocument);
- std::string status =
- ("type=" + typeString + " "
- "parts=" + std::to_string(parts) + " "
- "current=" + std::to_string(loKitDocument->pClass->getPart(loKitDocument)) + " "
- "width=" + std::to_string(width) + " "
- "height=" + std::to_string(height));
- if (typeString == "spreadsheet" || typeString == "presentation")
+ oss << " width=" << width
+ << " height=" << height;
+
+ if (type == LOK_DOCTYPE_SPREADSHEET || type == LOK_DOCTYPE_PRESENTATION)
{
- for (int i = 0; i < parts; i++)
+ for (auto i = 0; i < parts; ++i)
{
- status += "\n";
- status += typeString == "presentation" ?
- loKitDocument->pClass->getPartHash(loKitDocument, i):
- loKitDocument->pClass->getPartName(loKitDocument, i);
+ oss << "\n";
+ if (type == LOK_DOCTYPE_PRESENTATION)
+ {
+ oss << loKitDocument->pClass->getPartHash(loKitDocument, i);
+ }
+ else
+ {
+ oss << loKitDocument->pClass->getPartName(loKitDocument, i);
+ }
}
}
- return status;
+
+ return oss.str();
}
};
More information about the Libreoffice-commits
mailing list