summaryrefslogtreecommitdiff
path: root/svx
diff options
context:
space:
mode:
authorTomaž Vajngerl <tomaz.vajngerl@collabora.co.uk>2017-11-06 13:30:01 +0900
committerTomaž Vajngerl <quikee@gmail.com>2017-11-06 09:39:10 +0100
commit0a4ad544daaec4f773480e6301238c7f6958a9ab (patch)
tree912f2fd9df7afa1ae5704508a59a860380a6d667 /svx
parentda308320f0f00453476b20671651950bc498608f (diff)
TSCP: put more duplicated methods to common
Change-Id: Ic49e0dad1351684db3372214604d12b48d0be907 Reviewed-on: https://gerrit.libreoffice.org/44337 Tested-by: Jenkins <ci@libreoffice.org> Reviewed-by: Tomaž Vajngerl <quikee@gmail.com>
Diffstat (limited to 'svx')
-rw-r--r--svx/source/dialog/ClassificationCommon.cxx31
-rw-r--r--svx/source/dialog/ClassificationDialog.cxx69
2 files changed, 57 insertions, 43 deletions
diff --git a/svx/source/dialog/ClassificationCommon.cxx b/svx/source/dialog/ClassificationCommon.cxx
index 60cfcf520ab4..4d5d74938d5b 100644
--- a/svx/source/dialog/ClassificationCommon.cxx
+++ b/svx/source/dialog/ClassificationCommon.cxx
@@ -40,7 +40,21 @@ OUString convertClassificationResultToString(std::vector<svx::ClassificationResu
return sRepresentation;
}
-bool lcl_containsProperty(const uno::Sequence<beans::Property> & rProperties, const OUString& rName)
+OUString getProperty(uno::Reference<beans::XPropertyContainer> const & rxPropertyContainer, OUString const & rName)
+{
+ try
+ {
+ uno::Reference<beans::XPropertySet> xPropertySet(rxPropertyContainer, uno::UNO_QUERY);
+ return xPropertySet->getPropertyValue(rName).get<OUString>();
+ }
+ catch (const css::uno::Exception&)
+ {
+ }
+
+ return OUString();
+}
+
+bool containsProperty(uno::Sequence<beans::Property> const & rProperties, OUString const & rName)
{
return std::find_if(rProperties.begin(), rProperties.end(), [&](const beans::Property& rProperty)
{
@@ -48,13 +62,24 @@ bool lcl_containsProperty(const uno::Sequence<beans::Property> & rProperties, co
}) != rProperties.end();
}
+void removeAllProperties(uno::Reference<beans::XPropertyContainer> const & rxPropertyContainer)
+{
+ uno::Reference<beans::XPropertySet> xPropertySet(rxPropertyContainer, uno::UNO_QUERY);
+ uno::Sequence<beans::Property> aProperties = xPropertySet->getPropertySetInfo()->getProperties();
+
+ for (const beans::Property& rProperty : aProperties)
+ {
+ rxPropertyContainer->removeProperty(rProperty.Name);
+ }
+}
+
bool addOrInsertDocumentProperty(uno::Reference<beans::XPropertyContainer> const & rxPropertyContainer, OUString const & rsKey, OUString const & rsValue)
{
uno::Reference<beans::XPropertySet> xPropertySet(rxPropertyContainer, uno::UNO_QUERY);
try
{
- if (lcl_containsProperty(xPropertySet->getPropertySetInfo()->getProperties(), rsKey))
+ if (containsProperty(xPropertySet->getPropertySetInfo()->getProperties(), rsKey))
xPropertySet->setPropertyValue(rsKey, uno::makeAny(rsValue));
else
rxPropertyContainer->addProperty(rsKey, beans::PropertyAttribute::REMOVABLE, uno::makeAny(rsValue));
@@ -70,7 +95,7 @@ void insertFullTextualRepresentationAsDocumentProperty(uno::Reference<beans::XPr
sfx::ClassificationKeyCreator const & rKeyCreator,
std::vector<svx::ClassificationResult> const & rResults)
{
- OUString sString = svx::classification::convertClassificationResultToString(rResults);
+ OUString sString = convertClassificationResultToString(rResults);
addOrInsertDocumentProperty(rxPropertyContainer, rKeyCreator.makeFullTextualRepresentationKey(), sString);
}
diff --git a/svx/source/dialog/ClassificationDialog.cxx b/svx/source/dialog/ClassificationDialog.cxx
index 9458ceb95b3e..34b5d1504344 100644
--- a/svx/source/dialog/ClassificationDialog.cxx
+++ b/svx/source/dialog/ClassificationDialog.cxx
@@ -9,6 +9,7 @@
*/
#include <svx/ClassificationDialog.hxx>
+#include <svx/ClassificationCommon.hxx>
#include <svx/strings.hrc>
#include <svx/dialmgr.hxx>
@@ -78,6 +79,15 @@ namespace {
constexpr size_t RECENTLY_USED_LIMIT = 5;
+const OUString constRecentlyUsedFileName("recentlyUsed.xml");
+
+OUString lcl_getClassificationUserPath()
+{
+ OUString sPath("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/user/classification/");
+ rtl::Bootstrap::expandMacros(sPath);
+ return sPath;
+}
+
const SvxFieldItem* findField(editeng::Section const & rSection)
{
for (SfxPoolItem const * pPool : rSection.maAttributes)
@@ -112,26 +122,22 @@ bool stringToClassificationType(OString const & rsType, svx::ClassificationType
return true;
}
-OUString getStringRepresentation(std::vector<ClassificationResult> const & rResults)
+OUString classificationTypeToString(svx::ClassificationType const & reType)
{
- OUString sRepresentation = "";
- for (ClassificationResult const & rResult : rResults)
+ switch(reType)
{
- switch (rResult.meType)
- {
- case svx::ClassificationType::CATEGORY:
- case svx::ClassificationType::INTELLECTUAL_PROPERTY_PART:
- case svx::ClassificationType::MARKING:
- case svx::ClassificationType::TEXT:
- sRepresentation += rResult.msName;
- break;
-
- case svx::ClassificationType::PARAGRAPH:
- sRepresentation += " ";
- break;
- }
+ case svx::ClassificationType::CATEGORY:
+ return OUString("CATEGORY"); break;
+ case svx::ClassificationType::MARKING:
+ return OUString("MARKING"); break;
+ case svx::ClassificationType::TEXT:
+ return OUString("TEXT"); break;
+ case svx::ClassificationType::INTELLECTUAL_PROPERTY_PART:
+ return OUString("INTELLECTUAL_PROPERTY_PART"); break;
+ case svx::ClassificationType::PARAGRAPH:
+ return OUString("PARAGRAPH"); break;
}
- return sRepresentation;
+ return OUString();
}
void writeResultToXml(tools::XmlWriter & rXmlWriter,
@@ -140,20 +146,7 @@ void writeResultToXml(tools::XmlWriter & rXmlWriter,
for (ClassificationResult const & rResult : rResultCollection)
{
rXmlWriter.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;
- }
+ OUString sType = classificationTypeToString(rResult.meType);
rXmlWriter.attribute("type", sType);
rXmlWriter.startElement("string");
rXmlWriter.content(rResult.msName);
@@ -276,7 +269,7 @@ short ClassificationDialog::Execute()
{
for (std::vector<ClassificationResult> const & rResults : m_aRecentlyUsedValuesCollection)
{
- OUString rContentRepresentation = getStringRepresentation(rResults);
+ OUString rContentRepresentation = svx::classification::convertClassificationResultToString(rResults);
OUString rDescription = OUString::number(nNumber) + ": ";
nNumber++;
@@ -310,10 +303,8 @@ void ClassificationDialog::setupValues(std::vector<ClassificationResult> const &
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");
+ OUString sPath = lcl_getClassificationUserPath();
+ OUString sFilePath(sPath + constRecentlyUsedFileName);
if (!fileExists(sFilePath))
return;
@@ -378,11 +369,9 @@ void ClassificationDialog::readRecentlyUsed()
void ClassificationDialog::writeRecentlyUsed()
{
- OUString sPath("${$BRAND_BASE_DIR/" LIBO_ETC_FOLDER "/" SAL_CONFIGFILE("bootstrap") ":UserInstallation}/user/classification/");
- rtl::Bootstrap::expandMacros(sPath);
+ OUString sPath = lcl_getClassificationUserPath();
osl::Directory::createPath(sPath);
-
- OUString sFilePath(sPath + "recentlyUsed.xml");
+ OUString sFilePath(sPath + constRecentlyUsedFileName);
std::unique_ptr<SvStream> pStream;
pStream.reset(new SvFileStream(sFilePath, StreamMode::STD_READWRITE | StreamMode::TRUNC));