[Libreoffice-commits] core.git: Branch 'distro/collabora/cp-6.0' - sfx2/inc sfx2/source

Muhammet Kara (via logerrit) logerrit at kemper.freedesktop.org
Sat Aug 17 14:39:39 UTC 2019


 sfx2/inc/autoredactdialog.hxx        |   21 ++++-
 sfx2/source/doc/autoredactdialog.cxx |  142 +++++++++++++++++++++++++++++------
 2 files changed, 138 insertions(+), 25 deletions(-)

New commits:
commit 53bfc6452528e87a68c0ca1bfda601053cdfec03
Author:     Muhammet Kara <muhammet.kara at collabora.com>
AuthorDate: Sat Jun 8 23:27:56 2019 +0300
Commit:     Muhammet Kara <muhammet.kara at collabora.com>
CommitDate: Sat Aug 17 16:38:53 2019 +0200

    Auto redaction dialog 4th iteration
    
    * Add the Save & SaveHdl handlers
    * Add stubs for Load & LoadHdl handlers
    
    Change-Id: I5f58213c86e99f8bfc9075e04eedbb5cb546d9ad
    Reviewed-on: https://gerrit.libreoffice.org/73724
    Tested-by: Jenkins
    Reviewed-by: Muhammet Kara <muhammet.kara at collabora.com>
    Reviewed-on: https://gerrit.libreoffice.org/77161
    Tested-by: Muhammet Kara <muhammet.kara at collabora.com>

diff --git a/sfx2/inc/autoredactdialog.hxx b/sfx2/inc/autoredactdialog.hxx
index 267427c90b21..99c956246d69 100644
--- a/sfx2/inc/autoredactdialog.hxx
+++ b/sfx2/inc/autoredactdialog.hxx
@@ -89,10 +89,22 @@ public:
     //void connect_row_activated(const Link<weld::TreeView&, void>& rLink) { m_xControl->connect_row_activated(rLink); }
 };
 
+namespace sfx2
+{
+class FileDialogHelper;
+}
+
+enum class StartFileDialogType
+{
+    Open,
+    SaveAs
+};
+
 class SFX2_DLLPUBLIC SfxAutoRedactDialog : public SfxDialogController
 {
     SfxObjectShellLock m_xDocShell;
     std::vector<std::pair<RedactionTarget*, OUString>> m_aTableTargets;
+    std::unique_ptr<sfx2::FileDialogHelper> m_pFileDlg;
 
     std::unique_ptr<weld::Label> m_xRedactionTargetsLabel;
     std::unique_ptr<TargetsTable> m_xTargetsBox;
@@ -102,12 +114,17 @@ class SFX2_DLLPUBLIC SfxAutoRedactDialog : public SfxDialogController
     std::unique_ptr<weld::Button> m_xEditBtn;
     std::unique_ptr<weld::Button> m_xDeleteBtn;
 
-    /*DECL_LINK(LoadHdl, weld::Button&, void);
-    DECL_LINK(SaveHdl, weld::Button&, void);*/
+    DECL_LINK(Load, weld::Button&, void);
+    DECL_LINK(Save, weld::Button&, void);
     DECL_LINK(AddHdl, weld::Button&, void);
     DECL_LINK(EditHdl, weld::Button&, void);
     DECL_LINK(DeleteHdl, weld::Button&, void);
 
+    DECL_LINK(LoadHdl, sfx2::FileDialogHelper*, void);
+    DECL_LINK(SaveHdl, sfx2::FileDialogHelper*, void);
+
+    void StartFileDialog(StartFileDialogType nType, const OUString& rTitle);
+
 public:
     SfxAutoRedactDialog(weld::Window* pParent);
     virtual ~SfxAutoRedactDialog() override;
diff --git a/sfx2/source/doc/autoredactdialog.cxx b/sfx2/source/doc/autoredactdialog.cxx
index 266859a129ec..7c414cfc3189 100644
--- a/sfx2/source/doc/autoredactdialog.cxx
+++ b/sfx2/source/doc/autoredactdialog.cxx
@@ -7,31 +7,34 @@
  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
  */
 
-#include <osl/file.hxx>
 #include <autoredactdialog.hxx>
-#include <vcl/layout.hxx>
-#include <vcl/idle.hxx>
-#include <vcl/gdimtf.hxx>
-#include <svl/itemset.hxx>
-#include <svl/eitem.hxx>
-#include <svtools/sfxecode.hxx>
-#include <svtools/ehdl.hxx>
-#include <tools/urlobj.hxx>
-#include <tools/debug.hxx>
 
-#include <sfx2/strings.hrc>
-#include <sfx2/sfxsids.hrc>
+#include <preview.hxx>
 #include <sfx2/app.hxx>
+#include <sfx2/docfile.hxx>
+#include <sfx2/filedlghelper.hxx>
 #include <sfx2/objsh.hxx>
 #include <sfx2/sfxresid.hxx>
-#include <sfx2/docfile.hxx>
-#include <preview.hxx>
-#include <sfx2/printer.hxx>
-#include <unotools/viewoptions.hxx>
+#include <sfx2/sfxsids.hrc>
+#include <sfx2/strings.hrc>
+
+#include <osl/file.hxx>
+#include <sal/log.hxx>
+#include <svl/eitem.hxx>
+#include <svl/itemset.hxx>
+#include <svtools/ehdl.hxx>
+#include <svtools/sfxecode.hxx>
+#include <vcl/idle.hxx>
+#include <vcl/layout.hxx>
 #include <vcl/waitobj.hxx>
 #include <vcl/weld.hxx>
+#include <tools/debug.hxx>
+#include <tools/urlobj.hxx>
+#include <unotools/viewoptions.hxx>
 
-#include <sal/log.hxx>
+#include <com/sun/star/ui/dialogs/TemplateDescription.hpp>
+
+#include <boost/property_tree/json_parser.hpp>
 
 int TargetsTable::GetRowByTargetName(const OUString& sName)
 {
@@ -180,17 +183,20 @@ void TargetsTable::setRowData(const int& nRowIndex, const RedactionTarget* pTarg
     m_xControl->set_text(nRowIndex, pTarget->bWholeWords ? OUString("Yes") : OUString("No"), 4);
 }
 
-/*IMPL_LINK_NOARG(SfxAutoRedactDialog, LoadHdl, weld::Button&, void)
+IMPL_LINK_NOARG(SfxAutoRedactDialog, Load, weld::Button&, void)
 {
     //TODO: Implement
-    //Load a targets list from a previously saved file (a json file in the user profile dir?)
+    //Load a targets list from a previously saved file (a json file?)
+    // ask for filename, where we should load the new config data from
+    StartFileDialog(StartFileDialogType::Open, "Load Targets");
 }
 
-IMPL_LINK_NOARG(SfxAutoRedactDialog, SaveHdl, weld::Button&, void)
+IMPL_LINK_NOARG(SfxAutoRedactDialog, Save, weld::Button&, void)
 {
     //TODO: Implement
     //Allow saving the targets into a file
-}*/
+    StartFileDialog(StartFileDialogType::SaveAs, "Save Targets");
+}
 
 IMPL_LINK_NOARG(SfxAutoRedactDialog, AddHdl, weld::Button&, void)
 {
@@ -345,6 +351,96 @@ IMPL_LINK_NOARG(SfxAutoRedactDialog, DeleteHdl, weld::Button&, void)
     }
 }
 
+namespace
+{
+boost::property_tree::ptree redactionTargetToJSON(RedactionTarget* pTarget)
+{
+    boost::property_tree::ptree aNode;
+    aNode.put("sName", pTarget->sName.toUtf8().getStr());
+    aNode.put("eType", pTarget->sType);
+    aNode.put("sContent", pTarget->sContent.toUtf8().getStr());
+    aNode.put("bWholeWords", pTarget->bWholeWords);
+    aNode.put("bCaseSensitive", pTarget->bCaseSensitive);
+    aNode.put("nID", pTarget->nID);
+
+    return aNode;
+}
+}
+
+IMPL_LINK_NOARG(SfxAutoRedactDialog, LoadHdl, sfx2::FileDialogHelper*, void)
+{
+    //TODO: Implement
+    bool bDummy = hasTargets();
+
+    if (bDummy)
+        void();
+}
+
+IMPL_LINK_NOARG(SfxAutoRedactDialog, SaveHdl, sfx2::FileDialogHelper*, void)
+{
+    assert(m_pFileDlg);
+
+    OUString sTargetsFile;
+    if (ERRCODE_NONE == m_pFileDlg->GetError())
+        sTargetsFile = m_pFileDlg->GetPath();
+
+    if (sTargetsFile.isEmpty())
+        return;
+
+    OUString sSysPath;
+    osl::File::getSystemPathFromFileURL(sTargetsFile, sSysPath);
+    sTargetsFile = sSysPath;
+
+    weld::WaitObject aWaitObject(getDialog());
+
+    try
+    {
+        // Put the targets into a JSON array
+        boost::property_tree::ptree aTargetsArray;
+        for (const auto& targetPair : m_aTableTargets)
+        {
+            aTargetsArray.push_back(std::make_pair("", redactionTargetToJSON(targetPair.first)));
+        }
+
+        // Build the JSON tree
+        boost::property_tree::ptree aTargetsTree;
+        aTargetsTree.add_child("RedactionTargets", aTargetsArray);
+
+        // Create path string, and write JSON to file
+        std::string sPathStr(OUStringToOString(sTargetsFile, RTL_TEXTENCODING_UTF8).getStr());
+
+        boost::property_tree::write_json(sPathStr, aTargetsTree);
+    }
+    catch (css::uno::Exception& e)
+    {
+        SAL_WARN("sfx.doc",
+                 "Exception caught while trying to save the targets JSON to file: " << e.Message);
+        return;
+        //TODO: Warn the user with a message box
+    }
+}
+
+void SfxAutoRedactDialog::StartFileDialog(StartFileDialogType nType, const OUString& rTitle)
+{
+    OUString aFilterAllStr(SfxResId(STR_SFX_FILTERNAME_ALL));
+    OUString aFilterCfgStr("Target Set (*.json)");
+
+    bool bSave = nType == StartFileDialogType::SaveAs;
+    short nDialogType = bSave ? css::ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION
+                              : css::ui::dialogs::TemplateDescription::FILEOPEN_SIMPLE;
+    m_pFileDlg.reset(new sfx2::FileDialogHelper(nDialogType, FileDialogFlags::NONE, getDialog()));
+
+    m_pFileDlg->SetTitle(rTitle);
+    m_pFileDlg->AddFilter(aFilterAllStr, FILEDIALOG_FILTER_ALL);
+    m_pFileDlg->AddFilter(aFilterCfgStr, "*.json");
+    m_pFileDlg->SetCurrentFilter(aFilterCfgStr);
+
+    Link<sfx2::FileDialogHelper*, void> aDlgClosedLink
+        = bSave ? LINK(this, SfxAutoRedactDialog, SaveHdl)
+                : LINK(this, SfxAutoRedactDialog, LoadHdl);
+    m_pFileDlg->StartExecuteModal(aDlgClosedLink);
+}
+
 SfxAutoRedactDialog::SfxAutoRedactDialog(weld::Window* pParent)
     : SfxDialogController(pParent, "sfx/ui/autoredactdialog.ui", "AutoRedactDialog")
     , m_xRedactionTargetsLabel(m_xBuilder->weld_label("labelRedactionTargets"))
@@ -374,8 +470,8 @@ SfxAutoRedactDialog::SfxAutoRedactDialog(weld::Window* pParent)
     // TODO: fill the targets box
 
     // Handler connections
-    //m_xLoadBtn->connect_clicked(LINK(this, SfxAutoRedactDialog, LoadHdl));
-    //m_xSaveBtn->connect_clicked(LINK(this, SfxAutoRedactDialog, SaveHdl));
+    m_xLoadBtn->connect_clicked(LINK(this, SfxAutoRedactDialog, Load));
+    m_xSaveBtn->connect_clicked(LINK(this, SfxAutoRedactDialog, Save));
     m_xAddBtn->connect_clicked(LINK(this, SfxAutoRedactDialog, AddHdl));
     m_xEditBtn->connect_clicked(LINK(this, SfxAutoRedactDialog, EditHdl));
     m_xDeleteBtn->connect_clicked(LINK(this, SfxAutoRedactDialog, DeleteHdl));


More information about the Libreoffice-commits mailing list