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