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