Update ooo320-m1
[ooovba.git] / sw / source / ui / dbui / mailmergechildwindow.cxx
blobca506787a4db11a12b5a0a02452b213db2a77dbb
1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4 *
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: mailmergechildwindow.cxx,v $
10 * $Revision: 1.14 $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_sw.hxx"
35 #include <sfx2/viewfrm.hxx>
36 #include <sfx2/dispatch.hxx>
38 #include <cmdid.h>
39 #include <swmodule.hxx>
40 #include <view.hxx>
41 #include <edtwin.hxx>
42 #include <vcl/svapp.hxx>
43 #include <mailmergechildwindow.hxx>
44 #include <mmoutputpage.hxx>
45 #include <mmconfigitem.hxx>
46 #include <comphelper/processfactory.hxx>
47 #include "com/sun/star/mail/XSmtpService.hpp"
48 #include "com/sun/star/mail/MailServiceType.hpp"
49 #include <rtl/ref.hxx>
50 #include <maildispatcher.hxx>
51 #include <imaildsplistener.hxx>
52 #include <swunohelper.hxx>
53 #include <svtools/svmedit.hxx>
54 #include <vcl/msgbox.hxx>
55 #include <vcl/image.hxx>
56 #include <mailmergechildwindow.hrc>
57 #include <dbui.hrc>
58 #include <helpid.h>
60 using namespace ::com::sun::star;
62 SFX_IMPL_FLOATINGWINDOW( SwMailMergeChildWindow, FN_MAILMERGE_CHILDWINDOW )
63 //SFX_IMPL_FLOATINGWINDOW( SwSendMailChildWindow, FN_MAILMERGE_SENDMAIL_CHILDWINDOW )
65 /*------------------------------------------------------------------------
66 Beschreibung:
67 ------------------------------------------------------------------------*/
69 SwMailMergeChildWindow::SwMailMergeChildWindow( Window* _pParent,
70 USHORT nId,
71 SfxBindings* pBindings,
72 SfxChildWinInfo* pInfo ) :
73 SfxChildWindow( _pParent, nId )
75 pWindow = new SwMailMergeChildWin( pBindings, this, _pParent);
77 if (!pInfo->aSize.Width() || !pInfo->aSize.Height())
79 SwView* pActiveView = ::GetActiveView();
80 if(pActiveView)
82 const SwEditWin &rEditWin = pActiveView->GetEditWin();
83 pWindow->SetPosPixel(rEditWin.OutputToScreenPixel(Point(0, 0)));
85 else
86 pWindow->SetPosPixel(_pParent->OutputToScreenPixel(Point(0, 0)));
87 pInfo->aPos = pWindow->GetPosPixel();
88 pInfo->aSize = pWindow->GetSizePixel();
91 ((SwMailMergeChildWin *)pWindow)->Initialize(pInfo);
92 pWindow->Show();
95 /*------------------------------------------------------------------------
96 Beschreibung:
97 ------------------------------------------------------------------------*/
99 SwMailMergeChildWin::SwMailMergeChildWin( SfxBindings* _pBindings,
100 SfxChildWindow* pChild,
101 Window *pParent) :
102 SfxFloatingWindow(_pBindings, pChild, pParent, SW_RES(DLG_MAILMERGECHILD)),
103 m_aBackTB(this, SW_RES( TB_BACK ))
105 m_aBackTB.SetSelectHdl(LINK(this, SwMailMergeChildWin, BackHdl));
106 sal_uInt16 nIResId = GetSettings().GetStyleSettings().GetWindowColor().IsDark() ?
107 ILIST_TBX_HC : ILIST_TBX;
108 ResId aResId( nIResId, *pSwResMgr );
109 ImageList aIList(aResId);
110 FreeResource();
112 m_aBackTB.SetItemImage( 1, aIList.GetImage(FN_SHOW_ROOT) );
113 m_aBackTB.SetButtonType( BUTTON_SYMBOLTEXT );
114 Size aSz = m_aBackTB.CalcWindowSizePixel(1);
115 m_aBackTB.SetPosSizePixel( Point(), aSz );
116 SetOutputSizePixel(aSz);
117 m_aBackTB.Show();
120 /*------------------------------------------------------------------------
121 Beschreibung:
122 ------------------------------------------------------------------------*/
124 SwMailMergeChildWin::~SwMailMergeChildWin()
128 /*--------------------------------------------------------------------
129 Beschreibung:
130 --------------------------------------------------------------------*/
132 IMPL_LINK( SwMailMergeChildWin, BackHdl, ToolBox *, EMPTYARG )
134 GetBindings().GetDispatcher()->Execute(FN_MAILMERGE_WIZARD, SFX_CALLMODE_ASYNCHRON);
135 return 0;
138 /*-- 26.05.2004 10:12:44---------------------------------------------------
140 -----------------------------------------------------------------------*/
141 void SwMailMergeChildWin::FillInfo(SfxChildWinInfo& rInfo) const
143 SfxFloatingWindow::FillInfo(rInfo);
144 rInfo.aWinState.Erase();
145 rInfo.bVisible = sal_False;
147 /*-- 21.05.2004 14:07:37---------------------------------------------------
149 -----------------------------------------------------------------------*/
150 struct SwSendMailDialog_Impl
152 friend class SwSendMailDialog;
153 ::osl::Mutex aDescriptorMutex;
155 ::std::vector< SwMailDescriptor > aDescriptors;
156 sal_uInt32 nCurrentDescriptor;
157 sal_uInt32 nDocumentCount;
158 ::rtl::Reference< MailDispatcher > xMailDispatcher;
159 ::rtl::Reference< IMailDispatcherListener> xMailListener;
160 uno::Reference< mail::XMailService > xConnectedMailService;
161 uno::Reference< mail::XMailService > xConnectedInMailService;
162 Timer aRemoveTimer;
165 SwSendMailDialog_Impl() :
166 nCurrentDescriptor(0),
167 nDocumentCount(0)
169 aRemoveTimer.SetTimeout(500);
172 ~SwSendMailDialog_Impl()
174 // Shutdown must be called when the last reference to the
175 // mail dispatcher will be released in order to force a
176 // shutdown of the mail dispatcher thread.
177 // 'join' with the mail dispatcher thread leads to a
178 // deadlock (SolarMutex).
179 if( xMailDispatcher.is() && !xMailDispatcher->isShutdownRequested() )
180 xMailDispatcher->shutdown();
182 const SwMailDescriptor* GetNextDescriptor();
185 const SwMailDescriptor* SwSendMailDialog_Impl::GetNextDescriptor()
187 ::osl::MutexGuard aGuard(aDescriptorMutex);
188 if(nCurrentDescriptor < aDescriptors.size())
190 ++nCurrentDescriptor;
191 return &aDescriptors[nCurrentDescriptor - 1];
193 return 0;
196 /*-- 23.06.2004 10:19:55---------------------------------------------------
198 -----------------------------------------------------------------------*/
199 class SwMailDispatcherListener_Impl : public IMailDispatcherListener
201 SwSendMailDialog* m_pSendMailDialog;
203 public:
204 SwMailDispatcherListener_Impl(SwSendMailDialog& rParentDlg);
205 ~SwMailDispatcherListener_Impl();
207 virtual void started(::rtl::Reference<MailDispatcher> xMailDispatcher);
208 virtual void stopped(::rtl::Reference<MailDispatcher> xMailDispatcher);
209 virtual void idle(::rtl::Reference<MailDispatcher> xMailDispatcher);
210 virtual void mailDelivered(::rtl::Reference<MailDispatcher> xMailDispatcher,
211 uno::Reference< mail::XMailMessage> xMailMessage);
212 virtual void mailDeliveryError(::rtl::Reference<MailDispatcher> xMailDispatcher,
213 uno::Reference< mail::XMailMessage> xMailMessage, const rtl::OUString& sErrorMessage);
215 static void DeleteAttachments( uno::Reference< mail::XMailMessage >& xMessage );
218 /*-- 23.06.2004 10:04:48---------------------------------------------------
220 -----------------------------------------------------------------------*/
221 SwMailDispatcherListener_Impl::SwMailDispatcherListener_Impl(SwSendMailDialog& rParentDlg) :
222 m_pSendMailDialog(&rParentDlg)
225 /*-- 23.06.2004 10:04:48---------------------------------------------------
227 -----------------------------------------------------------------------*/
228 SwMailDispatcherListener_Impl::~SwMailDispatcherListener_Impl()
231 /*-- 23.06.2004 10:04:49---------------------------------------------------
233 -----------------------------------------------------------------------*/
234 void SwMailDispatcherListener_Impl::started(::rtl::Reference<MailDispatcher> /*xMailDispatcher*/)
237 /*-- 23.06.2004 10:04:49---------------------------------------------------
239 -----------------------------------------------------------------------*/
240 void SwMailDispatcherListener_Impl::stopped(
241 ::rtl::Reference<MailDispatcher> /*xMailDispatcher*/)
244 /*-- 23.06.2004 10:04:49---------------------------------------------------
246 -----------------------------------------------------------------------*/
247 void SwMailDispatcherListener_Impl::idle(::rtl::Reference<MailDispatcher> /*xMailDispatcher*/)
249 vos::OGuard aGuard(Application::GetSolarMutex());
250 m_pSendMailDialog->AllMailsSent();
252 /*-- 23.06.2004 10:04:50---------------------------------------------------
254 -----------------------------------------------------------------------*/
255 void SwMailDispatcherListener_Impl::mailDelivered(
256 ::rtl::Reference<MailDispatcher> /*xMailDispatcher*/,
257 uno::Reference< mail::XMailMessage> xMailMessage)
259 vos::OGuard aGuard(Application::GetSolarMutex());
260 m_pSendMailDialog->DocumentSent( xMailMessage, true, 0 );
261 DeleteAttachments( xMailMessage );
263 /*-- 23.06.2004 10:04:51---------------------------------------------------
265 -----------------------------------------------------------------------*/
266 void SwMailDispatcherListener_Impl::mailDeliveryError(
267 ::rtl::Reference<MailDispatcher> /*xMailDispatcher*/,
268 uno::Reference< mail::XMailMessage> xMailMessage,
269 const rtl::OUString& sErrorMessage)
271 vos::OGuard aGuard(Application::GetSolarMutex());
272 m_pSendMailDialog->DocumentSent( xMailMessage, false, &sErrorMessage );
273 DeleteAttachments( xMailMessage );
275 /*-- 23.06.2004 12:30:39---------------------------------------------------
277 -----------------------------------------------------------------------*/
278 void SwMailDispatcherListener_Impl::DeleteAttachments( uno::Reference< mail::XMailMessage >& xMessage )
280 uno::Sequence< mail::MailAttachment > aAttachments = xMessage->getAttachments();
282 for(sal_Int32 nFile = 0; nFile < aAttachments.getLength(); ++nFile)
286 uno::Reference< beans::XPropertySet > xTransferableProperties( aAttachments[nFile].Data, uno::UNO_QUERY_THROW);
287 if( xTransferableProperties.is() )
289 ::rtl::OUString sURL;
290 xTransferableProperties->getPropertyValue( ::rtl::OUString::createFromAscii("URL") ) >>= sURL;
291 if(sURL.getLength())
292 SWUnoHelper::UCB_DeleteFile( sURL );
295 catch( const uno::Exception& rEx )
297 (void)rEx;
301 /*-- 07.07.2004 13:45:51---------------------------------------------------
303 -----------------------------------------------------------------------*/
304 class SwSendWarningBox_Impl : public ModalDialog
306 FixedImage aWarningImageIM;
307 FixedInfo aWarningFI;
308 FixedText aDetailFT;
309 MultiLineEdit aDetailED;
310 FixedLine aSeparatorFL;
311 OKButton aOKPB;
313 public:
314 SwSendWarningBox_Impl(Window* pParent, const String& rDetails);
315 ~SwSendWarningBox_Impl();
317 /*-- 07.07.2004 13:52:41---------------------------------------------------
319 -----------------------------------------------------------------------*/
320 SwSendWarningBox_Impl::SwSendWarningBox_Impl(Window* pParent, const String& rDetails) :
321 ModalDialog(pParent, SW_RES( DLG_MM_SENDWARNING )),
322 aWarningImageIM(this, SW_RES( IM_WARNING )),
323 aWarningFI( this, SW_RES( FI_WARNING )),
324 aDetailFT( this, SW_RES( FT_DETAILS )),
325 aDetailED( this, SW_RES( ED_DETAILS )),
326 aSeparatorFL( this, SW_RES( FL_SEPARATOR )),
327 aOKPB( this, SW_RES(PB_OK))
329 FreeResource();
330 aWarningImageIM.SetImage(WarningBox::GetStandardImage());
331 aDetailED.SetText(rDetails);
333 /*-- 07.07.2004 13:52:41---------------------------------------------------
335 -----------------------------------------------------------------------*/
336 SwSendWarningBox_Impl::~SwSendWarningBox_Impl()
340 /*-- 21.05.2004 14:10:39---------------------------------------------------
342 -----------------------------------------------------------------------*/
343 #define ITEMID_TASK 1
344 #define ITEMID_STATUS 2
346 SwSendMailDialog::SwSendMailDialog(Window *pParent, SwMailMergeConfigItem& rConfigItem) :
347 ModelessDialog /*SfxModalDialog*/(pParent, SW_RES(DLG_MM_SENDMAILS)),
348 #ifdef MSC
349 #pragma warning (disable : 4355)
350 #endif
351 m_aStatusFL( this, SW_RES( FL_STATUS )),
352 m_aStatusFT( this, SW_RES( FT_STATUS1 )),
353 m_aTransferStatusFL( this, SW_RES( FL_TRANSFERSTATUS )),
354 m_aTransferStatusFT( this, SW_RES( FT_TRANSFERSTATUS )),
355 m_PausedFI(this, SW_RES( FI_PAUSED )),
356 m_aProgressBar( this, SW_RES( PB_PROGRESS )),
357 m_aErrorStatusFT( this, SW_RES( FT_ERRORSTATUS )),
358 m_aDetailsPB( this, SW_RES( PB_DETAILS )),
359 m_aStatusHB( this, WB_BUTTONSTYLE | WB_BOTTOMBORDER ),
360 m_aStatusLB( this, SW_RES( LB_STATUS )),
361 m_aSeparatorFL( this, SW_RES( FL_SEPARATOR )),
362 m_aStopPB( this, SW_RES( PB_STOP )),
363 m_aClosePB( this, SW_RES( PB_CLOSE )),
364 #ifdef MSC
365 #pragma warning (default : 4355)
366 #endif
367 m_sMore(m_aDetailsPB.GetText()),
368 m_sLess(SW_RES(ST_LESS)),
369 m_sContinue(SW_RES( ST_CONTINUE )),
370 m_sStop(m_aStopPB.GetText()),
371 m_sSend(SW_RES(ST_SEND)),
372 m_sTransferStatus(m_aTransferStatusFT.GetText()),
373 m_sErrorStatus( m_aErrorStatusFT.GetText()),
374 m_sSendingTo( SW_RES(ST_SENDINGTO )),
375 m_sCompleted( SW_RES(ST_COMPLETED )),
376 m_sFailed( SW_RES(ST_FAILED )),
377 m_sTerminateQuery( SW_RES( ST_TERMINATEQUERY )),
378 m_bCancel(false),
379 m_bDesctructionEnabled(false),
380 m_aImageList( SW_RES( ILIST ) ),
381 m_aImageListHC( SW_RES( ILIST_HC ) ),
382 m_pImpl(new SwSendMailDialog_Impl),
383 m_pConfigItem(&rConfigItem),
384 m_nSendCount(0),
385 m_nErrorCount(0)
387 m_nStatusHeight = m_aSeparatorFL.GetPosPixel().Y() - m_aStatusLB.GetPosPixel().Y();
388 String sTask(SW_RES(ST_TASK));
389 String sStatus(SW_RES(ST_STATUS));
390 m_aStatusLB.SetHelpId(HID_MM_SENDMAILS_STATUSLB);
392 FreeResource();
394 m_aDetailsPB.SetClickHdl(LINK( this, SwSendMailDialog, DetailsHdl_Impl));
395 m_aStopPB.SetClickHdl(LINK( this, SwSendMailDialog, StopHdl_Impl));
396 m_aClosePB.SetClickHdl(LINK( this, SwSendMailDialog, CloseHdl_Impl));
399 Size aLBSize(m_aStatusLB.GetSizePixel());
400 m_aStatusHB.SetSizePixel(aLBSize);
401 Size aHeadSize(m_aStatusHB.CalcWindowSizePixel());
402 aHeadSize.Width() = aLBSize.Width();
403 m_aStatusHB.SetSizePixel(aHeadSize);
404 Point aLBPos(m_aStatusLB.GetPosPixel());
405 m_aStatusHB.SetPosPixel(aLBPos);
406 aLBPos.Y() += aHeadSize.Height();
407 aLBSize.Height() -= aHeadSize.Height();
408 m_aStatusLB.SetPosSizePixel(aLBPos, aLBSize);
410 Size aSz(m_aStatusHB.GetOutputSizePixel());
411 long nPos1 = aSz.Width()/3 * 2;
412 long nPos2 = aSz.Width()/3;
413 m_aStatusHB.InsertItem( ITEMID_TASK, sTask,
414 nPos1,
415 HIB_LEFT | HIB_VCENTER );
416 m_aStatusHB.InsertItem( ITEMID_STATUS, sStatus,
417 nPos2,
418 HIB_LEFT | HIB_VCENTER );
419 m_aStatusHB.SetHelpId(HID_MM_ADDRESSLIST_HB );
420 m_aStatusHB.Show();
422 m_aStatusLB.SetHelpId(HID_MM_MAILSTATUS_TLB);
423 static long nTabs[] = {3, 0, nPos1, aSz.Width() };
424 m_aStatusLB.SetWindowBits( WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP );
425 m_aStatusLB.SetSelectionMode( SINGLE_SELECTION );
426 m_aStatusLB.SetTabs(&nTabs[0], MAP_PIXEL);
427 m_aStatusLB.SetSpaceBetweenEntries(3);
429 DetailsHdl_Impl( &m_aDetailsPB );
430 UpdateTransferStatus();
432 /*-- 21.05.2004 14:10:39---------------------------------------------------
434 -----------------------------------------------------------------------*/
435 SwSendMailDialog::~SwSendMailDialog()
437 if(m_pImpl->xMailDispatcher.is())
441 if(m_pImpl->xMailDispatcher->isStarted())
442 m_pImpl->xMailDispatcher->stop();
443 if(m_pImpl->xConnectedMailService.is() && m_pImpl->xConnectedMailService->isConnected())
444 m_pImpl->xConnectedMailService->disconnect();
445 if(m_pImpl->xConnectedInMailService.is() && m_pImpl->xConnectedInMailService->isConnected())
446 m_pImpl->xConnectedInMailService->disconnect();
448 uno::Reference<mail::XMailMessage> xMessage =
449 m_pImpl->xMailDispatcher->dequeueMailMessage();
450 while(xMessage.is())
452 SwMailDispatcherListener_Impl::DeleteAttachments( xMessage );
453 xMessage = m_pImpl->xMailDispatcher->dequeueMailMessage();
456 catch(const uno::Exception&)
460 delete m_pImpl;
462 /*-- 21.05.2004 14:10:40---------------------------------------------------
464 -----------------------------------------------------------------------*/
465 void SwSendMailDialog::AddDocument( SwMailDescriptor& rDesc )
467 ::osl::MutexGuard aGuard(m_pImpl->aDescriptorMutex);
468 m_pImpl->aDescriptors.push_back(rDesc);
469 // if the dialog is already running then continue sending of documents
470 if(m_pImpl->xMailDispatcher.is())
472 IterateMails();
476 /*-- 31.01.2005 08:59:35---------------------------------------------------
478 -----------------------------------------------------------------------*/
479 void SwSendMailDialog::SetDocumentCount( sal_Int32 nAllDocuments )
481 m_pImpl->nDocumentCount = nAllDocuments;
482 UpdateTransferStatus();
484 /*-- 21.05.2004 14:10:40---------------------------------------------------
486 -----------------------------------------------------------------------*/
487 void lcl_Move(Control& rCtrl, long nYOffset)
489 Point aPos(rCtrl.GetPosPixel());
490 aPos.Y() += nYOffset;
491 rCtrl.SetPosPixel(aPos);
493 /*-- 21.05.2004 14:10:40---------------------------------------------------
495 -----------------------------------------------------------------------*/
496 IMPL_LINK( SwSendMailDialog, DetailsHdl_Impl, PushButton*, EMPTYARG )
498 long nMove = 0;
499 if(m_aStatusLB.IsVisible())
501 m_aStatusLB.Hide();
502 m_aStatusHB.Hide();
503 nMove = - m_nStatusHeight;
504 m_aDetailsPB.SetText(m_sMore);
506 else
508 m_aStatusLB.Show();
509 m_aStatusHB.Show();
510 nMove = m_nStatusHeight;
511 m_aDetailsPB.SetText(m_sLess);
513 lcl_Move(m_aSeparatorFL, nMove);
514 lcl_Move(m_aStopPB, nMove);
515 lcl_Move(m_aClosePB, nMove);
516 Size aDlgSize = GetSizePixel(); aDlgSize.Height() += nMove; SetSizePixel(aDlgSize);
518 return 0;
520 /*-- 21.05.2004 14:10:40---------------------------------------------------
522 -----------------------------------------------------------------------*/
523 IMPL_LINK( SwSendMailDialog, StopHdl_Impl, PushButton*, pButton )
525 m_bCancel = true;
526 if(m_pImpl->xMailDispatcher.is())
528 if(m_pImpl->xMailDispatcher->isStarted())
530 m_pImpl->xMailDispatcher->stop();
531 pButton->SetText(m_sContinue);
532 m_PausedFI.Show();
534 else
536 m_pImpl->xMailDispatcher->start();
537 pButton->SetText(m_sStop);
538 m_PausedFI.Show(sal_False);
541 return 0;
543 /*-- 21.05.2004 14:10:40---------------------------------------------------
545 -----------------------------------------------------------------------*/
546 IMPL_LINK( SwSendMailDialog, CloseHdl_Impl, PushButton*, EMPTYARG )
548 ModelessDialog::Show( sal_False );
549 return 0;
551 /*-- 14.06.2004 09:48:30---------------------------------------------------
553 -----------------------------------------------------------------------*/
554 IMPL_STATIC_LINK_NOINSTANCE( SwSendMailDialog, StartSendMails, SwSendMailDialog*, pDialog )
556 pDialog->SendMails();
557 return 0;
559 /*-- 14.06.2004 09:48:30---------------------------------------------------
561 -----------------------------------------------------------------------*/
562 IMPL_STATIC_LINK( SwSendMailDialog, RemoveThis, Timer*, pTimer )
564 if( pThis->m_pImpl->xMailDispatcher.is() )
566 if(pThis->m_pImpl->xMailDispatcher->isStarted())
567 pThis->m_pImpl->xMailDispatcher->stop();
568 if(!pThis->m_pImpl->xMailDispatcher->isShutdownRequested())
569 pThis->m_pImpl->xMailDispatcher->shutdown();
572 if( pThis->m_bDesctructionEnabled &&
573 (!pThis->m_pImpl->xMailDispatcher.is() ||
574 !pThis->m_pImpl->xMailDispatcher->isRunning()))
576 delete pThis;
578 else
580 pTimer->Start();
582 return 0;
584 /*-- 07.07.2004 14:34:05---------------------------------------------------
586 -----------------------------------------------------------------------*/
587 IMPL_STATIC_LINK_NOINSTANCE( SwSendMailDialog, StopSendMails, SwSendMailDialog*, pDialog )
589 if(pDialog->m_pImpl->xMailDispatcher.is() &&
590 pDialog->m_pImpl->xMailDispatcher->isStarted())
592 pDialog->m_pImpl->xMailDispatcher->stop();
593 pDialog->m_aStopPB.SetText(pDialog->m_sContinue);
594 pDialog->m_PausedFI.Show();
596 return 0;
598 /*-- 14.06.2004 10:38:04---------------------------------------------------
600 -----------------------------------------------------------------------*/
601 void SwSendMailDialog::SendMails()
603 if(!m_pConfigItem)
605 DBG_ERROR("config item not set");
606 return;
608 String sErrorMessage;
609 bool bIsLoggedIn = false;
610 EnterWait();
611 //get a mail server connection
612 uno::Reference< mail::XSmtpService > xSmtpServer =
613 SwMailMergeHelper::ConnectToSmtpServer( *m_pConfigItem,
614 m_pImpl->xConnectedInMailService,
615 aEmptyStr, aEmptyStr, this );
616 bIsLoggedIn = xSmtpServer.is() && xSmtpServer->isConnected();
617 LeaveWait();
618 if(!bIsLoggedIn)
620 DBG_ERROR("create error message");
621 return;
623 m_pImpl->xMailDispatcher.set( new MailDispatcher(xSmtpServer));
624 IterateMails();
625 m_pImpl->xMailListener = new SwMailDispatcherListener_Impl(*this);
626 m_pImpl->xMailDispatcher->addListener(m_pImpl->xMailListener);
627 if(!m_bCancel)
629 m_pImpl->xMailDispatcher->start();
632 /* -----------------28.01.2005 10:17-----------------
634 --------------------------------------------------*/
635 void SwSendMailDialog::IterateMails()
637 const SwMailDescriptor* pCurrentMailDescriptor = m_pImpl->GetNextDescriptor();
638 while( pCurrentMailDescriptor )
640 if(!SwMailMergeHelper::CheckMailAddress( pCurrentMailDescriptor->sEMail ))
642 ImageList& rImgLst = GetSettings().GetStyleSettings().GetWindowColor().IsDark() ?
643 m_aImageListHC : m_aImageList;
644 Image aInsertImg = rImgLst.GetImage( FN_FORMULA_CANCEL );
646 String sMessage = m_sSendingTo;
647 String sTmp(pCurrentMailDescriptor->sEMail);
648 sTmp += '\t';
649 sTmp += m_sFailed;
650 sMessage.SearchAndReplaceAscii("%1", sTmp);
651 m_aStatusLB.InsertEntry( sMessage, aInsertImg, aInsertImg);
652 ++m_nSendCount;
653 ++m_nErrorCount;
654 UpdateTransferStatus( );
655 pCurrentMailDescriptor = m_pImpl->GetNextDescriptor();
656 continue;
658 SwMailMessage* pMessage = 0;
659 uno::Reference< mail::XMailMessage > xMessage = pMessage = new SwMailMessage;
660 if(m_pConfigItem->IsMailReplyTo())
661 pMessage->setReplyToAddress(m_pConfigItem->GetMailReplyTo());
662 pMessage->addRecipient( pCurrentMailDescriptor->sEMail );
663 pMessage->SetSenderName( m_pConfigItem->GetMailDisplayName() );
664 pMessage->SetSenderAddress( m_pConfigItem->GetMailAddress() );
665 if(pCurrentMailDescriptor->sAttachmentURL.getLength())
667 mail::MailAttachment aAttach;
668 aAttach.Data =
669 new SwMailTransferable(
670 pCurrentMailDescriptor->sAttachmentURL,
671 pCurrentMailDescriptor->sAttachmentName,
672 pCurrentMailDescriptor->sMimeType );
673 aAttach.ReadableName = pCurrentMailDescriptor->sAttachmentName;
674 pMessage->addAttachment( aAttach );
676 pMessage->setSubject( pCurrentMailDescriptor->sSubject );
677 uno::Reference< datatransfer::XTransferable> xBody =
678 new SwMailTransferable(
679 pCurrentMailDescriptor->sBodyContent,
680 pCurrentMailDescriptor->sBodyMimeType);
681 pMessage->setBody( xBody );
683 //CC and BCC are tokenized by ';'
684 if(pCurrentMailDescriptor->sCC.getLength())
686 String sTokens( pCurrentMailDescriptor->sCC );
687 sal_uInt16 nTokens = sTokens.GetTokenCount( ';' );
688 xub_StrLen nPos = 0;
689 for( sal_uInt16 nToken = 0; nToken < nTokens; ++nToken)
691 String sTmp = sTokens.GetToken( 0, ';', nPos);
692 if( sTmp.Len() )
693 pMessage->addCcRecipient( sTmp );
696 if(pCurrentMailDescriptor->sBCC.getLength())
698 String sTokens( pCurrentMailDescriptor->sBCC );
699 sal_uInt16 nTokens = sTokens.GetTokenCount( ';' );
700 xub_StrLen nPos = 0;
701 for( sal_uInt16 nToken = 0; nToken < nTokens; ++nToken)
703 String sTmp = sTokens.GetToken( 0, ';', nPos);
704 if( sTmp.Len() )
705 pMessage->addBccRecipient( sTmp );
708 m_pImpl->xMailDispatcher->enqueueMailMessage( xMessage );
709 pCurrentMailDescriptor = m_pImpl->GetNextDescriptor();
711 UpdateTransferStatus();
713 /*-- 27.08.2004 10:50:17---------------------------------------------------
715 -----------------------------------------------------------------------*/
716 void SwSendMailDialog::ShowDialog()
718 Application::PostUserEvent( STATIC_LINK( this, SwSendMailDialog,
719 StartSendMails ), this );
720 ModelessDialog::Show();
722 /*-- 27.08.2004 10:50:17---------------------------------------------------
724 -----------------------------------------------------------------------*/
725 void SwSendMailDialog::StateChanged( StateChangedType nStateChange )
727 ModelessDialog::StateChanged( nStateChange );
728 if(STATE_CHANGE_VISIBLE == nStateChange && !IsVisible())
730 m_pImpl->aRemoveTimer.SetTimeoutHdl( STATIC_LINK( this, SwSendMailDialog,
731 RemoveThis ) );
732 m_pImpl->aRemoveTimer.Start();
736 /*-- 23.06.2004 10:14:22---------------------------------------------------
738 -----------------------------------------------------------------------*/
739 void SwSendMailDialog::DocumentSent( uno::Reference< mail::XMailMessage> xMessage,
740 bool bResult,
741 const ::rtl::OUString* pError )
743 //sending should stop on send errors
744 if(pError &&
745 m_pImpl->xMailDispatcher.is() && m_pImpl->xMailDispatcher->isStarted())
747 Application::PostUserEvent( STATIC_LINK( this, SwSendMailDialog,
748 StopSendMails ), this );
750 ImageList& rImgLst = GetSettings().GetStyleSettings().GetWindowColor().IsDark() ?
751 m_aImageListHC : m_aImageList;
752 Image aInsertImg = rImgLst.GetImage( bResult ? FN_FORMULA_APPLY : FN_FORMULA_CANCEL );
754 String sMessage = m_sSendingTo;
755 String sTmp(xMessage->getRecipients()[0]);
756 sTmp += '\t';
757 sTmp += bResult ? m_sCompleted : m_sFailed;
758 sMessage.SearchAndReplaceAscii("%1", sTmp);
759 m_aStatusLB.InsertEntry( sMessage, aInsertImg, aInsertImg);
760 ++m_nSendCount;
761 if(!bResult)
762 ++m_nErrorCount;
764 UpdateTransferStatus( );
765 if(pError)
767 SwSendWarningBox_Impl* pDlg = new SwSendWarningBox_Impl(0, *pError);
768 pDlg->Execute();
769 delete pDlg;
772 /*-- 23.06.2004 11:25:31---------------------------------------------------
774 -----------------------------------------------------------------------*/
775 void SwSendMailDialog::UpdateTransferStatus()
777 String sStatus( m_sTransferStatus );
778 sStatus.SearchAndReplaceAscii("%1", String::CreateFromInt32(m_nSendCount) );
779 sStatus.SearchAndReplaceAscii("%2", String::CreateFromInt32(m_pImpl->nDocumentCount));
780 m_aTransferStatusFT.SetText(sStatus);
782 sStatus = m_sErrorStatus;
783 sStatus.SearchAndReplaceAscii("%1", String::CreateFromInt32(m_nErrorCount) );
784 m_aErrorStatusFT.SetText(sStatus);
786 if(m_pImpl->aDescriptors.size())
787 m_aProgressBar.SetValue((USHORT)(m_nSendCount * 100 / m_pImpl->aDescriptors.size()));
788 else
789 m_aProgressBar.SetValue(0);
791 /*-- 23.06.2004 11:18:50---------------------------------------------------
793 -----------------------------------------------------------------------*/
794 void SwSendMailDialog::AllMailsSent()
796 m_aStopPB.Enable(sal_False);