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 <unotools/configitem.hxx>
23 #include <com/sun/star/uno/Sequence.h>
24 #include <com/sun/star/mail/XAuthenticator.hpp>
25 #include <com/sun/star/mail/XConnectionListener.hpp>
26 #include <com/sun/star/uno/XCurrentContext.hpp>
27 #include <com/sun/star/mail/XMailMessage.hpp>
28 #include <com/sun/star/datatransfer/XTransferable.hpp>
29 #include <com/sun/star/beans/XPropertySet.hpp>
30 #include <cppuhelper/implbase.hxx>
31 #include <cppuhelper/compbase.hxx>
32 #include <vcl/scrbar.hxx>
33 #include <vcl/customweld.hxx>
34 #include <vcl/weld.hxx>
35 #include <rtl/ustring.hxx>
36 #include <swdllapi.h>
37 
39 
40 namespace com { namespace sun { namespace star { namespace mail {
41  class XMailService;
42  class XSmtpService;
43 } } } }
44 
45 namespace 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 {
66 
67  void DrawText_Impl(vcl::RenderContext& rRenderContext, const OUString& rAddress,
68  const Point& rTopLeft, const Size& rSize, bool bIsSelected);
69 
70  virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) override;
71  virtual void Resize() override;
72  virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
73  virtual void KeyInput( const KeyEvent& rKEvt ) override;
74  virtual void StateChanged( StateChangedType nStateChange ) override;
75  void UpdateScrollBar();
76 
77  DECL_LINK(ScrollHdl, ScrollBar*,void);
78 
79 public:
80  SwAddressPreview(vcl::Window* pParent, WinBits nStyle);
81  virtual ~SwAddressPreview() override;
82  virtual void dispose() override;
83 
84  void positionScrollBar();
85 
93  void AddAddress(const OUString& rAddress);
94  // for preview mode - replaces the currently used address by the given one
95  void SetAddress(const OUString& rAddress);
96  // removes all addresses
97  void Clear();
98 
99  // returns the selected address
100  sal_uInt16 GetSelectedAddress() const;
101  void SelectAddress(sal_uInt16 nSelect);
102 
103  // set the number of rows and columns of addresses
104  void SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns);
105 
106  // fill the actual data into a string (address block or greeting)
107  static OUString FillData(const OUString& rAddress, SwMailMergeConfigItem const & rConfigItem,
108  const css::uno::Sequence<OUString>* pAssignments = nullptr);
109 
110  void SetSelectHdl (const Link<LinkParamNone*,void>& rLink) { m_aSelectHdl = rLink; }
111 };
112 
114 {
115  std::unique_ptr<SwAddressPreview_Impl> pImpl;
116  std::unique_ptr<weld::ScrolledWindow> m_xVScrollBar;
117 
118  void DrawText_Impl(vcl::RenderContext& rRenderContext, const OUString& rAddress,
119  const Point& rTopLeft, const Size& rSize, bool bIsSelected);
120 
121  virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) override;
122  virtual bool MouseButtonDown( const MouseEvent& rMEvt ) override;
123  virtual bool KeyInput( const KeyEvent& rKEvt ) override;
124  void UpdateScrollBar();
125 
126  DECL_LINK(ScrollHdl, weld::ScrolledWindow&,void);
127 
128 public:
129  AddressPreview(std::unique_ptr<weld::ScrolledWindow> xParent);
130  virtual ~AddressPreview() override;
131 
139  void AddAddress(const OUString& rAddress);
140  // for preview mode - replaces the currently used address by the given one
141  void SetAddress(const OUString& rAddress);
142 
143  // returns the selected address
144  sal_uInt16 GetSelectedAddress() const;
145  void SelectAddress(sal_uInt16 nSelect);
146  void ReplaceSelectedAddress(const OUString&);
147  void RemoveSelectedAddress();
148 
149  // set the number of rows and columns of addresses
150  void SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns);
151  void EnableScrollBar();
152 };
153 
154 
155 // iterate over an address block or a greeting line the iterator returns the
156 // parts either as pure string or as column
158 {
159  OUString sText;
160  bool bIsColumn;
161  bool bIsReturn;
162 
164  : bIsColumn(false)
165  , bIsReturn(false)
166  {}
167 };
168 
170 {
171  OUString sAddress;
172 public:
173  SwAddressIterator(const OUString& rAddress) :
174  sAddress(rAddress)
175  {}
176 
178  bool HasMore() const { return !sAddress.isEmpty(); }
179 };
180 
182  public cppu::WeakImplHelper<css::mail::XAuthenticator>
183 {
184  OUString const m_aUserName;
185  OUString m_aPassword;
187 public:
189  : m_pParentWindow(nullptr)
190  {}
191  SwAuthenticator(const OUString& username, const OUString& password, weld::Window* pParent)
192  : m_aUserName(username)
193  , m_aPassword(password)
194  , m_pParentWindow(pParent)
195  {}
196  virtual ~SwAuthenticator() override;
197 
198  virtual OUString SAL_CALL getUserName() override;
199  virtual OUString SAL_CALL getPassword() override;
200 
201 };
202 
203 class SW_DLLPUBLIC SwConnectionContext : public cppu::WeakImplHelper<css::uno::XCurrentContext>
204 {
205  OUString const m_sMailServer;
206  sal_Int16 const m_nPort;
207  OUString const m_sConnectionType;
208 
209 public:
210  SwConnectionContext(const OUString& rMailServer, sal_Int16 nPort, const OUString& rConnectionType);
211  virtual ~SwConnectionContext() override;
212 
213  virtual css::uno::Any SAL_CALL getValueByName(const OUString& Name) override;
214 };
215 
217 {
218 public:
219  osl::Mutex m_aMutex;
220 };
221 
223  public SwMutexBase,
224  public cppu::WeakComponentImplHelper<css::mail::XConnectionListener>
225 {
226  using cppu::WeakComponentImplHelperBase::disposing;
227 
228 public:
230  cppu::WeakComponentImplHelper<css::mail::XConnectionListener>(m_aMutex)
231  {}
232  virtual ~SwConnectionListener() override;
233 
234  virtual void SAL_CALL connected(const css::lang::EventObject& aEvent) override;
235 
236  virtual void SAL_CALL disconnected(const css::lang::EventObject& aEvent) override;
237 
238  virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) override;
239 };
240 
242  public SwMutexBase,
243  public cppu::WeakComponentImplHelper<css::datatransfer::XTransferable, css::beans::XPropertySet>
244 {
245  OUString const m_aMimeType;
246  OUString const m_sBody;
247  OUString const m_aURL;
248  OUString const m_aName;
249  bool const m_bIsBody;
250 
251  public:
252  SwMailTransferable(const OUString& rURL, const OUString& rName, const OUString& rMimeType);
253  SwMailTransferable(const OUString& rBody, const OUString& rMimeType);
254  virtual ~SwMailTransferable() override;
255  virtual css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor& aFlavor) override;
256 
257  virtual css::uno::Sequence<css::datatransfer::DataFlavor> SAL_CALL getTransferDataFlavors() override;
258  virtual sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor& aFlavor) override;
259 
260  //XPropertySet
261  virtual css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() override;
262  virtual void SAL_CALL setPropertyValue(const OUString& aPropertyName, const css::uno::Any& aValue) override;
263 
264  virtual css::uno::Any SAL_CALL getPropertyValue(const OUString& PropertyName) override;
265  virtual void SAL_CALL addPropertyChangeListener(const OUString& aPropertyName,
266  const css::uno::Reference<css::beans::XPropertyChangeListener>& xListener) override;
267  virtual void SAL_CALL removePropertyChangeListener(const OUString& aPropertyName,
268  const css::uno::Reference<css::beans::XPropertyChangeListener >& aListener) override;
269  virtual void SAL_CALL addVetoableChangeListener(const OUString& PropertyName,
270  const css::uno::Reference<css::beans::XVetoableChangeListener>& aListener) override;
271  virtual void SAL_CALL removeVetoableChangeListener(const OUString& PropertyName,
272  const css::uno::Reference<css::beans::XVetoableChangeListener>& aListener) override;
273 
274 };
275 
277  public SwMutexBase,
278  public cppu::WeakComponentImplHelper<css::mail::XMailMessage>
279 {
280  OUString m_sSenderName;
283  OUString m_sSubject;
284 
285  css::uno::Reference<css::datatransfer::XTransferable> m_xBody;
286 // css::mail::MailMessageBody m_aBody;
287 
288  css::uno::Sequence<OUString> m_aRecipients;
289  css::uno::Sequence<OUString> m_aCcRecipients;
290  css::uno::Sequence<OUString> m_aBccRecipients;
291 // css::uno::Sequence<css::mail::MailAttachmentDescriptor> m_aAttachments;
292  css::uno::Sequence<css::mail::MailAttachment> m_aAttachments;
293 public:
294  SwMailMessage();
295  virtual ~SwMailMessage() override;
296 
297  // attributes
298  virtual OUString SAL_CALL getSenderName() override;
299  virtual OUString SAL_CALL getSenderAddress() override;
300  virtual OUString SAL_CALL getReplyToAddress() override;
301  virtual void SAL_CALL setReplyToAddress( const OUString& _replytoaddress ) override;
302  virtual OUString SAL_CALL getSubject() override;
303  virtual void SAL_CALL setSubject(const OUString& _subject) override;
304 
305  virtual css::uno::Reference<css::datatransfer::XTransferable> SAL_CALL getBody() override;
306  virtual void SAL_CALL setBody(const css::uno::Reference<css::datatransfer::XTransferable>& _body) override;
307 
308  // methods
309  virtual void SAL_CALL addRecipient( const OUString& sRecipientAddress ) override;
310  virtual void SAL_CALL addCcRecipient( const OUString& sRecipientAddress ) override;
311  virtual void SAL_CALL addBccRecipient( const OUString& sRecipientAddress ) override;
312  virtual css::uno::Sequence<OUString> SAL_CALL getRecipients() override;
313  virtual css::uno::Sequence<OUString> SAL_CALL getCcRecipients() override;
314  virtual css::uno::Sequence<OUString> SAL_CALL getBccRecipients() override;
315  virtual void SAL_CALL addAttachment(const css::mail::MailAttachment& aMailAttachment) override;
316  virtual css::uno::Sequence<css::mail::MailAttachment> SAL_CALL getAttachments() override;
317  void SetSenderName(const OUString& rSenderName)
318  {
319  m_sSenderName = rSenderName;
320  }
321  void SetSenderAddress(const OUString& rSenderAddress)
322  {
323  m_sSenderAddress = rSenderAddress;
324  }
325 };
326 
327 #endif
328 
329 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool HasMore() const
OUString const m_sConnectionType
::osl::Mutex m_aMutex
uno::Reference< mail::XSmtpService > ConnectToSmtpServer(SwMailMergeConfigItem const &rConfigItem, uno::Reference< mail::XMailService > &rxInMailService, const OUString &rInMailServerPassword, const OUString &rOutMailServerPassword, weld::Window *pDialogParentWindow)
virtual void MouseButtonDown(const MouseEvent &rMEvt)
css::uno::Sequence< OUString > m_aCcRecipients
SwAddressPreview_Impl * pImpl
VclPtr< ScrollBar > aVScrollBar
OUString const m_aURL
css::uno::Reference< css::datatransfer::XTransferable > m_xBody
weld::Window * m_pParentWindow
virtual void dispose() override
void SetSelectHdl(const Link< LinkParamNone *, void > &rLink)
OUString const m_sBody
StateChangedType
sal_Int64 WinBits
Link< LinkParamNone *, void > m_aSelectHdl
css::uno::Sequence< OUString > m_aBccRecipients
bool getPropertyValue(ValueType &rValue, css::uno::Reference< css::beans::XPropertySet > const &xPropSet, OUString const &propName)
sal_Int16 const m_nPort
void SetSenderName(const OUString &rSenderName)
OUString const m_aName
osl::Mutex m_aMutex
css::uno::Sequence< css::mail::MailAttachment > m_aAttachments
css::uno::Sequence< OUString > m_aRecipients
OUString CallSaveAsDialog(weld::Window *pParent, OUString &rFilter)
OUString m_sSenderAddress
unsigned char sal_Bool
std::unique_ptr< SwAddressPreview_Impl > pImpl
virtual void Resize()
virtual bool KeyInput(const KeyEvent &)
bool getPassword(const css::uno::Reference< css::task::XInteractionHandler > &xHandler, OUString &rOutPwd, bool bFirstTry, const OUString &rDocName)
SwAddressIterator(const OUString &rAddress)
#define SW_DLLPUBLIC
Definition: swdllapi.h:28
bool setPropertyValue(uno::Sequence< beans::PropertyValue > &aProp, const OUString &aName, const uno::Any &aValue)
OUString m_sSenderName
virtual void KeyInput(const KeyEvent &rKEvt)
OUString const m_sMailServer
OUString m_sReplyToAddress
virtual bool MouseButtonDown(const MouseEvent &)
OUString const m_aMimeType
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)
virtual void StateChanged(StateChangedType nStateChange)
std::unique_ptr< weld::ScrolledWindow > m_xVScrollBar
bool CheckMailAddress(const OUString &rMailAddress)
OUString const m_aUserName
SwAuthenticator(const OUString &username, const OUString &password, weld::Window *pParent)
virtual void Paint(vcl::RenderContext &rRenderContext, const tools::Rectangle &rRect)=0
void SetSenderAddress(const OUString &rSenderAddress)