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 <vcl/svapp.hxx>
22#include <osl/mutex.hxx>
23#include <svl/itemprop.hxx>
25#include <unotools/tempfile.hxx>
26#include <sfx2/app.hxx>
27#include <sfx2/docfilt.hxx>
28#include <tools/urlobj.hxx>
29#include <tools/diagnose_ex.h>
32#include <comphelper/string.hxx>
34#include <vcl/timer.hxx>
35#include <com/sun/star/sdb/CommandType.hpp>
36#include <com/sun/star/text/MailMergeType.hpp>
37#include <com/sun/star/text/MailMergeEvent.hpp>
38#include <com/sun/star/text/XMailMergeListener.hpp>
39#include <com/sun/star/beans/PropertyAttribute.hpp>
40#include <com/sun/star/sdbc/XResultSet.hpp>
41#include <com/sun/star/sdbc/XConnection.hpp>
42#include <com/sun/star/sdbc/XRowSet.hpp>
43#include <com/sun/star/frame/Desktop.hpp>
44#include <com/sun/star/util/XCloseable.hpp>
45#include <com/sun/star/util/CloseVetoException.hpp>
46#include <com/sun/star/sdbcx/XRowLocate.hpp>
47#include <com/sun/star/frame/XStorable.hpp>
48#include <com/sun/star/mail/XSmtpService.hpp>
49#include <sfx2/viewfrm.hxx>
50#include <sfx2/event.hxx>
52#include <printdata.hxx>
53#include <swevent.hxx>
54#include <unomailmerge.hxx>
55#include <unoprnms.hxx>
56#include <unomap.hxx>
57#include <swunohelper.hxx>
58#include <docsh.hxx>
60#include <view.hxx>
61#include <dbmgr.hxx>
62#include <unotxdoc.hxx>
63#include <wrtsh.hxx>
64#include <mmconfigitem.hxx>
65#include <mailmergehelper.hxx>
66
67#include <iodetect.hxx>
68
69#include <memory>
70
71using namespace ::com::sun::star;
72using namespace ::com::sun::star::frame;
73using namespace ::com::sun::star::uno;
74using namespace ::com::sun::star::lang;
75using namespace ::com::sun::star::beans;
76using namespace ::com::sun::star::text;
77using namespace SWUnoHelper;
78
79typedef ::utl::SharedUNOComponent< XInterface > SharedComponent;
80
81static osl::Mutex & GetMailMergeMutex()
82{
83 static osl::Mutex aMutex;
84 return aMutex;
85}
86
87namespace {
88
89enum CloseResult
90{
91 eSuccess, // successfully closed
92 eVetoed, // vetoed, ownership transferred to the vetoing instance
93 eFailed // failed for some unknown reason
94};
95
96}
97
98static CloseResult CloseModelAndDocSh(
99 Reference< frame::XModel > const &rxModel,
100 SfxObjectShellRef &rxDocSh )
101{
102 CloseResult eResult = eSuccess;
103
104 rxDocSh = nullptr;
105
109 Reference< util::XCloseable > xClose( rxModel, UNO_QUERY );
110 if (xClose.is())
111 {
112 try
113 {
116 xClose->close( true );
117 }
118 catch (const util::CloseVetoException&)
119 {
122 eResult = eVetoed;
123 }
124 catch (const uno::RuntimeException&)
125 {
126 eResult = eFailed;
127 }
128 }
129 return eResult;
130}
131
134 Reference< frame::XModel > &rxModel,
135 SfxObjectShellRef &rxDocSh,
136 const OUString &rURL,
137 bool bClose )
138{
139 // try to open the document readonly and hidden
140 Reference< frame::XModel > xTmpModel;
141 Sequence < PropertyValue > aArgs{ comphelper::makePropertyValue("Hidden", true) };
142 try
143 {
144 Reference < XDesktop2 > xDesktop = Desktop::create( ::comphelper::getProcessComponentContext() );
145 xTmpModel.set( xDesktop->loadComponentFromURL( rURL, "_blank", 0, aArgs ), UNO_QUERY );
146 }
147 catch (const Exception&)
148 {
149 return false;
150 }
151
152 // try to get the DocShell
153 SwDocShell *pTmpDocShell = nullptr;
154 if (auto pTextDoc = comphelper::getFromUnoTunnel<SwXTextDocument>(xTmpModel); pTextDoc)
155 pTmpDocShell = pTextDoc->GetDocShell();
156
157 bool bRes = false;
158 if (xTmpModel.is() && pTmpDocShell) // everything available?
159 {
160 if (bClose)
161 CloseModelAndDocSh( rxModel, rxDocSh );
162 // set new stuff
163 rxModel = xTmpModel;
164 rxDocSh = pTmpDocShell;
165 bRes = true;
166 }
167 else
168 {
169 // SfxObjectShellRef is ok here, since the document will be explicitly closed
170 SfxObjectShellRef xTmpDocSh = pTmpDocShell;
171 CloseModelAndDocSh( xTmpModel, xTmpDocSh );
172 }
173
174 return bRes;
175}
176
177namespace
178{
179 class DelayedFileDeletion : public ::cppu::WeakImplHelper<util::XCloseListener>
180 {
181 protected:
182 ::osl::Mutex m_aMutex;
183 Reference< util::XCloseable > m_xDocument;
184 Timer m_aDeleteTimer;
185 OUString m_sTemporaryFile;
186 sal_Int32 m_nPendingDeleteAttempts;
187
188 DelayedFileDeletion(DelayedFileDeletion const&) = delete;
189 DelayedFileDeletion& operator=(DelayedFileDeletion const&) = delete;
190
191 public:
192 DelayedFileDeletion( const Reference< XModel >& _rxModel,
193 const OUString& _rTemporaryFile );
194
195 protected:
196 virtual ~DelayedFileDeletion( ) override;
197
198 // XCloseListener
199 virtual void SAL_CALL queryClosing( const EventObject& _rSource, sal_Bool _bGetsOwnership ) override;
200 virtual void SAL_CALL notifyClosing( const EventObject& _rSource ) override;
201
202 // XEventListener
203 virtual void SAL_CALL disposing( const EventObject& Source ) override;
204
205 private:
206 void implTakeOwnership( );
207 DECL_LINK( OnTryDeleteFile, Timer*, void );
208 };
209
210 DelayedFileDeletion::DelayedFileDeletion( const Reference< XModel >& _rxModel, const OUString& _rTemporaryFile )
211 :
212 m_xDocument( _rxModel, UNO_QUERY )
213 ,m_aDeleteTimer("sw DelayedFileDeletion m_aDeleteTimer")
214 ,m_sTemporaryFile( _rTemporaryFile )
215 ,m_nPendingDeleteAttempts( 0 )
216 {
217 osl_atomic_increment( &m_refCount );
218 try
219 {
220 if ( m_xDocument.is() )
221 {
222 m_xDocument->addCloseListener( this );
223 // successfully added -> keep ourself alive
224 acquire();
225 }
226 else {
227 OSL_FAIL("DelayedFileDeletion::DelayedFileDeletion: model is no component!" );
228 }
229 }
230 catch (const Exception&)
231 {
232 OSL_FAIL("DelayedFileDeletion::DelayedFileDeletion: could not register as event listener at the model!" );
233 }
234 osl_atomic_decrement( &m_refCount );
235 }
236
237 IMPL_LINK_NOARG(DelayedFileDeletion, OnTryDeleteFile, Timer *, void)
238 {
239 ::osl::ClearableMutexGuard aGuard( m_aMutex );
240
241 bool bSuccess = false;
242 try
243 {
244 bool bDeliverOwnership = ( 0 == m_nPendingDeleteAttempts );
245 // if this is our last attempt, then anybody which vetoes this has to take the consequences
246 // (means take the ownership)
247 m_xDocument->close( bDeliverOwnership );
248 bSuccess = true;
249 }
250 catch (const util::CloseVetoException&)
251 {
252 // somebody vetoed -> next try
253 if ( m_nPendingDeleteAttempts )
254 {
255 // next attempt
256 --m_nPendingDeleteAttempts;
257 m_aDeleteTimer.Start();
258 }
259 else
260 bSuccess = true; // can't do anything here ...
261 }
262 catch (const Exception&)
263 {
264 TOOLS_WARN_EXCEPTION( "sw", "DelayedFileDeletion::OnTryDeleteFile: caught a strange exception!" );
265 bSuccess = true;
266 // can't do anything here ...
267 }
268
269 if ( bSuccess )
270 {
271 SWUnoHelper::UCB_DeleteFile( m_sTemporaryFile );
272 aGuard.clear();
273 release(); // this should be our last reference, we should be dead after this
274 }
275 }
276
277 void DelayedFileDeletion::implTakeOwnership( )
278 {
279 // revoke ourself as listener
280 try
281 {
282 m_xDocument->removeCloseListener( this );
283 }
284 catch (const Exception&)
285 {
286 OSL_FAIL("DelayedFileDeletion::implTakeOwnership: could not revoke the listener!" );
287 }
288
289 m_aDeleteTimer.SetTimeout( 3000 ); // 3 seconds
290 m_aDeleteTimer.SetInvokeHandler( LINK( this, DelayedFileDeletion, OnTryDeleteFile ) );
291 m_nPendingDeleteAttempts = 3; // try 3 times at most
292 m_aDeleteTimer.Start( );
293 }
294
295 void SAL_CALL DelayedFileDeletion::queryClosing( const EventObject& , sal_Bool _bGetsOwnership )
296 {
297 ::osl::MutexGuard aGuard( m_aMutex );
298 if ( _bGetsOwnership )
299 implTakeOwnership( );
300
301 // always veto: We want to take the ownership ourself, as this is the only chance to delete
302 // the temporary file which the model is based on
303 throw util::CloseVetoException( );
304 }
305
306 void SAL_CALL DelayedFileDeletion::notifyClosing( const EventObject& )
307 {
308 OSL_FAIL("DelayedFileDeletion::notifyClosing: how this?" );
309 // this should not happen:
310 // Either, a foreign instance closes the document, then we should veto this, and take the ownership
311 // Or, we ourself close the document, then we should not be a listener anymore
312 }
313
314 void SAL_CALL DelayedFileDeletion::disposing( const EventObject& )
315 {
316 OSL_FAIL("DelayedFileDeletion::disposing: how this?" );
317 // this should not happen:
318 // Either, a foreign instance closes the document, then we should veto this, and take the ownership
319 // Or, we ourself close the document, then we should not be a listener anymore
320 }
321
322 DelayedFileDeletion::~DelayedFileDeletion( )
323 {
324 }
325}
326
328 Reference< frame::XModel > &rxModel,
329 SfxObjectShellRef &rxDocSh,
330 const OUString &rTmpFileURL )
331{
332 bool bRes = false;
333 if (!rTmpFileURL.isEmpty())
334 {
335 bool bDelete = true;
336 if ( eVetoed == CloseModelAndDocSh( rxModel, rxDocSh ) )
337 {
338 // somebody vetoed the closing, and took the ownership of the document
339 // -> ensure that the temporary file is deleted later on
340 new DelayedFileDeletion( rxModel, rTmpFileURL );
341 // note: as soon as #106931# is fixed, the whole DelayedFileDeletion is to be superseded by
342 // a better solution
343 bDelete = false;
344 }
345
346 rxModel = nullptr;
347 rxDocSh = nullptr; // destroy doc shell
348
349 if ( bDelete )
350 {
351 if ( !SWUnoHelper::UCB_DeleteFile( rTmpFileURL ) )
352 {
353 new DelayedFileDeletion( rxModel, rTmpFileURL );
354 // same not as above: as soon as #106931#, ...
355 }
356 }
357 else
358 bRes = true; // file will be deleted delayed
359 }
360 return bRes;
361}
362
364 m_aEvtListeners ( GetMailMergeMutex() ),
365 m_aMergeListeners ( GetMailMergeMutex() ),
366 m_aPropListeners ( GetMailMergeMutex() ),
367 m_pPropSet( aSwMapProvider.GetPropertySet( PROPERTY_MAP_MAILMERGE ) ),
368 m_nDataCommandType(sdb::CommandType::TABLE),
369 m_nOutputType(MailMergeType::PRINTER),
370 m_bEscapeProcessing(true),
371 m_bSinglePrintJobs(false),
372 m_bFileNameFromColumn(false),
373 m_bSendAsHTML(false),
374 m_bSendAsAttachment(false),
375 m_bSaveAsSingleFile(false),
376 m_bDisposing(false),
377 m_pMgr(nullptr)
378{
379 // create empty document
380 // like in: SwModule::InsertEnv (appenv.cxx)
381 m_xDocSh = new SwDocShell( SfxObjectCreateMode::STANDARD );
382 m_xDocSh->DoInitNew();
384 SwView *pView = static_cast<SwView*>( pFrame->GetViewShell() );
385 pView->AttrChangedNotify(nullptr); //So that SelectShell is called.
386 m_xModel = m_xDocSh->GetModel();
387}
388
390{
391 if (!m_aTmpFileName.isEmpty())
393 else // there was no temporary file in use
394 {
398 if ( eVetoed == CloseModelAndDocSh( m_xModel, m_xDocSh ) )
399 OSL_FAIL("ownership transferred to vetoing object!" );
400
401 m_xModel = nullptr;
402 m_xDocSh = nullptr; // destroy doc shell
403 }
404}
405
406// Guarantee object consistence in case of an exception
408{
409public:
412 {
413 assert(m_pMailMerge); //mailmerge object missing
414 }
416 {
417 osl::MutexGuard aMgrGuard( GetMailMergeMutex() );
418 m_pMailMerge->m_pMgr = nullptr;
419 }
420
421private:
424
426};
427
429 const uno::Sequence< beans::NamedValue >& rArguments )
430{
431 SolarMutexGuard aGuard;
432 MailMergeExecuteFinalizer aFinalizer(this);
433
434 // get property values to be used
435 // (use values from the service as default and override them with
436 // the values that are provided as arguments)
437
438 uno::Sequence< uno::Any > aCurSelection = m_aSelection;
439 uno::Reference< sdbc::XResultSet > xCurResultSet = m_xResultSet;
440 uno::Reference< sdbc::XConnection > xCurConnection = m_xConnection;
441 uno::Reference< frame::XModel > xCurModel = m_xModel;
442 OUString aCurDataSourceName = m_aDataSourceName;
443 OUString aCurDataCommand = m_aDataCommand;
444 OUString aCurFilter = m_aFilter;
445 OUString aCurDocumentURL = m_aDocumentURL;
446 OUString aCurOutputURL = m_aOutputURL;
447 OUString aCurFileNamePrefix = m_aFileNamePrefix;
448 sal_Int32 nCurDataCommandType = m_nDataCommandType;
449 sal_Int16 nCurOutputType = m_nOutputType;
450 bool bCurEscapeProcessing = m_bEscapeProcessing;
451 bool bCurSinglePrintJobs = m_bSinglePrintJobs;
452 bool bCurFileNameFromColumn = m_bFileNameFromColumn;
453
454 SfxObjectShellRef xCurDocSh = m_xDocSh; // the document
455
456 for (const beans::NamedValue& rArgument : rArguments)
457 {
458 const OUString &rName = rArgument.Name;
459 const Any &rValue = rArgument.Value;
460
461 bool bOK = true;
462 if (rName == UNO_NAME_SELECTION)
463 bOK = rValue >>= aCurSelection;
464 else if (rName == UNO_NAME_RESULT_SET)
465 bOK = rValue >>= xCurResultSet;
466 else if (rName == UNO_NAME_CONNECTION)
467 bOK = rValue >>= xCurConnection;
468 else if (rName == UNO_NAME_MODEL)
469 throw PropertyVetoException("Property is read-only: " + rName, static_cast < cppu::OWeakObject * > ( this ) );
470 else if (rName == UNO_NAME_DATA_SOURCE_NAME)
471 bOK = rValue >>= aCurDataSourceName;
472 else if (rName == UNO_NAME_DAD_COMMAND)
473 bOK = rValue >>= aCurDataCommand;
474 else if (rName == UNO_NAME_FILTER)
475 bOK = rValue >>= aCurFilter;
476 else if (rName == UNO_NAME_DOCUMENT_URL)
477 {
478 bOK = rValue >>= aCurDocumentURL;
479 if (!aCurDocumentURL.isEmpty()
480 && !LoadFromURL_impl( xCurModel, xCurDocSh, aCurDocumentURL, false ))
481 throw RuntimeException("Failed to create document from URL: " + aCurDocumentURL, static_cast < cppu::OWeakObject * > ( this ) );
482 }
483 else if (rName == UNO_NAME_OUTPUT_URL)
484 {
485 bOK = rValue >>= aCurOutputURL;
486 if (!aCurOutputURL.isEmpty())
487 {
488 if (!UCB_IsDirectory(aCurOutputURL))
489 throw IllegalArgumentException("URL does not point to a directory: " + aCurOutputURL, static_cast < cppu::OWeakObject * > ( this ), 0 );
490 if (UCB_IsReadOnlyFileName(aCurOutputURL))
491 throw IllegalArgumentException("URL is read-only: " + aCurOutputURL, static_cast < cppu::OWeakObject * > ( this ), 0 );
492 }
493 }
494 else if (rName == UNO_NAME_FILE_NAME_PREFIX)
495 bOK = rValue >>= aCurFileNamePrefix;
496 else if (rName == UNO_NAME_DAD_COMMAND_TYPE)
497 bOK = rValue >>= nCurDataCommandType;
498 else if (rName == UNO_NAME_OUTPUT_TYPE)
499 bOK = rValue >>= nCurOutputType;
500 else if (rName == UNO_NAME_ESCAPE_PROCESSING)
501 bOK = rValue >>= bCurEscapeProcessing;
502 else if (rName == UNO_NAME_SINGLE_PRINT_JOBS)
503 bOK = rValue >>= bCurSinglePrintJobs;
504 else if (rName == UNO_NAME_FILE_NAME_FROM_COLUMN)
505 bOK = rValue >>= bCurFileNameFromColumn;
506 else if (rName == UNO_NAME_SUBJECT)
507 bOK = rValue >>= m_sSubject;
508 else if (rName == UNO_NAME_ADDRESS_FROM_COLUMN)
509 bOK = rValue >>= m_sAddressFromColumn;
510 else if (rName == UNO_NAME_SEND_AS_HTML)
511 bOK = rValue >>= m_bSendAsHTML;
512 else if (rName == UNO_NAME_MAIL_BODY)
513 bOK = rValue >>= m_sMailBody;
514 else if (rName == UNO_NAME_ATTACHMENT_NAME)
515 bOK = rValue >>= m_sAttachmentName;
516 else if (rName == UNO_NAME_ATTACHMENT_FILTER)
517 bOK = rValue >>= m_sAttachmentFilter;
518 else if (rName == UNO_NAME_COPIES_TO)
519 bOK = rValue >>= m_aCopiesTo;
520 else if (rName == UNO_NAME_BLIND_COPIES_TO)
521 bOK = rValue >>= m_aBlindCopiesTo;
522 else if (rName == UNO_NAME_SEND_AS_ATTACHMENT)
523 bOK = rValue >>= m_bSendAsAttachment;
524 else if (rName == UNO_NAME_PRINT_OPTIONS)
525 bOK = rValue >>= m_aPrintSettings;
526 else if (rName == UNO_NAME_SAVE_AS_SINGLE_FILE)
527 bOK = rValue >>= m_bSaveAsSingleFile;
528 else if (rName == UNO_NAME_SAVE_FILTER)
529 bOK = rValue >>= m_sSaveFilter;
530 else if (rName == UNO_NAME_SAVE_FILTER_OPTIONS)
531 bOK = rValue >>= m_sSaveFilterOptions;
532 else if (rName == UNO_NAME_SAVE_FILTER_DATA)
533 bOK = rValue >>= m_aSaveFilterData;
534 else if (rName == UNO_NAME_IN_SERVER_PASSWORD)
535 bOK = rValue >>= m_sInServerPassword;
536 else if (rName == UNO_NAME_OUT_SERVER_PASSWORD)
537 bOK = rValue >>= m_sOutServerPassword;
538 else
539 throw UnknownPropertyException( "Property is unknown: " + rName, static_cast < cppu::OWeakObject * > ( this ) );
540
541 if (!bOK)
542 throw IllegalArgumentException("Property type mismatch or property not set: " + rName, static_cast < cppu::OWeakObject * > ( this ), 0 );
543 }
544
545 // need to translate the selection: the API here requires a sequence of bookmarks, but the Merge
546 // method we will call below requires a sequence of indices.
547 if ( aCurSelection.hasElements() )
548 {
549 Sequence< Any > aTranslated( aCurSelection.getLength() );
550
551 bool bValid = false;
552 Reference< sdbcx::XRowLocate > xRowLocate( xCurResultSet, UNO_QUERY );
553 if ( xRowLocate.is() )
554 {
555 Any* pTranslated = aTranslated.getArray();
556
557 try
558 {
559 bool bEverythingsFine = true;
560 for ( const Any& rBookmark : std::as_const(aCurSelection) )
561 {
562 bEverythingsFine = xRowLocate->moveToBookmark( rBookmark );
563 if ( !bEverythingsFine )
564 break;
565 *pTranslated <<= xCurResultSet->getRow();
566 ++pTranslated;
567 }
568 if ( bEverythingsFine )
569 bValid = true;
570 }
571 catch (const Exception&)
572 {
573 bValid = false;
574 }
575 }
576
577 if ( !bValid )
578 {
579 throw IllegalArgumentException(
580 "The current 'Selection' does not describe a valid array of bookmarks, relative to the current 'ResultSet'.",
581 static_cast < cppu::OWeakObject * > ( this ),
582 0
583 );
584 }
585
586 aCurSelection = aTranslated;
587 }
588
589 SfxViewFrame* pFrame = SfxViewFrame::GetFirst( xCurDocSh.get(), false);
590 SwView *pView = pFrame ? dynamic_cast<SwView*>( pFrame->GetViewShell() ) : nullptr;
591 if (!pView)
592 throw RuntimeException();
593 SwWrtShell &rSh = *pView->GetWrtShellPtr();
594
595 // avoid assertion in 'Update' from Sfx by supplying a shell
596 // and thus avoiding the SelectShell call in Writers GetState function
597 // while still in Update of Sfx.
598 // (GetSelection in Update is not allowed)
599 if (!aCurDocumentURL.isEmpty())
600 pView->AttrChangedNotify(nullptr);//So that SelectShell is called.
601
602 SharedComponent aRowSetDisposeHelper;
603 if (!xCurResultSet.is())
604 {
605 if (aCurDataSourceName.isEmpty() || aCurDataCommand.isEmpty() )
606 {
607 OSL_FAIL("PropertyValues missing or unset");
608 throw IllegalArgumentException("Either the ResultSet or DataSourceName and DataCommand must be set.", static_cast < cppu::OWeakObject * > ( this ), 0 );
609 }
610
611 // build ResultSet from DataSourceName, DataCommand and DataCommandType
612
613 Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
614 if (xMgr.is())
615 {
616 Reference< XInterface > xInstance = xMgr->createInstance( "com.sun.star.sdb.RowSet" );
617 aRowSetDisposeHelper.reset( xInstance, SharedComponent::TakeOwnership );
618 Reference< XPropertySet > xRowSetPropSet( xInstance, UNO_QUERY );
619 OSL_ENSURE( xRowSetPropSet.is(), "failed to get XPropertySet interface from RowSet" );
620 if (xRowSetPropSet.is())
621 {
622 if (xCurConnection.is())
623 xRowSetPropSet->setPropertyValue( "ActiveConnection", Any( xCurConnection ) );
624 xRowSetPropSet->setPropertyValue( "DataSourceName", Any( aCurDataSourceName ) );
625 xRowSetPropSet->setPropertyValue( "Command", Any( aCurDataCommand ) );
626 xRowSetPropSet->setPropertyValue( "CommandType", Any( nCurDataCommandType ) );
627 xRowSetPropSet->setPropertyValue( "EscapeProcessing", Any( bCurEscapeProcessing ) );
628 xRowSetPropSet->setPropertyValue( "ApplyFilter", Any( true ) );
629 xRowSetPropSet->setPropertyValue( "Filter", Any( aCurFilter ) );
630
631 Reference< sdbc::XRowSet > xRowSet( xInstance, UNO_QUERY );
632 if (xRowSet.is())
633 xRowSet->execute(); // build ResultSet from properties
634 if( !xCurConnection.is() )
635 xCurConnection.set( xRowSetPropSet->getPropertyValue( "ActiveConnection" ), UNO_QUERY );
636 xCurResultSet = xRowSet;
637 OSL_ENSURE( xCurResultSet.is(), "failed to build ResultSet" );
638 }
639 }
640 }
641
642 svx::ODataAccessDescriptor aDescriptor;
643 aDescriptor.setDataSource(aCurDataSourceName);
644 aDescriptor[ svx::DataAccessDescriptorProperty::Connection ] <<= xCurConnection;
645 aDescriptor[ svx::DataAccessDescriptorProperty::Command ] <<= aCurDataCommand;
646 aDescriptor[ svx::DataAccessDescriptorProperty::CommandType ] <<= nCurDataCommandType;
647 aDescriptor[ svx::DataAccessDescriptorProperty::EscapeProcessing ] <<= bCurEscapeProcessing;
648 aDescriptor[ svx::DataAccessDescriptorProperty::Cursor ] <<= xCurResultSet;
649 // aDescriptor[ svx::DataAccessDescriptorProperty::ColumnName ] not used
650 // aDescriptor[ svx::DataAccessDescriptorProperty::ColumnObject ] not used
651 aDescriptor[ svx::DataAccessDescriptorProperty::Selection ] <<= aCurSelection;
652
653 DBManagerOptions nMergeType;
654 switch (nCurOutputType)
655 {
656 case MailMergeType::PRINTER : nMergeType = DBMGR_MERGE_PRINTER; break;
657 case MailMergeType::FILE : nMergeType = DBMGR_MERGE_FILE; break;
658 case MailMergeType::MAIL : nMergeType = DBMGR_MERGE_EMAIL; break;
659 case MailMergeType::SHELL : nMergeType = DBMGR_MERGE_SHELL; break;
660 default:
661 throw IllegalArgumentException("Invalid value of property: OutputType", static_cast < cppu::OWeakObject * > ( this ), 0 );
662 }
663
664 SwDBManager* pMgr = rSh.GetDBManager();
665 //force layout creation
666 rSh.CalcLayout();
667 OSL_ENSURE( pMgr, "database manager missing" );
668 m_pMgr = pMgr;
669
670 SwMergeDescriptor aMergeDesc( nMergeType, rSh, aDescriptor );
671
672 std::unique_ptr< SwMailMergeConfigItem > pMMConfigItem;
673 uno::Reference< mail::XMailService > xInService;
674 switch (nCurOutputType)
675 {
676 case MailMergeType::PRINTER:
677 {
679 SwPrintData aPrtData( rIDDA.getPrintData() );
680 aPrtData.SetPrintSingleJobs( bCurSinglePrintJobs );
681 rIDDA.setPrintData( aPrtData );
682 // #i25686# printing should not be done asynchronously to prevent dangling offices
683 // when mail merge is called as command line macro
684 aMergeDesc.aPrintOptions = m_aPrintSettings;
685 aMergeDesc.bCreateSingleFile = true;
686 }
687 break;
688 case MailMergeType::SHELL:
689 aMergeDesc.bCreateSingleFile = true;
690 pMMConfigItem.reset(new SwMailMergeConfigItem);
691 aMergeDesc.pMailMergeConfigItem = pMMConfigItem.get();
692 break;
693 case MailMergeType::FILE:
694 {
695 INetURLObject aURLObj;
696 aURLObj.SetSmartProtocol( INetProtocol::File );
697
698 if (!aCurDocumentURL.isEmpty())
699 {
700 // if OutputURL or FileNamePrefix are missing get
701 // them from DocumentURL
702 aURLObj.SetSmartURL( aCurDocumentURL );
703 if (aCurFileNamePrefix.isEmpty())
704 aCurFileNamePrefix = aURLObj.GetBase(); // filename without extension
705 if (aCurOutputURL.isEmpty())
706 {
707 aURLObj.removeSegment();
708 aCurOutputURL = aURLObj.GetMainURL( INetURLObject::DecodeMechanism::ToIUri );
709 }
710 }
711 else // default empty document without URL
712 {
713 if (aCurOutputURL.isEmpty())
714 throw RuntimeException("OutputURL is not set and can not be obtained.", static_cast < cppu::OWeakObject * > ( this ) );
715 }
716
717 aURLObj.SetSmartURL( aCurOutputURL );
718 OUString aPath = aURLObj.GetMainURL( INetURLObject::DecodeMechanism::ToIUri );
719
720 static const OUStringLiteral aDelim( u"/" );
721 if (!aPath.isEmpty() && !aPath.endsWith(aDelim))
722 aPath += aDelim;
723 if (bCurFileNameFromColumn)
724 aMergeDesc.sDBcolumn = aCurFileNamePrefix;
725 else
726 {
727 aPath += aCurFileNamePrefix;
728 }
729
730 aMergeDesc.sPrefix = aPath;
731 aMergeDesc.sSaveToFilter = m_sSaveFilter;
735 }
736 break;
737 case MailMergeType::MAIL:
738 {
739 aMergeDesc.sDBcolumn = m_sAddressFromColumn;
740 if(m_sAddressFromColumn.isEmpty())
741 throw RuntimeException("Mail address column not set.", static_cast < cppu::OWeakObject * > ( this ) );
743 aMergeDesc.sSubject = m_sSubject;
744 aMergeDesc.sMailBody = m_sMailBody;
746 aMergeDesc.aCopiesTo = m_aCopiesTo;
747 aMergeDesc.aBlindCopiesTo = m_aBlindCopiesTo;
748 aMergeDesc.bSendAsHTML = m_bSendAsHTML;
750
751 aMergeDesc.bCreateSingleFile = false;
752 pMMConfigItem.reset(new SwMailMergeConfigItem);
753 aMergeDesc.pMailMergeConfigItem = pMMConfigItem.get();
755 *pMMConfigItem,
756 xInService,
758 if( !aMergeDesc.xSmtpServer.is() || !aMergeDesc.xSmtpServer->isConnected())
759 throw RuntimeException("Failed to connect to mail server.", static_cast < cppu::OWeakObject * > ( this ) );
760 }
761 break;
762 }
763
764 // save document with temporary filename
765 std::shared_ptr<const SfxFilter> pSfxFlt = SwIoSystem::GetFilterOfFormat(
767 SwDocShell::Factory().GetFilterContainer() );
768 OUString aExtension(comphelper::string::stripStart(pSfxFlt->GetDefaultExtension(), '*'));
769 utl::TempFile aTempFile( u"SwMM", true, &aExtension );
770 m_aTmpFileName = aTempFile.GetURL();
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:417
void MergeCancel()
Definition: dbmgr.cxx:1639
void SetMergeSilent(bool bVal)
Definition: dbmgr.hxx:302
const SwXMailMerge * GetMailMergeEvtSrc() const
MailMergeEvent source.
Definition: dbmgr.hxx:298
void SetMailMergeEvtSrc(const SwXMailMerge *pSrc)
Definition: dbmgr.hxx:299
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:2779
Definition: view.hxx:145
SwWrtShell * GetWrtShellPtr() const
Definition: view.hxx:414
SwDocShell * GetDocShell()
Definition: view.cxx:1133
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)
OUString const & GetURL() const
IMPL_LINK_NOARG(SwContentControlButton, PopupModeEndHdl, weld::Popover &, void)
DBManagerOptions
Definition: dbmgr.hxx:87
@ DBMGR_MERGE_EMAIL
Send mail merge as email.
Definition: dbmgr.hxx:90
@ DBMGR_MERGE_SHELL
Create merge doc and keep the doc shell.
Definition: dbmgr.hxx:92
@ DBMGR_MERGE_PRINTER
Print mail merge.
Definition: dbmgr.hxx:89
@ DBMGR_MERGE_FILE
Save mail merge as files.
Definition: dbmgr.hxx:91
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:190
css::uno::Sequence< OUString > aBlindCopiesTo
Definition: dbmgr.hxx:192
bool bSendAsAttachment
Definition: dbmgr.hxx:195
OUString sSubject
Definition: dbmgr.hxx:188
css::uno::Sequence< OUString > aCopiesTo
Definition: dbmgr.hxx:191
css::uno::Reference< css::mail::XSmtpService > xSmtpServer
Definition: dbmgr.hxx:193
OUString sMailBody
Definition: dbmgr.hxx:189
OUString sPrefix
Basename incl.
Definition: dbmgr.hxx:173
OUString sDBcolumn
DB column to fetch EMail of Filename from.
Definition: dbmgr.hxx:204
css::uno::Sequence< css::beans::PropertyValue > aPrintOptions
Definition: dbmgr.hxx:216
OUString sSaveToFilter
Definition: dbmgr.hxx:156
css::uno::Sequence< css::beans::PropertyValue > aSaveToFilterData
Definition: dbmgr.hxx:158
OUString sSaveToFilterOptions
Definition: dbmgr.hxx:157
std::mutex m_aMutex
constexpr OUStringLiteral FILTER_XML
XML filter.
Definition: iodetect.hxx:37
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)
constexpr auto SFX_INTERFACE_NONE
css::uno::Type aType
SwMailMergeConfigItem * pMailMergeConfigItem
Definition: dbmgr.hxx:219
bool bCreateSingleFile
Create a single or multiple results.
Definition: dbmgr.hxx:150
#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:274
#define WID_FILE_NAME_FROM_COLUMN
Definition: unomap.hxx:268
#define WID_SEND_AS_ATTACHMENT
Definition: unomap.hxx:273
#define WID_MODEL
Definition: unomap.hxx:258
#define PROPERTY_MAP_MAILMERGE
Definition: unomap.hxx:114
#define WID_SAVE_AS_SINGLE_FILE
Definition: unomap.hxx:278
#define WID_SAVE_FILTER
Definition: unomap.hxx:279
#define WID_DOCUMENT_URL
Definition: unomap.hxx:262
#define WID_IN_SERVER_PASSWORD
Definition: unomap.hxx:282
#define WID_DATA_COMMAND_TYPE
Definition: unomap.hxx:264
#define WID_SINGLE_PRINT_JOBS
Definition: unomap.hxx:267
#define WID_ADDRESS_FROM_COLUMN
Definition: unomap.hxx:271
#define WID_SAVE_FILTER_DATA
Definition: unomap.hxx:285
#define WID_COPIES_TO
Definition: unomap.hxx:280
#define WID_CONNECTION
Definition: unomap.hxx:257
#define WID_ATTACHMENT_NAME
Definition: unomap.hxx:275
#define WID_FILE_NAME_PREFIX
Definition: unomap.hxx:269
#define WID_SAVE_FILTER_OPTIONS
Definition: unomap.hxx:284
#define WID_FILTER
Definition: unomap.hxx:261
#define WID_OUTPUT_TYPE
Definition: unomap.hxx:265
#define WID_SELECTION
Definition: unomap.hxx:255
#define WID_PRINT_OPTIONS
Definition: unomap.hxx:277
#define WID_DATA_COMMAND
Definition: unomap.hxx:260
#define WID_ESCAPE_PROCESSING
Definition: unomap.hxx:266
#define WID_OUTPUT_URL
Definition: unomap.hxx:263
#define WID_RESULT_SET
Definition: unomap.hxx:256
#define WID_SEND_AS_HTML
Definition: unomap.hxx:272
#define WID_OUT_SERVER_PASSWORD
Definition: unomap.hxx:283
#define WID_ATTACHMENT_FILTER
Definition: unomap.hxx:276
#define WID_MAIL_SUBJECT
Definition: unomap.hxx:270
#define WID_DATA_SOURCE_NAME
Definition: unomap.hxx:259
#define WID_BLIND_COPIES_TO
Definition: unomap.hxx:281
#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