diff options
author | Jan-Marek Glogowski <glogow@fbihome.de> | 2016-03-24 13:43:46 +0100 |
---|---|---|
committer | Jan-Marek Glogowski <glogow@fbihome.de> | 2016-03-24 22:40:41 +0100 |
commit | e637b6743a506ef74c93ccbe15ab6642f3baa34f (patch) | |
tree | 8318b820a833163d64f6b55e5c08b23978999bbd /sw/source | |
parent | 3e33c891ab9c49e6fb4b3767c5e6daae651ebc82 (diff) |
MM: move email subject and address into descriptor
Both are not related to the DBManager, but the mail merge job.
While at it, also drop the insane bSubjectIsFilename handling, add
an independent sPath, rename sAddressFromColumn to a more general
sDBcolumn, as it's also used for file name lookup in FILE mode, and
unify the DB column data handling.
Change-Id: I1b583f4a67279a229329ba7cd15fb8d2c215737c
Diffstat (limited to 'sw/source')
-rw-r--r-- | sw/source/ui/dialog/swdlgfact.cxx | 4 | ||||
-rw-r--r-- | sw/source/ui/dialog/swdlgfact.hxx | 2 | ||||
-rw-r--r-- | sw/source/ui/envelp/mailmrge.cxx | 38 | ||||
-rw-r--r-- | sw/source/uibase/dbui/dbmgr.cxx | 78 | ||||
-rw-r--r-- | sw/source/uibase/inc/mailmrge.hxx | 6 | ||||
-rw-r--r-- | sw/source/uibase/uno/unomailmerge.cxx | 25 |
6 files changed, 87 insertions, 66 deletions
diff --git a/sw/source/ui/dialog/swdlgfact.cxx b/sw/source/ui/dialog/swdlgfact.cxx index 808c8bedf276..9a1888fe0b17 100644 --- a/sw/source/ui/dialog/swdlgfact.cxx +++ b/sw/source/ui/dialog/swdlgfact.cxx @@ -512,9 +512,9 @@ OUString AbstractMailMergeDlg_Impl::GetColumnName() const return pDlg->GetColumnName(); } -OUString AbstractMailMergeDlg_Impl::GetPath() const +OUString AbstractMailMergeDlg_Impl::GetTargetURL() const { - return pDlg->GetPath(); + return pDlg->GetTargetURL(); } bool AbstractMailMergeCreateFromDlg_Impl::IsThisDocument() const diff --git a/sw/source/ui/dialog/swdlgfact.hxx b/sw/source/ui/dialog/swdlgfact.hxx index 605248b39c03..eedba0552bc7 100644 --- a/sw/source/ui/dialog/swdlgfact.hxx +++ b/sw/source/ui/dialog/swdlgfact.hxx @@ -284,7 +284,7 @@ class AbstractMailMergeDlg_Impl : public AbstractMailMergeDlg virtual bool IsSaveSingleDoc() const override; virtual bool IsGenerateFromDataBase() const override; virtual OUString GetColumnName() const override; - virtual OUString GetPath() const override; + virtual OUString GetTargetURL() const override; }; class SwMailMergeCreateFromDlg; diff --git a/sw/source/ui/envelp/mailmrge.cxx b/sw/source/ui/envelp/mailmrge.cxx index 5f55838598bf..184053aac2d7 100644 --- a/sw/source/ui/envelp/mailmrge.cxx +++ b/sw/source/ui/envelp/mailmrge.cxx @@ -486,12 +486,16 @@ IMPL_LINK_NOARG_TYPED(SwMailMergeDlg, ModifyHdl, Edit&, void) m_pFromRB->Check(); } +bool SwMailMergeDlg::AskUserFilename() const +{ + return (m_pSaveSingleDocRB->IsChecked() || !m_pGenerateFromDataBaseCB->IsChecked()); +} + bool SwMailMergeDlg::ExecQryShell() { if(pImpl->xSelSupp.is()) { pImpl->xSelSupp->removeSelectionChangeListener( pImpl->xChgLstnr ); } - SwDBManager* pMgr = rSh.GetDBManager(); if (m_pPrinterRB->IsChecked()) nMergeType = DBMGR_MERGE_PRINTER; @@ -501,33 +505,27 @@ bool SwMailMergeDlg::ExecQryShell() INetURLObject aAbs; if( pMedium ) aAbs = pMedium->GetURLObject(); - OUString sPath( + pModOpt->SetMailingPath( URIHelper::SmartRel2Abs( aAbs, m_pPathED->GetText(), URIHelper::GetMaybeFileHdl())); - pModOpt->SetMailingPath(sPath); - - if (!sPath.endsWith("/")) - sPath += "/"; pModOpt->SetIsNameFromColumn(m_pGenerateFromDataBaseCB->IsChecked()); - if (m_pGenerateFromDataBaseCB->IsEnabled() && m_pGenerateFromDataBaseCB->IsChecked()) { - pMgr->SetEMailColumn(m_pColumnLB->GetSelectEntry()); + if (!AskUserFilename()) { pModOpt->SetNameFromColumn(m_pColumnLB->GetSelectEntry()); if( m_pFilterLB->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND) m_sSaveFilter = *static_cast<const OUString*>(m_pFilterLB->GetSelectEntryData()); + m_sFilename = OUString(); } else { //#i97667# reset column name - otherwise it's remembered from the last run - pMgr->SetEMailColumn(OUString()); + pModOpt->SetNameFromColumn(OUString()); //start save as dialog OUString sFilter; - sPath = SwMailMergeHelper::CallSaveAsDialog(sFilter); - if (sPath.isEmpty()) + m_sFilename = SwMailMergeHelper::CallSaveAsDialog(sFilter); + if (m_sFilename.isEmpty()) return false; m_sSaveFilter = sFilter; } - - pMgr->SetSubject(sPath); } if (m_pFromRB->IsChecked()) { // Insert list @@ -579,6 +577,20 @@ bool SwMailMergeDlg::ExecQryShell() return true; } +OUString SwMailMergeDlg::GetTargetURL() const +{ + if( AskUserFilename() ) + return m_sFilename; + OUString sPath( pModOpt->GetMailingPath() ); + if( sPath.isEmpty() ) { + SvtPathOptions aPathOpt; + sPath = aPathOpt.GetWorkPath(); + } + if( !sPath.endsWith("/") ) + sPath += "/"; + return sPath; +} + IMPL_LINK_NOARG_TYPED(SwMailMergeDlg, InsertPathHdl, Button*, void) { OUString sPath( m_pPathED->GetText() ); diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx index 3439f9351f4e..0751476d3687 100644 --- a/sw/source/uibase/dbui/dbmgr.cxx +++ b/sw/source/uibase/dbui/dbmgr.cxx @@ -987,16 +987,20 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, uno::Reference< beans::XPropertySet > xColumnProp; { - bool bColumnName = !sEMailAddrField.isEmpty(); - - if (bColumnName) + // Check for (mandatory) email or (optional) filename column + SwDBFormatData aColumnDBFormat; + bool bColumnName = !rMergeDescriptor.sDBcolumn.isEmpty(); + if( bColumnName ) { uno::Reference< sdbcx::XColumnsSupplier > xColsSupp( pImpl->pMergeData->xResultSet, uno::UNO_QUERY ); uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns(); - if(!xCols->hasByName(sEMailAddrField)) + if( !xCols->hasByName( rMergeDescriptor.sDBcolumn ) ) return false; - uno::Any aCol = xCols->getByName(sEMailAddrField); + uno::Any aCol = xCols->getByName( rMergeDescriptor.sDBcolumn ); aCol >>= xColumnProp; + + aColumnDBFormat.xFormatter = pImpl->pMergeData->xFormatter; + aColumnDBFormat.aNullDate = pImpl->pMergeData->aNullDate; } // Try saving the source document @@ -1169,33 +1173,36 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, SwView* pWorkView = nullptr; SwDoc* pWorkDoc = nullptr; SwDBManager* pWorkDocOrigDBManager = nullptr; + bool bWorkDocInitialized = false; do { nStartRow = pImpl->pMergeData ? pImpl->pMergeData->xResultSet->getRow() : 0; { - OUString sPath(sSubject); + OUString sPath = rMergeDescriptor.sPath; + OUString sColumnData; - OUString sAddress; - if( !bMT_EMAIL && bColumnName ) + // Read the indicated data column, which should contain a valid mail + // address or an optional file name + if( bMT_EMAIL || bColumnName ) { - SwDBFormatData aDBFormat; - aDBFormat.xFormatter = pImpl->pMergeData->xFormatter; - aDBFormat.aNullDate = pImpl->pMergeData->aNullDate; - sAddress = GetDBField( xColumnProp, aDBFormat); - if (sAddress.isEmpty()) - sAddress = "_"; - sPath += sAddress; + sColumnData = GetDBField( xColumnProp, aColumnDBFormat ); + if( !bMT_EMAIL ) + { + if (sColumnData.isEmpty()) + sColumnData = "_"; + sPath += sColumnData; + } } // create a new temporary file name - only done once in case of bCreateSingleFile - if( bNeedsTempFiles && ( 1 == nDocNo || !bCreateSingleFile )) + if( bNeedsTempFiles && ( !bWorkDocInitialized || !bCreateSingleFile )) { INetURLObject aEntry(sPath); OUString sLeading; //#i97667# if the name is from a database field then it will be used _as is_ - if( !sAddress.isEmpty() ) - sLeading = sAddress; + if( !sColumnData.isEmpty() ) + sLeading = sColumnData; else sLeading = aEntry.GetBase(); aEntry.removeSegment(); @@ -1203,8 +1210,6 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, OUString sExt(comphelper::string::stripStart(pStoreToFilter->GetDefaultExtension(), '*')); aTempFile.reset( new utl::TempFile(sLeading, true, &sExt, &sPath)); - if( rMergeDescriptor.bSubjectIsFilename ) - aTempFile->EnableKillingFile(); if( !aTempFile->IsValid() ) { ErrorHandler::HandleError( ERRCODE_IO_NOTSUPPORTED ); @@ -1237,7 +1242,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, // Create a copy of the source document and work with that one instead of the source. // If we're not in the single file mode (which requires modifying the document for the merging), // it is enough to do this just once. Currently PDF also has to be treated special. - if( 1 == nDocNo || bCreateSingleFile || bIsPDFexport ) + if( !bWorkDocInitialized || bCreateSingleFile || bIsPDFexport ) { assert( !xWorkDocSh.Is()); // copy the source document @@ -1330,7 +1335,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, if( targetDocPageCount % 2 == 1 ) ++targetDocPageCount; // Docs always start on odd pages (so offset must be even). SwNodeIndex appendedDocStart = pTargetDoc->AppendDoc(*rWorkShell.GetDoc(), - nStartingPageNo, pTargetPageDesc, nDocNo == 1, targetDocPageCount); + nStartingPageNo, pTargetPageDesc, !bWorkDocInitialized, targetDocPageCount); targetDocPageCount += rWorkShell.GetPageCnt(); if ( (nMaxDumpDocs < 0) || (nDocNo <= nMaxDumpDocs) ) lcl_SaveDebugDoc( xTargetDocShell, "MergeDoc" ); @@ -1346,7 +1351,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, } else if( bMT_PRINTER ) { - if( 1 == nDocNo ) // set up printing only once at the beginning + if( !bWorkDocInitialized ) // set up printing only once at the beginning { uno::Sequence< beans::PropertyValue > aOptions( rMergeDescriptor.aPrintOptions ); lcl_PreparePrinterOptions( rMergeDescriptor.aPrintOptions, false, aOptions ); @@ -1374,11 +1379,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, } if( bMT_EMAIL ) { - SwDBFormatData aDBFormat; - aDBFormat.xFormatter = pImpl->pMergeData->xFormatter; - aDBFormat.aNullDate = pImpl->pMergeData->aNullDate; - OUString sMailAddress = GetDBField( xColumnProp, aDBFormat); - if(!SwMailMergeHelper::CheckMailAddress( sMailAddress )) + if( !SwMailMergeHelper::CheckMailAddress( sColumnData ) ) { OSL_FAIL("invalid e-Mail address in database column"); } @@ -1388,9 +1389,10 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, uno::Reference< mail::XMailMessage > xMessage = pMessage; if(rMergeDescriptor.pMailMergeConfigItem->IsMailReplyTo()) pMessage->setReplyToAddress(rMergeDescriptor.pMailMergeConfigItem->GetMailReplyTo()); - pMessage->addRecipient( sMailAddress ); + pMessage->addRecipient( sColumnData ); pMessage->SetSenderAddress( rMergeDescriptor.pMailMergeConfigItem->GetMailAddress() ); OUString sBody; + if(rMergeDescriptor.bSendAsAttachment) { sBody = rMergeDescriptor.sMailBody; @@ -1457,6 +1459,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, } } } + bWorkDocInitialized = true; nDocNo++; nEndRow = pImpl->pMergeData ? pImpl->pMergeData->xResultSet->getRow() : 0; @@ -1510,7 +1513,15 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell, { // save merged document assert( aTempFile.get() ); - INetURLObject aTempFileURL( rMergeDescriptor.bSubjectIsFilename ? sSubject : aTempFile->GetURL()); + INetURLObject aTempFileURL; + if( rMergeDescriptor.sPath.isEmpty() ) + aTempFileURL.SetURL( aTempFile->GetURL() ); + else + { + aTempFileURL.SetURL( rMergeDescriptor.sPath ); + // remove the unneeded temporary file + aTempFile->EnableKillingFile(); + } bNoError = lcl_SaveDoc( &aTempFileURL, pStoreToFilter, pStoreToFilterOptions, &rMergeDescriptor.aSaveToFilterData, bIsPDFexport, xTargetDocShell, *pTargetShell ); @@ -2860,12 +2871,11 @@ void SwDBManager::ExecuteFormLetter( SwWrtShell& rSh, SwMergeDescriptor aMergeDesc( pImpl->pMergeDialog->GetMergeType(), pView->GetWrtShell(), aDescriptor ); aMergeDesc.sSaveToFilter = pImpl->pMergeDialog->GetSaveFilter(); - aMergeDesc.bCreateSingleFile = pImpl->pMergeDialog->IsSaveSingleDoc() && pImpl->pMergeDialog->GetMergeType() != DBMGR_MERGE_PRINTER; - aMergeDesc.bSubjectIsFilename = aMergeDesc.bCreateSingleFile; + aMergeDesc.bCreateSingleFile = pImpl->pMergeDialog->IsSaveSingleDoc(); + aMergeDesc.sPath = pImpl->pMergeDialog->GetTargetURL(); if( !aMergeDesc.bCreateSingleFile && pImpl->pMergeDialog->IsGenerateFromDataBase() ) { - aMergeDesc.sAddressFromColumn = pImpl->pMergeDialog->GetColumnName(); - aMergeDesc.sSubject = pImpl->pMergeDialog->GetPath(); + aMergeDesc.sDBcolumn = pImpl->pMergeDialog->GetColumnName(); } MergeNew(aMergeDesc); diff --git a/sw/source/uibase/inc/mailmrge.hxx b/sw/source/uibase/inc/mailmrge.hxx index f4d1aae66ce2..cc30e6c787a5 100644 --- a/sw/source/uibase/inc/mailmrge.hxx +++ b/sw/source/uibase/inc/mailmrge.hxx @@ -103,6 +103,7 @@ class SwMailMergeDlg : public SvxStandardDialog Size m_aDialogSize; OUString m_sSaveFilter; + OUString m_sFilename; DECL_LINK_TYPED( ButtonHdl, Button*, void ); DECL_LINK_TYPED( InsertPathHdl, Button*, void ); @@ -113,6 +114,7 @@ class SwMailMergeDlg : public SvxStandardDialog virtual void Apply() override; bool ExecQryShell(); + bool AskUserFilename() const; public: SwMailMergeDlg(vcl::Window* pParent, SwWrtShell& rSh, @@ -128,8 +130,8 @@ public: bool IsSaveSingleDoc() const { return m_pSaveSingleDocRB->IsChecked(); } bool IsGenerateFromDataBase() const { return m_pGenerateFromDataBaseCB->IsChecked(); } - OUString GetColumnName() const { return m_pColumnLB->GetSelectEntry();} - OUString GetPath() const { return m_pPathED->GetText();} + OUString GetColumnName() const { return m_pColumnLB->GetSelectEntry(); } + OUString GetTargetURL() const; const OUString& GetSaveFilter() const {return m_sSaveFilter;} inline const css::uno::Sequence< css::uno::Any > GetSelection() const { return m_aSelection; } diff --git a/sw/source/uibase/uno/unomailmerge.cxx b/sw/source/uibase/uno/unomailmerge.cxx index dcf1b39154d0..d5b9d97ff55d 100644 --- a/sw/source/uibase/uno/unomailmerge.cxx +++ b/sw/source/uibase/uno/unomailmerge.cxx @@ -700,7 +700,6 @@ uno::Any SAL_CALL SwXMailMerge::execute( aMergeDesc.pMailMergeConfigItem = pMMConfigItem.get(); break; case MailMergeType::FILE: - case MailMergeType::MAIL: { INetURLObject aURLObj; aURLObj.SetSmartProtocol( INetProtocol::File ); @@ -731,23 +730,22 @@ uno::Any SAL_CALL SwXMailMerge::execute( if (!aPath.isEmpty() && !aPath.endsWith(aDelim)) aPath += aDelim; if (bCurFileNameFromColumn) - pMgr->SetEMailColumn( aCurFileNamePrefix ); + aMergeDesc.sDBcolumn = aCurFileNamePrefix; else { aPath += aCurFileNamePrefix; - pMgr->SetEMailColumn( OUString() ); - } - pMgr->SetSubject( aPath ); - if(MailMergeType::FILE == nCurOutputType) - { - aMergeDesc.sSaveToFilter = m_sSaveFilter; - aMergeDesc.sSaveToFilterOptions = m_sSaveFilterOptions; - aMergeDesc.aSaveToFilterData = m_aSaveFilterData; - aMergeDesc.bCreateSingleFile = m_bSaveAsSingleFile; } - else + + aMergeDesc.sPath = aPath; + aMergeDesc.sSaveToFilter = m_sSaveFilter; + aMergeDesc.sSaveToFilterOptions = m_sSaveFilterOptions; + aMergeDesc.aSaveToFilterData = m_aSaveFilterData; + aMergeDesc.bCreateSingleFile = m_bSaveAsSingleFile; + } + break; + case MailMergeType::MAIL: { - pMgr->SetEMailColumn( m_sAddressFromColumn ); + aMergeDesc.sDBcolumn = m_sAddressFromColumn; if(m_sAddressFromColumn.isEmpty()) throw RuntimeException("Mail address column not set.", static_cast < cppu::OWeakObject * > ( this ) ); aMergeDesc.sSaveToFilter = m_sAttachmentFilter; @@ -769,7 +767,6 @@ uno::Any SAL_CALL SwXMailMerge::execute( if( !aMergeDesc.xSmtpServer.is() || !aMergeDesc.xSmtpServer->isConnected()) throw RuntimeException("Failed to connect to mail server.", static_cast < cppu::OWeakObject * > ( this ) ); } - } break; } |