/src/libreoffice/sw/source/uibase/dbui/mailmergehelper.cxx
Line | Count | Source |
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 | | |
20 | | #include <swtypes.hxx> |
21 | | #include <mailmergehelper.hxx> |
22 | | #include <mmconfigitem.hxx> |
23 | | #include <docsh.hxx> |
24 | | #include <comphelper/documentconstants.hxx> |
25 | | #include <sfx2/filedlghelper.hxx> |
26 | | #include <sfx2/docfile.hxx> |
27 | | #include <com/sun/star/sdbc/SQLException.hpp> |
28 | | #include <com/sun/star/sdbcx/XColumnsSupplier.hpp> |
29 | | #include <com/sun/star/sdb/XColumn.hpp> |
30 | | #include <com/sun/star/beans/XPropertySet.hpp> |
31 | | #include <com/sun/star/ui/dialogs/TemplateDescription.hpp> |
32 | | #include <com/sun/star/ui/dialogs/XFilePicker3.hpp> |
33 | | #include <com/sun/star/mail/MailServiceProvider.hpp> |
34 | | #include <com/sun/star/mail/XSmtpService.hpp> |
35 | | #include <comphelper/processfactory.hxx> |
36 | | #include <o3tl/safeint.hxx> |
37 | | #include <rtl/ustrbuf.hxx> |
38 | | #include <tools/stream.hxx> |
39 | | #include <utility> |
40 | | #include <vcl/event.hxx> |
41 | | #include <vcl/settings.hxx> |
42 | | #include <vcl/weld/weldutils.hxx> |
43 | | #include <comphelper/diagnose_ex.hxx> |
44 | | #include <o3tl/string_view.hxx> |
45 | | |
46 | | #include <sfx2/passwd.hxx> |
47 | | |
48 | | #include <dbui.hrc> |
49 | | #include <strings.hrc> |
50 | | |
51 | | using namespace ::com::sun::star; |
52 | | using namespace ::com::sun::star::uno; |
53 | | using namespace ::com::sun::star::container; |
54 | | using namespace ::com::sun::star::sdb; |
55 | | using namespace ::com::sun::star::sdbc; |
56 | | using namespace ::com::sun::star::sdbcx; |
57 | | |
58 | | namespace SwMailMergeHelper |
59 | | { |
60 | | |
61 | | OUString CallSaveAsDialog(weld::Window* pParent, OUString& rFilter) |
62 | 0 | { |
63 | 0 | ::sfx2::FileDialogHelper aDialog( ui::dialogs::TemplateDescription::FILESAVE_AUTOEXTENSION, |
64 | 0 | FileDialogFlags::NONE, |
65 | 0 | SwDocShell::Factory().GetFactoryName(), SfxFilterFlags::NONE, SfxFilterFlags::NONE, pParent); |
66 | 0 | aDialog.SetContext(sfx2::FileDialogHelper::WriterMailMergeSaveAs); |
67 | |
|
68 | 0 | if (aDialog.Execute()!=ERRCODE_NONE) |
69 | 0 | { |
70 | 0 | return OUString(); |
71 | 0 | } |
72 | | |
73 | 0 | rFilter = aDialog.GetRealFilter(); |
74 | 0 | uno::Reference < ui::dialogs::XFilePicker3 > xFP = aDialog.GetFilePicker(); |
75 | 0 | return xFP->getSelectedFiles().getConstArray()[0]; |
76 | 0 | } |
77 | | |
78 | | /* |
79 | | simple address check: check for '@' |
80 | | for at least one '.' after the '@', |
81 | | for at least one character before the dot |
82 | | and for at least two characters after the dot |
83 | | */ |
84 | | bool CheckMailAddress( std::u16string_view aMailAddress ) |
85 | 0 | { |
86 | 0 | const size_t nPosAt = aMailAddress.find('@'); |
87 | 0 | if (nPosAt == std::u16string_view::npos || aMailAddress.rfind('@')!=nPosAt) |
88 | 0 | return false; |
89 | 0 | const size_t nPosDot = aMailAddress.find('.', nPosAt); |
90 | 0 | return !(nPosDot==std::u16string_view::npos || nPosDot-nPosAt<2 || aMailAddress.size()-nPosDot<3); |
91 | 0 | } |
92 | | |
93 | | uno::Reference< mail::XSmtpService > ConnectToSmtpServer( |
94 | | SwMailMergeConfigItem const & rConfigItem, |
95 | | uno::Reference< mail::XMailService >& rxInMailService, |
96 | | const OUString& rInMailServerPassword, |
97 | | const OUString& rOutMailServerPassword, |
98 | | weld::Window* pDialogParentWindow ) |
99 | 0 | { |
100 | 0 | uno::Reference< mail::XSmtpService > xSmtpServer; |
101 | 0 | const uno::Reference< uno::XComponentContext >& xContext = ::comphelper::getProcessComponentContext(); |
102 | 0 | try |
103 | 0 | { |
104 | 0 | uno::Reference< mail::XMailServiceProvider > xMailServiceProvider( |
105 | 0 | mail::MailServiceProvider::create( xContext ) ); |
106 | 0 | xSmtpServer.set(xMailServiceProvider->create(mail::MailServiceType_SMTP), uno::UNO_QUERY); |
107 | |
|
108 | 0 | uno::Reference< mail::XConnectionListener> xConnectionListener(new SwConnectionListener); |
109 | |
|
110 | 0 | if(rConfigItem.IsAuthentication() && rConfigItem.IsSMTPAfterPOP()) |
111 | 0 | { |
112 | 0 | uno::Reference< mail::XMailService > xInMailService = |
113 | 0 | xMailServiceProvider->create( |
114 | 0 | rConfigItem.IsInServerPOP() ? |
115 | 0 | mail::MailServiceType_POP3 : mail::MailServiceType_IMAP); |
116 | | //authenticate at the POP or IMAP server first |
117 | 0 | OUString sPasswd = rConfigItem.GetInServerPassword(); |
118 | 0 | if(!rInMailServerPassword.isEmpty()) |
119 | 0 | sPasswd = rInMailServerPassword; |
120 | 0 | uno::Reference<mail::XAuthenticator> xAuthenticator = |
121 | 0 | new SwAuthenticator( |
122 | 0 | rConfigItem.GetInServerUserName(), |
123 | 0 | sPasswd, |
124 | 0 | pDialogParentWindow); |
125 | |
|
126 | 0 | xInMailService->addConnectionListener(xConnectionListener); |
127 | | //check connection |
128 | 0 | uno::Reference< uno::XCurrentContext> xConnectionContext = |
129 | 0 | new SwConnectionContext( |
130 | 0 | rConfigItem.GetInServerName(), |
131 | 0 | rConfigItem.GetInServerPort(), |
132 | 0 | u"Insecure"_ustr); |
133 | 0 | xInMailService->connect(xConnectionContext, xAuthenticator); |
134 | 0 | rxInMailService = std::move(xInMailService); |
135 | 0 | } |
136 | 0 | rtl::Reference<SwAuthenticator> xAuthenticator; |
137 | 0 | if(rConfigItem.IsAuthentication() && |
138 | 0 | !rConfigItem.IsSMTPAfterPOP() && |
139 | 0 | !rConfigItem.GetMailUserName().isEmpty()) |
140 | 0 | { |
141 | 0 | OUString sPasswd = rConfigItem.GetMailPassword(); |
142 | 0 | if(!rOutMailServerPassword.isEmpty()) |
143 | 0 | sPasswd = rOutMailServerPassword; |
144 | 0 | xAuthenticator = |
145 | 0 | new SwAuthenticator(rConfigItem.GetMailUserName(), |
146 | 0 | sPasswd, |
147 | 0 | pDialogParentWindow); |
148 | 0 | } |
149 | 0 | else |
150 | 0 | xAuthenticator = new SwAuthenticator(); |
151 | | //just to check if the server exists |
152 | 0 | xSmtpServer->getSupportedConnectionTypes(); |
153 | | //check connection |
154 | |
|
155 | 0 | uno::Reference< uno::XCurrentContext> xConnectionContext = |
156 | 0 | new SwConnectionContext( |
157 | 0 | rConfigItem.GetMailServer(), |
158 | 0 | rConfigItem.GetMailPort(), |
159 | 0 | rConfigItem.IsSecureConnection() ? u"Ssl"_ustr : u"Insecure"_ustr ); |
160 | 0 | xSmtpServer->connect(xConnectionContext, xAuthenticator); |
161 | 0 | rxInMailService = xSmtpServer; |
162 | 0 | } |
163 | 0 | catch (const uno::Exception&) |
164 | 0 | { |
165 | 0 | TOOLS_WARN_EXCEPTION( "sw", ""); |
166 | 0 | } |
167 | 0 | return xSmtpServer; |
168 | 0 | } |
169 | | |
170 | | } //namespace |
171 | | |
172 | | struct SwAddressPreview_Impl |
173 | | { |
174 | | std::vector< OUString > aAddresses; |
175 | | sal_uInt16 nRows; |
176 | | sal_uInt16 nColumns; |
177 | | sal_uInt16 nSelectedAddress; |
178 | | bool bEnableScrollBar; |
179 | | |
180 | | SwAddressPreview_Impl() : |
181 | 0 | nRows(1), |
182 | 0 | nColumns(1), |
183 | 0 | nSelectedAddress(0), |
184 | 0 | bEnableScrollBar(false) |
185 | 0 | { |
186 | 0 | } |
187 | | }; |
188 | | |
189 | | OUString SwAddressPreview::FillData( |
190 | | const OUString& rAddress, |
191 | | SwMailMergeConfigItem const & rConfigItem, |
192 | | const Sequence< OUString>* pAssignments) |
193 | 0 | { |
194 | | //find the column names in the address string (with name assignment!) and |
195 | | //exchange the placeholder (like <Firstname>) with the database content |
196 | | //unassigned columns are expanded to <not assigned> |
197 | 0 | Reference< XColumnsSupplier > xColsSupp( rConfigItem.GetResultSet(), UNO_QUERY); |
198 | 0 | Reference <XNameAccess> xColAccess = xColsSupp.is() ? xColsSupp->getColumns() : nullptr; |
199 | 0 | Sequence< OUString> aAssignment = pAssignments ? |
200 | 0 | *pAssignments : |
201 | 0 | rConfigItem.GetColumnAssignment( |
202 | 0 | rConfigItem.GetCurrentDBData() ); |
203 | 0 | const OUString* pAssignment = aAssignment.getConstArray(); |
204 | 0 | const std::vector<std::pair<OUString, int>>& rDefHeaders = rConfigItem.GetDefaultAddressHeaders(); |
205 | |
|
206 | 0 | bool bIncludeCountry = rConfigItem.IsIncludeCountry(); |
207 | 0 | const OUString& rExcludeCountry = rConfigItem.GetExcludeCountry(); |
208 | 0 | bool bSpecialReplacementForCountry = (!bIncludeCountry || !rExcludeCountry.isEmpty()); |
209 | 0 | OUString sCountryColumn; |
210 | 0 | if( bSpecialReplacementForCountry ) |
211 | 0 | { |
212 | 0 | sCountryColumn = rDefHeaders[MM_PART_COUNTRY].first; |
213 | 0 | Sequence< OUString> aSpecialAssignment = |
214 | 0 | rConfigItem.GetColumnAssignment( rConfigItem.GetCurrentDBData() ); |
215 | 0 | if(aSpecialAssignment.getLength() > MM_PART_COUNTRY && aSpecialAssignment[MM_PART_COUNTRY].getLength()) |
216 | 0 | sCountryColumn = aSpecialAssignment[MM_PART_COUNTRY]; |
217 | 0 | } |
218 | |
|
219 | 0 | SwAddressIterator aIter(rAddress); |
220 | 0 | OUStringBuffer sAddress; |
221 | 0 | while(aIter.HasMore()) |
222 | 0 | { |
223 | 0 | SwMergeAddressItem aItem = aIter.Next(); |
224 | 0 | if(aItem.bIsColumn) |
225 | 0 | { |
226 | | //get the default column name |
227 | | |
228 | | //find the appropriate assignment |
229 | 0 | OUString sConvertedColumn = aItem.sText; |
230 | 0 | auto nSize = std::min(sal_uInt32(rDefHeaders.size()), sal_uInt32(aAssignment.getLength())); |
231 | 0 | for(sal_uInt32 nColumn = 0; nColumn < nSize; ++nColumn) |
232 | 0 | { |
233 | 0 | if (rDefHeaders[nColumn].first == aItem.sText && |
234 | 0 | !pAssignment[nColumn].isEmpty()) |
235 | 0 | { |
236 | 0 | sConvertedColumn = pAssignment[nColumn]; |
237 | 0 | break; |
238 | 0 | } |
239 | 0 | } |
240 | 0 | if(!sConvertedColumn.isEmpty() && |
241 | 0 | xColAccess.is() && |
242 | 0 | xColAccess->hasByName(sConvertedColumn)) |
243 | 0 | { |
244 | | //get the content and exchange it in the address string |
245 | 0 | Any aCol = xColAccess->getByName(sConvertedColumn); |
246 | 0 | Reference< XColumn > xColumn; |
247 | 0 | aCol >>= xColumn; |
248 | 0 | if(xColumn.is()) |
249 | 0 | { |
250 | 0 | try |
251 | 0 | { |
252 | 0 | OUString sReplace = xColumn->getString(); |
253 | |
|
254 | 0 | if( bSpecialReplacementForCountry && sCountryColumn == sConvertedColumn ) |
255 | 0 | { |
256 | 0 | if( !rExcludeCountry.isEmpty() && sReplace != rExcludeCountry ) |
257 | 0 | aItem.sText = sReplace; |
258 | 0 | else |
259 | 0 | aItem.sText.clear(); |
260 | 0 | } |
261 | 0 | else |
262 | 0 | { |
263 | 0 | aItem.sText = sReplace; |
264 | 0 | } |
265 | 0 | } |
266 | 0 | catch (const sdbc::SQLException&) |
267 | 0 | { |
268 | 0 | TOOLS_WARN_EXCEPTION( "sw", ""); |
269 | 0 | } |
270 | 0 | } |
271 | 0 | } |
272 | 0 | else |
273 | 0 | { |
274 | 0 | aItem.sText = "<" + SwResId(STR_NOTASSIGNED) + ">"; |
275 | 0 | } |
276 | |
|
277 | 0 | } |
278 | 0 | sAddress.append(aItem.sText); |
279 | 0 | } |
280 | 0 | return sAddress.makeStringAndClear(); |
281 | 0 | } |
282 | | |
283 | | SwAddressPreview::SwAddressPreview(std::unique_ptr<weld::ScrolledWindow> xWindow) |
284 | 0 | : m_pImpl(new SwAddressPreview_Impl()) |
285 | 0 | , m_xVScrollBar(std::move(xWindow)) |
286 | 0 | { |
287 | 0 | m_xVScrollBar->connect_vadjustment_value_changed(LINK(this, SwAddressPreview, ScrollHdl)); |
288 | 0 | } |
289 | | |
290 | | SwAddressPreview::~SwAddressPreview() |
291 | 0 | { |
292 | 0 | } |
293 | | |
294 | | IMPL_LINK_NOARG(SwAddressPreview, ScrollHdl, weld::ScrolledWindow&, void) |
295 | 0 | { |
296 | 0 | Invalidate(); |
297 | 0 | } |
298 | | |
299 | | void SwAddressPreview::AddAddress(const OUString& rAddress) |
300 | 0 | { |
301 | 0 | m_pImpl->aAddresses.push_back(rAddress); |
302 | 0 | UpdateScrollBar(); |
303 | 0 | } |
304 | | |
305 | | void SwAddressPreview::SetAddress(const OUString& rAddress) |
306 | 0 | { |
307 | 0 | m_pImpl->aAddresses.clear(); |
308 | 0 | m_pImpl->aAddresses.push_back(rAddress); |
309 | 0 | m_xVScrollBar->set_vpolicy(VclPolicyType::NEVER); |
310 | 0 | Invalidate(); |
311 | 0 | } |
312 | | |
313 | | sal_uInt16 SwAddressPreview::GetSelectedAddress()const |
314 | 0 | { |
315 | 0 | OSL_ENSURE(m_pImpl->nSelectedAddress < m_pImpl->aAddresses.size(), "selection invalid"); |
316 | 0 | return m_pImpl->nSelectedAddress; |
317 | 0 | } |
318 | | |
319 | | void SwAddressPreview::SelectAddress(sal_uInt16 nSelect) |
320 | 0 | { |
321 | 0 | OSL_ENSURE(m_pImpl->nSelectedAddress < m_pImpl->aAddresses.size(), "selection invalid"); |
322 | 0 | m_pImpl->nSelectedAddress = nSelect; |
323 | | // now make it visible... |
324 | 0 | sal_uInt16 nSelectRow = nSelect / m_pImpl->nColumns; |
325 | 0 | sal_uInt16 nStartRow = m_xVScrollBar->vadjustment_get_value(); |
326 | 0 | if( (nSelectRow < nStartRow) || (nSelectRow >= (nStartRow + m_pImpl->nRows) )) |
327 | 0 | m_xVScrollBar->vadjustment_set_value(nSelectRow); |
328 | 0 | } |
329 | | |
330 | | void SwAddressPreview::Clear() |
331 | 0 | { |
332 | 0 | m_pImpl->aAddresses.clear(); |
333 | 0 | m_pImpl->nSelectedAddress = 0; |
334 | 0 | UpdateScrollBar(); |
335 | 0 | } |
336 | | |
337 | | void SwAddressPreview::ReplaceSelectedAddress(const OUString& rNew) |
338 | 0 | { |
339 | 0 | m_pImpl->aAddresses[m_pImpl->nSelectedAddress] = rNew; |
340 | 0 | Invalidate(); |
341 | 0 | } |
342 | | |
343 | | void SwAddressPreview::RemoveSelectedAddress() |
344 | 0 | { |
345 | 0 | m_pImpl->aAddresses.erase(m_pImpl->aAddresses.begin() + m_pImpl->nSelectedAddress); |
346 | 0 | if(m_pImpl->nSelectedAddress) |
347 | 0 | --m_pImpl->nSelectedAddress; |
348 | 0 | UpdateScrollBar(); |
349 | 0 | Invalidate(); |
350 | 0 | } |
351 | | |
352 | | void SwAddressPreview::SetLayout(sal_uInt16 nRows, sal_uInt16 nColumns) |
353 | 0 | { |
354 | 0 | m_pImpl->nRows = nRows; |
355 | 0 | m_pImpl->nColumns = nColumns; |
356 | 0 | UpdateScrollBar(); |
357 | 0 | } |
358 | | |
359 | | void SwAddressPreview::EnableScrollBar() |
360 | 0 | { |
361 | 0 | m_pImpl->bEnableScrollBar = true; |
362 | 0 | } |
363 | | |
364 | | void SwAddressPreview::UpdateScrollBar() |
365 | 0 | { |
366 | 0 | if (m_pImpl->nColumns) |
367 | 0 | { |
368 | 0 | sal_uInt16 nResultingRows = o3tl::narrowing<sal_uInt16>(m_pImpl->aAddresses.size() + m_pImpl->nColumns - 1) / m_pImpl->nColumns; |
369 | 0 | ++nResultingRows; |
370 | 0 | auto nValue = m_xVScrollBar->vadjustment_get_value(); |
371 | 0 | if (nValue > nResultingRows) |
372 | 0 | nValue = nResultingRows; |
373 | 0 | m_xVScrollBar->set_vpolicy(m_pImpl->bEnableScrollBar && nResultingRows > m_pImpl->nRows ? VclPolicyType::ALWAYS : VclPolicyType::NEVER); |
374 | 0 | m_xVScrollBar->vadjustment_configure(nValue, nResultingRows, 1, 10, m_pImpl->nRows); |
375 | 0 | } |
376 | 0 | } |
377 | | |
378 | | void SwAddressPreview::Paint(vcl::RenderContext& rRenderContext, const tools::Rectangle&) |
379 | 0 | { |
380 | 0 | const StyleSettings& rSettings = rRenderContext.GetSettings().GetStyleSettings(); |
381 | 0 | rRenderContext.SetFillColor(rSettings.GetWindowColor()); |
382 | 0 | rRenderContext.SetLineColor(COL_TRANSPARENT); |
383 | 0 | rRenderContext.DrawRect(tools::Rectangle(Point(0, 0), GetOutputSizePixel())); |
384 | 0 | Color aPaintColor(IsEnabled() ? rSettings.GetWindowTextColor() : rSettings.GetDisableColor()); |
385 | 0 | rRenderContext.SetLineColor(aPaintColor); |
386 | |
|
387 | 0 | weld::SetPointFont(rRenderContext, GetDrawingArea()->get_font()); |
388 | 0 | vcl::Font aFont(rRenderContext.GetFont()); |
389 | 0 | aFont.SetColor(IsEnabled() ? rSettings.GetWindowTextColor() |
390 | 0 | : rSettings.GetDisableTextColor()); |
391 | 0 | rRenderContext.SetFont(aFont); |
392 | |
|
393 | 0 | Size aSize(GetOutputSizePixel()); |
394 | 0 | sal_uInt16 nStartRow = 0; |
395 | 0 | if (m_xVScrollBar->get_vpolicy() != VclPolicyType::NEVER) |
396 | 0 | { |
397 | 0 | aSize.AdjustWidth(-m_xVScrollBar->get_scroll_thickness()); |
398 | 0 | nStartRow = m_xVScrollBar->vadjustment_get_value(); |
399 | 0 | } |
400 | 0 | Size aPartSize(aSize.Width() / m_pImpl->nColumns, |
401 | 0 | aSize.Height() / m_pImpl->nRows); |
402 | 0 | aPartSize.AdjustWidth( -2 ); |
403 | 0 | aPartSize.AdjustHeight( -2 ); |
404 | |
|
405 | 0 | sal_uInt16 nAddress = nStartRow * m_pImpl->nColumns; |
406 | 0 | const sal_uInt16 nNumAddresses = o3tl::narrowing<sal_uInt16>(m_pImpl->aAddresses.size()); |
407 | 0 | for (sal_uInt16 nRow = 0; nRow < m_pImpl->nRows ; ++nRow) |
408 | 0 | { |
409 | 0 | for (sal_uInt16 nCol = 0; nCol < m_pImpl->nColumns; ++nCol) |
410 | 0 | { |
411 | 0 | if (nAddress >= nNumAddresses) |
412 | 0 | break; |
413 | 0 | Point aPos(nCol * aPartSize.Width(), |
414 | 0 | nRow * aPartSize.Height()); |
415 | 0 | aPos.Move(1, 1); |
416 | 0 | bool bIsSelected = nAddress == m_pImpl->nSelectedAddress; |
417 | 0 | if ((m_pImpl->nColumns * m_pImpl->nRows) == 1) |
418 | 0 | bIsSelected = false; |
419 | 0 | OUString adr(m_pImpl->aAddresses[nAddress]); |
420 | 0 | DrawText_Impl(rRenderContext, adr, aPos, aPartSize, bIsSelected); |
421 | 0 | ++nAddress; |
422 | 0 | } |
423 | 0 | } |
424 | 0 | rRenderContext.SetClipRegion(); |
425 | 0 | } |
426 | | |
427 | | bool SwAddressPreview::MouseButtonDown( const MouseEvent& rMEvt ) |
428 | 0 | { |
429 | 0 | if (rMEvt.IsLeft() && m_pImpl->nRows && m_pImpl->nColumns) |
430 | 0 | { |
431 | | //determine the selected address |
432 | 0 | const Point& rMousePos = rMEvt.GetPosPixel(); |
433 | 0 | Size aSize(GetOutputSizePixel()); |
434 | 0 | Size aPartSize( aSize.Width()/m_pImpl->nColumns, aSize.Height()/m_pImpl->nRows ); |
435 | 0 | sal_uInt32 nRow = rMousePos.Y() / aPartSize.Height() ; |
436 | 0 | if (m_xVScrollBar->get_vpolicy() != VclPolicyType::NEVER) |
437 | 0 | { |
438 | 0 | nRow += m_xVScrollBar->vadjustment_get_value(); |
439 | 0 | } |
440 | 0 | sal_uInt32 nCol = rMousePos.X() / aPartSize.Width(); |
441 | 0 | sal_uInt32 nSelect = nRow * m_pImpl->nColumns + nCol; |
442 | |
|
443 | 0 | if( nSelect < m_pImpl->aAddresses.size() && |
444 | 0 | m_pImpl->nSelectedAddress != o3tl::narrowing<sal_uInt16>(nSelect)) |
445 | 0 | { |
446 | 0 | m_pImpl->nSelectedAddress = o3tl::narrowing<sal_uInt16>(nSelect); |
447 | 0 | m_aSelectHdl.Call(nullptr); |
448 | 0 | } |
449 | 0 | Invalidate(); |
450 | 0 | } |
451 | 0 | return true; |
452 | 0 | } |
453 | | |
454 | | bool SwAddressPreview::KeyInput( const KeyEvent& rKEvt ) |
455 | 0 | { |
456 | 0 | sal_uInt16 nKey = rKEvt.GetKeyCode().GetCode(); |
457 | 0 | bool bHandled = false; |
458 | 0 | if (m_pImpl->nRows && m_pImpl->nColumns) |
459 | 0 | { |
460 | 0 | sal_uInt32 nSelectedRow = m_pImpl->nSelectedAddress / m_pImpl->nColumns; |
461 | 0 | sal_uInt32 nSelectedColumn = m_pImpl->nSelectedAddress - (nSelectedRow * m_pImpl->nColumns); |
462 | 0 | switch(nKey) |
463 | 0 | { |
464 | 0 | case KEY_UP: |
465 | 0 | if(nSelectedRow) |
466 | 0 | --nSelectedRow; |
467 | 0 | bHandled = true; |
468 | 0 | break; |
469 | 0 | case KEY_DOWN: |
470 | 0 | if(m_pImpl->aAddresses.size() > o3tl::make_unsigned(m_pImpl->nSelectedAddress + m_pImpl->nColumns)) |
471 | 0 | ++nSelectedRow; |
472 | 0 | bHandled = true; |
473 | 0 | break; |
474 | 0 | case KEY_LEFT: |
475 | 0 | if(nSelectedColumn) |
476 | 0 | --nSelectedColumn; |
477 | 0 | bHandled = true; |
478 | 0 | break; |
479 | 0 | case KEY_RIGHT: |
480 | 0 | if(nSelectedColumn < o3tl::make_unsigned(m_pImpl->nColumns - 1) && |
481 | 0 | m_pImpl->aAddresses.size() - 1 > m_pImpl->nSelectedAddress ) |
482 | 0 | ++nSelectedColumn; |
483 | 0 | bHandled = true; |
484 | 0 | break; |
485 | 0 | } |
486 | 0 | sal_uInt32 nSelect = nSelectedRow * m_pImpl->nColumns + nSelectedColumn; |
487 | 0 | if( nSelect < m_pImpl->aAddresses.size() && |
488 | 0 | m_pImpl->nSelectedAddress != o3tl::narrowing<sal_uInt16>(nSelect)) |
489 | 0 | { |
490 | 0 | m_pImpl->nSelectedAddress = o3tl::narrowing<sal_uInt16>(nSelect); |
491 | 0 | m_aSelectHdl.Call(nullptr); |
492 | 0 | Invalidate(); |
493 | 0 | } |
494 | 0 | } |
495 | 0 | return bHandled; |
496 | 0 | } |
497 | | |
498 | | void SwAddressPreview::DrawText_Impl(vcl::RenderContext& rRenderContext, std::u16string_view rAddress, |
499 | | const Point& rTopLeft, const Size& rSize, bool bIsSelected) |
500 | 0 | { |
501 | 0 | rRenderContext.SetClipRegion(vcl::Region(tools::Rectangle(rTopLeft, rSize))); |
502 | 0 | if (bIsSelected) |
503 | 0 | { |
504 | | //selection rectangle |
505 | 0 | const StyleSettings& rSettings = rRenderContext.GetSettings().GetStyleSettings(); |
506 | 0 | rRenderContext.SetFillColor(rSettings.GetDialogColor()); |
507 | 0 | rRenderContext.DrawRect(tools::Rectangle(rTopLeft, rSize)); |
508 | 0 | } |
509 | 0 | sal_Int32 nHeight = GetTextHeight(); |
510 | 0 | Point aStart = rTopLeft; |
511 | | //put it away from the border |
512 | 0 | aStart.Move(2, 2); |
513 | 0 | sal_Int32 nPos = 0; |
514 | 0 | do |
515 | 0 | { |
516 | 0 | rRenderContext.DrawText(aStart, OUString(o3tl::getToken(rAddress, 0, '\n', nPos))); |
517 | 0 | aStart.AdjustY(nHeight ); |
518 | 0 | } |
519 | 0 | while (nPos >= 0); |
520 | 0 | } |
521 | | |
522 | | SwMergeAddressItem SwAddressIterator::Next() |
523 | 0 | { |
524 | | //currently the string may either start with a '<' then it's a column |
525 | | //otherwise it's simple text maybe containing a return |
526 | 0 | SwMergeAddressItem aRet; |
527 | 0 | if(!m_sAddress.isEmpty()) |
528 | 0 | { |
529 | 0 | if(m_sAddress[0] == '<') |
530 | 0 | { |
531 | 0 | aRet.bIsColumn = true; |
532 | 0 | sal_Int32 nClose = m_sAddress.indexOf('>'); |
533 | 0 | OSL_ENSURE(nClose != -1, "closing '>' not found"); |
534 | 0 | if( nClose != -1 ) |
535 | 0 | { |
536 | 0 | aRet.sText = m_sAddress.copy(1, nClose - 1); |
537 | 0 | m_sAddress = m_sAddress.copy(nClose + 1); |
538 | 0 | } |
539 | 0 | else |
540 | 0 | { |
541 | 0 | aRet.sText = m_sAddress.copy(1, 1); |
542 | 0 | m_sAddress = m_sAddress.copy(1); |
543 | 0 | } |
544 | 0 | } |
545 | 0 | else |
546 | 0 | { |
547 | 0 | sal_Int32 nOpen = m_sAddress.indexOf('<'); |
548 | 0 | sal_Int32 nReturn = m_sAddress.indexOf('\n'); |
549 | 0 | if(nReturn == 0) |
550 | 0 | { |
551 | 0 | aRet.bIsReturn = true; |
552 | 0 | aRet.sText = "\n"; |
553 | 0 | m_sAddress = m_sAddress.copy(1); |
554 | 0 | } |
555 | 0 | else if(-1 == nOpen && -1 == nReturn) |
556 | 0 | { |
557 | 0 | aRet.sText = m_sAddress; |
558 | 0 | m_sAddress.clear(); |
559 | 0 | } |
560 | 0 | else |
561 | 0 | { |
562 | 0 | if (nOpen == -1) |
563 | 0 | nOpen = m_sAddress.getLength(); |
564 | 0 | if (nReturn == -1) |
565 | 0 | nReturn = m_sAddress.getLength(); |
566 | 0 | sal_Int32 nTarget = std::min(nOpen, nReturn); |
567 | 0 | aRet.sText = m_sAddress.copy(0, nTarget); |
568 | 0 | m_sAddress = m_sAddress.copy(nTarget); |
569 | 0 | } |
570 | 0 | } |
571 | 0 | } |
572 | 0 | return aRet; |
573 | |
|
574 | 0 | } |
575 | | |
576 | | SwAuthenticator::~SwAuthenticator() |
577 | 0 | { |
578 | 0 | } |
579 | | |
580 | | OUString SwAuthenticator::getUserName( ) |
581 | 0 | { |
582 | 0 | return m_aUserName; |
583 | 0 | } |
584 | | |
585 | | OUString SwAuthenticator::getPassword( ) |
586 | 0 | { |
587 | 0 | if(!m_aUserName.isEmpty() && m_aPassword.isEmpty() && m_pParentWindow) |
588 | 0 | { |
589 | 0 | SfxPasswordDialog aPasswdDlg(m_pParentWindow); |
590 | 0 | aPasswdDlg.SetMinLen(0); |
591 | 0 | if (RET_OK == aPasswdDlg.run()) |
592 | 0 | m_aPassword = aPasswdDlg.GetPassword(); |
593 | 0 | } |
594 | 0 | return m_aPassword; |
595 | 0 | } |
596 | | |
597 | | SwConnectionContext::SwConnectionContext( |
598 | | OUString aMailServer, sal_Int16 nPort, |
599 | | OUString aConnectionType) : |
600 | 0 | m_sMailServer(std::move(aMailServer)), |
601 | 0 | m_nPort(nPort), |
602 | 0 | m_sConnectionType(std::move(aConnectionType)) |
603 | 0 | { |
604 | 0 | } |
605 | | |
606 | | SwConnectionContext::~SwConnectionContext() |
607 | 0 | { |
608 | 0 | } |
609 | | |
610 | | uno::Any SwConnectionContext::getValueByName( const OUString& rName ) |
611 | 0 | { |
612 | 0 | uno::Any aRet; |
613 | 0 | if( rName == "ServerName" ) |
614 | 0 | aRet <<= m_sMailServer; |
615 | 0 | else if( rName == "Port" ) |
616 | 0 | aRet <<= static_cast<sal_Int32>(m_nPort); |
617 | 0 | else if( rName == "ConnectionType" ) |
618 | 0 | aRet <<= m_sConnectionType; |
619 | 0 | return aRet; |
620 | 0 | } |
621 | | |
622 | | SwConnectionListener::~SwConnectionListener() |
623 | 0 | { |
624 | 0 | } |
625 | | |
626 | | void SwConnectionListener::connected(const lang::EventObject& /*aEvent*/) |
627 | 0 | { |
628 | 0 | } |
629 | | |
630 | | void SwConnectionListener::disconnected(const lang::EventObject& /*aEvent*/) |
631 | 0 | { |
632 | 0 | } |
633 | | |
634 | | void SwConnectionListener::disposing(const lang::EventObject& /*aEvent*/) |
635 | 0 | { |
636 | 0 | } |
637 | | |
638 | | SwMailTransferable::SwMailTransferable(OUString aBody, OUString aMimeType) : |
639 | 0 | m_aMimeType(std::move( aMimeType )), |
640 | 0 | m_sBody(std::move( aBody )), |
641 | 0 | m_bIsBody( true ) |
642 | 0 | { |
643 | 0 | } Unexecuted instantiation: SwMailTransferable::SwMailTransferable(rtl::OUString, rtl::OUString) Unexecuted instantiation: SwMailTransferable::SwMailTransferable(rtl::OUString, rtl::OUString) |
644 | | |
645 | | SwMailTransferable::SwMailTransferable(OUString aURL, |
646 | | OUString aName, OUString aMimeType) : |
647 | 0 | m_aMimeType(std::move( aMimeType )), |
648 | 0 | m_aURL(std::move(aURL)), |
649 | 0 | m_aName(std::move( aName )), |
650 | 0 | m_bIsBody( false ) |
651 | 0 | { |
652 | 0 | } Unexecuted instantiation: SwMailTransferable::SwMailTransferable(rtl::OUString, rtl::OUString, rtl::OUString) Unexecuted instantiation: SwMailTransferable::SwMailTransferable(rtl::OUString, rtl::OUString, rtl::OUString) |
653 | | |
654 | | SwMailTransferable::~SwMailTransferable() |
655 | 0 | { |
656 | 0 | } |
657 | | |
658 | | uno::Any SwMailTransferable::getTransferData( const datatransfer::DataFlavor& /*aFlavor*/ ) |
659 | 0 | { |
660 | 0 | uno::Any aRet; |
661 | 0 | if( m_bIsBody ) |
662 | 0 | aRet <<= m_sBody; |
663 | 0 | else |
664 | 0 | { |
665 | 0 | Sequence<sal_Int8> aData; |
666 | 0 | SfxMedium aMedium( m_aURL, StreamMode::STD_READ ); |
667 | 0 | SvStream* pStream = aMedium.GetInStream(); |
668 | 0 | if ( aMedium.GetErrorCode() == ERRCODE_NONE && pStream) |
669 | 0 | { |
670 | 0 | aData.realloc(pStream->TellEnd()); |
671 | 0 | pStream->Seek(0); |
672 | 0 | sal_Int8 * pData = aData.getArray(); |
673 | 0 | pStream->ReadBytes( pData, aData.getLength() ); |
674 | 0 | } |
675 | 0 | aRet <<= aData; |
676 | 0 | } |
677 | 0 | return aRet; |
678 | 0 | } |
679 | | |
680 | | uno::Sequence< datatransfer::DataFlavor > SwMailTransferable::getTransferDataFlavors( ) |
681 | 0 | { |
682 | 0 | datatransfer::DataFlavor aRet; |
683 | 0 | aRet.MimeType = m_aMimeType; |
684 | 0 | if( m_bIsBody ) |
685 | 0 | { |
686 | 0 | aRet.DataType = cppu::UnoType<OUString>::get(); |
687 | 0 | } |
688 | 0 | else |
689 | 0 | { |
690 | 0 | aRet.HumanPresentableName = m_aName; |
691 | 0 | aRet.DataType = cppu::UnoType<uno::Sequence<sal_Int8>>::get(); |
692 | 0 | } |
693 | 0 | return { std::move(aRet) }; |
694 | 0 | } |
695 | | |
696 | | sal_Bool SwMailTransferable::isDataFlavorSupported( |
697 | | const datatransfer::DataFlavor& aFlavor ) |
698 | 0 | { |
699 | 0 | return (aFlavor.MimeType == m_aMimeType); |
700 | 0 | } |
701 | | |
702 | | uno::Reference< beans::XPropertySetInfo > SwMailTransferable::getPropertySetInfo( ) |
703 | 0 | { |
704 | 0 | return uno::Reference< beans::XPropertySetInfo >(); |
705 | 0 | } |
706 | | |
707 | | void SwMailTransferable::setPropertyValue( const OUString& , const uno::Any& ) |
708 | 0 | { |
709 | 0 | } |
710 | | |
711 | | uno::Any SwMailTransferable::getPropertyValue( const OUString& rPropertyName ) |
712 | 0 | { |
713 | 0 | uno::Any aRet; |
714 | 0 | if ( rPropertyName == "URL" ) |
715 | 0 | aRet <<= m_aURL; |
716 | 0 | return aRet; |
717 | 0 | } |
718 | | |
719 | | void SwMailTransferable::addPropertyChangeListener( |
720 | | const OUString&, const uno::Reference< beans::XPropertyChangeListener >& ) |
721 | 0 | { |
722 | 0 | } |
723 | | |
724 | | void SwMailTransferable::removePropertyChangeListener( |
725 | | const OUString&, |
726 | | const uno::Reference< beans::XPropertyChangeListener >& ) |
727 | 0 | { |
728 | 0 | } |
729 | | |
730 | | void SwMailTransferable::addVetoableChangeListener( |
731 | | const OUString&, |
732 | | const uno::Reference< beans::XVetoableChangeListener >& ) |
733 | 0 | { |
734 | 0 | } |
735 | | |
736 | | void SwMailTransferable::removeVetoableChangeListener( |
737 | | const OUString& , |
738 | | const uno::Reference< beans::XVetoableChangeListener >& ) |
739 | 0 | { |
740 | 0 | } |
741 | | |
742 | | SwMailMessage::SwMailMessage() |
743 | 0 | { |
744 | 0 | } Unexecuted instantiation: SwMailMessage::SwMailMessage() Unexecuted instantiation: SwMailMessage::SwMailMessage() |
745 | | |
746 | | SwMailMessage::~SwMailMessage() |
747 | 0 | { |
748 | 0 | } |
749 | | |
750 | | OUString SwMailMessage::getSenderName() |
751 | 0 | { |
752 | 0 | return m_sSenderName; |
753 | 0 | } |
754 | | |
755 | | OUString SwMailMessage::getSenderAddress() |
756 | 0 | { |
757 | 0 | return m_sSenderAddress; |
758 | 0 | } |
759 | | |
760 | | OUString SwMailMessage::getReplyToAddress() |
761 | 0 | { |
762 | 0 | return m_sReplyToAddress; |
763 | 0 | } |
764 | | |
765 | | void SwMailMessage::setReplyToAddress( const OUString& _replytoaddress ) |
766 | 0 | { |
767 | 0 | m_sReplyToAddress = _replytoaddress; |
768 | 0 | } |
769 | | |
770 | | OUString SwMailMessage::getSubject() |
771 | 0 | { |
772 | 0 | return m_sSubject; |
773 | 0 | } |
774 | | |
775 | | void SwMailMessage::setSubject( const OUString& _subject ) |
776 | 0 | { |
777 | 0 | m_sSubject = _subject; |
778 | 0 | } |
779 | | |
780 | | uno::Reference< datatransfer::XTransferable > SwMailMessage::getBody() |
781 | 0 | { |
782 | 0 | return m_xBody; |
783 | 0 | } |
784 | | |
785 | | void SwMailMessage::setBody( |
786 | | const uno::Reference< datatransfer::XTransferable >& rBody ) |
787 | 0 | { |
788 | 0 | m_xBody = rBody; |
789 | 0 | } |
790 | | |
791 | | void SwMailMessage::addRecipient( const OUString& rRecipientAddress ) |
792 | 0 | { |
793 | 0 | m_aRecipients.realloc(m_aRecipients.getLength() + 1); |
794 | 0 | m_aRecipients.getArray()[m_aRecipients.getLength() - 1] = rRecipientAddress; |
795 | 0 | } |
796 | | |
797 | | void SwMailMessage::addCcRecipient( const OUString& rRecipientAddress ) |
798 | 0 | { |
799 | 0 | m_aCcRecipients.realloc(m_aCcRecipients.getLength() + 1); |
800 | 0 | m_aCcRecipients.getArray()[m_aCcRecipients.getLength() - 1] = rRecipientAddress; |
801 | |
|
802 | 0 | } |
803 | | |
804 | | void SwMailMessage::addBccRecipient( const OUString& rRecipientAddress ) |
805 | 0 | { |
806 | 0 | m_aBccRecipients.realloc(m_aBccRecipients.getLength() + 1); |
807 | 0 | m_aBccRecipients.getArray()[m_aBccRecipients.getLength() - 1] = rRecipientAddress; |
808 | 0 | } |
809 | | |
810 | | uno::Sequence< OUString > SwMailMessage::getRecipients( ) |
811 | 0 | { |
812 | 0 | return m_aRecipients; |
813 | 0 | } |
814 | | |
815 | | uno::Sequence< OUString > SwMailMessage::getCcRecipients( ) |
816 | 0 | { |
817 | 0 | return m_aCcRecipients; |
818 | 0 | } |
819 | | |
820 | | uno::Sequence< OUString > SwMailMessage::getBccRecipients( ) |
821 | 0 | { |
822 | 0 | return m_aBccRecipients; |
823 | 0 | } |
824 | | |
825 | | void SwMailMessage::addAttachment( const mail::MailAttachment& rMailAttachment ) |
826 | 0 | { |
827 | 0 | m_aAttachments.realloc(m_aAttachments.getLength() + 1); |
828 | 0 | m_aAttachments.getArray()[m_aAttachments.getLength() - 1] = rMailAttachment; |
829 | 0 | } |
830 | | |
831 | | uno::Sequence< mail::MailAttachment > SwMailMessage::getAttachments( ) |
832 | 0 | { |
833 | 0 | return m_aAttachments; |
834 | 0 | } |
835 | | |
836 | | /* vim:set shiftwidth=4 softtabstop=4 expandtab: */ |