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