summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2017-11-01 12:53:03 +0900
committerTomaž Vajngerl <quikee@gmail.com>2017-11-02 07:29:28 +0100
commita0a287f566e548177847bdb69cba230089b44e54 (patch)
treed38bce991de8dc1a13000862e37eff5382a36e5f /svx
parentda5be4f3d78e2665a1d3c7443f24adecbb0940cf (diff)
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 <ci@libreoffice.org> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svx')
-rw-r--r--svx/source/dialog/ClassificationDialog.cxx206
1 files changed, 206 insertions, 0 deletions
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)
{