LibreOffice Module sw (master)  1
mmresultdialogs.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 <mmresultdialogs.hxx>
21 #include <mailmergewizard.hxx>
22 #include <mmconfigitem.hxx>
23 #include <mailconfigpage.hxx>
24 #include "mmgreetingspage.hxx"
25 #include <swmessdialog.hxx>
26 #include <cmdid.h>
27 #include <swtypes.hxx>
28 #include <view.hxx>
29 #include <wrtsh.hxx>
30 #include <docsh.hxx>
32 #include <hintids.hxx>
33 #include <swmodule.hxx>
34 
36 #include <editeng/langitem.hxx>
37 #include <o3tl/temporary.hxx>
38 #include <officecfg/Office/Writer.hxx>
39 #include <svl/itemset.hxx>
40 #include <svl/stritem.hxx>
41 #include <svtools/ehdl.hxx>
42 #include <svtools/sfxecode.hxx>
43 #include <vcl/layout.hxx>
44 #include <vcl/weld.hxx>
45 #include <sfx2/dinfdlg.hxx>
46 #include <sfx2/printer.hxx>
47 #include <sfx2/fcontnr.hxx>
48 #include <sfx2/viewfrm.hxx>
49 #include <sfx2/dispatch.hxx>
50 #include <sfx2/docfile.hxx>
51 #include <sfx2/docfilt.hxx>
52 #include <tools/urlobj.hxx>
53 #include <svl/urihelper.hxx>
54 #include <vcl/print.hxx>
55 #include <vcl/settings.hxx>
56 #include <rtl/tencinfo.h>
57 #include <sal/log.hxx>
58 
59 #include <unotools/tempfile.hxx>
60 #include <osl/file.hxx>
61 #include <com/sun/star/frame/XStorable.hpp>
62 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
63 #include <com/sun/star/sdb/XColumn.hpp>
64 #include <com/sun/star/task/ErrorCodeIOException.hpp>
65 #include <com/sun/star/document/XDocumentPropertiesSupplier.hpp>
66 #include <dbmgr.hxx>
67 #include <swunohelper.hxx>
68 #include <shellio.hxx>
69 #include <svtools/htmlcfg.hxx>
70 #include <sfx2/event.hxx>
71 #include <swevent.hxx>
72 #include <dbui.hxx>
73 #include <dbui.hrc>
74 #include <doc.hxx>
75 #include <sfx2/app.hxx>
76 #include <strings.hrc>
77 #include <unomid.h>
78 #include <comphelper/string.hxx>
79 #include <iodetect.hxx>
80 
81 using namespace svt;
82 using namespace ::com::sun::star;
83 using namespace ::com::sun::star::uno;
84 
85 #define MM_DOCTYPE_OOO 1
86 #define MM_DOCTYPE_PDF 2
87 #define MM_DOCTYPE_WORD 3
88 #define MM_DOCTYPE_HTML 4
89 #define MM_DOCTYPE_TEXT 5
90 
91 static OUString lcl_GetExtensionForDocType(sal_uLong nDocType)
92 {
93  OUString sExtension;
94  switch( nDocType )
95  {
96  case MM_DOCTYPE_OOO : sExtension = "odt"; break;
97  case MM_DOCTYPE_PDF : sExtension = "pdf"; break;
98  case MM_DOCTYPE_WORD: sExtension = "doc"; break;
99  case MM_DOCTYPE_HTML: sExtension = "html"; break;
100  case MM_DOCTYPE_TEXT: sExtension = "txt"; break;
101  }
102  return sExtension;
103 }
104 
105 static OUString lcl_GetColumnValueOf(const OUString& rColumn, Reference < container::XNameAccess> const & rxColAccess )
106 {
107  OUString sRet;
108  try
109  {
110  if (rxColAccess->hasByName(rColumn))
111  {
112  Any aCol = rxColAccess->getByName(rColumn);
113  Reference< sdb::XColumn > xColumn;
114  aCol >>= xColumn;
115  if(xColumn.is())
116  sRet = xColumn->getString();
117  }
118  }
119  catch (const uno::Exception&)
120  {
121  }
122  return sRet;
123 }
124 
126 {
127  DECL_LINK( ModifyHdl, weld::Entry&, void);
128 public:
129  SwSaveWarningBox_Impl(weld::Window* pParent, const OUString& rFileName);
130 
131  OUString GetFileName() const
132  {
133  return m_xEdit->get_text();
134  }
135 };
136 
138 {
140  DECL_LINK( ModifyHdl, weld::Entry&, void);
141 public:
142  SwSendQueryBox_Impl(weld::Window* pParent, const OString& rID,
143  const OUString& rUIXMLDescription);
144 
145  void SetValue(const OUString& rSet)
146  {
147  m_xEdit->set_text(rSet);
148  ModifyHdl(*m_xEdit);
149  }
150 
151  OUString GetValue() const
152  {
153  return m_xEdit->get_text();
154  }
155 
156  void SetIsEmptyTextAllowed(bool bSet)
157  {
158  bIsEmptyAllowed = bSet;
159  ModifyHdl(*m_xEdit);
160  }
161 };
162 
163 SwSaveWarningBox_Impl::SwSaveWarningBox_Impl(weld::Window* pParent, const OUString& rFileName)
164  : SwMessageAndEditDialog(pParent, "AlreadyExistsDialog",
165  "modules/swriter/ui/alreadyexistsdialog.ui")
166 {
167  m_xEdit->set_text(rFileName);
168  m_xEdit->connect_changed(LINK(this, SwSaveWarningBox_Impl, ModifyHdl));
169 
170  INetURLObject aTmp(rFileName);
171  m_xDialog->set_primary_text(m_xDialog->get_primary_text().replaceAll("%1", aTmp.getName(
173 
174  ModifyHdl(*m_xEdit);
175 }
176 
177 IMPL_LINK( SwSaveWarningBox_Impl, ModifyHdl, weld::Entry&, rEdit, void)
178 {
179  m_xOKPB->set_sensitive(!rEdit.get_text().isEmpty());
180 }
181 
183  const OUString& rUIXMLDescription)
184  : SwMessageAndEditDialog(pParent, rID, rUIXMLDescription)
185  , bIsEmptyAllowed(true)
186 {
187  m_xEdit->connect_changed(LINK(this, SwSendQueryBox_Impl, ModifyHdl));
188  ModifyHdl(*m_xEdit);
189 }
190 
191 IMPL_LINK( SwSendQueryBox_Impl, ModifyHdl, weld::Entry&, rEdit, void)
192 {
193  m_xOKPB->set_sensitive(bIsEmptyAllowed || !rEdit.get_text().isEmpty());
194 }
195 
197 {
198  std::unique_ptr<weld::Entry> m_xCCED;
199  std::unique_ptr<weld::Entry> m_xBCCED;
200 
201 public:
202  explicit SwCopyToDialog(weld::Window* pParent)
203  : SfxDialogController(pParent, "modules/swriter/ui/ccdialog.ui", "CCDialog")
204  , m_xCCED(m_xBuilder->weld_entry("cc"))
205  , m_xBCCED(m_xBuilder->weld_entry("bcc"))
206  {
207  }
208 
209  OUString GetCC() {return m_xCCED->get_text();}
210  void SetCC(const OUString& rSet) {m_xCCED->set_text(rSet);}
211 
212  OUString GetBCC() {return m_xBCCED->get_text();}
213  void SetBCC(const OUString& rSet) {m_xBCCED->set_text(rSet);}
214 };
215 
217  : SfxDialogController(pParent, "modules/swriter/ui/mmresultsavedialog.ui", "MMResultSaveDialog")
218  , m_bCancelSaving(false)
219  , m_xSaveAsOneRB(m_xBuilder->weld_radio_button("singlerb"))
220  , m_xSaveIndividualRB(m_xBuilder->weld_radio_button("individualrb"))
221  , m_xFromRB(m_xBuilder->weld_radio_button("fromrb"))
222  , m_xFromNF(m_xBuilder->weld_spin_button("from"))
223  , m_xToFT(m_xBuilder->weld_label("toft"))
224  , m_xToNF(m_xBuilder->weld_spin_button("to"))
225  , m_xOKButton(m_xBuilder->weld_button("ok"))
226 {
227  Link<weld::ToggleButton&,void> aLink = LINK(this, SwMMResultSaveDialog, DocumentSelectionHdl_Impl);
228  m_xSaveAsOneRB->connect_toggled(aLink);
229  m_xSaveIndividualRB->connect_toggled(aLink);
230  m_xFromRB->connect_toggled(aLink);
231  // m_pSaveAsOneRB is the default, so disable m_xFromNF and m_xToNF initially.
232  aLink.Call(*m_xSaveAsOneRB);
233  SwView* pView = ::GetActiveView();
234  const std::shared_ptr<SwMailMergeConfigItem>& xConfigItem = pView->GetMailMergeConfigItem();
235  assert(xConfigItem);
236  sal_Int32 nCount = xConfigItem->GetMergedDocumentCount();
237  m_xFromNF->set_max(nCount);
238  m_xToNF->set_max(nCount);
239  m_xToNF->set_value(nCount);
240 
241  m_xOKButton->connect_clicked(LINK(this, SwMMResultSaveDialog, SaveOutputHdl_Impl));
242 }
243 
245 {
246 }
247 
249  : SfxDialogController(pParent, "modules/swriter/ui/mmresultprintdialog.ui", "MMResultPrintDialog")
250  , m_xPrinterFT(m_xBuilder->weld_label("printerft"))
251  , m_xPrinterLB(m_xBuilder->weld_combo_box("printers"))
252  , m_xPrinterSettingsPB(m_xBuilder->weld_button("printersettings"))
253  , m_xPrintAllRB(m_xBuilder->weld_radio_button("printallrb"))
254  , m_xFromRB(m_xBuilder->weld_radio_button("fromrb"))
255  , m_xFromNF(m_xBuilder->weld_spin_button("from"))
256  , m_xToFT(m_xBuilder->weld_label("toft"))
257  , m_xToNF(m_xBuilder->weld_spin_button("to"))
258  , m_xOKButton(m_xBuilder->weld_button("ok"))
259 {
260  m_xPrinterLB->make_sorted();
261 
262  m_xPrinterLB->connect_changed(LINK(this, SwMMResultPrintDialog, PrinterChangeHdl_Impl));
263  m_xPrinterSettingsPB->connect_clicked(LINK(this, SwMMResultPrintDialog, PrinterSetupHdl_Impl));
264 
265  Link<weld::ToggleButton&,void> aLink = LINK(this, SwMMResultPrintDialog, DocumentSelectionHdl_Impl);
266  m_xPrintAllRB->connect_toggled(aLink);
267  m_xFromRB->connect_toggled(aLink);
268  // m_pPrintAllRB is the default, so disable m_xFromNF and m_xToNF initially.
269  aLink.Call(*m_xPrintAllRB);
270 
271  m_xOKButton->connect_clicked(LINK(this, SwMMResultPrintDialog, PrintHdl_Impl));
272 
274 }
275 
277 {
278 }
279 
281  : SfxDialogController(pParent, "modules/swriter/ui/mmresultemaildialog.ui", "MMResultEmailDialog")
282  , m_sConfigureMail(SwResId(ST_CONFIGUREMAIL))
283  , m_xMailToFT(m_xBuilder->weld_label("mailtoft"))
284  , m_xMailToLB(m_xBuilder->weld_combo_box("mailto"))
285  , m_xCopyToPB(m_xBuilder->weld_button("copyto"))
286  , m_xSubjectFT(m_xBuilder->weld_label("subjectft"))
287  , m_xSubjectED(m_xBuilder->weld_entry("subject"))
288  , m_xSendAsFT(m_xBuilder->weld_label("sendasft"))
289  , m_xSendAsLB(m_xBuilder->weld_combo_box("sendas"))
290  , m_xSendAsPB(m_xBuilder->weld_button("sendassettings"))
291  , m_xAttachmentGroup(m_xBuilder->weld_widget("attachgroup"))
292  , m_xAttachmentED(m_xBuilder->weld_entry("attach"))
293  , m_xSendAllRB(m_xBuilder->weld_radio_button("sendallrb"))
294  , m_xFromRB(m_xBuilder->weld_radio_button("fromrb"))
295  , m_xFromNF(m_xBuilder->weld_spin_button("from"))
296  , m_xToFT(m_xBuilder->weld_label("toft"))
297  , m_xToNF(m_xBuilder->weld_spin_button("to"))
298  , m_xOKButton(m_xBuilder->weld_button("ok"))
299 {
300  m_xCopyToPB->connect_clicked(LINK(this, SwMMResultEmailDialog, CopyToHdl_Impl));
301  m_xSendAsPB->connect_clicked(LINK(this, SwMMResultEmailDialog, SendAsHdl_Impl));
302  m_xSendAsLB->connect_changed(LINK(this, SwMMResultEmailDialog, SendTypeHdl_Impl));
303 
304  Link<weld::ToggleButton&,void> aLink = LINK(this, SwMMResultEmailDialog, DocumentSelectionHdl_Impl);
305  m_xSendAllRB->connect_toggled(aLink);
306  m_xFromRB->connect_toggled(aLink);
307  // m_xSendAllRB is the default, so disable m_xFromNF and m_xToNF initially.
308  aLink.Call(*m_xSendAllRB);
309 
310  m_xOKButton->connect_clicked(LINK(this, SwMMResultEmailDialog, SendDocumentsHdl_Impl));
311 
313 }
314 
316 {
317 }
318 
320 {
321  //fill printer ListBox
322  SwView* pView = ::GetActiveView();
323  const std::shared_ptr<SwMailMergeConfigItem>& xConfigItem = pView->GetMailMergeConfigItem();
324  const std::vector<OUString>& rPrinters = Printer::GetPrinterQueues();
325  unsigned int nCount = rPrinters.size();
326  bool bMergePrinterExists = false;
327 
328  for (unsigned int i = 0; i < nCount; ++i)
329  {
330  m_xPrinterLB->append_text( rPrinters[i] );
331  if( !bMergePrinterExists && rPrinters[i] == xConfigItem->GetSelectedPrinter() )
332  bMergePrinterExists = true;
333  }
334 
335  assert(xConfigItem);
336  if(!bMergePrinterExists)
337  {
338  SfxPrinter* pPrinter = pView->GetWrtShell().getIDocumentDeviceAccess().getPrinter( true );
339  m_xPrinterLB->set_active_text(pPrinter->GetName());
340  }
341  else
342  {
343  m_xPrinterLB->set_active_text(xConfigItem->GetSelectedPrinter());
344  }
345 
346  sal_Int32 count = xConfigItem->GetMergedDocumentCount();
347  m_xToNF->set_value(count);
348  m_xToNF->set_max(count);
349 
350  m_xPrinterLB->set_active_text(xConfigItem->GetSelectedPrinter());
351 }
352 
354 {
355  SwView* pView = ::GetActiveView();
356  const std::shared_ptr<SwMailMergeConfigItem>& xConfigItem = pView->GetMailMergeConfigItem();
357  assert(xConfigItem);
358 
359  SwView* pSourceView = xConfigItem->GetSourceView();
360  OSL_ENSURE(pSourceView, "no source view exists");
361  if (pSourceView)
362  {
363  SwDocShell* pDocShell = pSourceView->GetDocShell();
364  if (pDocShell->HasName())
365  {
366  INetURLObject aTmp(pDocShell->GetMedium()->GetName());
367  m_xAttachmentED->set_text(aTmp.getName(
369  }
370  }
371 
372  if (m_xAttachmentED->get_text().isEmpty())
373  {
374  OUString sAttach = "." + lcl_GetExtensionForDocType(m_xSendAsLB->get_active_id().toUInt32());
375  m_xAttachmentED->set_text(sAttach);
376 
377  }
378 
379  //fill mail address ListBox
380  if (m_xMailToLB->get_count())
381  return;
382 
383  //select first column
384  uno::Reference< sdbcx::XColumnsSupplier > xColsSupp(xConfigItem->GetResultSet(), uno::UNO_QUERY);
385  //get the name of the actual columns
386  uno::Reference < container::XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : nullptr;
387  uno::Sequence< OUString > aFields;
388  if (xColAccess.is())
389  aFields = xColAccess->getElementNames();
390  const OUString* pFields = aFields.getConstArray();
391  for (sal_Int32 nField = 0; nField < aFields.getLength(); ++nField)
392  m_xMailToLB->append_text(pFields[nField]);
393 
394  m_xMailToLB->set_active(0);
395  // then select the right one - may not be available
396  const std::vector<std::pair<OUString, int>>& rHeaders = xConfigItem->GetDefaultAddressHeaders();
397  OUString sEMailColumn = rHeaders[MM_PART_E_MAIL].first;
398  Sequence< OUString> aAssignment = xConfigItem->GetColumnAssignment(xConfigItem->GetCurrentDBData());
399  if (aAssignment.getLength() > MM_PART_E_MAIL && !aAssignment[MM_PART_E_MAIL].isEmpty())
400  sEMailColumn = aAssignment[MM_PART_E_MAIL];
401  m_xMailToLB->set_active_text(sEMailColumn);
402 
403  // HTML format pre-selected
404  m_xSendAsLB->set_active(3);
405  SendTypeHdl_Impl(*m_xSendAsLB);
406 
407 }
408 
409 IMPL_LINK_NOARG(SwMMResultSaveDialog, DocumentSelectionHdl_Impl, weld::ToggleButton&, void)
410 {
411  bool bEnableFromTo = m_xFromRB->get_active();
412  m_xFromNF->set_sensitive(bEnableFromTo);
413  m_xToFT->set_sensitive(bEnableFromTo);
414  m_xToNF->set_sensitive(bEnableFromTo);
415 }
416 
417 IMPL_LINK_NOARG(SwMMResultPrintDialog, DocumentSelectionHdl_Impl, weld::ToggleButton&, void)
418 {
419  bool bEnableFromTo = m_xFromRB->get_active();
420  m_xFromNF->set_sensitive(bEnableFromTo);
421  m_xToFT->set_sensitive(bEnableFromTo);
422  m_xToNF->set_sensitive(bEnableFromTo);
423 }
424 
425 IMPL_LINK_NOARG(SwMMResultEmailDialog, DocumentSelectionHdl_Impl, weld::ToggleButton&, void)
426 {
427  bool bEnableFromTo = m_xFromRB->get_active();
428  m_xFromNF->set_sensitive(bEnableFromTo);
429  m_xToFT->set_sensitive(bEnableFromTo);
430  m_xToNF->set_sensitive(bEnableFromTo);
431 }
432 
434 {
435  SwCopyToDialog aDlg(m_xDialog.get());
436  aDlg.SetCC(m_sCC );
437  aDlg.SetBCC(m_sBCC);
438  if (aDlg.run() == RET_OK)
439  {
440  m_sCC = aDlg.GetCC() ;
441  m_sBCC = aDlg.GetBCC();
442  }
443 }
444 
445 namespace {
446 
447 int documentStartPageNumber(SwMailMergeConfigItem* pConfigItem, int document, bool bIgnoreEmpty)
448 {
449  SwView* pTargetView = pConfigItem->GetTargetView();
450  assert( pTargetView );
451  SwCursorShell& shell = pTargetView->GetWrtShell();
452  const SwDocMergeInfo& info = pConfigItem->GetDocumentMergeInfo(document);
453  sal_uInt16 page;
454  shell.Push();
455  shell.GotoMark( info.startPageInTarget );
456  if (!bIgnoreEmpty)
457  shell.GetPageNum(page, o3tl::temporary(sal_uInt16()));
458  else
459  page = shell.GetPageNumSeqNonEmpty();
461  return page;
462 }
463 
464 int documentEndPageNumber(SwMailMergeConfigItem* pConfigItem, int document, bool bIgnoreEmpty)
465 {
466  SwView* pTargetView = pConfigItem->GetTargetView();
467  assert( pTargetView );
468  SwWrtShell& shell = pTargetView->GetWrtShell();
469  shell.Push();
470  if (document < int(pConfigItem->GetMergedDocumentCount()) - 1)
471  {
472  // Go to the page before the starting page of the next merged document.
473  const SwDocMergeInfo& info = pConfigItem->GetDocumentMergeInfo( document + 1 );
474  shell.GotoMark( info.startPageInTarget );
475  shell.EndPrvPg();
476  }
477  else
478  { // This is the last merged document, so it ends on the page at which the document ends.
479  shell.SttEndDoc( false ); // go to doc end
480  }
481  sal_uInt16 page;
482  if (!bIgnoreEmpty)
483  shell.GetPageNum(page, o3tl::temporary(sal_uInt16()));
484  else
485  page = shell.GetPageNumSeqNonEmpty();
487  return page;
488 }
489 
490 } // anonymous namespace
491 
493 {
494  SwView* pView = ::GetActiveView();
495  std::shared_ptr<SwMailMergeConfigItem> xConfigItem = pView->GetMailMergeConfigItem();
496  assert(xConfigItem);
497  if (!xConfigItem->GetTargetView())
499 
500  SwView* pTargetView = xConfigItem->GetTargetView();
501  assert(pTargetView);
502 
503  if (m_xSaveAsOneRB->get_active())
504  {
505  OUString sFilter;
506  const OUString sPath = SwMailMergeHelper::CallSaveAsDialog(m_xDialog.get(), sFilter);
507  if (sPath.isEmpty())
508  {
509  // just return back to the dialog
510  return;
511  }
512  uno::Sequence< beans::PropertyValue > aValues(1);
513  beans::PropertyValue* pValues = aValues.getArray();
514  pValues[0].Name = "FilterName";
515  pValues[0].Value <<= sFilter;
516 
517  uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
518  ErrCode nErrorCode = ERRCODE_NONE;
519  try
520  {
521  xStore->storeToURL( sPath, aValues );
522  }
523  catch (const task::ErrorCodeIOException& rErrorEx)
524  {
525  nErrorCode = ErrCode(rErrorEx.ErrCode);
526  }
527  catch (const Exception&)
528  {
529  nErrorCode = ERRCODE_IO_GENERAL;
530  }
531  if( nErrorCode != ERRCODE_NONE )
532  {
534  ErrorHandler::HandleError( nErrorCode );
535  }
536  }
537  else
538  {
539  sal_uInt32 nBegin = 0;
540  sal_uInt32 nEnd = 0;
541  sal_uInt32 documentCount = xConfigItem->GetMergedDocumentCount();
542 
543  if (m_xSaveIndividualRB->get_active())
544  {
545  nBegin = 0;
546  nEnd = documentCount;
547  }
548  else
549  {
550  nBegin = static_cast< sal_Int32 >(m_xFromNF->get_value() - 1);
551  nEnd = static_cast< sal_Int32 >(m_xToNF->get_value());
552  if(nEnd > documentCount)
553  nEnd = documentCount;
554  }
555  OUString sFilter;
556  OUString sPath = SwMailMergeHelper::CallSaveAsDialog(m_xDialog.get(), sFilter);
557  if (sPath.isEmpty())
558  {
559  // just return back to the dialog
560  return;
561  }
562  OUString sTargetTempURL = URIHelper::SmartRel2Abs(
565  std::shared_ptr<const SfxFilter> pSfxFlt = SwIoSystem::GetFilterOfFormat(
566  FILTER_XML,
567  SwDocShell::Factory().GetFilterContainer() );
568 
569  uno::Sequence< beans::PropertyValue > aValues(1);
570  beans::PropertyValue* pValues = aValues.getArray();
571  pValues[0].Name = "FilterName";
572  pValues[0].Value <<= pSfxFlt->GetFilterName();
573 
574  uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
575  ErrCode nErrorCode = ERRCODE_NONE;
576  try
577  {
578  xStore->storeToURL( sTargetTempURL, aValues );
579  }
580  catch (const task::ErrorCodeIOException& rErrorEx)
581  {
582  nErrorCode = ErrCode(rErrorEx.ErrCode);
583  }
584  catch (const Exception&)
585  {
586  nErrorCode = ERRCODE_IO_GENERAL;
587  }
588  if( nErrorCode != ERRCODE_NONE )
589  {
591  ErrorHandler::HandleError( nErrorCode );
592  }
593 
594  SwView* pSourceView = xConfigItem->GetSourceView();
595  std::shared_ptr<SaveMonitor> xSaveMonitor(new SaveMonitor(m_xDialog.get()));
596  xSaveMonitor->m_xDocName->set_label(pSourceView->GetDocShell()->GetTitle(22));
597  xSaveMonitor->m_xPrinter->set_label( INetURLObject( sPath ).getFSysPath( FSysStyle::Detect ) );
598  m_bCancelSaving = false;
599  weld::DialogController::runAsync(xSaveMonitor, [this, &xSaveMonitor](sal_Int32 nResult){
600  if (nResult == RET_CANCEL)
601  m_bCancelSaving = true;
602  xSaveMonitor.reset();
603  });
604 
605  for(sal_uInt32 nDoc = nBegin; nDoc < nEnd && !m_bCancelSaving; ++nDoc)
606  {
607  INetURLObject aURL(sPath);
608  OUString sExtension = aURL.getExtension();
609  if (sExtension.isEmpty())
610  {
611  sExtension = pSfxFlt->GetWildcard().getGlob().getToken(1, '.');
612  sPath += "." + sExtension;
613  }
614  OUString sStat = SwResId(STR_STATSTR_LETTER) + " " + OUString::number( nDoc );
615  xSaveMonitor->m_xPrintInfo->set_label(sStat);
616 
617  //now extract a document from the target document
618  // the shell will be closed at the end, but it is more safe to use SfxObjectShellLock here
619  SfxObjectShellLock xTempDocShell( new SwDocShell( SfxObjectCreateMode::STANDARD ) );
620  xTempDocShell->DoInitNew();
621  SfxViewFrame* pTempFrame = SfxViewFrame::LoadHiddenDocument( *xTempDocShell, SFX_INTERFACE_NONE );
622  SwView* pTempView = static_cast<SwView*>( pTempFrame->GetViewShell() );
623  pTargetView->GetWrtShell().StartAction();
624  SwgReaderOption aOpt;
625  aOpt.SetTextFormats( true );
626  aOpt.SetFrameFormats( true );
627  aOpt.SetPageDescs( true );
628  aOpt.SetNumRules( true );
629  aOpt.SetMerge( false );
630  pTempView->GetDocShell()->LoadStylesFromFile(
631  sTargetTempURL, aOpt, true );
632  pTempView->GetDocShell()->GetDoc()->ReplaceCompatibilityOptions( *pTargetView->GetDocShell()->GetDoc());
633  pTempView->GetDocShell()->GetDoc()->ReplaceDefaults( *pTargetView->GetDocShell()->GetDoc());
634  pTempView->GetDocShell()->GetDoc()->ReplaceDocumentProperties( *pTargetView->GetDocShell()->GetDoc(), true );
635 
636  pTargetView->GetWrtShell().PastePages(
637  pTempView->GetWrtShell(), documentStartPageNumber(xConfigItem.get(), nDoc, false),
638  documentEndPageNumber(xConfigItem.get(), nDoc, false));
639  pTargetView->GetWrtShell().EndAction();
640  //then save it
641  OUString sOutPath = aURL.GetMainURL(INetURLObject::DecodeMechanism::ToIUri);
642  OUString sCounter = "_" + OUString::number(nDoc + 1);
643  sOutPath = sOutPath.replaceAt( sOutPath.getLength() - sExtension.getLength() - 1, 0, sCounter);
644 
645  while(true)
646  {
647  //time for other slots is needed
648  Application::Reschedule( true );
649  bool bFailed = false;
650  try
651  {
652  pValues[0].Value <<= sFilter;
653  uno::Reference< frame::XStorable > xTempStore( xTempDocShell->GetModel(), uno::UNO_QUERY);
654  xTempStore->storeToURL( sOutPath, aValues );
655  }
656  catch (const uno::Exception&)
657  {
658  bFailed = true;
659  }
660 
661  if(bFailed)
662  {
663  std::unique_ptr<SwSaveWarningBox_Impl> xWarning(new SwSaveWarningBox_Impl(m_xDialog.get(), sOutPath));
664  if (RET_OK == xWarning->run())
665  sOutPath = xWarning->GetFileName();
666  else
667  {
668  xTempDocShell->DoClose();
669  m_xDialog->response(RET_OK);
670  return;
671  }
672  }
673  else
674  {
675  xTempDocShell->DoClose();
676  m_xDialog->response(RET_OK);
677  break;
678  }
679  }
680  }
681  if (xSaveMonitor)
682  xSaveMonitor->response(RET_OK);
683  ::osl::File::remove( sTargetTempURL );
684  }
685 
686  m_xDialog->response(RET_OK);
687 }
688 
689 IMPL_LINK(SwMMResultPrintDialog, PrinterChangeHdl_Impl, weld::ComboBox&, rBox, void)
690 {
691  SwView* pView = ::GetActiveView();
692  const std::shared_ptr<SwMailMergeConfigItem>& xConfigItem = pView->GetMailMergeConfigItem();
693  assert(xConfigItem);
694  if (rBox.get_active() != -1)
695  {
696  const QueueInfo* pInfo = Printer::GetQueueInfo( rBox.get_active_text(), false );
697 
698  if( pInfo )
699  {
700  if ( !m_pTempPrinter )
701  {
702  m_pTempPrinter = VclPtr<Printer>::Create( *pInfo );
703  }
704  else
705  {
706  if( (m_pTempPrinter->GetName() != pInfo->GetPrinterName()) ||
707  (m_pTempPrinter->GetDriverName() != pInfo->GetDriver()) )
708  {
709  m_pTempPrinter.disposeAndClear();
710  m_pTempPrinter = VclPtr<Printer>::Create( *pInfo );
711  }
712  }
713  }
714  else if( ! m_pTempPrinter )
715  m_pTempPrinter = VclPtr<Printer>::Create();
716 
717  m_xPrinterSettingsPB->set_sensitive(m_pTempPrinter->HasSupport(PrinterSupport::SetupDialog));
718  }
719  else
720  m_xPrinterSettingsPB->set_sensitive(false);
721 
722  xConfigItem->SetSelectedPrinter(rBox.get_active_text());
723 }
724 
726 {
727  SwView* pView = ::GetActiveView();
728  std::shared_ptr<SwMailMergeConfigItem> xConfigItem = pView->GetMailMergeConfigItem();
729  assert(xConfigItem);
730  if(!xConfigItem->GetTargetView())
732 
733  SwView* pTargetView = xConfigItem->GetTargetView();
734  assert(pTargetView);
735 
736  sal_uInt32 nBegin = 0;
737  sal_uInt32 nEnd = 0;
738  sal_uInt32 documentCount = xConfigItem->GetMergedDocumentCount();
739 
740  if (m_xPrintAllRB->get_active())
741  {
742  nBegin = 0;
743  nEnd = documentCount;
744  }
745  else
746  {
747  nBegin = m_xFromNF->get_value() - 1;
748  nEnd = m_xToNF->get_value();
749  if(nEnd > documentCount)
750  nEnd = documentCount;
751  }
752 
753  // If we skip autoinserted blanks, then the page numbers used in the print range string
754  // refer to the non-blank pages as they appear in the document (see tdf#89708).
755  const bool bIgnoreEmptyPages = !officecfg::Office::Writer::Print::EmptyPages::get();
756  const int nStartPage = documentStartPageNumber(xConfigItem.get(), nBegin, bIgnoreEmptyPages);
757  const int nEndPage = documentEndPageNumber(xConfigItem.get(), nEnd - 1, bIgnoreEmptyPages);
758 
759  const OUString sPages(OUString::number(nStartPage) + "-" + OUString::number(nEndPage));
760 
761  pTargetView->SetMailMergeConfigItem(xConfigItem);
762  if(m_pTempPrinter)
763  {
764  SfxPrinter *const pDocumentPrinter = pTargetView->GetWrtShell()
766  pDocumentPrinter->SetPrinterProps(m_pTempPrinter);
767  // this should be able to handle setting its own printer
768  pTargetView->SetPrinter(pDocumentPrinter);
769  }
770 
771  SfxObjectShell* pObjSh = pTargetView->GetViewFrame()->GetObjectShell();
772  SfxGetpApp()->NotifyEvent(SfxEventHint(SfxEventHintId::SwMailMerge, SwDocShell::GetEventName(STR_SW_EVENT_MAIL_MERGE), pObjSh));
773 
774  uno::Sequence < beans::PropertyValue > aProps( 2 );
775  aProps[0]. Name = "MonitorVisible";
776  aProps[0].Value <<= true;
777  aProps[1]. Name = "Pages";
778  aProps[1]. Value <<= sPages;
779 
780  pTargetView->ExecPrint( aProps, false, true );
781  SfxGetpApp()->NotifyEvent(SfxEventHint(SfxEventHintId::SwMailMergeEnd, SwDocShell::GetEventName(STR_SW_EVENT_MAIL_MERGE_END), pObjSh));
782 
783  m_xDialog->response(RET_OK);
784 }
785 
786 IMPL_LINK_NOARG(SwMMResultPrintDialog, PrinterSetupHdl_Impl, weld::Button&, void)
787 {
788  if (!m_pTempPrinter)
789  PrinterChangeHdl_Impl(*m_xPrinterLB);
790  if (m_pTempPrinter)
791  m_pTempPrinter->Setup(m_xDialog.get());
792 }
793 
794 IMPL_LINK(SwMMResultEmailDialog, SendTypeHdl_Impl, weld::ComboBox&, rBox, void)
795 {
796  auto nDocType = rBox.get_active_id().toUInt32();
797  bool bEnable = MM_DOCTYPE_HTML != nDocType && MM_DOCTYPE_TEXT != nDocType;
798  m_xSendAsPB->set_sensitive(bEnable);
799  m_xAttachmentGroup->set_sensitive(bEnable);
800  if(bEnable)
801  {
802  //add the correct extension
803  OUString sAttach(m_xAttachmentED->get_text());
804  //do nothing if the user has removed the name - the warning will come early enough
805  if (!sAttach.isEmpty())
806  {
807  sal_Int32 nTokenCount = comphelper::string::getTokenCount(sAttach, '.');
808  if( 2 > nTokenCount)
809  {
810  sAttach += ".";
811  ++nTokenCount;
812  }
813  sAttach = comphelper::string::setToken(sAttach, nTokenCount - 1, '.', lcl_GetExtensionForDocType( nDocType ));
814  m_xAttachmentED->set_text(sAttach);
815  }
816  }
817 }
818 
820 {
821  SwMailBodyDialog aDlg(m_xDialog.get());
822  aDlg.SetBody(m_sBody);
823  if (RET_OK == aDlg.run())
824  {
825  m_sBody = aDlg.GetBody();
826  }
827 }
828 
829 // Send documents as e-mail
830 IMPL_LINK_NOARG(SwMMResultEmailDialog, SendDocumentsHdl_Impl, weld::Button&, void)
831 {
832  SwView* pView = ::GetActiveView();
833  std::shared_ptr<SwMailMergeConfigItem> xConfigItem = pView->GetMailMergeConfigItem();
834  assert(xConfigItem);
835  if (!xConfigItem->GetTargetView())
837 
838  //get the composed document
839  SwView* pTargetView = xConfigItem->GetTargetView();
840  SAL_WARN_IF(!pTargetView, "sw.ui", "No TargetView in SwMailMergeConfigItem");
841 
842  if (xConfigItem->GetMailServer().isEmpty() ||
843  !SwMailMergeHelper::CheckMailAddress(xConfigItem->GetMailAddress()) )
844  {
845  std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(m_xDialog.get(),
846  VclMessageType::Question, VclButtonsType::YesNo,
847  m_sConfigureMail));
848  xQueryBox->add_button(Button::GetStandardText(StandardButtonType::Cancel), RET_CANCEL);
849  sal_uInt16 nRet = xQueryBox->run();
850  if (RET_YES == nRet )
851  {
852  SwView* pConfigView = pTargetView ? pTargetView : pView;
853  SfxAllItemSet aSet(pConfigView->GetPool());
854  SwMailConfigDlg aDlg(m_xDialog.get(), aSet);
855  nRet = aDlg.run();
856  }
857 
858  if(nRet != RET_OK && nRet != RET_YES)
859  return; // back to the dialog
860  }
861  //add the documents
862  sal_uInt32 nBegin = 0;
863  sal_uInt32 nEnd = 0;
864  if (m_xSendAllRB->get_active())
865  {
866  nBegin = 0;
867  nEnd = xConfigItem->GetMergedDocumentCount();
868  }
869  else
870  {
871  nBegin = static_cast< sal_Int32 >(m_xFromNF->get_value() - 1);
872  nEnd = static_cast< sal_Int32 >(m_xToNF->get_value());
873  if(nEnd > xConfigItem->GetMergedDocumentCount())
874  nEnd = xConfigItem->GetMergedDocumentCount();
875  }
876  bool bAsBody = false;
877  rtl_TextEncoding eEncoding = ::osl_getThreadTextEncoding();
878  SfxFilterContainer* pFilterContainer = SwDocShell::Factory().GetFilterContainer();
879  std::shared_ptr<const SfxFilter> pSfxFlt;
880  auto nDocType = m_xSendAsLB->get_active_id().toUInt32();
881  OUString sExtension = lcl_GetExtensionForDocType(nDocType);
882  switch( nDocType )
883  {
884  case MM_DOCTYPE_OOO:
885  {
886  //Make sure we don't pick e.g. the flat xml filter
887  //for this format
889  FILTER_XML,
890  SwDocShell::Factory().GetFilterContainer() );
891  }
892  break;
893  case MM_DOCTYPE_PDF:
894  {
895  pSfxFlt = pFilterContainer->GetFilter4FilterName(
896  "writer_pdf_Export",
897  SfxFilterFlags::EXPORT);
898  }
899  break;
900  case MM_DOCTYPE_WORD:
901  {
902  //the method SwIOSystemGetFilterOfFormat( ) returns the template filter
903  //because it uses the same user data :-(
904  SfxFilterMatcher aMatcher( pFilterContainer->GetName() );
905  SfxFilterMatcherIter aIter( aMatcher );
906  std::shared_ptr<const SfxFilter> pFilter = aIter.First();
907  while ( pFilter )
908  {
909  if( pFilter->GetUserData() == FILTER_WW8 && pFilter->CanExport() )
910  {
911  pSfxFlt = pFilter;
912  break;
913  }
914  pFilter = aIter.Next();
915  }
916 
917  }
918  break;
919  case MM_DOCTYPE_HTML:
920  {
921  bAsBody = true;
922  SvxHtmlOptions& rHtmlOptions = SvxHtmlOptions::Get();
923  eEncoding = rHtmlOptions.GetTextEncoding();
924  }
925  break;
926  case MM_DOCTYPE_TEXT:
927  {
928  bAsBody = true;
929  pSfxFlt = pFilterContainer->GetFilter4FilterName(
930  "Text (encoded)", SfxFilterFlags::EXPORT);
931  }
932  break;
933  }
934  if(!pSfxFlt)
935  pSfxFlt = pFilterContainer->GetFilter4Extension(sExtension, SfxFilterFlags::EXPORT);
936 
937  if(!pSfxFlt)
938  {
939  m_xDialog->response(RET_OK);
940  return;
941  }
942  OUString sMimeType = pSfxFlt->GetMimeType();
943 
944  if (m_xSubjectED->get_text().isEmpty())
945  {
946  std::unique_ptr<SwSendQueryBox_Impl> xQuery(new SwSendQueryBox_Impl(m_xDialog.get(), "SubjectDialog",
947  "modules/swriter/ui/subjectdialog.ui"));
948  xQuery->SetIsEmptyTextAllowed(true);
949  xQuery->SetValue("");
950  if(RET_OK == xQuery->run())
951  {
952  if (!xQuery->GetValue().isEmpty())
953  m_xSubjectED->set_text(xQuery->GetValue());
954  }
955  else
956  return; // back to the dialog
957  }
958  if(!bAsBody && m_xAttachmentED->get_text().isEmpty())
959  {
960  std::unique_ptr<SwSendQueryBox_Impl> xQuery(new SwSendQueryBox_Impl(m_xDialog.get(), "AttachNameDialog",
961  "modules/swriter/ui/attachnamedialog.ui"));
962  xQuery->SetIsEmptyTextAllowed(false);
963  if (RET_OK == xQuery->run())
964  {
965  OUString sAttach(xQuery->GetValue());
966  sal_Int32 nTokenCount = comphelper::string::getTokenCount(sAttach, '.');
967  if (2 > nTokenCount)
968  {
969  sAttach += ".";
970  ++nTokenCount;
971  }
972  sAttach = comphelper::string::setToken(sAttach, nTokenCount - 1, '.', lcl_GetExtensionForDocType(
973  m_xSendAsLB->get_active_id().toUInt32()));
974  m_xAttachmentED->set_text(sAttach);
975  }
976  else
977  return; // back to the dialog
978  }
979  OUString sEMailColumn = m_xMailToLB->get_active_text();
980  OSL_ENSURE( !sEMailColumn.isEmpty(), "No email column selected");
981  Reference< sdbcx::XColumnsSupplier > xColsSupp( xConfigItem->GetResultSet(), UNO_QUERY);
982  Reference < container::XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : nullptr;
983  if(sEMailColumn.isEmpty() || !xColAccess.is() || !xColAccess->hasByName(sEMailColumn))
984  {
985  m_xDialog->response(RET_OK);
986  return;
987  }
988 
989  OUString sFilterOptions;
990  if(MM_DOCTYPE_TEXT == nDocType)
991  {
992  SwAsciiOptions aOpt;
993  sal_uInt16 nAppScriptType = SvtLanguageOptions::GetI18NScriptTypeOfLanguage( GetAppLanguage() );
994  sal_uInt16 nWhich = GetWhichOfScript( RES_CHRATR_LANGUAGE, nAppScriptType);
995  aOpt.SetLanguage( static_cast<const SvxLanguageItem&>(pTargetView->GetWrtShell().
996  GetDefault( nWhich )).GetLanguage());
997  aOpt.SetParaFlags( LINEEND_CR );
998  aOpt.WriteUserData( sFilterOptions );
999  }
1000  else if(MM_DOCTYPE_HTML == nDocType)
1001  {
1002  sFilterOptions = "EmbedImages";
1003  }
1004  OUString sTargetTempURL = URIHelper::SmartRel2Abs(
1007  std::shared_ptr<const SfxFilter> pTargetSfxFlt = SwIoSystem::GetFilterOfFormat(
1008  FILTER_XML,
1009  SwDocShell::Factory().GetFilterContainer() );
1010 
1011  uno::Sequence< beans::PropertyValue > aValues(1);
1012  beans::PropertyValue* pValues = aValues.getArray();
1013  pValues[0].Name = "FilterName";
1014  pValues[0].Value <<= pTargetSfxFlt->GetFilterName();
1015 
1016  uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
1017  xStore->storeToURL( sTargetTempURL, aValues );
1018 
1019  //create the send dialog
1021  VclPtr<SwSendMailDialog> pDlg = VclPtr<SwSendMailDialog>::Create(pParent, *xConfigItem);
1022 
1023  pDlg->ShowDialog(nEnd - nBegin);
1024  //help to force painting the dialog
1025  //TODO/CLEANUP
1026  //predetermined breaking point
1027  Application::Reschedule( true );
1028  m_xDialog->response(RET_OK);
1029  for(sal_uInt32 nDoc = nBegin; nDoc < nEnd; ++nDoc)
1030  {
1031  SwDocMergeInfo& rInfo = xConfigItem->GetDocumentMergeInfo(nDoc);
1032 
1033  //now extract a document from the target document
1034  // the shell will be closed at the end, but it is more safe to use SfxObjectShellLock here
1035  SfxObjectShellLock xTempDocShell( new SwDocShell( SfxObjectCreateMode::STANDARD ) );
1036  xTempDocShell->DoInitNew();
1037  SfxViewFrame* pTempFrame = SfxViewFrame::LoadHiddenDocument( *xTempDocShell, SFX_INTERFACE_NONE );
1038  SwView* pTempView = static_cast<SwView*>( pTempFrame->GetViewShell() );
1039  pTargetView->GetWrtShell().StartAction();
1040  SwgReaderOption aOpt;
1041  aOpt.SetTextFormats( true );
1042  aOpt.SetFrameFormats( true );
1043  aOpt.SetPageDescs( true );
1044  aOpt.SetNumRules( true );
1045  aOpt.SetMerge( false );
1046  pTempView->GetDocShell()->LoadStylesFromFile(
1047  sTargetTempURL, aOpt, true );
1048  pTempView->GetDocShell()->GetDoc()->ReplaceCompatibilityOptions( *pTargetView->GetDocShell()->GetDoc());
1049  pTempView->GetDocShell()->GetDoc()->ReplaceDefaults( *pTargetView->GetDocShell()->GetDoc());
1050  pTempView->GetDocShell()->GetDoc()->ReplaceDocumentProperties( *pTargetView->GetDocShell()->GetDoc(), true );
1051  pTargetView->GetWrtShell().PastePages(
1052  pTempView->GetWrtShell(), documentStartPageNumber(xConfigItem.get(), nDoc, false),
1053  documentEndPageNumber(xConfigItem.get(), nDoc, false));
1054  pTargetView->GetWrtShell().EndAction();
1055 
1056  //then save it
1057  SfxStringItem aName(SID_FILE_NAME,
1061 
1062  {
1063  bool withFilterOptions = MM_DOCTYPE_TEXT == nDocType || MM_DOCTYPE_HTML == nDocType;
1064  uno::Sequence< beans::PropertyValue > aFilterValues(withFilterOptions ? 2 : 1);
1065  beans::PropertyValue* pFilterValues = aFilterValues.getArray();
1066  pFilterValues[0].Name = "FilterName";
1067  pFilterValues[0].Value <<= pSfxFlt->GetFilterName();
1068  if(withFilterOptions)
1069  {
1070  pFilterValues[1].Name = "FilterOptions";
1071  pFilterValues[1].Value <<= sFilterOptions;
1072  }
1073 
1074  uno::Reference< frame::XStorable > xTempStore( pTempView->GetDocShell()->GetModel(), uno::UNO_QUERY);
1075  xTempStore->storeToURL( aName.GetValue(), aFilterValues );
1076  }
1077  xTempDocShell->DoClose();
1078 
1079  sal_Int32 nTarget = xConfigItem->MoveResultSet(rInfo.nDBRow);
1080  OSL_ENSURE( nTarget == rInfo.nDBRow, "row of current document could not be selected");
1081  OSL_ENSURE( !sEMailColumn.isEmpty(), "No email column selected");
1082  OUString sEMail = lcl_GetColumnValueOf(sEMailColumn, xColAccess);
1083  SwMailDescriptor aDesc;
1084  aDesc.sEMail = sEMail;
1085  OUStringBuffer sBody;
1086  if(bAsBody)
1087  {
1088  {
1089  //read in the temporary file and use it as mail body
1090  SfxMedium aMedium( aName.GetValue(), StreamMode::READ);
1091  SvStream* pInStream = aMedium.GetInStream();
1092  if(pInStream)
1093  pInStream->SetStreamCharSet( eEncoding );
1094  else
1095  {
1096  OSL_FAIL("no output file created?");
1097  continue;
1098  }
1099  OString sLine;
1100  bool bDone = pInStream->ReadLine( sLine );
1101  while ( bDone )
1102  {
1103  sBody.append( OStringToOUString(sLine, eEncoding) );
1104  sBody.append("\n");
1105  bDone = pInStream->ReadLine( sLine );
1106  }
1107  }
1108  //remove the temporary file
1110  }
1111  else
1112  {
1113  sBody = m_sBody;
1114  aDesc.sAttachmentURL = aName.GetValue();
1115  OUString sAttachment(m_xAttachmentED->get_text());
1116  sal_Int32 nTokenCount = comphelper::string::getTokenCount(sAttachment, '.');
1117  if (2 > nTokenCount)
1118  {
1119  sAttachment += ".";
1120  sAttachment = comphelper::string::setToken(sAttachment, nTokenCount, '.', sExtension);
1121  }
1122  else if (sAttachment.getToken( nTokenCount - 1, '.') != sExtension)
1123  sAttachment += sExtension;
1124  aDesc.sAttachmentName = sAttachment;
1125  aDesc.sMimeType = sMimeType;
1126 
1127  if (xConfigItem->IsGreetingLine(true))
1128  {
1129  OUString sNameColumn = xConfigItem->GetAssignedColumn(MM_PART_LASTNAME);
1130  OUString sName = lcl_GetColumnValueOf(sNameColumn, xColAccess);
1131  OUString sGreeting;
1132  if(!sName.isEmpty() && xConfigItem->IsIndividualGreeting(true))
1133  {
1134  OUString sGenderColumn = xConfigItem->GetAssignedColumn(MM_PART_GENDER);
1135  const OUString& sFemaleValue = xConfigItem->GetFemaleGenderValue();
1136  OUString sGenderValue = lcl_GetColumnValueOf(sGenderColumn, xColAccess);
1137  SwMailMergeConfigItem::Gender eGenderType = sGenderValue == sFemaleValue ?
1140 
1141  sGreeting = SwAddressPreview::FillData(
1142  xConfigItem->GetGreetings(eGenderType)
1143  [xConfigItem->GetCurrentGreeting(eGenderType)],
1144  *xConfigItem);
1145  }
1146  else
1147  {
1148  sGreeting =
1149  xConfigItem->GetGreetings(SwMailMergeConfigItem::NEUTRAL)
1150  [xConfigItem->GetCurrentGreeting(SwMailMergeConfigItem::NEUTRAL)];
1151 
1152  }
1153  sGreeting += "\n";
1154  sBody.insert(0, sGreeting);
1155  }
1156  }
1157  aDesc.sBodyContent = sBody.makeStringAndClear();
1158  if(MM_DOCTYPE_HTML == nDocType)
1159  {
1160  aDesc.sBodyMimeType = "text/html; charset=" +
1161  OUString::createFromAscii(rtl_getBestMimeCharsetFromTextEncoding( eEncoding ));
1162  }
1163  else
1164  aDesc.sBodyMimeType = "text/plain; charset=UTF-8; format=flowed";
1165 
1166  aDesc.sSubject = m_xSubjectED->get_text();
1167  aDesc.sCC = m_sCC;
1168  aDesc.sBCC = m_sBCC;
1169  pDlg->AddDocument( aDesc );
1170  //help to force painting the dialog
1171  Application::Reschedule( true );
1172  //stop creating of data when dialog has been closed
1173  if(!pDlg->IsVisible())
1174  {
1175  break;
1176  }
1177  }
1178  pDlg->EnableDestruction();
1179  ::osl::File::remove( sTargetTempURL );
1180 
1181 }
1182 
1183 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
css::uno::Reference< css::linguistic2::XProofreadingIterator > get(css::uno::Reference< css::uno::XComponentContext > const &context)
SfxViewFrame * GetViewFrame() const
SwMMResultPrintDialog(weld::Window *pParent)
std::unique_ptr< weld::RadioButton > m_xFromRB
static OUString CreateTempName()
const size_t count(pCandidateA->getBorderLines().size())
SwMMResultSaveDialog(weld::Window *pParent)
std::unique_ptr< weld::SpinButton > m_xToNF
#define MM_DOCTYPE_HTML
void SetValue(const OUString &rSet)
void ShowDialog(sal_Int32 nExpectedCount)
void SetMailMergeConfigItem(std::shared_ptr< SwMailMergeConfigItem > const &rConfigItem)
Definition: view0.cxx:133
OUString GetTitle(sal_uInt16 nMaxLen=0) const
#define RES_CHRATR_LANGUAGE
Definition: hintids.hxx:78
SwView * GetActiveView()
Definition: swmodul1.cxx:123
#define MM_DOCTYPE_TEXT
void PastePages(SwFEShell &rToFill, sal_uInt16 nStartPage, sal_uInt16 nEndPage)
Paste some pages into another doc - used in mailmerge.
Definition: fecopy.cxx:1096
bool SttEndDoc(bool bStt)
Definition: crsrsh.cxx:563
void SetIsEmptyTextAllowed(bool bSet)
void SetPageDescs(const bool bNew)
Definition: shellio.hxx:122
std::shared_ptr< SwMailMergeConfigItem > const & GetMailMergeConfigItem() const
Definition: view0.cxx:139
const OUString & GetDriver() const
static vcl::Window * GetDefDialogParent()
const OUString & GetName() const
sal_uIntPtr sal_uLong
LanguageType GetLanguage(SfxItemSet const &aSet, sal_uInt16 nLangWhichId)
Definition: langhelper.cxx:402
bool Pop(SwCursorShell::PopMode=SwCursorShell::PopMode::DeleteStack)
Definition: wrtsh1.cxx:1690
bool EndPrvPg(bool bSelect=false)
Definition: move.cxx:330
SwSaveWarningBox_Impl(weld::Window *pParent, const OUString &rFileName)
void GetPageNum(sal_uInt16 &rnPhyNum, sal_uInt16 &rnVirtNum, bool bAtCursorPos=true, const bool bCalcFrame=true)
Definition: crsrsh.cxx:1197
void ReplaceCompatibilityOptions(const SwDoc &rSource)
Definition: docnew.cxx:869
OUString Name
css::uno::Reference< css::frame::XModel > GetModel() const
bool UCB_DeleteFile(const OUString &rURL)
Definition: swunohelper.cxx:58
std::unique_ptr< weld::Button > m_xOKButton
void SetParaFlags(LineEnd eVal)
Definition: shellio.hxx:83
bool GotoMark(const ::sw::mark::IMark *const pMark)
Definition: crbm.cxx:186
LINEEND_CR
virtual SfxObjectShell * GetObjectShell() override
std::unique_ptr< weld::Button > m_xCopyToPB
RET_CANCEL
SwWrtShell & GetWrtShell() const
Definition: view.hxx:400
SfxApplication * SfxGetpApp()
void SetTextFormats(const bool bNew)
Definition: shellio.hxx:125
Used by the UI to modify the document model.
Definition: wrtsh.hxx:86
Value
static bool runAsync(const std::shared_ptr< DialogController > &rController, const std::function< void(sal_Int32)> &)
OUString GetFileName() const
std::unique_ptr< weld::Entry > m_xEdit
sw::mark::IMark * startPageInTarget
void SetLanguage(LanguageType nVal)
Definition: shellio.hxx:80
constexpr auto SFX_INTERFACE_NONE
static OUString lcl_GetExtensionForDocType(sal_uLong nDocType)
RET_YES
void ReplaceDefaults(const SwDoc &rSource)
Definition: docnew.cxx:837
#define MM_DOCTYPE_WORD
SwMMResultEmailDialog(weld::Window *pParent)
SwDocMergeInfo & GetDocumentMergeInfo(sal_uInt32 nDocument)
IMPL_LINK_NOARG(SwMMResultSaveDialog, DocumentSelectionHdl_Impl, weld::ToggleButton &, void)
std::unique_ptr< weld::RadioButton > m_xSendAllRB
std::shared_ptr< const SfxFilter > GetFilter4Extension(const OUString &rExt, SfxFilterFlags nMust=SfxFilterFlags::IMPORT, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
std::unique_ptr< weld::Button > m_xOKButton
virtual ~SwMMResultEmailDialog() override
SfxItemPool & GetPool() const
static SvxHtmlOptions & Get()
sal_uInt32 GetMergedDocumentCount()
SwDoc * GetDoc()
returns Doc. But be careful!
Definition: docsh.hxx:202
std::unique_ptr< weld::RadioButton > m_xFromRB
const IDocumentDeviceAccess & getIDocumentDeviceAccess() const
Provides access to the document device interface.
Definition: viewsh.cxx:2590
Dialog implementing the printing of the result document.
std::unique_ptr< weld::ComboBox > m_xPrinterLB
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 STR_SW_EVENT_MAIL_MERGE_END
Definition: swevent.hxx:29
OUString GetValue() const
void AddDocument(SwMailDescriptor const &rDesc)
OUString CallSaveAsDialog(weld::Window *pParent, OUString &rFilter)
static bool Reschedule(bool bHandleAllCurrentEvents=false)
#define ERRCODE_IO_GENERAL
ErrCode LoadStylesFromFile(const OUString &rURL, SwgReaderOption const &rOpt, bool bUnoCall)
Definition: docsh2.cxx:1573
void EndAction(const bool bIdleEnd=false, const bool DoSetPosX=false)
Definition: crsrsh.cxx:229
SVL_DLLPUBLIC Link< OUString *, bool > const & GetMaybeFileHdl()
void Push()
store a copy of the current cursor on the cursor stack
Definition: crsrsh.cxx:2143
OUString getName(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
static DialogMask HandleError(ErrCode nId, weld::Window *pParent=nullptr, DialogMask nMask=DialogMask::MAX)
OUString sName
int i
void ExecPrint(const css::uno::Sequence< css::beans::PropertyValue > &, bool, bool)
const OUString & GetValue() const
sal_uInt16 GetPageNumSeqNonEmpty()
Definition: crsrsh.cxx:1217
static sal_Int16 GetI18NScriptTypeOfLanguage(LanguageType nLang)
#define MM_DOCTYPE_PDF
void NotifyEvent(const SfxEventHint &rEvent, bool bSynchron=true)
sal_uInt16 GetWhichOfScript(sal_uInt16 nWhich, sal_uInt16 nScript)
Definition: hints.cxx:195
std::unique_ptr< weld::Entry > m_xAttachmentED
bool HasName() const
OUString SwResId(const char *pId)
Definition: swmodule.cxx:191
Dialog implementing the sending as email of the result document.
std::unique_ptr< weld::Button > m_xOKButton
SwSendQueryBox_Impl(weld::Window *pParent, const OString &rID, const OUString &rUIXMLDescription)
std::unique_ptr< weld::Button > m_xSendAsPB
virtual SfxPrinter * getPrinter(bool bCreate) const =0
Return the printer set at the document.
SfxViewShell * GetViewShell() const
virtual sal_uInt16 SetPrinter(SfxPrinter *pNew, SfxPrinterChangeFlags nDiff=SFX_PRINTER_ALL) override
Definition: viewprt.cxx:111
SwDocShell * GetDocShell()
Definition: view.cxx:1115
virtual OUString get_text() const =0
#define FILTER_WW8
WinWord 97 filter.
Definition: iodetect.hxx:33
void WriteUserData(OUString &)
Definition: fltini.cxx:603
constexpr T & temporary(T &&x)
static const std::vector< OUString > & GetPrinterQueues()
std::unique_ptr< weld::ComboBox > m_xSendAsLB
void StartAction()
Definition: crsrsh.cxx:212
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
static std::shared_ptr< SwMailMergeConfigItem > PerformMailMerge(SwView const *pView)
Definition: dbmgr.cxx:3310
std::unique_ptr< weld::Entry > m_xBCCED
void GotoMark(const ::sw::mark::IMark *const pMark)
Definition: wrtsh3.cxx:138
void SetCC(const OUString &rSet)
weld::Entry & rEdit
#define SAL_WARN_IF(condition, area, stream)
#define ERRCODE_NONE
static SfxViewFrame * LoadHiddenDocument(SfxObjectShell const &i_rDoc, SfxInterfaceId i_nViewId)
static OUString GetStandardText(StandardButtonType eButton)
#define STR_SW_EVENT_MAIL_MERGE
Definition: swevent.hxx:28
void SetBody(const OUString &rBody)
void SetBCC(const OUString &rSet)
#define FILTER_XML
XML filter.
Definition: iodetect.hxx:35
#define MM_DOCTYPE_OOO
Dialog implementing the saving as of the result document.
#define ERRCTX_SFX_SAVEASDOC
std::shared_ptr< const SfxFilter > GetFilter4FilterName(const OUString &rName, SfxFilterFlags nMust=SfxFilterFlags::NONE, SfxFilterFlags nDont=SFX_FILTER_NOTINSTALLED) const
bool IsVisible() const
LanguageType GetAppLanguage()
Definition: init.cxx:760
bool DoInitNew(SfxMedium *pMedium=nullptr)
RET_OK
static VclPtr< reference_type > Create(Arg &&...arg)
void SetStreamCharSet(rtl_TextEncoding eCharSet)
static const QueueInfo * GetQueueInfo(const OUString &rPrinterName, bool bStatusUpdate)
std::unique_ptr< weld::ComboBox > m_xMailToLB
std::unique_ptr< weld::Button > m_xPrinterSettingsPB
std::unique_ptr< weld::Entry > m_xCCED
static OUString GetEventName(sal_Int32 nId)
Definition: docsh.cxx:1341
static weld::MessageDialog * CreateMessageDialog(weld::Widget *pParent, VclMessageType eMessageType, VclButtonsType eButtonType, const OUString &rPrimaryMessage)
std::unique_ptr< weld::SpinButton > m_xFromNF
std::unique_ptr< weld::SpinButton > m_xToNF
static OUString lcl_GetColumnValueOf(const OUString &rColumn, Reference< container::XNameAccess > const &rxColAccess)
IMPL_LINK(SwSaveWarningBox_Impl, ModifyHdl, weld::Entry &, rEdit, void)
OString const aName
void ReplaceDocumentProperties(const SwDoc &rSource, bool mailMerge=false)
Replace document properties with those from rSource.
Definition: docglos.cxx:83
bool CheckMailAddress(const OUString &rMailAddress)
rtl_TextEncoding GetTextEncoding() const
sal_Int32 getTokenCount(const OString &rIn, sal_Char cTok)
const OUString & GetPrinterName() const
bool Pop(PopMode)
delete cursor
Definition: crsrsh.cxx:2165
virtual ~SwMMResultSaveDialog() override
std::unique_ptr< weld::RadioButton > m_xSaveIndividualRB
OUString setToken(const OUString &rIn, sal_Int32 nToken, sal_Unicode cTok, const OUString &rNewToken)
void SetFrameFormats(const bool bNew)
Definition: shellio.hxx:119
OUString const & GetName() const
std::unique_ptr< weld::RadioButton > m_xPrintAllRB
static OUString FillData(const OUString &rAddress, SwMailMergeConfigItem const &rConfigItem, const css::uno::Sequence< OUString > *pAssignments=nullptr)
virtual ~SwMMResultPrintDialog() override
std::unique_ptr< weld::MessageDialog > m_xDialog
SwCopyToDialog(weld::Window *pParent)
Definition: view.hxx:146
void SetMerge(const bool bNew)
Definition: shellio.hxx:131
void SetNumRules(const bool bNew)
Definition: shellio.hxx:128
OUString getExtension(sal_Int32 nIndex=LAST_SEGMENT, bool bIgnoreFinalSlash=true, DecodeMechanism eMechanism=DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
std::unique_ptr< weld::RadioButton > m_xFromRB
SVL_DLLPUBLIC OUString SmartRel2Abs(INetURLObject const &rTheBaseURIRef, OUString const &rTheRelURIRef, Link< OUString *, bool > const &rMaybeFileHdl=Link< OUString *, bool >(), bool bCheckFileExists=true, bool bIgnoreFragment=false, INetURLObject::EncodeMechanism eEncodeMechanism=INetURLObject::EncodeMechanism::WasEncoded, INetURLObject::DecodeMechanism eDecodeMechanism=INetURLObject::DecodeMechanism::ToIUri, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8, FSysStyle eStyle=FSysStyle::Detect)
std::unique_ptr< weld::RadioButton > m_xSaveAsOneRB
SfxMedium * GetMedium() const