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