LibreOffice Module sw (master) 1
mailmergehelper.hxx
Go to the documentation of this file.
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#ifndef INCLUDED_SW_SOURCE_UIBASE_INC_MAILMERGEHELPER_HXX
20#define INCLUDED_SW_SOURCE_UIBASE_INC_MAILMERGEHELPER_HXX
21
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>
31#include <utility>
32#include <vcl/customweld.hxx>
33#include <vcl/weld.hxx>
34#include <rtl/ustring.hxx>
35#include <swdllapi.h>
36
38
39namespace com::sun::star::mail {
40 class XMailService;
41 class XSmtpService;
42}
43
44namespace SwMailMergeHelper
45{
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);
54}
55
57
58// Preview window used to show the possible selection of address blocks
59// and also the resulting address filled with database data
61{
62 std::unique_ptr<SwAddressPreview_Impl> m_pImpl;
63 std::unique_ptr<weld::ScrolledWindow> m_xVScrollBar;
65
66 void DrawText_Impl(vcl::RenderContext& rRenderContext, std::u16string_view rAddress,
67 const Point& rTopLeft, const Size& rSize, bool bIsSelected);
68
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();
73
75
76public:
77 SwAddressPreview(std::unique_ptr<weld::ScrolledWindow> xParent);
78 virtual ~SwAddressPreview() override;
79
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
91 void Clear();
92
93 // returns the selected address
94 sal_uInt16 GetSelectedAddress() const;
95 void SelectAddress(sal_uInt16 nSelect);
96 void ReplaceSelectedAddress(const OUString&);
97 void RemoveSelectedAddress();
98
99 // set the number of rows and columns of addresses
100 void SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns);
101 void EnableScrollBar();
102
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);
106
107 void SetSelectHdl (const Link<LinkParamNone*,void>& rLink) { m_aSelectHdl = rLink; }
108};
109
110
111// iterate over an address block or a greeting line the iterator returns the
112// parts either as pure string or as column
114{
115 OUString sText;
118
120 : bIsColumn(false)
121 , bIsReturn(false)
122 {}
123};
124
126{
127 OUString m_sAddress;
128public:
129 SwAddressIterator(OUString aAddress) :
130 m_sAddress(std::move(aAddress))
131 {}
132
134 bool HasMore() const { return !m_sAddress.isEmpty(); }
135};
136
138 public cppu::WeakImplHelper<css::mail::XAuthenticator>
139{
140 OUString m_aUserName;
141 OUString m_aPassword;
143public:
145 : m_pParentWindow(nullptr)
146 {}
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)
151 {}
152 virtual ~SwAuthenticator() override;
153
154 virtual OUString SAL_CALL getUserName() override;
155 virtual OUString SAL_CALL getPassword() override;
156
157};
158
159class SW_DLLPUBLIC SwConnectionContext final : public cppu::WeakImplHelper<css::uno::XCurrentContext>
160{
162 sal_Int16 m_nPort;
164
165public:
166 SwConnectionContext(OUString aMailServer, sal_Int16 nPort, OUString aConnectionType);
167 virtual ~SwConnectionContext() override;
168
169 virtual css::uno::Any SAL_CALL getValueByName(const OUString& Name) override;
170};
171
173 public comphelper::WeakComponentImplHelper<css::mail::XConnectionListener>
174{
176
177public:
178 virtual ~SwConnectionListener() override;
179
180 virtual void SAL_CALL connected(const css::lang::EventObject& aEvent) override;
181
182 virtual void SAL_CALL disconnected(const css::lang::EventObject& aEvent) override;
183
184 virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) override;
185};
186
188 public comphelper::WeakComponentImplHelper<css::datatransfer::XTransferable, css::beans::XPropertySet>
189{
190 OUString m_aMimeType;
191 OUString m_sBody;
192 OUString m_aURL;
193 OUString m_aName;
195
196 public:
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;
201
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;
204
205 //XPropertySet
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;
208
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;
218
219};
220
222 public comphelper::WeakComponentImplHelper<css::mail::XMailMessage>
223{
227 OUString m_sSubject;
228
229 css::uno::Reference<css::datatransfer::XTransferable> m_xBody;
230// css::mail::MailMessageBody m_aBody;
231
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;
237public:
239 virtual ~SwMailMessage() override;
240
241 // attributes
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;
248
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;
251
252 // methods
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)
262 {
263 m_sSenderName = rSenderName;
264 }
265 void SetSenderAddress(const OUString& rSenderAddress)
266 {
267 m_sSenderAddress = rSenderAddress;
268 }
269};
270
271#endif
272
273/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
AnyEventRef aEvent
SwAddressIterator(OUString aAddress)
std::unique_ptr< SwAddressPreview_Impl > m_pImpl
Link< LinkParamNone *, void > m_aSelectHdl
std::unique_ptr< weld::ScrolledWindow > m_xVScrollBar
DECL_DLLPRIVATE_LINK(ScrollHdl, weld::ScrolledWindow &, void)
void SetSelectHdl(const Link< LinkParamNone *, void > &rLink)
SwAuthenticator(OUString username, OUString password, weld::Window *pParent)
weld::Window * m_pParentWindow
OUString m_sSenderAddress
OUString m_sSenderName
css::uno::Sequence< OUString > m_aRecipients
css::uno::Reference< css::datatransfer::XTransferable > m_xBody
css::uno::Sequence< OUString > m_aBccRecipients
void SetSenderName(const OUString &rSenderName)
void SetSenderAddress(const OUString &rSenderAddress)
css::uno::Sequence< css::mail::MailAttachment > m_aAttachments
css::uno::Sequence< OUString > m_aCcRecipients
OUString m_sReplyToAddress
virtual void disposing(std::unique_lock< std::mutex > &)
virtual bool KeyInput(const KeyEvent &)
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)=0
virtual bool MouseButtonDown(const MouseEvent &)
uno::Reference< mail::XSmtpService > ConnectToSmtpServer(SwMailMergeConfigItem const &rConfigItem, uno::Reference< mail::XMailService > &rxInMailService, const OUString &rInMailServerPassword, const OUString &rOutMailServerPassword, weld::Window *pDialogParentWindow)
OUString CallSaveAsDialog(weld::Window *pParent, OUString &rFilter)
bool CheckMailAddress(std::u16string_view aMailAddress)
VBAHELPER_DLLPUBLIC bool setPropertyValue(css::uno::Sequence< css::beans::PropertyValue > &aProp, const OUString &aName, const css::uno::Any &aValue)
bool getPassword(const css::uno::Reference< css::task::XInteractionHandler > &xHandler, OUString &rOutPwd, bool bFirstTry, const OUString &rDocName)
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
OUString m_aPassword
unsigned char sal_Bool