24#include <bitmaps.hlst>
27#include <osl/diagnose.h>
29#include <com/sun/star/mail/XSmtpService.hpp>
43 :
vcl::OWizardPage(pPage, pWizard,
"modules/swriter/ui/mmoutputtypepage.ui",
"MMOutputTypePage")
45 , m_xLetterRB(m_xBuilder->weld_radio_button(
"letter"))
46 , m_xMailRB(m_xBuilder->weld_radio_button(
"email"))
47 , m_xLetterHint(m_xBuilder->weld_label(
"letterft"))
48 , m_xMailHint(m_xBuilder->weld_label(
"emailft"))
68 bool bLetter = m_xLetterRB->get_active();
69 m_xLetterHint->set_visible(bLetter);
70 m_xMailHint->set_visible(!bLetter);
71 m_pWizard->GetConfigItem().SetOutputToLetter(bLetter);
72 m_pWizard->UpdateRoadmap();
129 virtual void idle()
override;
130 virtual void mailDelivered(uno::Reference< mail::XMailMessage> xMailMessage)
override;
132 uno::Reference< mail::XMailMessage> xMailMessage,
const OUString& sErrorMessage)
override;
134 static void DeleteAttachments( uno::Reference< mail::XMailMessage >
const & xMessage );
139SwMailDispatcherListener_Impl::SwMailDispatcherListener_Impl(
SwSendMailDialog& rParentDlg)
140 : m_rSendMailDialog(rParentDlg)
144void SwMailDispatcherListener_Impl::idle()
147 m_rSendMailDialog.AllMailsSent();
150void SwMailDispatcherListener_Impl::mailDelivered(
151 uno::Reference< mail::XMailMessage> xMailMessage)
154 m_rSendMailDialog.DocumentSent( xMailMessage,
true,
nullptr );
155 DeleteAttachments( xMailMessage );
158void SwMailDispatcherListener_Impl::mailDeliveryError(
160 uno::Reference< mail::XMailMessage> xMailMessage,
161 const OUString& sErrorMessage)
164 m_rSendMailDialog.DocumentSent( xMailMessage,
false, &sErrorMessage );
165 DeleteAttachments( xMailMessage );
168void SwMailDispatcherListener_Impl::DeleteAttachments( uno::Reference< mail::XMailMessage >
const & xMessage )
170 const uno::Sequence< mail::MailAttachment > aAttachments = xMessage->getAttachments();
172 for(
const auto& rAttachment : aAttachments)
176 uno::Reference< beans::XPropertySet > xTransferableProperties( rAttachment.Data, uno::UNO_QUERY_THROW);
178 xTransferableProperties->getPropertyValue(
"URL") >>= sURL;
182 catch (
const uno::Exception&)
192 std::unique_ptr<weld::TextView> m_xDetailED;
194 SwSendWarningBox_Impl(
weld::Window* pParent,
const OUString& rDetails)
195 : MessageDialogController(pParent,
"modules/swriter/ui/warnemaildialog.ui",
"WarnEmailDialog",
"grid")
196 , m_xDetailED(m_xBuilder->weld_text_view(
"errors"))
198 m_xDetailED->set_size_request(80 * m_xDetailED->get_approximate_digit_width(),
199 8 * m_xDetailED->get_text_height());
200 m_xDetailED->set_text(rDetails);
207 : GenericDialogController(pParent,
"modules/swriter/ui/mmsendmails.ui",
"SendMailsDialog")
208 , m_sContinue(
SwResId( ST_CONTINUE ))
209 , m_sClose(
SwResId(ST_CLOSE_DIALOG))
210 , m_sSendingTo(
SwResId(ST_SENDINGTO ))
211 , m_sCompleted(
SwResId(ST_COMPLETED ))
212 , m_sFailed(
SwResId(ST_FAILED ))
213 , m_sAddressInvalid(
SwResId(ST_ADDRESS_INVALID))
215 , m_bDestructionEnabled(false)
217 , m_pConfigItem(&rConfigItem)
218 , m_nExpectedCount(0)
219 , m_nProcessedCount(0)
221 , m_xTransferStatus(m_xBuilder->weld_label(
"transferstatus"))
222 , m_xPaused(m_xBuilder->weld_label(
"paused"))
223 , m_xProgressBar(m_xBuilder->weld_progress_bar(
"progress"))
224 , m_xErrorStatus(m_xBuilder->weld_label(
"errorstatus"))
225 , m_xStatus(m_xBuilder->weld_tree_view(
"container"))
226 , m_xStop(m_xBuilder->weld_button(
"stop"))
227 , m_xCancel(m_xBuilder->weld_button(
"cancel"))
240 std::vector<int> aWidths
242 o3tl::narrowing<int>(
m_xStatus->get_checkbox_column_width()),
243 o3tl::narrowing<int>(aSize.
Width()/3 * 2)
245 m_xStatus->set_column_fixed_widths(aWidths);
253 if(!
m_pImpl->xMailDispatcher.is())
258 if(
m_pImpl->xMailDispatcher->isStarted())
259 m_pImpl->xMailDispatcher->stop();
260 if(
m_pImpl->xConnectedInMailService.is() &&
m_pImpl->xConnectedInMailService->isConnected())
261 m_pImpl->xConnectedInMailService->disconnect();
263 uno::Reference<mail::XMailMessage> xMessage =
264 m_pImpl->xMailDispatcher->dequeueMailMessage();
267 SwMailDispatcherListener_Impl::DeleteAttachments( xMessage );
268 xMessage =
m_pImpl->xMailDispatcher->dequeueMailMessage();
271 catch (
const uno::Exception&)
278 std::scoped_lock aGuard(
m_pImpl->aDescriptorMutex);
279 m_pImpl->aDescriptors.push_back(rDesc);
281 if(
m_pImpl->xMailDispatcher.is())
290 if(!
m_pImpl->xMailDispatcher.is())
293 if(
m_pImpl->xMailDispatcher->isStarted())
295 m_pImpl->xMailDispatcher->stop();
296 rButton.set_label(m_sContinue);
301 m_pImpl->xMailDispatcher->start();
302 rButton.set_label(m_sStop);
311 if (m_bDestructionEnabled)
327 if(
m_pImpl->xMailDispatcher.is() )
329 if(
m_pImpl->xMailDispatcher->isStarted())
330 m_pImpl->xMailDispatcher->stop();
331 if(!
m_pImpl->xMailDispatcher->isShutdownRequested())
332 m_pImpl->xMailDispatcher->shutdown();
335 if( m_bDestructionEnabled &&
336 (!
m_pImpl->xMailDispatcher.is() ||
337 !
m_pImpl->xMailDispatcher->isRunning()))
350 if(pDialog->
m_pImpl->xMailDispatcher.is() &&
351 pDialog->
m_pImpl->xMailDispatcher->isStarted())
353 pDialog->
m_pImpl->xMailDispatcher->stop();
363 OSL_FAIL(
"config item not set");
366 auto xWait(std::make_unique<weld::WaitObject>(
m_xDialog.get()));
368 uno::Reference< mail::XSmtpService > xSmtpServer =
370 m_pImpl->xConnectedInMailService,
371 OUString(), OUString(),
m_xDialog.get());
372 bool bIsLoggedIn = xSmtpServer.is() && xSmtpServer->isConnected();
376 OSL_FAIL(
"create error message");
381 m_pImpl->xMailListener =
new SwMailDispatcherListener_Impl(*
this);
385 m_pImpl->xMailDispatcher->start();
392 while( pCurrentMailDescriptor )
404 pCurrentMailDescriptor =
m_pImpl->GetNextDescriptor();
410 pMessage->addRecipient( pCurrentMailDescriptor->
sEMail );
415 mail::MailAttachment aAttach;
422 pMessage->addAttachment( aAttach );
424 pMessage->setSubject( pCurrentMailDescriptor->
sSubject );
425 uno::Reference< datatransfer::XTransferable> xBody =
429 pMessage->setBody( xBody );
432 if(!pCurrentMailDescriptor->
sCC.isEmpty())
437 OUString sTmp = pCurrentMailDescriptor->
sCC.getToken( 0,
';',
nPos );
438 if( !sTmp.isEmpty() )
439 pMessage->addCcRecipient( sTmp );
443 if(!pCurrentMailDescriptor->
sBCC.isEmpty())
448 OUString sTmp = pCurrentMailDescriptor->
sBCC.getToken( 0,
';',
nPos );
449 if( !sTmp.isEmpty() )
450 pMessage->addBccRecipient( sTmp );
454 m_pImpl->xMailDispatcher->enqueueMailMessage( pMessage );
455 pCurrentMailDescriptor =
m_pImpl->GetNextDescriptor();
463 StartSendMails ),
this );
469 const OUString* pError )
473 m_pImpl->xMailDispatcher.is() &&
m_pImpl->xMailDispatcher->isStarted())
476 StopSendMails ),
this );
478 OUString sInsertImg(bResult ? OUString(RID_BMP_FORMULA_APPLY) : OUString(RID_BMP_FORMULA_CANCEL));
493 SwSendWarningBox_Impl aDlg(
m_xDialog.get(), *pError);
508 if (!
m_pImpl->aDescriptors.empty())
Reference< XExecutableDialog > m_xDialog
static ImplSVEvent * PostUserEvent(const Link< void *, void > &rLink, void *pCaller=nullptr, bool bReferenceLink=false)
MailDispatcher listener interface.
A MailDispatcher should be used for sending a bunch a mail messages asynchronously.
constexpr tools::Long Height() const
constexpr tools::Long Width() const
OUString const & GetMailAddress() const
OUString const & GetMailDisplayName() const
bool IsMailReplyTo() const
OUString const & GetMailReplyTo() const
bool IsOutputToLetter() const
SwMailMergeOutputTypePage(weld::Container *pPage, SwMailMergeWizard *pWizard)
virtual ~SwMailMergeOutputTypePage() override
std::unique_ptr< weld::RadioButton > m_xLetterRB
std::unique_ptr< weld::RadioButton > m_xMailRB
SwMailMergeWizard * m_pWizard
SwMailMergeConfigItem & GetConfigItem()
void StartSend(sal_Int32 nExpectedCount)
SwMailMergeConfigItem * m_pConfigItem
void UpdateTransferStatus()
std::unique_ptr< weld::Label > m_xPaused
OUString m_sAddressInvalid
std::unique_ptr< weld::Label > m_xTransferStatus
std::unique_ptr< SwSendMailDialog_Impl > m_pImpl
void AddDocument(SwMailDescriptor const &rDesc)
SwSendMailDialog(weld::Window *pParent, SwMailMergeConfigItem &)
std::unique_ptr< weld::TreeView > m_xStatus
std::unique_ptr< weld::ProgressBar > m_xProgressBar
sal_Int32 m_nProcessedCount
void DocumentSent(css::uno::Reference< css::mail::XMailMessage > const &xMessage, bool bResult, const OUString *pError)
std::unique_ptr< weld::Button > m_xCancel
OUString m_sTransferStatus
std::unique_ptr< weld::Label > m_xErrorStatus
virtual ~SwSendMailDialog() override
std::unique_ptr< weld::Button > m_xStop
sal_Int32 m_nExpectedCount
void SetPriority(TaskPriority ePriority)
std::shared_ptr< weld::Dialog > m_xDialog
#define LINK(Instance, Class, Member)
IMPL_LINK_NOARG(SwMailMergeOutputTypePage, TypeHdl_Impl, weld::Toggleable &, void)
IMPL_STATIC_LINK(SwSendMailDialog, StartSendMails, void *, pDialog, void)
IMPL_LINK(SwSendMailDialog, StopHdl_Impl, weld::Button &, rButton, void)
bool UCB_DeleteFile(const OUString &rURL)
uno::Reference< mail::XSmtpService > ConnectToSmtpServer(SwMailMergeConfigItem const &rConfigItem, uno::Reference< mail::XMailService > &rxInMailService, const OUString &rInMailServerPassword, const OUString &rOutMailServerPassword, weld::Window *pDialogParentWindow)
bool CheckMailAddress(std::u16string_view aMailAddress)
std::recursive_mutex aDescriptorMutex
uno::Reference< mail::XMailService > xConnectedInMailService
::rtl::Reference< MailDispatcher > xMailDispatcher
std::vector< SwMailDescriptor > aDescriptors
const SwMailDescriptor * GetNextDescriptor()
sal_uInt32 nCurrentDescriptor
::rtl::Reference< IMailDispatcherListener > xMailListener
OUString SwResId(TranslateId aId)