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/scrbar.hxx>
32 #include <vcl/customweld.hxx>
33 #include <vcl/weld.hxx>
34 #include <rtl/ustring.hxx>
35 #include <swdllapi.h>
36 
38 
39 namespace com { namespace sun { namespace star { namespace mail {
40  class XMailService;
41  class XSmtpService;
42 } } } }
43 
44 namespace SwMailMergeHelper
45 {
46  SW_DLLPUBLIC OUString CallSaveAsDialog(weld::Window* pParent, OUString& rFilter);
47  SW_DLLPUBLIC bool CheckMailAddress(const OUString& rMailAddress);
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> pImpl;
63  std::unique_ptr<weld::ScrolledWindow> m_xVScrollBar;
65 
66  void DrawText_Impl(vcl::RenderContext& rRenderContext, const OUString& 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 
74  DECL_LINK(ScrollHdl, weld::ScrolledWindow&,void);
75 
76 public:
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;
116  bool bIsColumn;
117  bool bIsReturn;
118 
120  : bIsColumn(false)
121  , bIsReturn(false)
122  {}
123 };
124 
126 {
127  OUString sAddress;
128 public:
129  SwAddressIterator(const OUString& rAddress) :
130  sAddress(rAddress)
131  {}
132 
134  bool HasMore() const { return !sAddress.isEmpty(); }
135 };
136 
138  public cppu::WeakImplHelper<css::mail::XAuthenticator>
139 {
140  OUString const m_aUserName;
141  OUString m_aPassword;
143 public:
145  : m_pParentWindow(nullptr)
146  {}
147  SwAuthenticator(const OUString& username, const OUString& password, weld::Window* pParent)
148  : m_aUserName(username)
149  , m_aPassword(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 
159 class SW_DLLPUBLIC SwConnectionContext : public cppu::WeakImplHelper<css::uno::XCurrentContext>
160 {
161  OUString const m_sMailServer;
162  sal_Int16 const m_nPort;
163  OUString const m_sConnectionType;
164 
165 public:
166  SwConnectionContext(const OUString& rMailServer, sal_Int16 nPort, const OUString& rConnectionType);
167  virtual ~SwConnectionContext() override;
168 
169  virtual css::uno::Any SAL_CALL getValueByName(const OUString& Name) override;
170 };
171 
173 {
174 public:
175  osl::Mutex m_aMutex;
176 };
177 
179  public SwMutexBase,
180  public cppu::WeakComponentImplHelper<css::mail::XConnectionListener>
181 {
182  using cppu::WeakComponentImplHelperBase::disposing;
183 
184 public:
186  cppu::WeakComponentImplHelper<css::mail::XConnectionListener>(m_aMutex)
187  {}
188  virtual ~SwConnectionListener() override;
189 
190  virtual void SAL_CALL connected(const css::lang::EventObject& aEvent) override;
191 
192  virtual void SAL_CALL disconnected(const css::lang::EventObject& aEvent) override;
193 
194  virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) override;
195 };
196 
198  public SwMutexBase,
199  public cppu::WeakComponentImplHelper<css::datatransfer::XTransferable, css::beans::XPropertySet>
200 {
201  OUString const m_aMimeType;
202  OUString const m_sBody;
203  OUString const m_aURL;
204  OUString const m_aName;
205  bool const m_bIsBody;
206 
207  public:
208  SwMailTransferable(const OUString& rURL, const OUString& rName, const OUString& rMimeType);
209  SwMailTransferable(const OUString& rBody, const OUString& rMimeType);
210  virtual ~SwMailTransferable() override;
211  virtual css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor& aFlavor) override;
212 
213  virtual css::uno::Sequence<css::datatransfer::DataFlavor> SAL_CALL getTransferDataFlavors() override;
214  virtual sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor& aFlavor) override;
215 
216  //XPropertySet
217  virtual css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() override;
218  virtual void SAL_CALL setPropertyValue(const OUString& aPropertyName, const css::uno::Any& aValue) override;
219 
220  virtual css::uno::Any SAL_CALL getPropertyValue(const OUString& PropertyName) override;
221  virtual void SAL_CALL addPropertyChangeListener(const OUString& aPropertyName,
222  const css::uno::Reference<css::beans::XPropertyChangeListener>& xListener) override;
223  virtual void SAL_CALL removePropertyChangeListener(const OUString& aPropertyName,
224  const css::uno::Reference<css::beans::XPropertyChangeListener >& aListener) override;
225  virtual void SAL_CALL addVetoableChangeListener(const OUString& PropertyName,
226  const css::uno::Reference<css::beans::XVetoableChangeListener>& aListener) override;
227  virtual void SAL_CALL removeVetoableChangeListener(const OUString& PropertyName,
228  const css::uno::Reference<css::beans::XVetoableChangeListener>& aListener) override;
229 
230 };
231 
233  public SwMutexBase,
234  public cppu::WeakComponentImplHelper<css::mail::XMailMessage>
235 {
236  OUString m_sSenderName;
239  OUString m_sSubject;
240 
241  css::uno::Reference<css::datatransfer::XTransferable> m_xBody;
242 // css::mail::MailMessageBody m_aBody;
243 
244  css::uno::Sequence<OUString> m_aRecipients;
245  css::uno::Sequence<OUString> m_aCcRecipients;
246  css::uno::Sequence<OUString> m_aBccRecipients;
247 // css::uno::Sequence<css::mail::MailAttachmentDescriptor> m_aAttachments;
248  css::uno::Sequence<css::mail::MailAttachment> m_aAttachments;
249 public:
250  SwMailMessage();
251  virtual ~SwMailMessage() override;
252 
253  // attributes
254  virtual OUString SAL_CALL getSenderName() override;
255  virtual OUString SAL_CALL getSenderAddress() override;
256  virtual OUString SAL_CALL getReplyToAddress() override;
257  virtual void SAL_CALL setReplyToAddress( const OUString& _replytoaddress ) override;
258  virtual OUString SAL_CALL getSubject() override;
259  virtual void SAL_CALL setSubject(const OUString& _subject) override;
260 
261  virtual css::uno::Reference<css::datatransfer::XTransferable> SAL_CALL getBody() override;
262  virtual void SAL_CALL setBody(const css::uno::Reference<css::datatransfer::XTransferable>& _body) override;
263 
264  // methods
265  virtual void SAL_CALL addRecipient( const OUString& sRecipientAddress ) override;
266  virtual void SAL_CALL addCcRecipient( const OUString& sRecipientAddress ) override;
267  virtual void SAL_CALL addBccRecipient( const OUString& sRecipientAddress ) override;
268  virtual css::uno::Sequence<OUString> SAL_CALL getRecipients() override;
269  virtual css::uno::Sequence<OUString> SAL_CALL getCcRecipients() override;
270  virtual css::uno::Sequence<OUString> SAL_CALL getBccRecipients() override;
271  virtual void SAL_CALL addAttachment(const css::mail::MailAttachment& aMailAttachment) override;
272  virtual css::uno::Sequence<css::mail::MailAttachment> SAL_CALL getAttachments() override;
273  void SetSenderName(const OUString& rSenderName)
274  {
275  m_sSenderName = rSenderName;
276  }
277  void SetSenderAddress(const OUString& rSenderAddress)
278  {
279  m_sSenderAddress = rSenderAddress;
280  }
281 };
282 
283 #endif
284 
285 /* 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)