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