summaryrefslogtreecommitdiff
path: root/sw/source/uibase/inc/mailmergehelper.hxx
blob: 575c4f679bc2b39a76263c3720a4c72d7c904088 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
/* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
/*
 * This file is part of the LibreOffice project.
 *
 * This Source Code Form is subject to the terms of the Mozilla Public
 * License, v. 2.0. If a copy of the MPL was not distributed with this
 * file, You can obtain one at http://mozilla.org/MPL/2.0/.
 *
 * This file incorporates work covered by the following license notice:
 *
 *   Licensed to the Apache Software Foundation (ASF) under one or more
 *   contributor license agreements. See the NOTICE file distributed
 *   with this work for additional information regarding copyright
 *   ownership. The ASF licenses this file to you under the Apache
 *   License, Version 2.0 (the "License"); you may not use this file
 *   except in compliance with the License. You may obtain a copy of
 *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
 */
#ifndef INCLUDED_SW_SOURCE_UIBASE_INC_MAILMERGEHELPER_HXX
#define INCLUDED_SW_SOURCE_UIBASE_INC_MAILMERGEHELPER_HXX

#include <unotools/configitem.hxx>
#include <com/sun/star/uno/Sequence.h>
#include <com/sun/star/mail/XAuthenticator.hpp>
#include <com/sun/star/mail/XConnectionListener.hpp>
#include <com/sun/star/uno/XCurrentContext.hpp>
#include <com/sun/star/mail/XMailMessage.hpp>
#include <com/sun/star/datatransfer/XTransferable.hpp>
#include <com/sun/star/beans/XPropertySet.hpp>
#include <cppuhelper/implbase.hxx>
#include <cppuhelper/compbase.hxx>
#include <vcl/scrbar.hxx>
#include <vcl/customweld.hxx>
#include <vcl/weld.hxx>
#include <rtl/ustring.hxx>
#include <swdllapi.h>

class SwMailMergeConfigItem;

namespace com { namespace sun { namespace star { namespace mail {
    class XMailService;
    class XSmtpService;
} } } }

namespace SwMailMergeHelper
{
    SW_DLLPUBLIC OUString CallSaveAsDialog(weld::Window* pParent, OUString& rFilter);
    SW_DLLPUBLIC bool CheckMailAddress(const OUString& rMailAddress);
    SW_DLLPUBLIC css::uno::Reference<css::mail::XSmtpService> ConnectToSmtpServer(
                            SwMailMergeConfigItem const & rConfigItem,
                            css::uno::Reference<css::mail::XMailService>& xInMailService,
                            const OUString& rInMailServerPassword,
                            const OUString& rOutMailServerPassword,
                            weld::Window* pDialogParentWindow = nullptr);
}

struct SwAddressPreview_Impl;

// Preview window used to show the possible selection of address blocks
// and also the resulting address filled with database data
class SW_DLLPUBLIC SwAddressPreview : public vcl::Window
{
    VclPtr<ScrollBar> aVScrollBar;
    SwAddressPreview_Impl* pImpl;
    Link<LinkParamNone*,void> m_aSelectHdl;

    void DrawText_Impl(vcl::RenderContext& rRenderContext, const OUString& rAddress,
                       const Point& rTopLeft, const Size& rSize, bool bIsSelected);

    virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) override;
    virtual void Resize() override;
    virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
    virtual void KeyInput( const KeyEvent& rKEvt ) override;
    virtual void StateChanged( StateChangedType nStateChange ) override;
    void UpdateScrollBar();

    DECL_LINK(ScrollHdl, ScrollBar*,void);

public:
    SwAddressPreview(vcl::Window* pParent, WinBits nStyle);
    virtual ~SwAddressPreview() override;
    virtual void dispose() override;

    void positionScrollBar();

    /** The address string is a list of address elements separated by spaces
    and breaks. The addresses fit into the given layout. If more addresses then
    rows/columns should be used a scrollbar will be added.

     AddAddress appends the new address to the already added ones.
     Initially the first added address will be selected
    */
    void AddAddress(const OUString& rAddress);
    //  for preview mode - replaces the currently used address by the given one
    void SetAddress(const OUString& rAddress);
    // removes all addresses
    void Clear();

    // returns the selected address
    sal_uInt16 GetSelectedAddress() const;
    void SelectAddress(sal_uInt16 nSelect);
    void ReplaceSelectedAddress(const OUString&);
    void RemoveSelectedAddress();

    // set the number of rows and columns of addresses
    void SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns);
    void EnableScrollBar();

    // fill the actual data into a string (address block or greeting)
    static OUString FillData(const OUString& rAddress, SwMailMergeConfigItem const & rConfigItem,
                             const css::uno::Sequence<OUString>* pAssignments = nullptr);

    void SetSelectHdl (const Link<LinkParamNone*,void>& rLink) { m_aSelectHdl = rLink; }
};

class SW_DLLPUBLIC AddressPreview : public weld::CustomWidgetController
{
    std::unique_ptr<SwAddressPreview_Impl> pImpl;
    std::unique_ptr<weld::ScrolledWindow> m_xVScrollBar;
    Link<LinkParamNone*,void> m_aSelectHdl;

    void DrawText_Impl(vcl::RenderContext& rRenderContext, const OUString& rAddress,
                       const Point& rTopLeft, const Size& rSize, bool bIsSelected);

    virtual void Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) override;
    virtual void MouseButtonDown( const MouseEvent& rMEvt ) override;
    virtual bool KeyInput( const KeyEvent& rKEvt ) override;
    void UpdateScrollBar();

    DECL_LINK(ScrollHdl, weld::ScrolledWindow&,void);

public:
    AddressPreview(std::unique_ptr<weld::ScrolledWindow> xParent);
    virtual ~AddressPreview() override;

    /** The address string is a list of address elements separated by spaces
    and breaks. The addresses fit into the given layout. If more addresses then
    rows/columns should be used a scrollbar will be added.

     AddAddress appends the new address to the already added ones.
     Initially the first added address will be selected
    */
    void AddAddress(const OUString& rAddress);
    //  for preview mode - replaces the currently used address by the given one
    void SetAddress(const OUString& rAddress);
    // removes all addresses
    void Clear();

    // returns the selected address
    sal_uInt16 GetSelectedAddress() const;
    void SelectAddress(sal_uInt16 nSelect);
    void ReplaceSelectedAddress(const OUString&);
    void RemoveSelectedAddress();

    // set the number of rows and columns of addresses
    void SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns);
    void EnableScrollBar();

    // fill the actual data into a string (address block or greeting)
    static OUString FillData(const OUString& rAddress, SwMailMergeConfigItem const & rConfigItem,
                             const css::uno::Sequence<OUString>* pAssignments = nullptr);

    void SetSelectHdl (const Link<LinkParamNone*,void>& rLink) { m_aSelectHdl = rLink; }
};


// iterate over an address block or a greeting line the iterator returns the
// parts either as pure string or as column
struct SwMergeAddressItem
{
    OUString sText;
    bool bIsColumn;
    bool bIsReturn;

    SwMergeAddressItem()
        : bIsColumn(false)
        , bIsReturn(false)
    {}
};

class SW_DLLPUBLIC SwAddressIterator
{
    OUString sAddress;
public:
    SwAddressIterator(const OUString& rAddress) :
        sAddress(rAddress)
    {}

    SwMergeAddressItem  Next();
    bool HasMore() const { return !sAddress.isEmpty(); }
};

class SW_DLLPUBLIC SwAuthenticator :
    public cppu::WeakImplHelper<css::mail::XAuthenticator>
{
    OUString const m_aUserName;
    OUString m_aPassword;
    weld::Window* m_pParentWindow;
public:
    SwAuthenticator()
        : m_pParentWindow(nullptr)
    {}
    SwAuthenticator(const OUString& username, const OUString& password, weld::Window* pParent)
        : m_aUserName(username)
        , m_aPassword(password)
        , m_pParentWindow(pParent)
    {}
    virtual ~SwAuthenticator() override;

    virtual OUString SAL_CALL getUserName() override;
    virtual OUString SAL_CALL getPassword() override;

};

class SW_DLLPUBLIC SwConnectionContext : public cppu::WeakImplHelper<css::uno::XCurrentContext>
{
    OUString const m_sMailServer;
    sal_Int16 const m_nPort;
    OUString const m_sConnectionType;

public:
    SwConnectionContext(const OUString& rMailServer, sal_Int16 nPort, const OUString& rConnectionType);
    virtual ~SwConnectionContext() override;

    virtual css::uno::Any SAL_CALL getValueByName(const OUString& Name) override;
};

class SwMutexBase
{
public:
    osl::Mutex m_aMutex;
};

class SW_DLLPUBLIC SwConnectionListener :
        public SwMutexBase,
        public cppu::WeakComponentImplHelper<css::mail::XConnectionListener>
{
    using cppu::WeakComponentImplHelperBase::disposing;

public:
    SwConnectionListener() :
        cppu::WeakComponentImplHelper<css::mail::XConnectionListener>(m_aMutex)
    {}
    virtual ~SwConnectionListener() override;

    virtual void SAL_CALL connected(const css::lang::EventObject& aEvent) override;

    virtual void SAL_CALL disconnected(const css::lang::EventObject& aEvent) override;

    virtual void SAL_CALL disposing(const css::lang::EventObject& aEvent) override;
};

class SW_DLLPUBLIC SwMailTransferable :
        public SwMutexBase,
        public cppu::WeakComponentImplHelper<css::datatransfer::XTransferable, css::beans::XPropertySet>
{
    OUString const  m_aMimeType;
    OUString const  m_sBody;
    OUString const  m_aURL;
    OUString const  m_aName;
    bool const m_bIsBody;

    public:
    SwMailTransferable(const OUString& rURL, const OUString& rName, const OUString& rMimeType);
    SwMailTransferable(const OUString& rBody, const OUString& rMimeType);
    virtual ~SwMailTransferable() override;
    virtual css::uno::Any SAL_CALL getTransferData(const css::datatransfer::DataFlavor& aFlavor) override;

    virtual css::uno::Sequence<css::datatransfer::DataFlavor> SAL_CALL getTransferDataFlavors() override;
    virtual sal_Bool SAL_CALL isDataFlavorSupported(const css::datatransfer::DataFlavor& aFlavor) override;

    //XPropertySet
    virtual css::uno::Reference<css::beans::XPropertySetInfo> SAL_CALL getPropertySetInfo() override;
    virtual void SAL_CALL setPropertyValue(const OUString& aPropertyName, const css::uno::Any& aValue) override;

    virtual css::uno::Any SAL_CALL getPropertyValue(const OUString& PropertyName) override;
    virtual void SAL_CALL addPropertyChangeListener(const OUString& aPropertyName,
                                                    const css::uno::Reference<css::beans::XPropertyChangeListener>& xListener) override;
    virtual void SAL_CALL removePropertyChangeListener(const OUString& aPropertyName,
                                                       const css::uno::Reference<css::beans::XPropertyChangeListener >& aListener) override;
    virtual void SAL_CALL addVetoableChangeListener(const OUString& PropertyName,
                                                    const css::uno::Reference<css::beans::XVetoableChangeListener>& aListener) override;
    virtual void SAL_CALL removeVetoableChangeListener(const OUString& PropertyName,
                                                       const css::uno::Reference<css::beans::XVetoableChangeListener>& aListener) override;

};

class SW_DLLPUBLIC SwMailMessage :
        public SwMutexBase,
        public cppu::WeakComponentImplHelper<css::mail::XMailMessage>
{
    OUString m_sSenderName;
    OUString m_sSenderAddress;
    OUString m_sReplyToAddress;
    OUString m_sSubject;

    css::uno::Reference<css::datatransfer::XTransferable> m_xBody;
//  css::mail::MailMessageBody m_aBody;

    css::uno::Sequence<OUString> m_aRecipients;
    css::uno::Sequence<OUString> m_aCcRecipients;
    css::uno::Sequence<OUString> m_aBccRecipients;
//  css::uno::Sequence<css::mail::MailAttachmentDescriptor> m_aAttachments;
    css::uno::Sequence<css::mail::MailAttachment> m_aAttachments;
public:
    SwMailMessage();
    virtual ~SwMailMessage() override;

    // attributes
    virtual OUString SAL_CALL getSenderName() override;
    virtual OUString SAL_CALL getSenderAddress() override;
    virtual OUString SAL_CALL getReplyToAddress() override;
    virtual void SAL_CALL setReplyToAddress( const OUString& _replytoaddress ) override;
    virtual OUString SAL_CALL getSubject() override;
    virtual void SAL_CALL setSubject(const OUString& _subject) override;

    virtual css::uno::Reference<css::datatransfer::XTransferable> SAL_CALL getBody() override;
    virtual void SAL_CALL setBody(const css::uno::Reference<css::datatransfer::XTransferable>& _body) override;

    // methods
    virtual void SAL_CALL addRecipient( const OUString& sRecipientAddress ) override;
    virtual void SAL_CALL addCcRecipient( const OUString& sRecipientAddress ) override;
    virtual void SAL_CALL addBccRecipient( const OUString& sRecipientAddress ) override;
    virtual css::uno::Sequence<OUString> SAL_CALL getRecipients() override;
    virtual css::uno::Sequence<OUString> SAL_CALL getCcRecipients() override;
    virtual css::uno::Sequence<OUString> SAL_CALL getBccRecipients() override;
    virtual void SAL_CALL addAttachment(const css::mail::MailAttachment& aMailAttachment) override;
    virtual css::uno::Sequence<css::mail::MailAttachment> SAL_CALL getAttachments() override;
    void SetSenderName(const OUString& rSenderName)
    {
        m_sSenderName = rSenderName;
    }
    void SetSenderAddress(const OUString& rSenderAddress)
    {
        m_sSenderAddress = rSenderAddress;
    }
};

#endif

/* vim:set shiftwidth=4 softtabstop=4 expandtab: */