include/svx/ClassificationDialog.hxx | 13 + svx/source/dialog/ClassificationDialog.cxx | 206 +++++++++++++++++++++++++++++ 2 files changed, 217 insertions(+), 2 deletions(-)
New commits: commit a0a287f566e548177847bdb69cba230089b44e54 Author: Tomaž Vajngerl <tomaz.vajng...@collabora.co.uk> Date: Wed Nov 1 12:53:03 2017 +0900 TSCP: read/write recently used in advanced classification dialog This implements the reading and writing of the recently used content in the advanced classification dialog. The recently used content is stored to a xml file in the user profile folder under "classification" folder - filename "recentlyUsed.xml". The content is just a reflection of the resulting ClassificationResult vector in a simple xml form. Change-Id: If148ae123a6c826874b86dc1f374cdaab6e8fea9 Reviewed-on: https://gerrit.libreoffice.org/44150 Tested-by: Jenkins <c...@libreoffice.org> Reviewed-by: Tomaž Vajngerl <qui...@gmail.com> diff --git a/include/svx/ClassificationDialog.hxx b/include/svx/ClassificationDialog.hxx index 19e869a5f74d..a7825fef4a53 100644 --- a/include/svx/ClassificationDialog.hxx +++ b/include/svx/ClassificationDialog.hxx @@ -51,10 +51,19 @@ private: void insertField(ClassificationType eType, OUString const & rString, OUString const & rFullString); + std::vector<std::vector<ClassificationResult>> m_aRecentlyUsedValuesCollection; + std::vector<ClassificationResult> m_aInitialValues; + + void readIn(std::vector<ClassificationResult> const & rInput); + void readRecentlyUsed(); + void writeRecentlyUsed(); + public: ClassificationDialog(vcl::Window* pParent, bool bPerParagraph, const std::function<void()>& rParagraphSignHandler = [](){}); - virtual ~ClassificationDialog() override; - virtual void dispose() override; + ~ClassificationDialog() override; + + void dispose() override; + short Execute() override; std::vector<ClassificationResult> getResult(); void setupValues(std::vector<ClassificationResult> const & rInput); diff --git a/svx/source/dialog/ClassificationDialog.cxx b/svx/source/dialog/ClassificationDialog.cxx index f99d4f97bd0c..db5e7639ef9c 100644 --- a/svx/source/dialog/ClassificationDialog.cxx +++ b/svx/source/dialog/ClassificationDialog.cxx @@ -16,6 +16,13 @@ #include <editeng/wghtitem.hxx> #include <svl/itemset.hxx> +#include <osl/file.hxx> +#include <rtl/bootstrap.hxx> +#include <rtl/uri.hxx> +#include <config_folders.h> +#include <tools/XmlWriter.hxx> +#include <tools/XmlWalker.hxx> + namespace svx { namespace { @@ -30,6 +37,30 @@ const SvxFieldItem* findField(editeng::Section const & rSection) return nullptr; } +bool fileExists(OUString const & sFilename) +{ + osl::File aFile(sFilename); + osl::FileBase::RC eRC = aFile.open(osl_File_OpenFlag_Read); + return osl::FileBase::E_None == eRC; +} + +bool stringToclassificationType(OString const & rsType, svx::ClassificationType & reType) +{ + if (rsType == "CATEGORY") + reType = svx::ClassificationType::CATEGORY; + else if (rsType == "INTELLECTUAL_PROPERTY_PART") + reType = svx::ClassificationType::INTELLECTUAL_PROPERTY_PART; + else if (rsType == "MARKING") + reType = svx::ClassificationType::MARKING; + else if (rsType == "PARAGRAPH") + reType = svx::ClassificationType::PARAGRAPH; + else if (rsType == "TEXT") + reType = svx::ClassificationType::TEXT; + else + return false; + return true; +} + } // end anonymous namespace ClassificationDialog::ClassificationDialog(vcl::Window* pParent, const bool bPerParagraph, const std::function<void()>& rParagraphSignHandler) @@ -103,6 +134,19 @@ void ClassificationDialog::dispose() ModalDialog::dispose(); } +short ClassificationDialog::Execute() +{ + readRecentlyUsed(); + readIn(m_aInitialValues); + + short nResult = ModalDialog::Execute(); + if (nResult == RET_OK) + { + writeRecentlyUsed(); + } + return nResult; +} + void ClassificationDialog::insertField(ClassificationType eType, OUString const & rString, OUString const & rFullString) { ClassificationField aField(eType, rString, rFullString); @@ -111,6 +155,168 @@ void ClassificationDialog::insertField(ClassificationType eType, OUString const void ClassificationDialog::setupValues(std::vector<ClassificationResult> const & rInput) { + m_aInitialValues = rInput; +} + +void ClassificationDialog::readRecentlyUsed() +{ + OUString sPath("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/user/classification/"); + rtl::Bootstrap::expandMacros(sPath); + + OUString sFilePath(sPath + "recentlyUsed.xml"); + + if (!fileExists(sFilePath)) + return; + + SvFileStream aFileStream(sFilePath, StreamMode::READ); + tools::XmlWalker aWalker; + if (!aWalker.open(&aFileStream)) + return; + + if (aWalker.name() == "recentlyUsedClassifications") + { + aWalker.children(); + while (aWalker.isValid()) + { + if (aWalker.name() == "elementGroup") + { + std::vector<ClassificationResult> aResults; + + aWalker.children(); + + while (aWalker.isValid()) + { + if (aWalker.name() == "element") + { + svx::ClassificationType eType = svx::ClassificationType::TEXT; + OUString sString; + OUString sAbbreviatedString; + + // Convert string to classification type, but continue only if + // conversion was successful. + if (stringToclassificationType(aWalker.attribute("type"), eType)) + { + aWalker.children(); + + while (aWalker.isValid()) + { + if (aWalker.name() == "string") + { + sString = OStringToOUString(aWalker.content(), RTL_TEXTENCODING_UTF8); + } + else if (aWalker.name() == "abbreviatedString") + { + sAbbreviatedString = OStringToOUString(aWalker.content(), RTL_TEXTENCODING_UTF8); + } + aWalker.next(); + } + aWalker.parent(); + + aResults.push_back({ eType, sString, sAbbreviatedString }); + } + } + aWalker.next(); + } + aWalker.parent(); + m_aRecentlyUsedValuesCollection.push_back(aResults); + } + aWalker.next(); + } + aWalker.parent(); + } +} + +void ClassificationDialog::writeRecentlyUsed() +{ + OUString sPath("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/user/classification/"); + rtl::Bootstrap::expandMacros(sPath); + osl::Directory::createPath(sPath); + + OUString sFilePath(sPath + "recentlyUsed.xml"); + + std::unique_ptr<SvStream> pStream; + pStream.reset(new SvFileStream(sFilePath, StreamMode::STD_READWRITE | StreamMode::TRUNC)); + + tools::XmlWriter aXmlWriter(pStream.get()); + + if (!aXmlWriter.startDocument()) + return; + + aXmlWriter.startElement("recentlyUsedClassifications"); + + aXmlWriter.startElement("elementGroup"); + + for (ClassificationResult const & rResult : getResult()) + { + aXmlWriter.startElement("element"); + OUString sType; + switch(rResult.meType) + { + case svx::ClassificationType::CATEGORY: + sType = "CATEGORY"; break; + case svx::ClassificationType::MARKING: + sType = "MARKING"; break; + case svx::ClassificationType::TEXT: + sType = "TEXT"; break; + case svx::ClassificationType::INTELLECTUAL_PROPERTY_PART: + sType = "INTELLECTUAL_PROPERTY_PART"; break; + case svx::ClassificationType::PARAGRAPH: + sType = "PARAGRAPH"; break; + } + aXmlWriter.attribute("type", sType); + aXmlWriter.startElement("string"); + aXmlWriter.content(rResult.msString); + aXmlWriter.endElement(); + aXmlWriter.startElement("abbreviatedString"); + aXmlWriter.content(rResult.msAbbreviatedString); + aXmlWriter.endElement(); + aXmlWriter.endElement(); + } + aXmlWriter.endElement(); + + if (m_aRecentlyUsedValuesCollection.size() >= 5) + m_aRecentlyUsedValuesCollection.pop_back(); + + for (std::vector<ClassificationResult> const & rResultCollection : m_aRecentlyUsedValuesCollection) + { + aXmlWriter.startElement("elementGroup"); + + for (ClassificationResult const & rResult : rResultCollection) + { + aXmlWriter.startElement("element"); + OUString sType; + switch(rResult.meType) + { + case svx::ClassificationType::CATEGORY: + sType = "CATEGORY"; break; + case svx::ClassificationType::MARKING: + sType = "MARKING"; break; + case svx::ClassificationType::TEXT: + sType = "TEXT"; break; + case svx::ClassificationType::INTELLECTUAL_PROPERTY_PART: + sType = "INTELLECTUAL_PROPERTY_PART"; break; + case svx::ClassificationType::PARAGRAPH: + sType = "PARAGRAPH"; break; + } + aXmlWriter.attribute("type", sType); + aXmlWriter.startElement("string"); + aXmlWriter.content(rResult.msString); + aXmlWriter.endElement(); + aXmlWriter.startElement("abbreviatedString"); + aXmlWriter.content(rResult.msAbbreviatedString); + aXmlWriter.endElement(); + aXmlWriter.endElement(); + } + aXmlWriter.endElement(); + } + + aXmlWriter.endElement(); + + aXmlWriter.endDocument(); +} + +void ClassificationDialog::readIn(std::vector<ClassificationResult> const & rInput) +{ sal_Int32 nParagraph = -1; for (ClassificationResult const & rClassificationResult : rInput) {
_______________________________________________ Libreoffice-commits mailing list libreoffice-comm...@lists.freedesktop.org https://lists.freedesktop.org/mailman/listinfo/libreoffice-commits