Line data Source code
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 <svtools/stdctrl.hxx>
23 : #include <unotools/configitem.hxx>
24 : #include <com/sun/star/uno/Sequence.h>
25 : #include <com/sun/star/mail/XAuthenticator.hpp>
26 : #include <com/sun/star/mail/XConnectionListener.hpp>
27 : #include <com/sun/star/uno/XCurrentContext.hpp>
28 : #include <com/sun/star/mail/XMailMessage.hpp>
29 : #include <com/sun/star/datatransfer/XTransferable.hpp>
30 : #include <com/sun/star/beans/XPropertySet.hpp>
31 : #include <cppuhelper/implbase1.hxx>
32 : #include <cppuhelper/compbase1.hxx>
33 : #include <cppuhelper/compbase2.hxx>
34 : #include <vcl/scrbar.hxx>
35 : #include <rtl/ustring.hxx>
36 : #include "swdllapi.h"
37 :
38 : class SwMailMergeConfigItem;
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(OUString& rFilter);
48 : SW_DLLPUBLIC bool CheckMailAddress( const OUString& rMailAddress );
49 : SW_DLLPUBLIC com::sun::star::uno::Reference< com::sun::star::mail::XSmtpService >
50 : ConnectToSmtpServer( SwMailMergeConfigItem& rConfigItem,
51 : com::sun::star::uno::Reference< com::sun::star::mail::XMailService >& xInMailService,
52 : const OUString& rInMailServerPassword,
53 : const OUString& rOutMailServerPassword,
54 : vcl::Window* pDialogParentWindow = 0 );
55 : }
56 :
57 : struct SwAddressPreview_Impl;
58 :
59 : // Preview window used to show the possible selection of address blocks
60 : // and also the resulting address filled with database data
61 0 : class SW_DLLPUBLIC SwAddressPreview : public vcl::Window
62 : {
63 : ScrollBar aVScrollBar;
64 : SwAddressPreview_Impl* pImpl;
65 : Link m_aSelectHdl;
66 :
67 : void DrawText_Impl( const OUString& rAddress, const Point& rTopLeft, const Size& rSize, bool bIsSelected);
68 :
69 : virtual void Paint(const Rectangle&) SAL_OVERRIDE;
70 : virtual void Resize() SAL_OVERRIDE;
71 : virtual void MouseButtonDown( const MouseEvent& rMEvt ) SAL_OVERRIDE;
72 : virtual void KeyInput( const KeyEvent& rKEvt ) SAL_OVERRIDE;
73 : virtual void StateChanged( StateChangedType nStateChange ) SAL_OVERRIDE;
74 : void UpdateScrollBar();
75 :
76 : DECL_LINK(ScrollHdl, void*);
77 :
78 : public:
79 : SwAddressPreview(vcl::Window* pParent, WinBits nStyle=WB_BORDER);
80 :
81 : void positionScrollBar();
82 :
83 : /** The address string is a list of address elements separated by spaces
84 : and breaks. The addresses fit into the given layout. If more addresses then
85 : rows/columns should be used a scrollbar will be added.
86 :
87 : AddAddress appends the new address to the already added ones.
88 : Initially the first added address will be selected
89 : */
90 : void AddAddress(const OUString& rAddress);
91 : // for preview mode - replaces the currently used address by the given one
92 : void SetAddress(const OUString& rAddress);
93 : // removes all addresses
94 : void Clear();
95 :
96 : // returns the selected address
97 : sal_uInt16 GetSelectedAddress() const;
98 : void SelectAddress(sal_uInt16 nSelect);
99 : void ReplaceSelectedAddress(const OUString&);
100 : void RemoveSelectedAddress();
101 :
102 : // set the number of rows and columns of addresses
103 : void SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns);
104 : void EnableScrollBar(bool bEnable = true);
105 :
106 : // fill the actual data into a string (address block or greeting)
107 : static OUString FillData(
108 : const OUString& rAddress,
109 : SwMailMergeConfigItem& rConfigItem,
110 : const ::com::sun::star::uno::Sequence< OUString>* pAssignments = 0);
111 :
112 0 : void SetSelectHdl (const Link& rLink) {m_aSelectHdl = rLink;}
113 : };
114 :
115 : // iterate over an address block or a greeting line the iterator returns the
116 : // parts either as pure string or as column
117 232 : struct SwMergeAddressItem
118 : {
119 : OUString sText;
120 : bool bIsColumn;
121 : bool bIsReturn;
122 232 : SwMergeAddressItem() :
123 : bIsColumn(false),
124 232 : bIsReturn(false) {}
125 : };
126 :
127 40 : class SW_DLLPUBLIC SwAddressIterator
128 : {
129 : OUString sAddress;
130 : public:
131 40 : SwAddressIterator(const OUString& rAddress) :
132 40 : sAddress(rAddress){}
133 :
134 : SwMergeAddressItem Next();
135 272 : bool HasMore() const{return !sAddress.isEmpty();}
136 : };
137 :
138 : class SW_DLLPUBLIC SwAuthenticator :
139 : public cppu::WeakImplHelper1< ::com::sun::star::mail::XAuthenticator>
140 : {
141 : OUString m_aUserName;
142 : OUString m_aPassword;
143 : vcl::Window* m_pParentWindow;
144 : public:
145 0 : SwAuthenticator() : m_pParentWindow(0) {}
146 0 : SwAuthenticator(const OUString& username, const OUString& password, vcl::Window* pParent) :
147 : m_aUserName(username),
148 : m_aPassword(password),
149 0 : m_pParentWindow( pParent )
150 0 : {}
151 : virtual ~SwAuthenticator();
152 :
153 : virtual OUString SAL_CALL getUserName( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
154 : virtual OUString SAL_CALL getPassword( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
155 :
156 : };
157 :
158 : class SW_DLLPUBLIC SwConnectionContext :
159 : public cppu::WeakImplHelper1< ::com::sun::star::uno::XCurrentContext >
160 : {
161 : OUString m_sMailServer;
162 : sal_Int16 m_nPort;
163 : OUString m_sConnectionType;
164 :
165 : public:
166 : SwConnectionContext(const OUString& rMailServer, sal_Int16 nPort, const OUString& rConnectionType);
167 : virtual ~SwConnectionContext();
168 :
169 : virtual ::com::sun::star::uno::Any SAL_CALL getValueByName( const OUString& Name )
170 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
171 : };
172 :
173 0 : class SwMutexBase
174 : {
175 : public:
176 : osl::Mutex m_aMutex;
177 : };
178 :
179 : class SW_DLLPUBLIC SwConnectionListener :
180 : public SwMutexBase,
181 : public cppu::WeakComponentImplHelper1< ::com::sun::star::mail::XConnectionListener >
182 : {
183 : using cppu::WeakComponentImplHelperBase::disposing;
184 :
185 : public:
186 0 : SwConnectionListener() :
187 0 : cppu::WeakComponentImplHelper1< ::com::sun::star::mail::XConnectionListener>(m_aMutex)
188 0 : {}
189 : virtual ~SwConnectionListener();
190 :
191 : virtual void SAL_CALL connected(const ::com::sun::star::lang::EventObject& aEvent)
192 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
193 :
194 : virtual void SAL_CALL disconnected(const ::com::sun::star::lang::EventObject& aEvent)
195 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
196 :
197 : virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& aEvent)
198 : throw(com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
199 : };
200 :
201 : class SW_DLLPUBLIC SwMailTransferable :
202 : public SwMutexBase,
203 : public cppu::WeakComponentImplHelper2
204 : <
205 : ::com::sun::star::datatransfer::XTransferable,
206 : ::com::sun::star::beans::XPropertySet
207 : >
208 : {
209 : OUString m_aMimeType;
210 : OUString m_sBody;
211 : OUString m_aURL;
212 : OUString m_aName;
213 : bool m_bIsBody;
214 :
215 : public:
216 : SwMailTransferable(const OUString& rURL, const OUString& rName, const OUString& rMimeType);
217 : SwMailTransferable(const OUString& rBody, const OUString& rMimeType);
218 : virtual ~SwMailTransferable();
219 : virtual ::com::sun::star::uno::Any SAL_CALL
220 : getTransferData( const ::com::sun::star::datatransfer::DataFlavor& aFlavor )
221 : throw (::com::sun::star::datatransfer::UnsupportedFlavorException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
222 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::datatransfer::DataFlavor > SAL_CALL
223 : getTransferDataFlavors( )
224 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE ;
225 : virtual sal_Bool SAL_CALL
226 : isDataFlavorSupported( const ::com::sun::star::datatransfer::DataFlavor& aFlavor )
227 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
228 :
229 : //XPropertySet
230 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo( ) throw(::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
231 : virtual void SAL_CALL setPropertyValue( const OUString& aPropertyName, const ::com::sun::star::uno::Any& aValue ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::beans::PropertyVetoException, ::com::sun::star::lang::IllegalArgumentException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
232 : virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
233 : virtual void SAL_CALL addPropertyChangeListener( const OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& xListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
234 : virtual void SAL_CALL removePropertyChangeListener( const OUString& aPropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertyChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
235 : virtual void SAL_CALL addVetoableChangeListener( const OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
236 : virtual void SAL_CALL removeVetoableChangeListener( const OUString& PropertyName, const ::com::sun::star::uno::Reference< ::com::sun::star::beans::XVetoableChangeListener >& aListener ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
237 :
238 : };
239 :
240 : class SW_DLLPUBLIC SwMailMessage :
241 : public SwMutexBase,
242 : public cppu::WeakComponentImplHelper1< ::com::sun::star::mail::XMailMessage >
243 : {
244 : OUString m_sSenderName;
245 : OUString m_sSenderAddress;
246 : OUString m_sReplyToAddress;
247 : OUString m_sSubject;
248 :
249 : ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable> m_xBody;
250 : // ::com::sun::star::mail::MailMessageBody m_aBody;
251 :
252 : ::com::sun::star::uno::Sequence< OUString > m_aRecipients;
253 : ::com::sun::star::uno::Sequence< OUString > m_aCcRecipients;
254 : ::com::sun::star::uno::Sequence< OUString > m_aBccRecipients;
255 : // ::com::sun::star::uno::Sequence< ::com::sun::star::mail::MailAttachmentDescriptor > m_aAttachments;
256 : ::com::sun::star::uno::Sequence< ::com::sun::star::mail::MailAttachment > m_aAttachments;
257 : public:
258 : SwMailMessage();
259 : virtual ~SwMailMessage();
260 :
261 : // attributes
262 : virtual OUString SAL_CALL getSenderName() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
263 : virtual OUString SAL_CALL getSenderAddress() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
264 : virtual OUString SAL_CALL getReplyToAddress() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
265 : virtual void SAL_CALL setReplyToAddress( const OUString& _replytoaddress ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
266 : virtual OUString SAL_CALL getSubject() throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
267 : virtual void SAL_CALL setSubject( const OUString& _subject ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
268 :
269 : virtual ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > SAL_CALL
270 : getBody()
271 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
272 : virtual void SAL_CALL setBody( const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >& _body )
273 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
274 :
275 : // methods
276 : virtual void SAL_CALL addRecipient( const OUString& sRecipientAddress ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
277 : virtual void SAL_CALL addCcRecipient( const OUString& sRecipientAddress ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
278 : virtual void SAL_CALL addBccRecipient( const OUString& sRecipientAddress ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
279 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL
280 : getRecipients( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
281 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL
282 : getCcRecipients( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
283 : virtual ::com::sun::star::uno::Sequence< OUString > SAL_CALL
284 : getBccRecipients( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
285 : virtual void SAL_CALL addAttachment( const ::com::sun::star::mail::MailAttachment& aMailAttachment )
286 : throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
287 : virtual ::com::sun::star::uno::Sequence< ::com::sun::star::mail::MailAttachment > SAL_CALL
288 : getAttachments( ) throw (::com::sun::star::uno::RuntimeException, std::exception) SAL_OVERRIDE;
289 0 : void SetSenderName(const OUString& rSenderName)
290 0 : {m_sSenderName = rSenderName;}
291 0 : void SetSenderAddress(const OUString& rSenderAddress)
292 0 : {m_sSenderAddress = rSenderAddress;}
293 : };
294 :
295 : #endif
296 :
297 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|