[Libreoffice-commits] core.git: 4 commits - include/sfx2 sfx2/classification sfx2/source

Miklos Vajna vmiklos at collabora.co.uk
Tue Feb 23 15:09:31 UTC 2016


 include/sfx2/classificationhelper.hxx     |    2 
 sfx2/classification/example.xml           |    8 +--
 sfx2/source/view/classificationhelper.cxx |   77 ++++++++++++++++++++++++++++--
 sfx2/source/view/viewfrm.cxx              |   11 ----
 4 files changed, 80 insertions(+), 18 deletions(-)

New commits:
commit 12ef6bd2a37e2a3e27123c0f796b0e7f4e14f051
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Feb 23 15:24:38 2016 +0100

    sfx2 classification: update infobar after setting category name
    
    So one doesn't need to reload the document to see an up to date infobar.
    
    Change-Id: I42b0b8c2d7e4953157d73f06b724ba23f6b79cab

diff --git a/include/sfx2/classificationhelper.hxx b/include/sfx2/classificationhelper.hxx
index 1a19ee9..c8892dc 100644
--- a/include/sfx2/classificationhelper.hxx
+++ b/include/sfx2/classificationhelper.hxx
@@ -16,6 +16,7 @@
 #include <sfx2/dllapi.h>
 
 class SfxObjectShell;
+class SfxViewFrame;
 namespace basegfx
 {
 class BColor;
@@ -40,6 +41,7 @@ public:
     bool HasImpactLevel();
     basegfx::BColor GetImpactLevelColor();
     OUString GetDocumentWatermark();
+    void UpdateInfobar(SfxViewFrame& rViewFrame);
 };
 
 #endif
diff --git a/sfx2/source/view/classificationhelper.cxx b/sfx2/source/view/classificationhelper.cxx
index 1932585..ec9ea45 100644
--- a/sfx2/source/view/classificationhelper.cxx
+++ b/sfx2/source/view/classificationhelper.cxx
@@ -25,6 +25,9 @@
 #include <unotools/ucbstreamhelper.hxx>
 #include <unotools/streamwrap.hxx>
 #include <cppuhelper/implbase.hxx>
+#include <sfx2/sfx.hrc>
+#include <sfx2/sfxresid.hxx>
+#include <sfx2/viewfrm.hxx>
 #include <config_folders.h>
 
 using namespace com::sun::star;
@@ -286,6 +289,8 @@ public:
     void parsePolicy();
     /// Synchronize m_aLabels back to the object shell.
     void pushToObjectShell();
+    /// Updates infobar if necessary for an already loaded document.
+    void updateViewFrame();
 };
 
 SfxClassificationHelper::Impl::Impl(SfxObjectShell& rObjectShell)
@@ -486,6 +491,27 @@ void SfxClassificationHelper::SetBACName(const OUString& rName)
 
     m_pImpl->m_aLabels = it->second.m_aLabels;
     m_pImpl->pushToObjectShell();
+    SfxViewFrame* pViewFrame = SfxViewFrame::Current();
+    if (!pViewFrame)
+        return;
+
+    UpdateInfobar(*pViewFrame);
+}
+
+void SfxClassificationHelper::UpdateInfobar(SfxViewFrame& rViewFrame)
+{
+    OUString aBACName = GetBACName();
+    bool bImpactLevel = HasImpactLevel();
+    if (!aBACName.isEmpty() && bImpactLevel)
+    {
+        OUString aMessage = SfxResId(STR_CLASSIFIED_DOCUMENT);
+        aMessage = aMessage.replaceFirst("%1", aBACName);
+        basegfx::BColor aBackgroundColor = GetImpactLevelColor();
+        basegfx::BColor aForegroundColor(1.0, 1.0, 1.0);
+
+        rViewFrame.RemoveInfoBar("classification");
+        rViewFrame.AppendInfoBar("classification", aMessage, &aBackgroundColor, &aForegroundColor, &aForegroundColor, WB_CENTER);
+    }
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
diff --git a/sfx2/source/view/viewfrm.cxx b/sfx2/source/view/viewfrm.cxx
index f7315c7..0f49b8c 100644
--- a/sfx2/source/view/viewfrm.cxx
+++ b/sfx2/source/view/viewfrm.cxx
@@ -1348,16 +1348,7 @@ void SfxViewFrame::Notify( SfxBroadcaster& /*rBC*/, const SfxHint& rHint )
                 {
                     // Document has BAILS properties, display an infobar accordingly.
                     SfxClassificationHelper aHelper(*xObjSh.get());
-                    OUString aBACName = aHelper.GetBACName();
-                    bool bImpactLevel = aHelper.HasImpactLevel();
-                    if (!aBACName.isEmpty() && bImpactLevel)
-                    {
-                        OUString aMessage = SfxResId(STR_CLASSIFIED_DOCUMENT);
-                        aMessage = aMessage.replaceFirst("%1", aBACName);
-                        basegfx::BColor aBackgroundColor = aHelper.GetImpactLevelColor();
-                        basegfx::BColor aForegroundColor(1.0, 1.0, 1.0);
-                        AppendInfoBar("classification", aMessage, &aBackgroundColor, &aForegroundColor, &aForegroundColor, WB_CENTER);
-                    }
+                    aHelper.UpdateInfobar(*this);
                 }
 
                 break;
commit aad8e562765b2981e76a008e3eca04058279469f
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Feb 23 14:54:48 2016 +0100

    sfx2 classification: add or update labels
    
    Instead of just failing to add existing ones. Given that all "optional"
    properties are also updated (typically to "" or "None"), no need to
    remove properties.
    
    Change-Id: I50e73ac1ca3d3b7d3b3650ec6abdc0ff8c156936

diff --git a/sfx2/source/view/classificationhelper.cxx b/sfx2/source/view/classificationhelper.cxx
index 8c1d4b5..1932585 100644
--- a/sfx2/source/view/classificationhelper.cxx
+++ b/sfx2/source/view/classificationhelper.cxx
@@ -317,19 +317,32 @@ void SfxClassificationHelper::Impl::parsePolicy()
     m_aCategories = xClassificationParser->m_aCategories;
 }
 
+bool lcl_containsProperty(const uno::Sequence<beans::Property>& rProperties, const OUString& rName)
+{
+    return std::find_if(rProperties.begin(), rProperties.end(), [&](const beans::Property& rProperty)
+    {
+        return rProperty.Name == rName;
+    }) != rProperties.end();
+}
+
 void SfxClassificationHelper::Impl::pushToObjectShell()
 {
     uno::Reference<document::XDocumentProperties> xDocumentProperties = m_rObjectShell.getDocProperties();
     uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
+    uno::Reference<beans::XPropertySet> xPropertySet(xPropertyContainer, uno::UNO_QUERY);
+    uno::Sequence<beans::Property> aProperties = xPropertySet->getPropertySetInfo()->getProperties();
     for (const std::pair<OUString, OUString>& rLabel : m_aLabels)
     {
         try
         {
-            xPropertyContainer->addProperty(rLabel.first, beans::PropertyAttribute::REMOVABLE, uno::makeAny(rLabel.second));
+            if (lcl_containsProperty(aProperties, rLabel.first))
+                xPropertySet->setPropertyValue(rLabel.first, uno::makeAny(rLabel.second));
+            else
+                xPropertyContainer->addProperty(rLabel.first, beans::PropertyAttribute::REMOVABLE, uno::makeAny(rLabel.second));
         }
         catch (const uno::Exception& rException)
         {
-            SAL_WARN("sfx.view", "pushToObjectShell() failed to add property " << rLabel.first << ": " << rException.Message);
+            SAL_WARN("sfx.view", "pushToObjectShell() failed for property " << rLabel.first << ": " << rException.Message);
         }
     }
 }
commit 633e9b9b66f1717a90db73ee6954c8145b934ecb
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Feb 23 14:39:23 2016 +0100

    sfx2 classification: write category ID to document metadata
    
    The assumption is that the name may not be unique, but the ID always is.
    
    Change-Id: If6c5e34999c88732c978ed88871b384d9fe5c272

diff --git a/sfx2/classification/example.xml b/sfx2/classification/example.xml
index 40acd8a..053caeb 100644
--- a/sfx2/classification/example.xml
+++ b/sfx2/classification/example.xml
@@ -9,7 +9,7 @@
         <baf:BusinessAuthorizationCategory Identifier="urn:example:tscp:1:non-business" Name="Non-Business">
             <baf:LabelingRules/>
             <baf:ImpactLevel>
-                <baf:Scale>UK Cabinet</baf:Scale>
+                <baf:Scale>UK-Cabinet</baf:Scale>
                 <baf:ConfidentalityValue>0</baf:ConfidentalityValue>
             </baf:ImpactLevel>
         </baf:BusinessAuthorizationCategory>
@@ -21,7 +21,7 @@
                 </baf:VisualMarkingPart>
             </baf:LabelingRules>
             <baf:ImpactLevel>
-                <baf:Scale>UK Cabinet</baf:Scale>
+                <baf:Scale>UK-Cabinet</baf:Scale>
                 <baf:ConfidentalityValue>1</baf:ConfidentalityValue>
             </baf:ImpactLevel>
         </baf:BusinessAuthorizationCategory>
@@ -41,7 +41,7 @@
                 </baf:VisualMarkingPart>
             </baf:LabelingRules>
             <baf:ImpactLevel>
-                <baf:Scale>UK Cabinet</baf:Scale>
+                <baf:Scale>UK-Cabinet</baf:Scale>
                 <baf:ConfidentalityValue>2</baf:ConfidentalityValue>
             </baf:ImpactLevel>
         </baf:BusinessAuthorizationCategory>
@@ -61,7 +61,7 @@
                 </baf:VisualMarkingPart>
             </baf:LabelingRules>
             <baf:ImpactLevel>
-                <baf:Scale>UK Cabinet</baf:Scale>
+                <baf:Scale>UK-Cabinet</baf:Scale>
                 <baf:ConfidentalityValue>3</baf:ConfidentalityValue>
             </baf:ImpactLevel>
         </baf:BusinessAuthorizationCategory>
diff --git a/sfx2/source/view/classificationhelper.cxx b/sfx2/source/view/classificationhelper.cxx
index 014c5a8..8c1d4b5 100644
--- a/sfx2/source/view/classificationhelper.cxx
+++ b/sfx2/source/view/classificationhelper.cxx
@@ -131,20 +131,22 @@ throw (xml::sax::SAXException, uno::RuntimeException, std::exception)
         OUString aName = xAttribs->getValueByName("Name");
         if (!m_pCategory && !aName.isEmpty())
         {
+            OUString aIdentifier = xAttribs->getValueByName("Identifier");
+
             // Create a new category and initialize it with the data that's true for all categories.
             SfxClassificationCategory& rCategory = m_aCategories[aName];
             rCategory.m_aLabels["urn:bails:IntellectualProperty:PolicyAuthority:Name"] = m_aPolicyAuthorityName;
             rCategory.m_aLabels["urn:bails:IntellectualProperty:Policy:Name"] = m_aPolicyName;
+            rCategory.m_aLabels["urn:bails:IntellectualProperty:BusinessAuthorization:Identifier"] = m_aProgramID;
+            rCategory.m_aLabels["urn:bails:IntellectualProperty:BusinessAuthorizationCategory:Identifier"] = aIdentifier;
+            rCategory.m_aLabels["urn:bails:IntellectualProperty:BusinessAuthorizationCategory:Name"] = aName;
 
             // Also initialize defaults.
             rCategory.m_aLabels["urn:bails:IntellectualProperty:PolicyAuthority:Identifier"] = "None";
             rCategory.m_aLabels["urn:bails:IntellectualProperty:PolicyAuthority:Country"] = "None";
             rCategory.m_aLabels["urn:bails:IntellectualProperty:Policy:Identifier"] = "None";
             rCategory.m_aLabels["urn:bails:IntellectualProperty:BusinessAuthorization:Name"] = "None";
-            rCategory.m_aLabels["urn:bails:IntellectualProperty:BusinessAuthorization:Identifier"] = "None";
             rCategory.m_aLabels["urn:bails:IntellectualProperty:BusinessAuthorization:Locator"] = "None";
-            rCategory.m_aLabels["urn:bails:IntellectualProperty:BusinessAuthorizationCategory:Name"] = "None";
-            rCategory.m_aLabels["urn:bails:IntellectualProperty:BusinessAuthorizationCategory:Identifier"] = "None";
             rCategory.m_aLabels["urn:bails:IntellectualProperty:BusinessAuthorizationCategory:Identifier:OID"] = "None";
             rCategory.m_aLabels["urn:bails:IntellectualProperty:BusinessAuthorizationCategory:Locator"] = "None";
             rCategory.m_aLabels["urn:bails:IntellectualProperty:BusinessAuthorization:Locator"] = "None";
commit 27e2955e01d997a3b2be852126475cdf2aa7140b
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Tue Feb 23 14:18:42 2016 +0100

    sfx2 classification: write back updated labels as document properties
    
    The internal std::map is just for fast access, if document properties
    are not updated at the end, our changes are lost on document close.
    
    Change-Id: I34ce8e47faed96b6a9ddb5776806587d94fc4373

diff --git a/sfx2/source/view/classificationhelper.cxx b/sfx2/source/view/classificationhelper.cxx
index 2ae3415..014c5a8 100644
--- a/sfx2/source/view/classificationhelper.cxx
+++ b/sfx2/source/view/classificationhelper.cxx
@@ -16,6 +16,7 @@
 #include <com/sun/star/xml/sax/Parser.hpp>
 #include <com/sun/star/xml/sax/XDocumentHandler.hpp>
 #include <com/sun/star/xml/sax/SAXParseException.hpp>
+#include <com/sun/star/beans/PropertyAttribute.hpp>
 
 #include <sfx2/objsh.hxx>
 #include <o3tl/make_unique.hxx>
@@ -277,10 +278,19 @@ public:
     std::map<OUString, OUString> m_aLabels;
     /// Possible categories of a policy to choose from.
     std::map<OUString, SfxClassificationCategory> m_aCategories;
+    SfxObjectShell& m_rObjectShell;
 
+    Impl(SfxObjectShell& rObjectShell);
     void parsePolicy();
+    /// Synchronize m_aLabels back to the object shell.
+    void pushToObjectShell();
 };
 
+SfxClassificationHelper::Impl::Impl(SfxObjectShell& rObjectShell)
+    : m_rObjectShell(rObjectShell)
+{
+}
+
 void SfxClassificationHelper::Impl::parsePolicy()
 {
     OUString aPath("$BRAND_BASE_DIR/" LIBO_SHARE_FOLDER "/classification/example.xml");
@@ -305,6 +315,23 @@ void SfxClassificationHelper::Impl::parsePolicy()
     m_aCategories = xClassificationParser->m_aCategories;
 }
 
+void SfxClassificationHelper::Impl::pushToObjectShell()
+{
+    uno::Reference<document::XDocumentProperties> xDocumentProperties = m_rObjectShell.getDocProperties();
+    uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
+    for (const std::pair<OUString, OUString>& rLabel : m_aLabels)
+    {
+        try
+        {
+            xPropertyContainer->addProperty(rLabel.first, beans::PropertyAttribute::REMOVABLE, uno::makeAny(rLabel.second));
+        }
+        catch (const uno::Exception& rException)
+        {
+            SAL_WARN("sfx.view", "pushToObjectShell() failed to add property " << rLabel.first << ": " << rException.Message);
+        }
+    }
+}
+
 bool SfxClassificationHelper::IsClassified(SfxObjectShell& rObjectShell)
 {
     uno::Reference<document::XDocumentProperties> xDocumentProperties = rObjectShell.getDocProperties();
@@ -324,7 +351,7 @@ bool SfxClassificationHelper::IsClassified(SfxObjectShell& rObjectShell)
 }
 
 SfxClassificationHelper::SfxClassificationHelper(SfxObjectShell& rObjectShell)
-    : m_pImpl(o3tl::make_unique<Impl>())
+    : m_pImpl(o3tl::make_unique<Impl>(rObjectShell))
 {
     uno::Reference<document::XDocumentProperties> xDocumentProperties = rObjectShell.getDocProperties();
     uno::Reference<beans::XPropertyContainer> xPropertyContainer = xDocumentProperties->getUserDefinedProperties();
@@ -443,6 +470,7 @@ void SfxClassificationHelper::SetBACName(const OUString& rName)
     }
 
     m_pImpl->m_aLabels = it->second.m_aLabels;
+    m_pImpl->pushToObjectShell();
 }
 
 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */


More information about the Libreoffice-commits mailing list