summaryrefslogtreecommitdiff
path: root/sw/source/ui/uno/unomailmerge.cxx
diff options
context:
space:
mode:
authorJan-Marek Glogowski <glogow@fbihome.de>2013-12-22 17:42:20 +0100
committerMichael Stahl <mstahl@redhat.com>2014-02-12 10:23:05 +0000
commit1a12777f46954045afbe8fffa6dd199b4b338762 (patch)
tree48df2564f1dbdd151f6ee1460d5790c4264cee13 /sw/source/ui/uno/unomailmerge.cxx
parent2eb142f4207f921dfeb6f9d5cd34cb0fb288bdd1 (diff)
Export MailMerge cancel functionality via UNO.
If you start a mail merge jobs via UNO, there is no way to cancel it. But the functionality is already implemented and used by the LO internal mail merge dialogs. This patch adds an optional XCancellable interface to the MailMerge service and implements it in the SwXMailMerge class. As the XJob::execute function already uses the SolarMutex to prevent parallel runs, XCancellable::cancel can be implemented by storing the SwNewDBMgr in the private variable m_pMgr, protected by a mutex. The bCancel member has to be converted from a bitfield value to a real boolean, because otherwise all bitfield values would have to be protected by a mutex. Bitfield assignments aren't atomic as you always have to replace at least a byte. Change-Id: I007cc23fdf04ccfca7d3cd6180b0e17e99f53061 Reviewed-on: https://gerrit.libreoffice.org/7190 Reviewed-by: Michael Stahl <mstahl@redhat.com> Tested-by: Michael Stahl <mstahl@redhat.com>
Diffstat (limited to 'sw/source/ui/uno/unomailmerge.cxx')
-rw-r--r--sw/source/ui/uno/unomailmerge.cxx33
1 files changed, 32 insertions, 1 deletions
diff --git a/sw/source/ui/uno/unomailmerge.cxx b/sw/source/ui/uno/unomailmerge.cxx
index b6c93a0795dc..2e839d761df8 100644
--- a/sw/source/ui/uno/unomailmerge.cxx
+++ b/sw/source/ui/uno/unomailmerge.cxx
@@ -382,7 +382,8 @@ SwXMailMerge::SwXMailMerge() :
bSendAsHTML(sal_False),
bSendAsAttachment(sal_False),
bSaveAsSingleFile(sal_False),
- bDisposing(sal_False)
+ bDisposing(sal_False),
+ m_pMgr(0)
{
// create empty document
// like in: SwModule::InsertEnv (appenv.cxx)
@@ -411,11 +412,31 @@ SwXMailMerge::~SwXMailMerge()
}
}
+// Guarantee object consistence in case of an exception
+class MailMergeExecuteFinalizer {
+public:
+ MailMergeExecuteFinalizer(SwXMailMerge *mailmerge) {
+ OSL_ENSURE( mailmerge, "mailmerge object missing" );
+ this->m_aMailMerge = mailmerge;
+ }
+ ~MailMergeExecuteFinalizer() {
+ osl::MutexGuard pMgrGuard( GetMailMergeMutex() );
+ m_aMailMerge->m_pMgr = 0;
+ }
+
+private:
+ // Disallow copy
+ MailMergeExecuteFinalizer(const MailMergeExecuteFinalizer&) {}
+
+ SwXMailMerge *m_aMailMerge;
+};
+
uno::Any SAL_CALL SwXMailMerge::execute(
const uno::Sequence< beans::NamedValue >& rArguments )
throw (IllegalArgumentException, Exception, RuntimeException)
{
SolarMutexGuard aGuard;
+ MailMergeExecuteFinalizer aFinalizer(this);
// get property values to be used
// (use values from the service as default and override them with
@@ -655,6 +676,7 @@ uno::Any SAL_CALL SwXMailMerge::execute(
//force layout creation
rSh.CalcLayout();
OSL_ENSURE( pMgr, "database manager missing" );
+ m_pMgr = pMgr;
SwMergeDescriptor aMergeDesc( nMergeType, rSh, aDescriptor );
@@ -798,6 +820,15 @@ uno::Any SAL_CALL SwXMailMerge::execute(
return makeAny( sal_True );
}
+void SAL_CALL SwXMailMerge::cancel() throw (com::sun::star::uno::RuntimeException)
+{
+ // Cancel may be called from a second thread, so this protects from m_pMgr
+ /// cleanup in the execute function.
+ osl::MutexGuard pMgrGuard( GetMailMergeMutex() );
+ if (m_pMgr)
+ m_pMgr->MergeCancel();
+}
+
void SwXMailMerge::LaunchMailMergeEvent( const MailMergeEvent &rEvt ) const
{
cppu::OInterfaceIteratorHelper aIt( ((SwXMailMerge *) this)->aMergeListeners );