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