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