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 <cppuhelper/compbase.hxx>
31 #include <vcl/customweld.hxx>
32 #include <vcl/weld.hxx>
33 #include <rtl/ustring.hxx>
36 class SwMailMergeConfigItem
;
38 namespace com::sun::star::mail
{
43 namespace SwMailMergeHelper
45 SW_DLLPUBLIC OUString
CallSaveAsDialog(weld::Window
* pParent
, OUString
& rFilter
);
46 SW_DLLPUBLIC
bool CheckMailAddress(const OUString
& rMailAddress
);
47 SW_DLLPUBLIC
css::uno::Reference
<css::mail::XSmtpService
> ConnectToSmtpServer(
48 SwMailMergeConfigItem
const & rConfigItem
,
49 css::uno::Reference
<css::mail::XMailService
>& xInMailService
,
50 const OUString
& rInMailServerPassword
,
51 const OUString
& rOutMailServerPassword
,
52 weld::Window
* pDialogParentWindow
= nullptr);
55 struct SwAddressPreview_Impl
;
57 // Preview window used to show the possible selection of address blocks
58 // and also the resulting address filled with database data
59 class SW_DLLPUBLIC SwAddressPreview
: public weld::CustomWidgetController
61 std::unique_ptr
<SwAddressPreview_Impl
> pImpl
;
62 std::unique_ptr
<weld::ScrolledWindow
> m_xVScrollBar
;
63 Link
<LinkParamNone
*,void> m_aSelectHdl
;
65 void DrawText_Impl(vcl::RenderContext
& rRenderContext
, const OUString
& rAddress
,
66 const Point
& rTopLeft
, const Size
& rSize
, bool bIsSelected
);
68 virtual void Paint(vcl::RenderContext
& rRenderContext
, const tools::Rectangle
&) override
;
69 virtual bool MouseButtonDown( const MouseEvent
& rMEvt
) override
;
70 virtual bool KeyInput( const KeyEvent
& rKEvt
) override
;
71 void UpdateScrollBar();
73 DECL_LINK(ScrollHdl
, weld::ScrolledWindow
&,void);
76 SwAddressPreview(std::unique_ptr
<weld::ScrolledWindow
> xParent
);
77 virtual ~SwAddressPreview() override
;
79 /** The address string is a list of address elements separated by spaces
80 and breaks. The addresses fit into the given layout. If more addresses then
81 rows/columns should be used a scrollbar will be added.
83 AddAddress appends the new address to the already added ones.
84 Initially the first added address will be selected
86 void AddAddress(const OUString
& rAddress
);
87 // for preview mode - replaces the currently used address by the given one
88 void SetAddress(const OUString
& rAddress
);
89 // removes all addresses
92 // returns the selected address
93 sal_uInt16
GetSelectedAddress() const;
94 void SelectAddress(sal_uInt16 nSelect
);
95 void ReplaceSelectedAddress(const OUString
&);
96 void RemoveSelectedAddress();
98 // set the number of rows and columns of addresses
99 void SetLayout(sal_uInt16 nRows
, sal_uInt16 nColumns
);
100 void EnableScrollBar();
102 // fill the actual data into a string (address block or greeting)
103 static OUString
FillData(const OUString
& rAddress
, SwMailMergeConfigItem
const & rConfigItem
,
104 const css::uno::Sequence
<OUString
>* pAssignments
= nullptr);
106 void SetSelectHdl (const Link
<LinkParamNone
*,void>& rLink
) { m_aSelectHdl
= rLink
; }
110 // iterate over an address block or a greeting line the iterator returns the
111 // parts either as pure string or as column
112 struct SwMergeAddressItem
124 class SW_DLLPUBLIC SwAddressIterator
128 SwAddressIterator(const OUString
& rAddress
) :
132 SwMergeAddressItem
Next();
133 bool HasMore() const { return !sAddress
.isEmpty(); }
136 class SW_DLLPUBLIC SwAuthenticator
:
137 public cppu::WeakImplHelper
<css::mail::XAuthenticator
>
139 OUString m_aUserName
;
140 OUString m_aPassword
;
141 weld::Window
* m_pParentWindow
;
144 : m_pParentWindow(nullptr)
146 SwAuthenticator(const OUString
& username
, const OUString
& password
, weld::Window
* pParent
)
147 : m_aUserName(username
)
148 , m_aPassword(password
)
149 , m_pParentWindow(pParent
)
151 virtual ~SwAuthenticator() override
;
153 virtual OUString SAL_CALL
getUserName() override
;
154 virtual OUString SAL_CALL
getPassword() override
;
158 class SW_DLLPUBLIC SwConnectionContext
: public cppu::WeakImplHelper
<css::uno::XCurrentContext
>
160 OUString m_sMailServer
;
162 OUString m_sConnectionType
;
165 SwConnectionContext(const OUString
& rMailServer
, sal_Int16 nPort
, const OUString
& rConnectionType
);
166 virtual ~SwConnectionContext() override
;
168 virtual css::uno::Any SAL_CALL
getValueByName(const OUString
& Name
) override
;
177 class SW_DLLPUBLIC SwConnectionListener
:
179 public cppu::WeakComponentImplHelper
<css::mail::XConnectionListener
>
181 using cppu::WeakComponentImplHelperBase::disposing
;
184 SwConnectionListener() :
185 cppu::WeakComponentImplHelper
<css::mail::XConnectionListener
>(m_aMutex
)
187 virtual ~SwConnectionListener() override
;
189 virtual void SAL_CALL
connected(const css::lang::EventObject
& aEvent
) override
;
191 virtual void SAL_CALL
disconnected(const css::lang::EventObject
& aEvent
) override
;
193 virtual void SAL_CALL
disposing(const css::lang::EventObject
& aEvent
) override
;
196 class SW_DLLPUBLIC SwMailTransferable
:
198 public cppu::WeakComponentImplHelper
<css::datatransfer::XTransferable
, css::beans::XPropertySet
>
200 OUString m_aMimeType
;
207 SwMailTransferable(const OUString
& rURL
, const OUString
& rName
, const OUString
& rMimeType
);
208 SwMailTransferable(const OUString
& rBody
, const OUString
& rMimeType
);
209 virtual ~SwMailTransferable() override
;
210 virtual css::uno::Any SAL_CALL
getTransferData(const css::datatransfer::DataFlavor
& aFlavor
) override
;
212 virtual css::uno::Sequence
<css::datatransfer::DataFlavor
> SAL_CALL
getTransferDataFlavors() override
;
213 virtual sal_Bool SAL_CALL
isDataFlavorSupported(const css::datatransfer::DataFlavor
& aFlavor
) override
;
216 virtual css::uno::Reference
<css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo() override
;
217 virtual void SAL_CALL
setPropertyValue(const OUString
& aPropertyName
, const css::uno::Any
& aValue
) override
;
219 virtual css::uno::Any SAL_CALL
getPropertyValue(const OUString
& PropertyName
) override
;
220 virtual void SAL_CALL
addPropertyChangeListener(const OUString
& aPropertyName
,
221 const css::uno::Reference
<css::beans::XPropertyChangeListener
>& xListener
) override
;
222 virtual void SAL_CALL
removePropertyChangeListener(const OUString
& aPropertyName
,
223 const css::uno::Reference
<css::beans::XPropertyChangeListener
>& aListener
) override
;
224 virtual void SAL_CALL
addVetoableChangeListener(const OUString
& PropertyName
,
225 const css::uno::Reference
<css::beans::XVetoableChangeListener
>& aListener
) override
;
226 virtual void SAL_CALL
removeVetoableChangeListener(const OUString
& PropertyName
,
227 const css::uno::Reference
<css::beans::XVetoableChangeListener
>& aListener
) override
;
231 class SW_DLLPUBLIC SwMailMessage
:
233 public cppu::WeakComponentImplHelper
<css::mail::XMailMessage
>
235 OUString m_sSenderName
;
236 OUString m_sSenderAddress
;
237 OUString m_sReplyToAddress
;
240 css::uno::Reference
<css::datatransfer::XTransferable
> m_xBody
;
241 // css::mail::MailMessageBody m_aBody;
243 css::uno::Sequence
<OUString
> m_aRecipients
;
244 css::uno::Sequence
<OUString
> m_aCcRecipients
;
245 css::uno::Sequence
<OUString
> m_aBccRecipients
;
246 // css::uno::Sequence<css::mail::MailAttachmentDescriptor> m_aAttachments;
247 css::uno::Sequence
<css::mail::MailAttachment
> m_aAttachments
;
250 virtual ~SwMailMessage() override
;
253 virtual OUString SAL_CALL
getSenderName() override
;
254 virtual OUString SAL_CALL
getSenderAddress() override
;
255 virtual OUString SAL_CALL
getReplyToAddress() override
;
256 virtual void SAL_CALL
setReplyToAddress( const OUString
& _replytoaddress
) override
;
257 virtual OUString SAL_CALL
getSubject() override
;
258 virtual void SAL_CALL
setSubject(const OUString
& _subject
) override
;
260 virtual css::uno::Reference
<css::datatransfer::XTransferable
> SAL_CALL
getBody() override
;
261 virtual void SAL_CALL
setBody(const css::uno::Reference
<css::datatransfer::XTransferable
>& _body
) override
;
264 virtual void SAL_CALL
addRecipient( const OUString
& sRecipientAddress
) override
;
265 virtual void SAL_CALL
addCcRecipient( const OUString
& sRecipientAddress
) override
;
266 virtual void SAL_CALL
addBccRecipient( const OUString
& sRecipientAddress
) override
;
267 virtual css::uno::Sequence
<OUString
> SAL_CALL
getRecipients() override
;
268 virtual css::uno::Sequence
<OUString
> SAL_CALL
getCcRecipients() override
;
269 virtual css::uno::Sequence
<OUString
> SAL_CALL
getBccRecipients() override
;
270 virtual void SAL_CALL
addAttachment(const css::mail::MailAttachment
& aMailAttachment
) override
;
271 virtual css::uno::Sequence
<css::mail::MailAttachment
> SAL_CALL
getAttachments() override
;
272 void SetSenderName(const OUString
& rSenderName
)
274 m_sSenderName
= rSenderName
;
276 void SetSenderAddress(const OUString
& rSenderAddress
)
278 m_sSenderAddress
= rSenderAddress
;
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */