diff options
author | Muhammet Kara <muhammet.kara@collabora.com> | 2019-06-15 12:08:35 +0300 |
---|---|---|
committer | Muhammet Kara <muhammet.kara@collabora.com> | 2019-06-16 01:26:32 +0200 |
commit | b61a1ca837223ba9d7da1aa8936f228d89bde60a (patch) | |
tree | 42761ab146613e8b35365f2d1502e7b2b9b39056 /sfx2 | |
parent | b674d3c12a5819fbcb551e83bf6862afc85ef7f3 (diff) |
Add predefined targets to auto redaction
Change-Id: Ib8cf8b50944667d6a87a5cafb6995ad195699358
Reviewed-on: https://gerrit.libreoffice.org/74092
Tested-by: Jenkins
Reviewed-by: Muhammet Kara <muhammet.kara@collabora.com>
Diffstat (limited to 'sfx2')
-rw-r--r-- | sfx2/inc/SfxRedactionHelper.hxx | 14 | ||||
-rw-r--r-- | sfx2/inc/autoredactdialog.hxx | 7 | ||||
-rw-r--r-- | sfx2/source/doc/SfxRedactionHelper.cxx | 17 | ||||
-rw-r--r-- | sfx2/source/doc/autoredactdialog.cxx | 89 | ||||
-rw-r--r-- | sfx2/uiconfig/ui/addtargetdialog.ui | 52 |
5 files changed, 167 insertions, 12 deletions
diff --git a/sfx2/inc/SfxRedactionHelper.hxx b/sfx2/inc/SfxRedactionHelper.hxx index 2f470386d2dc..ae72c39f4886 100644 --- a/sfx2/inc/SfxRedactionHelper.hxx +++ b/sfx2/inc/SfxRedactionHelper.hxx @@ -120,6 +120,20 @@ public: /// Fill the search options based on the given redaction target static void fillSearchOptions(i18nutil::SearchOptions2& rSearchOpt, const RedactionTarget* pTarget); + +private: + static constexpr OUStringLiteral m_aPredefinedTargets[6] = { + "\\b(?:\\d[ -]*?){13,16}\\b", //Credit card numbers + "\\b[A-Z0-9._%+-]+@[A-Z0-9.-]+\\.[A-Z]{2,}\\b", //Email addresses + "\\b(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" + "\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)\\.(25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?)" + "\\b", //IP addresses + "([12]\\d{3}[./-](0[1-9]|1[0-2])[./" + "-](0[1-9]|[12]\\d|3[01]))|((0[1-9]|[12]\\d|3[01])[./-](0[1-9]|1[0-2])[./" + "-][12]\\d{3})", //Dates (numerical) + "\\s*[a-zA-Z]{2}(?:\\s*\\d\\s*){6}[a-zA-Z]?\\s*", //National Insurance Number (UK) + "([1-9])(?!\\1{2}-\\1{2}-\\1{4})[1-9]{2}-[1-9]{2}-[1-9]{4}" //Social Security Number (US) + }; }; #endif // INCLUDED_CUI_SOURCE_INC_SFXREDACTIONHELPER_HXX diff --git a/sfx2/inc/autoredactdialog.hxx b/sfx2/inc/autoredactdialog.hxx index 3b6b45c99032..bb633b9a9bb1 100644 --- a/sfx2/inc/autoredactdialog.hxx +++ b/sfx2/inc/autoredactdialog.hxx @@ -155,10 +155,15 @@ class SfxAddTargetDialog : public weld::GenericDialogController private: std::unique_ptr<weld::Entry> m_xName; std::unique_ptr<weld::ComboBox> m_xType; + std::unique_ptr<weld::Label> m_xLabelContent; std::unique_ptr<weld::Entry> m_xContent; + std::unique_ptr<weld::Label> m_xLabelPredefContent; + std::unique_ptr<weld::ComboBox> m_xPredefContent; std::unique_ptr<weld::CheckButton> m_xCaseSensitive; std::unique_ptr<weld::CheckButton> m_xWholeWords; + DECL_LINK(SelectTypeHdl, weld::ComboBox&, void); + public: SfxAddTargetDialog(weld::Window* pWindow, const OUString& rName); SfxAddTargetDialog(weld::Window* pWindow, const OUString& sName, @@ -167,7 +172,7 @@ public: OUString getName() const { return m_xName->get_text(); } RedactionTargetType getType() const; - OUString getContent() const { return m_xContent->get_text(); } + OUString getContent() const; bool isCaseSensitive() const { return m_xCaseSensitive->get_state() == TriState::TRISTATE_TRUE; diff --git a/sfx2/source/doc/SfxRedactionHelper.cxx b/sfx2/source/doc/SfxRedactionHelper.cxx index b6c3264d769a..efd06b14fccd 100644 --- a/sfx2/source/doc/SfxRedactionHelper.cxx +++ b/sfx2/source/doc/SfxRedactionHelper.cxx @@ -533,7 +533,8 @@ void SfxRedactionHelper::fillSearchOptions(i18nutil::SearchOptions2& rSearchOpt, return; } - if (pTarget->sType == RedactionTargetType::REDACTION_TARGET_REGEX) + if (pTarget->sType == RedactionTargetType::REDACTION_TARGET_REGEX + || pTarget->sType == RedactionTargetType::REDACTION_TARGET_PREDEFINED) { rSearchOpt.algorithmType = util::SearchAlgorithms_REGEXP; rSearchOpt.AlgorithmType2 = util::SearchAlgorithms2::REGEXP; @@ -545,10 +546,20 @@ void SfxRedactionHelper::fillSearchOptions(i18nutil::SearchOptions2& rSearchOpt, } rSearchOpt.Locale = GetAppLanguageTag().getLocale(); - rSearchOpt.searchString = pTarget->sContent; + if (pTarget->sType == RedactionTargetType::REDACTION_TARGET_PREDEFINED) + { + sal_Int32 nPredefIndex = pTarget->sContent.getToken(0, ';').toInt32(); + //sal_Int32 nPredefIndex = sContent.toInt32(); + + rSearchOpt.searchString = m_aPredefinedTargets[nPredefIndex]; + } + else + rSearchOpt.searchString = pTarget->sContent; + rSearchOpt.replaceString.clear(); - if (!pTarget->bCaseSensitive && pTarget->sType != RedactionTargetType::REDACTION_TARGET_REGEX) + if (!pTarget->bCaseSensitive && pTarget->sType != RedactionTargetType::REDACTION_TARGET_REGEX + && pTarget->sType != RedactionTargetType::REDACTION_TARGET_PREDEFINED) rSearchOpt.transliterateFlags |= TransliterationFlags::IGNORE_CASE; if (pTarget->bWholeWords) rSearchOpt.searchFlag |= util::SearchFlags::NORM_WORD_ONLY; diff --git a/sfx2/source/doc/autoredactdialog.cxx b/sfx2/source/doc/autoredactdialog.cxx index 3ec9872eb380..2a11a2a6e63a 100644 --- a/sfx2/source/doc/autoredactdialog.cxx +++ b/sfx2/source/doc/autoredactdialog.cxx @@ -128,11 +128,19 @@ void TargetsTable::InsertTarget(RedactionTarget* pTarget) pTarget->sName = GetNameProposal(); } + OUString sContent = pTarget->sContent; + + if (pTarget->sType == RedactionTargetType::REDACTION_TARGET_PREDEFINED) + { + //selection_num;selection_name + sContent = sContent.getToken(1, ';'); + } + // Add to the end int nRow = m_xControl->n_children(); m_xControl->append(OUString::number(reinterpret_cast<sal_Int64>(pTarget)), pTarget->sName); m_xControl->set_text(nRow, getTypeName(pTarget->sType), 1); - m_xControl->set_text(nRow, pTarget->sContent, 2); + m_xControl->set_text(nRow, sContent, 2); m_xControl->set_text(nRow, pTarget->bCaseSensitive ? OUString("Yes") : OUString("No"), 3); m_xControl->set_text(nRow, pTarget->bWholeWords ? OUString("Yes") : OUString("No"), 4); } @@ -176,9 +184,17 @@ OUString TargetsTable::GetNameProposal() void TargetsTable::setRowData(const int& nRowIndex, const RedactionTarget* pTarget) { + OUString sContent = pTarget->sContent; + + if (pTarget->sType == RedactionTargetType::REDACTION_TARGET_PREDEFINED) + { + //selection_num;selection_name + sContent = sContent.getToken(1, ';'); + } + m_xControl->set_text(nRowIndex, pTarget->sName, 0); m_xControl->set_text(nRowIndex, getTypeName(pTarget->sType), 1); - m_xControl->set_text(nRowIndex, pTarget->sContent, 2); + m_xControl->set_text(nRowIndex, sContent, 2); m_xControl->set_text(nRowIndex, pTarget->bCaseSensitive ? OUString("Yes") : OUString("No"), 3); m_xControl->set_text(nRowIndex, pTarget->bWholeWords ? OUString("Yes") : OUString("No"), 4); } @@ -600,16 +616,61 @@ bool SfxAutoRedactDialog::moveTargets( return true; } +IMPL_LINK_NOARG(SfxAddTargetDialog, SelectTypeHdl, weld::ComboBox&, void) +{ + if (m_xType->get_active_id() == "predefined") + { + // Hide the usual content widgets + // We will just set the id as content + // And handle with proper regex in the SfxRedactionHelper + m_xLabelContent->set_sensitive(false); + m_xLabelContent->set_visible(false); + m_xContent->set_sensitive(false); + m_xContent->set_visible(false); + m_xWholeWords->set_sensitive(false); + m_xWholeWords->set_visible(false); + m_xCaseSensitive->set_sensitive(false); + m_xCaseSensitive->set_visible(false); + + // And show the predefined targets + m_xLabelPredefContent->set_sensitive(true); + m_xLabelPredefContent->set_visible(true); + m_xPredefContent->set_sensitive(true); + m_xPredefContent->set_visible(true); + } + else + { + m_xLabelPredefContent->set_sensitive(false); + m_xLabelPredefContent->set_visible(false); + m_xPredefContent->set_sensitive(false); + m_xPredefContent->set_visible(false); + + m_xLabelContent->set_sensitive(true); + m_xLabelContent->set_visible(true); + m_xContent->set_sensitive(true); + m_xContent->set_visible(true); + m_xWholeWords->set_sensitive(true); + m_xWholeWords->set_visible(true); + m_xCaseSensitive->set_sensitive(true); + m_xCaseSensitive->set_visible(true); + } +} + SfxAddTargetDialog::SfxAddTargetDialog(weld::Window* pParent, const OUString& rName) : GenericDialogController(pParent, "sfx/ui/addtargetdialog.ui", "AddTargetDialog") , m_xName(m_xBuilder->weld_entry("name")) , m_xType(m_xBuilder->weld_combo_box("type")) + , m_xLabelContent(m_xBuilder->weld_label("label_content")) , m_xContent(m_xBuilder->weld_entry("content")) + , m_xLabelPredefContent(m_xBuilder->weld_label("label_content_predef")) + , m_xPredefContent(m_xBuilder->weld_combo_box("content_predef")) , m_xCaseSensitive(m_xBuilder->weld_check_button("checkboxCaseSensitive")) , m_xWholeWords(m_xBuilder->weld_check_button("checkboxWholeWords")) { m_xName->set_text(rName); m_xName->select_region(0, rName.getLength()); + + m_xType->connect_changed(LINK(this, SfxAddTargetDialog, SelectTypeHdl)); } SfxAddTargetDialog::SfxAddTargetDialog(weld::Window* pParent, const OUString& sName, @@ -619,7 +680,10 @@ SfxAddTargetDialog::SfxAddTargetDialog(weld::Window* pParent, const OUString& sN : GenericDialogController(pParent, "sfx/ui/addtargetdialog.ui", "AddTargetDialog") , m_xName(m_xBuilder->weld_entry("name")) , m_xType(m_xBuilder->weld_combo_box("type")) + , m_xLabelContent(m_xBuilder->weld_label("label_content")) , m_xContent(m_xBuilder->weld_entry("content")) + , m_xLabelPredefContent(m_xBuilder->weld_label("label_content_predef")) + , m_xPredefContent(m_xBuilder->weld_combo_box("content_predef")) , m_xCaseSensitive(m_xBuilder->weld_check_button("checkboxCaseSensitive")) , m_xWholeWords(m_xBuilder->weld_check_button("checkboxWholeWords")) { @@ -628,7 +692,15 @@ SfxAddTargetDialog::SfxAddTargetDialog(weld::Window* pParent, const OUString& sN m_xType->set_active_id(getTypeID(eTargetType)); - m_xContent->set_text(sContent); + if (eTargetType == RedactionTargetType::REDACTION_TARGET_PREDEFINED) + { + SelectTypeHdl(*m_xPredefContent); + m_xPredefContent->set_active(sContent.getToken(0, ';').toInt32()); + } + else + { + m_xContent->set_text(sContent); + } m_xCaseSensitive->set_active(bCaseSensitive); m_xWholeWords->set_active(bWholeWords); @@ -650,4 +722,15 @@ RedactionTargetType SfxAddTargetDialog::getType() const return RedactionTargetType::REDACTION_TARGET_UNKNOWN; } +OUString SfxAddTargetDialog::getContent() const +{ + if (m_xType->get_active_id() == "predefined") + { + return OUString(OUString::number(m_xPredefContent->get_active()) + ";" + + m_xPredefContent->get_active_text()); + } + + return m_xContent->get_text(); +} + /* vim:set shiftwidth=4 softtabstop=4 expandtab cinoptions=b1,g0,N-s cinkeys+=0=break: */ diff --git a/sfx2/uiconfig/ui/addtargetdialog.ui b/sfx2/uiconfig/ui/addtargetdialog.ui index 3d45c7a240bd..d4283222fb65 100644 --- a/sfx2/uiconfig/ui/addtargetdialog.ui +++ b/sfx2/uiconfig/ui/addtargetdialog.ui @@ -24,8 +24,8 @@ <object class="GtkButtonBox"> <property name="can_focus">False</property> <child> - <object class="GtkButton" id="cancel"> - <property name="label">gtk-cancel</property> + <object class="GtkButton" id="close"> + <property name="label">gtk-ok</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> @@ -39,8 +39,8 @@ </packing> </child> <child> - <object class="GtkButton" id="close"> - <property name="label">gtk-ok</property> + <object class="GtkButton" id="cancel"> + <property name="label">gtk-cancel</property> <property name="visible">True</property> <property name="can_focus">True</property> <property name="receives_default">True</property> @@ -145,6 +145,7 @@ <property name="visible">True</property> <property name="can_focus">True</property> <property name="margin_left">2</property> + <property name="margin_bottom">2</property> <property name="activates_default">True</property> <accessibility> <relation type="labelled-by" target="label_content"/> @@ -159,6 +160,9 @@ <object class="GtkComboBoxText" id="type"> <property name="visible">True</property> <property name="can_focus">False</property> + <property name="margin_left">2</property> + <property name="margin_bottom">2</property> + <property name="active">0</property> <items> <item id="text" translatable="yes" context="addtargetdialog|type">Text</item> <item id="regex" translatable="yes" context="addtargetdialog|type">Regex</item> @@ -173,6 +177,44 @@ <property name="top_attach">1</property> </packing> </child> + <child> + <object class="GtkLabel" id="label_content_predef"> + <property name="sensitive">False</property> + <property name="can_focus">False</property> + <property name="label" translatable="yes" context="addtargetdialog|label_content_predef">Content:</property> + <property name="use_underline">True</property> + <accessibility> + <relation type="label-for" target="content_predef"/> + </accessibility> + </object> + <packing> + <property name="left_attach">0</property> + <property name="top_attach">3</property> + </packing> + </child> + <child> + <object class="GtkComboBoxText" id="content_predef"> + <property name="sensitive">False</property> + <property name="can_focus">False</property> + <property name="margin_left">2</property> + <property name="active">0</property> + <items> + <item id="creditcard" translatable="yes" context="addtargetdialog|content_predef">Credit card numbers</item> + <item id="email" translatable="yes" context="addtargetdialog|content_predef">Email addresses</item> + <item id="ip" translatable="yes" context="addtargetdialog|content_predef">IP addresses</item> + <item id="numdates" translatable="yes" context="addtargetdialog|content_predef">Dates (Numerical)</item> + <item id="uknin" translatable="yes" context="addtargetdialog|content_predef">National Insurance Number (UK)</item> + <item id="usssn" translatable="yes" context="addtargetdialog|content_predef">Social Security Number (US)</item> + </items> + <accessibility> + <relation type="labelled-by" target="label_content_predef"/> + </accessibility> + </object> + <packing> + <property name="left_attach">1</property> + <property name="top_attach">3</property> + </packing> + </child> </object> <packing> <property name="expand">False</property> @@ -227,8 +269,8 @@ </object> </child> <action-widgets> - <action-widget response="-6">cancel</action-widget> <action-widget response="-5">close</action-widget> + <action-widget response="-6">cancel</action-widget> <action-widget response="-11">help</action-widget> </action-widgets> </object> |