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  PrinterChangeHdl_Impl(*m_xPrinterLB);
346 
347  sal_Int32 count = xConfigItem->GetMergedDocumentCount();
348  m_xToNF->set_value(count);
349  m_xToNF->set_max(count);
350 }
351 
353 {
354  SwView* pView = ::GetActiveView();
355  const std::shared_ptr<SwMailMergeConfigItem>& xConfigItem = pView->GetMailMergeConfigItem();
356  assert(xConfigItem);
357 
358  SwView* pSourceView = xConfigItem->GetSourceView();
359  OSL_ENSURE(pSourceView, "no source view exists");
360  if (pSourceView)
361  {
362  SwDocShell* pDocShell = pSourceView->GetDocShell();
363  if (pDocShell->HasName())
364  {
365  INetURLObject aTmp(pDocShell->GetMedium()->GetName());
366  m_xAttachmentED->set_text(aTmp.getName(
368  }
369  }
370 
371  if (m_xAttachmentED->get_text().isEmpty())
372  {
373  OUString sAttach = "." + lcl_GetExtensionForDocType(m_xSendAsLB->get_active_id().toUInt32());
374  m_xAttachmentED->set_text(sAttach);
375 
376  }
377 
378  //fill mail address ListBox
379  if (m_xMailToLB->get_count())
380  return;
381 
382  //select first column
383  uno::Reference< sdbcx::XColumnsSupplier > xColsSupp(xConfigItem->GetResultSet(), uno::UNO_QUERY);
384  //get the name of the actual columns
385  uno::Reference < container::XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : nullptr;
386  uno::Sequence< OUString > aFields;
387  if (xColAccess.is())
388  aFields = xColAccess->getElementNames();
389  for (const OUString& rField : aFields)
390  m_xMailToLB->append_text(rField);
391 
392  m_xMailToLB->set_active(0);
393  // then select the right one - may not be available
394  const std::vector<std::pair<OUString, int>>& rHeaders = xConfigItem->GetDefaultAddressHeaders();
395  OUString sEMailColumn = rHeaders[MM_PART_E_MAIL].first;
396  Sequence< OUString> aAssignment = xConfigItem->GetColumnAssignment(xConfigItem->GetCurrentDBData());
397  if (aAssignment.getLength() > MM_PART_E_MAIL && !aAssignment[MM_PART_E_MAIL].isEmpty())
398  sEMailColumn = aAssignment[MM_PART_E_MAIL];
399  m_xMailToLB->set_active_text(sEMailColumn);
400 
401  // HTML format pre-selected
402  m_xSendAsLB->set_active(3);
403  SendTypeHdl_Impl(*m_xSendAsLB);
404 
405 }
406 
407 IMPL_LINK_NOARG(SwMMResultSaveDialog, DocumentSelectionHdl_Impl, weld::ToggleButton&, void)
408 {
409  bool bEnableFromTo = m_xFromRB->get_active();
410  m_xFromNF->set_sensitive(bEnableFromTo);
411  m_xToFT->set_sensitive(bEnableFromTo);
412  m_xToNF->set_sensitive(bEnableFromTo);
413 }
414 
415 IMPL_LINK_NOARG(SwMMResultPrintDialog, DocumentSelectionHdl_Impl, weld::ToggleButton&, void)
416 {
417  bool bEnableFromTo = m_xFromRB->get_active();
418  m_xFromNF->set_sensitive(bEnableFromTo);
419  m_xToFT->set_sensitive(bEnableFromTo);
420  m_xToNF->set_sensitive(bEnableFromTo);
421 }
422 
423 IMPL_LINK_NOARG(SwMMResultEmailDialog, DocumentSelectionHdl_Impl, weld::ToggleButton&, void)
424 {
425  bool bEnableFromTo = m_xFromRB->get_active();
426  m_xFromNF->set_sensitive(bEnableFromTo);
427  m_xToFT->set_sensitive(bEnableFromTo);
428  m_xToNF->set_sensitive(bEnableFromTo);
429 }
430 
432 {
433  SwCopyToDialog aDlg(m_xDialog.get());
434  aDlg.SetCC(m_sCC );
435  aDlg.SetBCC(m_sBCC);
436  if (aDlg.run() == RET_OK)
437  {
438  m_sCC = aDlg.GetCC() ;
439  m_sBCC = aDlg.GetBCC();
440  }
441 }
442 
443 namespace {
444 
445 int documentStartPageNumber(SwMailMergeConfigItem* pConfigItem, int document, bool bIgnoreEmpty)
446 {
447  SwView* pTargetView = pConfigItem->GetTargetView();
448  assert( pTargetView );
449  SwCursorShell& shell = pTargetView->GetWrtShell();
450  const SwDocMergeInfo& info = pConfigItem->GetDocumentMergeInfo(document);
451  sal_uInt16 page;
452  shell.Push();
453  shell.GotoMark( info.startPageInTarget );
454  if (!bIgnoreEmpty)
455  shell.GetPageNum(page, o3tl::temporary(sal_uInt16()));
456  else
457  page = shell.GetPageNumSeqNonEmpty();
459  return page;
460 }
461 
462 int documentEndPageNumber(SwMailMergeConfigItem* pConfigItem, int document, bool bIgnoreEmpty)
463 {
464  SwView* pTargetView = pConfigItem->GetTargetView();
465  assert( pTargetView );
466  SwWrtShell& shell = pTargetView->GetWrtShell();
467  shell.Push();
468  if (document < int(pConfigItem->GetMergedDocumentCount()) - 1)
469  {
470  // Go to the page before the starting page of the next merged document.
471  const SwDocMergeInfo& info = pConfigItem->GetDocumentMergeInfo( document + 1 );
472  shell.GotoMark( info.startPageInTarget );
473  shell.EndPrvPg();
474  }
475  else
476  { // This is the last merged document, so it ends on the page at which the document ends.
477  shell.SttEndDoc( false ); // go to doc end
478  }
479  sal_uInt16 page;
480  if (!bIgnoreEmpty)
481  shell.GetPageNum(page, o3tl::temporary(sal_uInt16()));
482  else
483  page = shell.GetPageNumSeqNonEmpty();
485  return page;
486 }
487 
488 } // anonymous namespace
489 
491 {
492  SwView* pView = ::GetActiveView();
493  std::shared_ptr<SwMailMergeConfigItem> xConfigItem = pView->GetMailMergeConfigItem();
494  assert(xConfigItem);
495  if (!xConfigItem->GetTargetView())
497 
498  SwView* pTargetView = xConfigItem->GetTargetView();
499  assert(pTargetView);
500 
501  if (m_xSaveAsOneRB->get_active())
502  {
503  OUString sFilter;
504  const OUString sPath = SwMailMergeHelper::CallSaveAsDialog(m_xDialog.get(), sFilter);
505  if (sPath.isEmpty())
506  {
507  // just return back to the dialog
508  return;
509  }
510  uno::Sequence< beans::PropertyValue > aValues(1);
511  beans::PropertyValue* pValues = aValues.getArray();
512  pValues[0].Name = "FilterName";
513  pValues[0].Value <<= sFilter;
514 
515  uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
516  ErrCode nErrorCode = ERRCODE_NONE;
517  try
518  {
519  xStore->storeToURL( sPath, aValues );
520  }
521  catch (const task::ErrorCodeIOException& rErrorEx)
522  {
523  nErrorCode = ErrCode(rErrorEx.ErrCode);
524  }
525  catch (const Exception&)
526  {
527  nErrorCode = ERRCODE_IO_GENERAL;
528  }
529  if( nErrorCode != ERRCODE_NONE )
530  {
532  ErrorHandler::HandleError( nErrorCode );
533  }
534  }
535  else
536  {
537  sal_uInt32 nBegin = 0;
538  sal_uInt32 nEnd = 0;
539  sal_uInt32 documentCount = xConfigItem->GetMergedDocumentCount();
540 
541  if (m_xSaveIndividualRB->get_active())
542  {
543  nBegin = 0;
544  nEnd = documentCount;
545  }
546  else
547  {
548  nBegin = static_cast< sal_Int32 >(m_xFromNF->get_value() - 1);
549  nEnd = static_cast< sal_Int32 >(m_xToNF->get_value());
550  if(nEnd > documentCount)
551  nEnd = documentCount;
552  }
553  OUString sFilter;
554  OUString sPath = SwMailMergeHelper::CallSaveAsDialog(m_xDialog.get(), sFilter);
555  if (sPath.isEmpty())
556  {
557  // just return back to the dialog
558  return;
559  }
560  OUString sTargetTempURL = URIHelper::SmartRel2Abs(
563  std::shared_ptr<const SfxFilter> pSfxFlt = SwIoSystem::GetFilterOfFormat(
564  FILTER_XML,
565  SwDocShell::Factory().GetFilterContainer() );
566 
567  uno::Sequence< beans::PropertyValue > aValues(1);
568  beans::PropertyValue* pValues = aValues.getArray();
569  pValues[0].Name = "FilterName";
570  pValues[0].Value <<= pSfxFlt->GetFilterName();
571 
572  uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
573  ErrCode nErrorCode = ERRCODE_NONE;
574  try
575  {
576  xStore->storeToURL( sTargetTempURL, aValues );
577  }
578  catch (const task::ErrorCodeIOException& rErrorEx)
579  {
580  nErrorCode = ErrCode(rErrorEx.ErrCode);
581  }
582  catch (const Exception&)
583  {
584  nErrorCode = ERRCODE_IO_GENERAL;
585  }
586  if( nErrorCode != ERRCODE_NONE )
587  {
589  ErrorHandler::HandleError( nErrorCode );
590  }
591 
592  SwView* pSourceView = xConfigItem->GetSourceView();
593  std::shared_ptr<SaveMonitor> xSaveMonitor(new SaveMonitor(m_xDialog.get()));
594  xSaveMonitor->m_xDocName->set_label(pSourceView->GetDocShell()->GetTitle(22));
595  xSaveMonitor->m_xPrinter->set_label( INetURLObject( sPath ).getFSysPath( FSysStyle::Detect ) );
596  m_bCancelSaving = false;
597  weld::DialogController::runAsync(xSaveMonitor, [this, &xSaveMonitor](sal_Int32 nResult){
598  if (nResult == RET_CANCEL)
599  m_bCancelSaving = true;
600  xSaveMonitor.reset();
601  });
602 
603  for(sal_uInt32 nDoc = nBegin; nDoc < nEnd && !m_bCancelSaving; ++nDoc)
604  {
605  INetURLObject aURL(sPath);
606  OUString sExtension = aURL.getExtension();
607  if (sExtension.isEmpty())
608  {
609  sExtension = pSfxFlt->GetWildcard().getGlob().getToken(1, '.');
610  sPath += "." + sExtension;
611  }
612  OUString sStat = SwResId(STR_STATSTR_LETTER) + " " + OUString::number( nDoc );
613  xSaveMonitor->m_xPrintInfo->set_label(sStat);
614 
615  //now extract a document from the target document
616  // the shell will be closed at the end, but it is more safe to use SfxObjectShellLock here
617  SfxObjectShellLock xTempDocShell( new SwDocShell( SfxObjectCreateMode::STANDARD ) );
618  xTempDocShell->DoInitNew();
619  SfxViewFrame* pTempFrame = SfxViewFrame::LoadHiddenDocument( *xTempDocShell, SFX_INTERFACE_NONE );
620  SwView* pTempView = static_cast<SwView*>( pTempFrame->GetViewShell() );
621  pTargetView->GetWrtShell().StartAction();
622  SwgReaderOption aOpt;
623  aOpt.SetTextFormats( true );
624  aOpt.SetFrameFormats( true );
625  aOpt.SetPageDescs( true );
626  aOpt.SetNumRules( true );
627  aOpt.SetMerge( false );
628  pTempView->GetDocShell()->LoadStylesFromFile(
629  sTargetTempURL, aOpt, true );
630  pTempView->GetDocShell()->GetDoc()->ReplaceCompatibilityOptions( *pTargetView->GetDocShell()->GetDoc());
631  pTempView->GetDocShell()->GetDoc()->ReplaceDefaults( *pTargetView->GetDocShell()->GetDoc());
632  pTempView->GetDocShell()->GetDoc()->ReplaceDocumentProperties( *pTargetView->GetDocShell()->GetDoc(), true );
633 
634  pTargetView->GetWrtShell().PastePages(
635  pTempView->GetWrtShell(), documentStartPageNumber(xConfigItem.get(), nDoc, false),
636  documentEndPageNumber(xConfigItem.get(), nDoc, false));
637  pTargetView->GetWrtShell().EndAction();
638  //then save it
639  OUString sOutPath = aURL.GetMainURL(INetURLObject::DecodeMechanism::ToIUri);
640  OUString sCounter = "_" + OUString::number(nDoc + 1);
641  sOutPath = sOutPath.replaceAt( sOutPath.getLength() - sExtension.getLength() - 1, 0, sCounter);
642 
643  while(true)
644  {
645  //time for other slots is needed
646  Application::Reschedule( true );
647  bool bFailed = false;
648  try
649  {
650  pValues[0].Value <<= sFilter;
651  uno::Reference< frame::XStorable > xTempStore( xTempDocShell->GetModel(), uno::UNO_QUERY);
652  xTempStore->storeToURL( sOutPath, aValues );
653  }
654  catch (const uno::Exception&)
655  {
656  bFailed = true;
657  }
658 
659  if(bFailed)
660  {
661  std::unique_ptr<SwSaveWarningBox_Impl> xWarning(new SwSaveWarningBox_Impl(m_xDialog.get(), sOutPath));
662  if (RET_OK == xWarning->run())
663  sOutPath = xWarning->GetFileName();
664  else
665  {
666  xTempDocShell->DoClose();
667  m_xDialog->response(RET_OK);
668  return;
669  }
670  }
671  else
672  {
673  xTempDocShell->DoClose();
674  m_xDialog->response(RET_OK);
675  break;
676  }
677  }
678  }
679  if (xSaveMonitor)
680  xSaveMonitor->response(RET_OK);
681  ::osl::File::remove( sTargetTempURL );
682  }
683 
684  m_xDialog->response(RET_OK);
685 }
686 
687 IMPL_LINK(SwMMResultPrintDialog, PrinterChangeHdl_Impl, weld::ComboBox&, rBox, void)
688 {
689  SwView* pView = ::GetActiveView();
690  const std::shared_ptr<SwMailMergeConfigItem>& xConfigItem = pView->GetMailMergeConfigItem();
691  assert(xConfigItem);
692  if (rBox.get_active() != -1)
693  {
694  const QueueInfo* pInfo = Printer::GetQueueInfo( rBox.get_active_text(), false );
695 
696  if( pInfo )
697  {
698  if ( !m_pTempPrinter )
699  {
700  m_pTempPrinter = VclPtr<Printer>::Create( *pInfo );
701  }
702  else
703  {
704  if( (m_pTempPrinter->GetName() != pInfo->GetPrinterName()) ||
705  (m_pTempPrinter->GetDriverName() != pInfo->GetDriver()) )
706  {
707  m_pTempPrinter.disposeAndClear();
708  m_pTempPrinter = VclPtr<Printer>::Create( *pInfo );
709  }
710  }
711  }
712  else if( ! m_pTempPrinter )
713  m_pTempPrinter = VclPtr<Printer>::Create();
714 
715  m_xPrinterSettingsPB->set_sensitive(m_pTempPrinter->HasSupport(PrinterSupport::SetupDialog));
716  }
717  else
718  m_xPrinterSettingsPB->set_sensitive(false);
719 
720  xConfigItem->SetSelectedPrinter(rBox.get_active_text());
721 }
722 
724 {
725  SwView* pView = ::GetActiveView();
726  std::shared_ptr<SwMailMergeConfigItem> xConfigItem = pView->GetMailMergeConfigItem();
727  assert(xConfigItem);
728  if(!xConfigItem->GetTargetView())
730 
731  SwView* pTargetView = xConfigItem->GetTargetView();
732  assert(pTargetView);
733 
734  sal_uInt32 nBegin = 0;
735  sal_uInt32 nEnd = 0;
736  sal_uInt32 documentCount = xConfigItem->GetMergedDocumentCount();
737 
738  if (m_xPrintAllRB->get_active())
739  {
740  nBegin = 0;
741  nEnd = documentCount;
742  }
743  else
744  {
745  nBegin = m_xFromNF->get_value() - 1;
746  nEnd = m_xToNF->get_value();
747  if(nEnd > documentCount)
748  nEnd = documentCount;
749  }
750 
751  // If we skip autoinserted blanks, then the page numbers used in the print range string
752  // refer to the non-blank pages as they appear in the document (see tdf#89708).
753  const bool bIgnoreEmptyPages = !officecfg::Office::Writer::Print::EmptyPages::get();
754  const int nStartPage = documentStartPageNumber(xConfigItem.get(), nBegin, bIgnoreEmptyPages);
755  const int nEndPage = documentEndPageNumber(xConfigItem.get(), nEnd - 1, bIgnoreEmptyPages);
756 
757  const OUString sPages(OUString::number(nStartPage) + "-" + OUString::number(nEndPage));
758 
759  pTargetView->SetMailMergeConfigItem(xConfigItem);
760  if(m_pTempPrinter)
761  {
762  SfxPrinter *const pDocumentPrinter = pTargetView->GetWrtShell()
764  pDocumentPrinter->SetPrinterProps(m_pTempPrinter);
765  // this should be able to handle setting its own printer
766  pTargetView->SetPrinter(pDocumentPrinter);
767  }
768 
769  SfxObjectShell* pObjSh = pTargetView->GetViewFrame()->GetObjectShell();
770  SfxGetpApp()->NotifyEvent(SfxEventHint(SfxEventHintId::SwMailMerge, SwDocShell::GetEventName(STR_SW_EVENT_MAIL_MERGE), pObjSh));
771 
772  uno::Sequence < beans::PropertyValue > aProps( 2 );
773  aProps[0]. Name = "MonitorVisible";
774  aProps[0].Value <<= true;
775  aProps[1]. Name = "Pages";
776  aProps[1]. Value <<= sPages;
777 
778  pTargetView->ExecPrint( aProps, false, true );
779  SfxGetpApp()->NotifyEvent(SfxEventHint(SfxEventHintId::SwMailMergeEnd, SwDocShell::GetEventName(STR_SW_EVENT_MAIL_MERGE_END), pObjSh));
780 
781  m_xDialog->response(RET_OK);
782 }
783 
784 IMPL_LINK_NOARG(SwMMResultPrintDialog, PrinterSetupHdl_Impl, weld::Button&, void)
785 {
786  if (m_pTempPrinter)
787  m_pTempPrinter->Setup(m_xDialog.get());
788 }
789 
790 IMPL_LINK(SwMMResultEmailDialog, SendTypeHdl_Impl, weld::ComboBox&, rBox, void)
791 {
792  auto nDocType = rBox.get_active_id().toUInt32();
793  bool bEnable = MM_DOCTYPE_HTML != nDocType && MM_DOCTYPE_TEXT != nDocType;
794  m_xSendAsPB->set_sensitive(bEnable);
795  m_xAttachmentGroup->set_sensitive(bEnable);
796  if(bEnable)
797  {
798  //add the correct extension
799  OUString sAttach(m_xAttachmentED->get_text());
800  //do nothing if the user has removed the name - the warning will come early enough
801  if (!sAttach.isEmpty())
802  {
803  sal_Int32 nTokenCount = comphelper::string::getTokenCount(sAttach, '.');
804  if( 2 > nTokenCount)
805  {
806  sAttach += ".";
807  ++nTokenCount;
808  }
809  sAttach = comphelper::string::setToken(sAttach, nTokenCount - 1, '.', lcl_GetExtensionForDocType( nDocType ));
810  m_xAttachmentED->set_text(sAttach);
811  }
812  }
813 }
814 
816 {
817  SwMailBodyDialog aDlg(m_xDialog.get());
818  aDlg.SetBody(m_sBody);
819  if (RET_OK == aDlg.run())
820  {
821  m_sBody = aDlg.GetBody();
822  }
823 }
824 
825 // Send documents as e-mail
826 IMPL_LINK_NOARG(SwMMResultEmailDialog, SendDocumentsHdl_Impl, weld::Button&, void)
827 {
828  SwView* pView = ::GetActiveView();
829  std::shared_ptr<SwMailMergeConfigItem> xConfigItem = pView->GetMailMergeConfigItem();
830  assert(xConfigItem);
831  if (!xConfigItem->GetTargetView())
833 
834  //get the composed document
835  SwView* pTargetView = xConfigItem->GetTargetView();
836  SAL_WARN_IF(!pTargetView, "sw.ui", "No TargetView in SwMailMergeConfigItem");
837 
838  if (xConfigItem->GetMailServer().isEmpty() ||
839  !SwMailMergeHelper::CheckMailAddress(xConfigItem->GetMailAddress()) )
840  {
841  std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(m_xDialog.get(),
842  VclMessageType::Question, VclButtonsType::YesNo,
843  m_sConfigureMail));
844  xQueryBox->add_button(Button::GetStandardText(StandardButtonType::Cancel), RET_CANCEL);
845  sal_uInt16 nRet = xQueryBox->run();
846  if (RET_YES == nRet )
847  {
848  SwView* pConfigView = pTargetView ? pTargetView : pView;
849  SfxAllItemSet aSet(pConfigView->GetPool());
850  SwMailConfigDlg aDlg(m_xDialog.get(), aSet);
851  nRet = aDlg.run();
852  }
853 
854  if(nRet != RET_OK && nRet != RET_YES)
855  return; // back to the dialog
856  }
857  //add the documents
858  sal_uInt32 nBegin = 0;
859  sal_uInt32 nEnd = 0;
860  if (m_xSendAllRB->get_active())
861  {
862  nBegin = 0;
863  nEnd = xConfigItem->GetMergedDocumentCount();
864  }
865  else
866  {
867  nBegin = static_cast< sal_Int32 >(m_xFromNF->get_value() - 1);
868  nEnd = static_cast< sal_Int32 >(m_xToNF->get_value());
869  if(nEnd > xConfigItem->GetMergedDocumentCount())
870  nEnd = xConfigItem->GetMergedDocumentCount();
871  }
872  bool bAsBody = false;
873  rtl_TextEncoding eEncoding = ::osl_getThreadTextEncoding();
874  SfxFilterContainer* pFilterContainer = SwDocShell::Factory().GetFilterContainer();
875  std::shared_ptr<const SfxFilter> pSfxFlt;
876  auto nDocType = m_xSendAsLB->get_active_id().toUInt32();
877  OUString sExtension = lcl_GetExtensionForDocType(nDocType);
878  switch( nDocType )
879  {
880  case MM_DOCTYPE_OOO:
881  {
882  //Make sure we don't pick e.g. the flat xml filter
883  //for this format
885  FILTER_XML,
886  SwDocShell::Factory().GetFilterContainer() );
887  }
888  break;
889  case MM_DOCTYPE_PDF:
890  {
891  pSfxFlt = pFilterContainer->GetFilter4FilterName(
892  "writer_pdf_Export",
893  SfxFilterFlags::EXPORT);
894  }
895  break;
896  case MM_DOCTYPE_WORD:
897  {
898  //the method SwIOSystemGetFilterOfFormat( ) returns the template filter
899  //because it uses the same user data :-(
900  SfxFilterMatcher aMatcher( pFilterContainer->GetName() );
901  SfxFilterMatcherIter aIter( aMatcher );
902  std::shared_ptr<const SfxFilter> pFilter = aIter.First();
903  while ( pFilter )
904  {
905  if( pFilter->GetUserData() == FILTER_WW8 && pFilter->CanExport() )
906  {
907  pSfxFlt = pFilter;
908  break;
909  }
910  pFilter = aIter.Next();
911  }
912 
913  }
914  break;
915  case MM_DOCTYPE_HTML:
916  {
917  bAsBody = true;
918  SvxHtmlOptions& rHtmlOptions = SvxHtmlOptions::Get();
919  eEncoding = rHtmlOptions.GetTextEncoding();
920  }
921  break;
922  case MM_DOCTYPE_TEXT:
923  {
924  bAsBody = true;
925  pSfxFlt = pFilterContainer->GetFilter4FilterName(
926  "Text (encoded)", SfxFilterFlags::EXPORT);
927  }
928  break;
929  }
930  if(!pSfxFlt)
931  pSfxFlt = pFilterContainer->GetFilter4Extension(sExtension, SfxFilterFlags::EXPORT);
932 
933  if(!pSfxFlt)
934  {
935  m_xDialog->response(RET_OK);
936  return;
937  }
938  OUString sMimeType = pSfxFlt->GetMimeType();
939 
940  if (m_xSubjectED->get_text().isEmpty())
941  {
942  std::unique_ptr<SwSendQueryBox_Impl> xQuery(new SwSendQueryBox_Impl(m_xDialog.get(), "SubjectDialog",
943  "modules/swriter/ui/subjectdialog.ui"));
944  xQuery->SetIsEmptyTextAllowed(true);
945  xQuery->SetValue("");
946  if(RET_OK == xQuery->run())
947  {
948  if (!xQuery->GetValue().isEmpty())
949  m_xSubjectED->set_text(xQuery->GetValue());
950  }
951  else
952  return; // back to the dialog
953  }
954  if(!bAsBody && m_xAttachmentED->get_text().isEmpty())
955  {
956  std::unique_ptr<SwSendQueryBox_Impl> xQuery(new SwSendQueryBox_Impl(m_xDialog.get(), "AttachNameDialog",
957  "modules/swriter/ui/attachnamedialog.ui"));
958  xQuery->SetIsEmptyTextAllowed(false);
959  if (RET_OK == xQuery->run())
960  {
961  OUString sAttach(xQuery->GetValue());
962  sal_Int32 nTokenCount = comphelper::string::getTokenCount(sAttach, '.');
963  if (2 > nTokenCount)
964  {
965  sAttach += ".";
966  ++nTokenCount;
967  }
968  sAttach = comphelper::string::setToken(sAttach, nTokenCount - 1, '.', lcl_GetExtensionForDocType(
969  m_xSendAsLB->get_active_id().toUInt32()));
970  m_xAttachmentED->set_text(sAttach);
971  }
972  else
973  return; // back to the dialog
974  }
975  OUString sEMailColumn = m_xMailToLB->get_active_text();
976  OSL_ENSURE( !sEMailColumn.isEmpty(), "No email column selected");
977  Reference< sdbcx::XColumnsSupplier > xColsSupp( xConfigItem->GetResultSet(), UNO_QUERY);
978  Reference < container::XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : nullptr;
979  if(sEMailColumn.isEmpty() || !xColAccess.is() || !xColAccess->hasByName(sEMailColumn))
980  {
981  m_xDialog->response(RET_OK);
982  return;
983  }
984 
985  OUString sFilterOptions;
986  if(MM_DOCTYPE_TEXT == nDocType)
987  {
988  SwAsciiOptions aOpt;
989  sal_uInt16 nAppScriptType = SvtLanguageOptions::GetI18NScriptTypeOfLanguage( GetAppLanguage() );
990  sal_uInt16 nWhich = GetWhichOfScript( RES_CHRATR_LANGUAGE, nAppScriptType);
991  aOpt.SetLanguage( static_cast<const SvxLanguageItem&>(pTargetView->GetWrtShell().
992  GetDefault( nWhich )).GetLanguage());
993  aOpt.SetParaFlags( LINEEND_CR );
994  aOpt.WriteUserData( sFilterOptions );
995  }
996  else if(MM_DOCTYPE_HTML == nDocType)
997  {
998  sFilterOptions = "EmbedImages";
999  }
1000  OUString sTargetTempURL = URIHelper::SmartRel2Abs(
1003  std::shared_ptr<const SfxFilter> pTargetSfxFlt = SwIoSystem::GetFilterOfFormat(
1004  FILTER_XML,
1005  SwDocShell::Factory().GetFilterContainer() );
1006 
1007  uno::Sequence< beans::PropertyValue > aValues(1);
1008  beans::PropertyValue* pValues = aValues.getArray();
1009  pValues[0].Name = "FilterName";
1010  pValues[0].Value <<= pTargetSfxFlt->GetFilterName();
1011 
1012  uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
1013  xStore->storeToURL( sTargetTempURL, aValues );
1014 
1015  //create the send dialog
1017  VclPtr<SwSendMailDialog> pDlg = VclPtr<SwSendMailDialog>::Create(pParent, *xConfigItem);
1018 
1019  pDlg->ShowDialog(nEnd - nBegin);
1020  //help to force painting the dialog
1021  //TODO/CLEANUP
1022  //predetermined breaking point
1023  Application::Reschedule( true );
1024  m_xDialog->response(RET_OK);
1025  for(sal_uInt32 nDoc = nBegin; nDoc < nEnd; ++nDoc)
1026  {
1027  SwDocMergeInfo& rInfo = xConfigItem->GetDocumentMergeInfo(nDoc);
1028 
1029  //now extract a document from the target document
1030  // the shell will be closed at the end, but it is more safe to use SfxObjectShellLock here
1031  SfxObjectShellLock xTempDocShell( new SwDocShell( SfxObjectCreateMode::STANDARD ) );
1032  xTempDocShell->DoInitNew();
1033  SfxViewFrame* pTempFrame = SfxViewFrame::LoadHiddenDocument( *xTempDocShell, SFX_INTERFACE_NONE );
1034  SwView* pTempView = static_cast<SwView*>( pTempFrame->GetViewShell() );
1035  pTargetView->GetWrtShell().StartAction();
1036  SwgReaderOption aOpt;
1037  aOpt.SetTextFormats( true );
1038  aOpt.SetFrameFormats( true );
1039  aOpt.SetPageDescs( true );
1040  aOpt.SetNumRules( true );
1041  aOpt.SetMerge( false );
1042  pTempView->GetDocShell()->LoadStylesFromFile(
1043  sTargetTempURL, aOpt, true );
1044  pTempView->GetDocShell()->GetDoc()->ReplaceCompatibilityOptions( *pTargetView->GetDocShell()->GetDoc());
1045  pTempView->GetDocShell()->GetDoc()->ReplaceDefaults( *pTargetView->GetDocShell()->GetDoc());
1046  pTempView->GetDocShell()->GetDoc()->ReplaceDocumentProperties( *pTargetView->GetDocShell()->GetDoc(), true );
1047  pTargetView->GetWrtShell().PastePages(
1048  pTempView->GetWrtShell(), documentStartPageNumber(xConfigItem.get(), nDoc, false),
1049  documentEndPageNumber(xConfigItem.get(), nDoc, false));
1050  pTargetView->GetWrtShell().EndAction();
1051 
1052  //then save it
1053  SfxStringItem aName(SID_FILE_NAME,
1057 
1058  {
1059  bool withFilterOptions = MM_DOCTYPE_TEXT == nDocType || MM_DOCTYPE_HTML == nDocType;
1060  uno::Sequence< beans::PropertyValue > aFilterValues(withFilterOptions ? 2 : 1);
1061  beans::PropertyValue* pFilterValues = aFilterValues.getArray();
1062  pFilterValues[0].Name = "FilterName";
1063  pFilterValues[0].Value <<= pSfxFlt->GetFilterName();
1064  if(withFilterOptions)
1065  {
1066  pFilterValues[1].Name = "FilterOptions";
1067  pFilterValues[1].Value <<= sFilterOptions;
1068  }
1069 
1070  uno::Reference< frame::XStorable > xTempStore( pTempView->GetDocShell()->GetModel(), uno::UNO_QUERY);
1071  xTempStore->storeToURL( aName.GetValue(), aFilterValues );
1072  }
1073  xTempDocShell->DoClose();
1074 
1075  sal_Int32 nTarget = xConfigItem->MoveResultSet(rInfo.nDBRow);
1076  OSL_ENSURE( nTarget == rInfo.nDBRow, "row of current document could not be selected");
1077  OSL_ENSURE( !sEMailColumn.isEmpty(), "No email column selected");
1078  OUString sEMail = lcl_GetColumnValueOf(sEMailColumn, xColAccess);
1079  SwMailDescriptor aDesc;
1080  aDesc.sEMail = sEMail;
1081  OUStringBuffer sBody;
1082  if(bAsBody)
1083  {
1084  {
1085  //read in the temporary file and use it as mail body
1086  SfxMedium aMedium( aName.GetValue(), StreamMode::READ);
1087  SvStream* pInStream = aMedium.GetInStream();
1088  if(pInStream)
1089  pInStream->SetStreamCharSet( eEncoding );
1090  else
1091  {
1092  OSL_FAIL("no output file created?");
1093  continue;
1094  }
1095  OString sLine;
1096  bool bDone = pInStream->ReadLine( sLine );
1097  while ( bDone )
1098  {
1099  sBody.append( OStringToOUString(sLine, eEncoding) );
1100  sBody.append("\n");
1101  bDone = pInStream->ReadLine( sLine );
1102  }
1103  }
1104  //remove the temporary file
1106  }
1107  else
1108  {
1109  sBody = m_sBody;
1110  aDesc.sAttachmentURL = aName.GetValue();
1111  OUString sAttachment(m_xAttachmentED->get_text());
1112  sal_Int32 nTokenCount = comphelper::string::getTokenCount(sAttachment, '.');
1113  if (2 > nTokenCount)
1114  {
1115  sAttachment += ".";
1116  sAttachment = comphelper::string::setToken(sAttachment, nTokenCount, '.', sExtension);
1117  }
1118  else if (sAttachment.getToken( nTokenCount - 1, '.') != sExtension)
1119  sAttachment += sExtension;
1120  aDesc.sAttachmentName = sAttachment;
1121  aDesc.sMimeType = sMimeType;
1122 
1123  if (xConfigItem->IsGreetingLine(true))
1124  {
1125  OUString sNameColumn = xConfigItem->GetAssignedColumn(MM_PART_LASTNAME);
1126  OUString sName = lcl_GetColumnValueOf(sNameColumn, xColAccess);
1127  OUString sGreeting;
1128  if(!sName.isEmpty() && xConfigItem->IsIndividualGreeting(true))
1129  {
1130  OUString sGenderColumn = xConfigItem->GetAssignedColumn(MM_PART_GENDER);
1131  const OUString& sFemaleValue = xConfigItem->GetFemaleGenderValue();
1132  OUString sGenderValue = lcl_GetColumnValueOf(sGenderColumn, xColAccess);
1133  SwMailMergeConfigItem::Gender eGenderType = sGenderValue == sFemaleValue ?
1136 
1137  sGreeting = SwAddressPreview::FillData(
1138  xConfigItem->GetGreetings(eGenderType)
1139  [xConfigItem->GetCurrentGreeting(eGenderType)],
1140  *xConfigItem);
1141  }
1142  else
1143  {
1144  sGreeting =
1145  xConfigItem->GetGreetings(SwMailMergeConfigItem::NEUTRAL)
1146  [xConfigItem->GetCurrentGreeting(SwMailMergeConfigItem::NEUTRAL)];
1147 
1148  }
1149  sGreeting += "\n";
1150  sBody.insert(0, sGreeting);
1151  }
1152  }
1153  aDesc.sBodyContent = sBody.makeStringAndClear();
1154  if(MM_DOCTYPE_HTML == nDocType)
1155  {
1156  aDesc.sBodyMimeType = "text/html; charset=" +
1157  OUString::createFromAscii(rtl_getBestMimeCharsetFromTextEncoding( eEncoding ));
1158  }
1159  else
1160  aDesc.sBodyMimeType = "text/plain; charset=UTF-8; format=flowed";
1161 
1162  aDesc.sSubject = m_xSubjectED->get_text();
1163  aDesc.sCC = m_sCC;
1164  aDesc.sBCC = m_sBCC;
1165  pDlg->AddDocument( aDesc );
1166  //help to force painting the dialog
1167  Application::Reschedule( true );
1168  //stop creating of data when dialog has been closed
1169  if(!pDlg->IsVisible())
1170  {
1171  break;
1172  }
1173  }
1174  pDlg->EnableDestruction();
1175  ::osl::File::remove( sTargetTempURL );
1176 
1177 }
1178 
1179 /* 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:1697
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:59
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:88
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:203
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:1569
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:2145
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:112
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:3299
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:771
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:1348
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:2167
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