diff options
author | Szymon Kłos <szymon.klos@collabora.com> | 2022-03-24 11:29:59 +0100 |
---|---|---|
committer | Szymon Kłos <szymon.klos@collabora.com> | 2022-04-11 20:59:31 +0200 |
commit | 94d59b6227bf6818b191ee37d28b6fa64b67c9cf (patch) | |
tree | 0cc211481ef6d82ec30132d365382fe106592411 /sd | |
parent | 9ae398054833120df36bf51738cc4cfd7efb3fdc (diff) |
lok: use JsonWriter for annotations notification
This will unify received objects in LOK.
boost::property_tree used "string" for number values
we expect them to be a "number" type.
Change-Id: Ie90d7e2dd98bb371fc09878dcc6e96f4cdf73f3b
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132054
Tested-by: Jenkins CollaboraOffice <jenkinscollaboraoffice@gmail.com>
Reviewed-by: Dennis Francis <dennis.francis@collabora.com>
Reviewed-on: https://gerrit.libreoffice.org/c/core/+/132808
Tested-by: Jenkins
Reviewed-by: Szymon Kłos <szymon.klos@collabora.com>
Diffstat (limited to 'sd')
-rw-r--r-- | sd/source/core/annotations/Annotation.cxx | 55 |
1 files changed, 27 insertions, 28 deletions
diff --git a/sd/source/core/annotations/Annotation.cxx b/sd/source/core/annotations/Annotation.cxx index 1d1ca39fc9dd..991412f063d5 100644 --- a/sd/source/core/annotations/Annotation.cxx +++ b/sd/source/core/annotations/Annotation.cxx @@ -22,8 +22,6 @@ #include <Annotation.hxx> #include <drawdoc.hxx> -#include <boost/property_tree/json_parser.hpp> - #include <com/sun/star/drawing/XDrawPage.hpp> #include <comphelper/processfactory.hxx> @@ -38,6 +36,8 @@ #include <notifydocumentevent.hxx> +#include <tools/json_writer.hxx> + using namespace css; namespace com::sun::star::uno { class XComponentContext; } @@ -342,34 +342,33 @@ namespace { std::string lcl_LOKGetCommentPayload(CommentNotificationType nType, uno::Reference<office::XAnnotation> const & rxAnnotation) { - boost::property_tree::ptree aAnnotation; - aAnnotation.put("action", (nType == CommentNotificationType::Add ? "Add" : - (nType == CommentNotificationType::Remove ? "Remove" : - (nType == CommentNotificationType::Modify ? "Modify" : "???")))); - aAnnotation.put("id", sd::getAnnotationId(rxAnnotation)); - if (nType != CommentNotificationType::Remove && rxAnnotation.is()) + ::tools::JsonWriter aJsonWriter; { - aAnnotation.put("id", sd::getAnnotationId(rxAnnotation)); - aAnnotation.put("author", rxAnnotation->getAuthor()); - aAnnotation.put("dateTime", utl::toISO8601(rxAnnotation->getDateTime())); - uno::Reference<text::XText> xText(rxAnnotation->getTextRange()); - aAnnotation.put("text", xText->getString()); - const SdPage* pPage = sd::getAnnotationPage(rxAnnotation); - aAnnotation.put("parthash", pPage ? OString::number(pPage->GetHashCode()) : OString()); - geometry::RealPoint2D const & rPoint = rxAnnotation->getPosition(); - geometry::RealSize2D const & rSize = rxAnnotation->getSize(); - ::tools::Rectangle aRectangle(Point(rPoint.X * 100.0, rPoint.Y * 100.0), Size(rSize.Width * 100.0, rSize.Height * 100.0)); - aRectangle = o3tl::convert(aRectangle, o3tl::Length::mm100, o3tl::Length::twip); - OString sRectangle = aRectangle.toString(); - aAnnotation.put("rectangle", sRectangle.getStr()); + auto aCommentNode = aJsonWriter.startNode("comment"); + + aJsonWriter.put("action", (nType == CommentNotificationType::Add ? "Add" : + (nType == CommentNotificationType::Remove ? "Remove" : + (nType == CommentNotificationType::Modify ? "Modify" : "???")))); + aJsonWriter.put("id", sd::getAnnotationId(rxAnnotation)); + + if (nType != CommentNotificationType::Remove && rxAnnotation.is()) + { + aJsonWriter.put("id", sd::getAnnotationId(rxAnnotation)); + aJsonWriter.put("author", rxAnnotation->getAuthor()); + aJsonWriter.put("dateTime", utl::toISO8601(rxAnnotation->getDateTime())); + uno::Reference<text::XText> xText(rxAnnotation->getTextRange()); + aJsonWriter.put("text", xText->getString()); + const SdPage* pPage = sd::getAnnotationPage(rxAnnotation); + aJsonWriter.put("parthash", pPage ? OString::number(pPage->GetHashCode()) : OString()); + geometry::RealPoint2D const & rPoint = rxAnnotation->getPosition(); + geometry::RealSize2D const & rSize = rxAnnotation->getSize(); + ::tools::Rectangle aRectangle(Point(rPoint.X * 100.0, rPoint.Y * 100.0), Size(rSize.Width * 100.0, rSize.Height * 100.0)); + aRectangle = OutputDevice::LogicToLogic(aRectangle, MapMode(MapUnit::Map100thMM), MapMode(MapUnit::MapTwip)); + OString sRectangle = aRectangle.toString(); + aJsonWriter.put("rectangle", sRectangle.getStr()); + } } - - boost::property_tree::ptree aTree; - aTree.add_child("comment", aAnnotation); - std::stringstream aStream; - boost::property_tree::write_json(aStream, aTree); - - return aStream.str(); + return aJsonWriter.extractData(); } } // anonymous ns |