LCOV - code coverage report
Current view: top level - sw/source/ui/dbui - mmoutputtypepage.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 0 294 0.0 %
Date: 2014-11-03 Functions: 0 42 0.0 %
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 <mmoutputtypepage.hxx>
      21             : #include <mailmergewizard.hxx>
      22             : #include <mmconfigitem.hxx>
      23             : #include <vcl/msgbox.hxx>
      24             : #include <dbui.hrc>
      25             : #include <swtypes.hxx>
      26             : #include <boost/scoped_ptr.hpp>
      27             : 
      28           0 : SwMailMergeOutputTypePage::SwMailMergeOutputTypePage(SwMailMergeWizard* pParent)
      29             :     : svt::OWizardPage(pParent, "MMOutputTypePage",
      30             :         "modules/swriter/ui/mmoutputtypepage.ui")
      31           0 :     , m_pWizard(pParent)
      32             : {
      33           0 :     get(m_pLetterRB, "letter");
      34           0 :     get(m_pMailRB, "email");
      35           0 :     get(m_pLetterHint, "letterft");
      36           0 :     get(m_pMailHint, "emailft");
      37             : 
      38           0 :     Link aLink = LINK(this, SwMailMergeOutputTypePage, TypeHdl_Impl);
      39           0 :     m_pLetterRB->SetClickHdl(aLink);
      40           0 :     m_pMailRB->SetClickHdl(aLink);
      41             : 
      42           0 :     SwMailMergeConfigItem& rConfigItem = m_pWizard->GetConfigItem();
      43           0 :     if(rConfigItem.IsOutputToLetter())
      44           0 :         m_pLetterRB->Check();
      45             :     else
      46           0 :         m_pMailRB->Check();
      47           0 :     TypeHdl_Impl(m_pLetterRB);
      48             : 
      49           0 : }
      50             : 
      51           0 : IMPL_LINK_NOARG(SwMailMergeOutputTypePage, TypeHdl_Impl)
      52             : {
      53           0 :     bool bLetter = m_pLetterRB->IsChecked();
      54           0 :     m_pLetterHint->Show(bLetter);
      55           0 :     m_pMailHint->Show(!bLetter);
      56           0 :     m_pWizard->GetConfigItem().SetOutputToLetter(bLetter);
      57           0 :     m_pWizard->updateRoadmapItemLabel( MM_ADDRESSBLOCKPAGE );
      58           0 :     m_pWizard->UpdateRoadmap();
      59           0 :     return 0;
      60             : }
      61             : 
      62             : 
      63             : #include <rtl/ref.hxx>
      64             : #include <com/sun/star/mail/XSmtpService.hpp>
      65             : #include <comphelper/string.hxx>
      66             : #include <vcl/svapp.hxx>
      67             : 
      68             : #include <helpid.h>
      69             : #include <cmdid.h>
      70             : #include <swunohelper.hxx>
      71             : #include <mmoutputpage.hxx>
      72             : #include <maildispatcher.hxx>
      73             : #include <imaildsplistener.hxx>
      74             : 
      75             : using namespace ::com::sun::star;
      76             : 
      77             : struct SwSendMailDialog_Impl
      78             : {
      79             :     friend class SwSendMailDialog;
      80             :     ::osl::Mutex                                aDescriptorMutex;
      81             : 
      82             :     ::std::vector< SwMailDescriptor >           aDescriptors;
      83             :     sal_uInt32                                  nCurrentDescriptor;
      84             :     sal_uInt32                                  nDocumentCount;
      85             :     ::rtl::Reference< MailDispatcher >          xMailDispatcher;
      86             :     ::rtl::Reference< IMailDispatcherListener>  xMailListener;
      87             :     uno::Reference< mail::XMailService >        xConnectedMailService;
      88             :     uno::Reference< mail::XMailService >        xConnectedInMailService;
      89             :     Timer                                       aRemoveTimer;
      90             : 
      91           0 :     SwSendMailDialog_Impl() :
      92             :         nCurrentDescriptor(0),
      93           0 :         nDocumentCount(0)
      94             :              {
      95           0 :                 aRemoveTimer.SetTimeout(500);
      96           0 :              }
      97             : 
      98           0 :     ~SwSendMailDialog_Impl()
      99           0 :     {
     100             :         // Shutdown must be called when the last reference to the
     101             :         // mail dispatcher will be released in order to force a
     102             :         // shutdown of the mail dispatcher thread.
     103             :         // 'join' with the mail dispatcher thread leads to a
     104             :         // deadlock (SolarMutex).
     105           0 :         if( xMailDispatcher.is() && !xMailDispatcher->isShutdownRequested() )
     106           0 :             xMailDispatcher->shutdown();
     107           0 :     }
     108             :     const SwMailDescriptor* GetNextDescriptor();
     109             : };
     110             : 
     111           0 : const SwMailDescriptor* SwSendMailDialog_Impl::GetNextDescriptor()
     112             : {
     113           0 :     ::osl::MutexGuard aGuard(aDescriptorMutex);
     114           0 :     if(nCurrentDescriptor < aDescriptors.size())
     115             :     {
     116           0 :         ++nCurrentDescriptor;
     117           0 :         return &aDescriptors[nCurrentDescriptor - 1];
     118             :     }
     119           0 :     return 0;
     120             : }
     121             : 
     122             : using namespace ::com::sun::star;
     123             : class SwMailDispatcherListener_Impl : public IMailDispatcherListener
     124             : {
     125             :     SwSendMailDialog* m_pSendMailDialog;
     126             : 
     127             : public:
     128             :     SwMailDispatcherListener_Impl(SwSendMailDialog& rParentDlg);
     129             :     virtual ~SwMailDispatcherListener_Impl();
     130             : 
     131             :     virtual void started(::rtl::Reference<MailDispatcher> xMailDispatcher) SAL_OVERRIDE;
     132             :     virtual void stopped(::rtl::Reference<MailDispatcher> xMailDispatcher) SAL_OVERRIDE;
     133             :     virtual void idle(::rtl::Reference<MailDispatcher> xMailDispatcher) SAL_OVERRIDE;
     134             :     virtual void mailDelivered(::rtl::Reference<MailDispatcher> xMailDispatcher,
     135             :                 uno::Reference< mail::XMailMessage> xMailMessage) SAL_OVERRIDE;
     136             :     virtual void mailDeliveryError(::rtl::Reference<MailDispatcher> xMailDispatcher,
     137             :                 uno::Reference< mail::XMailMessage> xMailMessage, const OUString& sErrorMessage) SAL_OVERRIDE;
     138             : 
     139             :     static void DeleteAttachments( uno::Reference< mail::XMailMessage >& xMessage );
     140             : };
     141             : 
     142           0 : SwMailDispatcherListener_Impl::SwMailDispatcherListener_Impl(SwSendMailDialog& rParentDlg) :
     143           0 :     m_pSendMailDialog(&rParentDlg)
     144             : {
     145           0 : }
     146             : 
     147           0 : SwMailDispatcherListener_Impl::~SwMailDispatcherListener_Impl()
     148             : {
     149           0 : }
     150             : 
     151           0 : void SwMailDispatcherListener_Impl::started(::rtl::Reference<MailDispatcher> /*xMailDispatcher*/)
     152             : {
     153           0 : }
     154             : 
     155           0 : void SwMailDispatcherListener_Impl::stopped(
     156             :                         ::rtl::Reference<MailDispatcher> /*xMailDispatcher*/)
     157             : {
     158           0 : }
     159             : 
     160           0 : void SwMailDispatcherListener_Impl::idle(::rtl::Reference<MailDispatcher> /*xMailDispatcher*/)
     161             : {
     162           0 :     SolarMutexGuard aGuard;
     163           0 :     m_pSendMailDialog->AllMailsSent();
     164           0 : }
     165             : 
     166           0 : void SwMailDispatcherListener_Impl::mailDelivered(
     167             :                         ::rtl::Reference<MailDispatcher> /*xMailDispatcher*/,
     168             :                         uno::Reference< mail::XMailMessage> xMailMessage)
     169             : {
     170           0 :     SolarMutexGuard aGuard;
     171           0 :     m_pSendMailDialog->DocumentSent( xMailMessage, true, 0 );
     172           0 :     DeleteAttachments( xMailMessage );
     173           0 : }
     174             : 
     175           0 : void SwMailDispatcherListener_Impl::mailDeliveryError(
     176             :                 ::rtl::Reference<MailDispatcher> /*xMailDispatcher*/,
     177             :                 uno::Reference< mail::XMailMessage> xMailMessage,
     178             :                 const OUString& sErrorMessage)
     179             : {
     180           0 :     SolarMutexGuard aGuard;
     181           0 :     m_pSendMailDialog->DocumentSent( xMailMessage, false, &sErrorMessage );
     182           0 :     DeleteAttachments( xMailMessage );
     183           0 : }
     184             : 
     185           0 : void SwMailDispatcherListener_Impl::DeleteAttachments( uno::Reference< mail::XMailMessage >& xMessage )
     186             : {
     187           0 :     uno::Sequence< mail::MailAttachment > aAttachments = xMessage->getAttachments();
     188             : 
     189           0 :     for(sal_Int32 nFile = 0; nFile < aAttachments.getLength(); ++nFile)
     190             :     {
     191             :         try
     192             :         {
     193           0 :             uno::Reference< beans::XPropertySet > xTransferableProperties( aAttachments[nFile].Data, uno::UNO_QUERY_THROW);
     194           0 :             if( xTransferableProperties.is() )
     195             :             {
     196           0 :                 OUString sURL;
     197           0 :                 xTransferableProperties->getPropertyValue("URL") >>= sURL;
     198           0 :                 if(!sURL.isEmpty())
     199           0 :                     SWUnoHelper::UCB_DeleteFile( sURL );
     200           0 :             }
     201             :         }
     202           0 :         catch (const uno::Exception&)
     203             :         {
     204             :         }
     205           0 :     }
     206           0 : }
     207             : 
     208           0 : class SwSendWarningBox_Impl : public MessageDialog
     209             : {
     210             :     VclMultiLineEdit  *m_pDetailED;
     211             : public:
     212             :     SwSendWarningBox_Impl(vcl::Window* pParent, const OUString& rDetails);
     213             : };
     214             : 
     215           0 : SwSendWarningBox_Impl::SwSendWarningBox_Impl(vcl::Window* pParent, const OUString& rDetails)
     216           0 :     : MessageDialog(pParent, "WarnEmailDialog", "modules/swriter/ui/warnemaildialog.ui")
     217             : {
     218           0 :     get(m_pDetailED, "errors");
     219           0 :     m_pDetailED->SetMaxTextWidth(80 * m_pDetailED->approximate_char_width());
     220           0 :     m_pDetailED->set_width_request(80 * m_pDetailED->approximate_char_width());
     221           0 :     m_pDetailED->set_height_request(8 * m_pDetailED->GetTextHeight());
     222           0 :     m_pDetailED->SetText(rDetails);
     223           0 : }
     224             : 
     225             : #define ITEMID_TASK     1
     226             : #define ITEMID_STATUS   2
     227             : 
     228           0 : SwSendMailDialog::SwSendMailDialog(vcl::Window *pParent, SwMailMergeConfigItem& rConfigItem) :
     229             :     ModelessDialog /*SfxModalDialog*/(pParent, "SendMailsDialog", "modules/swriter/ui/mmsendmails.ui"),
     230           0 :     m_pTransferStatus(get<FixedText>("transferstatus")),
     231           0 :     m_pPaused(get<FixedText>("paused")),
     232           0 :     m_pProgressBar(get<ProgressBar>("progress")),
     233           0 :     m_pErrorStatus(get<FixedText>("errorstatus")),
     234           0 :     m_pContainer(get<SvSimpleTableContainer>("container")),
     235           0 :     m_pStop(get<PushButton>("stop")),
     236           0 :     m_pClose(get<PushButton>("close")),
     237             :     m_sContinue(SW_RES( ST_CONTINUE )),
     238           0 :     m_sStop(m_pStop->GetText()),
     239           0 :     m_sTransferStatus(m_pTransferStatus->GetText()),
     240           0 :     m_sErrorStatus(   m_pErrorStatus->GetText()),
     241             :     m_sSendingTo(   SW_RES(ST_SENDINGTO )),
     242             :     m_sCompleted(   SW_RES(ST_COMPLETED )),
     243             :     m_sFailed(      SW_RES(ST_FAILED     )),
     244             :     m_bCancel(false),
     245             :     m_bDesctructionEnabled(false),
     246             :     m_aImageList( SW_RES( ILIST ) ),
     247           0 :     m_pImpl(new SwSendMailDialog_Impl),
     248             :     m_pConfigItem(&rConfigItem),
     249             :     m_nSendCount(0),
     250           0 :     m_nErrorCount(0)
     251             : {
     252           0 :     Size aSize = m_pContainer->LogicToPixel(Size(226, 80), MAP_APPFONT);
     253           0 :     m_pContainer->set_width_request(aSize.Width());
     254           0 :     m_pContainer->set_height_request(aSize.Height());
     255           0 :     m_pStatus = new SvSimpleTable(*m_pContainer);
     256           0 :     m_pStatusHB = &(m_pStatus->GetTheHeaderBar());
     257             : 
     258           0 :     m_nStatusHeight = m_pContainer->get_height_request();
     259           0 :     OUString sTask(SW_RES(ST_TASK));
     260           0 :     OUString sStatus(SW_RES(ST_STATUS));
     261             : 
     262           0 :     m_pStop->SetClickHdl(LINK( this, SwSendMailDialog, StopHdl_Impl));
     263           0 :     m_pClose->SetClickHdl(LINK( this, SwSendMailDialog, CloseHdl_Impl));
     264             : 
     265           0 :     long nPos1 = aSize.Width()/3 * 2;
     266           0 :     long nPos2 = aSize.Width()/3;
     267             :     m_pStatusHB->InsertItem( ITEMID_TASK, sTask,
     268             :                             nPos1,
     269           0 :                             HIB_LEFT | HIB_VCENTER );
     270             :     m_pStatusHB->InsertItem( ITEMID_STATUS, sStatus,
     271             :                             nPos2,
     272           0 :                             HIB_LEFT | HIB_VCENTER );
     273             : 
     274           0 :     static long nTabs[] = {2, 0, nPos1};
     275           0 :     m_pStatus->SetStyle( m_pStatus->GetStyle() | WB_SORT | WB_HSCROLL | WB_CLIPCHILDREN | WB_TABSTOP );
     276           0 :     m_pStatus->SetSelectionMode( SINGLE_SELECTION );
     277           0 :     m_pStatus->SetTabs(&nTabs[0], MAP_PIXEL);
     278           0 :     m_pStatus->SetSpaceBetweenEntries(3);
     279             : 
     280           0 :     UpdateTransferStatus();
     281           0 : }
     282             : 
     283           0 : SwSendMailDialog::~SwSendMailDialog()
     284             : {
     285           0 :     if(m_pImpl->xMailDispatcher.is())
     286             :     {
     287             :         try
     288             :         {
     289           0 :             if(m_pImpl->xMailDispatcher->isStarted())
     290           0 :                 m_pImpl->xMailDispatcher->stop();
     291           0 :             if(m_pImpl->xConnectedMailService.is() && m_pImpl->xConnectedMailService->isConnected())
     292           0 :                 m_pImpl->xConnectedMailService->disconnect();
     293           0 :             if(m_pImpl->xConnectedInMailService.is() && m_pImpl->xConnectedInMailService->isConnected())
     294           0 :                 m_pImpl->xConnectedInMailService->disconnect();
     295             : 
     296             :             uno::Reference<mail::XMailMessage> xMessage =
     297           0 :                     m_pImpl->xMailDispatcher->dequeueMailMessage();
     298           0 :             while(xMessage.is())
     299             :             {
     300           0 :                 SwMailDispatcherListener_Impl::DeleteAttachments( xMessage );
     301           0 :                 xMessage = m_pImpl->xMailDispatcher->dequeueMailMessage();
     302           0 :             }
     303             :         }
     304           0 :         catch (const uno::Exception&)
     305             :         {
     306             :         }
     307             :     }
     308           0 :     delete m_pStatus;
     309           0 :     delete m_pImpl;
     310           0 : }
     311             : 
     312           0 : void SwSendMailDialog::AddDocument( SwMailDescriptor& rDesc )
     313             : {
     314           0 :     ::osl::MutexGuard aGuard(m_pImpl->aDescriptorMutex);
     315           0 :     m_pImpl->aDescriptors.push_back(rDesc);
     316             :     // if the dialog is already running then continue sending of documents
     317           0 :     if(m_pImpl->xMailDispatcher.is())
     318             :     {
     319           0 :         IterateMails();
     320           0 :     }
     321             : 
     322           0 : }
     323             : 
     324           0 : void SwSendMailDialog::SetDocumentCount( sal_Int32 nAllDocuments )
     325             : {
     326           0 :     m_pImpl->nDocumentCount = nAllDocuments;
     327           0 :     UpdateTransferStatus();
     328           0 : }
     329             : 
     330           0 : IMPL_LINK( SwSendMailDialog, StopHdl_Impl, PushButton*, pButton )
     331             : {
     332           0 :     m_bCancel = true;
     333           0 :     if(m_pImpl->xMailDispatcher.is())
     334             :     {
     335           0 :         if(m_pImpl->xMailDispatcher->isStarted())
     336             :         {
     337           0 :             m_pImpl->xMailDispatcher->stop();
     338           0 :             pButton->SetText(m_sContinue);
     339           0 :             m_pPaused->Show();
     340             :         }
     341             :         else
     342             :         {
     343           0 :             m_pImpl->xMailDispatcher->start();
     344           0 :             pButton->SetText(m_sStop);
     345           0 :             m_pPaused->Show(false);
     346             :         }
     347             :     }
     348           0 :     return 0;
     349             : }
     350             : 
     351           0 : IMPL_LINK_NOARG(SwSendMailDialog, CloseHdl_Impl)
     352             : {
     353           0 :     ModelessDialog::Show( false );
     354           0 :     return 0;
     355             : }
     356             : 
     357           0 : IMPL_STATIC_LINK_NOINSTANCE( SwSendMailDialog, StartSendMails, SwSendMailDialog*, pDialog )
     358             : {
     359           0 :     pDialog->SendMails();
     360           0 :     return 0;
     361             : }
     362             : 
     363           0 : IMPL_STATIC_LINK( SwSendMailDialog, RemoveThis, Timer*, pTimer )
     364             : {
     365           0 :     if( pThis->m_pImpl->xMailDispatcher.is() )
     366             :     {
     367           0 :         if(pThis->m_pImpl->xMailDispatcher->isStarted())
     368           0 :             pThis->m_pImpl->xMailDispatcher->stop();
     369           0 :         if(!pThis->m_pImpl->xMailDispatcher->isShutdownRequested())
     370           0 :             pThis->m_pImpl->xMailDispatcher->shutdown();
     371             :     }
     372             : 
     373           0 :     if( pThis->m_bDesctructionEnabled &&
     374           0 :             (!pThis->m_pImpl->xMailDispatcher.is() ||
     375           0 :                     !pThis->m_pImpl->xMailDispatcher->isRunning()))
     376             :     {
     377           0 :         delete pThis;
     378             :     }
     379             :     else
     380             :     {
     381           0 :         pTimer->Start();
     382             :     }
     383           0 :     return 0;
     384             : }
     385             : 
     386           0 : IMPL_STATIC_LINK_NOINSTANCE( SwSendMailDialog, StopSendMails, SwSendMailDialog*, pDialog )
     387             : {
     388           0 :     if(pDialog->m_pImpl->xMailDispatcher.is() &&
     389           0 :         pDialog->m_pImpl->xMailDispatcher->isStarted())
     390             :     {
     391           0 :         pDialog->m_pImpl->xMailDispatcher->stop();
     392           0 :         pDialog->m_pStop->SetText(pDialog->m_sContinue);
     393           0 :         pDialog->m_pPaused->Show();
     394             :     }
     395           0 :     return 0;
     396             : }
     397             : 
     398           0 : void  SwSendMailDialog::SendMails()
     399             : {
     400           0 :     if(!m_pConfigItem)
     401             :     {
     402             :         OSL_FAIL("config item not set");
     403           0 :         return;
     404             :     }
     405           0 :     EnterWait();
     406             :     //get a mail server connection
     407             :     uno::Reference< mail::XSmtpService > xSmtpServer =
     408             :                 SwMailMergeHelper::ConnectToSmtpServer( *m_pConfigItem,
     409             :                                             m_pImpl->xConnectedInMailService,
     410           0 :                                             aEmptyOUStr, aEmptyOUStr, this );
     411           0 :     bool bIsLoggedIn = xSmtpServer.is() && xSmtpServer->isConnected();
     412           0 :     LeaveWait();
     413           0 :     if(!bIsLoggedIn)
     414             :     {
     415             :         OSL_FAIL("create error message");
     416           0 :         return;
     417             :     }
     418           0 :     m_pImpl->xMailDispatcher.set( new MailDispatcher(xSmtpServer));
     419           0 :     IterateMails();
     420           0 :     m_pImpl->xMailListener = new SwMailDispatcherListener_Impl(*this);
     421           0 :     m_pImpl->xMailDispatcher->addListener(m_pImpl->xMailListener);
     422           0 :     if(!m_bCancel)
     423             :     {
     424           0 :         m_pImpl->xMailDispatcher->start();
     425           0 :     }
     426             : }
     427             : 
     428           0 : void  SwSendMailDialog::IterateMails()
     429             : {
     430           0 :     const SwMailDescriptor* pCurrentMailDescriptor = m_pImpl->GetNextDescriptor();
     431           0 :     while( pCurrentMailDescriptor )
     432             :     {
     433           0 :         if(!SwMailMergeHelper::CheckMailAddress( pCurrentMailDescriptor->sEMail ))
     434             :         {
     435           0 :             Image aInsertImg = m_aImageList.GetImage( FN_FORMULA_CANCEL );
     436             : 
     437           0 :             OUString sMessage = m_sSendingTo;
     438           0 :             OUString sTmp(pCurrentMailDescriptor->sEMail);
     439           0 :             sTmp += "\t";
     440           0 :             sTmp += m_sFailed;
     441           0 :             m_pStatus->InsertEntry( sMessage.replaceFirst("%1", sTmp), aInsertImg, aInsertImg);
     442           0 :             ++m_nSendCount;
     443           0 :             ++m_nErrorCount;
     444           0 :             UpdateTransferStatus( );
     445           0 :             pCurrentMailDescriptor = m_pImpl->GetNextDescriptor();
     446           0 :             continue;
     447             :         }
     448           0 :         SwMailMessage* pMessage = new SwMailMessage;
     449           0 :         uno::Reference< mail::XMailMessage > xMessage = pMessage;
     450           0 :         if(m_pConfigItem->IsMailReplyTo())
     451           0 :             pMessage->setReplyToAddress(m_pConfigItem->GetMailReplyTo());
     452           0 :         pMessage->addRecipient( pCurrentMailDescriptor->sEMail );
     453           0 :         pMessage->SetSenderName( m_pConfigItem->GetMailDisplayName() );
     454           0 :         pMessage->SetSenderAddress( m_pConfigItem->GetMailAddress() );
     455           0 :         if(!pCurrentMailDescriptor->sAttachmentURL.isEmpty())
     456             :         {
     457           0 :             mail::MailAttachment aAttach;
     458           0 :             aAttach.Data =
     459             :                     new SwMailTransferable(
     460             :                         pCurrentMailDescriptor->sAttachmentURL,
     461             :                         pCurrentMailDescriptor->sAttachmentName,
     462           0 :                         pCurrentMailDescriptor->sMimeType );
     463           0 :             aAttach.ReadableName = pCurrentMailDescriptor->sAttachmentName;
     464           0 :             pMessage->addAttachment( aAttach );
     465             :         }
     466           0 :         pMessage->setSubject( pCurrentMailDescriptor->sSubject );
     467             :         uno::Reference< datatransfer::XTransferable> xBody =
     468             :                     new SwMailTransferable(
     469             :                         pCurrentMailDescriptor->sBodyContent,
     470           0 :                         pCurrentMailDescriptor->sBodyMimeType);
     471           0 :         pMessage->setBody( xBody );
     472             : 
     473             :         //CC and BCC are tokenized by ';'
     474           0 :         if(!pCurrentMailDescriptor->sCC.isEmpty())
     475             :         {
     476           0 :             OUString sTokens( pCurrentMailDescriptor->sCC );
     477           0 :             sal_uInt16 nTokens = comphelper::string::getTokenCount(sTokens, ';');
     478           0 :             sal_Int32 nPos = 0;
     479           0 :             for( sal_uInt16 nToken = 0; nToken < nTokens; ++nToken)
     480             :             {
     481           0 :                 OUString sTmp = sTokens.getToken( 0, ';', nPos);
     482           0 :                 if( !sTmp.isEmpty() )
     483           0 :                     pMessage->addCcRecipient( sTmp );
     484           0 :             }
     485             :         }
     486           0 :         if(!pCurrentMailDescriptor->sBCC.isEmpty())
     487             :         {
     488           0 :             OUString sTokens( pCurrentMailDescriptor->sBCC );
     489           0 :             sal_uInt16 nTokens = comphelper::string::getTokenCount(sTokens, ';');
     490           0 :             sal_Int32 nPos = 0;
     491           0 :             for( sal_uInt16 nToken = 0; nToken < nTokens; ++nToken)
     492             :             {
     493           0 :                 OUString sTmp = sTokens.getToken( 0, ';', nPos);
     494           0 :                 if( !sTmp.isEmpty() )
     495           0 :                     pMessage->addBccRecipient( sTmp );
     496           0 :             }
     497             :         }
     498           0 :         m_pImpl->xMailDispatcher->enqueueMailMessage( xMessage );
     499           0 :         pCurrentMailDescriptor = m_pImpl->GetNextDescriptor();
     500           0 :     }
     501           0 :     UpdateTransferStatus();
     502           0 : }
     503             : 
     504           0 : void SwSendMailDialog::ShowDialog()
     505             : {
     506             :     Application::PostUserEvent( STATIC_LINK( this, SwSendMailDialog,
     507           0 :                                                 StartSendMails ), this );
     508           0 :     ModelessDialog::Show();
     509           0 : }
     510             : 
     511           0 : void  SwSendMailDialog::StateChanged( StateChangedType nStateChange )
     512             : {
     513           0 :     ModelessDialog::StateChanged( nStateChange );
     514           0 :     if(StateChangedType::VISIBLE == nStateChange && !IsVisible())
     515             :     {
     516             :         m_pImpl->aRemoveTimer.SetTimeoutHdl( STATIC_LINK( this, SwSendMailDialog,
     517           0 :                                                     RemoveThis ) );
     518           0 :         m_pImpl->aRemoveTimer.Start();
     519             :     }
     520           0 : }
     521             : 
     522           0 : void SwSendMailDialog::DocumentSent( uno::Reference< mail::XMailMessage> xMessage,
     523             :                                         bool bResult,
     524             :                                         const OUString* pError )
     525             : {
     526             :     //sending should stop on send errors
     527           0 :     if(pError &&
     528           0 :         m_pImpl->xMailDispatcher.is() && m_pImpl->xMailDispatcher->isStarted())
     529             :     {
     530             :         Application::PostUserEvent( STATIC_LINK( this, SwSendMailDialog,
     531           0 :                                                     StopSendMails ), this );
     532             :     }
     533           0 :     Image aInsertImg = m_aImageList.GetImage( bResult ? FN_FORMULA_APPLY : FN_FORMULA_CANCEL );
     534             : 
     535           0 :     OUString sMessage = m_sSendingTo;
     536           0 :     OUString sTmp(xMessage->getRecipients()[0]);
     537           0 :     sTmp += "\t";
     538           0 :     sTmp += bResult ? m_sCompleted : m_sFailed;
     539           0 :     m_pStatus->InsertEntry( sMessage.replaceFirst("%1", sTmp), aInsertImg, aInsertImg);
     540           0 :     ++m_nSendCount;
     541           0 :     if(!bResult)
     542           0 :         ++m_nErrorCount;
     543             : 
     544           0 :     UpdateTransferStatus( );
     545             : 
     546           0 :     if (pError)
     547             :     {
     548           0 :         boost::scoped_ptr<SwSendWarningBox_Impl> pDlg(new SwSendWarningBox_Impl(0, *pError));
     549           0 :         pDlg->Execute();
     550           0 :     }
     551           0 : }
     552             : 
     553           0 : void SwSendMailDialog::UpdateTransferStatus()
     554             : {
     555           0 :     OUString sStatus( m_sTransferStatus );
     556           0 :     sStatus = sStatus.replaceFirst("%1", OUString::number(m_nSendCount) );
     557           0 :     sStatus = sStatus.replaceFirst("%2", OUString::number(m_pImpl->aDescriptors.size()));
     558           0 :     m_pTransferStatus->SetText(sStatus);
     559             : 
     560           0 :     sStatus = m_sErrorStatus.replaceFirst("%1", OUString::number(m_nErrorCount) );
     561           0 :     m_pErrorStatus->SetText(sStatus);
     562             : 
     563           0 :     if(m_pImpl->aDescriptors.size())
     564           0 :         m_pProgressBar->SetValue((sal_uInt16)(m_nSendCount * 100 / m_pImpl->aDescriptors.size()));
     565             :     else
     566           0 :         m_pProgressBar->SetValue(0);
     567           0 : }
     568             : 
     569           0 : void SwSendMailDialog::AllMailsSent()
     570             : {
     571           0 :     m_pStop->Enable(false);
     572           0 : }
     573             : 
     574             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10