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_radio_button("fromrb"))
255  , m_xFromNF(m_xBuilder->weld_spin_button("from"))
256  , m_xToFT(m_xBuilder->weld_label("toft"))
257  , m_xToNF(m_xBuilder->weld_spin_button("to"))
258  , m_xOKButton(m_xBuilder->weld_button("ok"))
259 {
260  Link<weld::ToggleButton&,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::ToggleButton&,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::ToggleButton&,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::ToggleButton&, 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::ToggleButton&, 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::ToggleButton&, 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  if (!xConfigItem->GetTargetView())
556 
557  SwView* pTargetView = xConfigItem->GetTargetView();
558  assert(pTargetView);
559 
560  OUString sFilter;
561  OUString sPath = SwMailMergeHelper::CallSaveAsDialog(m_xDialog.get(), sFilter);
562  if (sPath.isEmpty())
563  {
564  // just return back to the dialog
565  return;
566  }
567 
568  if (m_xSaveAsOneRB->get_active())
569  {
570  uno::Sequence< beans::PropertyValue > aValues(1);
571  beans::PropertyValue* pValues = aValues.getArray();
572  pValues[0].Name = "FilterName";
573  pValues[0].Value <<= sFilter;
574 
575  uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
576  ErrCode nErrorCode = ERRCODE_NONE;
577  try
578  {
579  xStore->storeToURL( sPath, aValues );
580  }
581  catch (const task::ErrorCodeIOException& rErrorEx)
582  {
583  nErrorCode = ErrCode(rErrorEx.ErrCode);
584  }
585  catch (const Exception&)
586  {
587  nErrorCode = ERRCODE_IO_GENERAL;
588  }
589  if( nErrorCode != ERRCODE_NONE )
590  {
592  ErrorHandler::HandleError( nErrorCode );
593  }
594  }
595  else
596  {
597  const sal_uInt32 nDocumentCount = xConfigItem->GetMergedDocumentCount();
598  sal_uInt32 nBegin = 0;
599  sal_uInt32 nEnd = nDocumentCount;
600 
601  if (!m_xSaveIndividualRB->get_active())
602  {
603  nBegin = static_cast< sal_Int32 >(m_xFromNF->get_value() - 1);
604  nEnd = static_cast< sal_Int32 >(m_xToNF->get_value());
605  if(nEnd > nDocumentCount)
606  nEnd = nDocumentCount;
607  }
608 
609  OUString sTargetTempURL = URIHelper::SmartRel2Abs(
612  std::shared_ptr<const SfxFilter> pSfxFlt = SwIoSystem::GetFilterOfFormat(
613  FILTER_XML,
614  SwDocShell::Factory().GetFilterContainer() );
615 
616  uno::Sequence< beans::PropertyValue > aValues(1);
617  beans::PropertyValue* pValues = aValues.getArray();
618  pValues[0].Name = "FilterName";
619  pValues[0].Value <<= pSfxFlt->GetFilterName();
620 
621  uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
622  ErrCode nErrorCode = ERRCODE_NONE;
623  try
624  {
625  xStore->storeToURL( sTargetTempURL, aValues );
626  }
627  catch (const task::ErrorCodeIOException& rErrorEx)
628  {
629  nErrorCode = ErrCode(rErrorEx.ErrCode);
630  }
631  catch (const Exception&)
632  {
633  nErrorCode = ERRCODE_IO_GENERAL;
634  }
635  if( nErrorCode != ERRCODE_NONE )
636  {
638  ErrorHandler::HandleError( nErrorCode );
639  }
640 
641  SwView* pSourceView = xConfigItem->GetSourceView();
642  auto xSaveMonitor = std::make_shared<SaveMonitor>(m_xDialog.get());
643  xSaveMonitor->m_xDocName->set_label(pSourceView->GetDocShell()->GetTitle(22));
644  xSaveMonitor->m_xPrinter->set_label( INetURLObject( sPath ).getFSysPath( FSysStyle::Detect ) );
645  m_bCancelSaving = false;
646  weld::DialogController::runAsync(xSaveMonitor, [this, &xSaveMonitor](sal_Int32 nResult){
647  if (nResult == RET_CANCEL)
648  m_bCancelSaving = true;
649  xSaveMonitor.reset();
650  });
651 
652  for(sal_uInt32 nDoc = nBegin; nDoc < nEnd && !m_bCancelSaving; ++nDoc)
653  {
654  INetURLObject aURL(sPath);
655  OUString sExtension = aURL.getExtension();
656  if (sExtension.isEmpty())
657  {
658  sExtension = pSfxFlt->GetWildcard().getGlob().getToken(1, '.');
659  sPath += "." + sExtension;
660  }
661  OUString sStat = SwResId(STR_STATSTR_LETTER) + " " + OUString::number( nDoc );
662  xSaveMonitor->m_xPrintInfo->set_label(sStat);
663 
664  //now extract a document from the target document
665  // the shell will be closed at the end, but it is more safe to use SfxObjectShellLock here
666  SfxObjectShellLock xTempDocShell( new SwDocShell( SfxObjectCreateMode::STANDARD ) );
667  xTempDocShell->DoInitNew();
668  SfxViewFrame* pTempFrame = SfxViewFrame::LoadHiddenDocument( *xTempDocShell, SFX_INTERFACE_NONE );
669  SwView* pTempView = static_cast<SwView*>( pTempFrame->GetViewShell() );
670  pTargetView->GetWrtShell().StartAction();
671  SwgReaderOption aOpt;
672  aOpt.SetTextFormats( true );
673  aOpt.SetFrameFormats( true );
674  aOpt.SetPageDescs( true );
675  aOpt.SetNumRules( true );
676  aOpt.SetMerge( false );
677  pTempView->GetDocShell()->LoadStylesFromFile(
678  sTargetTempURL, aOpt, true );
679  pTempView->GetDocShell()->GetDoc()->ReplaceCompatibilityOptions( *pTargetView->GetDocShell()->GetDoc());
680  pTempView->GetDocShell()->GetDoc()->ReplaceDefaults( *pTargetView->GetDocShell()->GetDoc());
681  pTempView->GetDocShell()->GetDoc()->ReplaceDocumentProperties( *pTargetView->GetDocShell()->GetDoc(), true );
682 
683  pTargetView->GetWrtShell().PastePages(
684  pTempView->GetWrtShell(), documentStartPageNumber(xConfigItem.get(), nDoc, false),
685  documentEndPageNumber(xConfigItem.get(), nDoc, false));
686  pTargetView->GetWrtShell().EndAction();
687  //then save it
688  OUString sOutPath = aURL.GetMainURL(INetURLObject::DecodeMechanism::ToIUri);
689  OUString sCounter = "_" + OUString::number(nDoc + 1);
690  sOutPath = sOutPath.replaceAt( sOutPath.getLength() - sExtension.getLength() - 1, 0, sCounter);
691 
692  while(true)
693  {
694  //time for other slots is needed
696 
697  bool bFailed = false;
698  try
699  {
700  pValues[0].Value <<= sFilter;
701  uno::Reference< frame::XStorable > xTempStore( xTempDocShell->GetModel(), uno::UNO_QUERY);
702  xTempStore->storeToURL( sOutPath, aValues );
703  }
704  catch (const uno::Exception&)
705  {
706  bFailed = true;
707  }
708 
709  if(bFailed)
710  {
711  std::unique_ptr<SwSaveWarningBox_Impl> xWarning(new SwSaveWarningBox_Impl(m_xDialog.get(), sOutPath));
712  if (RET_OK == xWarning->run())
713  sOutPath = xWarning->GetFileName();
714  else
715  {
716  xTempDocShell->DoClose();
717  m_xDialog->response(RET_OK);
718  return;
719  }
720  }
721  else
722  {
723  xTempDocShell->DoClose();
724  m_xDialog->response(RET_OK);
725  break;
726  }
727  }
728  }
729  if (xSaveMonitor)
730  xSaveMonitor->response(RET_OK);
731  ::osl::File::remove( sTargetTempURL );
732  }
733 
734  m_xDialog->response(RET_OK);
735 }
736 
737 IMPL_LINK(SwMMResultPrintDialog, PrinterChangeHdl_Impl, weld::ComboBox&, rBox, void)
738 {
739  SwView* pView = ::GetActiveView();
740  const std::shared_ptr<SwMailMergeConfigItem>& xConfigItem = pView->GetMailMergeConfigItem();
741  assert(xConfigItem);
742  if (rBox.get_active() != -1)
743  {
744  const QueueInfo* pInfo = Printer::GetQueueInfo( rBox.get_active_text(), false );
745 
746  if( pInfo )
747  {
748  if ( !m_pTempPrinter )
749  {
750  m_pTempPrinter = VclPtr<Printer>::Create( *pInfo );
751  }
752  else
753  {
754  if( (m_pTempPrinter->GetName() != pInfo->GetPrinterName()) ||
755  (m_pTempPrinter->GetDriverName() != pInfo->GetDriver()) )
756  {
757  m_pTempPrinter.disposeAndClear();
758  m_pTempPrinter = VclPtr<Printer>::Create( *pInfo );
759  }
760  }
761  }
762  else if( ! m_pTempPrinter )
763  m_pTempPrinter = VclPtr<Printer>::Create();
764 
765  m_xPrinterSettingsPB->set_sensitive(m_pTempPrinter->HasSupport(PrinterSupport::SetupDialog));
766  }
767  else
768  m_xPrinterSettingsPB->set_sensitive(false);
769 
770  xConfigItem->SetSelectedPrinter(rBox.get_active_text());
771 }
772 
774 {
775  SwView* pView = ::GetActiveView();
776  std::shared_ptr<SwMailMergeConfigItem> xConfigItem = pView->GetMailMergeConfigItem();
777  assert(xConfigItem);
778  if(!xConfigItem->GetTargetView())
780 
781  SwView* pTargetView = xConfigItem->GetTargetView();
782  assert(pTargetView);
783 
784  const sal_uInt32 nDocumentCount = xConfigItem->GetMergedDocumentCount();
785  sal_uInt32 nBegin = 0;
786  sal_uInt32 nEnd = nDocumentCount;
787 
788  if (!m_xPrintAllRB->get_active())
789  {
790  nBegin = m_xFromNF->get_value() - 1;
791  nEnd = m_xToNF->get_value();
792  if(nEnd > nDocumentCount)
793  nEnd = nDocumentCount;
794  }
795 
796  // If we skip autoinserted blanks, then the page numbers used in the print range string
797  // refer to the non-blank pages as they appear in the document (see tdf#89708).
798  const bool bIgnoreEmptyPages =
800  const int nStartPage = documentStartPageNumber(xConfigItem.get(), nBegin, bIgnoreEmptyPages);
801  const int nEndPage = documentEndPageNumber(xConfigItem.get(), nEnd - 1, bIgnoreEmptyPages);
802 
803  const OUString sPages(OUString::number(nStartPage) + "-" + OUString::number(nEndPage));
804 
805  pTargetView->SetMailMergeConfigItem(xConfigItem);
806  if(m_pTempPrinter)
807  {
808  SfxPrinter *const pDocumentPrinter = pTargetView->GetWrtShell()
810  pDocumentPrinter->SetPrinterProps(m_pTempPrinter);
811  // this should be able to handle setting its own printer
812  pTargetView->SetPrinter(pDocumentPrinter);
813  }
814 
815  SfxObjectShell* pObjSh = pTargetView->GetViewFrame()->GetObjectShell();
816  SfxGetpApp()->NotifyEvent(SfxEventHint(SfxEventHintId::SwMailMerge, SwDocShell::GetEventName(STR_SW_EVENT_MAIL_MERGE), pObjSh));
817 
818  uno::Sequence < beans::PropertyValue > aProps( 2 );
819  aProps[0]. Name = "MonitorVisible";
820  aProps[0].Value <<= true;
821  aProps[1]. Name = "Pages";
822  aProps[1]. Value <<= sPages;
823 
824  pTargetView->ExecPrint( aProps, false, true );
825  SfxGetpApp()->NotifyEvent(SfxEventHint(SfxEventHintId::SwMailMergeEnd, SwDocShell::GetEventName(STR_SW_EVENT_MAIL_MERGE_END), pObjSh));
826 
827  m_xDialog->response(RET_OK);
828 }
829 
830 IMPL_LINK_NOARG(SwMMResultPrintDialog, PrinterSetupHdl_Impl, weld::Button&, void)
831 {
832  if (m_pTempPrinter)
833  m_pTempPrinter->Setup(m_xDialog.get());
834 }
835 
836 IMPL_LINK(SwMMResultEmailDialog, SendTypeHdl_Impl, weld::ComboBox&, rBox, void)
837 {
838  auto nDocType = rBox.get_active_id().toUInt32();
839  bool bEnable = MM_DOCTYPE_HTML != nDocType && MM_DOCTYPE_TEXT != nDocType;
840  bool bIsPDF = nDocType == MM_DOCTYPE_PDF;
841  m_xSendAsPB->set_sensitive(bEnable);
842  m_xAttachmentGroup->set_sensitive(bEnable);
843  if(bEnable)
844  {
845  //add the correct extension
846  OUString sAttach(m_xAttachmentED->get_text());
847  //do nothing if the user has removed the name - the warning will come early enough
848  if (!sAttach.isEmpty())
849  {
850  sal_Int32 nTokenCount = comphelper::string::getTokenCount(sAttach, '.');
851  if( 2 > nTokenCount)
852  {
853  sAttach += ".";
854  ++nTokenCount;
855  }
856  sAttach = comphelper::string::setToken(sAttach, nTokenCount - 1, '.', lcl_GetExtensionForDocType( nDocType ));
857  m_xAttachmentED->set_text(sAttach);
858  }
859  }
860 
861  if(bIsPDF)
862  {
863  m_xPasswordCB->set_sensitive(true);
864  m_xPasswordFT->set_sensitive(true);
865  m_xPasswordLB->set_sensitive(true);
866  CheckHdl(*m_xPasswordCB);
867  }
868  else
869  {
870  m_xPasswordCB->set_sensitive(false);
871  m_xPasswordFT->set_sensitive(false);
872  m_xPasswordLB->set_sensitive(false);
873  }
874 }
875 
877 {
878  SwMailBodyDialog aDlg(m_xDialog.get());
879  aDlg.SetBody(m_sBody);
880  if (RET_OK == aDlg.run())
881  {
882  m_sBody = aDlg.GetBody();
883  }
884 }
885 
886 // Send documents as e-mail
887 IMPL_LINK_NOARG(SwMMResultEmailDialog, SendDocumentsHdl_Impl, weld::Button&, void)
888 {
889  SwView* pView = ::GetActiveView();
890  std::shared_ptr<SwMailMergeConfigItem> xConfigItem = pView->GetMailMergeConfigItem();
891  assert(xConfigItem);
892  if (!xConfigItem->GetTargetView())
894 
895  //get the composed document
896  SwView* pTargetView = xConfigItem->GetTargetView();
897  SAL_WARN_IF(!pTargetView, "sw.ui", "No TargetView in SwMailMergeConfigItem");
898 
899  if (xConfigItem->GetMailServer().isEmpty() ||
900  !SwMailMergeHelper::CheckMailAddress(xConfigItem->GetMailAddress()) )
901  {
902  std::unique_ptr<weld::MessageDialog> xQueryBox(Application::CreateMessageDialog(m_xDialog.get(),
903  VclMessageType::Question, VclButtonsType::YesNo,
904  m_sConfigureMail));
905  xQueryBox->add_button(GetStandardText(StandardButtonType::Cancel), RET_CANCEL);
906  sal_uInt16 nRet = xQueryBox->run();
907  if (RET_YES == nRet )
908  {
909  SwView* pConfigView = pTargetView ? pTargetView : pView;
910  SfxAllItemSet aSet(pConfigView->GetPool());
911  SwMailConfigDlg aDlg(m_xDialog.get(), aSet);
912  nRet = aDlg.run();
913  }
914 
915  if(nRet != RET_OK && nRet != RET_YES)
916  return; // back to the dialog
917 
918  // SwMailConfigDlg writes mail merge email settings only to (global) config,
919  // so copy them to the existing config item
921  }
922  //add the documents
923  const sal_uInt32 nDocumentCount = xConfigItem->GetMergedDocumentCount();
924  sal_uInt32 nBegin = 0;
925  sal_uInt32 nEnd = nDocumentCount;
926  if (!m_xSendAllRB->get_active())
927  {
928  nBegin = static_cast< sal_Int32 >(m_xFromNF->get_value() - 1);
929  nEnd = static_cast< sal_Int32 >(m_xToNF->get_value());
930  if(nEnd > nDocumentCount)
931  nEnd = nDocumentCount;
932  }
933  bool bAsBody = false;
934  rtl_TextEncoding eEncoding = ::osl_getThreadTextEncoding();
935  SfxFilterContainer* pFilterContainer = SwDocShell::Factory().GetFilterContainer();
936  std::shared_ptr<const SfxFilter> pSfxFlt;
937  auto nDocType = m_xSendAsLB->get_active_id().toUInt32();
938  OUString sExtension = lcl_GetExtensionForDocType(nDocType);
939  switch( nDocType )
940  {
941  case MM_DOCTYPE_OOO:
942  {
943  //Make sure we don't pick e.g. the flat xml filter
944  //for this format
945  pSfxFlt = pFilterContainer->GetFilter4FilterName(
946  "writer8",
947  SfxFilterFlags::EXPORT);
948  }
949  break;
950  case MM_DOCTYPE_PDF:
951  {
952  pSfxFlt = pFilterContainer->GetFilter4FilterName(
953  "writer_pdf_Export",
954  SfxFilterFlags::EXPORT);
955  }
956  break;
957  case MM_DOCTYPE_WORD:
958  {
959  //the method SwIOSystemGetFilterOfFormat( ) returns the template filter
960  //because it uses the same user data :-(
961  SfxFilterMatcher aMatcher( pFilterContainer->GetName() );
962  SfxFilterMatcherIter aIter( aMatcher );
963  std::shared_ptr<const SfxFilter> pFilter = aIter.First();
964  while ( pFilter )
965  {
966  if( pFilter->GetUserData() == FILTER_WW8 && pFilter->CanExport() )
967  {
968  pSfxFlt = pFilter;
969  break;
970  }
971  pFilter = aIter.Next();
972  }
973 
974  }
975  break;
976  case MM_DOCTYPE_HTML:
977  {
978  bAsBody = true;
979  SvxHtmlOptions& rHtmlOptions = SvxHtmlOptions::Get();
980  eEncoding = rHtmlOptions.GetTextEncoding();
981  }
982  break;
983  case MM_DOCTYPE_TEXT:
984  {
985  bAsBody = true;
986  pSfxFlt = pFilterContainer->GetFilter4FilterName(
987  "Text (encoded)", SfxFilterFlags::EXPORT);
988  }
989  break;
990  }
991  if(!pSfxFlt)
992  pSfxFlt = pFilterContainer->GetFilter4Extension(sExtension, SfxFilterFlags::EXPORT);
993 
994  if(!pSfxFlt)
995  {
996  m_xDialog->response(RET_OK);
997  return;
998  }
999  OUString sMimeType = pSfxFlt->GetMimeType();
1000 
1001  if (m_xSubjectED->get_text().isEmpty())
1002  {
1003  std::unique_ptr<SwSendQueryBox_Impl> xQuery(new SwSendQueryBox_Impl(m_xDialog.get(), "SubjectDialog",
1004  "modules/swriter/ui/subjectdialog.ui"));
1005  xQuery->SetIsEmptyTextAllowed(true);
1006  xQuery->SetValue("");
1007  if(RET_OK == xQuery->run())
1008  {
1009  if (!xQuery->GetValue().isEmpty())
1010  m_xSubjectED->set_text(xQuery->GetValue());
1011  }
1012  else
1013  return; // back to the dialog
1014  }
1015  if(!bAsBody && m_xAttachmentED->get_text().isEmpty())
1016  {
1017  std::unique_ptr<SwSendQueryBox_Impl> xQuery(new SwSendQueryBox_Impl(m_xDialog.get(), "AttachNameDialog",
1018  "modules/swriter/ui/attachnamedialog.ui"));
1019  xQuery->SetIsEmptyTextAllowed(false);
1020  if (RET_OK == xQuery->run())
1021  {
1022  OUString sAttach(xQuery->GetValue());
1023  sal_Int32 nTokenCount = comphelper::string::getTokenCount(sAttach, '.');
1024  if (2 > nTokenCount)
1025  {
1026  sAttach += ".";
1027  ++nTokenCount;
1028  }
1029  sAttach = comphelper::string::setToken(sAttach, nTokenCount - 1, '.', lcl_GetExtensionForDocType(
1030  m_xSendAsLB->get_active_id().toUInt32()));
1031  m_xAttachmentED->set_text(sAttach);
1032  }
1033  else
1034  return; // back to the dialog
1035  }
1036 
1037  OUString sEMailColumn = m_xMailToLB->get_active_text();
1038  OSL_ENSURE( !sEMailColumn.isEmpty(), "No email column selected");
1039  Reference< sdbcx::XColumnsSupplier > xColsSupp( xConfigItem->GetResultSet(), UNO_QUERY);
1040  Reference < container::XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : nullptr;
1041  if(sEMailColumn.isEmpty() || !xColAccess.is() || !xColAccess->hasByName(sEMailColumn))
1042  {
1043  m_xDialog->response(RET_OK);
1044  return;
1045  }
1046 
1047  OUString sPasswordColumn = m_xPasswordLB->get_active_text();
1048  OSL_ENSURE( !sPasswordColumn.isEmpty(), "No password column selected");
1049  if(sPasswordColumn.isEmpty() || !xColAccess.is() || !xColAccess->hasByName(sPasswordColumn))
1050  {
1051  m_xDialog->response(RET_OK);
1052  return;
1053  }
1054 
1055  OUString sFilterOptions;
1056  if(MM_DOCTYPE_TEXT == nDocType)
1057  {
1058  SwAsciiOptions aOpt;
1059  sal_uInt16 nAppScriptType = SvtLanguageOptions::GetI18NScriptTypeOfLanguage( GetAppLanguage() );
1060  sal_uInt16 nWhich = GetWhichOfScript( RES_CHRATR_LANGUAGE, nAppScriptType);
1061  aOpt.SetLanguage( static_cast<const SvxLanguageItem&>(pTargetView->GetWrtShell().
1062  GetDefault( nWhich )).GetLanguage());
1063  aOpt.SetParaFlags( LINEEND_CR );
1064  aOpt.WriteUserData( sFilterOptions );
1065  }
1066  else if(MM_DOCTYPE_HTML == nDocType)
1067  {
1068  sFilterOptions = "EmbedImages";
1069  }
1070  OUString sTargetTempURL = URIHelper::SmartRel2Abs(
1073  std::shared_ptr<const SfxFilter> pTargetSfxFlt = SwIoSystem::GetFilterOfFormat(
1074  FILTER_XML,
1075  SwDocShell::Factory().GetFilterContainer() );
1076 
1077  uno::Sequence< beans::PropertyValue > aValues(1);
1078  beans::PropertyValue* pValues = aValues.getArray();
1079  pValues[0].Name = "FilterName";
1080  pValues[0].Value <<= pTargetSfxFlt->GetFilterName();
1081 
1082  uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
1083  xStore->storeToURL( sTargetTempURL, aValues );
1084 
1085  //create the send dialog
1087  std::shared_ptr<SwSendMailDialog> xDlg = std::make_shared<SwSendMailDialog>(pParent ? pParent->GetFrameWeld() : nullptr, *xConfigItem);
1088 
1089  xDlg->StartSend(nEnd - nBegin);
1090  weld::DialogController::runAsync(xDlg, [](sal_Int32 /*nResult*/){});
1091 
1092  //help to force painting the dialog
1093  //TODO/CLEANUP
1094  //predetermined breaking point
1095  Application::Reschedule( true );
1096  m_xDialog->response(RET_OK);
1097  for(sal_uInt32 nDoc = nBegin; nDoc < nEnd; ++nDoc)
1098  {
1099  SwDocMergeInfo& rInfo = xConfigItem->GetDocumentMergeInfo(nDoc);
1100 
1101  //now extract a document from the target document
1102  // the shell will be closed at the end, but it is more safe to use SfxObjectShellLock here
1103  SfxObjectShellLock xTempDocShell( new SwDocShell( SfxObjectCreateMode::STANDARD ) );
1104  xTempDocShell->DoInitNew();
1105  SfxViewFrame* pTempFrame = SfxViewFrame::LoadHiddenDocument( *xTempDocShell, SFX_INTERFACE_NONE );
1106  SwView* pTempView = static_cast<SwView*>( pTempFrame->GetViewShell() );
1107  pTargetView->GetWrtShell().StartAction();
1108  SwgReaderOption aOpt;
1109  aOpt.SetTextFormats( true );
1110  aOpt.SetFrameFormats( true );
1111  aOpt.SetPageDescs( true );
1112  aOpt.SetNumRules( true );
1113  aOpt.SetMerge( false );
1114  pTempView->GetDocShell()->LoadStylesFromFile(
1115  sTargetTempURL, aOpt, true );
1116  pTempView->GetDocShell()->GetDoc()->ReplaceCompatibilityOptions( *pTargetView->GetDocShell()->GetDoc());
1117  pTempView->GetDocShell()->GetDoc()->ReplaceDefaults( *pTargetView->GetDocShell()->GetDoc());
1118  pTempView->GetDocShell()->GetDoc()->ReplaceDocumentProperties( *pTargetView->GetDocShell()->GetDoc(), true );
1119  pTargetView->GetWrtShell().PastePages(
1120  pTempView->GetWrtShell(), documentStartPageNumber(xConfigItem.get(), nDoc, false),
1121  documentEndPageNumber(xConfigItem.get(), nDoc, false));
1122  pTargetView->GetWrtShell().EndAction();
1123 
1124  //then save it
1125  SfxStringItem aName(SID_FILE_NAME,
1129 
1130  {
1131  bool withFilterOptions = MM_DOCTYPE_TEXT == nDocType || MM_DOCTYPE_HTML == nDocType;
1132  bool withPasswordOptions = m_xPasswordCB->get_active();
1133 
1134  sal_Int32 nTarget = xConfigItem->MoveResultSet(rInfo.nDBRow);
1135  OSL_ENSURE( nTarget == rInfo.nDBRow, "row of current document could not be selected");
1136  OUString sPassword = lcl_GetColumnValueOf(sPasswordColumn, xColAccess);
1137 
1138  sal_Int32 nOptionCount = (withFilterOptions && withPasswordOptions) ? 4 : withPasswordOptions ? 3 : withFilterOptions ? 2 : 1;
1139  sal_Int32 nOpt = 0;
1140  uno::Sequence< beans::PropertyValue > aFilterValues(nOptionCount);
1141  beans::PropertyValue* pFilterValues = aFilterValues.getArray();
1142 
1143  pFilterValues[nOpt].Name = "FilterName";
1144  pFilterValues[nOpt].Value <<= pSfxFlt->GetFilterName();
1145 
1146  if(withFilterOptions)
1147  {
1148  nOpt++;
1149  pFilterValues[nOpt].Name = "FilterOptions";
1150  pFilterValues[nOpt].Value <<= sFilterOptions;
1151  }
1152 
1153  if(withPasswordOptions)
1154  {
1155  nOpt++;
1156  pFilterValues[nOpt].Name = "EncryptFile";
1157  pFilterValues[nOpt].Value <<= true;
1158  nOpt++;
1159  pFilterValues[nOpt].Name = "DocumentOpenPassword";
1160  pFilterValues[nOpt].Value <<= sPassword;
1161  }
1162 
1163  uno::Reference< frame::XStorable > xTempStore( pTempView->GetDocShell()->GetModel(), uno::UNO_QUERY);
1164  xTempStore->storeToURL( aName.GetValue(), aFilterValues );
1165  }
1166  xTempDocShell->DoClose();
1167 
1168  sal_Int32 nTarget = xConfigItem->MoveResultSet(rInfo.nDBRow);
1169  OSL_ENSURE( nTarget == rInfo.nDBRow, "row of current document could not be selected");
1170  OSL_ENSURE( !sEMailColumn.isEmpty(), "No email column selected");
1171  OUString sEMail = lcl_GetColumnValueOf(sEMailColumn, xColAccess);
1172  SwMailDescriptor aDesc;
1173  aDesc.sEMail = sEMail;
1174  OUStringBuffer sBody;
1175  if(bAsBody)
1176  {
1177  {
1178  //read in the temporary file and use it as mail body
1179  SfxMedium aMedium( aName.GetValue(), StreamMode::READ);
1180  SvStream* pInStream = aMedium.GetInStream();
1181  if(pInStream)
1182  pInStream->SetStreamCharSet( eEncoding );
1183  else
1184  {
1185  OSL_FAIL("no output file created?");
1186  continue;
1187  }
1188  OString sLine;
1189  bool bDone = pInStream->ReadLine( sLine );
1190  while ( bDone )
1191  {
1192  sBody.append( OStringToOUString(sLine, eEncoding) );
1193  sBody.append("\n");
1194  bDone = pInStream->ReadLine( sLine );
1195  }
1196  }
1197  //remove the temporary file
1199  }
1200  else
1201  {
1202  sBody = m_sBody;
1203  aDesc.sAttachmentURL = aName.GetValue();
1204  OUString sAttachment(m_xAttachmentED->get_text());
1205  sal_Int32 nTokenCount = comphelper::string::getTokenCount(sAttachment, '.');
1206  if (2 > nTokenCount)
1207  {
1208  sAttachment += ".";
1209  sAttachment = comphelper::string::setToken(sAttachment, nTokenCount, '.', sExtension);
1210  }
1211  else if (sAttachment.getToken( nTokenCount - 1, '.') != sExtension)
1212  sAttachment += sExtension;
1213  aDesc.sAttachmentName = sAttachment;
1214  aDesc.sMimeType = sMimeType;
1215 
1216  if (xConfigItem->IsGreetingLine(true))
1217  {
1218  OUString sNameColumn = xConfigItem->GetAssignedColumn(MM_PART_LASTNAME);
1219  OUString sName = lcl_GetColumnValueOf(sNameColumn, xColAccess);
1220  OUString sGreeting;
1221  if(!sName.isEmpty() && xConfigItem->IsIndividualGreeting(true))
1222  {
1223  OUString sGenderColumn = xConfigItem->GetAssignedColumn(MM_PART_GENDER);
1224  const OUString& sFemaleValue = xConfigItem->GetFemaleGenderValue();
1225  OUString sGenderValue = lcl_GetColumnValueOf(sGenderColumn, xColAccess);
1226  SwMailMergeConfigItem::Gender eGenderType = sGenderValue == sFemaleValue ?
1229 
1230  sGreeting = SwAddressPreview::FillData(
1231  xConfigItem->GetGreetings(eGenderType)
1232  [xConfigItem->GetCurrentGreeting(eGenderType)],
1233  *xConfigItem);
1234  }
1235  else
1236  {
1237  sGreeting =
1238  xConfigItem->GetGreetings(SwMailMergeConfigItem::NEUTRAL)
1239  [xConfigItem->GetCurrentGreeting(SwMailMergeConfigItem::NEUTRAL)];
1240 
1241  }
1242  sGreeting += "\n";
1243  sBody.insert(0, sGreeting);
1244  }
1245  }
1246  aDesc.sBodyContent = sBody.makeStringAndClear();
1247  if(MM_DOCTYPE_HTML == nDocType)
1248  {
1249  aDesc.sBodyMimeType = "text/html; charset=" +
1250  OUString::createFromAscii(rtl_getBestMimeCharsetFromTextEncoding( eEncoding ));
1251  }
1252  else
1253  aDesc.sBodyMimeType = "text/plain; charset=UTF-8; format=flowed";
1254 
1255  aDesc.sSubject = m_xSubjectED->get_text();
1256  aDesc.sCC = m_sCC;
1257  aDesc.sBCC = m_sBCC;
1258  xDlg->AddDocument( aDesc );
1259  //help to force painting the dialog
1260  Application::Reschedule( true );
1261  //stop creating of data when dialog has been closed
1262  if (!xDlg->getDialog()->get_visible())
1263  {
1264  break;
1265  }
1266  }
1267  xDlg->EnableDestruction();
1268  ::osl::File::remove( sTargetTempURL );
1269 }
1270 
1271 /* 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
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:1091
bool SttEndDoc(bool bStt)
Definition: crsrsh.cxx:572
OUString const & GetMailAddress() const
void SetMailDisplayName(const OUString &rName)
void SetPageDescs(const bool bNew)
Definition: shellio.hxx:118
std::shared_ptr< SwMailMergeConfigItem > const & GetMailMergeConfigItem() const
Definition: view0.cxx:128
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
static vcl::Window * GetDefDialogParent()
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:399
bool Pop(SwCursorShell::PopMode=SwCursorShell::PopMode::DeleteStack)
Definition: wrtsh1.cxx:1718
std::unique_ptr< weld::SpinButton > m_xToNF
bool EndPrvPg(bool bSelect=false)
Definition: move.cxx:334
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:1207
void SetMailReplyTo(bool bSet)
void ReplaceCompatibilityOptions(const SwDoc &rSource)
Definition: docnew.cxx:872
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
void SetParaFlags(LineEnd eVal)
Definition: shellio.hxx:78
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:398
SfxApplication * SfxGetpApp()
void SetTextFormats(const bool bNew)
Definition: shellio.hxx:121
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:75
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:840
#define MM_DOCTYPE_WORD
SwMMResultEmailDialog(weld::Window *pParent)
const BorderLinePrimitive2D *pCandidateB assert(pCandidateA)
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:2586
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
int i
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:239
SVL_DLLPUBLIC Link< OUString *, bool > const & GetMaybeFileHdl()
void Push()
store a copy of the current cursor on the cursor stack
Definition: crsrsh.cxx:2236
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:1227
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:165
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:96
SwDocShell * GetDocShell()
Definition: view.cxx:1108
virtual OUString get_text() const =0
#define FILTER_WW8
WinWord 97 filter.
Definition: iodetect.hxx:33
void WriteUserData(OUString &)
Definition: fltini.cxx:571
constexpr T & temporary(T &&x)
static const std::vector< OUString > & GetPrinterQueues()
std::unique_ptr< weld::ComboBox > m_xSendAsLB
void StartAction()
Definition: crsrsh.cxx:222
OUString const & GetMailDisplayName() const
ErrCode LoadStylesFromFile(const OUString &rURL, SwgReaderOption &rOpt, bool bUnoCall)
Definition: docsh2.cxx:1549
OUString GetMainURL(DecodeMechanism eMechanism, rtl_TextEncoding eCharset=RTL_TEXTENCODING_UTF8) const
static std::shared_ptr< SwMailMergeConfigItem > PerformMailMerge(SwView const *pView)
Definition: dbmgr.cxx:3205
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
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: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:728
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:1314
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
bool Pop(PopMode)
delete cursor
Definition: crsrsh.cxx:2258
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:115
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:127
void SetNumRules(const bool bNew)
Definition: shellio.hxx:124
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