1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
19 #ifndef INCLUDED_SW_SOURCE_UIBASE_INC_MAILMERGEHELPER_HXX
20 #define INCLUDED_SW_SOURCE_UIBASE_INC_MAILMERGEHELPER_HXX
22 #include <com/sun/star/uno/Sequence.h>
23 #include <com/sun/star/mail/XAuthenticator.hpp>
24 #include <com/sun/star/mail/XConnectionListener.hpp>
25 #include <com/sun/star/uno/XCurrentContext.hpp>
26 #include <com/sun/star/mail/XMailMessage.hpp>
27 #include <com/sun/star/datatransfer/XTransferable.hpp>
28 #include <com/sun/star/beans/XPropertySet.hpp>
29 #include <cppuhelper/implbase.hxx>
30 #include <comphelper/compbase.hxx>
32 #include <vcl/customweld.hxx>
33 #include <vcl/weld.hxx>
34 #include <rtl/ustring.hxx>
37 class SwMailMergeConfigItem
;
39 namespace com::sun::star::mail
{
44 namespace SwMailMergeHelper
46 SW_DLLPUBLIC OUString
CallSaveAsDialog(weld::Window
* pParent
, OUString
& rFilter
);
47 SW_DLLPUBLIC
bool CheckMailAddress(std::u16string_view aMailAddress
);
48 SW_DLLPUBLIC
css::uno::Reference
<css::mail::XSmtpService
> ConnectToSmtpServer(
49 SwMailMergeConfigItem
const & rConfigItem
,
50 css::uno::Reference
<css::mail::XMailService
>& xInMailService
,
51 const OUString
& rInMailServerPassword
,
52 const OUString
& rOutMailServerPassword
,
53 weld::Window
* pDialogParentWindow
= nullptr);
56 struct SwAddressPreview_Impl
;
58 // Preview window used to show the possible selection of address blocks
59 // and also the resulting address filled with database data
60 class SW_DLLPUBLIC SwAddressPreview final
: public weld::CustomWidgetController
62 std::unique_ptr
<SwAddressPreview_Impl
> m_pImpl
;
63 std::unique_ptr
<weld::ScrolledWindow
> m_xVScrollBar
;
64 Link
<LinkParamNone
*,void> m_aSelectHdl
;
66 void DrawText_Impl(vcl::RenderContext
& rRenderContext
, std::u16string_view rAddress
,
67 const Point
& rTopLeft
, const Size
& rSize
, bool bIsSelected
);
69 virtual void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&) override
;
70 virtual bool MouseButtonDown( const MouseEvent
& rMEvt
) override
;
71 virtual bool KeyInput( const KeyEvent
& rKEvt
) override
;
72 void UpdateScrollBar();
74 DECL_DLLPRIVATE_LINK(ScrollHdl
, weld::ScrolledWindow
&,void);
77 SwAddressPreview(std::unique_ptr
<weld::ScrolledWindow
> xParent
);
78 virtual ~SwAddressPreview() override
;
80 /** The address string is a list of address elements separated by spaces
81 and breaks. The addresses fit into the given layout. If more addresses then
82 rows/columns should be used a scrollbar will be added.
84 AddAddress appends the new address to the already added ones.
85 Initially the first added address will be selected
87 void AddAddress(const OUString
& rAddress
);
88 // for preview mode - replaces the currently used address by the given one
89 void SetAddress(const OUString
& rAddress
);
90 // removes all addresses
93 // returns the selected address
94 sal_uInt16
GetSelectedAddress() const;
95 void SelectAddress(sal_uInt16 nSelect
);
96 void ReplaceSelectedAddress(const OUString
&);
97 void RemoveSelectedAddress();
99 // set the number of rows and columns of addresses
100 void SetLayout(sal_uInt16 nRows
, sal_uInt16 nColumns
);
101 void EnableScrollBar();
103 // fill the actual data into a string (address block or greeting)
104 static OUString
FillData(const OUString
& rAddress
, SwMailMergeConfigItem
const & rConfigItem
,
105 const css::uno::Sequence
<OUString
>* pAssignments
= nullptr);
107 void SetSelectHdl (const Link
<LinkParamNone
*,void>& rLink
) { m_aSelectHdl
= rLink
; }
111 // iterate over an address block or a greeting line the iterator returns the
112 // parts either as pure string or as column
113 struct SwMergeAddressItem
125 class SW_DLLPUBLIC SwAddressIterator
129 SwAddressIterator(OUString aAddress
) :
130 m_sAddress(std::move(aAddress
))
133 SwMergeAddressItem
Next();
134 bool HasMore() const { return !m_sAddress
.isEmpty(); }
137 class SW_DLLPUBLIC SwAuthenticator final
:
138 public cppu::WeakImplHelper
<css::mail::XAuthenticator
>
140 OUString m_aUserName
;
141 OUString m_aPassword
;
142 weld::Window
* m_pParentWindow
;
145 : m_pParentWindow(nullptr)
147 SwAuthenticator(OUString username
, OUString password
, weld::Window
* pParent
)
148 : m_aUserName(std::move(username
))
149 , m_aPassword(std::move(password
))
150 , m_pParentWindow(pParent
)
152 virtual ~SwAuthenticator() override
;
154 virtual OUString SAL_CALL
getUserName() override
;
155 virtual OUString SAL_CALL
getPassword() override
;
159 class SW_DLLPUBLIC SwConnectionContext final
: public cppu::WeakImplHelper
<css::uno::XCurrentContext
>
161 OUString m_sMailServer
;
163 OUString m_sConnectionType
;
166 SwConnectionContext(OUString aMailServer
, sal_Int16 nPort
, OUString aConnectionType
);
167 virtual ~SwConnectionContext() override
;
169 virtual css::uno::Any SAL_CALL
getValueByName(const OUString
& Name
) override
;
172 class SW_DLLPUBLIC SwConnectionListener final
:
173 public comphelper::WeakComponentImplHelper
<css::mail::XConnectionListener
>
175 using comphelper::WeakComponentImplHelperBase::disposing
;
178 virtual ~SwConnectionListener() override
;
180 virtual void SAL_CALL
connected(const css::lang::EventObject
& aEvent
) override
;
182 virtual void SAL_CALL
disconnected(const css::lang::EventObject
& aEvent
) override
;
184 virtual void SAL_CALL
disposing(const css::lang::EventObject
& aEvent
) override
;
187 class SW_DLLPUBLIC SwMailTransferable final
:
188 public comphelper::WeakComponentImplHelper
<css::datatransfer::XTransferable
, css::beans::XPropertySet
>
190 OUString m_aMimeType
;
197 SwMailTransferable(OUString aURL
, OUString aName
, OUString aMimeType
);
198 SwMailTransferable(OUString aBody
, OUString aMimeType
);
199 virtual ~SwMailTransferable() override
;
200 virtual css::uno::Any SAL_CALL
getTransferData(const css::datatransfer::DataFlavor
& aFlavor
) override
;
202 virtual css::uno::Sequence
<css::datatransfer::DataFlavor
> SAL_CALL
getTransferDataFlavors() override
;
203 virtual sal_Bool SAL_CALL
isDataFlavorSupported(const css::datatransfer::DataFlavor
& aFlavor
) override
;
206 virtual css::uno::Reference
<css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo() override
;
207 virtual void SAL_CALL
setPropertyValue(const OUString
& aPropertyName
, const css::uno::Any
& aValue
) override
;
209 virtual css::uno::Any SAL_CALL
getPropertyValue(const OUString
& PropertyName
) override
;
210 virtual void SAL_CALL
addPropertyChangeListener(const OUString
& aPropertyName
,
211 const css::uno::Reference
<css::beans::XPropertyChangeListener
>& xListener
) override
;
212 virtual void SAL_CALL
removePropertyChangeListener(const OUString
& aPropertyName
,
213 const css::uno::Reference
<css::beans::XPropertyChangeListener
>& aListener
) override
;
214 virtual void SAL_CALL
addVetoableChangeListener(const OUString
& PropertyName
,
215 const css::uno::Reference
<css::beans::XVetoableChangeListener
>& aListener
) override
;
216 virtual void SAL_CALL
removeVetoableChangeListener(const OUString
& PropertyName
,
217 const css::uno::Reference
<css::beans::XVetoableChangeListener
>& aListener
) override
;
221 class SW_DLLPUBLIC SwMailMessage final
:
222 public comphelper::WeakComponentImplHelper
<css::mail::XMailMessage
>
224 OUString m_sSenderName
;
225 OUString m_sSenderAddress
;
226 OUString m_sReplyToAddress
;
229 css::uno::Reference
<css::datatransfer::XTransferable
> m_xBody
;
230 // css::mail::MailMessageBody m_aBody;
232 css::uno::Sequence
<OUString
> m_aRecipients
;
233 css::uno::Sequence
<OUString
> m_aCcRecipients
;
234 css::uno::Sequence
<OUString
> m_aBccRecipients
;
235 // css::uno::Sequence<css::mail::MailAttachmentDescriptor> m_aAttachments;
236 css::uno::Sequence
<css::mail::MailAttachment
> m_aAttachments
;
239 virtual ~SwMailMessage() override
;
242 virtual OUString SAL_CALL
getSenderName() override
;
243 virtual OUString SAL_CALL
getSenderAddress() override
;
244 virtual OUString SAL_CALL
getReplyToAddress() override
;
245 virtual void SAL_CALL
setReplyToAddress( const OUString
& _replytoaddress
) override
;
246 virtual OUString SAL_CALL
getSubject() override
;
247 virtual void SAL_CALL
setSubject(const OUString
& _subject
) override
;
249 virtual css::uno::Reference
<css::datatransfer::XTransferable
> SAL_CALL
getBody() override
;
250 virtual void SAL_CALL
setBody(const css::uno::Reference
<css::datatransfer::XTransferable
>& _body
) override
;
253 virtual void SAL_CALL
addRecipient( const OUString
& sRecipientAddress
) override
;
254 virtual void SAL_CALL
addCcRecipient( const OUString
& sRecipientAddress
) override
;
255 virtual void SAL_CALL
addBccRecipient( const OUString
& sRecipientAddress
) override
;
256 virtual css::uno::Sequence
<OUString
> SAL_CALL
getRecipients() override
;
257 virtual css::uno::Sequence
<OUString
> SAL_CALL
getCcRecipients() override
;
258 virtual css::uno::Sequence
<OUString
> SAL_CALL
getBccRecipients() override
;
259 virtual void SAL_CALL
addAttachment(const css::mail::MailAttachment
& aMailAttachment
) override
;
260 virtual css::uno::Sequence
<css::mail::MailAttachment
> SAL_CALL
getAttachments() override
;
261 void SetSenderName(const OUString
& rSenderName
)
263 m_sSenderName
= rSenderName
;
265 void SetSenderAddress(const OUString
& rSenderAddress
)
267 m_sSenderAddress
= rSenderAddress
;
273 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */