[Libreoffice-commits] core.git: 3 commits - include/sfx2 sd/source sfx2/source sw/source writerfilter/source

Miklos Vajna vmiklos at collabora.co.uk
Thu Mar 10 17:13:23 UTC 2016


 include/sfx2/classificationhelper.hxx          |    2 +
 sd/source/core/drawdoc.cxx                     |   32 +++++++++++++++++++++
 sd/source/ui/view/sdview3.cxx                  |   17 ++++++++++-
 sfx2/source/view/classificationhelper.cxx      |   29 +++++++++++++++++++
 sw/source/uibase/dochdl/swdtflvr.cxx           |   24 +--------------
 writerfilter/source/rtftok/rtfdocumentimpl.cxx |   38 +------------------------
 6 files changed, 83 insertions(+), 59 deletions(-)

New commits:
commit eff3f82033b5862af6300876aa69d9de0486d61b
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Mar 10 17:41:04 2016 +0100

    sd: handle classification during copy&paste
    
    This is the same feature as done for sw internal copy&paste and for the
    sw RTF filter: if the copying would leak information, better not to do
    that.
    
    Change-Id: I39186d7b798d822f1f3a5a4b1ce2aa000c6f7906

diff --git a/sd/source/ui/view/sdview3.cxx b/sd/source/ui/view/sdview3.cxx
index 2818612..cb01375 100644
--- a/sd/source/ui/view/sdview3.cxx
+++ b/sd/source/ui/view/sdview3.cxx
@@ -70,6 +70,7 @@
 #include "unomodel.hxx"
 #include "ViewClipboard.hxx"
 #include <sfx2/ipclient.hxx>
+#include <sfx2/classificationhelper.hxx>
 #include <comphelper/storagehelper.hxx>
 #include <comphelper/processfactory.hxx>
 #include <tools/stream.hxx>
@@ -355,7 +356,21 @@ bool View::InsertData( const TransferableDataHelper& rDataHelper,
     // the work was done; this allows to check multiple formats and not just fail
     // when a CHECK_FORMAT_TRANS(*format*) detected format does not work. This is
     // e.g. necessary for SotClipboardFormatId::BITMAP
-    if( pOwnData && nFormat == SotClipboardFormatId::NONE )
+
+    if (!bReturn && pOwnData)
+    {
+        // Paste only if SfxClassificationHelper recommends so.
+        const SfxObjectShellRef& pSource = pOwnData->GetDocShell();
+        SfxObjectShell* pDestination = mrDoc.GetDocSh();
+        if (pSource && pDestination)
+        {
+            SfxClassificationCheckPasteResult eResult = SfxClassificationHelper::CheckPaste(pSource->getDocProperties(), pDestination->getDocProperties());
+            if (!SfxClassificationHelper::ShowPasteInfo(eResult))
+                bReturn = true;
+        }
+    }
+
+    if( !bReturn && pOwnData && nFormat == SotClipboardFormatId::NONE )
     {
         const View* pSourceView = pOwnData->GetView();
 
commit 7c9f080aca4665980e8cf25ee42ad1b5ec64624b
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Mar 10 17:34:23 2016 +0100

    sd: copy doc metadata to clipboard document
    
    Just like in sw, doc metadata wasn't copied to the document. As a start,
    copy the user-defined doc properties. Note that this just takes care of
    the source -> clipboard part, it's still up to the clipboard ->
    destination code to decide how to merge the properties at the end.
    
    Change-Id: Ic506e25ab598f4748d443d65664a193d589acd3c

diff --git a/sd/source/core/drawdoc.cxx b/sd/source/core/drawdoc.cxx
index 62235b5..286c924 100644
--- a/sd/source/core/drawdoc.cxx
+++ b/sd/source/core/drawdoc.cxx
@@ -23,6 +23,9 @@
 #include <com/sun/star/text/WritingMode.hpp>
 #include <com/sun/star/document/PrinterIndependentLayout.hpp>
 #include <com/sun/star/i18n/ScriptType.hpp>
+#include <com/sun/star/beans/XPropertyContainer.hpp>
+#include <com/sun/star/beans/PropertyAttribute.hpp>
+#include <com/sun/star/document/XDocumentProperties.hpp>
 #include <editeng/forbiddencharacterstable.hxx>
 
 #include <svx/svxids.hrc>
@@ -438,6 +441,33 @@ SdrModel* SdDrawDocument::AllocModel() const
     return AllocSdDrawDocument();
 }
 
+namespace
+{
+
+/// Copies all user-defined properties from pSource to pDestination.
+void lcl_copyUserDefinedProperties(SfxObjectShell* pSource, SfxObjectShell* pDestination)
+{
+    if (!pSource || !pDestination)
+        return;
+
+    uno::Reference<document::XDocumentProperties> xSource = pSource->getDocProperties();
+    uno::Reference<document::XDocumentProperties> xDestination = pDestination->getDocProperties();
+    uno::Reference<beans::XPropertyContainer> xSourcePropertyContainer = xSource->getUserDefinedProperties();
+    uno::Reference<beans::XPropertyContainer> xDestinationPropertyContainer = xDestination->getUserDefinedProperties();
+    uno::Reference<beans::XPropertySet> xSourcePropertySet(xSourcePropertyContainer, uno::UNO_QUERY);
+    uno::Sequence<beans::Property> aProperties = xSourcePropertySet->getPropertySetInfo()->getProperties();
+
+    for (const beans::Property& rProperty : aProperties)
+    {
+        const OUString& rKey = rProperty.Name;
+        uno::Any aValue = xSourcePropertySet->getPropertyValue(rKey);
+        // We know that pDestination was just created, so has no properties: addProperty() will never throw.
+        xDestinationPropertyContainer->addProperty(rKey, beans::PropertyAttribute::REMOVABLE, aValue);
+    }
+}
+
+}
+
 // This method creates a new document (SdDrawDocument) and returns a pointer to
 // said document. The drawing engine uses this method to put the document (or
 // parts of it) into the clipboard/DragServer.
@@ -481,6 +511,8 @@ SdDrawDocument* SdDrawDocument::AllocSdDrawDocument() const
             pNewStylePool->CopyLayoutSheets(aOldLayoutName, *pOldStylePool, aCreatedSheets );
         }
 
+        lcl_copyUserDefinedProperties(GetDocSh(), pNewDocSh);
+
         pNewModel->NewOrLoadCompleted( DOC_LOADED );  // loaded from source document
     }
     else if( mbAllocDocSh )
commit 275443f052887f67a6d459d443293690daa3ae24
Author: Miklos Vajna <vmiklos at collabora.co.uk>
Date:   Thu Mar 10 15:04:25 2016 +0100

    sfx2 classification: merge common code from sw and writerfilter
    
    The two versions were almost a duplicate.
    
    Change-Id: I3148150d62484a55fc8d59ca354998f211435c0b

diff --git a/include/sfx2/classificationhelper.hxx b/include/sfx2/classificationhelper.hxx
index 9ce8933..5cf0cdd 100644
--- a/include/sfx2/classificationhelper.hxx
+++ b/include/sfx2/classificationhelper.hxx
@@ -45,6 +45,8 @@ public:
     /// Checks if pasting from xSource to xDestination would leak information.
     static SfxClassificationCheckPasteResult CheckPaste(const css::uno::Reference<css::document::XDocumentProperties>& xSource,
             const css::uno::Reference<css::document::XDocumentProperties>& xDestination);
+    /// Wrapper around CheckPaste(): informs the user if necessary and finds out if the paste can be continued or not.
+    static bool ShowPasteInfo(SfxClassificationCheckPasteResult eResult);
 
     SfxClassificationHelper(const css::uno::Reference<css::document::XDocumentProperties>& xDocumentProperties);
     ~SfxClassificationHelper();
diff --git a/sfx2/source/view/classificationhelper.cxx b/sfx2/source/view/classificationhelper.cxx
index 2abcff8..fc1d236 100644
--- a/sfx2/source/view/classificationhelper.cxx
+++ b/sfx2/source/view/classificationhelper.cxx
@@ -32,6 +32,7 @@
 #include <sfx2/viewfrm.hxx>
 #include <tools/datetime.hxx>
 #include <unotools/datetime.hxx>
+#include <vcl/layout.hxx>
 #include <config_folders.h>
 
 using namespace com::sun::star;
@@ -454,6 +455,34 @@ SfxClassificationCheckPasteResult SfxClassificationHelper::CheckPaste(const uno:
     return SfxClassificationCheckPasteResult::None;
 }
 
+bool SfxClassificationHelper::ShowPasteInfo(SfxClassificationCheckPasteResult eResult)
+{
+    switch (eResult)
+    {
+    case SfxClassificationCheckPasteResult::None:
+    {
+        return true;
+    }
+    break;
+    case SfxClassificationCheckPasteResult::TargetDocNotClassified:
+    {
+        if (!Application::IsHeadlessModeEnabled())
+            ScopedVclPtrInstance<MessageDialog>::Create(nullptr, SfxResId(STR_TARGET_DOC_NOT_CLASSIFIED), VCL_MESSAGE_INFO)->Execute();
+        return false;
+    }
+    break;
+    case SfxClassificationCheckPasteResult::DocClassificationTooLow:
+    {
+        if (!Application::IsHeadlessModeEnabled())
+            ScopedVclPtrInstance<MessageDialog>::Create(nullptr, SfxResId(STR_DOC_CLASSIFICATION_TOO_LOW), VCL_MESSAGE_INFO)->Execute();
+        return false;
+    }
+    break;
+    }
+
+    return true;
+}
+
 SfxClassificationHelper::SfxClassificationHelper(const uno::Reference<document::XDocumentProperties>& xDocumentProperties)
     : m_pImpl(o3tl::make_unique<Impl>(xDocumentProperties))
 {
diff --git a/sw/source/uibase/dochdl/swdtflvr.cxx b/sw/source/uibase/dochdl/swdtflvr.cxx
index 6d47e8f..5dc3dfd 100644
--- a/sw/source/uibase/dochdl/swdtflvr.cxx
+++ b/sw/source/uibase/dochdl/swdtflvr.cxx
@@ -3226,28 +3226,8 @@ bool lcl_checkClassification(SwDoc* pSourceDoc, SwDoc* pDestinationDoc)
     if (!pSourceShell || !pDestinationShell)
         return true;
 
-    switch (SfxClassificationHelper::CheckPaste(pSourceShell->getDocProperties(), pDestinationShell->getDocProperties()))
-    {
-    case SfxClassificationCheckPasteResult::None:
-    {
-        return true;
-    }
-    break;
-    case SfxClassificationCheckPasteResult::TargetDocNotClassified:
-    {
-        ScopedVclPtrInstance<MessageDialog>::Create(nullptr, SfxResId(STR_TARGET_DOC_NOT_CLASSIFIED), VCL_MESSAGE_INFO)->Execute();
-        return false;
-    }
-    break;
-    case SfxClassificationCheckPasteResult::DocClassificationTooLow:
-    {
-        ScopedVclPtrInstance<MessageDialog>::Create(nullptr, SfxResId(STR_DOC_CLASSIFICATION_TOO_LOW), VCL_MESSAGE_INFO)->Execute();
-        return false;
-    }
-    break;
-    }
-
-    return true;
+    SfxClassificationCheckPasteResult eResult = SfxClassificationHelper::CheckPaste(pSourceShell->getDocProperties(), pDestinationShell->getDocProperties());
+    return SfxClassificationHelper::ShowPasteInfo(eResult);
 }
 
 }
diff --git a/writerfilter/source/rtftok/rtfdocumentimpl.cxx b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
index c51ea14..021d802 100644
--- a/writerfilter/source/rtftok/rtfdocumentimpl.cxx
+++ b/writerfilter/source/rtftok/rtfdocumentimpl.cxx
@@ -5131,39 +5131,6 @@ bool lcl_containsProperty(const uno::Sequence<beans::Property>& rProperties, con
     }) != rProperties.end();
 }
 
-namespace
-{
-
-RTFError lcl_checkClassification(const uno::Reference<document::XDocumentProperties>& xSource, const uno::Reference<document::XDocumentProperties>& xDestination)
-{
-    switch (SfxClassificationHelper::CheckPaste(xSource, xDestination))
-    {
-    case SfxClassificationCheckPasteResult::None:
-    {
-        return RTFError::OK;
-    }
-    break;
-    case SfxClassificationCheckPasteResult::TargetDocNotClassified:
-    {
-        if (!Application::IsHeadlessModeEnabled())
-            ScopedVclPtrInstance<MessageDialog>::Create(nullptr, SfxResId(STR_TARGET_DOC_NOT_CLASSIFIED), VCL_MESSAGE_INFO)->Execute();
-        return RTFError::CLASSIFICATION;
-    }
-    break;
-    case SfxClassificationCheckPasteResult::DocClassificationTooLow:
-    {
-        if (!Application::IsHeadlessModeEnabled())
-            ScopedVclPtrInstance<MessageDialog>::Create(nullptr, SfxResId(STR_DOC_CLASSIFICATION_TOO_LOW), VCL_MESSAGE_INFO)->Execute();
-        return RTFError::CLASSIFICATION;
-    }
-    break;
-    }
-
-    return RTFError::OK;
-}
-
-}
-
 RTFError RTFDocumentImpl::popState()
 {
     //SAL_INFO("writerfilter", OSL_THIS_FUNC << " before pop: m_pTokenizer->getGroup() " << m_pTokenizer->getGroup() <<
@@ -5985,9 +5952,8 @@ RTFError RTFDocumentImpl::popState()
             if (!m_bIsNewDoc)
             {
                 // Check classification.
-                RTFError nError = lcl_checkClassification(xDocumentProperties, m_xDocumentProperties);
-                if (nError != RTFError::OK)
-                    return nError;
+                if (!SfxClassificationHelper::ShowPasteInfo(SfxClassificationHelper::CheckPaste(xDocumentProperties, m_xDocumentProperties)))
+                    return RTFError::CLASSIFICATION;
             }
 
             uno::Reference<beans::XPropertyContainer> xClipboardPropertyContainer = xDocumentProperties->getUserDefinedProperties();


More information about the Libreoffice-commits mailing list