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