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>
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>
34 #include <swdllapi.h>
35 
37 
38 namespace com { namespace sun { namespace star { namespace mail {
39  class XMailService;
40  class XSmtpService;
41 } } } }
42 
43 namespace SwMailMergeHelper
44 {
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);
53 }
54 
56 
57 // Preview window used to show the possible selection of address blocks
58 // and also the resulting address filled with database data
60 {
61  std::unique_ptr<SwAddressPreview_Impl> pImpl;
62  std::unique_ptr<weld::ScrolledWindow> m_xVScrollBar;
64 
65  void DrawText_Impl(vcl::RenderContext& rRenderContext, const OUString& rAddress,
66  const Point& rTopLeft, const Size& rSize, bool bIsSelected);
67 
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();
72 
73  DECL_LINK(ScrollHdl, weld::ScrolledWindow&,void);
74 
75 public:
76  SwAddressPreview(std::unique_ptr<weld::ScrolledWindow> xParent);
77  virtual ~SwAddressPreview() override;
78 
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
90  void Clear();
91 
92  // returns the selected address
93  sal_uInt16 GetSelectedAddress() const;
94  void SelectAddress(sal_uInt16 nSelect);
95  void ReplaceSelectedAddress(const OUString&);
96  void RemoveSelectedAddress();
97 
98  // set the number of rows and columns of addresses
99  void SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns);
100  void EnableScrollBar();
101 
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);
105 
106  void SetSelectHdl (const Link<LinkParamNone*,void>& rLink) { m_aSelectHdl = rLink; }
107 };
108 
109 
110 // iterate over an address block or a greeting line the iterator returns the
111 // parts either as pure string or as column
113 {
114  OUString sText;
115  bool bIsColumn;
116  bool bIsReturn;
117 
119  : bIsColumn(false)
120  , bIsReturn(false)
121  {}
122 };
123 
125 {
126  OUString sAddress;
127 public:
128  SwAddressIterator(const OUString& rAddress) :
129  sAddress(rAddress)
130  {}
131 
133  bool HasMore() const { return !sAddress.isEmpty(); }
134 };
135 
137  public cppu::WeakImplHelper<css::mail::XAuthenticator>
138 {
139  OUString const m_aUserName;
140  OUString m_aPassword;
142 public:
144  : m_pParentWindow(nullptr)
145  {}
146  SwAuthenticator(const OUString& username, const OUString& password, weld::Window* pParent)
147  : m_aUserName(username)
148  , m_aPassword(password)
149  , m_pParentWindow(pParent)
150  {}
151  virtual ~SwAuthenticator() override;
152 
153  virtual OUString SAL_CALL getUserName() override;
154  virtual OUString SAL_CALL getPassword() override;
155 
156 };
157 
158 class SW_DLLPUBLIC SwConnectionContext : public cppu::WeakImplHelper<css::uno::XCurrentContext>
159 {
160  OUString const m_sMailServer;
161  sal_Int16 const m_nPort;
162  OUString const m_sConnectionType;
163 
164 public:
165  SwConnectionContext(const OUString& rMailServer, sal_Int16 nPort, const OUString& rConnectionType);
166  virtual ~SwConnectionContext() override;
167 
168  virtual css::uno::Any SAL_CALL getValueByName(const OUString& Name) override;
169 };
170 
172 {
173 public:
174  osl::Mutex m_aMutex;
175 };
176 
178  public SwMutexBase,
179  public cppu::WeakComponentImplHelper<css::mail::XConnectionListener>
180 {
181  using cppu::WeakComponentImplHelperBase::disposing;
182 
183 public:
185  cppu::WeakComponentImplHelper<css::mail::XConnectionListener>(m_aMutex)
186  {}
187  virtual ~SwConnectionListener() override;
188 
189  virtual void SAL_CALL connected(const css::lang::EventObject& aEvent) override;
190 
191  virtual void SAL_CALL disconnected(const css::lang::EventObject& aEvent) override;
192 
193  virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) override;
194 };
195 
197  public SwMutexBase,
198  public cppu::WeakComponentImplHelper<css::datatransfer::XTransferable, css::beans::XPropertySet>
199 {
200  OUString const m_aMimeType;
201  OUString const m_sBody;
202  OUString const m_aURL;
203  OUString const m_aName;
204  bool const m_bIsBody;
205 
206  public:
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;
211 
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;
214 
215  //XPropertySet
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;
218 
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;
228 
229 };
230 
232  public SwMutexBase,
233  public cppu::WeakComponentImplHelper<css::mail::XMailMessage>
234 {
235  OUString m_sSenderName;
238  OUString m_sSubject;
239 
240  css::uno::Reference<css::datatransfer::XTransferable> m_xBody;
241 // css::mail::MailMessageBody m_aBody;
242 
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;
248 public:
249  SwMailMessage();
250  virtual ~SwMailMessage() override;
251 
252  // attributes
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;
259 
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;
262 
263  // methods
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)
273  {
274  m_sSenderName = rSenderName;
275  }
276  void SetSenderAddress(const OUString& rSenderAddress)
277  {
278  m_sSenderAddress = rSenderAddress;
279  }
280 };
281 
282 #endif
283 
284 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
bool HasMore() const
OUString const m_sConnectionType
::osl::Mutex m_aMutex
std::unique_ptr< weld::ScrolledWindow > m_xVScrollBar
uno::Reference< mail::XSmtpService > ConnectToSmtpServer(SwMailMergeConfigItem const &rConfigItem, uno::Reference< mail::XMailService > &rxInMailService, const OUString &rInMailServerPassword, const OUString &rOutMailServerPassword, weld::Window *pDialogParentWindow)
css::uno::Sequence< OUString > m_aCcRecipients
OUString const m_aURL
css::uno::Reference< css::datatransfer::XTransferable > m_xBody
weld::Window * m_pParentWindow
void SetSelectHdl(const Link< LinkParamNone *, void > &rLink)
OUString const m_sBody
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
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
OUString const m_sMailServer
OUString m_sReplyToAddress
virtual bool MouseButtonDown(const MouseEvent &)
OUString const m_aMimeType
std::unique_ptr< SwAddressPreview_Impl > pImpl
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)