xref: /trunk/main/sw/source/ui/inc/mailmergehelper.hxx (revision cdf0e10c)
1 /*************************************************************************
2  *
3  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4  *
5  * Copyright 2000, 2010 Oracle and/or its affiliates.
6  *
7  * OpenOffice.org - a multi-platform office productivity suite
8  *
9  * This file is part of OpenOffice.org.
10  *
11  * OpenOffice.org is free software: you can redistribute it and/or modify
12  * it under the terms of the GNU Lesser General Public License version 3
13  * only, as published by the Free Software Foundation.
14  *
15  * OpenOffice.org is distributed in the hope that it will be useful,
16  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18  * GNU Lesser General Public License version 3 for more details
19  * (a copy is included in the LICENSE file that accompanied this code).
20  *
21  * You should have received a copy of the GNU Lesser General Public License
22  * version 3 along with OpenOffice.org.  If not, see
23  * <http://www.openoffice.org/license.html>
24  * for a copy of the LGPLv3 License.
25  *
26  ************************************************************************/
27 #ifndef _MAILMERGEHELPER_HXX
28 #define _MAILMERGEHELPER_HXX
29 
30 #include <svtools/stdctrl.hxx>
31 #include <unotools/configitem.hxx>
32 #include <com/sun/star/uno/Sequence.h>
33 #include "com/sun/star/mail/XAuthenticator.hpp"
34 #include "com/sun/star/mail/XConnectionListener.hpp"
35 #include "com/sun/star/uno/XCurrentContext.hpp"
36 #include "com/sun/star/mail/XMailMessage.hpp"
37 #include "com/sun/star/datatransfer/XTransferable.hpp"
38 #include <com/sun/star/beans/XPropertySet.hpp>
39 #include <cppuhelper/implbase1.hxx>
40 #include <cppuhelper/compbase1.hxx>
41 #include <cppuhelper/compbase2.hxx>
42 #include <vcl/scrbar.hxx>
43 #include "swdllapi.h"
44 
45 
46 class SwMailMergeConfigItem;
47 namespace com{ namespace sun{ namespace star{
48     namespace uno{
49         class XComponentContext;
50     }
51     namespace lang{
52         class XMultiServiceFactory;
53     }
54     namespace mail{
55         class XSmtpService;
56         class XMailService;
57     }
58 }}}
59 /*-- 14.06.2004 12:27:42---------------------------------------------------
60 
61   -----------------------------------------------------------------------*/
62 namespace SwMailMergeHelper
63 {
64     SW_DLLPUBLIC String  CallSaveAsDialog(String& rFilter);
65     SW_DLLPUBLIC bool    CheckMailAddress( const ::rtl::OUString& rMailAddress );
66     SW_DLLPUBLIC com::sun::star::uno::Reference< com::sun::star::mail::XSmtpService >
67                          ConnectToSmtpServer( SwMailMergeConfigItem& rConfigItem,
68                             com::sun::star::uno::Reference< com::sun::star::mail::XMailService >&  xInMailService,
69                             const String& rInMailServerPassword,
70                             const String& rOutMailServerPassword,
71                             Window* pDialogParentWindow = 0 );
72 }
73 /* -----------------06.04.2004 10:29-----------------
74 
75  --------------------------------------------------*/
76 class SW_DLLPUBLIC SwBoldFixedInfo : public FixedInfo
77 {
78 public:
79     SwBoldFixedInfo(Window* pParent, const ResId& rResId);
80     ~SwBoldFixedInfo();
81 };
82 struct SwAddressPreview_Impl;
83 namespace com{namespace sun{namespace star{
84     namespace container{
85         class XNameAccess;
86     }
87 }}}
88 
89 /*-- 27.04.2004 13:20:00---------------------------------------------------
90     Preview window used to show the possible selection of address blocks
91     and also the resulting address filled with database data
92   -----------------------------------------------------------------------*/
93 class SW_DLLPUBLIC SwAddressPreview : public Window
94 {
95     ScrollBar               aVScrollBar;
96     SwAddressPreview_Impl*  pImpl;
97     Link                    m_aSelectHdl;
98 
99     void DrawText_Impl( const ::rtl::OUString& rAddress, const Point& rTopLeft, const Size& rSize, bool bIsSelected);
100 
101     virtual void        Paint(const Rectangle&);
102     virtual void        MouseButtonDown( const MouseEvent& rMEvt );
103     virtual void        KeyInput( const KeyEvent& rKEvt );
104     virtual void        StateChanged( StateChangedType nStateChange );
105     void                UpdateScrollBar();
106 
107     DECL_LINK(ScrollHdl, ScrollBar*);
108 
109 public:
110     SwAddressPreview(Window* pParent, const ResId rResId);
111     ~SwAddressPreview();
112 
113     /** The address string is a list of address elements separated by spaces
114     and breaks. The addresses fit into the given layout. If more addresses then
115     rows/columns should be used a scrollbar will be added.
116 
117      AddAddress appends the new address to the already added ones.
118      Initially the first added address will be selected
119     */
120     void                    AddAddress(const ::rtl::OUString& rAddress);
121     //  for preview mode - replaces the currently used address by the given one
122     void                    SetAddress(const ::rtl::OUString& rAddress);
123     // removes all addresses
124     void                    Clear();
125 
126     // returns the selected address
127     sal_uInt16              GetSelectedAddress() const;
128     void                    SelectAddress(sal_uInt16 nSelect);
129     void                    ReplaceSelectedAddress(const ::rtl::OUString&);
130     void                    RemoveSelectedAddress();
131 
132     // set the number of rows and columns of addresses
133     void                    SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns);
134     void                    EnableScrollBar(bool bEnable = true);
135 
136     // fill the actual data into a string (address block or greeting)
137     static String FillData(
138             const ::rtl::OUString& rAddress,
139             SwMailMergeConfigItem& rConfigItem,
140             const ::com::sun::star::uno::Sequence< ::rtl::OUString>* pAssignments = 0);
141 
142     void    SetSelectHdl (const Link& rLink) {m_aSelectHdl = rLink;}
143 };
144 
145 /*-- 11.05.2004 15:39:59---------------------------------------------------
146     iterate over an address block or a greeting line
147     the iterator returns the parts either as pure string
148     or as column
149   -----------------------------------------------------------------------*/
150 struct SwMergeAddressItem
151 {
152     String  sText;
153     bool    bIsColumn;
154     bool    bIsReturn;
155     SwMergeAddressItem() :
156         bIsColumn(false),
157         bIsReturn(false) {}
158 };
159 class SW_DLLPUBLIC   SwAddressIterator
160 {
161     String sAddress;
162 public:
163     SwAddressIterator(const String& rAddress) :
164         sAddress(rAddress){}
165 
166     SwMergeAddressItem  Next();
167     bool                HasMore() const{return sAddress.Len() > 0;}
168 };
169 
170 /*-- 21.05.2004 10:31:15---------------------------------------------------
171 
172   -----------------------------------------------------------------------*/
173 class SW_DLLPUBLIC SwAuthenticator :
174     public cppu::WeakImplHelper1< ::com::sun::star::mail::XAuthenticator>
175 {
176     ::rtl::OUString m_aUserName;
177     ::rtl::OUString m_aPassword;
178     Window*         m_pParentWindow;
179 public:
180     SwAuthenticator() : m_pParentWindow(0) {}
181     SwAuthenticator(const ::rtl::OUString& username, const ::rtl::OUString& password, Window* pParent) :
182         m_aUserName(username),
183         m_aPassword(password),
184         m_pParentWindow( pParent )
185     {}
186     ~SwAuthenticator();
187 
188     virtual ::rtl::OUString SAL_CALL getUserName( ) throw (::com::sun::star::uno::RuntimeException);
189     virtual ::rtl::OUString SAL_CALL getPassword(  ) throw (::com::sun::star::uno::RuntimeException);
190 
191 };
192 /*-- 25.08.2004 12:48:47---------------------------------------------------
193 
194   -----------------------------------------------------------------------*/
195 class SW_DLLPUBLIC SwConnectionContext :
196     public cppu::WeakImplHelper1< ::com::sun::star::uno::XCurrentContext >
197 {
198     ::rtl::OUString     m_sMailServer;
199     sal_Int16           m_nPort;
200     ::rtl::OUString     m_sConnectionType;
201 
202 public:
203     SwConnectionContext(const ::rtl::OUString& rMailServer, sal_Int16 nPort, const ::rtl::OUString& rConnectionType);
204     ~SwConnectionContext();
205 
206     virtual ::com::sun::star::uno::Any SAL_CALL     getValueByName( const ::rtl::OUString& Name )
207                                                             throw (::com::sun::star::uno::RuntimeException);
208 };
209 /*-- 21.05.2004 10:39:20---------------------------------------------------
210 
211   -----------------------------------------------------------------------*/
212 class SwMutexBase
213 {
214 public:
215     osl::Mutex m_aMutex;
216 };
217 /*-- 21.05.2004 10:39:20---------------------------------------------------
218 
219   -----------------------------------------------------------------------*/
220 class SW_DLLPUBLIC SwConnectionListener :
221         public SwMutexBase,
222         public cppu::WeakComponentImplHelper1< ::com::sun::star::mail::XConnectionListener >
223 {
224     using cppu::WeakComponentImplHelperBase::disposing;
225 
226 public:
227     SwConnectionListener() :
228         cppu::WeakComponentImplHelper1< ::com::sun::star::mail::XConnectionListener>(m_aMutex)
229     {}
230     ~SwConnectionListener();
231 
232     virtual void SAL_CALL connected(const ::com::sun::star::lang::EventObject& aEvent)
233         throw (::com::sun::star::uno::RuntimeException);
234 
235     virtual void SAL_CALL disconnected(const ::com::sun::star::lang::EventObject& aEvent)
236         throw (::com::sun::star::uno::RuntimeException);
237 
238     virtual void SAL_CALL disposing(const com::sun::star::lang::EventObject& aEvent)
239         throw(com::sun::star::uno::RuntimeException);
240 };
241 
242 /*-- 13.07.2004 09:02:12---------------------------------------------------
243 
244   -----------------------------------------------------------------------*/
245 class SwMailTransferable :
246         public SwMutexBase,
247         public cppu::WeakComponentImplHelper2
248         <
249             ::com::sun::star::datatransfer::XTransferable,
250             ::com::sun::star::beans::XPropertySet
251         >
252 {
253     rtl::OUString  m_aMimeType;
254     rtl::OUString  m_sBody;
255     rtl::OUString  m_aURL;
256     rtl::OUString  m_aName;
257     bool           m_bIsBody;
258 
259     public:
260     SwMailTransferable(const rtl::OUString& rURL, const rtl::OUString& rName, const rtl::OUString& rMimeType);
261     SwMailTransferable(const rtl::OUString& rBody, const rtl::OUString& rMimeType);
262     ~SwMailTransferable();
263     virtual ::com::sun::star::uno::Any SAL_CALL
264                         getTransferData( const ::com::sun::star::datatransfer::DataFlavor& aFlavor )
265                             throw (::com::sun::star::datatransfer::UnsupportedFlavorException, ::com::sun::star::io::IOException, ::com::sun::star::uno::RuntimeException);
266     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::datatransfer::DataFlavor > SAL_CALL
267                         getTransferDataFlavors(  )
268                             throw (::com::sun::star::uno::RuntimeException) ;
269     virtual ::sal_Bool SAL_CALL
270                         isDataFlavorSupported( const ::com::sun::star::datatransfer::DataFlavor& aFlavor )
271                             throw (::com::sun::star::uno::RuntimeException);
272 
273     //XPropertySet
274     virtual ::com::sun::star::uno::Reference< ::com::sun::star::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo(  ) throw(::com::sun::star::uno::RuntimeException);
275     virtual void SAL_CALL setPropertyValue( const ::rtl::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);
276     virtual ::com::sun::star::uno::Any SAL_CALL getPropertyValue( const ::rtl::OUString& PropertyName ) throw(::com::sun::star::beans::UnknownPropertyException, ::com::sun::star::lang::WrappedTargetException, ::com::sun::star::uno::RuntimeException);
277     virtual void SAL_CALL addPropertyChangeListener( const ::rtl::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);
278     virtual void SAL_CALL removePropertyChangeListener( const ::rtl::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);
279     virtual void SAL_CALL addVetoableChangeListener( const ::rtl::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);
280     virtual void SAL_CALL removeVetoableChangeListener( const ::rtl::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);
281 
282 };
283 
284 /*-- 22.06.2004 16:38:34---------------------------------------------------
285 
286   -----------------------------------------------------------------------*/
287 class SwMailMessage :
288         public SwMutexBase,
289         public cppu::WeakComponentImplHelper1< ::com::sun::star::mail::XMailMessage >
290 {
291     ::rtl::OUString                                                                         m_sSenderName;
292     ::rtl::OUString                                                                         m_sSenderAddress;
293     ::rtl::OUString                                                                         m_sReplyToAddress;
294     ::rtl::OUString                                                                         m_sSubject;
295 
296     ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable>        m_xBody;
297 //    ::com::sun::star::mail::MailMessageBody                                                 m_aBody;
298 
299     ::com::sun::star::uno::Sequence< ::rtl::OUString >                                      m_aRecipients;
300     ::com::sun::star::uno::Sequence< ::rtl::OUString >                                      m_aCcRecipients;
301     ::com::sun::star::uno::Sequence< ::rtl::OUString >                                      m_aBccRecipients;
302 //    ::com::sun::star::uno::Sequence< ::com::sun::star::mail::MailAttachmentDescriptor >     m_aAttachments;
303     ::com::sun::star::uno::Sequence<  ::com::sun::star::mail::MailAttachment >              m_aAttachments;
304 public:
305     SwMailMessage();
306     ~SwMailMessage();
307 
308     // Attributes
309     virtual ::rtl::OUString SAL_CALL    getSenderName() throw (::com::sun::star::uno::RuntimeException);
310     virtual ::rtl::OUString SAL_CALL    getSenderAddress() throw (::com::sun::star::uno::RuntimeException);
311     virtual ::rtl::OUString SAL_CALL    getReplyToAddress() throw (::com::sun::star::uno::RuntimeException);
312     virtual void SAL_CALL               setReplyToAddress( const ::rtl::OUString& _replytoaddress ) throw (::com::sun::star::uno::RuntimeException);
313     virtual ::rtl::OUString SAL_CALL    getSubject() throw (::com::sun::star::uno::RuntimeException);
314     virtual void SAL_CALL               setSubject( const ::rtl::OUString& _subject ) throw (::com::sun::star::uno::RuntimeException);
315 
316     virtual ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable > SAL_CALL
317                                         getBody()
318                                                 throw (::com::sun::star::uno::RuntimeException);
319     virtual void SAL_CALL               setBody( const ::com::sun::star::uno::Reference< ::com::sun::star::datatransfer::XTransferable >& _body )
320                                                 throw (::com::sun::star::uno::RuntimeException);
321 
322     // Methods
323     virtual void SAL_CALL               addRecipient( const ::rtl::OUString& sRecipientAddress ) throw (::com::sun::star::uno::RuntimeException);
324     virtual void SAL_CALL               addCcRecipient( const ::rtl::OUString& sRecipientAddress ) throw (::com::sun::star::uno::RuntimeException);
325     virtual void SAL_CALL               addBccRecipient( const ::rtl::OUString& sRecipientAddress ) throw (::com::sun::star::uno::RuntimeException);
326     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
327                                         getRecipients(  ) throw (::com::sun::star::uno::RuntimeException);
328     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
329                                         getCcRecipients(  ) throw (::com::sun::star::uno::RuntimeException);
330     virtual ::com::sun::star::uno::Sequence< ::rtl::OUString > SAL_CALL
331                                         getBccRecipients(  ) throw (::com::sun::star::uno::RuntimeException);
332     virtual void SAL_CALL               addAttachment( const ::com::sun::star::mail::MailAttachment& aMailAttachment )
333                                             throw (::com::sun::star::uno::RuntimeException);
334     virtual ::com::sun::star::uno::Sequence< ::com::sun::star::mail::MailAttachment > SAL_CALL
335                                         getAttachments(  ) throw (::com::sun::star::uno::RuntimeException);
336     void                                SetSenderName(const ::rtl::OUString& rSenderName)
337                                                 {m_sSenderName = rSenderName;}
338     void                                SetSenderAddress(const ::rtl::OUString& rSenderAddress)
339                                                 {m_sSenderAddress = rSenderAddress;}
340 };
341 /*-- 21.05.2004 10:17:22---------------------------------------------------
342 
343   -----------------------------------------------------------------------*/
344 SW_DLLPUBLIC ::com::sun::star::uno::Reference< ::com::sun::star::uno::XComponentContext>
345         getCurrentCmpCtx(
346             ::com::sun::star::uno::Reference<
347                 ::com::sun::star::lang::XMultiServiceFactory> rSrvMgr);
348 #endif
349 
350