LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/sw/source/ui/dbui - mailmergechildwindow.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 2 340 0.6 %
Date: 2013-07-09 Functions: 3 49 6.1 %
Legend: Lines: hit not hit

          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 <sfx2/viewfrm.hxx>
      21             : #include <sfx2/dispatch.hxx>
      22             : 
      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>
      45             : 
      46             : using namespace ::com::sun::star;
      47             : 
      48          33 : SFX_IMPL_FLOATINGWINDOW( SwMailMergeChildWindow, FN_MAILMERGE_CHILDWINDOW )
      49             : 
      50           0 : SwMailMergeChildWindow::SwMailMergeChildWindow( Window* _pParent,
      51             :                                 sal_uInt16 nId,
      52             :                                 SfxBindings* pBindings,
      53             :                                 SfxChildWinInfo* pInfo ) :
      54           0 :                                 SfxChildWindow( _pParent, nId )
      55             : {
      56           0 :     pWindow = new SwMailMergeChildWin( pBindings, this, _pParent);
      57             : 
      58           0 :     if (!pInfo->aSize.Width() || !pInfo->aSize.Height())
      59             :     {
      60           0 :         SwView* pActiveView = ::GetActiveView();
      61           0 :         if(pActiveView)
      62             :         {
      63           0 :             const SwEditWin &rEditWin = pActiveView->GetEditWin();
      64           0 :             pWindow->SetPosPixel(rEditWin.OutputToScreenPixel(Point(0, 0)));
      65             :         }
      66             :         else
      67           0 :             pWindow->SetPosPixel(_pParent->OutputToScreenPixel(Point(0, 0)));
      68           0 :         pInfo->aPos = pWindow->GetPosPixel();
      69           0 :         pInfo->aSize = pWindow->GetSizePixel();
      70             :     }
      71             : 
      72           0 :     ((SwMailMergeChildWin *)pWindow)->Initialize(pInfo);
      73           0 :     pWindow->Show();
      74           0 : }
      75             : 
      76           0 : SwMailMergeChildWin::SwMailMergeChildWin( SfxBindings* _pBindings,
      77             :                             SfxChildWindow* pChild,
      78             :                             Window *pParent) :
      79             :     SfxFloatingWindow(_pBindings, pChild, pParent, SW_RES(DLG_MAILMERGECHILD)),
      80           0 :     m_aBackTB(this, SW_RES( TB_BACK ))
      81             : {
      82           0 :     m_aBackTB.SetSelectHdl(LINK(this, SwMailMergeChildWin, BackHdl));
      83           0 :     sal_uInt16 nIResId = ILIST_TBX;
      84           0 :     ResId aResId( nIResId, *pSwResMgr );
      85           0 :     ImageList aIList(aResId);
      86           0 :     FreeResource();
      87             : 
      88           0 :     m_aBackTB.SetItemImage( 1, aIList.GetImage(FN_SHOW_ROOT) );
      89           0 :     m_aBackTB.SetButtonType( BUTTON_SYMBOLTEXT );
      90           0 :     Size aSz = m_aBackTB.CalcWindowSizePixel(1);
      91           0 :     m_aBackTB.SetPosSizePixel( Point(), aSz );
      92           0 :     SetOutputSizePixel(aSz);
      93           0 :     m_aBackTB.Show();
      94           0 : }
      95             : 
      96           0 : SwMailMergeChildWin::~SwMailMergeChildWin()
      97             : {
      98           0 : }
      99             : 
     100           0 : IMPL_LINK_NOARG(SwMailMergeChildWin, BackHdl)
     101             : {
     102           0 :     GetBindings().GetDispatcher()->Execute(FN_MAILMERGE_WIZARD, SFX_CALLMODE_ASYNCHRON);
     103           0 :     return 0;
     104             : }
     105             : 
     106           0 : void SwMailMergeChildWin::FillInfo(SfxChildWinInfo& rInfo) const
     107             : {
     108           0 :     SfxFloatingWindow::FillInfo(rInfo);
     109           0 :     rInfo.aWinState = OString();
     110           0 :     rInfo.bVisible = sal_False;
     111           0 : }
     112             : 
     113             : struct SwSendMailDialog_Impl
     114             : {
     115             :     friend class SwSendMailDialog;
     116             :     ::osl::Mutex                                aDescriptorMutex;
     117             : 
     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;
     126             : 
     127             : 
     128           0 :     SwSendMailDialog_Impl() :
     129             :         nCurrentDescriptor(0),
     130           0 :         nDocumentCount(0)
     131             :              {
     132           0 :                 aRemoveTimer.SetTimeout(500);
     133           0 :              }
     134             : 
     135           0 :     ~SwSendMailDialog_Impl()
     136           0 :     {
     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           0 :         if( xMailDispatcher.is() && !xMailDispatcher->isShutdownRequested() )
     143           0 :             xMailDispatcher->shutdown();
     144           0 :     }
     145             :     const SwMailDescriptor* GetNextDescriptor();
     146             : };
     147             : 
     148           0 : const SwMailDescriptor* SwSendMailDialog_Impl::GetNextDescriptor()
     149             : {
     150           0 :     ::osl::MutexGuard aGuard(aDescriptorMutex);
     151           0 :     if(nCurrentDescriptor < aDescriptors.size())
     152             :     {
     153           0 :         ++nCurrentDescriptor;
     154           0 :         return &aDescriptors[nCurrentDescriptor - 1];
     155             :     }
     156           0 :     return 0;
     157             : }
     158             : 
     159             : class SwMailDispatcherListener_Impl : public IMailDispatcherListener
     160             : {
     161             :     SwSendMailDialog* m_pSendMailDialog;
     162             : 
     163             : public:
     164             :     SwMailDispatcherListener_Impl(SwSendMailDialog& rParentDlg);
     165             :     ~SwMailDispatcherListener_Impl();
     166             : 
     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);
     174             : 
     175             :     static void DeleteAttachments( uno::Reference< mail::XMailMessage >& xMessage );
     176             : };
     177             : 
     178           0 : SwMailDispatcherListener_Impl::SwMailDispatcherListener_Impl(SwSendMailDialog& rParentDlg) :
     179           0 :     m_pSendMailDialog(&rParentDlg)
     180             : {
     181           0 : }
     182             : 
     183           0 : SwMailDispatcherListener_Impl::~SwMailDispatcherListener_Impl()
     184             : {
     185           0 : }
     186             : 
     187           0 : void SwMailDispatcherListener_Impl::started(::rtl::Reference<MailDispatcher> /*xMailDispatcher*/)
     188             : {
     189           0 : }
     190             : 
     191           0 : void SwMailDispatcherListener_Impl::stopped(
     192             :                         ::rtl::Reference<MailDispatcher> /*xMailDispatcher*/)
     193             : {
     194           0 : }
     195             : 
     196           0 : void SwMailDispatcherListener_Impl::idle(::rtl::Reference<MailDispatcher> /*xMailDispatcher*/)
     197             : {
     198           0 :     SolarMutexGuard aGuard;
     199           0 :     m_pSendMailDialog->AllMailsSent();
     200           0 : }
     201             : 
     202           0 : void SwMailDispatcherListener_Impl::mailDelivered(
     203             :                         ::rtl::Reference<MailDispatcher> /*xMailDispatcher*/,
     204             :                         uno::Reference< mail::XMailMessage> xMailMessage)
     205             : {
     206           0 :     SolarMutexGuard aGuard;
     207           0 :     m_pSendMailDialog->DocumentSent( xMailMessage, true, 0 );
     208           0 :     DeleteAttachments( xMailMessage );
     209           0 : }
     210             : 
     211           0 : void SwMailDispatcherListener_Impl::mailDeliveryError(
     212             :                 ::rtl::Reference<MailDispatcher> /*xMailDispatcher*/,
     213             :                 uno::Reference< mail::XMailMessage> xMailMessage,
     214             :                 const OUString& sErrorMessage)
     215             : {
     216           0 :     SolarMutexGuard aGuard;
     217           0 :     m_pSendMailDialog->DocumentSent( xMailMessage, false, &sErrorMessage );
     218           0 :     DeleteAttachments( xMailMessage );
     219           0 : }
     220             : 
     221           0 : void SwMailDispatcherListener_Impl::DeleteAttachments( uno::Reference< mail::XMailMessage >& xMessage )
     222             : {
     223           0 :     uno::Sequence< mail::MailAttachment > aAttachments = xMessage->getAttachments();
     224             : 
     225           0 :     for(sal_Int32 nFile = 0; nFile < aAttachments.getLength(); ++nFile)
     226             :     {
     227             :         try
     228             :         {
     229           0 :             uno::Reference< beans::XPropertySet > xTransferableProperties( aAttachments[nFile].Data, uno::UNO_QUERY_THROW);
     230           0 :             if( xTransferableProperties.is() )
     231             :             {
     232           0 :                 OUString sURL;
     233           0 :                 xTransferableProperties->getPropertyValue("URL") >>= sURL;
     234           0 :                 if(!sURL.isEmpty())
     235           0 :                     SWUnoHelper::UCB_DeleteFile( sURL );
     236           0 :             }
     237             :         }
     238           0 :         catch (const uno::Exception&)
     239             :         {
     240             :         }
     241           0 :     }
     242           0 : }
     243             : 
     244             : class SwSendWarningBox_Impl : public ModalDialog
     245             : {
     246             :     FixedImage      aWarningImageIM;
     247             :     FixedInfo       aWarningFI;
     248             :     FixedText       aDetailFT;
     249             :     MultiLineEdit   aDetailED;
     250             :     FixedLine       aSeparatorFL;
     251             :     OKButton        aOKPB;
     252             : 
     253             : public:
     254             :     SwSendWarningBox_Impl(Window* pParent, const String& rDetails);
     255             :     ~SwSendWarningBox_Impl();
     256             : };
     257             : 
     258           0 : 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           0 :     aOKPB(          this, SW_RES(PB_OK))
     266             : {
     267           0 :     FreeResource();
     268           0 :     aWarningImageIM.SetImage(WarningBox::GetStandardImage());
     269           0 :     aDetailED.SetText(rDetails);
     270           0 : }
     271             : 
     272           0 : SwSendWarningBox_Impl::~SwSendWarningBox_Impl()
     273             : {
     274           0 : }
     275             : 
     276             : #define ITEMID_TASK     1
     277             : #define ITEMID_STATUS   2
     278             : 
     279           0 : 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           0 :     m_sMore(m_aDetailsPB.GetText()),
     301             :     m_sLess(SW_RES(ST_LESS)),
     302             :     m_sContinue(SW_RES( ST_CONTINUE )),
     303           0 :     m_sStop(m_aStopPB.GetText()),
     304             :     m_sSend(SW_RES(ST_SEND)),
     305           0 :     m_sTransferStatus(m_aTransferStatusFT.GetText()),
     306           0 :     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           0 :     m_pImpl(new SwSendMailDialog_Impl),
     315             :     m_pConfigItem(&rConfigItem),
     316             :     m_nSendCount(0),
     317           0 :     m_nErrorCount(0)
     318             : {
     319           0 :     m_nStatusHeight =  m_aSeparatorFL.GetPosPixel().Y() - m_aStatusLB.GetPosPixel().Y();
     320           0 :     String sTask(SW_RES(ST_TASK));
     321           0 :     String sStatus(SW_RES(ST_STATUS));
     322           0 :     m_aStatusLB.SetHelpId(HID_MM_SENDMAILS_STATUSLB);
     323             : 
     324           0 :     FreeResource();
     325             : 
     326           0 :     m_aDetailsPB.SetClickHdl(LINK( this, SwSendMailDialog, DetailsHdl_Impl));
     327           0 :     m_aStopPB.SetClickHdl(LINK( this, SwSendMailDialog, StopHdl_Impl));
     328           0 :     m_aClosePB.SetClickHdl(LINK( this, SwSendMailDialog, CloseHdl_Impl));
     329             : 
     330             : 
     331           0 :     Size aLBSize(m_aStatusLB.GetSizePixel());
     332           0 :     m_aStatusHB.SetSizePixel(aLBSize);
     333           0 :     Size aHeadSize(m_aStatusHB.CalcWindowSizePixel());
     334           0 :     aHeadSize.Width() = aLBSize.Width();
     335           0 :     m_aStatusHB.SetSizePixel(aHeadSize);
     336           0 :     Point aLBPos(m_aStatusLB.GetPosPixel());
     337           0 :     m_aStatusHB.SetPosPixel(aLBPos);
     338           0 :     aLBPos.Y() += aHeadSize.Height();
     339           0 :     aLBSize.Height() -= aHeadSize.Height();
     340           0 :     m_aStatusLB.SetPosSizePixel(aLBPos, aLBSize);
     341             : 
     342           0 :     Size aSz(m_aStatusHB.GetOutputSizePixel());
     343           0 :     long nPos1 = aSz.Width()/3 * 2;
     344           0 :     long nPos2 = aSz.Width()/3;
     345             :     m_aStatusHB.InsertItem( ITEMID_TASK, sTask,
     346             :                             nPos1,
     347           0 :                             HIB_LEFT | HIB_VCENTER );
     348             :     m_aStatusHB.InsertItem( ITEMID_STATUS, sStatus,
     349             :                             nPos2,
     350           0 :                             HIB_LEFT | HIB_VCENTER );
     351           0 :     m_aStatusHB.SetHelpId(HID_MM_ADDRESSLIST_HB );
     352           0 :     m_aStatusHB.Show();
     353             : 
     354           0 :     m_aStatusLB.SetHelpId(HID_MM_MAILSTATUS_TLB);
     355           0 :     static long nTabs[] = {3, 0, nPos1, aSz.Width() };
     356           0 :     m_aStatusLB.SetStyle( m_aStatusLB.GetStyle() | WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP );
     357           0 :     m_aStatusLB.SetSelectionMode( SINGLE_SELECTION );
     358           0 :     m_aStatusLB.SetTabs(&nTabs[0], MAP_PIXEL);
     359           0 :     m_aStatusLB.SetSpaceBetweenEntries(3);
     360             : 
     361           0 :     DetailsHdl_Impl( &m_aDetailsPB );
     362           0 :     UpdateTransferStatus();
     363           0 : }
     364             : 
     365           0 : SwSendMailDialog::~SwSendMailDialog()
     366             : {
     367           0 :     if(m_pImpl->xMailDispatcher.is())
     368             :     {
     369             :         try
     370             :         {
     371           0 :             if(m_pImpl->xMailDispatcher->isStarted())
     372           0 :                 m_pImpl->xMailDispatcher->stop();
     373           0 :             if(m_pImpl->xConnectedMailService.is() && m_pImpl->xConnectedMailService->isConnected())
     374           0 :                 m_pImpl->xConnectedMailService->disconnect();
     375           0 :             if(m_pImpl->xConnectedInMailService.is() && m_pImpl->xConnectedInMailService->isConnected())
     376           0 :                 m_pImpl->xConnectedInMailService->disconnect();
     377             : 
     378             :             uno::Reference<mail::XMailMessage> xMessage =
     379           0 :                     m_pImpl->xMailDispatcher->dequeueMailMessage();
     380           0 :             while(xMessage.is())
     381             :             {
     382           0 :                 SwMailDispatcherListener_Impl::DeleteAttachments( xMessage );
     383           0 :                 xMessage = m_pImpl->xMailDispatcher->dequeueMailMessage();
     384           0 :             }
     385             :         }
     386           0 :         catch (const uno::Exception&)
     387             :         {
     388             :         }
     389             :     }
     390           0 :     delete m_pImpl;
     391           0 : }
     392             : 
     393           0 : void SwSendMailDialog::AddDocument( SwMailDescriptor& rDesc )
     394             : {
     395           0 :     ::osl::MutexGuard aGuard(m_pImpl->aDescriptorMutex);
     396           0 :     m_pImpl->aDescriptors.push_back(rDesc);
     397             :     // if the dialog is already running then continue sending of documents
     398           0 :     if(m_pImpl->xMailDispatcher.is())
     399             :     {
     400           0 :         IterateMails();
     401           0 :     }
     402             : 
     403           0 : }
     404             : 
     405           0 : void SwSendMailDialog::SetDocumentCount( sal_Int32 nAllDocuments )
     406             : {
     407           0 :     m_pImpl->nDocumentCount = nAllDocuments;
     408           0 :     UpdateTransferStatus();
     409           0 : }
     410             : 
     411           0 : static void lcl_Move(Control& rCtrl, long nYOffset)
     412             : {
     413           0 :     Point aPos(rCtrl.GetPosPixel());
     414           0 :     aPos.Y() += nYOffset;
     415           0 :     rCtrl.SetPosPixel(aPos);
     416           0 : }
     417             : 
     418           0 : IMPL_LINK_NOARG(SwSendMailDialog, DetailsHdl_Impl)
     419             : {
     420           0 :     long nMove = 0;
     421           0 :     if(m_aStatusLB.IsVisible())
     422             :     {
     423           0 :         m_aStatusLB.Hide();
     424           0 :         m_aStatusHB.Hide();
     425           0 :         nMove = - m_nStatusHeight;
     426           0 :         m_aDetailsPB.SetText(m_sMore);
     427             :     }
     428             :     else
     429             :     {
     430           0 :         m_aStatusLB.Show();
     431           0 :         m_aStatusHB.Show();
     432           0 :         nMove = m_nStatusHeight;
     433           0 :         m_aDetailsPB.SetText(m_sLess);
     434             :     }
     435           0 :     lcl_Move(m_aSeparatorFL, nMove);
     436           0 :     lcl_Move(m_aStopPB, nMove);
     437           0 :     lcl_Move(m_aClosePB, nMove);
     438           0 :     Size aDlgSize = GetSizePixel(); aDlgSize.Height() += nMove; SetSizePixel(aDlgSize);
     439             : 
     440           0 :     return 0;
     441             : }
     442             : 
     443           0 : IMPL_LINK( SwSendMailDialog, StopHdl_Impl, PushButton*, pButton )
     444             : {
     445           0 :     m_bCancel = true;
     446           0 :     if(m_pImpl->xMailDispatcher.is())
     447             :     {
     448           0 :         if(m_pImpl->xMailDispatcher->isStarted())
     449             :         {
     450           0 :             m_pImpl->xMailDispatcher->stop();
     451           0 :             pButton->SetText(m_sContinue);
     452           0 :             m_PausedFI.Show();
     453             :         }
     454             :         else
     455             :         {
     456           0 :             m_pImpl->xMailDispatcher->start();
     457           0 :             pButton->SetText(m_sStop);
     458           0 :             m_PausedFI.Show(sal_False);
     459             :         }
     460             :     }
     461           0 :     return 0;
     462             : }
     463             : 
     464           0 : IMPL_LINK_NOARG(SwSendMailDialog, CloseHdl_Impl)
     465             : {
     466           0 :     ModelessDialog::Show( sal_False );
     467           0 :     return 0;
     468             : }
     469             : 
     470           0 : IMPL_STATIC_LINK_NOINSTANCE( SwSendMailDialog, StartSendMails, SwSendMailDialog*, pDialog )
     471             : {
     472           0 :     pDialog->SendMails();
     473           0 :     return 0;
     474             : }
     475             : 
     476           0 : IMPL_STATIC_LINK( SwSendMailDialog, RemoveThis, Timer*, pTimer )
     477             : {
     478           0 :     if( pThis->m_pImpl->xMailDispatcher.is() )
     479             :     {
     480           0 :         if(pThis->m_pImpl->xMailDispatcher->isStarted())
     481           0 :             pThis->m_pImpl->xMailDispatcher->stop();
     482           0 :         if(!pThis->m_pImpl->xMailDispatcher->isShutdownRequested())
     483           0 :             pThis->m_pImpl->xMailDispatcher->shutdown();
     484             :     }
     485             : 
     486           0 :     if( pThis->m_bDesctructionEnabled &&
     487           0 :             (!pThis->m_pImpl->xMailDispatcher.is() ||
     488           0 :                     !pThis->m_pImpl->xMailDispatcher->isRunning()))
     489             :     {
     490           0 :         delete pThis;
     491             :     }
     492             :     else
     493             :     {
     494           0 :         pTimer->Start();
     495             :     }
     496           0 :     return 0;
     497             : }
     498             : 
     499           0 : IMPL_STATIC_LINK_NOINSTANCE( SwSendMailDialog, StopSendMails, SwSendMailDialog*, pDialog )
     500             : {
     501           0 :     if(pDialog->m_pImpl->xMailDispatcher.is() &&
     502           0 :         pDialog->m_pImpl->xMailDispatcher->isStarted())
     503             :     {
     504           0 :         pDialog->m_pImpl->xMailDispatcher->stop();
     505           0 :         pDialog->m_aStopPB.SetText(pDialog->m_sContinue);
     506           0 :         pDialog->m_PausedFI.Show();
     507             :     }
     508           0 :     return 0;
     509             : }
     510             : 
     511           0 : void  SwSendMailDialog::SendMails()
     512             : {
     513           0 :     if(!m_pConfigItem)
     514             :     {
     515             :         OSL_FAIL("config item not set");
     516           0 :         return;
     517             :     }
     518           0 :     EnterWait();
     519             :     //get a mail server connection
     520             :     uno::Reference< mail::XSmtpService > xSmtpServer =
     521             :                 SwMailMergeHelper::ConnectToSmtpServer( *m_pConfigItem,
     522             :                                             m_pImpl->xConnectedInMailService,
     523           0 :                                             aEmptyStr, aEmptyStr, this );
     524           0 :     bool bIsLoggedIn = xSmtpServer.is() && xSmtpServer->isConnected();
     525           0 :     LeaveWait();
     526           0 :     if(!bIsLoggedIn)
     527             :     {
     528             :         OSL_FAIL("create error message");
     529           0 :         return;
     530             :     }
     531           0 :     m_pImpl->xMailDispatcher.set( new MailDispatcher(xSmtpServer));
     532           0 :     IterateMails();
     533           0 :     m_pImpl->xMailListener = new SwMailDispatcherListener_Impl(*this);
     534           0 :     m_pImpl->xMailDispatcher->addListener(m_pImpl->xMailListener);
     535           0 :     if(!m_bCancel)
     536             :     {
     537           0 :         m_pImpl->xMailDispatcher->start();
     538           0 :     }
     539             : }
     540             : 
     541           0 : void  SwSendMailDialog::IterateMails()
     542             : {
     543           0 :     const SwMailDescriptor* pCurrentMailDescriptor = m_pImpl->GetNextDescriptor();
     544           0 :     while( pCurrentMailDescriptor )
     545             :     {
     546           0 :         if(!SwMailMergeHelper::CheckMailAddress( pCurrentMailDescriptor->sEMail ))
     547             :         {
     548           0 :             Image aInsertImg = m_aImageList.GetImage( FN_FORMULA_CANCEL );
     549             : 
     550           0 :             String sMessage = m_sSendingTo;
     551           0 :             String sTmp(pCurrentMailDescriptor->sEMail);
     552           0 :             sTmp += '\t';
     553           0 :             sTmp += m_sFailed;
     554           0 :             sMessage.SearchAndReplaceAscii("%1", sTmp);
     555           0 :             m_aStatusLB.InsertEntry( sMessage, aInsertImg, aInsertImg);
     556           0 :             ++m_nSendCount;
     557           0 :             ++m_nErrorCount;
     558           0 :             UpdateTransferStatus( );
     559           0 :             pCurrentMailDescriptor = m_pImpl->GetNextDescriptor();
     560           0 :             continue;
     561             :         }
     562           0 :         SwMailMessage* pMessage = new SwMailMessage;
     563           0 :         uno::Reference< mail::XMailMessage > xMessage = pMessage;
     564           0 :         if(m_pConfigItem->IsMailReplyTo())
     565           0 :             pMessage->setReplyToAddress(m_pConfigItem->GetMailReplyTo());
     566           0 :         pMessage->addRecipient( pCurrentMailDescriptor->sEMail );
     567           0 :         pMessage->SetSenderName( m_pConfigItem->GetMailDisplayName() );
     568           0 :         pMessage->SetSenderAddress( m_pConfigItem->GetMailAddress() );
     569           0 :         if(!pCurrentMailDescriptor->sAttachmentURL.isEmpty())
     570             :         {
     571           0 :             mail::MailAttachment aAttach;
     572           0 :             aAttach.Data =
     573             :                     new SwMailTransferable(
     574             :                         pCurrentMailDescriptor->sAttachmentURL,
     575             :                         pCurrentMailDescriptor->sAttachmentName,
     576           0 :                         pCurrentMailDescriptor->sMimeType );
     577           0 :             aAttach.ReadableName = pCurrentMailDescriptor->sAttachmentName;
     578           0 :             pMessage->addAttachment( aAttach );
     579             :         }
     580           0 :         pMessage->setSubject( pCurrentMailDescriptor->sSubject );
     581             :         uno::Reference< datatransfer::XTransferable> xBody =
     582             :                     new SwMailTransferable(
     583             :                         pCurrentMailDescriptor->sBodyContent,
     584           0 :                         pCurrentMailDescriptor->sBodyMimeType);
     585           0 :         pMessage->setBody( xBody );
     586             : 
     587             :         //CC and BCC are tokenized by ';'
     588           0 :         if(!pCurrentMailDescriptor->sCC.isEmpty())
     589             :         {
     590           0 :             String sTokens( pCurrentMailDescriptor->sCC );
     591           0 :             sal_uInt16 nTokens = comphelper::string::getTokenCount(sTokens, ';');
     592           0 :             sal_Int32 nPos = 0;
     593           0 :             for( sal_uInt16 nToken = 0; nToken < nTokens; ++nToken)
     594             :             {
     595           0 :                 String sTmp = sTokens.GetToken( 0, ';', nPos);
     596           0 :                 if( sTmp.Len() )
     597           0 :                     pMessage->addCcRecipient( sTmp );
     598           0 :             }
     599             :         }
     600           0 :         if(!pCurrentMailDescriptor->sBCC.isEmpty())
     601             :         {
     602           0 :             String sTokens( pCurrentMailDescriptor->sBCC );
     603           0 :             sal_uInt16 nTokens = comphelper::string::getTokenCount(sTokens, ';');
     604           0 :             sal_Int32 nPos = 0;
     605           0 :             for( sal_uInt16 nToken = 0; nToken < nTokens; ++nToken)
     606             :             {
     607           0 :                 String sTmp = sTokens.GetToken( 0, ';', nPos);
     608           0 :                 if( sTmp.Len() )
     609           0 :                     pMessage->addBccRecipient( sTmp );
     610           0 :             }
     611             :         }
     612           0 :         m_pImpl->xMailDispatcher->enqueueMailMessage( xMessage );
     613           0 :         pCurrentMailDescriptor = m_pImpl->GetNextDescriptor();
     614           0 :     }
     615           0 :     UpdateTransferStatus();
     616           0 : }
     617             : 
     618           0 : void SwSendMailDialog::ShowDialog()
     619             : {
     620             :     Application::PostUserEvent( STATIC_LINK( this, SwSendMailDialog,
     621           0 :                                                 StartSendMails ), this );
     622           0 :     ModelessDialog::Show();
     623           0 : }
     624             : 
     625           0 : void  SwSendMailDialog::StateChanged( StateChangedType nStateChange )
     626             : {
     627           0 :     ModelessDialog::StateChanged( nStateChange );
     628           0 :     if(STATE_CHANGE_VISIBLE == nStateChange && !IsVisible())
     629             :     {
     630             :         m_pImpl->aRemoveTimer.SetTimeoutHdl( STATIC_LINK( this, SwSendMailDialog,
     631           0 :                                                     RemoveThis ) );
     632           0 :         m_pImpl->aRemoveTimer.Start();
     633             :     }
     634           0 : }
     635             : 
     636           0 : void SwSendMailDialog::DocumentSent( uno::Reference< mail::XMailMessage> xMessage,
     637             :                                         bool bResult,
     638             :                                         const OUString* pError )
     639             : {
     640             :     //sending should stop on send errors
     641           0 :     if(pError &&
     642           0 :         m_pImpl->xMailDispatcher.is() && m_pImpl->xMailDispatcher->isStarted())
     643             :     {
     644             :         Application::PostUserEvent( STATIC_LINK( this, SwSendMailDialog,
     645           0 :                                                     StopSendMails ), this );
     646             :     }
     647           0 :     Image aInsertImg = m_aImageList.GetImage( bResult ? FN_FORMULA_APPLY : FN_FORMULA_CANCEL );
     648             : 
     649           0 :     String sMessage = m_sSendingTo;
     650           0 :     String sTmp(xMessage->getRecipients()[0]);
     651           0 :     sTmp += '\t';
     652           0 :     sTmp += bResult ? m_sCompleted : m_sFailed;
     653           0 :     sMessage.SearchAndReplaceAscii("%1", sTmp);
     654           0 :     m_aStatusLB.InsertEntry( sMessage, aInsertImg, aInsertImg);
     655           0 :     ++m_nSendCount;
     656           0 :     if(!bResult)
     657           0 :         ++m_nErrorCount;
     658             : 
     659           0 :     UpdateTransferStatus( );
     660           0 :     if(pError)
     661             :     {
     662           0 :         SwSendWarningBox_Impl* pDlg = new SwSendWarningBox_Impl(0, *pError);
     663           0 :         pDlg->Execute();
     664           0 :         delete pDlg;
     665           0 :     }
     666           0 : }
     667             : 
     668           0 : void SwSendMailDialog::UpdateTransferStatus()
     669             : {
     670           0 :     String sStatus( m_sTransferStatus );
     671           0 :     sStatus.SearchAndReplaceAscii("%1", OUString::number(m_nSendCount) );
     672           0 :     sStatus.SearchAndReplaceAscii("%2", OUString::number(m_pImpl->nDocumentCount));
     673           0 :     m_aTransferStatusFT.SetText(sStatus);
     674             : 
     675           0 :     sStatus = m_sErrorStatus;
     676           0 :     sStatus.SearchAndReplaceAscii("%1", OUString::number(m_nErrorCount) );
     677           0 :     m_aErrorStatusFT.SetText(sStatus);
     678             : 
     679           0 :     if(m_pImpl->aDescriptors.size())
     680           0 :         m_aProgressBar.SetValue((sal_uInt16)(m_nSendCount * 100 / m_pImpl->aDescriptors.size()));
     681             :     else
     682           0 :         m_aProgressBar.SetValue(0);
     683           0 : }
     684             : 
     685           0 : void SwSendMailDialog::AllMailsSent()
     686             : {
     687           0 :     m_aStopPB.Enable(sal_False);
     688          99 : }
     689             : 
     690             : 
     691             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10