summaryrefslogtreecommitdiff
path: root/sw/source
diff options
context:
space:
mode:
authorEilidh McAdam <eilidh.mcadam@gmail.com>2014-07-25 20:35:43 +0100
committerBjörn Michaelsen <bjoern.michaelsen@canonical.com>2014-09-16 08:37:43 +0000
commit636718c960a36bc28d37a69ac102dd6cb696bfba (patch)
tree33637a0c465cff7175c4486ed3e83bda98dee8e3 /sw/source
parent4851cde7b98226b0f82ae2b191c290173e9b06c6 (diff)
Make UNO and wizard mail merge use same function.
Instead of MergeDocuments and MergeMailFiles duplicating largely the same functionality, the only user of MergeDocuments (MM wizard) now uses MergeMailFiles. Change-Id: Ifad183bdeabf5ca1eb08b4b1df557404a54a9fdd Reviewed-on: https://gerrit.libreoffice.org/10981 Reviewed-by: Björn Michaelsen <bjoern.michaelsen@canonical.com> Tested-by: Björn Michaelsen <bjoern.michaelsen@canonical.com>
Diffstat (limited to 'sw/source')
-rw-r--r--sw/source/ui/dbui/mailmergewizard.cxx16
-rw-r--r--sw/source/uibase/dbui/dbmgr.cxx33
2 files changed, 39 insertions, 10 deletions
diff --git a/sw/source/ui/dbui/mailmergewizard.cxx b/sw/source/ui/dbui/mailmergewizard.cxx
index 677717d6306b..d2ac379d7668 100644
--- a/sw/source/ui/dbui/mailmergewizard.cxx
+++ b/sw/source/ui/dbui/mailmergewizard.cxx
@@ -34,6 +34,7 @@
#include <sfx2/viewfrm.hxx>
#include <wrtsh.hxx>
#include <vcl/msgbox.hxx>
+#include <svx/dataaccessdescriptor.hxx>
#include <helpid.h>
@@ -269,8 +270,19 @@ void SwMailMergeWizard::UpdateRoadmap()
// enables/disables pages in the roadmap depending on the current page and state
void SwMailMergeWizard::CreateTargetDocument()
{
- GetSwView()->GetWrtShell().GetDBManager()->
- MergeDocuments( m_rConfigItem, *GetSwView() );
+ svx::ODataAccessDescriptor aDescriptor;
+ aDescriptor.setDataSource( m_rConfigItem.GetCurrentDBData().sDataSource );
+ aDescriptor[ svx::daConnection ] <<= m_rConfigItem.GetConnection().getTyped();
+ aDescriptor[ svx::daCursor ] <<= m_rConfigItem.GetResultSet();
+ aDescriptor[ svx::daCommand ] <<= m_rConfigItem.GetCurrentDBData().sCommand;
+ aDescriptor[ svx::daCommandType ] <<= m_rConfigItem.GetCurrentDBData().nCommandType;
+
+ SwMergeDescriptor aMergeDesc( DBMGR_MERGE_ONLY, GetSwView()->GetWrtShell(),
+ aDescriptor);
+ aMergeDesc.pMailMergeConfigItem = &m_rConfigItem;
+ aMergeDesc.bCreateSingleFile = true;
+
+ GetSwView()->GetWrtShell().GetDBManager()->MergeNew( aMergeDesc );
m_rConfigItem.SetMergeDone();
if( m_rConfigItem.GetTargetView() )
m_rConfigItem.GetTargetView()->GetViewFrame()->GetFrame().Appear();
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index fcb47c6c4b11..fdd8e6956ce0 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -318,7 +318,7 @@ static bool lcl_GetColumnCnt(SwDSParam* pParam,
};
// import data
-bool SwDBManager::MergeNew(const SwMergeDescriptor& rMergeDesc )
+bool SwDBManager::MergeNew( const SwMergeDescriptor& rMergeDesc )
{
OSL_ENSURE(!bInMerge && !pImpl->pMergeData, "merge already activated!");
@@ -434,6 +434,7 @@ bool SwDBManager::MergeNew(const SwMergeDescriptor& rMergeDesc )
case DBMGR_MERGE_MAILING:
case DBMGR_MERGE_MAILFILES:
case DBMGR_MERGE_SINGLE_FILE:
+ case DBMGR_MERGE_ONLY:
// save files and send them as e-Mail if required
bRet = MergeMailFiles(&rMergeDesc.rSh,
rMergeDesc);
@@ -849,13 +850,14 @@ static void lcl_SaveDoc( SfxObjectShell *xTargetDocShell,
#endif
bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
- const SwMergeDescriptor& rMergeDescriptor)
+ const SwMergeDescriptor& rMergeDescriptor)
{
//check if the doc is synchronized and contains at least one linked section
bool bSynchronizedDoc = pSourceShell->IsLabelDoc() && pSourceShell->GetSectionFmtCount() > 1;
bool bNoError = true;
bool bEMail = rMergeDescriptor.nMergeType == DBMGR_MERGE_MAILING;
const bool bAsSingleFile = rMergeDescriptor.nMergeType == DBMGR_MERGE_SINGLE_FILE;
+ bool bMergeOnly = rMergeDescriptor.nMergeType == DBMGR_MERGE_ONLY;
::rtl::Reference< MailDispatcher > xMailDispatcher;
OUString sBodyMimeType;
@@ -925,9 +927,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
SwWrtShell* pTargetShell = 0;
SwDoc* pTargetDoc = 0;
- // the shell will be explicitly closed at the end of the method, but it is
- // still more safe to use SfxObjectShellLock here
- SfxObjectShellLock xTargetDocShell;
+ SfxObjectShellRef xTargetDocShell;
SwView* pTargetView = 0;
boost::scoped_ptr< utl::TempFile > aTempFile;
@@ -1126,6 +1126,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
else
pTargetPageDesc = pTargetShell->FindPageDescByName( sModifiedStartingPageDesc );
+ sal_uInt16 nStartPage = pTargetShell->GetPageCnt();
#ifdef DBG_UTIL
if ( nDocNo <= MAX_DOC_DUMP )
lcl_SaveDoc( xWorkDocSh, "WorkDoc", nDocNo );
@@ -1139,6 +1140,15 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
if ( nDocNo <= MAX_DOC_DUMP )
lcl_SaveDoc( xTargetDocShell, "MergeDoc" );
#endif
+ if (bMergeOnly)
+ {
+ SwDocMergeInfo aMergeInfo;
+ aMergeInfo.nStartPageInTarget = nStartPage;
+ aMergeInfo.nEndPageInTarget =
+ nStartPage + pSourceShell->GetPageCnt() - 1;
+ aMergeInfo.nDBRow = nStartRow;
+ rMergeDescriptor.pMailMergeConfigItem->AddMergedDocument( aMergeInfo );
+ }
}
else
{
@@ -1278,7 +1288,11 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
aPrtMonDlg.Show( false );
// save the single output document
- if(rMergeDescriptor.bCreateSingleFile || bAsSingleFile)
+ if (bMergeOnly)
+ {
+ rMergeDescriptor.pMailMergeConfigItem->SetTargetView( pTargetView );
+ }
+ else if(rMergeDescriptor.bCreateSingleFile || bAsSingleFile)
{
if( rMergeDescriptor.nMergeType != DBMGR_MERGE_MAILMERGE )
{
@@ -1347,7 +1361,10 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
pTargetView->ExecPrint( aOptions, IsMergeSilent(), rMergeDescriptor.bPrintAsync );
}
- xTargetDocShell->DoClose();
+
+ // Leave docshell available for caller (e.g. MM wizard)
+ if (!bMergeOnly)
+ xTargetDocShell->DoClose();
}
//remove the temporary files
@@ -2770,7 +2787,7 @@ sal_Int32 SwDBManager::MergeDocuments( SwMailMergeConfigItem& rMMConfig,
bInMerge = true;
sal_Int32 nRet = 0;
pImpl->pMergeData = new SwDSParam(
- rMMConfig.GetCurrentDBData(), xResultSet, rMMConfig.GetSelection());
+ rMMConfig.GetCurrentDBData(), xResultSet, rMMConfig.GetSelection());
try{
//set to start position