sw/inc/doc.hxx                  |   17 +++++
 sw/source/core/doc/docglos.cxx  |  121 ++++++++++++++++++++++++----------------
 sw/source/uibase/dbui/dbmgr.cxx |   46 +++++++++++++--
 3 files changed, 131 insertions(+), 53 deletions(-)

New commits:
commit cde554a731596f1ca53a911656b6503c96dadcc7
Author: Jan-Marek Glogowski <glo...@fbihome.de>
Date:   Sun Aug 3 12:10:40 2014 +0200

    fdo#81782 MM: copy most document properties
    
    Mail merge wasn't copying the document properties into the target
    document. It also has to copy most document properties into the
    working copy, as ConvertFieldsToText is called just there.
    
    Change-Id: I7e07fec712c225f667d960a94f4eb3fd0b83f041
    Reviewed-on: https://gerrit.libreoffice.org/10987
    Reviewed-by: Björn Michaelsen <bjoern.michael...@canonical.com>
    Tested-by: Björn Michaelsen <bjoern.michael...@canonical.com>

diff --git a/sw/inc/doc.hxx b/sw/inc/doc.hxx
index 21466fa..1742d8e 100644
--- a/sw/inc/doc.hxx
+++ b/sw/inc/doc.hxx
@@ -899,7 +899,22 @@ public:
     void ReplaceDefaults( const SwDoc& rSource );
 
     // Replace all compatability options with those from rSource.
-    void ReplaceCompatabilityOptions(const SwDoc& rSource);
+    void ReplaceCompatabilityOptions( const SwDoc& rSource );
+
+    /** Replace all user defined document properties with xSourceDocProps.
+
+        Convenince function used by ReplaceDocumentProperties to skip some UNO 
calls.
+     */
+    void ReplaceUserDefinedDocumentProperties( const 
::com::sun::star::uno::Reference< 
::com::sun::star::document::XDocumentProperties > xSourceDocProps );
+
+    // Replace all user defined document properties with those from rSource.
+    void ReplaceUserDefinedDocumentProperties( const SwDoc& rSource );
+
+    /** Replace document properties with those from rSource.
+
+        This includes the user defined document properties!
+     */
+    void ReplaceDocumentProperties(const SwDoc& rSource);
 
     // Query if style (paragraph- / character- / frame- / page-) is used.
     bool IsUsed( const SwModify& ) const;
diff --git a/sw/source/core/doc/docglos.cxx b/sw/source/core/doc/docglos.cxx
index 593e257..390177e 100644
--- a/sw/source/core/doc/docglos.cxx
+++ b/sw/source/core/doc/docglos.cxx
@@ -35,43 +35,26 @@
 
 using namespace ::com::sun::star;
 
-/// copy document properties via public interface
-static void lcl_copyDocumentProperties(
-        uno::Reference<document::XDocumentProperties> i_xSource,
-        uno::Reference<document::XDocumentProperties> i_xTarget) {
-    OSL_ENSURE(i_xSource.is(), "null reference");
-    OSL_ENSURE(i_xTarget.is(), "null reference");
-
-    i_xTarget->setAuthor(i_xSource->getAuthor());
-    i_xTarget->setGenerator(i_xSource->getGenerator());
-    i_xTarget->setCreationDate(i_xSource->getCreationDate());
-    i_xTarget->setTitle(i_xSource->getTitle());
-    i_xTarget->setSubject(i_xSource->getSubject());
-    i_xTarget->setDescription(i_xSource->getDescription());
-    i_xTarget->setKeywords(i_xSource->getKeywords());
-    i_xTarget->setLanguage(i_xSource->getLanguage());
-    i_xTarget->setModifiedBy(i_xSource->getModifiedBy());
-    i_xTarget->setModificationDate(i_xSource->getModificationDate());
-    i_xTarget->setPrintedBy(i_xSource->getPrintedBy());
-    i_xTarget->setPrintDate(i_xSource->getPrintDate());
-    i_xTarget->setTemplateName(i_xSource->getTemplateName());
-    i_xTarget->setTemplateURL(i_xSource->getTemplateURL());
-    i_xTarget->setTemplateDate(i_xSource->getTemplateDate());
-    i_xTarget->setAutoloadURL(i_xSource->getAutoloadURL());
-    i_xTarget->setAutoloadSecs(i_xSource->getAutoloadSecs());
-    i_xTarget->setDefaultTarget(i_xSource->getDefaultTarget());
-    i_xTarget->setDocumentStatistics(i_xSource->getDocumentStatistics());
-    i_xTarget->setEditingCycles(i_xSource->getEditingCycles());
-    i_xTarget->setEditingDuration(i_xSource->getEditingDuration());
+void SwDoc::ReplaceUserDefinedDocumentProperties(
+        uno::Reference<document::XDocumentProperties> xSourceDocProps)
+{
+    OSL_ENSURE(xSourceDocProps.is(), "null reference");
+
+    uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
+        GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
+    uno::Reference<document::XDocumentProperties> xDocProps(
+        xDPS->getDocumentProperties() );
+    OSL_ENSURE(xDocProps.is(), "null reference");
 
     uno::Reference<beans::XPropertySet> xSourceUDSet(
-        i_xSource->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
+        xSourceDocProps->getUserDefinedProperties(), uno::UNO_QUERY_THROW);
     uno::Reference<beans::XPropertyContainer> xTargetUD(
-        i_xTarget->getUserDefinedProperties());
+        xDocProps->getUserDefinedProperties());
     uno::Reference<beans::XPropertySet> xTargetUDSet(xTargetUD,
         uno::UNO_QUERY_THROW);
     uno::Sequence<beans::Property> tgtprops
         = xTargetUDSet->getPropertySetInfo()->getProperties();
+
     for (sal_Int32 i = 0; i < tgtprops.getLength(); ++i) {
         try {
             xTargetUD->removeProperty(tgtprops [i].Name);
@@ -79,20 +62,71 @@ static void lcl_copyDocumentProperties(
             // ignore
         }
     }
-    try {
-        uno::Reference<beans::XPropertySetInfo> xSetInfo
-            = xSourceUDSet->getPropertySetInfo();
-        uno::Sequence<beans::Property> srcprops = xSetInfo->getProperties();
-        for (sal_Int32 i = 0; i < srcprops.getLength(); ++i) {
+
+    uno::Reference<beans::XPropertySetInfo> xSetInfo
+        = xSourceUDSet->getPropertySetInfo();
+    uno::Sequence<beans::Property> srcprops = xSetInfo->getProperties();
+
+    for (sal_Int32 i = 0; i < srcprops.getLength(); ++i) {
+        try {
             OUString name = srcprops[i].Name;
             xTargetUD->addProperty(name, srcprops[i].Attributes,
                 xSourceUDSet->getPropertyValue(name));
+        } catch (uno::Exception &) {
+            // ignore
         }
-    } catch (uno::Exception &) {
-        // ignore
     }
 }
 
+void SwDoc::ReplaceUserDefinedDocumentProperties(const SwDoc& rSource)
+{
+    uno::Reference<document::XDocumentPropertiesSupplier> xSourceDPS(
+        rSource.GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
+    uno::Reference<document::XDocumentProperties> xSourceDocProps(
+        xSourceDPS->getDocumentProperties() );
+
+    ReplaceUserDefinedDocumentProperties( xSourceDocProps );
+}
+
+void SwDoc::ReplaceDocumentProperties(const SwDoc& rSource)
+{
+    uno::Reference<document::XDocumentPropertiesSupplier> xSourceDPS(
+        rSource.GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
+    uno::Reference<document::XDocumentProperties> xSourceDocProps(
+        xSourceDPS->getDocumentProperties() );
+    OSL_ENSURE(xSourceDocProps.is(), "null reference");
+
+    uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
+        GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
+    uno::Reference<document::XDocumentProperties> xDocProps(
+        xDPS->getDocumentProperties() );
+    OSL_ENSURE(xDocProps.is(), "null reference");
+
+    xDocProps->setAuthor(xSourceDocProps->getAuthor());
+    xDocProps->setGenerator(xSourceDocProps->getGenerator());
+    xDocProps->setCreationDate(xSourceDocProps->getCreationDate());
+    xDocProps->setTitle(xSourceDocProps->getTitle());
+    xDocProps->setSubject(xSourceDocProps->getSubject());
+    xDocProps->setDescription(xSourceDocProps->getDescription());
+    xDocProps->setKeywords(xSourceDocProps->getKeywords());
+    xDocProps->setLanguage(xSourceDocProps->getLanguage());
+    xDocProps->setModifiedBy(xSourceDocProps->getModifiedBy());
+    xDocProps->setModificationDate(xSourceDocProps->getModificationDate());
+    xDocProps->setPrintedBy(xSourceDocProps->getPrintedBy());
+    xDocProps->setPrintDate(xSourceDocProps->getPrintDate());
+    xDocProps->setTemplateName(xSourceDocProps->getTemplateName());
+    xDocProps->setTemplateURL(xSourceDocProps->getTemplateURL());
+    xDocProps->setTemplateDate(xSourceDocProps->getTemplateDate());
+    xDocProps->setAutoloadURL(xSourceDocProps->getAutoloadURL());
+    xDocProps->setAutoloadSecs(xSourceDocProps->getAutoloadSecs());
+    xDocProps->setDefaultTarget(xSourceDocProps->getDefaultTarget());
+    xDocProps->setDocumentStatistics(xSourceDocProps->getDocumentStatistics());
+    xDocProps->setEditingCycles(xSourceDocProps->getEditingCycles());
+    xDocProps->setEditingDuration(xSourceDocProps->getEditingDuration());
+
+    ReplaceUserDefinedDocumentProperties( xSourceDocProps );
+}
+
 /// inserts an AutoText block
 bool SwDoc::InsertGlossary( SwTextBlocks& rBlock, const OUString& rEntry,
                             SwPaM& rPaM, SwCrsrShell* pShell )
@@ -116,17 +150,8 @@ bool SwDoc::InsertGlossary( SwTextBlocks& rBlock, const 
OUString& rEntry,
             // target document to the glossary document
             // OSL_ENSURE(GetDocShell(), "no SwDocShell"); // may be clipboard!
             OSL_ENSURE(pGDoc->GetDocShell(), "no SwDocShell at glossary");
-            if (GetDocShell() && pGDoc->GetDocShell()) {
-                uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
-                    GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
-                uno::Reference<document::XDocumentProperties> xDocProps(
-                    xDPS->getDocumentProperties() );
-                uno::Reference<document::XDocumentPropertiesSupplier> xGlosDPS(
-                    pGDoc->GetDocShell()->GetModel(), uno::UNO_QUERY_THROW);
-                uno::Reference<document::XDocumentProperties> xGlosDocProps(
-                    xGlosDPS->getDocumentProperties() );
-                lcl_copyDocumentProperties(xDocProps, xGlosDocProps);
-        }
+            if (GetDocShell() && pGDoc->GetDocShell())
+                pGDoc->ReplaceDocumentProperties( *this );
             pGDoc->getIDocumentFieldsAccess().SetFixFields(false, NULL);
 
             // StartAllAction();
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index 59a43f6..d25743c 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -822,6 +822,32 @@ static void lcl_RemoveSectionLinks( SwWrtShell& rWorkShell 
)
     rWorkShell.SetLabelDoc( false );
 }
 
+// based on SwDoc::ReplaceDocumentProperties
+static void lcl_CopyDocumentPorperties(
+    const uno::Reference<document::XDocumentProperties> &xSourceDocProps,
+    const SfxObjectShell *xTargetDocShell, SwDoc *pTargetDoc)
+{
+    uno::Reference<document::XDocumentPropertiesSupplier> xDPS(
+        xTargetDocShell->GetModel(), uno::UNO_QUERY_THROW);
+    uno::Reference<document::XDocumentProperties> xTargetDocProps(
+        xDPS->getDocumentProperties());
+    OSL_ENSURE(xTargetDocProps.is(), "DocumentProperties is null");
+
+    xTargetDocProps->setTitle( xSourceDocProps->getTitle() );
+    xTargetDocProps->setSubject( xSourceDocProps->getSubject() );
+    xTargetDocProps->setDescription( xSourceDocProps->getDescription() );
+    xTargetDocProps->setKeywords( xSourceDocProps->getKeywords() );
+    xTargetDocProps->setAuthor( xSourceDocProps->getAuthor() );
+    xTargetDocProps->setGenerator( xSourceDocProps->getGenerator() );
+    xTargetDocProps->setLanguage( xSourceDocProps->getLanguage() );
+
+    // Manually set the creation date, otherwise author field isn't filled
+    // during MM, as it's set when saving the document the first time.
+    xTargetDocProps->setCreationDate( xSourceDocProps->getModificationDate() );
+
+    pTargetDoc->ReplaceUserDefinedDocumentProperties( xSourceDocProps );
+}
+
 #ifdef DBG_UTIL
 
 #define MAX_DOC_DUMP 3
@@ -895,6 +921,15 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
         // Try saving the source document
         SfxDispatcher* pSfxDispatcher = 
pSourceShell->GetView().GetViewFrame()->GetDispatcher();
         SwDocShell* pSourceDocSh = pSourceShell->GetView().GetDocShell();
+
+        uno::Reference<document::XDocumentProperties> xSourceDocProps;
+        {
+            uno::Reference<document::XDocumentPropertiesSupplier>
+                xDPS(pSourceDocSh->GetModel(), uno::UNO_QUERY);
+            xSourceDocProps.set(xDPS->getDocumentProperties());
+            OSL_ENSURE(xSourceDocProps.is(), "DocumentProperties is null");
+        }
+
         if( !bMergeOnly && pSourceDocSh->IsModified() )
             pSfxDispatcher->Execute( pSourceDocSh->HasName() ? SID_SAVEDOC : 
SID_SAVEASDOC, SFX_CALLMODE_SYNCHRON|SFX_CALLMODE_RECORD);
         if( bMergeOnly || !pSourceDocSh->IsModified() )
@@ -995,6 +1030,8 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
                 lcl_CopyCompatibilityOptions( *pSourceShell, *pTargetShell);
                 // #72821# copy dynamic defaults
                 lcl_CopyDynamicDefaults( *pSourceShell->GetDoc(), 
*pTargetShell->GetDoc() );
+
+                lcl_CopyDocumentPorperties( xSourceDocProps, xTargetDocShell, 
pTargetDoc );
             }
 
             // Progress, to prohibit KeyInputs
@@ -1085,10 +1122,6 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* 
pSourceShell,
                         // The SfxObjectShell will be closed explicitly later 
but it is more safe to use SfxObjectShellLock here
                         // copy the source document
                         SfxObjectShellLock xWorkDocSh = 
pSourceDocSh->GetDoc()->CreateCopy( true );
-#ifdef DBG_UTIL
-                        if ( nDocNo <= MAX_DOC_DUMP )
-                            lcl_SaveDoc( xWorkDocSh, "WorkDoc", nDocNo );
-#endif
 
                         //create a view frame for the document
                         SwView* pWorkView = static_cast< SwView* >( 
SfxViewFrame::LoadHiddenDocument( *xWorkDocSh, 0 )->GetViewShell() );
@@ -1097,6 +1130,11 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* 
pSourceShell,
                         pWorkView->AttrChangedNotify( &rWorkShell );// in 
order for SelectShell to be called
 
                         SwDoc* pWorkDoc = rWorkShell.GetDoc();
+                        lcl_CopyDocumentPorperties( xSourceDocProps, 
xWorkDocSh, pWorkDoc );
+#ifdef DBG_UTIL
+                        if ( nDocNo <= MAX_DOC_DUMP )
+                            lcl_SaveDoc( xWorkDocSh, "WorkDoc", nDocNo );
+#endif
                         SwDBManager* pOldDBManager = pWorkDoc->GetDBManager();
                         pWorkDoc->SetDBManager( this );
                         
pWorkDoc->getIDocumentLinksAdministration().EmbedAllLinks();
_______________________________________________
Libreoffice-commits mailing list
libreoffice-comm...@lists.freedesktop.org
http://lists.freedesktop.org/mailman/listinfo/libreoffice-commits

Reply via email to