LibreOffice Module sw (master) 1
unomailmerge.cxx
Go to the documentation of this file.
1/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2/*
3 * This file is part of the LibreOffice project.
4 *
5 * This Source Code Form is subject to the terms of the Mozilla Public
6 * License, v. 2.0. If a copy of the MPL was not distributed with this
7 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 *
9 * This file incorporates work covered by the following license notice:
10 *
11 * Licensed to the Apache Software Foundation (ASF) under one or more
12 * contributor license agreements. See the NOTICE file distributed
13 * with this work for additional information regarding copyright
14 * ownership. The ASF licenses this file to you under the Apache
15 * License, Version 2.0 (the "License"); you may not use this file
16 * except in compliance with the License. You may obtain a copy of
17 * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 */
19
21#include <utility>
22#include <vcl/svapp.hxx>
23#include <osl/mutex.hxx>
24#include <svl/itemprop.hxx>
26#include <unotools/tempfile.hxx>
27#include <sfx2/app.hxx>
28#include <sfx2/docfilt.hxx>
29#include <tools/urlobj.hxx>
33#include <comphelper/string.hxx>
35#include <vcl/timer.hxx>
36#include <com/sun/star/sdb/CommandType.hpp>
37#include <com/sun/star/text/MailMergeType.hpp>
38#include <com/sun/star/text/MailMergeEvent.hpp>
39#include <com/sun/star/text/XMailMergeListener.hpp>
40#include <com/sun/star/beans/PropertyAttribute.hpp>
41#include <com/sun/star/sdbc/XResultSet.hpp>
42#include <com/sun/star/sdbc/XConnection.hpp>
43#include <com/sun/star/sdbc/XRowSet.hpp>
44#include <com/sun/star/frame/Desktop.hpp>
45#include <com/sun/star/util/XCloseable.hpp>
46#include <com/sun/star/util/CloseVetoException.hpp>
47#include <com/sun/star/sdbcx/XRowLocate.hpp>
48#include <com/sun/star/frame/XStorable.hpp>
49#include <com/sun/star/mail/XSmtpService.hpp>
50#include <sfx2/viewfrm.hxx>
51#include <sfx2/event.hxx>
53#include <printdata.hxx>
54#include <swevent.hxx>
55#include <unomailmerge.hxx>
56#include <unoprnms.hxx>
57#include <unomap.hxx>
58#include <swunohelper.hxx>
59#include <docsh.hxx>
61#include <view.hxx>
62#include <dbmgr.hxx>
63#include <unotxdoc.hxx>
64#include <wrtsh.hxx>
65#include <mmconfigitem.hxx>
66#include <mailmergehelper.hxx>
67
68#include <iodetect.hxx>
69
70#include <memory>
71
72using namespace ::com::sun::star;
73using namespace ::com::sun::star::frame;
74using namespace ::com::sun::star::uno;
75using namespace ::com::sun::star::lang;
76using namespace ::com::sun::star::beans;
77using namespace ::com::sun::star::text;
78using namespace SWUnoHelper;
79
80typedef ::utl::SharedUNOComponent< XInterface > SharedComponent;
81
82static osl::Mutex & GetMailMergeMutex()
83{
84 static osl::Mutex aMutex;
85 return aMutex;
86}
87
88namespace {
89
90enum CloseResult
91{
92 eSuccess, // successfully closed
93 eVetoed, // vetoed, ownership transferred to the vetoing instance
94 eFailed // failed for some unknown reason
95};
96
97}
98
99static CloseResult CloseModelAndDocSh(
100 Reference< frame::XModel > const &rxModel,
101 SfxObjectShellRef &rxDocSh )
102{
103 CloseResult eResult = eSuccess;
104
105 rxDocSh = nullptr;
106
110 Reference< util::XCloseable > xClose( rxModel, UNO_QUERY );
111 if (xClose.is())
112 {
113 try
114 {
117 xClose->close( true );
118 }
119 catch (const util::CloseVetoException&)
120 {
123 eResult = eVetoed;
124 }
125 catch (const uno::RuntimeException&)
126 {
127 eResult = eFailed;
128 }
129 }
130 return eResult;
131}
132
135 Reference< frame::XModel > &rxModel,
136 SfxObjectShellRef &rxDocSh,
137 const OUString &rURL,
138 bool bClose )
139{
140 // try to open the document readonly and hidden
141 Reference< frame::XModel > xTmpModel;
142 Sequence < PropertyValue > aArgs{ comphelper::makePropertyValue("Hidden", true) };
143 try
144 {
145 Reference < XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
146 xTmpModel.set( xDesktop->loadComponentFromURL( rURL, "_blank", 0, aArgs ), UNO_QUERY );
147 }
148 catch (const Exception&)
149 {
150 return false;
151 }
152
153 // try to get the DocShell
154 SwDocShell *pTmpDocShell = nullptr;
155 if (auto pTextDoc = comphelper::getFromUnoTunnel<SwXTextDocument>(xTmpModel); pTextDoc)
156 pTmpDocShell = pTextDoc->GetDocShell();
157
158 bool bRes = false;
159 if (xTmpModel.is() && pTmpDocShell) // everything available?
160 {
161 if (bClose)
162 CloseModelAndDocSh( rxModel, rxDocSh );
163 // set new stuff
164 rxModel = xTmpModel;
165 rxDocSh = pTmpDocShell;
166 bRes = true;
167 }
168 else
169 {
170 // SfxObjectShellRef is ok here, since the document will be explicitly closed
171 SfxObjectShellRef xTmpDocSh = pTmpDocShell;
172 CloseModelAndDocSh( xTmpModel, xTmpDocSh );
173 }
174
175 return bRes;
176}
177
178namespace
179{
180 class DelayedFileDeletion : public ::cppu::WeakImplHelper<util::XCloseListener>
181 {
182 protected:
183 ::osl::Mutex m_aMutex;
184 Reference< util::XCloseable > m_xDocument;
185 Timer m_aDeleteTimer;
186 OUString m_sTemporaryFile;
187 sal_Int32 m_nPendingDeleteAttempts;
188
189 DelayedFileDeletion(DelayedFileDeletion const&) = delete;
190 DelayedFileDeletion& operator=(DelayedFileDeletion const&) = delete;
191
192 public:
193 DelayedFileDeletion( const Reference< XModel >& _rxModel,
194 OUString _aTemporaryFile );
195
196 protected:
197 virtual ~DelayedFileDeletion( ) override;
198
199 // XCloseListener
200 virtual void SAL_CALL queryClosing( const EventObject& _rSource, sal_Bool _bGetsOwnership ) override;
201 virtual void SAL_CALL notifyClosing( const EventObject& _rSource ) override;
202
203 // XEventListener
204 virtual void SAL_CALL disposing( const EventObject& Source ) override;
205
206 private:
207 void implTakeOwnership( );
208 DECL_LINK( OnTryDeleteFile, Timer*, void );
209 };
210
211 DelayedFileDeletion::DelayedFileDeletion( const Reference< XModel >& _rxModel, OUString _aTemporaryFile )
212 :
213 m_xDocument( _rxModel, UNO_QUERY )
214 ,m_aDeleteTimer("sw DelayedFileDeletion m_aDeleteTimer")
215 ,m_sTemporaryFile(std::move( _aTemporaryFile ))
216 ,m_nPendingDeleteAttempts( 0 )
217 {
218 osl_atomic_increment( &m_refCount );
219 try
220 {
221 if ( m_xDocument.is() )
222 {
223 m_xDocument->addCloseListener( this );
224 // successfully added -> keep ourself alive
225 acquire();
226 }
227 else {
228 OSL_FAIL("DelayedFileDeletion::DelayedFileDeletion: model is no component!" );
229 }
230 }
231 catch (const Exception&)
232 {
233 OSL_FAIL("DelayedFileDeletion::DelayedFileDeletion: could not register as event listener at the model!" );
234 }
235 osl_atomic_decrement( &m_refCount );
236 }
237
238 IMPL_LINK_NOARG(DelayedFileDeletion, OnTryDeleteFile, Timer *, void)
239 {
240 ::osl::ClearableMutexGuard aGuard( m_aMutex );
241
242 bool bSuccess = false;
243 try
244 {
245 bool bDeliverOwnership = ( 0 == m_nPendingDeleteAttempts );
246 // if this is our last attempt, then anybody which vetoes this has to take the consequences
247 // (means take the ownership)
248 m_xDocument->close( bDeliverOwnership );
249 bSuccess = true;
250 }
251 catch (const util::CloseVetoException&)
252 {
253 // somebody vetoed -> next try
254 if ( m_nPendingDeleteAttempts )
255 {
256 // next attempt
257 --m_nPendingDeleteAttempts;
258 m_aDeleteTimer.Start();
259 }
260 else
261 bSuccess = true; // can't do anything here ...
262 }
263 catch (const Exception&)
264 {
265 TOOLS_WARN_EXCEPTION( "sw", "DelayedFileDeletion::OnTryDeleteFile: caught a strange exception!" );
266 bSuccess = true;
267 // can't do anything here ...
268 }
269
270 if ( bSuccess )
271 {
272 SWUnoHelper::UCB_DeleteFile( m_sTemporaryFile );
273 aGuard.clear();
274 release(); // this should be our last reference, we should be dead after this
275 }
276 }
277
278 void DelayedFileDeletion::implTakeOwnership( )
279 {
280 // revoke ourself as listener
281 try
282 {
283 m_xDocument->removeCloseListener( this );
284 }
285 catch (const Exception&)
286 {
287 OSL_FAIL("DelayedFileDeletion::implTakeOwnership: could not revoke the listener!" );
288 }
289
290 m_aDeleteTimer.SetTimeout( 3000 ); // 3 seconds
291 m_aDeleteTimer.SetInvokeHandler( LINK( this, DelayedFileDeletion, OnTryDeleteFile ) );
292 m_nPendingDeleteAttempts = 3; // try 3 times at most
293 m_aDeleteTimer.Start( );
294 }
295
296 void SAL_CALL DelayedFileDeletion::queryClosing( const EventObject& , sal_Bool _bGetsOwnership )
297 {
298 ::osl::MutexGuard aGuard( m_aMutex );
299 if ( _bGetsOwnership )
300 implTakeOwnership( );
301
302 // always veto: We want to take the ownership ourself, as this is the only chance to delete
303 // the temporary file which the model is based on
304 throw util::CloseVetoException( );
305 }
306
307 void SAL_CALL DelayedFileDeletion::notifyClosing( const EventObject& )
308 {
309 OSL_FAIL("DelayedFileDeletion::notifyClosing: how this?" );
310 // this should not happen:
311 // Either, a foreign instance closes the document, then we should veto this, and take the ownership
312 // Or, we ourself close the document, then we should not be a listener anymore
313 }
314
315 void SAL_CALL DelayedFileDeletion::disposing( const EventObject& )
316 {
317 OSL_FAIL("DelayedFileDeletion::disposing: how this?" );
318 // this should not happen:
319 // Either, a foreign instance closes the document, then we should veto this, and take the ownership
320 // Or, we ourself close the document, then we should not be a listener anymore
321 }
322
323 DelayedFileDeletion::~DelayedFileDeletion( )
324 {
325 }
326}
327
329 Reference< frame::XModel > &rxModel,
330 SfxObjectShellRef &rxDocSh,
331 const OUString &rTmpFileURL )
332{
333 bool bRes = false;
334 if (!rTmpFileURL.isEmpty())
335 {
336 bool bDelete = true;
337 if ( eVetoed == CloseModelAndDocSh( rxModel, rxDocSh ) )
338 {
339 // somebody vetoed the closing, and took the ownership of the document
340 // -> ensure that the temporary file is deleted later on
341 new DelayedFileDeletion( rxModel, rTmpFileURL );
342 // note: as soon as #106931# is fixed, the whole DelayedFileDeletion is to be superseded by
343 // a better solution
344 bDelete = false;
345 }
346
347 rxModel = nullptr;
348 rxDocSh = nullptr; // destroy doc shell
349
350 if ( bDelete )
351 {
352 if ( !SWUnoHelper::UCB_DeleteFile( rTmpFileURL ) )
353 {
354 new DelayedFileDeletion( rxModel, rTmpFileURL );
355 // same not as above: as soon as #106931#, ...
356 }
357 }
358 else
359 bRes = true; // file will be deleted delayed
360 }
361 return bRes;
362}
363
365 m_aEvtListeners ( GetMailMergeMutex() ),
366 m_aMergeListeners ( GetMailMergeMutex() ),
367 m_aPropListeners ( GetMailMergeMutex() ),
368 m_pPropSet( aSwMapProvider.GetPropertySet( PROPERTY_MAP_MAILMERGE ) ),
369 m_nDataCommandType(sdb::CommandType::TABLE),
370 m_nOutputType(MailMergeType::PRINTER),
371 m_bEscapeProcessing(true),
372 m_bSinglePrintJobs(false),
373 m_bFileNameFromColumn(false),
374 m_bSendAsHTML(false),
375 m_bSendAsAttachment(false),
376 m_bSaveAsSingleFile(false),
377 m_bDisposing(false),
378 m_pMgr(nullptr)
379{
380 // create empty document
381 // like in: SwModule::InsertEnv (appenv.cxx)
382 m_xDocSh = new SwDocShell( SfxObjectCreateMode::STANDARD );
383 m_xDocSh->DoInitNew();
385 SwView *pView = static_cast<SwView*>( pFrame->GetViewShell() );
386 pView->AttrChangedNotify(nullptr); //So that SelectShell is called.
387 m_xModel = m_xDocSh->GetModel();
388}
389
391{
392 if (!m_aTmpFileName.isEmpty())
394 else // there was no temporary file in use
395 {
399 if ( eVetoed == CloseModelAndDocSh( m_xModel, m_xDocSh ) )
400 OSL_FAIL("ownership transferred to vetoing object!" );
401
402 m_xModel = nullptr;
403 m_xDocSh = nullptr; // destroy doc shell
404 }
405}
406
407// Guarantee object consistence in case of an exception
409{
410public:
413 {
414 assert(m_pMailMerge); //mailmerge object missing
415 }
417 {
418 osl::MutexGuard aMgrGuard( GetMailMergeMutex() );
419 m_pMailMerge->m_pMgr = nullptr;
420 }
421
422private:
425
427};
428
430 const uno::Sequence< beans::NamedValue >& rArguments )
431{
432 SolarMutexGuard aGuard;
433 MailMergeExecuteFinalizer aFinalizer(this);
434
435 // get property values to be used
436 // (use values from the service as default and override them with
437 // the values that are provided as arguments)
438
439 uno::Sequence< uno::Any > aCurSelection = m_aSelection;
440 uno::Reference< sdbc::XResultSet > xCurResultSet = m_xResultSet;
441 uno::Reference< sdbc::XConnection > xCurConnection = m_xConnection;
442 uno::Reference< frame::XModel > xCurModel = m_xModel;
443 OUString aCurDataSourceName = m_aDataSourceName;
444 OUString aCurDataCommand = m_aDataCommand;
445 OUString aCurFilter = m_aFilter;
446 OUString aCurDocumentURL = m_aDocumentURL;
447 OUString aCurOutputURL = m_aOutputURL;
448 OUString aCurFileNamePrefix = m_aFileNamePrefix;
449 sal_Int32 nCurDataCommandType = m_nDataCommandType;
450 sal_Int16 nCurOutputType = m_nOutputType;
451 bool bCurEscapeProcessing = m_bEscapeProcessing;
452 bool bCurSinglePrintJobs = m_bSinglePrintJobs;
453 bool bCurFileNameFromColumn = m_bFileNameFromColumn;
454
455 SfxObjectShellRef xCurDocSh = m_xDocSh; // the document
456
457 for (const beans::NamedValue& rArgument : rArguments)
458 {
459 const OUString &rName = rArgument.Name;
460 const Any &rValue = rArgument.Value;
461
462 bool bOK = true;
463 if (rName == UNO_NAME_SELECTION)
464 bOK = rValue >>= aCurSelection;
465 else if (rName == UNO_NAME_RESULT_SET)
466 bOK = rValue >>= xCurResultSet;
467 else if (rName == UNO_NAME_CONNECTION)
468 bOK = rValue >>= xCurConnection;
469 else if (rName == UNO_NAME_MODEL)
470 throw PropertyVetoException("Property is read-only: " + rName, static_cast < cppu::OWeakObject * > ( this ) );
471 else if (rName == UNO_NAME_DATA_SOURCE_NAME)
472 bOK = rValue >>= aCurDataSourceName;
473 else if (rName == UNO_NAME_DAD_COMMAND)
474 bOK = rValue >>= aCurDataCommand;
475 else if (rName == UNO_NAME_FILTER)
476 bOK = rValue >>= aCurFilter;
477 else if (rName == UNO_NAME_DOCUMENT_URL)
478 {
479 bOK = rValue >>= aCurDocumentURL;
480 if (!aCurDocumentURL.isEmpty()
481 && !LoadFromURL_impl( xCurModel, xCurDocSh, aCurDocumentURL, false ))
482 throw RuntimeException("Failed to create document from URL: " + aCurDocumentURL, static_cast < cppu::OWeakObject * > ( this ) );
483 }
484 else if (rName == UNO_NAME_OUTPUT_URL)
485 {
486 bOK = rValue >>= aCurOutputURL;
487 if (!aCurOutputURL.isEmpty())
488 {
489 if (!UCB_IsDirectory(aCurOutputURL))
490 throw IllegalArgumentException("URL does not point to a directory: " + aCurOutputURL, static_cast < cppu::OWeakObject * > ( this ), 0 );
491 if (UCB_IsReadOnlyFileName(aCurOutputURL))
492 throw IllegalArgumentException("URL is read-only: " + aCurOutputURL, static_cast < cppu::OWeakObject * > ( this ), 0 );
493 }
494 }
495 else if (rName == UNO_NAME_FILE_NAME_PREFIX)
496 bOK = rValue >>= aCurFileNamePrefix;
497 else if (rName == UNO_NAME_DAD_COMMAND_TYPE)
498 bOK = rValue >>= nCurDataCommandType;
499 else if (rName == UNO_NAME_OUTPUT_TYPE)
500 bOK = rValue >>= nCurOutputType;
501 else if (rName == UNO_NAME_ESCAPE_PROCESSING)
502 bOK = rValue >>= bCurEscapeProcessing;
503 else if (rName == UNO_NAME_SINGLE_PRINT_JOBS)
504 bOK = rValue >>= bCurSinglePrintJobs;
505 else if (rName == UNO_NAME_FILE_NAME_FROM_COLUMN)
506 bOK = rValue >>= bCurFileNameFromColumn;
507 else if (rName == UNO_NAME_SUBJECT)
508 bOK = rValue >>= m_sSubject;
509 else if (rName == UNO_NAME_ADDRESS_FROM_COLUMN)
510 bOK = rValue >>= m_sAddressFromColumn;
511 else if (rName == UNO_NAME_SEND_AS_HTML)
512 bOK = rValue >>= m_bSendAsHTML;
513 else if (rName == UNO_NAME_MAIL_BODY)
514 bOK = rValue >>= m_sMailBody;
515 else if (rName == UNO_NAME_ATTACHMENT_NAME)
516 bOK = rValue >>= m_sAttachmentName;
517 else if (rName == UNO_NAME_ATTACHMENT_FILTER)
518 bOK = rValue >>= m_sAttachmentFilter;
519 else if (rName == UNO_NAME_COPIES_TO)
520 bOK = rValue >>= m_aCopiesTo;
521 else if (rName == UNO_NAME_BLIND_COPIES_TO)
522 bOK = rValue >>= m_aBlindCopiesTo;
523 else if (rName == UNO_NAME_SEND_AS_ATTACHMENT)
524 bOK = rValue >>= m_bSendAsAttachment;
525 else if (rName == UNO_NAME_PRINT_OPTIONS)
526 bOK = rValue >>= m_aPrintSettings;
527 else if (rName == UNO_NAME_SAVE_AS_SINGLE_FILE)
528 bOK = rValue >>= m_bSaveAsSingleFile;
529 else if (rName == UNO_NAME_SAVE_FILTER)
530 bOK = rValue >>= m_sSaveFilter;
531 else if (rName == UNO_NAME_SAVE_FILTER_OPTIONS)
532 bOK = rValue >>= m_sSaveFilterOptions;
533 else if (rName == UNO_NAME_SAVE_FILTER_DATA)
534 bOK = rValue >>= m_aSaveFilterData;
535 else if (rName == UNO_NAME_IN_SERVER_PASSWORD)
536 bOK = rValue >>= m_sInServerPassword;
537 else if (rName == UNO_NAME_OUT_SERVER_PASSWORD)
538 bOK = rValue >>= m_sOutServerPassword;
539 else
540 throw UnknownPropertyException( "Property is unknown: " + rName, static_cast < cppu::OWeakObject * > ( this ) );
541
542 if (!bOK)
543 throw IllegalArgumentException("Property type mismatch or property not set: " + rName, static_cast < cppu::OWeakObject * > ( this ), 0 );
544 }
545
546 // need to translate the selection: the API here requires a sequence of bookmarks, but the Merge
547 // method we will call below requires a sequence of indices.
548 if ( aCurSelection.hasElements() )
549 {
550 Sequence< Any > aTranslated( aCurSelection.getLength() );
551
552 bool bValid = false;
553 Reference< sdbcx::XRowLocate > xRowLocate( xCurResultSet, UNO_QUERY );
554 if ( xRowLocate.is() )
555 {
556 Any* pTranslated = aTranslated.getArray();
557
558 try
559 {
560 bool bEverythingsFine = true;
561 for ( const Any& rBookmark : std::as_const(aCurSelection) )
562 {
563 bEverythingsFine = xRowLocate->moveToBookmark( rBookmark );
564 if ( !bEverythingsFine )
565 break;
566 *pTranslated <<= xCurResultSet->getRow();
567 ++pTranslated;
568 }
569 if ( bEverythingsFine )
570 bValid = true;
571 }
572 catch (const Exception&)
573 {
574 bValid = false;
575 }
576 }
577
578 if ( !bValid )
579 {
580 throw IllegalArgumentException(
581 "The current 'Selection' does not describe a valid array of bookmarks, relative to the current 'ResultSet'.",
582 static_cast < cppu::OWeakObject * > ( this ),
583 0
584 );
585 }
586
587 aCurSelection = aTranslated;
588 }
589
590 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( xCurDocSh.get(), false);
591 SwView *pView = pFrame ? dynamic_cast<SwView*>( pFrame->GetViewShell() ) : nullptr;
592 if (!pView)
593 throw RuntimeException();
594 SwWrtShell &rSh = *pView->GetWrtShellPtr();
595
596 // avoid assertion in 'Update' from Sfx by supplying a shell
597 // and thus avoiding the SelectShell call in Writers GetState function
598 // while still in Update of Sfx.
599 // (GetSelection in Update is not allowed)
600 if (!aCurDocumentURL.isEmpty())
601 pView->AttrChangedNotify(nullptr);//So that SelectShell is called.
602
603 SharedComponent aRowSetDisposeHelper;
604 if (!xCurResultSet.is())
605 {
606 if (aCurDataSourceName.isEmpty() || aCurDataCommand.isEmpty() )
607 {
608 OSL_FAIL("PropertyValues missing or unset");
609 throw IllegalArgumentException("Either the ResultSet or DataSourceName and DataCommand must be set.", static_cast < cppu::OWeakObject * > ( this ), 0 );
610 }
611
612 // build ResultSet from DataSourceName, DataCommand and DataCommandType
613
614 Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
615 if (xMgr.is())
616 {
617 Reference< XInterface > xInstance = xMgr->createInstance( "com.sun.star.sdb.RowSet" );
618 aRowSetDisposeHelper.reset( xInstance, SharedComponent::TakeOwnership );
619 Reference< XPropertySet > xRowSetPropSet( xInstance, UNO_QUERY );
620 OSL_ENSURE( xRowSetPropSet.is(), "failed to get XPropertySet interface from RowSet" );
621 if (xRowSetPropSet.is())
622 {
623 if (xCurConnection.is())
624 xRowSetPropSet->setPropertyValue( "ActiveConnection", Any( xCurConnection ) );
625 xRowSetPropSet->setPropertyValue( "DataSourceName", Any( aCurDataSourceName ) );
626 xRowSetPropSet->setPropertyValue( "Command", Any( aCurDataCommand ) );
627 xRowSetPropSet->setPropertyValue( "CommandType", Any( nCurDataCommandType ) );
628 xRowSetPropSet->setPropertyValue( "EscapeProcessing", Any( bCurEscapeProcessing ) );
629 xRowSetPropSet->setPropertyValue( "ApplyFilter", Any( true ) );
630 xRowSetPropSet->setPropertyValue( "Filter", Any( aCurFilter ) );
631
632 Reference< sdbc::XRowSet > xRowSet( xInstance, UNO_QUERY );
633 if (xRowSet.is())
634 xRowSet->execute(); // build ResultSet from properties
635 if( !xCurConnection.is() )
636 xCurConnection.set( xRowSetPropSet->getPropertyValue( "ActiveConnection" ), UNO_QUERY );
637 xCurResultSet = xRowSet;
638 OSL_ENSURE( xCurResultSet.is(), "failed to build ResultSet" );
639 }
640 }
641 }
642
643 svx::ODataAccessDescriptor aDescriptor;
644 aDescriptor.setDataSource(aCurDataSourceName);
645 aDescriptor[ svx::DataAccessDescriptorProperty::Connection ] <<= xCurConnection;
646 aDescriptor[ svx::DataAccessDescriptorProperty::Command ] <<= aCurDataCommand;
647 aDescriptor[ svx::DataAccessDescriptorProperty::CommandType ] <<= nCurDataCommandType;
648 aDescriptor[ svx::DataAccessDescriptorProperty::EscapeProcessing ] <<= bCurEscapeProcessing;
649 aDescriptor[ svx::DataAccessDescriptorProperty::Cursor ] <<= xCurResultSet;
650 // aDescriptor[ svx::DataAccessDescriptorProperty::ColumnName ] not used
651 // aDescriptor[ svx::DataAccessDescriptorProperty::ColumnObject ] not used
652 aDescriptor[ svx::DataAccessDescriptorProperty::Selection ] <<= aCurSelection;
653
654 DBManagerOptions nMergeType;
655 switch (nCurOutputType)
656 {
657 case MailMergeType::PRINTER : nMergeType = DBMGR_MERGE_PRINTER; break;
658 case MailMergeType::FILE : nMergeType = DBMGR_MERGE_FILE; break;
659 case MailMergeType::MAIL : nMergeType = DBMGR_MERGE_EMAIL; break;
660 case MailMergeType::SHELL : nMergeType = DBMGR_MERGE_SHELL; break;
661 default:
662 throw IllegalArgumentException("Invalid value of property: OutputType", static_cast < cppu::OWeakObject * > ( this ), 0 );
663 }
664
665 SwDBManager* pMgr = rSh.GetDBManager();
666 //force layout creation
667 rSh.CalcLayout();
668 OSL_ENSURE( pMgr, "database manager missing" );
669 m_pMgr = pMgr;
670
671 SwMergeDescriptor aMergeDesc( nMergeType, rSh, aDescriptor );
672
673 std::unique_ptr< SwMailMergeConfigItem > pMMConfigItem;
674 uno::Reference< mail::XMailService > xInService;
675 switch (nCurOutputType)
676 {
677 case MailMergeType::PRINTER:
678 {
680 SwPrintData aPrtData( rIDDA.getPrintData() );
681 aPrtData.SetPrintSingleJobs( bCurSinglePrintJobs );
682 rIDDA.setPrintData( aPrtData );
683 // #i25686# printing should not be done asynchronously to prevent dangling offices
684 // when mail merge is called as command line macro
685 aMergeDesc.aPrintOptions = m_aPrintSettings;
686 aMergeDesc.bCreateSingleFile = true;
687 }
688 break;
689 case MailMergeType::SHELL:
690 aMergeDesc.bCreateSingleFile = true;
691 pMMConfigItem.reset(new SwMailMergeConfigItem);
692 aMergeDesc.pMailMergeConfigItem = pMMConfigItem.get();
693 break;
694 case MailMergeType::FILE:
695 {
696 INetURLObject aURLObj;
697 aURLObj.SetSmartProtocol( INetProtocol::File );
698
699 if (!aCurDocumentURL.isEmpty())
700 {
701 // if OutputURL or FileNamePrefix are missing get
702 // them from DocumentURL
703 aURLObj.SetSmartURL( aCurDocumentURL );
704 if (aCurFileNamePrefix.isEmpty())
705 aCurFileNamePrefix = aURLObj.GetBase(); // filename without extension
706 if (aCurOutputURL.isEmpty())
707 {
708 aURLObj.removeSegment();
709 aCurOutputURL = aURLObj.GetMainURL( INetURLObject::DecodeMechanism::ToIUri );
710 }
711 }
712 else // default empty document without URL
713 {
714 if (aCurOutputURL.isEmpty())
715 throw RuntimeException("OutputURL is not set and can not be obtained.", static_cast < cppu::OWeakObject * > ( this ) );
716 }
717
718 aURLObj.SetSmartURL( aCurOutputURL );
719 OUString aPath = aURLObj.GetMainURL( INetURLObject::DecodeMechanism::ToIUri );
720
721 static const OUStringLiteral aDelim( u"/" );
722 if (!aPath.isEmpty() && !aPath.endsWith(aDelim))
723 aPath += aDelim;
724 if (bCurFileNameFromColumn)
725 aMergeDesc.sDBcolumn = aCurFileNamePrefix;
726 else
727 {
728 aPath += aCurFileNamePrefix;
729 }
730
731 aMergeDesc.sPrefix = aPath;
732 aMergeDesc.sSaveToFilter = m_sSaveFilter;
736 }
737 break;
738 case MailMergeType::MAIL:
739 {
740 aMergeDesc.sDBcolumn = m_sAddressFromColumn;
741 if(m_sAddressFromColumn.isEmpty())
742 throw RuntimeException("Mail address column not set.", static_cast < cppu::OWeakObject * > ( this ) );
744 aMergeDesc.sSubject = m_sSubject;
745 aMergeDesc.sMailBody = m_sMailBody;
747 aMergeDesc.aCopiesTo = m_aCopiesTo;
748 aMergeDesc.aBlindCopiesTo = m_aBlindCopiesTo;
749 aMergeDesc.bSendAsHTML = m_bSendAsHTML;
751
752 aMergeDesc.bCreateSingleFile = false;
753 pMMConfigItem.reset(new SwMailMergeConfigItem);
754 aMergeDesc.pMailMergeConfigItem = pMMConfigItem.get();
756 *pMMConfigItem,
757 xInService,
759 if( !aMergeDesc.xSmtpServer.is() || !aMergeDesc.xSmtpServer->isConnected())
760 throw RuntimeException("Failed to connect to mail server.", static_cast < cppu::OWeakObject * > ( this ) );
761 }
762 break;
763 }
764
765 // save document with temporary filename
766 std::shared_ptr<const SfxFilter> pSfxFlt = SwIoSystem::GetFilterOfFormat(
768 SwDocShell::Factory().GetFilterContainer() );
769 OUString aExtension(comphelper::string::stripStart(pSfxFlt->GetDefaultExtension(), '*'));
770 m_aTmpFileName = utl::CreateTempURL( u"SwMM", true, aExtension );
771
772 Reference< XStorable > xStorable( xCurModel, UNO_QUERY );
773 bool bStoredAsTemporary = false;
774 if ( xStorable.is() )
775 {
776 try
777 {
778 xStorable->storeAsURL( m_aTmpFileName, Sequence< PropertyValue >() );
779 bStoredAsTemporary = true;
780 }
781 catch (const Exception&)
782 {
783 }
784 }
785 if ( !bStoredAsTemporary )
786 throw RuntimeException("Failed to save temporary file.", static_cast < cppu::OWeakObject * > ( this ) );
787
788 pMgr->SetMergeSilent( true ); // suppress dialogs, message boxes, etc.
789 const SwXMailMerge *pOldSrc = pMgr->GetMailMergeEvtSrc();
790 OSL_ENSURE( !pOldSrc || pOldSrc == this, "Ooops... different event source already set." );
791 pMgr->SetMailMergeEvtSrc( this ); // launch events for listeners
792
793 SfxGetpApp()->NotifyEvent(SfxEventHint(SfxEventHintId::SwMailMerge, SwDocShell::GetEventName(STR_SW_EVENT_MAIL_MERGE), xCurDocSh.get()));
794 bool bSucc = pMgr->Merge( aMergeDesc );
795 SfxGetpApp()->NotifyEvent(SfxEventHint(SfxEventHintId::SwMailMergeEnd, SwDocShell::GetEventName(STR_SW_EVENT_MAIL_MERGE_END), xCurDocSh.get()));
796
797 pMgr->SetMailMergeEvtSrc( pOldSrc );
798
799 if ( xCurModel.get() != m_xModel.get() )
800 { // in case it was a temporary model -> close it, and delete the file
801 DeleteTmpFile_Impl( xCurModel, xCurDocSh, m_aTmpFileName );
802 m_aTmpFileName.clear();
803 }
804 // (in case it wasn't a temporary model, it will be closed in the dtor, at the latest)
805
806 if (!bSucc)
807 throw Exception("Mail merge failed. Sorry, no further information available.", static_cast < cppu::OWeakObject * > ( this ) );
808
809 //de-initialize services
810 if(xInService.is() && xInService->isConnected())
811 xInService->disconnect();
812 if(aMergeDesc.xSmtpServer.is() && aMergeDesc.xSmtpServer->isConnected())
813 aMergeDesc.xSmtpServer->disconnect();
814
815 if (DBMGR_MERGE_SHELL == nMergeType)
816 {
817 return Any( aMergeDesc.pMailMergeConfigItem->GetTargetView()->GetDocShell()->GetBaseModel() );
818 }
819 else
820 return Any( true );
821}
822
823void SAL_CALL SwXMailMerge::cancel()
824{
825 // Cancel may be called from a second thread, so this protects from m_pMgr
827 osl::MutexGuard aMgrGuard( GetMailMergeMutex() );
828 if (m_pMgr)
830}
831
832void SwXMailMerge::LaunchMailMergeEvent( const MailMergeEvent &rEvt ) const
833{
835 while (aIt.hasMoreElements())
836 {
837 static_cast< XMailMergeListener* >( aIt.next() )->notifyMailMergeEvent( rEvt );
838 }
839}
840
841void SwXMailMerge::launchEvent( const PropertyChangeEvent &rEvt ) const
842{
844 m_aPropListeners.getContainer( rEvt.PropertyHandle );
845 if (pContainer)
846 {
847 pContainer->notifyEach( &XPropertyChangeListener::propertyChange, rEvt );
848 }
849}
850
851uno::Reference< beans::XPropertySetInfo > SAL_CALL SwXMailMerge::getPropertySetInfo( )
852{
853 SolarMutexGuard aGuard;
854 static Reference< XPropertySetInfo > aRef = m_pPropSet->getPropertySetInfo();
855 return aRef;
856}
857
859 const OUString& rPropertyName, const uno::Any& rValue )
860{
861 SolarMutexGuard aGuard;
862
863 const SfxItemPropertyMapEntry* pCur = m_pPropSet->getPropertyMap().getByName( rPropertyName );
864 if (!pCur)
865 throw UnknownPropertyException(rPropertyName);
866 else if (pCur->nFlags & PropertyAttribute::READONLY)
867 throw PropertyVetoException();
868 else
869 {
870 void *pData = nullptr;
871 switch (pCur->nWID)
872 {
873 case WID_SELECTION : pData = &m_aSelection; break;
874 case WID_RESULT_SET : pData = &m_xResultSet; break;
875 case WID_CONNECTION : pData = &m_xConnection; break;
876 case WID_MODEL : pData = &m_xModel; break;
878 case WID_DATA_COMMAND : pData = &m_aDataCommand; break;
879 case WID_FILTER : pData = &m_aFilter; break;
880 case WID_DOCUMENT_URL : pData = &m_aDocumentURL; break;
881 case WID_OUTPUT_URL : pData = &m_aOutputURL; break;
883 case WID_OUTPUT_TYPE : pData = &m_nOutputType; break;
888 case WID_MAIL_SUBJECT: pData = &m_sSubject; break;
890 case WID_SEND_AS_HTML: pData = &m_bSendAsHTML; break;
892 case WID_MAIL_BODY: pData = &m_sMailBody; break;
897 case WID_SAVE_FILTER: pData = &m_sSaveFilter; break;
900 case WID_COPIES_TO: pData = &m_aCopiesTo; break;
904 default :
905 OSL_FAIL("unknown WID");
906 }
907 Any aOld( pData, pCur->aType );
908
909 bool bChanged = false;
910 bool bOK = true;
911 if (aOld != rValue)
912 {
913 if (pData == &m_aSelection)
914 bOK = rValue >>= m_aSelection;
915 else if (pData == &m_xResultSet)
916 bOK = rValue >>= m_xResultSet;
917 else if (pData == &m_xConnection)
918 bOK = rValue >>= m_xConnection;
919 else if (pData == &m_xModel)
920 bOK = rValue >>= m_xModel;
921 else if (pData == &m_aDataSourceName)
922 bOK = rValue >>= m_aDataSourceName;
923 else if (pData == &m_aDataCommand)
924 bOK = rValue >>= m_aDataCommand;
925 else if (pData == &m_aFilter)
926 bOK = rValue >>= m_aFilter;
927 else if (pData == &m_aDocumentURL)
928 {
929 OUString aText;
930 bOK = rValue >>= aText;
931 if (!aText.isEmpty()
932 && !LoadFromURL_impl( m_xModel, m_xDocSh, aText, true ))
933 throw RuntimeException("Failed to create document from URL: " + aText, static_cast < cppu::OWeakObject * > ( this ) );
934 m_aDocumentURL = aText;
935 }
936 else if (pData == &m_aOutputURL)
937 {
938 OUString aText;
939 bOK = rValue >>= aText;
940 if (!aText.isEmpty())
941 {
942 if (!UCB_IsDirectory(aText))
943 throw IllegalArgumentException("URL does not point to a directory: " + aText, static_cast < cppu::OWeakObject * > ( this ), 0 );
944 if (UCB_IsReadOnlyFileName(aText))
945 throw IllegalArgumentException("URL is read-only: " + aText, static_cast < cppu::OWeakObject * > ( this ), 0 );
946 }
947 m_aOutputURL = aText;
948 }
949 else if (pData == &m_nDataCommandType)
950 bOK = rValue >>= m_nDataCommandType;
951 else if (pData == &m_nOutputType)
952 bOK = rValue >>= m_nOutputType;
953 else if (pData == &m_bEscapeProcessing)
954 bOK = rValue >>= m_bEscapeProcessing;
955 else if (pData == &m_bSinglePrintJobs)
956 bOK = rValue >>= m_bSinglePrintJobs;
957 else if (pData == &m_bFileNameFromColumn)
958 bOK = rValue >>= m_bFileNameFromColumn;
959 else if (pData == &m_aFileNamePrefix)
960 bOK = rValue >>= m_aFileNamePrefix;
961 else if (pData == &m_sSubject)
962 bOK = rValue >>= m_sSubject;
963 else if (pData == &m_sAddressFromColumn)
964 bOK = rValue >>= m_sAddressFromColumn;
965 else if (pData == &m_bSendAsHTML)
966 bOK = rValue >>= m_bSendAsHTML;
967 else if (pData == &m_bSendAsAttachment)
968 bOK = rValue >>= m_bSendAsAttachment;
969 else if (pData == &m_sMailBody)
970 bOK = rValue >>= m_sMailBody;
971 else if (pData == &m_sAttachmentName)
972 bOK = rValue >>= m_sAttachmentName;
973 else if (pData == &m_sAttachmentFilter)
974 bOK = rValue >>= m_sAttachmentFilter;
975 else if (pData == &m_aPrintSettings)
976 bOK = rValue >>= m_aPrintSettings;
977 else if (pData == &m_bSaveAsSingleFile)
978 bOK = rValue >>= m_bSaveAsSingleFile;
979 else if (pData == &m_sSaveFilter)
980 bOK = rValue >>= m_sSaveFilter;
981 else if (pData == &m_sSaveFilterOptions)
982 bOK = rValue >>= m_sSaveFilterOptions;
983 else if (pData == &m_aSaveFilterData)
984 bOK = rValue >>= m_aSaveFilterData;
985 else if (pData == &m_aCopiesTo)
986 bOK = rValue >>= m_aCopiesTo;
987 else if (pData == &m_aBlindCopiesTo)
988 bOK = rValue >>= m_aBlindCopiesTo;
989 else if(pData == &m_sInServerPassword)
990 bOK = rValue >>= m_sInServerPassword;
991 else if(pData == &m_sOutServerPassword)
992 bOK = rValue >>= m_sOutServerPassword;
993 else {
994 OSL_FAIL("invalid pointer" );
995 }
996 OSL_ENSURE( bOK, "set value failed" );
997 bChanged = true;
998 }
999 if (!bOK)
1000 throw IllegalArgumentException("Property type mismatch or property not set: " + rPropertyName, static_cast < cppu::OWeakObject * > ( this ), 0 );
1001
1002 if (bChanged)
1003 {
1004 PropertyChangeEvent aChgEvt( static_cast<XPropertySet *>(this), rPropertyName,
1005 false, pCur->nWID, aOld, rValue );
1006 launchEvent( aChgEvt );
1007 }
1008 }
1009}
1010
1012 const OUString& rPropertyName )
1013{
1014 SolarMutexGuard aGuard;
1015
1016 Any aRet;
1017
1018 const SfxItemPropertyMapEntry* pCur = m_pPropSet->getPropertyMap().getByName( rPropertyName );
1019 if (!pCur)
1020 throw UnknownPropertyException(rPropertyName);
1021
1022 switch (pCur->nWID)
1023 {
1024 case WID_SELECTION : aRet <<= m_aSelection; break;
1025 case WID_RESULT_SET : aRet <<= m_xResultSet; break;
1026 case WID_CONNECTION : aRet <<= m_xConnection; break;
1027 case WID_MODEL : aRet <<= m_xModel; break;
1028 case WID_DATA_SOURCE_NAME : aRet <<= m_aDataSourceName; break;
1029 case WID_DATA_COMMAND : aRet <<= m_aDataCommand; break;
1030 case WID_FILTER : aRet <<= m_aFilter; break;
1031 case WID_DOCUMENT_URL : aRet <<= m_aDocumentURL; break;
1032 case WID_OUTPUT_URL : aRet <<= m_aOutputURL; break;
1033 case WID_DATA_COMMAND_TYPE : aRet <<= m_nDataCommandType; break;
1034 case WID_OUTPUT_TYPE : aRet <<= m_nOutputType; break;
1035 case WID_ESCAPE_PROCESSING : aRet <<= m_bEscapeProcessing; break;
1036 case WID_SINGLE_PRINT_JOBS : aRet <<= m_bSinglePrintJobs; break;
1037 case WID_FILE_NAME_FROM_COLUMN : aRet <<= m_bFileNameFromColumn; break;
1038 case WID_FILE_NAME_PREFIX : aRet <<= m_aFileNamePrefix; break;
1039 case WID_MAIL_SUBJECT: aRet <<= m_sSubject; break;
1040 case WID_ADDRESS_FROM_COLUMN: aRet <<= m_sAddressFromColumn; break;
1041 case WID_SEND_AS_HTML: aRet <<= m_bSendAsHTML; break;
1042 case WID_SEND_AS_ATTACHMENT: aRet <<= m_bSendAsAttachment; break;
1043 case WID_MAIL_BODY: aRet <<= m_sMailBody; break;
1044 case WID_ATTACHMENT_NAME: aRet <<= m_sAttachmentName; break;
1045 case WID_ATTACHMENT_FILTER: aRet <<= m_sAttachmentFilter;break;
1046 case WID_PRINT_OPTIONS: aRet <<= m_aPrintSettings; break;
1047 case WID_SAVE_AS_SINGLE_FILE: aRet <<= m_bSaveAsSingleFile; break;
1048 case WID_SAVE_FILTER: aRet <<= m_sSaveFilter; break;
1049 case WID_SAVE_FILTER_OPTIONS: aRet <<= m_sSaveFilterOptions; break;
1050 case WID_SAVE_FILTER_DATA: aRet <<= m_aSaveFilterData; break;
1051 case WID_COPIES_TO: aRet <<= m_aCopiesTo; break;
1052 case WID_BLIND_COPIES_TO: aRet <<= m_aBlindCopiesTo;break;
1053 case WID_IN_SERVER_PASSWORD: aRet <<= m_sInServerPassword; break;
1054 case WID_OUT_SERVER_PASSWORD: aRet <<= m_sOutServerPassword; break;
1055 default :
1056 OSL_FAIL("unknown WID");
1057 }
1058
1059 return aRet;
1060}
1061
1063 const OUString& rPropertyName,
1064 const uno::Reference< beans::XPropertyChangeListener >& rListener )
1065{
1066 SolarMutexGuard aGuard;
1067 if (!m_bDisposing && rListener.is())
1068 {
1069 const SfxItemPropertyMapEntry* pCur = m_pPropSet->getPropertyMap().getByName( rPropertyName );
1070 if (!pCur)
1071 throw UnknownPropertyException(rPropertyName);
1072 m_aPropListeners.addInterface( pCur->nWID, rListener );
1073 }
1074}
1075
1077 const OUString& rPropertyName,
1078 const uno::Reference< beans::XPropertyChangeListener >& rListener )
1079{
1080 SolarMutexGuard aGuard;
1081 if (!m_bDisposing && rListener.is())
1082 {
1083 const SfxItemPropertyMapEntry* pCur = m_pPropSet->getPropertyMap().getByName( rPropertyName );
1084 if (!pCur)
1085 throw UnknownPropertyException(rPropertyName);
1086 m_aPropListeners.removeInterface( pCur->nWID, rListener );
1087 }
1088}
1089
1091 const OUString& /*rPropertyName*/,
1092 const uno::Reference< beans::XVetoableChangeListener >& /*rListener*/ )
1093{
1094 // no vetoable property, thus no support for vetoable change listeners
1095 OSL_FAIL("not implemented");
1096}
1097
1099 const OUString& /*rPropertyName*/,
1100 const uno::Reference< beans::XVetoableChangeListener >& /*rListener*/ )
1101{
1102 // no vetoable property, thus no support for vetoable change listeners
1103 OSL_FAIL("not implemented");
1104}
1105
1107{
1108 SolarMutexGuard aGuard;
1109
1110 if (!m_bDisposing)
1111 {
1112 m_bDisposing = true;
1113
1114 EventObject aEvtObj( static_cast<XPropertySet *>(this) );
1118 }
1119}
1120
1122 const Reference< XEventListener >& rxListener )
1123{
1124 SolarMutexGuard aGuard;
1125 if (!m_bDisposing && rxListener.is())
1126 m_aEvtListeners.addInterface( rxListener );
1127}
1128
1130 const Reference< XEventListener >& rxListener )
1131{
1132 SolarMutexGuard aGuard;
1133 if (!m_bDisposing && rxListener.is())
1134 m_aEvtListeners.removeInterface( rxListener );
1135}
1136
1138 const uno::Reference< XMailMergeListener >& rxListener )
1139{
1140 SolarMutexGuard aGuard;
1141 if (!m_bDisposing && rxListener.is())
1142 m_aMergeListeners.addInterface( rxListener );
1143}
1144
1146 const uno::Reference< XMailMergeListener >& rxListener )
1147{
1148 SolarMutexGuard aGuard;
1149 if (!m_bDisposing && rxListener.is())
1150 m_aMergeListeners.removeInterface( rxListener );
1151}
1152
1154{
1155 return "SwXMailMerge";
1156}
1157
1158sal_Bool SAL_CALL SwXMailMerge::supportsService( const OUString& rServiceName )
1159{
1160 return cppu::supportsService(this, rServiceName);
1161}
1162
1163uno::Sequence< OUString > SAL_CALL SwXMailMerge::getSupportedServiceNames()
1164{
1165 return { "com.sun.star.text.MailMerge", "com.sun.star.sdb.DataAccessDescriptor" };
1166}
1167
1168/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SfxApplication * SfxGetpApp()
Provides access to the formatting devices of a document.
virtual void setPrintData(const SwPrintData &rPrtData)=0
Sets the PrintData.
virtual const SwPrintData & getPrintData() const =0
Returns the PrintData.
void SetSmartProtocol(INetProtocol eTheSmartScheme)
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
bool removeSegment(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true)
bool SetSmartURL(std::u16string_view rTheAbsURIRef, EncodeMechanism eMechanism=EncodeMechanism::WasEncoded, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
OUString GetBase() const
MailMergeExecuteFinalizer(MailMergeExecuteFinalizer const &)=delete
MailMergeExecuteFinalizer(SwXMailMerge *mailmerge)
MailMergeExecuteFinalizer & operator=(MailMergeExecuteFinalizer const &)=delete
void NotifyEvent(const SfxEventHint &rEvent, bool bSynchron=true)
const SfxItemPropertyMapEntry * getByName(std::u16string_view rName) const
const SfxItemPropertyMap & getPropertyMap() const
css::uno::Reference< css::beans::XPropertySetInfo > const & getPropertySetInfo() const
css::uno::Reference< css::frame::XModel3 > GetBaseModel() const
SfxViewShell * GetViewShell() const
static SfxViewFrame * GetFirst(const SfxObjectShell *pDoc=nullptr, bool bOnlyVisible=true)
static SfxViewFrame * LoadHiddenDocument(SfxObjectShell const &i_rDoc, SfxInterfaceId i_nViewId)
bool Merge(const SwMergeDescriptor &rMergeDesc)
Merging of data records into fields.
Definition: dbmgr.cxx:431
void MergeCancel()
Definition: dbmgr.cxx:1663
void SetMergeSilent(bool bVal)
Definition: dbmgr.hxx:303
const SwXMailMerge * GetMailMergeEvtSrc() const
MailMergeEvent source.
Definition: dbmgr.hxx:299
void SetMailMergeEvtSrc(const SwXMailMerge *pSrc)
Definition: dbmgr.hxx:300
static OUString GetEventName(sal_Int32 nId)
Definition: docsh.cxx:1329
virtual void CalcLayout() override
To enable set up of StartActions and EndActions.
Definition: edws.cxx:108
SwDBManager * GetDBManager() const
For evaluation of DB fields (new DB-manager).
Definition: edfld.cxx:328
static SW_DLLPUBLIC std::shared_ptr< const SfxFilter > GetFilterOfFormat(std::u16string_view rFormat, const SfxFilterContainer *pCnt=nullptr)
find for an internal format name the corresponding filter entry
Definition: iodetect.cxx:68
void SetPrintSingleJobs(bool b)
Definition: printdata.hxx:164
const IDocumentDeviceAccess & getIDocumentDeviceAccess() const
Provides access to the document device interface.
Definition: viewsh.cxx:2805
Definition: view.hxx:146
SwWrtShell * GetWrtShellPtr() const
Definition: view.hxx:417
SwDocShell * GetDocShell()
Definition: view.cxx:1160
Used by the UI to modify the document model.
Definition: wrtsh.hxx:97
Gives UNO access to the global mail merge functionality, via the com.sun.star.text....
css::uno::Reference< css::frame::XModel > m_xModel
void LaunchMailMergeEvent(const css::text::MailMergeEvent &rData) const
OUString m_aOutputURL
SfxObjectShellRef m_xDocSh
OUString m_aFileNamePrefix
OUString m_sAttachmentName
OUString m_sAttachmentFilter
virtual void SAL_CALL addMailMergeEventListener(const css::uno::Reference< css::text::XMailMergeListener > &xListener) override
sal_Int32 m_nDataCommandType
bool m_bSinglePrintJobs
virtual css::uno::Sequence< OUString > SAL_CALL getSupportedServiceNames() override
OUString m_aDataSourceName
bool m_bSendAsAttachment
virtual void SAL_CALL removeMailMergeEventListener(const css::uno::Reference< css::text::XMailMergeListener > &xListener) override
virtual void SAL_CALL setPropertyValue(const OUString &aPropertyName, const css::uno::Any &aValue) override
virtual void SAL_CALL addPropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &xListener) override
css::uno::Sequence< OUString > m_aBlindCopiesTo
virtual void SAL_CALL dispose() override
css::uno::Sequence< css::beans::PropertyValue > m_aPrintSettings
css::uno::Sequence< css::uno::Any > m_aSelection
virtual ~SwXMailMerge() override
SwDBManager * m_pMgr
bool m_bSaveAsSingleFile
css::uno::Reference< css::sdbc::XResultSet > m_xResultSet
OUString m_aDataCommand
void launchEvent(const css::beans::PropertyChangeEvent &rEvt) const
OUString m_sSubject
css::uno::Reference< css::sdbc::XConnection > m_xConnection
bool m_bFileNameFromColumn
virtual void SAL_CALL removeEventListener(const css::uno::Reference< css::lang::XEventListener > &aListener) override
OUString m_aFilter
css::uno::Sequence< css::beans::PropertyValue > m_aSaveFilterData
virtual css::uno::Any SAL_CALL getPropertyValue(const OUString &PropertyName) override
virtual sal_Bool SAL_CALL supportsService(const OUString &ServiceName) override
OUString m_sOutServerPassword
comphelper::OInterfaceContainerHelper2 m_aMergeListeners
virtual OUString SAL_CALL getImplementationName() override
OPropertyListenerContainerHelper m_aPropListeners
OUString m_aTmpFileName
css::uno::Sequence< OUString > m_aCopiesTo
virtual void SAL_CALL addVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
virtual void SAL_CALL addEventListener(const css::uno::Reference< css::lang::XEventListener > &xListener) override
bool m_bEscapeProcessing
virtual void SAL_CALL cancel() override
OUString m_sSaveFilterOptions
comphelper::OInterfaceContainerHelper3< css::lang::XEventListener > m_aEvtListeners
sal_Int16 m_nOutputType
const SfxItemPropertySet * m_pPropSet
OUString m_sAddressFromColumn
virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo() override
OUString m_sMailBody
virtual css::uno::Any SAL_CALL execute(const css::uno::Sequence< css::beans::NamedValue > &Arguments) override
OUString m_aDocumentURL
OUString m_sSaveFilter
virtual void SAL_CALL removePropertyChangeListener(const OUString &aPropertyName, const css::uno::Reference< css::beans::XPropertyChangeListener > &aListener) override
OUString m_sInServerPassword
virtual void SAL_CALL removeVetoableChangeListener(const OUString &PropertyName, const css::uno::Reference< css::beans::XVetoableChangeListener > &aListener) override
void disposeAndClear(const css::lang::EventObject &rEvt)
sal_Int32 removeInterface(const css::uno::Reference< css::uno::XInterface > &rxIFace)
sal_Int32 addInterface(const css::uno::Reference< css::uno::XInterface > &rxIFace)
sal_Int32 addInterface(const css::uno::Reference< ListenerT > &rxIFace)
void disposeAndClear(const css::lang::EventObject &rEvt)
sal_Int32 removeInterface(const css::uno::Reference< ListenerT > &rxIFace)
void notifyEach(void(SAL_CALL ListenerT::*NotificationMethod)(const EventT &), const EventT &Event)
css::uno::XInterface * next()
sal_Int32 addInterface(const key &rKey, const css::uno::Reference< listener > &rListener)
sal_Int32 removeInterface(const key &rKey, const css::uno::Reference< listener > &rListener)
void disposeAndClear(const css::lang::EventObject &rEvt)
OInterfaceContainerHelper3< listener > * getContainer(const key &rKey) const
void setDataSource(const OUString &_sDataSourceNameOrLocation)
T * get() const
void reset(const css::uno::Reference< INTERFACE > &_rxComponent, AssignmentMode _eMode=TakeOwnership)
IMPL_LINK_NOARG(SwContentControlButton, PopupModeEndHdl, weld::Popover &, void)
DBManagerOptions
Definition: dbmgr.hxx:88
@ DBMGR_MERGE_EMAIL
Send mail merge as email.
Definition: dbmgr.hxx:91
@ DBMGR_MERGE_SHELL
Create merge doc and keep the doc shell.
Definition: dbmgr.hxx:93
@ DBMGR_MERGE_PRINTER
Print mail merge.
Definition: dbmgr.hxx:90
@ DBMGR_MERGE_FILE
Save mail merge as files.
Definition: dbmgr.hxx:92
Reference< XOfficeDatabaseDocument > m_xDocument
#define TOOLS_WARN_EXCEPTION(area, stream)
DECL_LINK(CheckNameHdl, SvxNameDialog &, bool)
float u
Mutex aMutex
eSuccess
OUString sAttachmentName
Definition: dbmgr.hxx:191
css::uno::Sequence< OUString > aBlindCopiesTo
Definition: dbmgr.hxx:193
bool bSendAsAttachment
Definition: dbmgr.hxx:196
OUString sSubject
Definition: dbmgr.hxx:189
css::uno::Sequence< OUString > aCopiesTo
Definition: dbmgr.hxx:192
css::uno::Reference< css::mail::XSmtpService > xSmtpServer
Definition: dbmgr.hxx:194
OUString sMailBody
Definition: dbmgr.hxx:190
OUString sPrefix
Basename incl.
Definition: dbmgr.hxx:174
OUString sDBcolumn
DB column to fetch EMail of Filename from.
Definition: dbmgr.hxx:205
css::uno::Sequence< css::beans::PropertyValue > aPrintOptions
Definition: dbmgr.hxx:217
OUString sSaveToFilter
Definition: dbmgr.hxx:157
css::uno::Sequence< css::beans::PropertyValue > aSaveToFilterData
Definition: dbmgr.hxx:159
OUString sSaveToFilterOptions
Definition: dbmgr.hxx:158
std::mutex m_aMutex
constexpr OUStringLiteral FILTER_XML
XML filter.
Definition: iodetect.hxx:38
std::unique_ptr< sal_Int32[]> pData
bool UCB_DeleteFile(const OUString &rURL)
Definition: swunohelper.cxx:59
bool UCB_IsDirectory(const OUString &rURL)
bool UCB_IsReadOnlyFileName(const OUString &rURL)
uno::Reference< mail::XSmtpService > ConnectToSmtpServer(SwMailMergeConfigItem const &rConfigItem, uno::Reference< mail::XMailService > &rxInMailService, const OUString &rInMailServerPassword, const OUString &rOutMailServerPassword, weld::Window *pDialogParentWindow)
@ Exception
class SAL_NO_VTABLE XPropertySet
OString stripStart(const OString &rIn, char c)
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
bool CPPUHELPER_DLLPUBLIC supportsService(css::lang::XServiceInfo *implementation, rtl::OUString const &name)
OUString CreateTempURL(const OUString *pParent, bool bDirectory)
constexpr auto SFX_INTERFACE_NONE
css::uno::Type aType
SwMailMergeConfigItem * pMailMergeConfigItem
Definition: dbmgr.hxx:220
bool bCreateSingleFile
Create a single or multiple results.
Definition: dbmgr.hxx:151
#define STR_SW_EVENT_MAIL_MERGE
Definition: swevent.hxx:28
#define STR_SW_EVENT_MAIL_MERGE_END
Definition: swevent.hxx:29
unsigned char sal_Bool
static osl::Mutex & GetMailMergeMutex()
static bool DeleteTmpFile_Impl(Reference< frame::XModel > &rxModel, SfxObjectShellRef &rxDocSh, const OUString &rTmpFileURL)
::utl::SharedUNOComponent< XInterface > SharedComponent
static bool LoadFromURL_impl(Reference< frame::XModel > &rxModel, SfxObjectShellRef &rxDocSh, const OUString &rURL, bool bClose)
static CloseResult CloseModelAndDocSh(Reference< frame::XModel > const &rxModel, SfxObjectShellRef &rxDocSh)
SwUnoPropertyMapProvider aSwMapProvider
Definition: unomap1.cxx:87
#define WID_MAIL_BODY
Definition: unomap.hxx:275
#define WID_FILE_NAME_FROM_COLUMN
Definition: unomap.hxx:269
#define WID_SEND_AS_ATTACHMENT
Definition: unomap.hxx:274
#define WID_MODEL
Definition: unomap.hxx:259
#define PROPERTY_MAP_MAILMERGE
Definition: unomap.hxx:115
#define WID_SAVE_AS_SINGLE_FILE
Definition: unomap.hxx:279
#define WID_SAVE_FILTER
Definition: unomap.hxx:280
#define WID_DOCUMENT_URL
Definition: unomap.hxx:263
#define WID_IN_SERVER_PASSWORD
Definition: unomap.hxx:283
#define WID_DATA_COMMAND_TYPE
Definition: unomap.hxx:265
#define WID_SINGLE_PRINT_JOBS
Definition: unomap.hxx:268
#define WID_ADDRESS_FROM_COLUMN
Definition: unomap.hxx:272
#define WID_SAVE_FILTER_DATA
Definition: unomap.hxx:286
#define WID_COPIES_TO
Definition: unomap.hxx:281
#define WID_CONNECTION
Definition: unomap.hxx:258
#define WID_ATTACHMENT_NAME
Definition: unomap.hxx:276
#define WID_FILE_NAME_PREFIX
Definition: unomap.hxx:270
#define WID_SAVE_FILTER_OPTIONS
Definition: unomap.hxx:285
#define WID_FILTER
Definition: unomap.hxx:262
#define WID_OUTPUT_TYPE
Definition: unomap.hxx:266
#define WID_SELECTION
Definition: unomap.hxx:256
#define WID_PRINT_OPTIONS
Definition: unomap.hxx:278
#define WID_DATA_COMMAND
Definition: unomap.hxx:261
#define WID_ESCAPE_PROCESSING
Definition: unomap.hxx:267
#define WID_OUTPUT_URL
Definition: unomap.hxx:264
#define WID_RESULT_SET
Definition: unomap.hxx:257
#define WID_SEND_AS_HTML
Definition: unomap.hxx:273
#define WID_OUT_SERVER_PASSWORD
Definition: unomap.hxx:284
#define WID_ATTACHMENT_FILTER
Definition: unomap.hxx:277
#define WID_MAIL_SUBJECT
Definition: unomap.hxx:271
#define WID_DATA_SOURCE_NAME
Definition: unomap.hxx:260
#define WID_BLIND_COPIES_TO
Definition: unomap.hxx:282
#define UNO_NAME_DAD_COMMAND
Definition: unoprnms.hxx:733
#define UNO_NAME_MODEL
Definition: unoprnms.hxx:722
#define UNO_NAME_DATA_SOURCE_NAME
Definition: unoprnms.hxx:723
#define UNO_NAME_FILE_NAME_PREFIX
Definition: unoprnms.hxx:731
#define UNO_NAME_SAVE_FILTER_OPTIONS
Definition: unoprnms.hxx:772
#define UNO_NAME_OUT_SERVER_PASSWORD
Definition: unoprnms.hxx:771
#define UNO_NAME_CONNECTION
Definition: unoprnms.hxx:721
#define UNO_NAME_FILTER
Definition: unoprnms.hxx:724
#define UNO_NAME_MAIL_BODY
Definition: unoprnms.hxx:762
#define UNO_NAME_SELECTION
Definition: unoprnms.hxx:719
#define UNO_NAME_SEND_AS_HTML
Definition: unoprnms.hxx:760
#define UNO_NAME_SUBJECT
Definition: unoprnms.hxx:758
#define UNO_NAME_IN_SERVER_PASSWORD
Definition: unoprnms.hxx:770
#define UNO_NAME_RESULT_SET
Definition: unoprnms.hxx:720
#define UNO_NAME_SAVE_AS_SINGLE_FILE
Definition: unoprnms.hxx:766
#define UNO_NAME_COPIES_TO
Definition: unoprnms.hxx:768
#define UNO_NAME_DAD_COMMAND_TYPE
Definition: unoprnms.hxx:735
#define UNO_NAME_BLIND_COPIES_TO
Definition: unoprnms.hxx:769
#define UNO_NAME_DOCUMENT_URL
Definition: unoprnms.hxx:725
#define UNO_NAME_ADDRESS_FROM_COLUMN
Definition: unoprnms.hxx:759
#define UNO_NAME_OUTPUT_URL
Definition: unoprnms.hxx:726
#define UNO_NAME_ATTACHMENT_NAME
Definition: unoprnms.hxx:763
#define UNO_NAME_PRINT_OPTIONS
Definition: unoprnms.hxx:765
#define UNO_NAME_OUTPUT_TYPE
Definition: unoprnms.hxx:727
#define UNO_NAME_SAVE_FILTER_DATA
Definition: unoprnms.hxx:773
#define UNO_NAME_SAVE_FILTER
Definition: unoprnms.hxx:767
#define UNO_NAME_ATTACHMENT_FILTER
Definition: unoprnms.hxx:764
#define UNO_NAME_SEND_AS_ATTACHMENT
Definition: unoprnms.hxx:761
#define UNO_NAME_FILE_NAME_FROM_COLUMN
Definition: unoprnms.hxx:730
#define UNO_NAME_SINGLE_PRINT_JOBS
Definition: unoprnms.hxx:729
#define UNO_NAME_ESCAPE_PROCESSING
Definition: unoprnms.hxx:728
TABLE