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>
32#include <utility>
33#include <vcl/customweld.hxx>
34#include <vcl/weld.hxx>
35#include <rtl/ustring.hxx>
36#include <swdllapi.h>
37
39
40namespace com::sun::star::mail {
41 class XMailService;
42 class XSmtpService;
43}
44
45namespace SwMailMergeHelper
46{
47 SW_DLLPUBLIC OUString CallSaveAsDialog(weld::Window* pParent, OUString& rFilter);
48 SW_DLLPUBLIC bool CheckMailAddress(const OUString& rMailAddress);
49 SW_DLLPUBLIC css::uno::Reference<css::mail::XSmtpService> ConnectToSmtpServer(
50 SwMailMergeConfigItem const & rConfigItem,
51 css::uno::Reference<css::mail::XMailService>& xInMailService,
52 const OUString& rInMailServerPassword,
53 const OUString& rOutMailServerPassword,
54 weld::Window* pDialogParentWindow = nullptr);
55}
56
58
59// Preview window used to show the possible selection of address blocks
60// and also the resulting address filled with database data
62{
63 std::unique_ptr<SwAddressPreview_Impl> m_pImpl;
64 std::unique_ptr<weld::ScrolledWindow> m_xVScrollBar;
66
67 void DrawText_Impl(vcl::RenderContext& rRenderContext, std::u16string_view rAddress,
68 const Point& rTopLeft, const Size& rSize, bool bIsSelected);
69
70 virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) override;
71 virtual bool MouseButtonDown( const MouseEvent& rMEvt ) override;
72 virtual bool KeyInput( const KeyEvent& rKEvt ) override;
73 void UpdateScrollBar();
74
76
77public:
78 SwAddressPreview(std::unique_ptr<weld::ScrolledWindow> xParent);
79 virtual ~SwAddressPreview() override;
80
88 void AddAddress(const OUString& rAddress);
89 // for preview mode - replaces the currently used address by the given one
90 void SetAddress(const OUString& rAddress);
91 // removes all addresses
92 void Clear();
93
94 // returns the selected address
95 sal_uInt16 GetSelectedAddress() const;
96 void SelectAddress(sal_uInt16 nSelect);
97 void ReplaceSelectedAddress(const OUString&);
98 void RemoveSelectedAddress();
99
100 // set the number of rows and columns of addresses
101 void SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns);
102 void EnableScrollBar();
103
104 // fill the actual data into a string (address block or greeting)
105 static OUString FillData(const OUString& rAddress, SwMailMergeConfigItem const & rConfigItem,
106 const css::uno::Sequence<OUString>* pAssignments = nullptr);
107
108 void SetSelectHdl (const Link<LinkParamNone*,void>& rLink) { m_aSelectHdl = rLink; }
109};
110
111
112// iterate over an address block or a greeting line the iterator returns the
113// parts either as pure string or as column
115{
116 OUString sText;
119
121 : bIsColumn(false)
122 , bIsReturn(false)
123 {}
124};
125
127{
128 OUString m_sAddress;
129public:
130 SwAddressIterator(OUString aAddress) :
131 m_sAddress(std::move(aAddress))
132 {}
133
135 bool HasMore() const { return !m_sAddress.isEmpty(); }
136};
137
139 public cppu::WeakImplHelper<css::mail::XAuthenticator>
140{
141 OUString m_aUserName;
142 OUString m_aPassword;
144public:
146 : m_pParentWindow(nullptr)
147 {}
148 SwAuthenticator(OUString username, OUString password, weld::Window* pParent)
149 : m_aUserName(std::move(username))
150 , m_aPassword(std::move(password))
151 , m_pParentWindow(pParent)
152 {}
153 virtual ~SwAuthenticator() override;
154
155 virtual OUString SAL_CALL getUserName() override;
156 virtual OUString SAL_CALL getPassword() override;
157
158};
159
160class SW_DLLPUBLIC SwConnectionContext final : public cppu::WeakImplHelper<css::uno::XCurrentContext>
161{
163 sal_Int16 m_nPort;
165
166public:
167 SwConnectionContext(OUString aMailServer, sal_Int16 nPort, OUString aConnectionType);
168 virtual ~SwConnectionContext() override;
169
170 virtual css::uno::Any SAL_CALL getValueByName(const OUString& Name) override;
171};
172
174 public cppu::BaseMutex,
175 public cppu::WeakComponentImplHelper<css::mail::XConnectionListener>
176{
177 using cppu::WeakComponentImplHelperBase::disposing;
178
179public:
181 cppu::WeakComponentImplHelper<css::mail::XConnectionListener>(m_aMutex)
182 {}
183 virtual ~SwConnectionListener() override;
184
185 virtual void SAL_CALL connected(const css::lang::EventObject& aEvent) override;
186
187 virtual void SAL_CALL disconnected(const css::lang::EventObject& aEvent) override;
188
189 virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) override;
190};
191
193 public cppu::BaseMutex,
194 public cppu::WeakComponentImplHelper<css::datatransfer::XTransferable, css::beans::XPropertySet>
195{
196 OUString m_aMimeType;
197 OUString m_sBody;
198 OUString m_aURL;
199 OUString m_aName;
201
202 public:
203 SwMailTransferable(OUString aURL, OUString aName, OUString aMimeType);
204 SwMailTransferable(OUString aBody, OUString aMimeType);
205 virtual ~SwMailTransferable() override;
206 virtual css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor& aFlavor) override;
207
208 virtual css::uno::Sequence<css::datatransfer::DataFlavor> SAL_CALL getTransferDataFlavors() override;
209 virtual sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor& aFlavor) override;
210
211 //XPropertySet
212 virtual css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() override;
213 virtual void SAL_CALL setPropertyValue(const OUString& aPropertyName, const css::uno::Any& aValue) override;
214
215 virtual css::uno::Any SAL_CALL getPropertyValue(const OUString& PropertyName) override;
216 virtual void SAL_CALL addPropertyChangeListener(const OUString& aPropertyName,
217 const css::uno::Reference<css::beans::XPropertyChangeListener>& xListener) override;
218 virtual void SAL_CALL removePropertyChangeListener(const OUString& aPropertyName,
219 const css::uno::Reference<css::beans::XPropertyChangeListener >& aListener) override;
220 virtual void SAL_CALL addVetoableChangeListener(const OUString& PropertyName,
221 const css::uno::Reference<css::beans::XVetoableChangeListener>& aListener) override;
222 virtual void SAL_CALL removeVetoableChangeListener(const OUString& PropertyName,
223 const css::uno::Reference<css::beans::XVetoableChangeListener>& aListener) override;
224
225};
226
228 public cppu::BaseMutex,
229 public cppu::WeakComponentImplHelper<css::mail::XMailMessage>
230{
234 OUString m_sSubject;
235
236 css::uno::Reference<css::datatransfer::XTransferable> m_xBody;
237// css::mail::MailMessageBody m_aBody;
238
239 css::uno::Sequence<OUString> m_aRecipients;
240 css::uno::Sequence<OUString> m_aCcRecipients;
241 css::uno::Sequence<OUString> m_aBccRecipients;
242// css::uno::Sequence<css::mail::MailAttachmentDescriptor> m_aAttachments;
243 css::uno::Sequence<css::mail::MailAttachment> m_aAttachments;
244public:
246 virtual ~SwMailMessage() override;
247
248 // attributes
249 virtual OUString SAL_CALL getSenderName() override;
250 virtual OUString SAL_CALL getSenderAddress() override;
251 virtual OUString SAL_CALL getReplyToAddress() override;
252 virtual void SAL_CALL setReplyToAddress( const OUString& _replytoaddress ) override;
253 virtual OUString SAL_CALL getSubject() override;
254 virtual void SAL_CALL setSubject(const OUString& _subject) override;
255
256 virtual css::uno::Reference<css::datatransfer::XTransferable> SAL_CALL getBody() override;
257 virtual void SAL_CALL setBody(const css::uno::Reference<css::datatransfer::XTransferable>& _body) override;
258
259 // methods
260 virtual void SAL_CALL addRecipient( const OUString& sRecipientAddress ) override;
261 virtual void SAL_CALL addCcRecipient( const OUString& sRecipientAddress ) override;
262 virtual void SAL_CALL addBccRecipient( const OUString& sRecipientAddress ) override;
263 virtual css::uno::Sequence<OUString> SAL_CALL getRecipients() override;
264 virtual css::uno::Sequence<OUString> SAL_CALL getCcRecipients() override;
265 virtual css::uno::Sequence<OUString> SAL_CALL getBccRecipients() override;
266 virtual void SAL_CALL addAttachment(const css::mail::MailAttachment& aMailAttachment) override;
267 virtual css::uno::Sequence<css::mail::MailAttachment> SAL_CALL getAttachments() override;
268 void SetSenderName(const OUString& rSenderName)
269 {
270 m_sSenderName = rSenderName;
271 }
272 void SetSenderAddress(const OUString& rSenderAddress)
273 {
274 m_sSenderAddress = rSenderAddress;
275 }
276};
277
278#endif
279
280/* vim:set shiftwidth=4 softtabstop=4 expandtab: */
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 bool KeyInput(const KeyEvent &)
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)=0
virtual bool MouseButtonDown(const MouseEvent &)
std::mutex m_aMutex
bool CheckMailAddress(const OUString &rMailAddress)
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)
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