summaryrefslogtreecommitdiff
path: root/sw
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2016-01-18 15:04:12 +0100
committerJan-Marek Glogowski <glogow@fbihome.de>2016-03-24 22:40:46 +0100
commit435ca34e14af3a8a5bacd54a011adbe235ac772b (patch)
treed8630d0091b0ee7691707fac0f551c0f803e12d6 /sw
parent5c1433d87cd015e30d3fc5c6554550e2cc46cc1c (diff)
MM: merge cancel and error variable
An error always includes the "cancel", while a cancel doesn't have to be an error. So merge handling by using an enum. Change-Id: I154dccbd3063d7ce37ee3cb90b4f193cb1edd466
Diffstat (limited to 'sw')
-rw-r--r--sw/inc/dbmgr.hxx16
-rw-r--r--sw/source/uibase/dbui/dbmgr.cxx48
2 files changed, 32 insertions, 32 deletions
diff --git a/sw/inc/dbmgr.hxx b/sw/inc/dbmgr.hxx
index 71611e24d367..9365949d4a31 100644
--- a/sw/inc/dbmgr.hxx
+++ b/sw/inc/dbmgr.hxx
@@ -230,14 +230,12 @@ class SW_DLLPUBLIC SwDBManager
{
friend class SwConnectionDisposedListener_Impl;
- /** Mail merge cancel indicator
+ enum class MergeStatus
+ {
+ OK = 0, CANCEL, ERROR
+ };
- TODO: convert m_bCancel to a three state escalating enum
- run, cancel, error. Not sure if this helps readability /
- further code cleanup, but it would be easier to follow the
- seamantics and we could get rid of bNoError in MergeMailFiles
- */
- bool m_bCancel;
+ MergeStatus m_aMergeStatus; ///< current / last merge status
bool bInitDBFields : 1;
bool bInMerge : 1; ///< merge process active
bool bMergeSilent : 1; ///< suppress display of dialogs/boxes (used when called over API)
@@ -296,6 +294,10 @@ public:
bool MergeNew( const SwMergeDescriptor& rMergeDesc, vcl::Window* pParent = nullptr );
void MergeCancel();
+ inline bool IsMergeOk() { return MergeStatus::OK == m_aMergeStatus; };
+ inline bool IsMergeCancel() { return MergeStatus::CANCEL <= m_aMergeStatus; };
+ inline bool IsMergeError() { return MergeStatus::ERROR <= m_aMergeStatus; };
+
/// Initialize data fields that lack name of database.
inline bool IsInitDBFields() const { return bInitDBFields; }
inline void SetInitDBFields(bool b) { bInitDBFields = b; }
diff --git a/sw/source/uibase/dbui/dbmgr.cxx b/sw/source/uibase/dbui/dbmgr.cxx
index 219abc20d0b6..5b3a653c0387 100644
--- a/sw/source/uibase/dbui/dbmgr.cxx
+++ b/sw/source/uibase/dbui/dbmgr.cxx
@@ -750,7 +750,7 @@ void SwDBManager::GetColumnNames(ListBox* pListBox,
}
SwDBManager::SwDBManager(SwDoc* pDoc)
- : m_bCancel(false)
+ : m_aMergeStatus( MergeStatus::OK )
, bInitDBFields(false)
, bInMerge(false)
, bMergeSilent(false)
@@ -984,10 +984,6 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
OUString sMailBodyMimeType;
rtl_TextEncoding sMailEncoding = ::osl_getThreadTextEncoding();
- // bNoError should be handled together with m_bCancel. while an error
- // should always also set cancel, cancel doesn't indicate an / set error.
- bool bNoError = true;
-
uno::Reference< beans::XPropertySet > xColumnProp;
{
// Check for (mandatory) email or (optional) filename column
@@ -1067,7 +1063,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
}
const bool bIsPDFexport = pStoreToFilter && pStoreToFilter->GetFilterName() == "writer_pdf_Export";
- m_bCancel = false;
+ m_aMergeStatus = MergeStatus::OK;
// in case of creating a single resulting file this has to be created here
SwView* pTargetView = rMergeDescriptor.pMailMergeConfigItem ?
@@ -1238,12 +1234,11 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
if( !aTempFile->IsValid() )
{
ErrorHandler::HandleError( ERRCODE_IO_NOTSUPPORTED );
- bNoError = false;
- m_bCancel = true;
+ m_aMergeStatus = MergeStatus::ERROR;
}
}
- if( !m_bCancel )
+ if( IsMergeOk() )
{
std::unique_ptr< INetURLObject > aTempFileURL;
if( bNeedsTempFiles )
@@ -1391,12 +1386,12 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
// some GetPrinter functions have a true default, so keep the false
SfxPrinter* pDocPrt = pWorkView->GetPrinter( false );
JobSetup aJobSetup = pDocPrt ? pDocPrt->GetJobSetup() : pWorkView->GetJobSetup();
- m_bCancel = !Printer::PreparePrintJob( pWorkView->GetPrinterController(), aJobSetup );
+ if( !Printer::PreparePrintJob( pWorkView->GetPrinterController(), aJobSetup ) )
+ MergeCancel();
}
- if( !m_bCancel && !Printer::ExecutePrintJob( pWorkView->GetPrinterController()))
+ if( IsMergeOk() && !Printer::ExecutePrintJob( pWorkView->GetPrinterController()) )
{
- m_bCancel = true;
- bNoError = false;
+ m_aMergeStatus = MergeStatus::ERROR;
}
}
else
@@ -1408,10 +1403,9 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
&rMergeDescriptor.aSaveToFilterData, bIsPDFexport,
xWorkDocSh, rWorkShell, &sFileURL ) )
{
- m_bCancel = true;
- bNoError = false;
+ m_aMergeStatus = MergeStatus::ERROR;
}
- if( bMT_EMAIL && bNoError )
+ if( bMT_EMAIL && !IsMergeError() )
{
if( !SwMailMergeHelper::CheckMailAddress( sColumnData ) )
{
@@ -1505,7 +1499,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
aLayout->FreezeLayout(true);
bFreezedLayouts = true;
}
- } while( !m_bCancel &&
+ } while( IsMergeOk() &&
(bSynchronizedDoc && (nStartRow != nEndRow)? ExistsNextRecord() : ToNextMergeRecord()));
if ( xWorkDocSh.Is() && pWorkView->GetWrtShell().IsExpFieldsLocked() )
@@ -1524,7 +1518,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
xWorkDocSh->DoClose();
}
}
- else if( !m_bCancel ) // && bCreateSingleFile
+ else if( IsMergeOk() ) // && bCreateSingleFile
{
RESCHEDULE_GUI;
@@ -1543,7 +1537,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
RESCHEDULE_GUI;
- if( !m_bCancel && bMT_FILE )
+ if( IsMergeOk() && bMT_FILE )
{
// save merged document
assert( aTempFile.get() );
@@ -1556,11 +1550,14 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
// remove the unneeded temporary file
aTempFile->EnableKillingFile();
}
- bNoError = lcl_SaveDoc( &aTempFileURL, pStoreToFilter,
+ if( !lcl_SaveDoc( &aTempFileURL, pStoreToFilter,
pStoreToFilterOptions, &rMergeDescriptor.aSaveToFilterData,
- bIsPDFexport, xTargetDocShell, *pTargetShell );
+ bIsPDFexport, xTargetDocShell, *pTargetShell ) )
+ {
+ m_aMergeStatus = MergeStatus::ERROR;
+ }
}
- else if( !m_bCancel && bMT_PRINTER )
+ else if( IsMergeOk() && bMT_PRINTER )
{
// print the target document
uno::Sequence< beans::PropertyValue > aOptions( rMergeDescriptor.aPrintOptions );
@@ -1568,7 +1565,7 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
pTargetView->ExecPrint( aOptions, IsMergeSilent(), rMergeDescriptor.bPrintAsync );
}
- if( !m_bCancel && bMT_SHELL )
+ if( IsMergeOk() && bMT_SHELL )
// leave docshell available for caller (e.g. MM wizard)
rMergeDescriptor.pMailMergeConfigItem->SetTargetView( pTargetView );
else
@@ -1601,12 +1598,13 @@ bool SwDBManager::MergeMailFiles(SwWrtShell* pSourceShell,
xMailDispatcher->shutdown();
}
- return bNoError;
+ return !IsMergeError();
}
void SwDBManager::MergeCancel()
{
- m_bCancel = true;
+ if (m_aMergeStatus < MergeStatus::CANCEL)
+ m_aMergeStatus = MergeStatus::CANCEL;
}
IMPL_LINK_TYPED( SwDBManager, PrtCancelHdl, Button *, pButton, void )