summaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorMuhammet Kara <muhammet.kara@collabora.com>2019-06-12 21:21:26 +0300
committerMuhammet Kara <muhammet.kara@collabora.com>2019-08-17 16:39:49 +0200
commitad06753daebbfb69fded5ae3e5631502d16581bb (patch)
tree327d87d6f9bb6e311c4222b2187d36cd1c6b59dc
parentAuto redaction dialog 5th iteration (diff)
downloadcore-ad06753daebbfb69fded5ae3e5631502d16581bb.tar.gz
core-ad06753daebbfb69fded5ae3e5631502d16581bb.zip
Auto redaction dialog 6th iteration
* Binds everything together. * The auto redaction process works end to end now. * Only for case sensitive text content (no regex support yet) Change-Id: I6edd67472d376e2c0d91ac4b1ff90d98c49b13ac Reviewed-on: https://gerrit.libreoffice.org/73908 Tested-by: Jenkins Reviewed-by: Muhammet Kara <muhammet.kara@collabora.com> Reviewed-on: https://gerrit.libreoffice.org/77163 Tested-by: Muhammet Kara <muhammet.kara@collabora.com>
-rw-r--r--sfx2/inc/SfxRedactionHelper.hxx14
-rw-r--r--sfx2/inc/autoredactdialog.hxx13
-rw-r--r--sfx2/source/doc/SfxRedactionHelper.cxx29
-rw-r--r--sfx2/source/doc/autoredactdialog.cxx22
-rw-r--r--sfx2/source/doc/objserv.cxx12
5 files changed, 70 insertions, 20 deletions
diff --git a/sfx2/inc/SfxRedactionHelper.hxx b/sfx2/inc/SfxRedactionHelper.hxx
index 44a78ab9b877..9be54ca8ac22 100644
--- a/sfx2/inc/SfxRedactionHelper.hxx
+++ b/sfx2/inc/SfxRedactionHelper.hxx
@@ -31,6 +31,7 @@ class SfxStringItem;
class GDIMetaFile;
class DocumentToGraphicRenderer;
class SfxViewFrame;
+struct RedactionTarget;
struct PageMargins
{
@@ -66,10 +67,12 @@ public:
* Creates one shape and one draw page for each gdimetafile,
* and inserts the shapes into the newly created draw pages.
* */
- static void addPagesToDraw(uno::Reference<XComponent>& xComponent, const sal_Int32& nPages,
- const std::vector<GDIMetaFile>& aMetaFiles,
- const std::vector<::Size>& aPageSizes,
- const PageMargins& aPageMargins);
+ static void
+ addPagesToDraw(uno::Reference<XComponent>& xComponent, const sal_Int32& nPages,
+ const std::vector<GDIMetaFile>& aMetaFiles,
+ const std::vector<::Size>& aPageSizes, const PageMargins& aPageMargins,
+ const std::vector<std::pair<RedactionTarget*, OUString>>& r_aTableTargets,
+ const bool& bIsAutoRedact);
/*
* Makes the Redaction toolbar visible to the user.
* Meant to be called after converting a document to a Draw doc
@@ -104,7 +107,8 @@ public:
* Search for the given term through the gdimetafile, which has the whole content of a draw page,
* and draw redaction rectangles to the appropriate positions with suitable sizes.
* */
- static void autoRedactPage(const OUString& sRedactionTerm, const GDIMetaFile& rGDIMetaFile,
+ static void autoRedactPage(const RedactionTarget* pRedactionTarget,
+ const GDIMetaFile& rGDIMetaFile,
uno::Reference<drawing::XDrawPage>& xPage,
uno::Reference<XComponent>& xComponent);
};
diff --git a/sfx2/inc/autoredactdialog.hxx b/sfx2/inc/autoredactdialog.hxx
index 2336d66c4063..bab00cf536a3 100644
--- a/sfx2/inc/autoredactdialog.hxx
+++ b/sfx2/inc/autoredactdialog.hxx
@@ -105,6 +105,7 @@ class SFX2_DLLPUBLIC SfxAutoRedactDialog : public SfxDialogController
SfxObjectShellLock m_xDocShell;
std::vector<std::pair<RedactionTarget*, OUString>> m_aTableTargets;
std::unique_ptr<sfx2::FileDialogHelper> m_pFileDlg;
+ bool m_bIsValidState;
std::unique_ptr<weld::Label> m_xRedactionTargetsLabel;
std::unique_ptr<TargetsTable> m_xTargetsBox;
@@ -133,10 +134,16 @@ public:
SfxAutoRedactDialog(weld::Window* pParent);
virtual ~SfxAutoRedactDialog() override;
- /*
- * Check if the dialog has any valid redaction targets.
- */
+ /// Check if the dialog has any valid redaction targets.
bool hasTargets() const;
+ /// Check if the dialog is in a valid state.
+ bool isValidState() const { return m_bIsValidState; }
+ /** Literally moves targets into the given vector.
+ * At the end of the operation, m_aTableTargets vector becomes empty.
+ * The contents of the given vector will be erased before being filled in.
+ * Returns true if successfull.
+ */
+ bool moveTargets(std::vector<std::pair<RedactionTarget*, OUString>>& r_aTargets);
// TODO: Some method(s) to check emptiness/validity
// TODO: Some method(s) to get the search params/objects
diff --git a/sfx2/source/doc/SfxRedactionHelper.cxx b/sfx2/source/doc/SfxRedactionHelper.cxx
index a5ee9ae588d9..b9049c2b6d7b 100644
--- a/sfx2/source/doc/SfxRedactionHelper.cxx
+++ b/sfx2/source/doc/SfxRedactionHelper.cxx
@@ -8,6 +8,7 @@
*/
#include <SfxRedactionHelper.hxx>
+#include <autoredactdialog.hxx>
#include <com/sun/star/drawing/XDrawPagesSupplier.hpp>
#include <com/sun/star/drawing/LineStyle.hpp>
@@ -204,11 +205,12 @@ void SfxRedactionHelper::getPageMetaFilesFromDoc(std::vector<GDIMetaFile>& aMeta
}
}
-void SfxRedactionHelper::addPagesToDraw(uno::Reference<XComponent>& xComponent,
- const sal_Int32& nPages,
- const std::vector<GDIMetaFile>& aMetaFiles,
- const std::vector<::Size>& aPageSizes,
- const PageMargins& aPageMargins)
+void SfxRedactionHelper::addPagesToDraw(
+ uno::Reference<XComponent>& xComponent, const sal_Int32& nPages,
+ const std::vector<GDIMetaFile>& aMetaFiles, const std::vector<::Size>& aPageSizes,
+ const PageMargins& aPageMargins,
+ const std::vector<std::pair<RedactionTarget*, OUString>>& r_aTableTargets,
+ const bool& bIsAutoRedact)
{
// Access the draw pages
uno::Reference<drawing::XDrawPagesSupplier> xDrawPagesSupplier(xComponent, uno::UNO_QUERY);
@@ -248,7 +250,13 @@ void SfxRedactionHelper::addPagesToDraw(uno::Reference<XComponent>& xComponent,
xPage->add(xShape);
- //autoRedactPage("deployment", rGDIMetaFile, xPage, xComponent);
+ if (bIsAutoRedact && !r_aTableTargets.empty())
+ {
+ for (const auto& targetPair : r_aTableTargets)
+ {
+ autoRedactPage(targetPair.first, rGDIMetaFile, xPage, xComponent);
+ }
+ }
}
// Remove the extra page at the beginning
@@ -468,14 +476,19 @@ void SfxRedactionHelper::addRedactionRectToPage(
}
}
-void SfxRedactionHelper::autoRedactPage(const OUString& sRedactionTerm,
+void SfxRedactionHelper::autoRedactPage(const RedactionTarget* pRedactionTarget,
const GDIMetaFile& rGDIMetaFile,
uno::Reference<drawing::XDrawPage>& xPage,
uno::Reference<XComponent>& xComponent)
{
+ if (pRedactionTarget == nullptr || pRedactionTarget->sContent.isEmpty())
+ return;
+
+ OUString sContent(pRedactionTarget->sContent);
+
// Search for the redaction strings, and get the rectangle coordinates
std::vector<::tools::Rectangle> aRedactionRectangles;
- searchInMetaFile(sRedactionTerm, rGDIMetaFile, aRedactionRectangles, xComponent);
+ searchInMetaFile(sContent, rGDIMetaFile, aRedactionRectangles, xComponent);
// Add the redaction rectangles to the page
addRedactionRectToPage(xComponent, xPage, aRedactionRectangles);
diff --git a/sfx2/source/doc/autoredactdialog.cxx b/sfx2/source/doc/autoredactdialog.cxx
index 7025baa81576..73ec02cfc420 100644
--- a/sfx2/source/doc/autoredactdialog.cxx
+++ b/sfx2/source/doc/autoredactdialog.cxx
@@ -528,6 +528,7 @@ void SfxAutoRedactDialog::clearTargets()
SfxAutoRedactDialog::SfxAutoRedactDialog(weld::Window* pParent)
: SfxDialogController(pParent, "sfx/ui/autoredactdialog.ui", "AutoRedactDialog")
+ , m_bIsValidState(true)
, m_xRedactionTargetsLabel(m_xBuilder->weld_label("labelRedactionTargets"))
, m_xTargetsBox(new TargetsTable(m_xBuilder->weld_tree_view("targets")))
, m_xLoadBtn(m_xBuilder->weld_button("btnLoadTargets"))
@@ -578,6 +579,27 @@ bool SfxAutoRedactDialog::hasTargets() const
return true;
}
+bool SfxAutoRedactDialog::moveTargets(
+ std::vector<std::pair<RedactionTarget*, OUString>>& r_aTargets)
+{
+ try
+ {
+ r_aTargets.clear();
+ r_aTargets.insert(r_aTargets.end(), std::make_move_iterator(m_aTableTargets.begin()),
+ std::make_move_iterator(m_aTableTargets.end()));
+ m_aTableTargets.clear();
+ m_bIsValidState = false;
+ }
+ catch (const css::uno::Exception& e)
+ {
+ SAL_WARN("sfx.doc", "Exception caught while moving redaction targets: " << e.Message);
+ m_bIsValidState = false;
+ return false;
+ }
+
+ return true;
+}
+
SfxAddTargetDialog::SfxAddTargetDialog(weld::Window* pParent, const OUString& rName)
: GenericDialogController(pParent, "sfx/ui/addtargetdialog.ui", "AddTargetDialog")
, m_xName(m_xBuilder->weld_entry("name"))
diff --git a/sfx2/source/doc/objserv.cxx b/sfx2/source/doc/objserv.cxx
index f7368c984708..691d01f62a46 100644
--- a/sfx2/source/doc/objserv.cxx
+++ b/sfx2/source/doc/objserv.cxx
@@ -425,6 +425,8 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
SfxInstanceCloseGuard_Impl aModelGuard;
bool bIsPDFExport = false;
+ bool bIsAutoRedact = false;
+ std::vector<std::pair<RedactionTarget*, OUString>> aRedactionTargets;
switch(nId)
{
case SID_VERSION:
@@ -535,17 +537,19 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
case SID_AUTOREDACTDOC:
{
- //TODO: Implement
SfxAutoRedactDialog aDlg(pDialogParent);
- sal_uInt16 nResult = aDlg.run();
+ sal_Int16 nResult = aDlg.run();
- if (nResult != RET_OK || !aDlg.hasTargets())
+ if (nResult != RET_OK || !aDlg.hasTargets() || !aDlg.isValidState())
{
//Do nothing
return;
}
// else continue with normal redaction
+ bIsAutoRedact = true;
+ aDlg.moveTargets(aRedactionTargets);
+
[[fallthrough]];
}
@@ -579,7 +583,7 @@ void SfxObjectShell::ExecFile_Impl(SfxRequest &rReq)
uno::Reference<lang::XComponent> xComponent = xComponentLoader->loadComponentFromURL("private:factory/sdraw", "_default", 0, {});
// Add the doc pages to the new draw document
- SfxRedactionHelper::addPagesToDraw(xComponent, nPages, aMetaFiles, aPageSizes, aPageMargins);
+ SfxRedactionHelper::addPagesToDraw(xComponent, nPages, aMetaFiles, aPageSizes, aPageMargins, aRedactionTargets, bIsAutoRedact);
// Show the Redaction toolbar
SfxViewFrame* pViewFrame = SfxViewFrame::Current();