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