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