Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : : #include <swtypes.hxx>
30 : : #include <mailmergehelper.hxx>
31 : : #include <svtools/stdctrl.hxx>
32 : : #include <mmconfigitem.hxx>
33 : : #include <docsh.hxx>
34 : : #include <sfx2/filedlghelper.hxx>
35 : : #include <sfx2/docfile.hxx>
36 : : #include <sfx2/app.hxx>
37 : : #include <sfx2/fcontnr.hxx>
38 : : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
39 : : #include <com/sun/star/sdb/XColumn.hpp>
40 : : #include <com/sun/star/beans/XPropertySet.hpp>
41 : : #include "com/sun/star/ui/dialogs/TemplateDescription.hpp"
42 : : #include <com/sun/star/ui/dialogs/XFilePicker.hpp>
43 : : #include "com/sun/star/mail/MailServiceProvider.hpp"
44 : : #include "com/sun/star/mail/XSmtpService.hpp"
45 : : #include <comphelper/processfactory.hxx>
46 : : #include <comphelper/string.hxx>
47 : : #include <vcl/msgbox.hxx>
48 : : #include <sfx2/passwd.hxx>
49 : :
50 : : #include <dbui.hrc>
51 : :
52 : : using namespace ::com::sun::star;
53 : : using namespace ::com::sun::star::uno;
54 : : using namespace ::com::sun::star::container;
55 : : using namespace ::com::sun::star::sdb;
56 : : using namespace ::com::sun::star::sdbc;
57 : : using namespace ::com::sun::star::sdbcx;
58 : :
59 : : using rtl::OUString;
60 : :
61 : : namespace SwMailMergeHelper
62 : : {
63 : :
64 : 0 : String CallSaveAsDialog(String& rFilter)
65 : : {
66 : : ErrCode nRet;
67 [ # # ][ # # ]: 0 : String sFactory(rtl::OUString::createFromAscii(SwDocShell::Factory().GetShortName()));
68 : : ::sfx2::FileDialogHelper aDialog( ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION,
69 : : 0,
70 [ # # ]: 0 : sFactory );
71 : :
72 [ # # ]: 0 : String sRet;
73 [ # # ]: 0 : nRet = aDialog.Execute();
74 [ # # ]: 0 : if(ERRCODE_NONE == nRet)
75 : : {
76 [ # # ]: 0 : uno::Reference < ui::dialogs::XFilePicker > xFP = aDialog.GetFilePicker();
77 [ # # ][ # # ]: 0 : sRet = xFP->getFiles().getConstArray()[0];
[ # # ][ # # ]
78 [ # # ][ # # ]: 0 : rFilter = aDialog.GetRealFilter();
[ # # ]
79 : : }
80 [ # # ][ # # ]: 0 : return sRet;
81 : : }
82 : :
83 : : /*
84 : : simple address check: check for '@'
85 : : for at least one '.' after the '@'
86 : : and for at least to characters before and after the dot
87 : : */
88 : 0 : bool CheckMailAddress( const ::rtl::OUString& rMailAddress )
89 : : {
90 [ # # ]: 0 : String sAddress(rMailAddress);
91 [ # # ][ # # ]: 0 : if (!(comphelper::string::getTokenCount(sAddress, '@') == 2))
[ # # ]
92 : 0 : return false;
93 [ # # ][ # # ]: 0 : sAddress = sAddress.GetToken(1, '@');
[ # # ]
94 [ # # ][ # # ]: 0 : if (comphelper::string::getTokenCount(sAddress, '.') < 2)
[ # # ]
95 : 0 : return false;
96 [ # # ][ # # ]: 0 : if(sAddress.GetToken( 0, '.').Len() < 2 || sAddress.GetToken( 1, '.').Len() < 2)
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # #
# # ]
97 : 0 : return false;
98 [ # # ]: 0 : return true;
99 : : }
100 : :
101 : 0 : uno::Reference< mail::XSmtpService > ConnectToSmtpServer(
102 : : SwMailMergeConfigItem& rConfigItem,
103 : : uno::Reference< mail::XMailService >& rxInMailService,
104 : : const String& rInMailServerPassword,
105 : : const String& rOutMailServerPassword,
106 : : Window* pDialogParentWindow )
107 : : {
108 : 0 : uno::Reference< mail::XSmtpService > xSmtpServer;
109 [ # # ]: 0 : uno::Reference< lang::XMultiServiceFactory> rMgr = ::comphelper::getProcessServiceFactory();
110 [ # # ]: 0 : if (rMgr.is())
111 : : try
112 : : {
113 : : uno::Reference< mail::XMailServiceProvider > xMailServiceProvider =
114 [ # # ][ # # ]: 0 : mail::MailServiceProvider::create(getCurrentCmpCtx(rMgr));
115 : : xSmtpServer = uno::Reference< mail::XSmtpService > (
116 [ # # ]: 0 : xMailServiceProvider->create(
117 : : mail::MailServiceType_SMTP
118 [ # # ][ # # ]: 0 : ), uno::UNO_QUERY);
[ # # ]
119 : :
120 [ # # ][ # # ]: 0 : uno::Reference< mail::XConnectionListener> xConnectionListener(new SwConnectionListener());
[ # # ]
121 : :
122 [ # # ][ # # ]: 0 : if(rConfigItem.IsAuthentication() && rConfigItem.IsSMTPAfterPOP())
[ # # ][ # # ]
[ # # ]
123 : : {
124 : : uno::Reference< mail::XMailService > xInMailService =
125 [ # # ]: 0 : xMailServiceProvider->create(
126 [ # # ]: 0 : rConfigItem.IsInServerPOP() ?
127 [ # # ][ # # ]: 0 : mail::MailServiceType_POP3 : mail::MailServiceType_IMAP);
128 : : //authenticate at the POP or IMAP server first
129 [ # # ][ # # ]: 0 : String sPasswd = rConfigItem.GetInServerPassword();
130 [ # # ]: 0 : if(rInMailServerPassword.Len())
131 [ # # ]: 0 : sPasswd = rInMailServerPassword;
132 : : uno::Reference<mail::XAuthenticator> xAuthenticator =
133 : : new SwAuthenticator(
134 : : rConfigItem.GetInServerUserName(),
135 : : sPasswd,
136 [ # # ][ # # ]: 0 : pDialogParentWindow);
[ # # ][ # # ]
[ # # ]
137 : :
138 [ # # ][ # # ]: 0 : xInMailService->addConnectionListener(xConnectionListener);
139 : : //check connection
140 : : uno::Reference< uno::XCurrentContext> xConnectionContext =
141 : : new SwConnectionContext(
142 : : rConfigItem.GetInServerName(),
143 [ # # ]: 0 : rConfigItem.GetInServerPort(),
144 [ # # ][ # # ]: 0 : ::rtl::OUString("Insecure"));
[ # # ][ # # ]
145 [ # # ][ # # ]: 0 : xInMailService->connect(xConnectionContext, xAuthenticator);
146 [ # # ][ # # ]: 0 : rxInMailService = xInMailService;
147 : : }
148 : 0 : uno::Reference< mail::XAuthenticator> xAuthenticator;
149 [ # # ]: 0 : if(rConfigItem.IsAuthentication() &&
[ # # # # ]
[ # # ][ # # ]
150 [ # # ]: 0 : !rConfigItem.IsSMTPAfterPOP() &&
151 [ # # ][ # # ]: 0 : !rConfigItem.GetMailUserName().isEmpty())
[ # # ]
152 : : {
153 [ # # ][ # # ]: 0 : String sPasswd = rConfigItem.GetMailPassword();
154 [ # # ]: 0 : if(rOutMailServerPassword.Len())
155 [ # # ]: 0 : sPasswd = rOutMailServerPassword;
156 : : xAuthenticator =
157 : : new SwAuthenticator(rConfigItem.GetMailUserName(),
158 : : sPasswd,
159 [ # # ][ # # ]: 0 : pDialogParentWindow);
[ # # ][ # # ]
[ # # ][ # # ]
160 : : }
161 : : else
162 [ # # ][ # # ]: 0 : xAuthenticator = new SwAuthenticator();
[ # # ]
163 : : //just to check if the server exists
164 [ # # ][ # # ]: 0 : xSmtpServer->getSupportedConnectionTypes();
[ # # ]
165 : : //check connection
166 : :
167 : : uno::Reference< uno::XCurrentContext> xConnectionContext =
168 : : new SwConnectionContext(
169 : : rConfigItem.GetMailServer(),
170 [ # # ]: 0 : rConfigItem.GetMailPort(),
171 [ # # ][ # # ]: 0 : rConfigItem.IsSecureConnection() ? OUString("Ssl") : OUString("Insecure") );
[ # # ][ # # ]
[ # # ][ # # ]
[ # # ][ # # ]
[ # # # # ]
172 [ # # ][ # # ]: 0 : xSmtpServer->connect(xConnectionContext, xAuthenticator);
173 [ # # ][ # # ]: 0 : rxInMailService = uno::Reference< mail::XMailService >( xSmtpServer, uno::UNO_QUERY );
[ # # ]
174 : : }
175 [ # # ]: 0 : catch (const uno::Exception&)
176 : : {
177 : : OSL_FAIL("exception caught");
178 : : }
179 : 0 : return xSmtpServer;
180 : : }
181 : :
182 : :
183 : : } //namespace
184 : :
185 : 0 : SwBoldFixedInfo::SwBoldFixedInfo(Window* pParent, const ResId& rResId) :
186 : 0 : FixedInfo(pParent, rResId)
187 : : {
188 [ # # ]: 0 : Font aFont = GetFont();
189 [ # # ]: 0 : aFont.SetWeight( WEIGHT_BOLD );
190 [ # # ][ # # ]: 0 : SetFont( aFont );
191 : 0 : }
192 : :
193 : 0 : SwBoldFixedInfo::~SwBoldFixedInfo()
194 : : {
195 [ # # ]: 0 : }
196 : :
197 : : struct SwAddressPreview_Impl
198 : : {
199 : : ::std::vector< ::rtl::OUString > aAdresses;
200 : : sal_uInt16 nRows;
201 : : sal_uInt16 nColumns;
202 : : sal_uInt16 nSelectedAddress;
203 : : bool bEnableScrollBar;
204 : :
205 : 0 : SwAddressPreview_Impl() :
206 : : nRows(1),
207 : : nColumns(1),
208 : : nSelectedAddress(0),
209 : 0 : bEnableScrollBar(false)
210 : : {
211 : 0 : }
212 : : };
213 : :
214 : 0 : SwAddressPreview::SwAddressPreview(Window* pParent, const ResId rResId) :
215 : : Window( pParent, rResId ),
216 : : aVScrollBar(this, WB_VSCROLL),
217 [ # # ][ # # ]: 0 : pImpl(new SwAddressPreview_Impl())
[ # # ][ # # ]
218 : : {
219 [ # # ]: 0 : aVScrollBar.SetScrollHdl(LINK(this, SwAddressPreview, ScrollHdl));
220 : 0 : Size aSize(GetOutputSizePixel());
221 [ # # ]: 0 : Size aScrollSize(aVScrollBar.GetSizePixel());
222 : 0 : aScrollSize.Height() = aSize.Height();
223 [ # # ]: 0 : aVScrollBar.SetSizePixel(aScrollSize);
224 : 0 : Point aSrollPos(aSize.Width() - aScrollSize.Width(), 0);
225 [ # # ]: 0 : aVScrollBar.SetPosPixel(aSrollPos);
226 [ # # ]: 0 : Show();
227 : 0 : }
228 : :
229 [ # # ]: 0 : SwAddressPreview::~SwAddressPreview()
230 : : {
231 [ # # ]: 0 : }
232 : :
233 : 0 : IMPL_LINK_NOARG(SwAddressPreview, ScrollHdl)
234 : : {
235 : 0 : Invalidate();
236 : 0 : return 0;
237 : : }
238 : :
239 : 0 : void SwAddressPreview::AddAddress(const ::rtl::OUString& rAddress)
240 : : {
241 : 0 : pImpl->aAdresses.push_back(rAddress);
242 : 0 : UpdateScrollBar();
243 : 0 : }
244 : :
245 : 0 : void SwAddressPreview::SetAddress(const ::rtl::OUString& rAddress)
246 : : {
247 : 0 : pImpl->aAdresses.clear();
248 : 0 : pImpl->aAdresses.push_back(rAddress);
249 : 0 : aVScrollBar.Show(sal_False);
250 : 0 : Invalidate();
251 : 0 : }
252 : :
253 : 0 : sal_uInt16 SwAddressPreview::GetSelectedAddress()const
254 : : {
255 : : OSL_ENSURE(pImpl->nSelectedAddress < pImpl->aAdresses.size(), "selection invalid");
256 : 0 : return pImpl->nSelectedAddress;
257 : : }
258 : :
259 : 0 : void SwAddressPreview::SelectAddress(sal_uInt16 nSelect)
260 : : {
261 : : OSL_ENSURE(pImpl->nSelectedAddress < pImpl->aAdresses.size(), "selection invalid");
262 : 0 : pImpl->nSelectedAddress = nSelect;
263 : : // now make it visible..
264 : 0 : sal_uInt16 nSelectRow = nSelect / pImpl->nColumns;
265 : 0 : sal_uInt16 nStartRow = (sal_uInt16)aVScrollBar.GetThumbPos();
266 [ # # ][ # # ]: 0 : if( (nSelectRow < nStartRow) || (nSelectRow >= (nStartRow + pImpl->nRows) ))
267 : 0 : aVScrollBar.SetThumbPos( nSelectRow );
268 : 0 : }
269 : :
270 : 0 : void SwAddressPreview::Clear()
271 : : {
272 : 0 : pImpl->aAdresses.clear();
273 : 0 : pImpl->nSelectedAddress = 0;
274 : 0 : UpdateScrollBar();
275 : 0 : }
276 : :
277 : 0 : void SwAddressPreview::ReplaceSelectedAddress(const ::rtl::OUString& rNew)
278 : : {
279 : 0 : pImpl->aAdresses[pImpl->nSelectedAddress] = rNew;
280 : 0 : Invalidate();
281 : 0 : }
282 : :
283 : 0 : void SwAddressPreview::RemoveSelectedAddress()
284 : : {
285 [ # # ][ # # ]: 0 : pImpl->aAdresses.erase(pImpl->aAdresses.begin() + pImpl->nSelectedAddress);
286 [ # # ]: 0 : if(pImpl->nSelectedAddress)
287 : 0 : --pImpl->nSelectedAddress;
288 : 0 : UpdateScrollBar();
289 : 0 : Invalidate();
290 : 0 : }
291 : :
292 : 0 : void SwAddressPreview::SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns)
293 : : {
294 : 0 : pImpl->nRows = nRows;
295 : 0 : pImpl->nColumns = nColumns;
296 : 0 : UpdateScrollBar();
297 : 0 : }
298 : :
299 : 0 : void SwAddressPreview::EnableScrollBar(bool bEnable)
300 : : {
301 : 0 : pImpl->bEnableScrollBar = bEnable;
302 : 0 : }
303 : :
304 : 0 : void SwAddressPreview::UpdateScrollBar()
305 : : {
306 [ # # ]: 0 : if(pImpl->nColumns)
307 : : {
308 : 0 : aVScrollBar.SetVisibleSize(pImpl->nRows);
309 : 0 : sal_uInt16 nResultingRows = (sal_uInt16)(pImpl->aAdresses.size() + pImpl->nColumns - 1) / pImpl->nColumns;
310 : 0 : ++nResultingRows;
311 [ # # ][ # # ]: 0 : aVScrollBar.Show(pImpl->bEnableScrollBar && nResultingRows > pImpl->nRows);
312 [ # # ]: 0 : aVScrollBar.SetRange(Range(0, nResultingRows));
313 [ # # ]: 0 : if(aVScrollBar.GetThumbPos() > nResultingRows)
314 : 0 : aVScrollBar.SetThumbPos(nResultingRows);
315 : : }
316 : 0 : }
317 : :
318 : 0 : void SwAddressPreview::Paint(const Rectangle&)
319 : : {
320 : 0 : const StyleSettings& rSettings = GetSettings().GetStyleSettings();
321 [ # # ]: 0 : SetFillColor(rSettings.GetWindowColor());
322 [ # # ]: 0 : SetLineColor( Color(COL_TRANSPARENT) );
323 [ # # ][ # # ]: 0 : DrawRect( Rectangle(Point(0, 0), GetOutputSizePixel()) );
324 [ # # ][ # # ]: 0 : Color aPaintColor(IsEnabled() ? rSettings.GetWindowTextColor() : rSettings.GetDisableColor());
325 [ # # ]: 0 : SetLineColor(aPaintColor);
326 [ # # ]: 0 : Font aFont(GetFont());
327 [ # # ]: 0 : aFont.SetColor(aPaintColor);
328 [ # # ]: 0 : SetFont(aFont);
329 : :
330 : 0 : Size aSize = GetOutputSizePixel();
331 : 0 : sal_uInt16 nStartRow = 0;
332 [ # # ][ # # ]: 0 : if(aVScrollBar.IsVisible())
333 : : {
334 [ # # ]: 0 : aSize.Width() -= aVScrollBar.GetSizePixel().Width();
335 : 0 : nStartRow = (sal_uInt16)aVScrollBar.GetThumbPos();
336 : : }
337 : 0 : Size aPartSize( aSize.Width()/pImpl->nColumns, aSize.Height()/pImpl->nRows );
338 : 0 : aPartSize.Width() -= 2;
339 : 0 : aPartSize.Height() -= 2;
340 : :
341 : 0 : sal_uInt16 nAddress = nStartRow * pImpl->nColumns;
342 : 0 : const sal_uInt16 nNumAddresses = static_cast< sal_uInt16 >(pImpl->aAdresses.size());
343 [ # # ]: 0 : for(sal_uInt16 nRow = 0; nRow < pImpl->nRows ; ++nRow)
344 : : {
345 [ # # ]: 0 : for(sal_uInt16 nCol = 0; nCol < pImpl->nColumns; ++nCol)
346 : : {
347 [ # # ]: 0 : if(nAddress >= nNumAddresses)
348 : : break;
349 : 0 : Point aPos(nCol * aPartSize.Width(), (nRow) * aPartSize.Height());
350 : 0 : aPos.Move(1,1);
351 : 0 : bool bIsSelected = nAddress == pImpl->nSelectedAddress;
352 [ # # ]: 0 : if((pImpl->nColumns * pImpl->nRows) == 1)
353 : 0 : bIsSelected = false;
354 : 0 : ::rtl::OUString adr(pImpl->aAdresses[nAddress]);
355 [ # # ]: 0 : DrawText_Impl(adr,aPos,aPartSize,bIsSelected);
356 : 0 : ++nAddress;
357 : 0 : }
358 : : }
359 [ # # ][ # # ]: 0 : SetClipRegion();
360 : 0 : }
361 : :
362 : 0 : void SwAddressPreview::MouseButtonDown( const MouseEvent& rMEvt )
363 : : {
364 : 0 : Window::MouseButtonDown(rMEvt);
365 [ # # ][ # # ]: 0 : if(rMEvt.IsLeft() && ( pImpl->nRows || pImpl->nColumns))
[ # # ][ # # ]
366 : : {
367 : : //determine the selected address
368 : 0 : const Point& rMousePos = rMEvt.GetPosPixel();
369 : 0 : Size aSize(GetOutputSizePixel());
370 : 0 : Size aPartSize( aSize.Width()/pImpl->nColumns, aSize.Height()/pImpl->nRows );
371 : 0 : sal_uInt32 nRow = rMousePos.Y() / aPartSize.Height() ;
372 [ # # ][ # # ]: 0 : if(aVScrollBar.IsVisible())
373 : : {
374 : 0 : nRow += (sal_uInt16)aVScrollBar.GetThumbPos();
375 : : }
376 : 0 : sal_uInt32 nCol = rMousePos.X() / aPartSize.Width();
377 : 0 : sal_uInt32 nSelect = nRow * pImpl->nColumns + nCol;
378 : :
379 [ # # ][ # # ]: 0 : if( nSelect < pImpl->aAdresses.size() &&
[ # # ]
380 : : pImpl->nSelectedAddress != (sal_uInt16)nSelect)
381 : : {
382 : 0 : pImpl->nSelectedAddress = (sal_uInt16)nSelect;
383 [ # # ]: 0 : m_aSelectHdl.Call(this);
384 : : }
385 [ # # ]: 0 : Invalidate();
386 : : }
387 : 0 : }
388 : :
389 : 0 : void SwAddressPreview::KeyInput( const KeyEvent& rKEvt )
390 : : {
391 : 0 : sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode();
392 [ # # ][ # # ]: 0 : if(pImpl->nRows || pImpl->nColumns)
393 : : {
394 : 0 : sal_uInt32 nSelectedRow = (pImpl->nSelectedAddress + 1)/ pImpl->nColumns;
395 : 0 : sal_uInt32 nSelectedColumn = pImpl->nSelectedAddress % nSelectedRow;
396 [ # # # # : 0 : switch(nKey)
# ]
397 : : {
398 : : case KEY_UP:
399 [ # # ]: 0 : if(nSelectedRow)
400 : 0 : --nSelectedRow;
401 : 0 : break;
402 : : case KEY_DOWN:
403 [ # # ]: 0 : if(pImpl->aAdresses.size() > sal_uInt32(pImpl->nSelectedAddress + pImpl->nColumns))
404 : 0 : ++nSelectedRow;
405 : 0 : break;
406 : : case KEY_LEFT:
407 [ # # ]: 0 : if(nSelectedColumn)
408 : 0 : --nSelectedColumn;
409 : 0 : break;
410 : : case KEY_RIGHT:
411 [ # # # # ]: 0 : if(nSelectedColumn < sal_uInt32(pImpl->nColumns - 1) &&
[ # # ]
412 : 0 : pImpl->aAdresses.size() - 1 > pImpl->nSelectedAddress )
413 : 0 : ++nSelectedColumn;
414 : 0 : break;
415 : : }
416 : 0 : sal_uInt32 nSelect = nSelectedRow * pImpl->nColumns + nSelectedColumn;
417 [ # # ][ # # ]: 0 : if( nSelect < pImpl->aAdresses.size() &&
[ # # ]
418 : : pImpl->nSelectedAddress != (sal_uInt16)nSelect)
419 : : {
420 : 0 : pImpl->nSelectedAddress = (sal_uInt16)nSelect;
421 : 0 : m_aSelectHdl.Call(this);
422 : 0 : Invalidate();
423 : 0 : }
424 : : }
425 : : else
426 : 0 : Window::KeyInput(rKEvt);
427 : 0 : }
428 : :
429 : 0 : void SwAddressPreview::StateChanged( StateChangedType nStateChange )
430 : : {
431 [ # # ]: 0 : if(nStateChange == STATE_CHANGE_ENABLE)
432 : 0 : Invalidate();
433 : 0 : Window::StateChanged(nStateChange);
434 : 0 : }
435 : :
436 : 0 : void SwAddressPreview::DrawText_Impl(
437 : : const ::rtl::OUString& rAddress, const Point& rTopLeft, const Size& rSize, bool bIsSelected)
438 : : {
439 [ # # ][ # # ]: 0 : SetClipRegion( Region( Rectangle(rTopLeft, rSize)) );
[ # # ][ # # ]
440 [ # # ]: 0 : if(bIsSelected)
441 : : {
442 : : //selection rectangle
443 [ # # ]: 0 : SetFillColor(Color(COL_TRANSPARENT));
444 [ # # ][ # # ]: 0 : DrawRect(Rectangle(rTopLeft, rSize));
445 : : }
446 [ # # ]: 0 : sal_Int32 nHeight = GetTextHeight();
447 [ # # ]: 0 : String sAddress(rAddress);
448 [ # # ][ # # ]: 0 : sal_uInt16 nTokens = comphelper::string::getTokenCount(sAddress, '\n');
449 : 0 : Point aStart = rTopLeft;
450 : : //put it away from the border
451 : 0 : aStart.Move( 2, 2);
452 [ # # ]: 0 : for(sal_uInt16 nToken = 0; nToken < nTokens; nToken++)
453 : : {
454 [ # # ][ # # ]: 0 : DrawText( aStart, sAddress.GetToken(nToken, '\n') );
[ # # ]
455 : 0 : aStart.Y() += nHeight;
456 [ # # ]: 0 : }
457 : 0 : }
458 : :
459 : 0 : String SwAddressPreview::FillData(
460 : : const ::rtl::OUString& rAddress,
461 : : SwMailMergeConfigItem& rConfigItem,
462 : : const Sequence< ::rtl::OUString>* pAssignments)
463 : : {
464 : : //find the column names in the address string (with name assignment!) and
465 : : //exchange the placeholder (like <Firstname>) with the database content
466 : : //unassigned columns are expanded to <not assigned>
467 [ # # ][ # # ]: 0 : Reference< XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), UNO_QUERY);
468 [ # # ][ # # ]: 0 : Reference <XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : 0;
[ # # ][ # # ]
469 : : Sequence< ::rtl::OUString> aAssignment = pAssignments ?
470 : : *pAssignments :
471 : : rConfigItem.GetColumnAssignment(
472 [ # # ][ # # ]: 0 : rConfigItem.GetCurrentDBData() );
[ # # ][ # # ]
473 : 0 : const ::rtl::OUString* pAssignment = aAssignment.getConstArray();
474 [ # # ]: 0 : const ResStringArray& rDefHeaders = rConfigItem.GetDefaultAddressHeaders();
475 [ # # ]: 0 : String sAddress(rAddress);
476 [ # # ]: 0 : String sNotAssigned(SW_RES(STR_NOTASSIGNED));
477 [ # # ]: 0 : sNotAssigned.Insert('<', 0);
478 [ # # ]: 0 : sNotAssigned += '>';
479 : :
480 [ # # ]: 0 : sal_Bool bIncludeCountry = rConfigItem.IsIncludeCountry();
481 [ # # ]: 0 : const ::rtl::OUString rExcludeCountry = rConfigItem.GetExcludeCountry();
482 [ # # ][ # # ]: 0 : bool bSpecialReplacementForCountry = (!bIncludeCountry || !rExcludeCountry.isEmpty());
483 [ # # ]: 0 : String sCountryColumn;
484 [ # # ]: 0 : if( bSpecialReplacementForCountry )
485 : : {
486 [ # # ][ # # ]: 0 : sCountryColumn = rDefHeaders.GetString(MM_PART_COUNTRY);
487 : : Sequence< ::rtl::OUString> aSpecialAssignment =
488 [ # # ][ # # ]: 0 : rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() );
489 [ # # ][ # # ]: 0 : if(aSpecialAssignment.getLength() > MM_PART_COUNTRY && aSpecialAssignment[MM_PART_COUNTRY].getLength())
[ # # ][ # # ]
490 [ # # ][ # # ]: 0 : sCountryColumn = aSpecialAssignment[MM_PART_COUNTRY];
[ # # ]
491 : : }
492 : :
493 [ # # ]: 0 : SwAddressIterator aIter(sAddress);
494 [ # # ]: 0 : sAddress.Erase();
495 [ # # ]: 0 : while(aIter.HasMore())
496 : : {
497 [ # # ]: 0 : SwMergeAddressItem aItem = aIter.Next();
498 [ # # ]: 0 : if(aItem.bIsColumn)
499 : : {
500 : : //get the default column name
501 : :
502 : : //find the appropriate assignment
503 [ # # ]: 0 : String sConvertedColumn = aItem.sText;
504 [ # # # # ]: 0 : for(sal_uInt16 nColumn = 0;
[ # # ]
505 : 0 : nColumn < rDefHeaders.Count() && nColumn < aAssignment.getLength();
506 : : ++nColumn)
507 : : {
508 [ # # ][ # # ]: 0 : if (rDefHeaders.GetString(nColumn).equals(aItem.sText) &&
[ # # # # ]
[ # # ][ # # ]
[ # # # #
# # ]
509 : 0 : !pAssignment[nColumn].isEmpty())
510 : : {
511 [ # # ]: 0 : sConvertedColumn = pAssignment[nColumn];
512 : 0 : break;
513 : : }
514 : : }
515 [ # # # # ]: 0 : if(sConvertedColumn.Len() &&
[ # # ][ # # ]
516 : 0 : xColAccess.is() &&
517 [ # # ][ # # ]: 0 : xColAccess->hasByName(sConvertedColumn))
[ # # ][ # # ]
[ # # ]
518 : : {
519 : : //get the content and exchange it in the address string
520 [ # # ][ # # ]: 0 : Any aCol = xColAccess->getByName(sConvertedColumn);
[ # # ]
521 : 0 : Reference< XColumn > xColumn;
522 [ # # ]: 0 : aCol >>= xColumn;
523 [ # # ]: 0 : if(xColumn.is())
524 : : {
525 : : try
526 : : {
527 [ # # ][ # # ]: 0 : ::rtl::OUString sReplace = xColumn->getString();
528 : :
529 [ # # ][ # # ]: 0 : if( bSpecialReplacementForCountry && sCountryColumn == sConvertedColumn )
[ # # ][ # # ]
530 : : {
531 [ # # ][ # # ]: 0 : if( !rExcludeCountry.isEmpty() && sReplace != rExcludeCountry )
[ # # ]
532 [ # # ]: 0 : aItem.sText = sReplace;
533 : : else
534 [ # # ]: 0 : aItem.sText.Erase();
535 : : }
536 : : else
537 : : {
538 [ # # ]: 0 : aItem.sText = sReplace;
539 [ # # ]: 0 : }
540 : : }
541 [ # # ]: 0 : catch (const sdbc::SQLException&)
542 : : {
543 : : OSL_FAIL("SQLException caught");
544 : : }
545 : 0 : }
546 : : }
547 : : else
548 : : {
549 [ # # ]: 0 : aItem.sText = sNotAssigned;
550 [ # # ]: 0 : }
551 : :
552 : : }
553 [ # # ]: 0 : sAddress += aItem.sText;
554 [ # # ]: 0 : }
555 [ # # ][ # # ]: 0 : return sAddress;
[ # # ][ # # ]
556 : : }
557 : :
558 : 0 : SwMergeAddressItem SwAddressIterator::Next()
559 : : {
560 : : //currently the string may either start with a '<' then it's a column
561 : : //otherwise it's simple text maybe containing a return
562 : 0 : SwMergeAddressItem aRet;
563 [ # # ]: 0 : if(sAddress.Len())
564 : : {
565 [ # # ]: 0 : if(sAddress.GetChar(0) == '<')
566 : : {
567 : 0 : aRet.bIsColumn = true;
568 [ # # ]: 0 : xub_StrLen nClose = sAddress.Search('>');
569 : : OSL_ENSURE(nClose != STRING_NOTFOUND, "closing '>' not found");
570 [ # # ]: 0 : if( nClose != STRING_NOTFOUND )
571 : : {
572 [ # # ][ # # ]: 0 : aRet.sText = sAddress.Copy(1, nClose - 1);
[ # # ]
573 [ # # ]: 0 : sAddress.Erase(0, nClose + 1);
574 : : }
575 : : else
576 : : {
577 [ # # ][ # # ]: 0 : aRet.sText = sAddress.Copy(1, 1);
[ # # ]
578 [ # # ]: 0 : sAddress.Erase(0, 1);
579 : : }
580 : : }
581 : : else
582 : : {
583 [ # # ]: 0 : xub_StrLen nOpen = sAddress.Search('<');
584 [ # # ]: 0 : xub_StrLen nReturn = sAddress.Search('\n');
585 [ # # ]: 0 : if(nReturn == 0)
586 : : {
587 : 0 : aRet.bIsReturn = true;
588 [ # # ]: 0 : aRet.sText = '\n';
589 [ # # ]: 0 : sAddress.Erase(0, 1);
590 : : }
591 [ # # ][ # # ]: 0 : else if(STRING_NOTFOUND == nOpen && STRING_NOTFOUND == nReturn)
592 : : {
593 : 0 : nOpen = sAddress.Len();
594 [ # # ]: 0 : aRet.sText = sAddress;
595 [ # # ]: 0 : sAddress.Erase();
596 : : }
597 : : else
598 : : {
599 [ # # ]: 0 : xub_StrLen nTarget = ::std::min(nOpen, nReturn);
600 [ # # ][ # # ]: 0 : aRet.sText = sAddress.Copy(0, nTarget);
[ # # ]
601 [ # # ]: 0 : sAddress.Erase(0, nTarget);
602 : : }
603 : : }
604 : : }
605 : 0 : return aRet;
606 : :
607 : : }
608 : :
609 : 0 : SwAuthenticator::~SwAuthenticator()
610 : : {
611 [ # # ]: 0 : }
612 : :
613 : 0 : OUString SwAuthenticator::getUserName( ) throw (RuntimeException)
614 : : {
615 : 0 : return m_aUserName;
616 : : }
617 : :
618 : 0 : OUString SwAuthenticator::getPassword( ) throw (RuntimeException)
619 : : {
620 [ # # ][ # # ]: 0 : if(!m_aUserName.isEmpty() && m_aPassword.isEmpty() && m_pParentWindow)
[ # # ][ # # ]
621 : : {
622 : : SfxPasswordDialog* pPasswdDlg =
623 [ # # ]: 0 : new SfxPasswordDialog( m_pParentWindow );
624 : 0 : pPasswdDlg->SetMinLen( 0 );
625 [ # # ]: 0 : if(RET_OK == pPasswdDlg->Execute())
626 [ # # ]: 0 : m_aPassword = pPasswdDlg->GetPassword();
627 : : }
628 : 0 : return m_aPassword;
629 : : }
630 : :
631 : 0 : SwConnectionContext::SwConnectionContext(
632 : : const ::rtl::OUString& rMailServer, sal_Int16 nPort,
633 : : const ::rtl::OUString& rConnectionType) :
634 : : m_sMailServer(rMailServer),
635 : : m_nPort(nPort),
636 : 0 : m_sConnectionType(rConnectionType)
637 : : {
638 : 0 : }
639 : :
640 : 0 : SwConnectionContext::~SwConnectionContext()
641 : : {
642 [ # # ]: 0 : }
643 : :
644 : 0 : uno::Any SwConnectionContext::getValueByName( const ::rtl::OUString& rName )
645 : : throw (uno::RuntimeException)
646 : : {
647 : 0 : uno::Any aRet;
648 [ # # ]: 0 : if( !rName.compareToAscii( "ServerName" ))
649 [ # # ]: 0 : aRet <<= m_sMailServer;
650 [ # # ]: 0 : else if( !rName.compareToAscii( "Port" ))
651 [ # # ]: 0 : aRet <<= (sal_Int32) m_nPort;
652 [ # # ]: 0 : else if( !rName.compareToAscii( "ConnectionType" ))
653 [ # # ]: 0 : aRet <<= m_sConnectionType;
654 : 0 : return aRet;
655 : : }
656 : :
657 [ # # ]: 0 : SwConnectionListener::~SwConnectionListener()
658 : : {
659 [ # # ]: 0 : }
660 : :
661 : 0 : void SwConnectionListener::connected(const lang::EventObject& /*aEvent*/)
662 : : throw (uno::RuntimeException)
663 : : {
664 : 0 : }
665 : :
666 : 0 : void SwConnectionListener::disconnected(const lang::EventObject& /*aEvent*/)
667 : : throw (uno::RuntimeException)
668 : : {
669 : 0 : }
670 : :
671 : 0 : void SwConnectionListener::disposing(const lang::EventObject& /*aEvent*/)
672 : : throw(uno::RuntimeException)
673 : : {
674 : 0 : }
675 : :
676 : 0 : uno::Reference< uno::XComponentContext> getCurrentCmpCtx(
677 : : uno::Reference<lang::XMultiServiceFactory> rSrvMgr)
678 : : {
679 : : uno::Reference< beans::XPropertySet > xPropSet =
680 [ # # ]: 0 : uno::Reference< beans::XPropertySet>(rSrvMgr, uno::UNO_QUERY);
681 [ # # ][ # # ]: 0 : Any aAny = xPropSet->getPropertyValue( ::rtl::OUString("DefaultContext"));
682 : 0 : uno::Reference< uno::XComponentContext> rCmpCtx;
683 [ # # ]: 0 : aAny >>= rCmpCtx;
684 : 0 : return rCmpCtx;
685 : : }
686 : :
687 : 0 : SwMailTransferable::SwMailTransferable(const rtl::OUString& rBody, const rtl::OUString& rMimeType) :
688 : : cppu::WeakComponentImplHelper2< datatransfer::XTransferable, beans::XPropertySet >(m_aMutex),
689 : : m_aMimeType( rMimeType ),
690 : : m_sBody( rBody ),
691 : 0 : m_bIsBody( true )
692 : : {
693 : 0 : }
694 : :
695 : 0 : SwMailTransferable::SwMailTransferable(const rtl::OUString& rURL,
696 : : const rtl::OUString& rName, const rtl::OUString& rMimeType) :
697 : : cppu::WeakComponentImplHelper2< datatransfer::XTransferable, beans::XPropertySet >(m_aMutex),
698 : : m_aMimeType( rMimeType ),
699 : : m_aURL(rURL),
700 : : m_aName( rName ),
701 : 0 : m_bIsBody( false )
702 : : {
703 : 0 : }
704 : :
705 [ # # ]: 0 : SwMailTransferable::~SwMailTransferable()
706 : : {
707 [ # # ]: 0 : }
708 : :
709 : 0 : uno::Any SwMailTransferable::getTransferData( const datatransfer::DataFlavor& /*aFlavor*/ )
710 : : throw (datatransfer::UnsupportedFlavorException,
711 : : io::IOException, uno::RuntimeException)
712 : : {
713 : 0 : uno::Any aRet;
714 [ # # ]: 0 : if( m_bIsBody )
715 [ # # ]: 0 : aRet <<= ::rtl::OUString(m_sBody);
716 : : else
717 : : {
718 [ # # ]: 0 : Sequence<sal_Int8> aData;
719 [ # # ][ # # ]: 0 : SfxMedium aMedium( m_aURL, STREAM_STD_READ );
[ # # ]
720 [ # # ]: 0 : SvStream* pStream = aMedium.GetInStream();
721 [ # # ][ # # ]: 0 : if ( aMedium.GetErrorCode() == ERRCODE_NONE && pStream)
[ # # ][ # # ]
722 : : {
723 [ # # ]: 0 : pStream->Seek(STREAM_SEEK_TO_END);
724 [ # # ]: 0 : aData.realloc(pStream->Tell());
725 [ # # ]: 0 : pStream->Seek(0);
726 [ # # ]: 0 : sal_Int8 * pData = aData.getArray();
727 [ # # ]: 0 : pStream->Read( pData, aData.getLength() );
728 : : }
729 [ # # ][ # # ]: 0 : aRet <<= aData;
[ # # ]
730 : : }
731 : 0 : return aRet;
732 : : }
733 : :
734 : 0 : uno::Sequence< datatransfer::DataFlavor > SwMailTransferable::getTransferDataFlavors( )
735 : : throw (uno::RuntimeException)
736 : : {
737 : 0 : uno::Sequence< datatransfer::DataFlavor > aRet(1);
738 [ # # ]: 0 : aRet[0].MimeType = m_aMimeType;
739 [ # # ]: 0 : if( m_bIsBody )
740 : : {
741 [ # # ][ # # ]: 0 : aRet[0].DataType = getCppuType((::rtl::OUString*)0);
742 : : }
743 : : else
744 : : {
745 [ # # ]: 0 : aRet[0].HumanPresentableName = m_aName;
746 [ # # ][ # # ]: 0 : aRet[0].DataType = getCppuType((uno::Sequence<sal_Int8>*)0);
747 : : }
748 : 0 : return aRet;
749 : : }
750 : :
751 : 0 : sal_Bool SwMailTransferable::isDataFlavorSupported(
752 : : const datatransfer::DataFlavor& aFlavor )
753 : : throw (uno::RuntimeException)
754 : : {
755 : 0 : return (aFlavor.MimeType == ::rtl::OUString(m_aMimeType));
756 : : }
757 : :
758 : 0 : uno::Reference< beans::XPropertySetInfo > SwMailTransferable::getPropertySetInfo( ) throw(uno::RuntimeException)
759 : : {
760 : 0 : return uno::Reference< beans::XPropertySetInfo >();
761 : : }
762 : :
763 : 0 : void SwMailTransferable::setPropertyValue( const ::rtl::OUString& , const uno::Any& )
764 : : throw(beans::UnknownPropertyException, beans::PropertyVetoException, lang::IllegalArgumentException,
765 : : lang::WrappedTargetException, uno::RuntimeException)
766 : : {
767 : 0 : }
768 : :
769 : 0 : uno::Any SwMailTransferable::getPropertyValue( const ::rtl::OUString& rPropertyName )
770 : : throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
771 : : {
772 : 0 : uno::Any aRet;
773 [ # # ]: 0 : if ( rPropertyName == "URL" )
774 [ # # ]: 0 : aRet <<= m_aURL;
775 : 0 : return aRet;
776 : : }
777 : :
778 : 0 : void SwMailTransferable::addPropertyChangeListener(
779 : : const ::rtl::OUString&, const uno::Reference< beans::XPropertyChangeListener >& )
780 : : throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
781 : : {
782 : 0 : }
783 : :
784 : 0 : void SwMailTransferable::removePropertyChangeListener(
785 : : const ::rtl::OUString&,
786 : : const uno::Reference< beans::XPropertyChangeListener >& )
787 : : throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
788 : : {
789 : 0 : }
790 : :
791 : 0 : void SwMailTransferable::addVetoableChangeListener(
792 : : const ::rtl::OUString&,
793 : : const uno::Reference< beans::XVetoableChangeListener >& )
794 : : throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
795 : : {
796 : 0 : }
797 : :
798 : 0 : void SwMailTransferable::removeVetoableChangeListener(
799 : : const ::rtl::OUString& ,
800 : : const uno::Reference< beans::XVetoableChangeListener >& )
801 : : throw(beans::UnknownPropertyException, lang::WrappedTargetException, uno::RuntimeException)
802 : : {
803 : 0 : }
804 : :
805 : 0 : SwMailMessage::SwMailMessage() :
806 [ # # ][ # # ]: 0 : cppu::WeakComponentImplHelper1< mail::XMailMessage>(m_aMutex)
[ # # ][ # # ]
807 : : {
808 : 0 : }
809 : :
810 [ # # ][ # # ]: 0 : SwMailMessage::~SwMailMessage()
[ # # ][ # # ]
[ # # ]
811 : : {
812 [ # # ]: 0 : }
813 : :
814 : 0 : ::rtl::OUString SwMailMessage::getSenderName() throw (uno::RuntimeException)
815 : : {
816 : 0 : return m_sSenderName;
817 : : }
818 : :
819 : 0 : ::rtl::OUString SwMailMessage::getSenderAddress() throw (uno::RuntimeException)
820 : : {
821 : 0 : return m_sSenderAddress;
822 : : }
823 : :
824 : 0 : ::rtl::OUString SwMailMessage::getReplyToAddress() throw (uno::RuntimeException)
825 : : {
826 : 0 : return m_sReplyToAddress;
827 : : }
828 : :
829 : 0 : void SwMailMessage::setReplyToAddress( const ::rtl::OUString& _replytoaddress ) throw (uno::RuntimeException)
830 : : {
831 : 0 : m_sReplyToAddress = _replytoaddress;
832 : 0 : }
833 : :
834 : 0 : ::rtl::OUString SwMailMessage::getSubject() throw (uno::RuntimeException)
835 : : {
836 : 0 : return m_sSubject;
837 : : }
838 : :
839 : 0 : void SwMailMessage::setSubject( const ::rtl::OUString& _subject ) throw (uno::RuntimeException)
840 : : {
841 : 0 : m_sSubject = _subject;
842 : 0 : }
843 : :
844 : 0 : uno::Reference< datatransfer::XTransferable > SwMailMessage::getBody() throw (uno::RuntimeException)
845 : : {
846 : 0 : return m_xBody;
847 : : }
848 : :
849 : 0 : void SwMailMessage::setBody(
850 : : const uno::Reference< datatransfer::XTransferable >& rBody )
851 : : throw (uno::RuntimeException)
852 : : {
853 : 0 : m_xBody = rBody;
854 : 0 : }
855 : :
856 : 0 : void SwMailMessage::addRecipient( const ::rtl::OUString& rRecipientAddress )
857 : : throw (uno::RuntimeException)
858 : : {
859 : 0 : m_aRecipients.realloc(m_aRecipients.getLength() + 1);
860 : 0 : m_aRecipients[m_aRecipients.getLength() - 1] = rRecipientAddress;
861 : 0 : }
862 : :
863 : 0 : void SwMailMessage::addCcRecipient( const ::rtl::OUString& rRecipientAddress )
864 : : throw (uno::RuntimeException)
865 : : {
866 : 0 : m_aCcRecipients.realloc(m_aCcRecipients.getLength() + 1);
867 : 0 : m_aCcRecipients[m_aCcRecipients.getLength() - 1] = rRecipientAddress;
868 : :
869 : 0 : }
870 : :
871 : 0 : void SwMailMessage::addBccRecipient( const ::rtl::OUString& rRecipientAddress ) throw (uno::RuntimeException)
872 : : {
873 : 0 : m_aBccRecipients.realloc(m_aBccRecipients.getLength() + 1);
874 : 0 : m_aBccRecipients[m_aBccRecipients.getLength() - 1] = rRecipientAddress;
875 : 0 : }
876 : :
877 : 0 : uno::Sequence< ::rtl::OUString > SwMailMessage::getRecipients( ) throw (uno::RuntimeException)
878 : : {
879 : 0 : return m_aRecipients;
880 : : }
881 : :
882 : 0 : uno::Sequence< ::rtl::OUString > SwMailMessage::getCcRecipients( ) throw (uno::RuntimeException)
883 : : {
884 : 0 : return m_aCcRecipients;
885 : : }
886 : :
887 : 0 : uno::Sequence< ::rtl::OUString > SwMailMessage::getBccRecipients( ) throw (uno::RuntimeException)
888 : : {
889 : 0 : return m_aBccRecipients;
890 : : }
891 : :
892 : 0 : void SwMailMessage::addAttachment( const mail::MailAttachment& rMailAttachment )
893 : : throw (uno::RuntimeException)
894 : : {
895 : 0 : m_aAttachments.realloc(m_aAttachments.getLength() + 1);
896 : 0 : m_aAttachments[m_aAttachments.getLength() - 1] = rMailAttachment;
897 : 0 : }
898 : :
899 : 0 : uno::Sequence< mail::MailAttachment > SwMailMessage::getAttachments( )
900 : : throw (uno::RuntimeException)
901 : : {
902 : 0 : return m_aAttachments;
903 : : }
904 : :
905 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|