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