update credits
[LibreOffice.git] / sw / source / ui / dbui / mailmergechildwindow.cxx
blob49bcc64d0eba9c66807fc8237677c69d51980d1f
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
20 #include <sfx2/viewfrm.hxx>
21 #include <sfx2/dispatch.hxx>
23 #include <cmdid.h>
24 #include <swmodule.hxx>
25 #include <view.hxx>
26 #include <edtwin.hxx>
27 #include <vcl/svapp.hxx>
28 #include <mailmergechildwindow.hxx>
29 #include <mmoutputpage.hxx>
30 #include <mmconfigitem.hxx>
31 #include <comphelper/processfactory.hxx>
32 #include <comphelper/string.hxx>
33 #include "com/sun/star/mail/XSmtpService.hpp"
34 #include "com/sun/star/mail/MailServiceType.hpp"
35 #include <rtl/ref.hxx>
36 #include <maildispatcher.hxx>
37 #include <imaildsplistener.hxx>
38 #include <swunohelper.hxx>
39 #include <svtools/svmedit.hxx>
40 #include <vcl/msgbox.hxx>
41 #include <vcl/image.hxx>
42 #include <mailmergechildwindow.hrc>
43 #include <dbui.hrc>
44 #include <helpid.h>
46 using namespace ::com::sun::star;
48 SFX_IMPL_FLOATINGWINDOW( SwMailMergeChildWindow, FN_MAILMERGE_CHILDWINDOW )
50 SwMailMergeChildWindow::SwMailMergeChildWindow( Window* _pParent,
51 sal_uInt16 nId,
52 SfxBindings* pBindings,
53 SfxChildWinInfo* pInfo ) :
54 SfxChildWindow( _pParent, nId )
56 pWindow = new SwMailMergeChildWin( pBindings, this, _pParent);
58 if (!pInfo->aSize.Width() || !pInfo->aSize.Height())
60 SwView* pActiveView = ::GetActiveView();
61 if(pActiveView)
63 const SwEditWin &rEditWin = pActiveView->GetEditWin();
64 pWindow->SetPosPixel(rEditWin.OutputToScreenPixel(Point(0, 0)));
66 else
67 pWindow->SetPosPixel(_pParent->OutputToScreenPixel(Point(0, 0)));
68 pInfo->aPos = pWindow->GetPosPixel();
69 pInfo->aSize = pWindow->GetSizePixel();
72 ((SwMailMergeChildWin *)pWindow)->Initialize(pInfo);
73 pWindow->Show();
76 SwMailMergeChildWin::SwMailMergeChildWin( SfxBindings* _pBindings,
77 SfxChildWindow* pChild,
78 Window *pParent) :
79 SfxFloatingWindow(_pBindings, pChild, pParent, SW_RES(DLG_MAILMERGECHILD)),
80 m_aBackTB(this, SW_RES( TB_BACK ))
82 m_aBackTB.SetSelectHdl(LINK(this, SwMailMergeChildWin, BackHdl));
83 sal_uInt16 nIResId = ILIST_TBX;
84 ResId aResId( nIResId, *pSwResMgr );
85 ImageList aIList(aResId);
86 FreeResource();
88 m_aBackTB.SetItemImage( 1, aIList.GetImage(FN_SHOW_ROOT) );
89 m_aBackTB.SetButtonType( BUTTON_SYMBOLTEXT );
90 Size aSz = m_aBackTB.CalcWindowSizePixel(1);
91 m_aBackTB.SetPosSizePixel( Point(), aSz );
92 SetOutputSizePixel(aSz);
93 m_aBackTB.Show();
96 SwMailMergeChildWin::~SwMailMergeChildWin()
100 IMPL_LINK_NOARG(SwMailMergeChildWin, BackHdl)
102 GetBindings().GetDispatcher()->Execute(FN_MAILMERGE_WIZARD, SFX_CALLMODE_ASYNCHRON);
103 return 0;
106 void SwMailMergeChildWin::FillInfo(SfxChildWinInfo& rInfo) const
108 SfxFloatingWindow::FillInfo(rInfo);
109 rInfo.aWinState = OString();
110 rInfo.bVisible = sal_False;
113 struct SwSendMailDialog_Impl
115 friend class SwSendMailDialog;
116 ::osl::Mutex aDescriptorMutex;
118 ::std::vector< SwMailDescriptor > aDescriptors;
119 sal_uInt32 nCurrentDescriptor;
120 sal_uInt32 nDocumentCount;
121 ::rtl::Reference< MailDispatcher > xMailDispatcher;
122 ::rtl::Reference< IMailDispatcherListener> xMailListener;
123 uno::Reference< mail::XMailService > xConnectedMailService;
124 uno::Reference< mail::XMailService > xConnectedInMailService;
125 Timer aRemoveTimer;
128 SwSendMailDialog_Impl() :
129 nCurrentDescriptor(0),
130 nDocumentCount(0)
132 aRemoveTimer.SetTimeout(500);
135 ~SwSendMailDialog_Impl()
137 // Shutdown must be called when the last reference to the
138 // mail dispatcher will be released in order to force a
139 // shutdown of the mail dispatcher thread.
140 // 'join' with the mail dispatcher thread leads to a
141 // deadlock (SolarMutex).
142 if( xMailDispatcher.is() && !xMailDispatcher->isShutdownRequested() )
143 xMailDispatcher->shutdown();
145 const SwMailDescriptor* GetNextDescriptor();
148 const SwMailDescriptor* SwSendMailDialog_Impl::GetNextDescriptor()
150 ::osl::MutexGuard aGuard(aDescriptorMutex);
151 if(nCurrentDescriptor < aDescriptors.size())
153 ++nCurrentDescriptor;
154 return &aDescriptors[nCurrentDescriptor - 1];
156 return 0;
159 class SwMailDispatcherListener_Impl : public IMailDispatcherListener
161 SwSendMailDialog* m_pSendMailDialog;
163 public:
164 SwMailDispatcherListener_Impl(SwSendMailDialog& rParentDlg);
165 ~SwMailDispatcherListener_Impl();
167 virtual void started(::rtl::Reference<MailDispatcher> xMailDispatcher);
168 virtual void stopped(::rtl::Reference<MailDispatcher> xMailDispatcher);
169 virtual void idle(::rtl::Reference<MailDispatcher> xMailDispatcher);
170 virtual void mailDelivered(::rtl::Reference<MailDispatcher> xMailDispatcher,
171 uno::Reference< mail::XMailMessage> xMailMessage);
172 virtual void mailDeliveryError(::rtl::Reference<MailDispatcher> xMailDispatcher,
173 uno::Reference< mail::XMailMessage> xMailMessage, const OUString& sErrorMessage);
175 static void DeleteAttachments( uno::Reference< mail::XMailMessage >& xMessage );
178 SwMailDispatcherListener_Impl::SwMailDispatcherListener_Impl(SwSendMailDialog& rParentDlg) :
179 m_pSendMailDialog(&rParentDlg)
183 SwMailDispatcherListener_Impl::~SwMailDispatcherListener_Impl()
187 void SwMailDispatcherListener_Impl::started(::rtl::Reference<MailDispatcher> /*xMailDispatcher*/)
191 void SwMailDispatcherListener_Impl::stopped(
192 ::rtl::Reference<MailDispatcher> /*xMailDispatcher*/)
196 void SwMailDispatcherListener_Impl::idle(::rtl::Reference<MailDispatcher> /*xMailDispatcher*/)
198 SolarMutexGuard aGuard;
199 m_pSendMailDialog->AllMailsSent();
202 void SwMailDispatcherListener_Impl::mailDelivered(
203 ::rtl::Reference<MailDispatcher> /*xMailDispatcher*/,
204 uno::Reference< mail::XMailMessage> xMailMessage)
206 SolarMutexGuard aGuard;
207 m_pSendMailDialog->DocumentSent( xMailMessage, true, 0 );
208 DeleteAttachments( xMailMessage );
211 void SwMailDispatcherListener_Impl::mailDeliveryError(
212 ::rtl::Reference<MailDispatcher> /*xMailDispatcher*/,
213 uno::Reference< mail::XMailMessage> xMailMessage,
214 const OUString& sErrorMessage)
216 SolarMutexGuard aGuard;
217 m_pSendMailDialog->DocumentSent( xMailMessage, false, &sErrorMessage );
218 DeleteAttachments( xMailMessage );
221 void SwMailDispatcherListener_Impl::DeleteAttachments( uno::Reference< mail::XMailMessage >& xMessage )
223 uno::Sequence< mail::MailAttachment > aAttachments = xMessage->getAttachments();
225 for(sal_Int32 nFile = 0; nFile < aAttachments.getLength(); ++nFile)
229 uno::Reference< beans::XPropertySet > xTransferableProperties( aAttachments[nFile].Data, uno::UNO_QUERY_THROW);
230 if( xTransferableProperties.is() )
232 OUString sURL;
233 xTransferableProperties->getPropertyValue( OUString("URL") ) >>= sURL;
234 if(!sURL.isEmpty())
235 SWUnoHelper::UCB_DeleteFile( sURL );
238 catch (const uno::Exception&)
244 class SwSendWarningBox_Impl : public ModalDialog
246 FixedImage aWarningImageIM;
247 FixedInfo aWarningFI;
248 FixedText aDetailFT;
249 MultiLineEdit aDetailED;
250 FixedLine aSeparatorFL;
251 OKButton aOKPB;
253 public:
254 SwSendWarningBox_Impl(Window* pParent, const String& rDetails);
255 ~SwSendWarningBox_Impl();
258 SwSendWarningBox_Impl::SwSendWarningBox_Impl(Window* pParent, const String& rDetails) :
259 ModalDialog(pParent, SW_RES( DLG_MM_SENDWARNING )),
260 aWarningImageIM(this, SW_RES( IM_WARNING )),
261 aWarningFI( this, SW_RES( FI_WARNING )),
262 aDetailFT( this, SW_RES( FT_DETAILS )),
263 aDetailED( this, SW_RES( ED_DETAILS )),
264 aSeparatorFL( this, SW_RES( FL_SEPARATOR )),
265 aOKPB( this, SW_RES(PB_OK))
267 FreeResource();
268 aWarningImageIM.SetImage(WarningBox::GetStandardImage());
269 aDetailED.SetText(rDetails);
272 SwSendWarningBox_Impl::~SwSendWarningBox_Impl()
276 #define ITEMID_TASK 1
277 #define ITEMID_STATUS 2
279 SwSendMailDialog::SwSendMailDialog(Window *pParent, SwMailMergeConfigItem& rConfigItem) :
280 ModelessDialog /*SfxModalDialog*/(pParent, SW_RES(DLG_MM_SENDMAILS)),
281 #ifdef _MSC_VER
282 #pragma warning (disable : 4355)
283 #endif
284 m_aStatusFL( this, SW_RES( FL_STATUS )),
285 m_aStatusFT( this, SW_RES( FT_STATUS1 )),
286 m_aTransferStatusFL( this, SW_RES( FL_TRANSFERSTATUS )),
287 m_aTransferStatusFT( this, SW_RES( FT_TRANSFERSTATUS )),
288 m_PausedFI(this, SW_RES( FI_PAUSED )),
289 m_aProgressBar( this, SW_RES( PB_PROGRESS )),
290 m_aErrorStatusFT( this, SW_RES( FT_ERRORSTATUS )),
291 m_aDetailsPB( this, SW_RES( PB_DETAILS )),
292 m_aStatusHB( this, WB_BUTTONSTYLE | WB_BOTTOMBORDER ),
293 m_aStatusLB( this, SW_RES( LB_STATUS )),
294 m_aSeparatorFL( this, SW_RES( FL_SEPARATOR )),
295 m_aStopPB( this, SW_RES( PB_STOP )),
296 m_aClosePB( this, SW_RES( PB_CLOSE )),
297 #ifdef _MSC_VER
298 #pragma warning (default : 4355)
299 #endif
300 m_sMore(m_aDetailsPB.GetText()),
301 m_sLess(SW_RES(ST_LESS)),
302 m_sContinue(SW_RES( ST_CONTINUE )),
303 m_sStop(m_aStopPB.GetText()),
304 m_sSend(SW_RES(ST_SEND)),
305 m_sTransferStatus(m_aTransferStatusFT.GetText()),
306 m_sErrorStatus( m_aErrorStatusFT.GetText()),
307 m_sSendingTo( SW_RES(ST_SENDINGTO )),
308 m_sCompleted( SW_RES(ST_COMPLETED )),
309 m_sFailed( SW_RES(ST_FAILED )),
310 m_sTerminateQuery( SW_RES( ST_TERMINATEQUERY )),
311 m_bCancel(false),
312 m_bDesctructionEnabled(false),
313 m_aImageList( SW_RES( ILIST ) ),
314 m_pImpl(new SwSendMailDialog_Impl),
315 m_pConfigItem(&rConfigItem),
316 m_nSendCount(0),
317 m_nErrorCount(0)
319 m_nStatusHeight = m_aSeparatorFL.GetPosPixel().Y() - m_aStatusLB.GetPosPixel().Y();
320 String sTask(SW_RES(ST_TASK));
321 String sStatus(SW_RES(ST_STATUS));
322 m_aStatusLB.SetHelpId(HID_MM_SENDMAILS_STATUSLB);
324 FreeResource();
326 m_aDetailsPB.SetClickHdl(LINK( this, SwSendMailDialog, DetailsHdl_Impl));
327 m_aStopPB.SetClickHdl(LINK( this, SwSendMailDialog, StopHdl_Impl));
328 m_aClosePB.SetClickHdl(LINK( this, SwSendMailDialog, CloseHdl_Impl));
331 Size aLBSize(m_aStatusLB.GetSizePixel());
332 m_aStatusHB.SetSizePixel(aLBSize);
333 Size aHeadSize(m_aStatusHB.CalcWindowSizePixel());
334 aHeadSize.Width() = aLBSize.Width();
335 m_aStatusHB.SetSizePixel(aHeadSize);
336 Point aLBPos(m_aStatusLB.GetPosPixel());
337 m_aStatusHB.SetPosPixel(aLBPos);
338 aLBPos.Y() += aHeadSize.Height();
339 aLBSize.Height() -= aHeadSize.Height();
340 m_aStatusLB.SetPosSizePixel(aLBPos, aLBSize);
342 Size aSz(m_aStatusHB.GetOutputSizePixel());
343 long nPos1 = aSz.Width()/3 * 2;
344 long nPos2 = aSz.Width()/3;
345 m_aStatusHB.InsertItem( ITEMID_TASK, sTask,
346 nPos1,
347 HIB_LEFT | HIB_VCENTER );
348 m_aStatusHB.InsertItem( ITEMID_STATUS, sStatus,
349 nPos2,
350 HIB_LEFT | HIB_VCENTER );
351 m_aStatusHB.SetHelpId(HID_MM_ADDRESSLIST_HB );
352 m_aStatusHB.Show();
354 m_aStatusLB.SetHelpId(HID_MM_MAILSTATUS_TLB);
355 static long nTabs[] = {3, 0, nPos1, aSz.Width() };
356 m_aStatusLB.SetStyle( m_aStatusLB.GetStyle() | WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP );
357 m_aStatusLB.SetSelectionMode( SINGLE_SELECTION );
358 m_aStatusLB.SetTabs(&nTabs[0], MAP_PIXEL);
359 m_aStatusLB.SetSpaceBetweenEntries(3);
361 DetailsHdl_Impl( &m_aDetailsPB );
362 UpdateTransferStatus();
365 SwSendMailDialog::~SwSendMailDialog()
367 if(m_pImpl->xMailDispatcher.is())
371 if(m_pImpl->xMailDispatcher->isStarted())
372 m_pImpl->xMailDispatcher->stop();
373 if(m_pImpl->xConnectedMailService.is() && m_pImpl->xConnectedMailService->isConnected())
374 m_pImpl->xConnectedMailService->disconnect();
375 if(m_pImpl->xConnectedInMailService.is() && m_pImpl->xConnectedInMailService->isConnected())
376 m_pImpl->xConnectedInMailService->disconnect();
378 uno::Reference<mail::XMailMessage> xMessage =
379 m_pImpl->xMailDispatcher->dequeueMailMessage();
380 while(xMessage.is())
382 SwMailDispatcherListener_Impl::DeleteAttachments( xMessage );
383 xMessage = m_pImpl->xMailDispatcher->dequeueMailMessage();
386 catch (const uno::Exception&)
390 delete m_pImpl;
393 void SwSendMailDialog::AddDocument( SwMailDescriptor& rDesc )
395 ::osl::MutexGuard aGuard(m_pImpl->aDescriptorMutex);
396 m_pImpl->aDescriptors.push_back(rDesc);
397 // if the dialog is already running then continue sending of documents
398 if(m_pImpl->xMailDispatcher.is())
400 IterateMails();
405 void SwSendMailDialog::SetDocumentCount( sal_Int32 nAllDocuments )
407 m_pImpl->nDocumentCount = nAllDocuments;
408 UpdateTransferStatus();
411 static void lcl_Move(Control& rCtrl, long nYOffset)
413 Point aPos(rCtrl.GetPosPixel());
414 aPos.Y() += nYOffset;
415 rCtrl.SetPosPixel(aPos);
418 IMPL_LINK_NOARG(SwSendMailDialog, DetailsHdl_Impl)
420 long nMove = 0;
421 if(m_aStatusLB.IsVisible())
423 m_aStatusLB.Hide();
424 m_aStatusHB.Hide();
425 nMove = - m_nStatusHeight;
426 m_aDetailsPB.SetText(m_sMore);
428 else
430 m_aStatusLB.Show();
431 m_aStatusHB.Show();
432 nMove = m_nStatusHeight;
433 m_aDetailsPB.SetText(m_sLess);
435 lcl_Move(m_aSeparatorFL, nMove);
436 lcl_Move(m_aStopPB, nMove);
437 lcl_Move(m_aClosePB, nMove);
438 Size aDlgSize = GetSizePixel(); aDlgSize.Height() += nMove; SetSizePixel(aDlgSize);
440 return 0;
443 IMPL_LINK( SwSendMailDialog, StopHdl_Impl, PushButton*, pButton )
445 m_bCancel = true;
446 if(m_pImpl->xMailDispatcher.is())
448 if(m_pImpl->xMailDispatcher->isStarted())
450 m_pImpl->xMailDispatcher->stop();
451 pButton->SetText(m_sContinue);
452 m_PausedFI.Show();
454 else
456 m_pImpl->xMailDispatcher->start();
457 pButton->SetText(m_sStop);
458 m_PausedFI.Show(sal_False);
461 return 0;
464 IMPL_LINK_NOARG(SwSendMailDialog, CloseHdl_Impl)
466 ModelessDialog::Show( sal_False );
467 return 0;
470 IMPL_STATIC_LINK_NOINSTANCE( SwSendMailDialog, StartSendMails, SwSendMailDialog*, pDialog )
472 pDialog->SendMails();
473 return 0;
476 IMPL_STATIC_LINK( SwSendMailDialog, RemoveThis, Timer*, pTimer )
478 if( pThis->m_pImpl->xMailDispatcher.is() )
480 if(pThis->m_pImpl->xMailDispatcher->isStarted())
481 pThis->m_pImpl->xMailDispatcher->stop();
482 if(!pThis->m_pImpl->xMailDispatcher->isShutdownRequested())
483 pThis->m_pImpl->xMailDispatcher->shutdown();
486 if( pThis->m_bDesctructionEnabled &&
487 (!pThis->m_pImpl->xMailDispatcher.is() ||
488 !pThis->m_pImpl->xMailDispatcher->isRunning()))
490 delete pThis;
492 else
494 pTimer->Start();
496 return 0;
499 IMPL_STATIC_LINK_NOINSTANCE( SwSendMailDialog, StopSendMails, SwSendMailDialog*, pDialog )
501 if(pDialog->m_pImpl->xMailDispatcher.is() &&
502 pDialog->m_pImpl->xMailDispatcher->isStarted())
504 pDialog->m_pImpl->xMailDispatcher->stop();
505 pDialog->m_aStopPB.SetText(pDialog->m_sContinue);
506 pDialog->m_PausedFI.Show();
508 return 0;
511 void SwSendMailDialog::SendMails()
513 if(!m_pConfigItem)
515 OSL_FAIL("config item not set");
516 return;
518 EnterWait();
519 //get a mail server connection
520 uno::Reference< mail::XSmtpService > xSmtpServer =
521 SwMailMergeHelper::ConnectToSmtpServer( *m_pConfigItem,
522 m_pImpl->xConnectedInMailService,
523 aEmptyStr, aEmptyStr, this );
524 bool bIsLoggedIn = xSmtpServer.is() && xSmtpServer->isConnected();
525 LeaveWait();
526 if(!bIsLoggedIn)
528 OSL_FAIL("create error message");
529 return;
531 m_pImpl->xMailDispatcher.set( new MailDispatcher(xSmtpServer));
532 IterateMails();
533 m_pImpl->xMailListener = new SwMailDispatcherListener_Impl(*this);
534 m_pImpl->xMailDispatcher->addListener(m_pImpl->xMailListener);
535 if(!m_bCancel)
537 m_pImpl->xMailDispatcher->start();
541 void SwSendMailDialog::IterateMails()
543 const SwMailDescriptor* pCurrentMailDescriptor = m_pImpl->GetNextDescriptor();
544 while( pCurrentMailDescriptor )
546 if(!SwMailMergeHelper::CheckMailAddress( pCurrentMailDescriptor->sEMail ))
548 Image aInsertImg = m_aImageList.GetImage( FN_FORMULA_CANCEL );
550 String sMessage = m_sSendingTo;
551 String sTmp(pCurrentMailDescriptor->sEMail);
552 sTmp += '\t';
553 sTmp += m_sFailed;
554 sMessage.SearchAndReplaceAscii("%1", sTmp);
555 m_aStatusLB.InsertEntry( sMessage, aInsertImg, aInsertImg);
556 ++m_nSendCount;
557 ++m_nErrorCount;
558 UpdateTransferStatus( );
559 pCurrentMailDescriptor = m_pImpl->GetNextDescriptor();
560 continue;
562 SwMailMessage* pMessage = new SwMailMessage;
563 uno::Reference< mail::XMailMessage > xMessage = pMessage;
564 if(m_pConfigItem->IsMailReplyTo())
565 pMessage->setReplyToAddress(m_pConfigItem->GetMailReplyTo());
566 pMessage->addRecipient( pCurrentMailDescriptor->sEMail );
567 pMessage->SetSenderName( m_pConfigItem->GetMailDisplayName() );
568 pMessage->SetSenderAddress( m_pConfigItem->GetMailAddress() );
569 if(!pCurrentMailDescriptor->sAttachmentURL.isEmpty())
571 mail::MailAttachment aAttach;
572 aAttach.Data =
573 new SwMailTransferable(
574 pCurrentMailDescriptor->sAttachmentURL,
575 pCurrentMailDescriptor->sAttachmentName,
576 pCurrentMailDescriptor->sMimeType );
577 aAttach.ReadableName = pCurrentMailDescriptor->sAttachmentName;
578 pMessage->addAttachment( aAttach );
580 pMessage->setSubject( pCurrentMailDescriptor->sSubject );
581 uno::Reference< datatransfer::XTransferable> xBody =
582 new SwMailTransferable(
583 pCurrentMailDescriptor->sBodyContent,
584 pCurrentMailDescriptor->sBodyMimeType);
585 pMessage->setBody( xBody );
587 //CC and BCC are tokenized by ';'
588 if(!pCurrentMailDescriptor->sCC.isEmpty())
590 String sTokens( pCurrentMailDescriptor->sCC );
591 sal_uInt16 nTokens = comphelper::string::getTokenCount(sTokens, ';');
592 sal_Int32 nPos = 0;
593 for( sal_uInt16 nToken = 0; nToken < nTokens; ++nToken)
595 String sTmp = sTokens.GetToken( 0, ';', nPos);
596 if( sTmp.Len() )
597 pMessage->addCcRecipient( sTmp );
600 if(!pCurrentMailDescriptor->sBCC.isEmpty())
602 String sTokens( pCurrentMailDescriptor->sBCC );
603 sal_uInt16 nTokens = comphelper::string::getTokenCount(sTokens, ';');
604 sal_Int32 nPos = 0;
605 for( sal_uInt16 nToken = 0; nToken < nTokens; ++nToken)
607 String sTmp = sTokens.GetToken( 0, ';', nPos);
608 if( sTmp.Len() )
609 pMessage->addBccRecipient( sTmp );
612 m_pImpl->xMailDispatcher->enqueueMailMessage( xMessage );
613 pCurrentMailDescriptor = m_pImpl->GetNextDescriptor();
615 UpdateTransferStatus();
618 void SwSendMailDialog::ShowDialog()
620 Application::PostUserEvent( STATIC_LINK( this, SwSendMailDialog,
621 StartSendMails ), this );
622 ModelessDialog::Show();
625 void SwSendMailDialog::StateChanged( StateChangedType nStateChange )
627 ModelessDialog::StateChanged( nStateChange );
628 if(STATE_CHANGE_VISIBLE == nStateChange && !IsVisible())
630 m_pImpl->aRemoveTimer.SetTimeoutHdl( STATIC_LINK( this, SwSendMailDialog,
631 RemoveThis ) );
632 m_pImpl->aRemoveTimer.Start();
636 void SwSendMailDialog::DocumentSent( uno::Reference< mail::XMailMessage> xMessage,
637 bool bResult,
638 const OUString* pError )
640 //sending should stop on send errors
641 if(pError &&
642 m_pImpl->xMailDispatcher.is() && m_pImpl->xMailDispatcher->isStarted())
644 Application::PostUserEvent( STATIC_LINK( this, SwSendMailDialog,
645 StopSendMails ), this );
647 Image aInsertImg = m_aImageList.GetImage( bResult ? FN_FORMULA_APPLY : FN_FORMULA_CANCEL );
649 String sMessage = m_sSendingTo;
650 String sTmp(xMessage->getRecipients()[0]);
651 sTmp += '\t';
652 sTmp += bResult ? m_sCompleted : m_sFailed;
653 sMessage.SearchAndReplaceAscii("%1", sTmp);
654 m_aStatusLB.InsertEntry( sMessage, aInsertImg, aInsertImg);
655 ++m_nSendCount;
656 if(!bResult)
657 ++m_nErrorCount;
659 UpdateTransferStatus( );
660 if(pError)
662 SwSendWarningBox_Impl* pDlg = new SwSendWarningBox_Impl(0, *pError);
663 pDlg->Execute();
664 delete pDlg;
668 void SwSendMailDialog::UpdateTransferStatus()
670 String sStatus( m_sTransferStatus );
671 sStatus.SearchAndReplaceAscii("%1", OUString::number(m_nSendCount) );
672 sStatus.SearchAndReplaceAscii("%2", OUString::number(m_pImpl->nDocumentCount));
673 m_aTransferStatusFT.SetText(sStatus);
675 sStatus = m_sErrorStatus;
676 sStatus.SearchAndReplaceAscii("%1", OUString::number(m_nErrorCount) );
677 m_aErrorStatusFT.SetText(sStatus);
679 if(m_pImpl->aDescriptors.size())
680 m_aProgressBar.SetValue((sal_uInt16)(m_nSendCount * 100 / m_pImpl->aDescriptors.size()));
681 else
682 m_aProgressBar.SetValue(0);
685 void SwSendMailDialog::AllMailsSent()
687 m_aStopPB.Enable(sal_False);
691 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */