sw/inc/editsh.hxx | 5 ++ sw/source/core/edit/edfcol.cxx | 68 ++++++++++++++++++++++----------------- sw/source/core/txtnode/ndtxt.cxx | 2 - 3 files changed, 44 insertions(+), 31 deletions(-)
New commits: commit 83a72f46d34fde7a119b00fcc0a7bf58dbe0076a Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> AuthorDate: Tue Oct 2 06:02:39 2018 -0400 Commit: Ashod Nakashian <ashnak...@gmail.com> CommitDate: Mon Dec 3 08:12:39 2018 +0100 sw: paragraph-sign: formatting Change-Id: I9bf1b58aa6e18202a5f7eba010cc5b914e1d33d4 Reviewed-on: https://gerrit.libreoffice.org/63005 Tested-by: Jenkins Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx index f2be581ff73f..083ad320fbec 100644 --- a/sw/source/core/edit/edfcol.cxx +++ b/sw/source/core/edit/edfcol.cxx @@ -359,14 +359,16 @@ SignatureDescr lcl_getSignatureDescr(const uno::Reference<frame::XModel>& xModel SignatureDescr aDescr; aDescr.msId = sFieldId; + const OUString prefix = ParagraphSignatureRDFNamespace + sFieldId; const std::map<OUString, OUString> aStatements = lcl_getRDFStatements(xModel, xParagraph); - const auto itSig = aStatements.find(ParagraphSignatureRDFNamespace + sFieldId + ParagraphSignatureDigestRDFName); + + const auto itSig = aStatements.find(prefix + ParagraphSignatureDigestRDFName); aDescr.msSignature = (itSig != aStatements.end() ? itSig->second : OUString()); - const auto itDate = aStatements.find(ParagraphSignatureRDFNamespace + sFieldId + ParagraphSignatureDateRDFName); + const auto itDate = aStatements.find(prefix + ParagraphSignatureDateRDFName); aDescr.msDate = (itDate != aStatements.end() ? itDate->second : OUString()); - const auto itUsage = aStatements.find(ParagraphSignatureRDFNamespace + sFieldId + ParagraphSignatureUsageRDFName); + const auto itUsage = aStatements.find(prefix + ParagraphSignatureUsageRDFName); aDescr.msUsage = (itUsage != aStatements.end() ? itUsage->second : OUString()); return aDescr; @@ -376,14 +378,16 @@ SignatureDescr lcl_getSignatureDescr(const uno::Reference<frame::XModel>& xModel const uno::Reference<css::text::XTextContent>& xParagraph, const uno::Reference<css::text::XTextField>& xField) { - const std::pair<OUString, OUString> pair = lcl_getRDF(xModel, xField, ParagraphSignatureIdRDFName); - return (!pair.second.isEmpty() ? lcl_getSignatureDescr(xModel, xParagraph, pair.second) : SignatureDescr()); + const OUString sFieldId = lcl_getRDF(xModel, xField, ParagraphSignatureIdRDFName).second; + if (!sFieldId.isEmpty()) + return lcl_getSignatureDescr(xModel, xParagraph, sFieldId); + + return SignatureDescr(); } /// Validate and create the signature field display text from the fields. -std::pair<bool, OUString> -lcl_MakeParagraphSignatureFieldText(const SignatureDescr& aDescr, - const OString& utf8Text) +std::pair<bool, OUString> lcl_MakeParagraphSignatureFieldText(const SignatureDescr& aDescr, + const OString& utf8Text) { OUString msg = SwResId(STR_INVALID_SIGNATURE); bool valid = false; @@ -399,7 +403,8 @@ lcl_MakeParagraphSignatureFieldText(const SignatureDescr& aDescr, const std::vector<unsigned char> sig(svl::crypto::DecodeHexString(encSignature)); SignatureInformation aInfo(0); valid = svl::crypto::Signing::Verify(data, false, sig, aInfo); - valid = valid && aInfo.nStatus == css::xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED; + valid = valid + && aInfo.nStatus == xml::crypto::SecurityOperationStatus_OPERATION_SUCCEEDED; msg = SwResId(STR_SIGNED_BY) + ": " + aInfo.ouSubject + ", "; msg += aDescr.msDate; @@ -411,7 +416,6 @@ lcl_MakeParagraphSignatureFieldText(const SignatureDescr& aDescr, return std::make_pair(valid, msg); } - /// Validate and return validation result and signature field display text. std::pair<bool, OUString> lcl_MakeParagraphSignatureFieldText(const uno::Reference<frame::XModel>& xModel, @@ -427,11 +431,10 @@ lcl_MakeParagraphSignatureFieldText(const uno::Reference<frame::XModel>& xModel, OUString lcl_getNextSignatureId(const uno::Reference<frame::XModel>& xModel, const uno::Reference<text::XTextContent>& xParagraph) { - const std::pair<OUString, OUString> pair = lcl_getRDF(xModel, xParagraph, ParagraphSignatureLastIdRDFName); - return OUString::number(!pair.second.isEmpty() ? pair.second.toInt32() + 1 : 1); + const OUString sFieldId = lcl_getRDF(xModel, xParagraph, ParagraphSignatureLastIdRDFName).second; + return OUString::number(!sFieldId.isEmpty() ? sFieldId.toInt32() + 1 : 1); } - /// Creates and inserts Paragraph Signature Metadata field and creates the RDF entry uno::Reference<text::XTextField> lcl_InsertParagraphSignature(const uno::Reference<frame::XModel>& xModel, const uno::Reference<text::XTextContent>& xParagraph, @@ -465,10 +468,11 @@ uno::Reference<text::XTextField> lcl_InsertParagraphSignature(const uno::Referen // Now set the RDF on the paragraph, since that's what is preserved in .doc(x). const css::uno::Reference<css::rdf::XResource> xParaSubject(xParagraph, uno::UNO_QUERY); + const OUString prefix = ParagraphSignatureRDFNamespace + sId; SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xParaSubject, ParagraphSignatureLastIdRDFName, sId); - SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xParaSubject, ParagraphSignatureRDFNamespace + sId + ParagraphSignatureDigestRDFName, signature); - SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xParaSubject, ParagraphSignatureRDFNamespace + sId + ParagraphSignatureUsageRDFName, usage); - SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xParaSubject, ParagraphSignatureRDFNamespace + sId + ParagraphSignatureDateRDFName, rBuffer.makeStringAndClear()); + SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xParaSubject, prefix + ParagraphSignatureDigestRDFName, signature); + SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xParaSubject, prefix + ParagraphSignatureUsageRDFName, usage); + SwRDFHelper::addStatement(xModel, MetaNS, MetaFilename, xParaSubject, prefix + ParagraphSignatureDateRDFName, rBuffer.makeStringAndClear()); return xField; } @@ -511,8 +515,9 @@ bool lcl_UpdateParagraphSignatureField(SwDoc* pDoc, const uno::Reference<css::text::XTextField>& xField, const OString& utf8Text) { - const std::pair<bool, OUString> res = lcl_MakeParagraphSignatureFieldText(xModel, xParagraph, xField, utf8Text); - return lcl_DoUpdateParagraphSignatureField(pDoc, xField, res.second); + const OUString sDisplayText + = lcl_MakeParagraphSignatureFieldText(xModel, xParagraph, xField, utf8Text).second; + return lcl_DoUpdateParagraphSignatureField(pDoc, xField, sDisplayText); } void lcl_RemoveParagraphMetadataField(const uno::Reference<css::text::XTextField>& xField) commit 6ad096aeeb5c85a82fba70526569f074b67a083c Author: Ashod Nakashian <ashod.nakash...@collabora.co.uk> AuthorDate: Tue Oct 2 05:20:38 2018 -0400 Commit: Ashod Nakashian <ashnak...@gmail.com> CommitDate: Mon Dec 3 08:12:23 2018 +0100 sw: paragraph-sign: validate current SwTextNode directly When invoking undo, it turns out that the cursor position is updated after the text modification, which triggers the paragraph signature validation. Relying on the cursor position, then, results in the wrong (previous) paragraph to be validated (if the undo is in a different paragraph). Since we have the correct SwTextNode when it's modified (due to undo or otherwise), there is no reason why we shouldn't use it and try to deduce it from the cursor. Change-Id: I4c3283d59738988dcc1c592a9f3ef2c818ce675d Reviewed-on: https://gerrit.libreoffice.org/63004 Tested-by: Jenkins Reviewed-by: Ashod Nakashian <ashnak...@gmail.com> diff --git a/sw/inc/editsh.hxx b/sw/inc/editsh.hxx index 3da4e3617ca0..6dd4c1ca9a9b 100644 --- a/sw/inc/editsh.hxx +++ b/sw/inc/editsh.hxx @@ -366,7 +366,10 @@ public: /// Sign the paragraph at the cursor. void SignParagraph(); - /// Validate current paragraph signatures, if any, at the cursor start. + /// Validate the paragraph signatures, if any, of the current text node. + void ValidateParagraphSignatures(SwTextNode* pNode, bool updateDontRemove); + + /// Validate the current paragraph signatures, if any, at the cursor start. void ValidateCurrentParagraphSignatures(bool updateDontRemove); /// Validate all paragraph signatures. diff --git a/sw/source/core/edit/edfcol.cxx b/sw/source/core/edit/edfcol.cxx index b827f9306fc1..f2be581ff73f 100644 --- a/sw/source/core/edit/edfcol.cxx +++ b/sw/source/core/edit/edfcol.cxx @@ -1804,16 +1804,13 @@ void SwEditShell::SignParagraph() GetDoc()->GetIDocumentUndoRedo().EndUndo(SwUndoId::PARA_SIGN_ADD, nullptr); } -void SwEditShell::ValidateCurrentParagraphSignatures(bool updateDontRemove) +void SwEditShell::ValidateParagraphSignatures(SwTextNode* pNode, bool updateDontRemove) { - SwDocShell* pDocShell = GetDoc()->GetDocShell(); - if (!pDocShell || !GetCursor() || !GetCursor()->Start() || !IsParagraphSignatureValidationEnabled()) + if (!pNode || !IsParagraphSignatureValidationEnabled()) return; - SwPaM* pPaM = GetCursor(); - const SwPosition* pPosStart = pPaM->Start(); - SwTextNode* pNode = pPosStart->nNode.GetNode().GetTextNode(); - if (!pNode) + // Table text signing is not supported. + if (pNode->FindTableNode() != nullptr) return; // Prevent recursive validation since this is triggered on node updates, which we do below. @@ -1822,12 +1819,20 @@ void SwEditShell::ValidateCurrentParagraphSignatures(bool updateDontRemove) SetParagraphSignatureValidation(bOldValidationFlag); }); - // Table text signing is not supported. - if (pNode->FindTableNode() != nullptr) + uno::Reference<text::XTextContent> xParentText = SwXParagraph::CreateXParagraph(*GetDoc(), pNode); + lcl_ValidateParagraphSignatures(GetDoc(), xParentText, updateDontRemove); +} + +void SwEditShell::ValidateCurrentParagraphSignatures(bool updateDontRemove) +{ + SwDocShell* pDocShell = GetDoc()->GetDocShell(); + if (!pDocShell || !GetCursor() || !GetCursor()->Start() || !IsParagraphSignatureValidationEnabled()) return; - uno::Reference<text::XTextContent> xParentText = SwXParagraph::CreateXParagraph(*pNode->GetDoc(), pNode); - lcl_ValidateParagraphSignatures(GetDoc(), xParentText, updateDontRemove); + SwPaM* pPaM = GetCursor(); + const SwPosition* pPosStart = pPaM->Start(); + SwTextNode* pNode = pPosStart->nNode.GetNode().GetTextNode(); + ValidateParagraphSignatures(pNode, updateDontRemove); } void SwEditShell::ValidateAllParagraphSignatures(bool updateDontRemove) diff --git a/sw/source/core/txtnode/ndtxt.cxx b/sw/source/core/txtnode/ndtxt.cxx index ce948ec68c3c..4c756a5466c2 100644 --- a/sw/source/core/txtnode/ndtxt.cxx +++ b/sw/source/core/txtnode/ndtxt.cxx @@ -1541,7 +1541,7 @@ void SwTextNode::Update( // Update the paragraph signatures. if (SwEditShell* pEditShell = GetDoc()->GetEditShell()) { - pEditShell->ValidateCurrentParagraphSignatures(true); + pEditShell->ValidateParagraphSignatures(this, true); } // Inform LOK clients about change in position of redlines (if any) _______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits