Line data Source code
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 <mmoutputpage.hxx>
21 : #include <mailmergewizard.hxx>
22 : #include <mmconfigitem.hxx>
23 : #include <mailmergechildwindow.hxx>
24 : #include <mailconfigpage.hxx>
25 : #include <cmdid.h>
26 : #include <swtypes.hxx>
27 : #include <view.hxx>
28 : #include <wrtsh.hxx>
29 : #include <docsh.hxx>
30 : #include <IDocumentDeviceAccess.hxx>
31 : #include <hintids.hxx>
32 : #include <editeng/scripttypeitem.hxx>
33 : #include <editeng/langitem.hxx>
34 : #include <svl/itemset.hxx>
35 : #include <svl/stritem.hxx>
36 : #include <svtools/ehdl.hxx>
37 : #include <svtools/sfxecode.hxx>
38 : #include <vcl/msgbox.hxx>
39 : #include <sfx2/dinfdlg.hxx>
40 : #include <sfx2/printer.hxx>
41 : #include <sfx2/fcontnr.hxx>
42 : #include <sfx2/viewfrm.hxx>
43 : #include <sfx2/dispatch.hxx>
44 : #include <sfx2/docfile.hxx>
45 : #include <tools/urlobj.hxx>
46 : #include <svl/urihelper.hxx>
47 : #include <vcl/print.hxx>
48 : #include <unotools/tempfile.hxx>
49 : #include <osl/file.hxx>
50 : #include <mmgreetingspage.hxx>
51 : #include <com/sun/star/frame/XStorable.hpp>
52 : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
53 : #include <com/sun/star/sdb/XColumn.hpp>
54 : #include <dbmgr.hxx>
55 : #include <swunohelper.hxx>
56 : #include <osl/mutex.hxx>
57 : #include <shellio.hxx>
58 : #include <svtools/htmlcfg.hxx>
59 : #include <sfx2/event.hxx>
60 : #include <swevent.hxx>
61 : #include <mmoutputpage.hrc>
62 : #include <dbui.hxx>
63 : #include <dbui.hrc>
64 : #include <helpid.h>
65 : #include <sfx2/app.hxx>
66 : #include <statstr.hrc>
67 : #include <unomid.h>
68 : #include <comphelper/string.hxx>
69 :
70 : using namespace svt;
71 : using namespace ::com::sun::star;
72 : using namespace ::com::sun::star::uno;
73 :
74 0 : static String lcl_GetExtensionForDocType(sal_uLong nDocType)
75 : {
76 0 : rtl::OUString sExtension;
77 0 : switch( nDocType )
78 : {
79 0 : case MM_DOCTYPE_OOO : sExtension = rtl::OUString( "odt" ); break;
80 0 : case MM_DOCTYPE_PDF : sExtension = rtl::OUString( "pdf" ); break;
81 0 : case MM_DOCTYPE_WORD: sExtension = rtl::OUString( "doc" ); break;
82 0 : case MM_DOCTYPE_HTML: sExtension = rtl::OUString( "html" ); break;
83 0 : case MM_DOCTYPE_TEXT: sExtension = rtl::OUString( "txt" ); break;
84 : }
85 0 : return sExtension;
86 : }
87 :
88 0 : static ::rtl::OUString lcl_GetColumnValueOf(const ::rtl::OUString& rColumn, Reference < container::XNameAccess>& rxColAccess )
89 : {
90 0 : ::rtl::OUString sRet;
91 : try
92 : {
93 0 : if (rxColAccess->hasByName(rColumn))
94 : {
95 0 : Any aCol = rxColAccess->getByName(rColumn);
96 0 : Reference< sdb::XColumn > xColumn;
97 0 : aCol >>= xColumn;
98 0 : if(xColumn.is())
99 0 : sRet = xColumn->getString();
100 : }
101 : }
102 0 : catch (const uno::Exception&)
103 : {
104 : }
105 0 : return sRet;
106 : }
107 :
108 : class SwSaveWarningBox_Impl : public ModalDialog
109 : {
110 : FixedImage aWarningImageIM;
111 : FixedInfo aWarningFI;
112 :
113 : FixedText aFileNameFT;
114 : Edit aFileNameED;
115 :
116 : FixedLine aSeparatorFL;
117 : OKButton aOKPB;
118 : CancelButton aCancelPB;
119 :
120 : DECL_LINK( ModifyHdl, Edit*);
121 : public:
122 : SwSaveWarningBox_Impl(Window* pParent, const String& rFileName);
123 : ~SwSaveWarningBox_Impl();
124 :
125 0 : String GetFileName() const {return aFileNameED.GetText();}
126 : };
127 :
128 : class SwSendQueryBox_Impl : public ModalDialog
129 : {
130 : FixedImage aQueryImageIM;
131 : FixedInfo aQueryFI;
132 :
133 : Edit aTextED;
134 :
135 : FixedLine aSeparatorFL;
136 : OKButton aOKPB;
137 : CancelButton aCancelPB;
138 :
139 : bool bIsEmptyAllowed;
140 : DECL_LINK( ModifyHdl, Edit*);
141 : public:
142 : SwSendQueryBox_Impl(Window* pParent, const String& rQueryText);
143 : ~SwSendQueryBox_Impl();
144 :
145 0 : void SetValue(const String& rSet)
146 : {
147 0 : aTextED.SetText(rSet);
148 0 : ModifyHdl( &aTextED );
149 0 : }
150 0 : String GetValue() const {return aTextED.GetText();}
151 :
152 0 : void SetIsEmptyTextAllowed(bool bSet)
153 : {
154 0 : bIsEmptyAllowed = bSet;
155 0 : ModifyHdl( &aTextED );
156 0 : }
157 : };
158 :
159 0 : SwSaveWarningBox_Impl::SwSaveWarningBox_Impl(Window* pParent, const String& rFileName) :
160 : ModalDialog(pParent, SW_RES( DLG_MM_SAVEWARNING )),
161 : aWarningImageIM(this, SW_RES( IM_WARNING )),
162 : aWarningFI(this, SW_RES( FI_WARNING )),
163 : aFileNameFT(this, SW_RES( FT_FILENAME )),
164 : aFileNameED(this, SW_RES( ED_FILENAME )),
165 : aSeparatorFL(this, SW_RES( FL_SEPARATOR )),
166 : aOKPB(this, SW_RES( PB_OK )),
167 0 : aCancelPB(this, SW_RES( PB_CANCEL ))
168 : {
169 0 : FreeResource();
170 0 : aWarningImageIM.SetImage(WarningBox::GetStandardImage());
171 0 : aFileNameED.SetText(rFileName);
172 0 : aFileNameED.SetModifyHdl(LINK(this, SwSaveWarningBox_Impl, ModifyHdl));
173 0 : ModifyHdl( &aFileNameED );
174 0 : }
175 :
176 0 : SwSaveWarningBox_Impl::~SwSaveWarningBox_Impl()
177 : {
178 0 : }
179 :
180 0 : IMPL_LINK( SwSaveWarningBox_Impl, ModifyHdl, Edit*, pEdit)
181 : {
182 0 : aOKPB.Enable(pEdit->GetText().Len() > 0);
183 0 : return 0;
184 : }
185 :
186 0 : SwSendQueryBox_Impl::SwSendQueryBox_Impl(Window* pParent, const String& rText) :
187 : ModalDialog(pParent, SW_RES( DLG_MM_QUERY )),
188 : aQueryImageIM( this, SW_RES( IM_QUERY )),
189 : aQueryFI( this, SW_RES( FI_QUERY )),
190 : aTextED( this, SW_RES( ED_TEXT )),
191 : aSeparatorFL(this, SW_RES( FL_SEPARATOR )),
192 : aOKPB(this, SW_RES( PB_OK )),
193 : aCancelPB(this, SW_RES( PB_CANCEL )),
194 0 : bIsEmptyAllowed(true)
195 : {
196 0 : FreeResource();
197 0 : aQueryFI.SetText(rText);
198 0 : aQueryImageIM.SetImage(QueryBox::GetStandardImage());
199 0 : aTextED.SetModifyHdl(LINK(this, SwSendQueryBox_Impl, ModifyHdl));
200 0 : ModifyHdl( &aTextED );
201 0 : }
202 :
203 0 : SwSendQueryBox_Impl::~SwSendQueryBox_Impl()
204 : {
205 0 : }
206 :
207 0 : IMPL_LINK( SwSendQueryBox_Impl, ModifyHdl, Edit*, pEdit)
208 : {
209 0 : aOKPB.Enable(bIsEmptyAllowed || (pEdit->GetText().Len() > 0));
210 0 : return 0;
211 : }
212 :
213 : class SwCopyToDialog : public SfxModalDialog
214 : {
215 : FixedInfo m_aDescriptionFI;
216 : FixedText m_aCCFT;
217 : Edit m_aCCED;
218 : FixedText m_aBCCFT;
219 : Edit m_aBCCED;
220 :
221 : FixedInfo m_aNoteFI;
222 : FixedLine m_aSeparatorFL;
223 :
224 : OKButton m_aOK;
225 : CancelButton m_aCancel;
226 : HelpButton m_aHelp;
227 :
228 : public:
229 : SwCopyToDialog(Window* pParent);
230 : ~SwCopyToDialog();
231 :
232 0 : String GetCC() {return m_aCCED.GetText();}
233 0 : void SetCC(const String& rSet) {m_aCCED.SetText(rSet);}
234 :
235 0 : String GetBCC() {return m_aBCCED.GetText();}
236 0 : void SetBCC(const String& rSet) {m_aBCCED.SetText(rSet);}
237 : };
238 :
239 0 : SwCopyToDialog::SwCopyToDialog(Window* pParent) :
240 : SfxModalDialog(pParent, SW_RES(DLG_MM_COPYTO)),
241 : #ifdef MSC
242 : #pragma warning (disable : 4355)
243 : #endif
244 : m_aDescriptionFI( this, SW_RES( FI_DESCRIPTION )),
245 : m_aCCFT( this, SW_RES( FT_CC )),
246 : m_aCCED( this, SW_RES( ED_CC )),
247 : m_aBCCFT( this, SW_RES( FT_BCC )),
248 : m_aBCCED( this, SW_RES( ED_BCC )),
249 : m_aNoteFI( this, SW_RES( FI_NOTE )),
250 : m_aSeparatorFL( this, SW_RES( FL_SEPARATOR )),
251 : m_aOK( this, SW_RES( PB_OK )),
252 : m_aCancel( this, SW_RES( PB_CANCEL )),
253 0 : m_aHelp( this, SW_RES( PB_HELP ))
254 : #ifdef MSC
255 : #pragma warning (default : 4355)
256 : #endif
257 : {
258 0 : FreeResource();
259 0 : }
260 :
261 0 : SwCopyToDialog::~SwCopyToDialog()
262 : {
263 0 : }
264 :
265 0 : SwMailMergeOutputPage::SwMailMergeOutputPage( SwMailMergeWizard* _pParent) :
266 : svt::OWizardPage( _pParent, SW_RES(DLG_MM_OUTPUT_PAGE)),
267 : #ifdef MSC
268 : #pragma warning (disable : 4355)
269 : #endif
270 : m_aHeaderFI(this, SW_RES( FI_HEADER ) ),
271 : m_aOptionsFI(this, SW_RES( FI_OPTIONS ) ),
272 : m_aSaveStartDocRB(this, SW_RES( RB_SAVESTARTDOC ) ),
273 : m_aSaveMergedDocRB(this, SW_RES( RB_SAVEMERGEDDOC ) ),
274 : m_aPrintRB(this, SW_RES( RB_PRINT ) ),
275 : m_aSendMailRB(this, SW_RES( RB_SENDMAIL ) ),
276 :
277 : m_aSeparatorFL(this, SW_RES( FL_SEPARATOR ) ),
278 :
279 : m_aSaveStartDocPB(this, SW_RES( PB_SAVESTARTDOC ) ),
280 :
281 : m_aSaveAsOneRB(this, SW_RES( RB_SAVEASONE ) ),
282 : m_aSaveIndividualRB(this, SW_RES( RB_SAVEINDIVIDUAL ) ),
283 : m_aPrintAllRB(this, SW_RES( RB_PRINTALL ) ),
284 : m_aSendAllRB( this, SW_RES( RB_SENDALL ) ),
285 :
286 : m_aFromRB(this, SW_RES( RB_FROM ) ),
287 : m_aFromNF(this, SW_RES( NF_FROM ) ),
288 : m_aToFT(this, SW_RES( FT_TO ) ),
289 : m_aToNF(this, SW_RES( NF_TO ) ),
290 : m_aSaveNowPB(this, SW_RES( PB_SAVENOW ) ),
291 :
292 : m_aPrinterFT(this, SW_RES( FT_PRINT ) ),
293 : m_aPrinterLB(this, SW_RES( LB_PRINT ) ),
294 : m_aPrinterSettingsPB(this, SW_RES( PB_PRINTERSETTINGS ) ),
295 : m_aPrintNowPB(this, SW_RES( PB_PRINTNOW ) ),
296 :
297 : m_aMailToFT( this, SW_RES( FT_MAILTO ) ),
298 : m_aMailToLB( this, SW_RES( LB_MAILTO ) ),
299 : m_aCopyToPB( this, SW_RES( PB_COPYTO ) ),
300 : m_aSubjectFT( this, SW_RES( FT_SUBJECT ) ),
301 : m_aSubjectED( this, SW_RES( ED_SUBJECT ) ),
302 : m_aSendAsFT( this, SW_RES( FT_SENDAS ) ),
303 : m_aSendAsLB( this, SW_RES( LB_SENDAS ) ),
304 : m_aAttachmentFT( this, SW_RES( FT_ATTACHMENT ) ),
305 : m_aAttachmentED( this, SW_RES( ED_ATTACHMENT ) ),
306 : m_aSendAsPB( this, SW_RES( PB_SENDAS ) ),
307 : m_aSendDocumentsPB( this, SW_RES( PB_SENDDOCUMENTS ) ),
308 :
309 : m_sSaveStartST(SW_RES( ST_SAVESTART ) ),
310 : m_sSaveMergedST(SW_RES( ST_SAVEMERGED ) ),
311 : m_sPrintST(SW_RES( ST_PRINT ) ),
312 : m_sSendMailST(SW_RES( ST_SENDMAIL ) ),
313 :
314 : m_sDefaultAttachmentST(SW_RES( ST_DEFAULTATTACHMENT )),
315 : m_sNoSubjectQueryST(SW_RES( ST_SUBJECTQUERY )),
316 : m_sNoSubjectST(SW_RES( ST_NOSUBJECT )),
317 : m_sNoAttachmentNameST(SW_RES( ST_NOATTACHMENTNAME )),
318 : m_sConfigureMail(SW_RES( ST_CONFIGUREMAIL)),
319 : #ifdef MSC
320 : #pragma warning (default : 4355)
321 : #endif
322 : m_bCancelSaving( false ),
323 : m_pWizard(_pParent),
324 0 : m_pTempPrinter( 0 )
325 : {
326 0 : FreeResource();
327 :
328 0 : SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
329 : // #i51949# hide e-Mail option if e-Mail is not supported
330 0 : if(!rConfigItem.IsMailAvailable())
331 0 : m_aSendMailRB.Hide();
332 :
333 0 : Link aLink = LINK(this, SwMailMergeOutputPage, OutputTypeHdl_Impl);
334 0 : m_aSaveStartDocRB.SetClickHdl(aLink);
335 0 : m_aSaveMergedDocRB.SetClickHdl(aLink);
336 0 : m_aPrintRB.SetClickHdl(aLink);
337 0 : m_aSendMailRB.SetClickHdl(aLink);
338 0 : m_aSaveStartDocRB.Check();
339 0 : m_aPrintAllRB.Check();
340 0 : m_aSaveAsOneRB.Check();
341 0 : m_aSendAllRB.Check();
342 :
343 0 : m_aSaveStartDocPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, SaveStartHdl_Impl));
344 0 : m_aSaveNowPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, SaveOutputHdl_Impl));
345 0 : m_aPrinterLB.SetSelectHdl(LINK(this, SwMailMergeOutputPage, PrinterChangeHdl_Impl));
346 0 : m_aPrintNowPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, PrintHdl_Impl));
347 0 : m_aPrinterSettingsPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, PrinterSetupHdl_Impl));
348 :
349 0 : m_aSendAsPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, SendAsHdl_Impl)),
350 0 : m_aSendDocumentsPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, SendDocumentsHdl_Impl)),
351 0 : m_aSendAsLB.SetSelectHdl(LINK(this, SwMailMergeOutputPage, SendTypeHdl_Impl));
352 :
353 0 : m_nFromToRBPos = m_aFromRB.GetPosPixel().Y();
354 0 : m_nFromToFTPos = m_aToFT.GetPosPixel().Y();
355 0 : m_nFromToNFPos = m_aFromNF.GetPosPixel().Y();
356 :
357 0 : m_nRBOffset = m_nFromToRBPos - m_aSaveIndividualRB.GetPosPixel().Y();
358 :
359 0 : OutputTypeHdl_Impl(&m_aSaveStartDocRB);
360 :
361 0 : m_aCopyToPB.SetClickHdl(LINK(this, SwMailMergeOutputPage, CopyToHdl_Impl));
362 :
363 0 : m_aSaveAsOneRB.SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
364 0 : m_aSaveIndividualRB.SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
365 0 : m_aPrintAllRB.SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
366 0 : m_aSendAllRB.SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
367 :
368 0 : m_aFromRB.SetClickHdl(LINK(this, SwMailMergeOutputPage, DocumentSelectionHdl_Impl));
369 : //#i63267# printing might be disabled
370 0 : m_aPrintRB.Enable(!Application::GetSettings().GetMiscSettings().GetDisablePrinting());
371 0 : }
372 :
373 0 : SwMailMergeOutputPage::~SwMailMergeOutputPage()
374 : {
375 0 : delete m_pTempPrinter;
376 0 : }
377 :
378 0 : void SwMailMergeOutputPage::ActivatePage()
379 : {
380 : //fill printer ListBox
381 0 : const std::vector<rtl::OUString>& rPrinters = Printer::GetPrinterQueues();
382 0 : unsigned int nCount = rPrinters.size();
383 0 : if ( nCount )
384 : {
385 0 : for( unsigned int i = 0; i < nCount; i++ )
386 : {
387 0 : m_aPrinterLB.InsertEntry( rPrinters[i] );
388 : }
389 :
390 : }
391 0 : SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
392 :
393 0 : SwView* pTargetView = rConfigItem.GetTargetView();
394 : OSL_ENSURE(pTargetView, "no target view exists");
395 0 : if(pTargetView)
396 : {
397 0 : SfxPrinter* pPrinter = pTargetView->GetWrtShell().getIDocumentDeviceAccess()->getPrinter( true );
398 0 : m_aPrinterLB.SelectEntry( pPrinter->GetName() );
399 0 : m_aToNF.SetValue( rConfigItem.GetMergedDocumentCount() );
400 0 : m_aToNF.SetMax( rConfigItem.GetMergedDocumentCount() );
401 : }
402 0 : m_aPrinterLB.SelectEntry( rConfigItem.GetSelectedPrinter() );
403 :
404 0 : SwView* pSourceView = rConfigItem.GetSourceView();
405 : OSL_ENSURE(pSourceView, "no source view exists");
406 0 : if(pSourceView)
407 : {
408 0 : SwDocShell* pDocShell = pSourceView->GetDocShell();
409 0 : if ( pDocShell->HasName() )
410 : {
411 0 : INetURLObject aTmp( pDocShell->GetMedium()->GetName() );
412 : m_aAttachmentED.SetText(aTmp.getName(
413 0 : INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ));
414 : }
415 : }
416 0 : }
417 :
418 0 : bool SwMailMergeOutputPage::canAdvance() const
419 : {
420 0 : return false;
421 : }
422 :
423 0 : IMPL_LINK(SwMailMergeOutputPage, OutputTypeHdl_Impl, RadioButton*, pButton)
424 : {
425 : Control* aControls[] =
426 : {
427 : &m_aSaveStartDocPB,
428 : &m_aSaveAsOneRB, &m_aSaveIndividualRB,
429 : &m_aFromRB, &m_aFromNF, &m_aToFT, &m_aToNF,
430 : &m_aSaveNowPB,
431 : &m_aPrinterFT, &m_aPrinterLB, &m_aPrinterSettingsPB, &m_aPrintAllRB,
432 : &m_aPrintNowPB,
433 : &m_aMailToFT, &m_aMailToLB, &m_aCopyToPB,
434 : &m_aSubjectFT, &m_aSubjectED,
435 : &m_aSendAsFT, &m_aSendAsLB, &m_aSendAsPB,
436 : &m_aAttachmentFT, &m_aAttachmentED,
437 : &m_aSendAllRB, &m_aSendDocumentsPB,
438 : 0
439 0 : };
440 0 : SetUpdateMode(sal_True);
441 0 : Control** pControl = aControls;
442 0 : do
443 : {
444 0 : (*pControl)->Show(sal_False);
445 :
446 : } while(*(++pControl));
447 :
448 0 : if(&m_aSaveStartDocRB == pButton)
449 : {
450 0 : m_aSaveStartDocPB.Show();
451 0 : m_aSeparatorFL.SetText(m_sSaveStartST);
452 :
453 : }
454 0 : else if(&m_aSaveMergedDocRB == pButton)
455 : {
456 : Control* aSaveMergedControls[] =
457 : {
458 : &m_aSaveAsOneRB, &m_aSaveIndividualRB,
459 : &m_aFromRB, &m_aFromNF, &m_aToFT, &m_aToNF,
460 : &m_aSaveNowPB,
461 : 0
462 0 : };
463 0 : Control** pSaveMergeControl = aSaveMergedControls;
464 0 : do
465 : {
466 0 : (*pSaveMergeControl)->Show(sal_True);
467 :
468 : } while(*(++pSaveMergeControl));
469 0 : if(!m_aFromRB.IsChecked() && !m_aSaveAsOneRB.IsChecked())
470 : {
471 0 : m_aSaveIndividualRB.Check();
472 : }
473 0 : m_aSeparatorFL.SetText(m_sSaveMergedST);
474 : //reposition the from/to line
475 0 : if(m_aFromRB.GetPosPixel().Y() != m_nFromToRBPos)
476 : {
477 0 : Point aPos(m_aFromRB.GetPosPixel()); aPos.Y() = m_nFromToRBPos; m_aFromRB.SetPosPixel(aPos);
478 0 : aPos = m_aToFT.GetPosPixel(); aPos.Y() = m_nFromToFTPos; m_aToFT.SetPosPixel(aPos);
479 0 : aPos = m_aFromNF.GetPosPixel(); aPos.Y() = m_nFromToNFPos; m_aFromNF.SetPosPixel(aPos);
480 0 : aPos = m_aToNF.GetPosPixel(); aPos.Y() = m_nFromToNFPos; m_aToNF.SetPosPixel(aPos);
481 : }
482 : }
483 0 : else if(&m_aPrintRB == pButton)
484 : {
485 : Control* aPrintControls[] =
486 : {
487 : &m_aFromRB, &m_aFromNF, &m_aToFT, &m_aToNF,
488 : &m_aPrinterFT, &m_aPrinterLB, &m_aPrinterSettingsPB, &m_aPrintAllRB,
489 : &m_aPrintNowPB,
490 : 0
491 0 : };
492 0 : Control** pPrinterControl = aPrintControls;
493 0 : do
494 : {
495 0 : (*pPrinterControl)->Show(sal_True);
496 :
497 : } while(*(++pPrinterControl));
498 0 : if(!m_aFromRB.IsChecked())
499 0 : m_aPrintAllRB.Check();
500 :
501 0 : m_aSeparatorFL.SetText(m_sPrintST);
502 : //reposition the from/to line
503 0 : long nRB_FT_Offset = m_nFromToRBPos - m_nFromToFTPos;
504 0 : long nNewRBXPos = m_aPrintAllRB.GetPosPixel().Y() + m_nRBOffset;
505 :
506 0 : Point aPos(m_aFromRB.GetPosPixel());aPos.Y() = nNewRBXPos; m_aFromRB.SetPosPixel(aPos);
507 0 : aPos = m_aToFT.GetPosPixel(); aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aToFT.SetPosPixel(aPos);
508 0 : aPos = m_aFromNF.GetPosPixel(); aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aFromNF.SetPosPixel(aPos);
509 0 : aPos = m_aToNF.GetPosPixel(); aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aToNF.SetPosPixel(aPos);
510 : }
511 : else
512 : {
513 : Control* aMailControls[] =
514 : {
515 : &m_aFromRB, &m_aFromNF, &m_aToFT, &m_aToNF,
516 : &m_aMailToFT, &m_aMailToLB, &m_aCopyToPB,
517 : &m_aSubjectFT, &m_aSubjectED,
518 : &m_aSendAsFT, &m_aSendAsLB, &m_aSendAsPB,
519 : &m_aAttachmentFT, &m_aAttachmentED,
520 : &m_aSendAllRB, &m_aSendDocumentsPB, 0
521 0 : };
522 0 : Control** pMailControl = aMailControls;
523 0 : do
524 : {
525 0 : (*pMailControl)->Show(sal_True);
526 :
527 : } while(*(++pMailControl));
528 :
529 0 : if(!m_aFromRB.IsChecked())
530 0 : m_aSendAllRB.Check();
531 0 : if(!m_aAttachmentED.GetText().Len())
532 : {
533 0 : String sAttach( m_sDefaultAttachmentST );
534 0 : sAttach += '.';
535 : sAttach += lcl_GetExtensionForDocType(
536 0 : (sal_uLong)m_aSendAsLB.GetEntryData(m_aSendAsLB.GetSelectEntryPos()));
537 0 : m_aAttachmentED.SetText( sAttach );
538 :
539 : }
540 0 : m_aSeparatorFL.SetText(m_sSendMailST);
541 : //fill mail address ListBox
542 0 : if(!m_aMailToLB.GetEntryCount())
543 : {
544 0 : SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
545 : //select first column
546 0 : uno::Reference< sdbcx::XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), uno::UNO_QUERY);
547 : //get the name of the actual columns
548 0 : uno::Reference < container::XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
549 0 : uno::Sequence< ::rtl::OUString > aFields;
550 0 : if(xColAccess.is())
551 0 : aFields = xColAccess->getElementNames();
552 0 : const ::rtl::OUString* pFields = aFields.getConstArray();
553 0 : for(sal_Int32 nField = 0; nField < aFields.getLength(); ++nField)
554 0 : m_aMailToLB.InsertEntry(pFields[nField]);
555 :
556 0 : m_aMailToLB.SelectEntryPos(0);
557 : // then select the right one - may not be available
558 0 : const ResStringArray& rHeaders = rConfigItem.GetDefaultAddressHeaders();
559 0 : String sEMailColumn = rHeaders.GetString( MM_PART_E_MAIL );
560 : Sequence< ::rtl::OUString> aAssignment =
561 0 : rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
562 0 : if(aAssignment.getLength() > MM_PART_E_MAIL && !aAssignment[MM_PART_E_MAIL].isEmpty())
563 0 : sEMailColumn = aAssignment[MM_PART_E_MAIL];
564 0 : m_aMailToLB.SelectEntry(sEMailColumn);
565 : // HTML format pre-selected
566 0 : m_aSendAsLB.SelectEntryPos(3);
567 0 : SendTypeHdl_Impl(&m_aSendAsLB);
568 : }
569 0 : if(m_aSendAllRB.GetPosPixel().Y() + m_nRBOffset != m_aFromRB.GetPosPixel().Y())
570 : {
571 0 : long nRB_FT_Offset = m_nFromToRBPos - m_nFromToFTPos;
572 0 : long nNewRBXPos = m_aSendAllRB.GetPosPixel().Y() + m_nRBOffset;
573 :
574 0 : Point aPos(m_aFromRB.GetPosPixel());aPos.Y() = nNewRBXPos; m_aFromRB.SetPosPixel(aPos);
575 0 : aPos = m_aToFT.GetPosPixel(); aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aToFT.SetPosPixel(aPos);
576 0 : aPos = m_aFromNF.GetPosPixel(); aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aFromNF.SetPosPixel(aPos);
577 0 : aPos = m_aToNF.GetPosPixel(); aPos.Y() = nNewRBXPos + nRB_FT_Offset; m_aToNF.SetPosPixel(aPos);
578 : }
579 : }
580 0 : m_aFromRB.GetClickHdl().Call(m_aFromRB.IsChecked() ? &m_aFromRB : 0);
581 :
582 0 : SetUpdateMode(sal_False);
583 0 : return 0;
584 : }
585 :
586 0 : IMPL_LINK(SwMailMergeOutputPage, DocumentSelectionHdl_Impl, RadioButton*, pButton)
587 : {
588 0 : sal_Bool bEnableFromTo = pButton == &m_aFromRB;
589 0 : m_aFromNF.Enable(bEnableFromTo);
590 0 : m_aToFT.Enable(bEnableFromTo);
591 0 : m_aToNF.Enable(bEnableFromTo);
592 0 : return 0;
593 : }
594 :
595 0 : IMPL_LINK(SwMailMergeOutputPage, CopyToHdl_Impl, PushButton*, pButton)
596 : {
597 0 : SwCopyToDialog* pDlg = new SwCopyToDialog(pButton);
598 0 : pDlg->SetCC(m_sCC );
599 0 : pDlg->SetBCC(m_sBCC);
600 0 : if(RET_OK == pDlg->Execute())
601 : {
602 0 : m_sCC = pDlg->GetCC() ;
603 0 : m_sBCC = pDlg->GetBCC();
604 : }
605 0 : delete pDlg;
606 0 : return 0;
607 : }
608 :
609 0 : IMPL_LINK(SwMailMergeOutputPage, SaveStartHdl_Impl, PushButton*, pButton)
610 : {
611 0 : SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
612 0 : SwView* pSourceView = rConfigItem.GetSourceView();
613 : OSL_ENSURE( pSourceView, "source view missing");
614 0 : if(pSourceView)
615 : {
616 0 : SfxViewFrame* pSourceViewFrm = pSourceView->GetViewFrame();
617 : uno::Reference< frame::XFrame > xFrame =
618 0 : pSourceViewFrm->GetFrame().GetFrameInterface();
619 0 : xFrame->getContainerWindow()->setVisible(sal_True);
620 0 : pSourceViewFrm->GetDispatcher()->Execute(SID_SAVEDOC, SFX_CALLMODE_SYNCHRON);
621 0 : xFrame->getContainerWindow()->setVisible(sal_False);
622 0 : SwDocShell* pDocShell = pSourceView->GetDocShell();
623 : //if the document has been saved it's URL has to be stored for
624 : // later use and it can be closed now
625 0 : if(pDocShell->HasName() && !pDocShell->IsModified())
626 : {
627 0 : INetURLObject aURL = pDocShell->GetMedium()->GetURLObject();
628 : //update the attachment name
629 0 : if(!m_aAttachmentED.GetText().Len())
630 : {
631 0 : if ( pDocShell->HasName() )
632 : {
633 : m_aAttachmentED.SetText(aURL.getName(
634 0 : INetURLObject::LAST_SEGMENT, true, INetURLObject::DECODE_WITH_CHARSET ));
635 : }
636 : }
637 :
638 : rConfigItem.AddSavedDocument(
639 0 : aURL.GetMainURL(INetURLObject::DECODE_TO_IURI));
640 0 : pButton->Enable(sal_False);
641 0 : m_pWizard->enableButtons(WZB_FINISH, sal_True);
642 0 : pButton->Enable(sal_False);
643 :
644 0 : }
645 : }
646 0 : return 0;
647 : }
648 :
649 0 : IMPL_LINK_NOARG(SwMailMergeOutputPage, SaveCancelHdl_Impl)
650 : {
651 0 : m_bCancelSaving = true;
652 0 : return 0;
653 : }
654 :
655 0 : IMPL_LINK(SwMailMergeOutputPage, SaveOutputHdl_Impl, PushButton*, pButton)
656 : {
657 0 : SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
658 0 : SwView* pTargetView = rConfigItem.GetTargetView();
659 : OSL_ENSURE(pTargetView, "no target view exists");
660 0 : if(!pTargetView)
661 0 : return 0;
662 :
663 0 : if(m_aSaveAsOneRB.IsChecked())
664 : {
665 0 : String sFilter;
666 0 : String sPath = SwMailMergeHelper::CallSaveAsDialog(sFilter);
667 0 : if(!sPath.Len())
668 0 : return 0;
669 0 : uno::Sequence< beans::PropertyValue > aValues(1);
670 0 : beans::PropertyValue* pValues = aValues.getArray();
671 0 : pValues[0].Name = "FilterName";
672 0 : pValues[0].Value <<= ::rtl::OUString(sFilter);
673 :
674 0 : uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
675 0 : sal_uInt32 nErrorCode = ERRCODE_NONE;
676 : try
677 : {
678 0 : xStore->storeToURL( sPath, aValues );
679 : }
680 0 : catch (const task::ErrorCodeIOException& rErrorEx)
681 : {
682 0 : nErrorCode = (sal_uInt32)rErrorEx.ErrCode;
683 : }
684 0 : catch (const Exception&)
685 : {
686 0 : nErrorCode = ERRCODE_IO_GENERAL;
687 : }
688 0 : if( nErrorCode != ERRCODE_NONE )
689 : {
690 0 : SfxErrorContext aEc(ERRCTX_SFX_SAVEASDOC, pTargetView->GetDocShell()->GetTitle());
691 0 : ErrorHandler::HandleError( nErrorCode );
692 0 : }
693 : }
694 : else
695 : {
696 0 : sal_uInt32 nBegin = 0;
697 0 : sal_uInt32 nEnd = 0;
698 0 : if(m_aSaveIndividualRB.IsChecked())
699 : {
700 0 : nBegin = 0;
701 0 : nEnd = rConfigItem.GetMergedDocumentCount();
702 : }
703 : else
704 : {
705 0 : nBegin = static_cast< sal_Int32 >(m_aFromNF.GetValue() - 1);
706 0 : nEnd = static_cast< sal_Int32 >(m_aToNF.GetValue());
707 0 : if(nEnd > rConfigItem.GetMergedDocumentCount())
708 0 : nEnd = rConfigItem.GetMergedDocumentCount();
709 : }
710 0 : String sFilter;
711 0 : String sPath = SwMailMergeHelper::CallSaveAsDialog(sFilter);
712 0 : if(!sPath.Len())
713 0 : return 0;
714 : String sTargetTempURL = URIHelper::SmartRel2Abs(
715 : INetURLObject(), utl::TempFile::CreateTempName(),
716 0 : URIHelper::GetMaybeFileHdl());
717 : const SfxFilter *pSfxFlt = SwIoSystem::GetFilterOfFormat(
718 : rtl::OUString( FILTER_XML ),
719 0 : SwDocShell::Factory().GetFilterContainer() );
720 :
721 0 : uno::Sequence< beans::PropertyValue > aValues(1);
722 0 : beans::PropertyValue* pValues = aValues.getArray();
723 0 : pValues[0].Name = "FilterName";
724 0 : pValues[0].Value <<= ::rtl::OUString(pSfxFlt->GetFilterName());
725 :
726 0 : uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
727 0 : sal_uInt32 nErrorCode = ERRCODE_NONE;
728 : try
729 : {
730 0 : xStore->storeToURL( sTargetTempURL, aValues );
731 : }
732 0 : catch (const task::ErrorCodeIOException& rErrorEx)
733 : {
734 0 : nErrorCode = (sal_uInt32)rErrorEx.ErrCode;
735 : }
736 0 : catch (const Exception&)
737 : {
738 0 : nErrorCode = ERRCODE_IO_GENERAL;
739 : }
740 0 : if( nErrorCode != ERRCODE_NONE )
741 : {
742 0 : SfxErrorContext aEc(ERRCTX_SFX_SAVEASDOC, pTargetView->GetDocShell()->GetTitle());
743 0 : ErrorHandler::HandleError( nErrorCode );
744 : }
745 :
746 0 : SwView* pSourceView = rConfigItem.GetSourceView();
747 0 : PrintMonitor aSaveMonitor(this, PrintMonitor::MONITOR_TYPE_SAVE);
748 0 : aSaveMonitor.aDocName.SetText(pSourceView->GetDocShell()->GetTitle(22));
749 0 : aSaveMonitor.aCancel.SetClickHdl(LINK(this, SwMailMergeOutputPage, SaveCancelHdl_Impl));
750 0 : aSaveMonitor.aPrinter.SetText( INetURLObject( sPath ).getFSysPath( INetURLObject::FSYS_DETECT ) );
751 0 : aSaveMonitor.ResizeControls();
752 :
753 0 : m_bCancelSaving = false;
754 0 : aSaveMonitor.Show();
755 0 : m_pWizard->enableButtons(WZB_CANCEL, sal_False);
756 :
757 0 : for(sal_uInt32 nDoc = nBegin; nDoc < nEnd && !m_bCancelSaving; ++nDoc)
758 : {
759 0 : SwDocMergeInfo& rInfo = rConfigItem.GetDocumentMergeInfo(nDoc);
760 0 : INetURLObject aURL(sPath);
761 0 : String sExtension = aURL.getExtension();
762 0 : if(!sExtension.Len())
763 : {
764 0 : sExtension = comphelper::string::getToken(pSfxFlt->GetWildcard().getGlob(), 1, '.');
765 0 : sPath += '.';
766 0 : sPath += sExtension;
767 : }
768 0 : String sStat(SW_RES(STR_STATSTR_LETTER));
769 0 : sStat += ' ';
770 0 : sStat += String::CreateFromInt32( nDoc );
771 0 : aSaveMonitor.aPrintInfo.SetText(sStat);
772 :
773 : //now extract a document from the target document
774 : // the shell will be closed at the end, but it is more safe to use SfxObjectShellLock here
775 0 : SfxObjectShellLock xTempDocShell( new SwDocShell( SFX_CREATE_MODE_STANDARD ) );
776 0 : xTempDocShell->DoInitNew( 0 );
777 0 : SfxViewFrame* pTempFrame = SfxViewFrame::LoadHiddenDocument( *xTempDocShell, 0 );
778 0 : SwView* pTempView = static_cast<SwView*>( pTempFrame->GetViewShell() );
779 0 : pTargetView->GetWrtShell().StartAction();
780 0 : SwgReaderOption aOpt;
781 0 : aOpt.SetTxtFmts( sal_True );
782 0 : aOpt.SetFrmFmts( sal_True );
783 0 : aOpt.SetPageDescs( sal_True );
784 0 : aOpt.SetNumRules( sal_True );
785 0 : aOpt.SetMerge( sal_False );
786 : pTempView->GetDocShell()->LoadStylesFromFile(
787 0 : sTargetTempURL, aOpt, sal_True );
788 :
789 0 : pTargetView->GetWrtShell().PastePages(pTempView->GetWrtShell(),
790 0 : (sal_uInt16)rInfo.nStartPageInTarget, (sal_uInt16)rInfo.nEndPageInTarget );
791 0 : pTargetView->GetWrtShell().EndAction();
792 : //then save it
793 0 : String sOutPath = aURL.GetMainURL(INetURLObject::DECODE_TO_IURI);
794 0 : String sCounter = rtl::OUString('_');
795 0 : sCounter += String::CreateFromInt32(nDoc);
796 0 : sOutPath.Insert(sCounter, sOutPath.Len() - sExtension.Len() - 1);
797 :
798 0 : while(true)
799 : {
800 : //time for other slots is needed
801 0 : for(sal_Int16 r = 0; r < 10; ++r)
802 0 : Application::Reschedule();
803 0 : bool bFailed = false;
804 : try
805 : {
806 0 : pValues[0].Value <<= ::rtl::OUString(sFilter);
807 0 : uno::Reference< frame::XStorable > xTempStore( xTempDocShell->GetModel(), uno::UNO_QUERY);
808 0 : xTempStore->storeToURL( sOutPath, aValues );
809 : }
810 0 : catch (const uno::Exception&)
811 : {
812 0 : bFailed = true;
813 : }
814 :
815 0 : if(bFailed)
816 : {
817 0 : SwSaveWarningBox_Impl aWarning( pButton, sOutPath );
818 0 : if(RET_OK == aWarning.Execute())
819 0 : sOutPath = aWarning.GetFileName();
820 : else
821 : {
822 0 : xTempDocShell->DoClose();
823 0 : return 0;
824 0 : }
825 : }
826 : else
827 : {
828 0 : xTempDocShell->DoClose();
829 0 : break;
830 : }
831 : }
832 0 : }
833 0 : ::osl::File::remove( sTargetTempURL );
834 : }
835 0 : m_pWizard->enableButtons(WZB_CANCEL, sal_True);
836 0 : m_pWizard->enableButtons(WZB_FINISH, sal_True);
837 0 : return 0;
838 : }
839 :
840 0 : IMPL_LINK(SwMailMergeOutputPage, PrinterChangeHdl_Impl, ListBox*, pBox)
841 : {
842 0 : SwView *const pTargetView = m_pWizard->GetConfigItem().GetTargetView();
843 0 : SfxPrinter *const pDocumentPrinter = pTargetView->GetWrtShell()
844 0 : .getIDocumentDeviceAccess()->getPrinter(true);
845 0 : if (pDocumentPrinter && pBox->GetSelectEntryPos() != LISTBOX_ENTRY_NOTFOUND)
846 : {
847 0 : const QueueInfo* pInfo = Printer::GetQueueInfo( pBox->GetSelectEntry(), false );
848 :
849 0 : if( pInfo )
850 : {
851 0 : if ( !m_pTempPrinter )
852 : {
853 0 : if ((pDocumentPrinter->GetName() == pInfo->GetPrinterName()) &&
854 0 : (pDocumentPrinter->GetDriverName() == pInfo->GetDriver()))
855 : {
856 0 : m_pTempPrinter = new Printer(pDocumentPrinter->GetJobSetup());
857 : }
858 : else
859 0 : m_pTempPrinter = new Printer( *pInfo );
860 : }
861 : else
862 : {
863 0 : if( (m_pTempPrinter->GetName() != pInfo->GetPrinterName()) ||
864 0 : (m_pTempPrinter->GetDriverName() != pInfo->GetDriver()) )
865 : {
866 0 : delete m_pTempPrinter;
867 0 : m_pTempPrinter = new Printer( *pInfo );
868 : }
869 : }
870 : }
871 0 : else if( ! m_pTempPrinter )
872 0 : m_pTempPrinter = new Printer();
873 :
874 0 : m_aPrinterSettingsPB.Enable( m_pTempPrinter->HasSupport( SUPPORT_SETUPDIALOG ) );
875 : }
876 : else
877 0 : m_aPrinterSettingsPB.Disable();
878 0 : m_pWizard->GetConfigItem().SetSelectedPrinter( pBox->GetSelectEntry() );
879 :
880 0 : return 0;
881 : }
882 :
883 0 : IMPL_LINK_NOARG(SwMailMergeOutputPage, PrintHdl_Impl)
884 : {
885 0 : SwView* pTargetView = m_pWizard->GetConfigItem().GetTargetView();
886 : OSL_ENSURE(pTargetView, "no target view exists");
887 0 : if(!pTargetView)
888 0 : return 0;
889 :
890 0 : sal_uInt32 nBegin = 0;
891 0 : sal_uInt32 nEnd = 0;
892 0 : SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
893 0 : if(m_aPrintAllRB.IsChecked())
894 : {
895 0 : nBegin = 0;
896 0 : nEnd = rConfigItem.GetMergedDocumentCount();
897 : }
898 : else
899 : {
900 0 : nBegin = static_cast< sal_Int32 >(m_aFromNF.GetValue() - 1);
901 0 : nEnd = static_cast< sal_Int32 >(m_aToNF.GetValue());
902 0 : if(nEnd > rConfigItem.GetMergedDocumentCount())
903 0 : nEnd = rConfigItem.GetMergedDocumentCount();
904 : }
905 0 : rConfigItem.SetPrintRange( (sal_uInt16)nBegin, (sal_uInt16)nEnd );
906 0 : SwDocMergeInfo& rStartInfo = rConfigItem.GetDocumentMergeInfo(nBegin);
907 0 : SwDocMergeInfo& rEndInfo = rConfigItem.GetDocumentMergeInfo(nEnd - 1);
908 :
909 0 : rtl::OUString sPages(rtl::OUString::valueOf( rStartInfo.nStartPageInTarget ));
910 0 : sPages += rtl::OUString(RTL_CONSTASCII_USTRINGPARAM(" - "));
911 0 : sPages += rtl::OUString::valueOf( rEndInfo.nEndPageInTarget );
912 :
913 0 : SwWrtShell& rSh = pTargetView->GetWrtShell();
914 0 : pTargetView->SetMailMergeConfigItem(&rConfigItem, 0, sal_False);
915 0 : if(m_pTempPrinter)
916 : {
917 0 : SfxPrinter *const pDocumentPrinter = pTargetView->GetWrtShell()
918 0 : .getIDocumentDeviceAccess()->getPrinter(true);
919 0 : pDocumentPrinter->SetPrinterProps(m_pTempPrinter);
920 : // this should be able to handle setting its own printer
921 0 : pTargetView->SetPrinter(pDocumentPrinter);
922 : }
923 :
924 0 : SfxObjectShell* pObjSh = pTargetView->GetViewFrame()->GetObjectShell();
925 0 : SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_MAIL_MERGE, SwDocShell::GetEventName(STR_SW_EVENT_MAIL_MERGE), pObjSh));
926 0 : rSh.GetNewDBMgr()->SetMergeType( DBMGR_MERGE_DOCUMENTS );
927 0 : SfxBoolItem aMergeSilent(SID_SILENT, sal_False);
928 0 : m_pWizard->enableButtons(WZB_CANCEL, sal_False);
929 :
930 0 : uno::Sequence < beans::PropertyValue > aProps( 2 );
931 0 : aProps[0]. Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("MonitorVisible"));
932 0 : aProps[0].Value <<= sal_True;
933 0 : aProps[1]. Name = rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("Pages"));
934 0 : aProps[1]. Value <<= sPages;
935 :
936 0 : pTargetView->ExecPrint( aProps, false, true );
937 0 : SFX_APP()->NotifyEvent(SfxEventHint(SW_EVENT_MAIL_MERGE_END, SwDocShell::GetEventName(STR_SW_EVENT_MAIL_MERGE_END), pObjSh));
938 :
939 0 : pTargetView->SetMailMergeConfigItem(0, 0, sal_False);
940 0 : m_pWizard->enableButtons(WZB_CANCEL, sal_True);
941 0 : m_pWizard->enableButtons(WZB_FINISH, sal_True);
942 0 : return 0;
943 : }
944 :
945 0 : IMPL_LINK(SwMailMergeOutputPage, PrinterSetupHdl_Impl, PushButton*, pButton)
946 : {
947 0 : if( !m_pTempPrinter )
948 0 : PrinterChangeHdl_Impl(&m_aPrinterLB);
949 0 : if(m_pTempPrinter)
950 0 : m_pTempPrinter->Setup(pButton);
951 0 : return 0;
952 : }
953 :
954 0 : IMPL_LINK(SwMailMergeOutputPage, SendTypeHdl_Impl, ListBox*, pBox)
955 : {
956 0 : sal_uLong nDocType = (sal_uLong)pBox->GetEntryData(pBox->GetSelectEntryPos());
957 0 : sal_Bool bEnable = MM_DOCTYPE_HTML != nDocType && MM_DOCTYPE_TEXT != nDocType;
958 0 : m_aSendAsPB.Enable( bEnable );
959 0 : m_aAttachmentFT.Enable( bEnable );
960 0 : m_aAttachmentED.Enable( bEnable );
961 0 : if(bEnable)
962 : {
963 : //add the correct extension
964 0 : String sAttach(m_aAttachmentED.GetText());
965 : //do nothing if the user has removed the name - the warning will come early enough
966 0 : if(sAttach.Len())
967 : {
968 0 : xub_StrLen nTokenCount = comphelper::string::getTokenCount(sAttach, '.');
969 0 : if( 2 > nTokenCount)
970 : {
971 0 : sAttach += '.';
972 0 : ++nTokenCount;
973 : }
974 0 : sAttach.SetToken( nTokenCount - 1, '.', lcl_GetExtensionForDocType( nDocType ));
975 0 : m_aAttachmentED.SetText(sAttach);
976 0 : }
977 : }
978 0 : return 0;
979 : }
980 :
981 0 : IMPL_LINK(SwMailMergeOutputPage, SendAsHdl_Impl, PushButton*, pButton)
982 : {
983 0 : SwMailBodyDialog* pDlg = new SwMailBodyDialog(pButton, m_pWizard);
984 0 : pDlg->SetBody(m_sBody);
985 0 : if(RET_OK == pDlg->Execute())
986 : {
987 0 : m_sBody = pDlg->GetBody();
988 : }
989 0 : return 0;
990 : }
991 :
992 : /*-------------------------------------------------------------------------
993 : Send documents as e-mail
994 : -----------------------------------------------------------------------*/
995 0 : IMPL_LINK(SwMailMergeOutputPage, SendDocumentsHdl_Impl, PushButton*, pButton)
996 : {
997 0 : SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
998 :
999 : //get the composed document
1000 0 : SwView* pTargetView = rConfigItem.GetTargetView();
1001 : OSL_ENSURE(pTargetView, "no target view exists");
1002 0 : if(!pTargetView)
1003 0 : return 0;
1004 :
1005 0 : if(rConfigItem.GetMailServer().isEmpty() ||
1006 0 : !SwMailMergeHelper::CheckMailAddress(rConfigItem.GetMailAddress()) )
1007 : {
1008 0 : QueryBox aQuery(pButton, WB_YES_NO_CANCEL, m_sConfigureMail);
1009 0 : sal_uInt16 nRet = aQuery.Execute();
1010 0 : if(RET_YES == nRet )
1011 : {
1012 0 : SfxAllItemSet aSet(pTargetView->GetPool());
1013 0 : SwMailConfigDlg* pDlg = new SwMailConfigDlg(pButton, aSet);
1014 0 : nRet = pDlg->Execute();
1015 0 : delete pDlg;
1016 : }
1017 :
1018 0 : if(nRet != RET_OK && nRet != RET_YES)
1019 0 : return 0;
1020 : }
1021 : //add the documents
1022 0 : sal_uInt32 nBegin = 0;
1023 0 : sal_uInt32 nEnd = 0;
1024 0 : if(m_aSendAllRB.IsChecked())
1025 : {
1026 0 : nBegin = 0;
1027 0 : nEnd = rConfigItem.GetMergedDocumentCount();
1028 : }
1029 : else
1030 : {
1031 0 : nBegin = static_cast< sal_Int32 >(m_aFromNF.GetValue() - 1);
1032 0 : nEnd = static_cast< sal_Int32 >(m_aToNF.GetValue());
1033 0 : if(nEnd > rConfigItem.GetMergedDocumentCount())
1034 0 : nEnd = rConfigItem.GetMergedDocumentCount();
1035 : }
1036 0 : bool bAsBody = false;
1037 0 : rtl_TextEncoding eEncoding = ::osl_getThreadTextEncoding();
1038 0 : SfxFilterContainer* pFilterContainer = SwDocShell::Factory().GetFilterContainer();
1039 0 : const SfxFilter *pSfxFlt = 0;
1040 0 : sal_uLong nDocType = (sal_uLong)m_aSendAsLB.GetEntryData(m_aSendAsLB.GetSelectEntryPos());
1041 0 : String sExtension = lcl_GetExtensionForDocType(nDocType);
1042 0 : switch( nDocType )
1043 : {
1044 : case MM_DOCTYPE_OOO:
1045 : {
1046 : //Make sure we don't pick e.g. the flat xml filter
1047 : //for this format
1048 : pSfxFlt = SwIoSystem::GetFilterOfFormat(
1049 : rtl::OUString( FILTER_XML ),
1050 0 : SwDocShell::Factory().GetFilterContainer() );
1051 : }
1052 0 : break;
1053 : case MM_DOCTYPE_PDF:
1054 : {
1055 : pSfxFlt = pFilterContainer->GetFilter4FilterName(
1056 : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("writer_pdf_Export")),
1057 0 : SFX_FILTER_EXPORT);
1058 : }
1059 0 : break;
1060 : case MM_DOCTYPE_WORD:
1061 : {
1062 : //the method SwIOSystemGetFilterOfFormat( ) returns the template filter
1063 : //because it uses the same user data :-(
1064 0 : SfxFilterMatcher aMatcher( pFilterContainer->GetName() );
1065 0 : SfxFilterMatcherIter aIter( aMatcher );
1066 0 : const SfxFilter* pFilter = aIter.First();
1067 0 : while ( pFilter )
1068 : {
1069 0 : if( pFilter->GetUserData() == FILTER_WW8 && pFilter->CanExport() )
1070 : {
1071 0 : pSfxFlt = pFilter;
1072 0 : break;
1073 : }
1074 0 : pFilter = aIter.Next();
1075 0 : }
1076 :
1077 : }
1078 0 : break;
1079 : case MM_DOCTYPE_HTML:
1080 : {
1081 0 : bAsBody = true;
1082 0 : SvxHtmlOptions& rHtmlOptions = SvxHtmlOptions::Get();
1083 0 : eEncoding = rHtmlOptions.GetTextEncoding();
1084 : }
1085 0 : break;
1086 : case MM_DOCTYPE_TEXT:
1087 0 : bAsBody = true;
1088 0 : break;
1089 : }
1090 0 : if(!pSfxFlt)
1091 0 : pSfxFlt = pFilterContainer->GetFilter4Extension(sExtension, SFX_FILTER_EXPORT);
1092 :
1093 0 : if(!pSfxFlt)
1094 0 : return 0;
1095 0 : ::rtl::OUString sMimeType = pSfxFlt->GetMimeType();
1096 :
1097 0 : if(!m_aSubjectED.GetText().Len())
1098 : {
1099 0 : SwSendQueryBox_Impl aQuery(pButton, m_sNoSubjectQueryST);
1100 0 : aQuery.SetIsEmptyTextAllowed(true);
1101 0 : aQuery.SetValue(m_sNoSubjectST);
1102 0 : if(RET_OK == aQuery.Execute())
1103 : {
1104 0 : if(aQuery.GetValue() != m_sNoSubjectST)
1105 0 : m_aSubjectED.SetText(aQuery.GetValue());
1106 : }
1107 : else
1108 0 : return 0;
1109 : }
1110 0 : if(!bAsBody && !m_aAttachmentED.GetText().Len())
1111 : {
1112 0 : SwSendQueryBox_Impl aQuery(pButton, m_sNoAttachmentNameST);
1113 0 : aQuery.SetIsEmptyTextAllowed(false);
1114 0 : if(RET_OK == aQuery.Execute())
1115 : {
1116 0 : String sAttach(aQuery.GetValue());
1117 0 : xub_StrLen nTokenCount = comphelper::string::getTokenCount(sAttach, '.');
1118 0 : if( 2 > nTokenCount)
1119 : {
1120 0 : sAttach += '.';
1121 0 : ++nTokenCount;
1122 : }
1123 : sAttach.SetToken( nTokenCount - 1, '.', lcl_GetExtensionForDocType(
1124 0 : (sal_uLong)m_aSendAsLB.GetEntryData(m_aSendAsLB.GetSelectEntryPos())));
1125 0 : m_aAttachmentED.SetText(sAttach);
1126 : }
1127 : else
1128 0 : return 0;
1129 : }
1130 0 : SfxStringItem aFilterName( SID_FILTER_NAME, pSfxFlt->GetFilterName() );
1131 0 : String sEMailColumn = m_aMailToLB.GetSelectEntry();
1132 : OSL_ENSURE( sEMailColumn.Len(), "No email column selected");
1133 0 : Reference< sdbcx::XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), UNO_QUERY);
1134 0 : Reference < container::XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
1135 0 : if(!sEMailColumn.Len() || !xColAccess.is() || !xColAccess->hasByName(sEMailColumn))
1136 0 : return 0;
1137 :
1138 0 : String sFilterOptions;
1139 0 : if(MM_DOCTYPE_TEXT == nDocType)
1140 : {
1141 0 : SwAsciiOptions aOpt;
1142 0 : sal_uInt16 nAppScriptType = GetI18NScriptTypeOfLanguage( (sal_uInt16)GetAppLanguage() );
1143 0 : sal_uInt16 nWhich = GetWhichOfScript( RES_CHRATR_LANGUAGE, nAppScriptType);
1144 0 : aOpt.SetLanguage( ((SvxLanguageItem&)pTargetView->GetWrtShell().
1145 0 : GetDefault( nWhich )).GetLanguage());
1146 0 : aOpt.SetParaFlags( LINEEND_CR );
1147 0 : aOpt.WriteUserData( sFilterOptions );
1148 : }
1149 : String sTargetTempURL = URIHelper::SmartRel2Abs(
1150 : INetURLObject(), utl::TempFile::CreateTempName(),
1151 0 : URIHelper::GetMaybeFileHdl());
1152 : const SfxFilter *pTargetSfxFlt = SwIoSystem::GetFilterOfFormat(
1153 : rtl::OUString( FILTER_XML ),
1154 0 : SwDocShell::Factory().GetFilterContainer() );
1155 :
1156 0 : uno::Sequence< beans::PropertyValue > aValues(1);
1157 0 : beans::PropertyValue* pValues = aValues.getArray();
1158 0 : pValues[0].Name = "FilterName";
1159 0 : pValues[0].Value <<= ::rtl::OUString(pTargetSfxFlt->GetFilterName());
1160 :
1161 0 : uno::Reference< frame::XStorable > xStore( pTargetView->GetDocShell()->GetModel(), uno::UNO_QUERY);
1162 0 : xStore->storeToURL( sTargetTempURL, aValues );
1163 :
1164 : //create the send dialog
1165 0 : SwSendMailDialog* pDlg = new SwSendMailDialog( pButton, rConfigItem );
1166 0 : pDlg->SetDocumentCount( nEnd );
1167 0 : pDlg->ShowDialog();
1168 : //help to force painting the dialog
1169 : //TODO/CLEANUP
1170 : //predetermined breaking point
1171 0 : for ( sal_Int16 i = 0; i < 25; i++)
1172 0 : Application::Reschedule();
1173 0 : for(sal_uInt32 nDoc = nBegin; nDoc < nEnd; ++nDoc)
1174 : {
1175 0 : m_pWizard->EnterWait();
1176 0 : SwDocMergeInfo& rInfo = rConfigItem.GetDocumentMergeInfo(nDoc);
1177 :
1178 : //now extract a document from the target document
1179 : // the shell will be closed at the end, but it is more safe to use SfxObjectShellLock here
1180 0 : SfxObjectShellLock xTempDocShell( new SwDocShell( SFX_CREATE_MODE_STANDARD ) );
1181 0 : xTempDocShell->DoInitNew( 0 );
1182 0 : SfxViewFrame* pTempFrame = SfxViewFrame::LoadHiddenDocument( *xTempDocShell, 0 );
1183 0 : SwView* pTempView = static_cast<SwView*>( pTempFrame->GetViewShell() );
1184 0 : pTargetView->GetWrtShell().StartAction();
1185 0 : SwgReaderOption aOpt;
1186 0 : aOpt.SetTxtFmts( sal_True );
1187 0 : aOpt.SetFrmFmts( sal_True );
1188 0 : aOpt.SetPageDescs( sal_True );
1189 0 : aOpt.SetNumRules( sal_True );
1190 0 : aOpt.SetMerge( sal_False );
1191 : pTempView->GetDocShell()->LoadStylesFromFile(
1192 0 : sTargetTempURL, aOpt, sal_True );
1193 0 : pTargetView->GetWrtShell().PastePages(pTempView->GetWrtShell(),
1194 0 : (sal_uInt16)rInfo.nStartPageInTarget, (sal_uInt16)rInfo.nEndPageInTarget );
1195 0 : pTargetView->GetWrtShell().EndAction();
1196 :
1197 : //then save it
1198 : SfxStringItem aName(SID_FILE_NAME,
1199 : URIHelper::SmartRel2Abs(
1200 : INetURLObject(), utl::TempFile::CreateTempName(0),
1201 0 : URIHelper::GetMaybeFileHdl()) );
1202 :
1203 : {
1204 0 : uno::Sequence< beans::PropertyValue > aFilterValues(MM_DOCTYPE_TEXT == nDocType ? 2 : 1);
1205 0 : beans::PropertyValue* pFilterValues = aFilterValues.getArray();
1206 0 : pFilterValues[0].Name = "FilterName";
1207 0 : pFilterValues[0].Value <<= ::rtl::OUString(pSfxFlt->GetFilterName());
1208 0 : if(MM_DOCTYPE_TEXT == nDocType)
1209 : {
1210 0 : pFilterValues[1].Name = "FilterOptions";
1211 0 : pFilterValues[1].Value <<= ::rtl::OUString(sFilterOptions);
1212 : }
1213 :
1214 0 : uno::Reference< frame::XStorable > xTempStore( pTempView->GetDocShell()->GetModel(), uno::UNO_QUERY);
1215 0 : xTempStore->storeToURL( aName.GetValue(), aFilterValues );
1216 : }
1217 0 : xTempDocShell->DoClose();
1218 :
1219 0 : sal_Int32 nTarget = rConfigItem.MoveResultSet(rInfo.nDBRow);
1220 : OSL_ENSURE( nTarget == rInfo.nDBRow, "row of current document could not be selected");
1221 : (void)nTarget;
1222 : OSL_ENSURE( sEMailColumn.Len(), "No email column selected");
1223 0 : ::rtl::OUString sEMail = lcl_GetColumnValueOf(sEMailColumn, xColAccess);
1224 0 : SwMailDescriptor aDesc;
1225 0 : aDesc.sEMail = sEMail;
1226 0 : rtl::OUString sBody;
1227 0 : if(bAsBody)
1228 : {
1229 : {
1230 : //read in the temporary file and use it as mail body
1231 0 : SfxMedium aMedium( aName.GetValue(), STREAM_READ);
1232 0 : SvStream* pInStream = aMedium.GetInStream();
1233 0 : if(pInStream)
1234 0 : pInStream->SetStreamCharSet( eEncoding );
1235 : else
1236 : {
1237 : OSL_FAIL("no output file created?");
1238 0 : continue;
1239 : }
1240 0 : rtl::OString sLine;
1241 0 : sal_Bool bDone = pInStream->ReadLine( sLine );
1242 0 : while ( bDone )
1243 : {
1244 0 : sBody += rtl::OStringToOUString(sLine, eEncoding);
1245 0 : sBody += rtl::OUString('\n');
1246 0 : bDone = pInStream->ReadLine( sLine );
1247 0 : }
1248 : }
1249 : //remove the temporary file
1250 0 : SWUnoHelper::UCB_DeleteFile( aName.GetValue() );
1251 : }
1252 : else
1253 : {
1254 0 : sBody = m_sBody;
1255 0 : aDesc.sAttachmentURL = aName.GetValue();
1256 0 : String sAttachment(m_aAttachmentED.GetText());
1257 0 : xub_StrLen nTokenCount = comphelper::string::getTokenCount(sAttachment, '.');
1258 0 : if( 2 > nTokenCount)
1259 : {
1260 0 : sAttachment += '.';
1261 0 : sAttachment.SetToken( nTokenCount, '.', sExtension);
1262 : }
1263 0 : else if(sAttachment.GetToken( nTokenCount - 1, '.') != sExtension)
1264 0 : sAttachment += sExtension;
1265 0 : aDesc.sAttachmentName = sAttachment;
1266 0 : aDesc.sMimeType = sMimeType;
1267 :
1268 0 : if(rConfigItem.IsGreetingLine(sal_True))
1269 : {
1270 0 : ::rtl::OUString sNameColumn = rConfigItem.GetAssignedColumn(MM_PART_LASTNAME);
1271 0 : ::rtl::OUString sName = lcl_GetColumnValueOf(sNameColumn, xColAccess);
1272 0 : String sGreeting;
1273 0 : if(!sName.isEmpty() && rConfigItem.IsIndividualGreeting(sal_True))
1274 : {
1275 0 : ::rtl::OUString sGenderColumn = rConfigItem.GetAssignedColumn(MM_PART_GENDER);
1276 0 : const ::rtl::OUString& sFemaleValue = rConfigItem.GetFemaleGenderValue();
1277 0 : ::rtl::OUString sGenderValue = lcl_GetColumnValueOf(sGenderColumn, xColAccess);
1278 0 : SwMailMergeConfigItem::Gender eGenderType = sGenderValue == sFemaleValue ?
1279 : SwMailMergeConfigItem::FEMALE :
1280 0 : SwMailMergeConfigItem::MALE;
1281 :
1282 : sGreeting = SwAddressPreview::FillData(
1283 : rConfigItem.GetGreetings(eGenderType)
1284 0 : [rConfigItem.GetCurrentGreeting(eGenderType)],
1285 0 : rConfigItem);
1286 : }
1287 : else
1288 : {
1289 : sGreeting =
1290 : rConfigItem.GetGreetings(SwMailMergeConfigItem::NEUTRAL)
1291 0 : [rConfigItem.GetCurrentGreeting(SwMailMergeConfigItem::NEUTRAL)];
1292 :
1293 : }
1294 0 : sGreeting += '\n';
1295 0 : ::rtl::OUString sTemp( sGreeting );
1296 0 : sTemp += sBody;
1297 0 : sBody = sTemp;
1298 0 : }
1299 : }
1300 0 : aDesc.sBodyContent = sBody;
1301 0 : if(MM_DOCTYPE_HTML == nDocType)
1302 : {
1303 0 : aDesc.sBodyMimeType = ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("text/html; charset="));
1304 : aDesc.sBodyMimeType += ::rtl::OUString::createFromAscii(
1305 0 : rtl_getBestMimeCharsetFromTextEncoding( eEncoding ));
1306 : }
1307 : else
1308 : aDesc.sBodyMimeType =
1309 0 : ::rtl::OUString(RTL_CONSTASCII_USTRINGPARAM("text/plain; charset=UTF-8; format=flowed"));
1310 :
1311 0 : aDesc.sSubject = m_aSubjectED.GetText();
1312 0 : aDesc.sCC = m_sCC;
1313 0 : aDesc.sBCC = m_sBCC;
1314 0 : pDlg->AddDocument( aDesc );
1315 : //help to force painting the dialog
1316 0 : for ( sal_Int16 i = 0; i < 25; i++)
1317 0 : Application::Reschedule();
1318 : //stop creating of data when dialog has been closed
1319 0 : if(!pDlg->IsVisible())
1320 : {
1321 0 : m_pWizard->LeaveWait();
1322 : break;
1323 : }
1324 0 : m_pWizard->LeaveWait();
1325 0 : }
1326 0 : pDlg->EnableDesctruction();
1327 0 : ::osl::File::remove( sTargetTempURL );
1328 :
1329 0 : m_pWizard->enableButtons(WZB_FINISH, sal_True);
1330 : //the dialog deletes itself
1331 : //delete pDlg;
1332 0 : return 0;
1333 0 : }
1334 :
1335 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|