LibreOffice Module sw (master)  1
mmconfigitem.cxx
Go to the documentation of this file.
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 
21 #include <mmconfigitem.hxx>
23 #include <vector>
24 #include <swtypes.hxx>
25 #include <com/sun/star/uno/Any.hxx>
26 #include <com/sun/star/beans/PropertyValue.hpp>
27 #include <com/sun/star/frame/XDispatch.hpp>
28 #include <com/sun/star/sdbc/XDataSource.hpp>
29 #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
30 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
31 #include <com/sun/star/beans/XPropertySet.hpp>
32 #include <com/sun/star/sdbc/XRowSet.hpp>
33 #include <com/sun/star/view/XSelectionSupplier.hpp>
35 #include <comphelper/types.hxx>
36 #include <com/sun/star/sdb/CommandType.hpp>
37 #include <comphelper/sequence.hxx>
38 #include <rtl/ustrbuf.hxx>
39 #include <sal/log.hxx>
40 #include <unotools/configitem.hxx>
41 #include <tools/diagnose_ex.h>
42 #include <mailmergehelper.hxx>
43 #include <swunohelper.hxx>
44 #include <dbmgr.hxx>
45 #include <view.hxx>
46 #include <unodispatch.hxx>
47 #include <wrtsh.hxx>
48 #include <dbui.hrc>
49 
50 using namespace utl;
51 using namespace ::com::sun::star;
52 using namespace ::com::sun::star::uno;
53 using namespace ::com::sun::star::lang;
54 using namespace ::com::sun::star::beans;
55 using namespace ::com::sun::star::sdb;
56 using namespace ::com::sun::star::sdbc;
57 using namespace ::com::sun::star::sdbcx;
58 
59 constexpr OUStringLiteral cAddressDataAssignments = u"AddressDataAssignments";
60 const char cDBColumnAssignments[] = "DBColumnAssignments";
61 const char cDataSourceName[] = "DataSource/DataSourceName";
62 const char cDataTableName[] = "DataSource/DataTableName" ;
63 const char cDataCommandType[] = "DataSource/DataCommandType";
64 
65 #define SECURE_PORT 587
66 #define DEFAULT_PORT 25
67 #define POP_PORT 110
68 #define POP_SECURE_PORT 995
69 #define IMAP_PORT 143
70 #define IMAP_SECURE_PORT 993
71 
72 namespace {
73 
74 struct DBAddressDataAssignment
75 {
76  SwDBData aDBData;
77  Sequence< OUString> aDBColumnAssignments;
78  //if loaded the name of the node has to be saved
79  OUString sConfigNodeName;
80  //all created or changed assignments need to be stored
81  bool bColumnAssignmentsChanged;
82 
83  DBAddressDataAssignment() :
84  bColumnAssignmentsChanged(false)
85  {}
86 };
87 
88 }
89 
91 {
92  friend class SwMailMergeConfigItem;
95  Reference< XColumnsSupplier> m_xColumnsSupplier;
96  Reference< XResultSet> m_xResultSet;
98  OUString m_sFilter;
100 
101  std::vector<DBAddressDataAssignment> m_aAddressDataAssignments;
102  std::vector< OUString> m_aAddressBlocks;
106 
110 
113  std::vector< OUString> m_aFemaleGreetingLines;
115  std::vector< OUString> m_aMaleGreetingLines;
117  std::vector< OUString> m_aNeutralGreetingLines;
120  uno::Sequence< OUString> m_aSavedDocuments;
121 
124 
125  //mail settings
127  OUString m_sMailAddress;
128  OUString m_sMailReplyTo;
129  OUString m_sMailServer;
130  OUString m_sMailUserName;
131  OUString m_sMailPassword;
132 
134  OUString m_sInServerName;
135  sal_Int16 m_nInServerPort;
139 
140  sal_Int16 m_nMailPort;
144 
146 
147  std::vector<std::pair<OUString, int>> m_AddressHeaderSA;
148 
149  //these addresses are not stored in the configuration
150  std::vector< SwDocMergeInfo > m_aMergeInfos;
151 
152  //we do overwrite the usersettings in a special case
153  //then we do remind the usersettings here
158 
159  static const Sequence< OUString>& GetPropertyNames();
160 
161  virtual void ImplCommit() override;
162 
163 public:
165 
166  virtual void Notify( const css::uno::Sequence< OUString >& aPropertyNames ) override;
167  Sequence< OUString> GetAddressBlocks(bool bConvertToConfig = false) const;
168  void SetAddressBlocks(
169  const Sequence< OUString>& rBlocks,
170  bool bConvertFromConfig = false);
171  uno::Sequence< OUString>
173  bool bConvertToConfig = false) const;
175  const uno::Sequence< OUString>& rBlocks,
176  bool bConvertFromConfig = false);
177 
178  void SetCurrentAddressBlockIndex( sal_Int32 nSet );
179  sal_Int32 GetCurrentAddressBlockIndex() const
180  { return m_nCurrentAddressBlock; }
181  sal_Int32 GetCurrentGreeting(SwMailMergeConfigItem::Gender eType) const;
182  void SetCurrentGreeting(SwMailMergeConfigItem::Gender eType, sal_Int32 nIndex);
183 
184 };
185 
187  ConfigItem("Office.Writer/MailMergeWizard", ConfigItemMode::NONE),
188  m_nResultSetCursorPos(-1),
189  m_nCurrentAddressBlock(0),
190  m_bIsAddressBlock(true),
191  m_bIsHideEmptyParagraphs(false),
192  m_bIsOutputToLetter(true),
193  m_bIncludeCountry(false),
194  m_bIsGreetingLine(true),
195  m_bIsIndividualGreetingLine(false),
196  m_nCurrentFemaleGreeting(0),
197  m_nCurrentMaleGreeting(0),
198  m_nCurrentNeutralGreeting(0),
199  m_bIsGreetingLineInMail(false),
200  m_bIsIndividualGreetingLineInMail(false),
201  m_bIsSMPTAfterPOP(false),
202  m_nInServerPort( POP_SECURE_PORT ),
203  m_bInServerPOP( true ),
204  m_nMailPort(SECURE_PORT),
205  m_bIsMailReplyTo(false),
206  m_bIsSecureConnection(true),
207  m_bIsAuthentication(false),
208 
209  m_bIsEMailSupported(false),
210  m_bUserSettingWereOverwritten(false),
211  m_bIsAddressBlock_LastUserSetting(false),
212  m_bIsGreetingLineInMail_LastUserSetting(false),
213  m_bIsGreetingLine_LastUserSetting(false)
214 {
215  for (size_t i = 0; i < SAL_N_ELEMENTS(SA_ADDRESS_HEADER); ++i)
216  {
217  m_AddressHeaderSA.emplace_back(SwResId(SA_ADDRESS_HEADER[i].first), SA_ADDRESS_HEADER[i].second);
218  }
219 
220  const Sequence<OUString>& rNames = GetPropertyNames();
221  Sequence<Any> aValues = GetProperties(rNames);
222  const Any* pValues = aValues.getConstArray();
223  assert(aValues.getLength() == rNames.getLength());
224  if(aValues.getLength() == rNames.getLength())
225  {
226  for(int nProp = 0; nProp < rNames.getLength(); nProp++)
227  {
228  switch(nProp)
229  {
230  case 0: pValues[nProp] >>= m_bIsOutputToLetter; break;
231  case 1: pValues[nProp] >>= m_bIncludeCountry; break;
232  case 2: pValues[nProp] >>= m_sExcludeCountry; break;
233  case 3:
234  {
235  Sequence< OUString> aBlocks;
236  pValues[nProp] >>= aBlocks;
237  SetAddressBlocks(aBlocks, true);
238  }
239  break;
240  case 4: pValues[nProp] >>= m_bIsAddressBlock; break;
241  case 5: pValues[nProp] >>= m_bIsGreetingLine; break;
242  case 6: pValues[nProp] >>= m_bIsIndividualGreetingLine; break;
243  case 7 :
244  case 8 :
245  case 9 :
246  {
247  Sequence< OUString> aGreetings;
248  pValues[nProp] >>= aGreetings;
250  SwMailMergeConfigItem::FEMALE + nProp - 7), aGreetings, true);
251  }
252  break;
253 
254  case 10: pValues[nProp] >>= m_nCurrentFemaleGreeting; break;
255  case 11: pValues[nProp] >>= m_nCurrentMaleGreeting; break;
256  case 12: pValues[nProp] >>= m_nCurrentNeutralGreeting; break;
257  case 13: pValues[nProp] >>= m_sFemaleGenderValue; break;
258  case 14: pValues[nProp] >>= m_sMailDisplayName; break;
259  case 15: pValues[nProp] >>= m_sMailAddress; break;
260  case 16: pValues[nProp] >>= m_bIsMailReplyTo; break;
261  case 17: pValues[nProp] >>= m_sMailReplyTo; break;
262  case 18: pValues[nProp] >>= m_sMailServer; break;
263  case 19: pValues[nProp] >>= m_nMailPort; break;
264  case 20: pValues[nProp] >>= m_bIsSecureConnection; break;
265  case 21: pValues[nProp] >>= m_bIsAuthentication; break;
266  case 22: pValues[nProp] >>= m_sMailUserName; break;
267  case 23: pValues[nProp] >>= m_sMailPassword; break;
268  case 24 :pValues[nProp] >>= m_aDBData.sDataSource; break;
269  case 25 :pValues[nProp] >>= m_aDBData.sCommand; break;
270  case 26 :
271  {
272  short nTemp = 0;
273  if(pValues[nProp] >>= nTemp)
274  m_aDBData.nCommandType = nTemp;
275  }
276  break;
277  case 27: pValues[nProp] >>= m_sFilter; break;
278  case 28: pValues[nProp] >>= m_aSavedDocuments; break;
279  case 29:
280  pValues[nProp] >>= m_bIsEMailSupported;
281  break;
282  case 30: pValues[nProp] >>= m_bIsGreetingLineInMail; break;
283  case 31: pValues[nProp] >>= m_bIsIndividualGreetingLineInMail; break;
284  case 32: pValues[nProp] >>= m_bIsSMPTAfterPOP; break;
285  case 33: pValues[nProp] >>= m_sInServerName; break;
286  case 34: pValues[nProp] >>= m_nInServerPort; break;
287  case 35: pValues[nProp] >>= m_bInServerPOP; break;
288  case 36: pValues[nProp] >>= m_sInServerUserName; break;
289  case 37: pValues[nProp] >>= m_sInServerPassword; break;
290  case 38: pValues[nProp] >>= m_bIsHideEmptyParagraphs; break;
291  case 39: pValues[nProp] >>= m_nCurrentAddressBlock; break;
292  }
293  }
294  ClearModified();
295  }
296  //read the list of data base assignments
298  if(aAssignments.hasElements())
299  {
300  //create a list of property names to load the URLs of all data bases
301  const OUString* pAssignments = aAssignments.getConstArray();
302  Sequence< OUString > aAssignProperties(4 * aAssignments.getLength());
303  OUString* pAssignProperties = aAssignProperties.getArray();
304  sal_Int32 nAssign;
305  for(nAssign = 0; nAssign < aAssignProperties.getLength(); nAssign += 4)
306  {
307  OUString sAssignPath = OUString::Concat(cAddressDataAssignments) +
308  "/" +
309  pAssignments[nAssign / 4] +
310  "/";
311  pAssignProperties[nAssign] = sAssignPath;
312  pAssignProperties[nAssign] += cDataSourceName;
313  pAssignProperties[nAssign + 1] = sAssignPath;
314  pAssignProperties[nAssign + 1] += cDataTableName;
315  pAssignProperties[nAssign + 2] = sAssignPath;
316  pAssignProperties[nAssign + 2] += cDataCommandType;
317  pAssignProperties[nAssign + 3] = sAssignPath;
318  pAssignProperties[nAssign + 3] += cDBColumnAssignments;
319  }
320  Sequence<Any> aAssignValues = GetProperties(aAssignProperties);
321  const Any* pAssignValues = aAssignValues.getConstArray();
322  for(nAssign = 0; nAssign < aAssignValues.getLength(); nAssign += 4 )
323  {
324  DBAddressDataAssignment aAssignment;
325  pAssignValues[nAssign] >>= aAssignment.aDBData.sDataSource;
326  pAssignValues[nAssign + 1] >>= aAssignment.aDBData.sCommand;
327  pAssignValues[nAssign + 2] >>= aAssignment.aDBData.nCommandType;
328  pAssignValues[nAssign + 3] >>= aAssignment.aDBColumnAssignments;
329  aAssignment.sConfigNodeName = pAssignments[nAssign / 4];
330  m_aAddressDataAssignments.push_back(aAssignment);
331  }
332  }
333  //check if the saved documents still exist
334  if(!m_aSavedDocuments.hasElements())
335  return;
336 
337  uno::Sequence< OUString > aTempDocuments(m_aSavedDocuments.getLength());
338  auto begin = aTempDocuments.getArray();
339  OUString* pTempDocuments = std::copy_if(std::cbegin(m_aSavedDocuments), std::cend(m_aSavedDocuments), begin,
340  [](const OUString& rDoc) { return SWUnoHelper::UCB_IsFile( rDoc ); });
341  sal_Int32 nIndex = static_cast<sal_Int32>(std::distance(begin, pTempDocuments));
342  if(nIndex < m_aSavedDocuments.getLength())
343  {
344  m_aSavedDocuments.swap(aTempDocuments);
345  m_aSavedDocuments.realloc(nIndex);
346  }
347 }
348 
350 {
351  if(m_aAddressBlocks.size() >= sal::static_int_cast<sal_uInt32, sal_Int32>(nSet))
352  {
353  m_nCurrentAddressBlock = nSet;
354  SetModified();
355  }
356 }
357 
358 static OUString lcl_CreateNodeName(Sequence<OUString>& rAssignments )
359 {
360  sal_Int32 nStart = rAssignments.getLength();
361  OUString sNewName;
362  //search if the name exists
363  while(true)
364  {
365  sNewName = "_" + OUString::number(nStart++);
366  if(comphelper::findValue(rAssignments, sNewName) == -1)
367  break;
368  }
369  // add the new name to the array of existing names
370  rAssignments.realloc(rAssignments.getLength() + 1);
371  rAssignments.getArray()[rAssignments.getLength() - 1] = sNewName;
372  return sNewName;
373 }
374 
375 static void lcl_ConvertToNumbers(OUString& rBlock, const std::vector<std::pair<OUString, int>>& rHeaders )
376 {
377  //convert the strings used for UI to numbers used for the configuration
378  OUString sBlock(rBlock.replaceAll("\n", "\\n"));
379  for (size_t i = 0; i < rHeaders.size(); ++i)
380  {
381  OUString sHeader = "<" + rHeaders[i].first + ">";
382  OUString sReplace = "<" + OUStringChar(sal_Unicode('0' + i)) + ">";
383  sBlock = sBlock.replaceAll(sHeader, sReplace);
384  }
385  rBlock = sBlock;
386 }
387 
388 static void lcl_ConvertFromNumbers(OUString& rBlock, const std::vector<std::pair<OUString, int>>& rHeaders)
389 {
390  //convert the numbers used for the configuration to strings used for UI to numbers
391  //doesn't use ReplaceAll to prevent expansion of numbers inside of the headers
392  SwAddressIterator aGreetingIter(rBlock.replaceAll("\\n", "\n"));
393  OUStringBuffer sBlock;
394  while(aGreetingIter.HasMore())
395  {
396  SwMergeAddressItem aNext = aGreetingIter.Next();
397  if(aNext.bIsColumn)
398  {
399  //the text should be 1 characters long
400  sal_Unicode cChar = aNext.sText[0];
401  if(cChar >= '0' && cChar <= 'c')
402  {
403  sBlock.append("<");
404  sal_uInt16 nHeader = cChar - '0';
405  if(nHeader < rHeaders.size())
406  sBlock.append(rHeaders[nHeader].first);
407  sBlock.append(">");
408  }
409  else
410  {
411  SAL_WARN("sw.ui", "parse error in address block or greeting line");
412  }
413  }
414  else
415  sBlock.append(aNext.sText);
416  }
417  rBlock = sBlock.makeStringAndClear();
418 }
419 
421 {
422  static Sequence<OUString> aNames {
423  "OutputToLetter", // 0
424  "IncludeCountry", // 1
425  "ExcludeCountry", // 2
426  "AddressBlockSettings", // 3
427  "IsAddressBlock", // 4
428  "IsGreetingLine", // 5
429  "IsIndividualGreetingLine", // 6
430  "FemaleGreetingLines", // 7
431  "MaleGreetingLines", // 8
432  "NeutralGreetingLines", // 9
433  "CurrentFemaleGreeting", // 10
434  "CurrentMaleGreeting", // 11
435  "CurrentNeutralGreeting", // 12
436  "FemaleGenderValue", // 13
437  "MailDisplayName", // 14
438  "MailAddress", // 15
439  "IsMailReplyTo", // 16
440  "MailReplyTo", // 17
441  "MailServer", // 18
442  "MailPort", // 19
443  "IsSecureConnection", // 20
444  "IsAuthentication", // 21
445  "MailUserName", // 22
446  "MailPassword", // 23
447  "DataSource/DataSourceName", // 24
448  "DataSource/DataTableName", // 25
449  "DataSource/DataCommandType",// 26
450  "Filter", // 27
451  "SavedDocuments", // 28
452  "EMailSupported", // 29
453  "IsEMailGreetingLine", //30
454  "IsEMailIndividualGreetingLine", //31
455  "IsSMPTAfterPOP", //32
456  "InServerName", //33
457  "InServerPort", //34
458  "InServerIsPOP", //35
459  "InServerUserName", //36
460  "InServerPassword", //37
461  "IsHideEmptyParagraphs", //38
462  "CurrentAddressBlock" //39
463  };
464  return aNames;
465 }
466 
467 void SwMailMergeConfigItem_Impl::Notify( const css::uno::Sequence< OUString >& ) {}
468 
470 {
472  Sequence<Any> aValues(aNames.getLength());
473  Any* pValues = aValues.getArray();
474 
475  for(int nProp = 0; nProp < aNames.getLength(); nProp++)
476  {
477  switch(nProp)
478  {
479  case 0: pValues[nProp] <<= m_bIsOutputToLetter; break;
480  case 1: pValues[nProp] <<= m_bIncludeCountry; break;
481  case 2: pValues[nProp] <<= m_sExcludeCountry; break;
482  case 3: pValues[nProp] <<= GetAddressBlocks(true); break;
483  case 4:
484  {
486  pValues[nProp] <<= m_bIsAddressBlock_LastUserSetting;
487  else
488  pValues[nProp] <<= m_bIsAddressBlock;
489  break;
490  }
491  case 5:
492  {
494  pValues[nProp] <<= m_bIsGreetingLine_LastUserSetting;
495  else
496  pValues[nProp] <<= m_bIsGreetingLine;
497  break;
498  }
499  case 6: pValues[nProp] <<= m_bIsIndividualGreetingLine; break;
500  case 7:
501  case 8:
502  case 9:
503  pValues[nProp] <<= GetGreetings(
505  SwMailMergeConfigItem::FEMALE + nProp - 7), true);
506  break;
507  case 10: pValues[nProp] <<= m_nCurrentFemaleGreeting; break;
508  case 11: pValues[nProp] <<= m_nCurrentMaleGreeting; break;
509  case 12: pValues[nProp] <<= m_nCurrentNeutralGreeting; break;
510  case 13: pValues[nProp] <<= m_sFemaleGenderValue; break;
511  case 14: pValues[nProp] <<= m_sMailDisplayName; break;
512  case 15: pValues[nProp] <<= m_sMailAddress; break;
513  case 16: pValues[nProp] <<= m_bIsMailReplyTo; break;
514  case 17: pValues[nProp] <<= m_sMailReplyTo; break;
515  case 18: pValues[nProp] <<= m_sMailServer; break;
516  case 19: pValues[nProp] <<= m_nMailPort; break;
517  case 20: pValues[nProp] <<= m_bIsSecureConnection; break;
518  case 21: pValues[nProp] <<= m_bIsAuthentication; break;
519  case 22: pValues[nProp] <<= m_sMailUserName; break;
520  case 23: pValues[nProp] <<= m_sMailPassword; break;
521  case 24 :pValues[nProp] <<= m_aDBData.sDataSource; break;
522  case 25 :pValues[nProp] <<= m_aDBData.sCommand; break;
523  case 26 :pValues[nProp] <<= m_aDBData.nCommandType; break;
524  case 27 :pValues[nProp] <<= m_sFilter; break;
525  case 28 :pValues[nProp] <<= m_aSavedDocuments; break;
526  case 29: pValues[nProp] <<= m_bIsEMailSupported; break;
527  case 30:
528  {
530  pValues[nProp] <<= m_bIsGreetingLineInMail_LastUserSetting;
531  else
532  pValues[nProp] <<= m_bIsGreetingLineInMail;
533  break;
534  }
535  case 31: pValues[nProp] <<= m_bIsIndividualGreetingLineInMail; break;
536  case 32: pValues[nProp] <<= m_bIsSMPTAfterPOP; break;
537  case 33: pValues[nProp] <<= m_sInServerName; break;
538  case 34: pValues[nProp] <<= m_nInServerPort; break;
539  case 35: pValues[nProp] <<= m_bInServerPOP; break;
540  case 36: pValues[nProp] <<= m_sInServerUserName; break;
541  case 37: pValues[nProp] <<= m_sInServerPassword; break;
542  case 38: pValues[nProp] <<= m_bIsHideEmptyParagraphs; break;
543  case 39: pValues[nProp] <<= m_nCurrentAddressBlock; break;
544  }
545  }
546  PutProperties(aNames, aValues);
547  //store the changed / new assignments
548 
549  //load the existing node names to find new names
551 
552  for(const auto& rAssignment : m_aAddressDataAssignments)
553  {
554  if(rAssignment.bColumnAssignmentsChanged)
555  {
556  //create a new node name
557  OUString sNewNode = !rAssignment.sConfigNodeName.isEmpty() ?
558  rAssignment.sConfigNodeName :
559  lcl_CreateNodeName(aAssignments);
560  OUString sSlash = "/";
561  OUString sNodePath = cAddressDataAssignments + sSlash + sNewNode + sSlash;
562  //only one new entry is written
563  Sequence< PropertyValue > aNewValues
564  {
565  comphelper::makePropertyValue(sNodePath + cDataSourceName, rAssignment.aDBData.sDataSource),
566  comphelper::makePropertyValue(sNodePath + cDataTableName, rAssignment.aDBData.sCommand),
567  comphelper::makePropertyValue(sNodePath + cDataCommandType, rAssignment.aDBData.nCommandType),
568  comphelper::makePropertyValue(sNodePath + cDBColumnAssignments, rAssignment.aDBColumnAssignments)
569  };
571  }
572  }
573 
575 }
576 
578  bool bConvertToConfig) const
579 {
581  std::transform(m_aAddressBlocks.begin(), m_aAddressBlocks.end(), aRet.getArray(),
582  [this, bConvertToConfig](const OUString& rBlock) -> OUString {
583  OUString sBlock = rBlock;
584  if(bConvertToConfig)
586  return sBlock;
587  });
588  return aRet;
589 }
590 
592  const Sequence< OUString>& rBlocks,
593  bool bConvertFromConfig)
594 {
595  m_aAddressBlocks.clear();
596  std::transform(rBlocks.begin(), rBlocks.end(), std::back_inserter(m_aAddressBlocks),
597  [this, bConvertFromConfig](const OUString& rBlock) -> OUString {
598  OUString sBlock = rBlock;
599  if(bConvertFromConfig)
601  return sBlock;
602  });
604  SetModified();
605 }
606 
608  SwMailMergeConfigItem::Gender eType, bool bConvertToConfig) const
609 {
610  const std::vector< OUString>& rGreetings =
614  Sequence< OUString> aRet(rGreetings.size());
615  std::transform(rGreetings.begin(), rGreetings.end(), aRet.getArray(),
616  [this, bConvertToConfig](const OUString& rGreeting) -> OUString {
617  OUString sGreeting = rGreeting;
618  if(bConvertToConfig)
620  return sGreeting;
621  });
622  return aRet;
623 }
624 
627  const Sequence< OUString>& rSetGreetings,
628  bool bConvertFromConfig)
629 {
630  std::vector< OUString>& rGreetings =
634 
635  rGreetings.clear();
636  std::transform(rSetGreetings.begin(), rSetGreetings.end(), std::back_inserter(rGreetings),
637  [this, bConvertFromConfig](const OUString& rGreeting) -> OUString {
638  OUString sGreeting = rGreeting;
639  if(bConvertFromConfig)
641  return sGreeting;
642  });
643  SetModified();
644 }
645 
647  SwMailMergeConfigItem::Gender eType) const
648 {
649  sal_Int32 nRet;
650  switch(eType)
651  {
654  default: nRet = m_nCurrentNeutralGreeting; break;
655  }
656  return nRet;
657 }
658 
660  SwMailMergeConfigItem::Gender eType, sal_Int32 nIndex)
661 {
662  bool bChanged = false;
663  switch(eType)
664  {
666  bChanged = m_nCurrentFemaleGreeting != nIndex;
667  m_nCurrentFemaleGreeting = nIndex;
668  break;
670  bChanged = m_nCurrentMaleGreeting != nIndex;
671  m_nCurrentMaleGreeting = nIndex;
672  break;
673  default:
674  bChanged = m_nCurrentNeutralGreeting != nIndex;
675  m_nCurrentNeutralGreeting = nIndex;
676  }
677  if(bChanged)
678  SetModified();
679 }
680 
685  m_nGreetingMoves(0),
686  m_nBegin(0),
687  m_nEnd(0),
688  m_pSourceView(nullptr),
689  m_pTargetView(nullptr)
690 {
691 }
692 
694 {
695  if (m_xDBChangedListener.is())
696  {
697  uno::Reference<view::XSelectionSupplier> xSupplier = m_pSourceView->GetUNOObject();
698  xSupplier->removeSelectionChangeListener(m_xDBChangedListener);
699  m_xDBChangedListener.clear();
700  }
701 }
702 
704 {
705  const SwDBData& rDBData = m_pSourceView->GetWrtShell().GetDBData();
706  SetCurrentDBData(rDBData);
707 }
708 
710 {
712 }
713 
715 {
716  if(m_pImpl->IsModified())
717  m_pImpl->Commit();
718 }
719 
720 const std::vector<std::pair<OUString, int>>& SwMailMergeConfigItem::GetDefaultAddressHeaders() const
721 {
722  return m_pImpl->m_AddressHeaderSA;
723 }
724 
726  const Sequence< OUString>& rBlocks)
727 {
728  m_pImpl->SetAddressBlocks(rBlocks);
729 }
730 
732 {
733  return m_pImpl->GetAddressBlocks();
734 }
735 
737 {
738  return m_pImpl->m_bIsAddressBlock && IsOutputToLetter();
739 }
740 
742 {
743  m_pImpl->m_bUserSettingWereOverwritten = false;
744  if(m_pImpl->m_bIsAddressBlock != bSet)
745  {
746  m_pImpl->m_bIsAddressBlock = bSet;
747  m_pImpl->SetModified();
748  }
749 }
750 
752 {
753  return m_pImpl->m_bIsHideEmptyParagraphs;
754 }
755 
757 {
758  if(m_pImpl->m_bIsHideEmptyParagraphs != bSet)
759  {
760  m_pImpl->m_bIsHideEmptyParagraphs = bSet;
761  m_pImpl->SetModified();
762  }
763 }
764 
766 {
767  return m_pImpl->m_bIncludeCountry;
768 }
769 
771 {
772  return m_pImpl->m_sExcludeCountry;
773 }
774 
775 void SwMailMergeConfigItem::SetCountrySettings(bool bSet, const OUString& rCountry)
776 {
777  if(m_pImpl->m_sExcludeCountry != rCountry ||
778  m_pImpl->m_bIncludeCountry != bSet)
779  {
780  m_pImpl->m_bIncludeCountry = bSet;
781  m_pImpl->m_sExcludeCountry = bSet ? rCountry : OUString();
782  m_pImpl->SetModified();
783  }
784 }
785 
787  Reference< XDataSource> const & xSource,
788  const SharedConnection& rConnection,
789  Reference< XColumnsSupplier> const & xColumnsSupplier,
790  const SwDBData& rDBData)
791 {
792  m_pImpl->m_xSource = xSource ;
793  m_pImpl->m_xConnection = rConnection ;
794  m_pImpl->m_xColumnsSupplier = xColumnsSupplier;
795  m_pImpl->m_aDBData = rDBData;
796  m_pImpl->m_xResultSet = nullptr;
797  m_pImpl->m_nResultSetCursorPos = 0;
798  m_pImpl->SetModified();
799 }
800 
802 {
803  return m_pImpl->m_xSource;
804 }
805 
807 {
808  return m_pImpl->m_xConnection;
809 }
810 
811 Reference< XColumnsSupplier> const & SwMailMergeConfigItem::GetColumnsSupplier()
812 {
813  if(!m_pImpl->m_xColumnsSupplier.is() && m_pImpl->m_xConnection.is())
814  {
815  m_pImpl->m_xColumnsSupplier = SwDBManager::GetColumnSupplier(m_pImpl->m_xConnection,
816  m_pImpl->m_aDBData.sCommand,
817  m_pImpl->m_aDBData.nCommandType == CommandType::TABLE ?
819  }
820  return m_pImpl->m_xColumnsSupplier;
821 }
822 
824 {
825  return m_pImpl->m_aDBData;
826 }
827 
829 {
830  if(m_pImpl->m_aDBData != rDBData)
831  {
832  m_pImpl->m_aDBData = rDBData;
833  m_pImpl->m_xConnection.clear();
834  m_pImpl->m_xSource = nullptr;
835  m_pImpl->m_xResultSet = nullptr;
836  m_pImpl->m_xColumnsSupplier = nullptr;
837  m_pImpl->SetModified();
838  }
839 }
840 
841 Reference< XResultSet> const & SwMailMergeConfigItem::GetResultSet() const
842 {
843  if(!m_pImpl->m_xConnection.is() && !m_pImpl->m_aDBData.sDataSource.isEmpty())
844  {
845  m_pImpl->m_xConnection.reset(
846  SwDBManager::GetConnection(m_pImpl->m_aDBData.sDataSource, m_pImpl->m_xSource, m_pSourceView),
848  );
849  }
850  if(!m_pImpl->m_xResultSet.is() && m_pImpl->m_xConnection.is())
851  {
852  try
853  {
854  Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
855 
856  Reference<XRowSet> xRowSet( xMgr->createInstance("com.sun.star.sdb.RowSet"), UNO_QUERY );
857  Reference<XPropertySet> xRowProperties(xRowSet, UNO_QUERY);
858  xRowProperties->setPropertyValue("DataSourceName", Any(m_pImpl->m_aDBData.sDataSource));
859  xRowProperties->setPropertyValue("Command", Any(m_pImpl->m_aDBData.sCommand));
860  xRowProperties->setPropertyValue("CommandType", Any(m_pImpl->m_aDBData.nCommandType));
861  xRowProperties->setPropertyValue("FetchSize", Any(sal_Int32(10)));
862  xRowProperties->setPropertyValue("ActiveConnection", Any(m_pImpl->m_xConnection.getTyped()));
863  try
864  {
865  xRowProperties->setPropertyValue("ApplyFilter", Any(!m_pImpl->m_sFilter.isEmpty()));
866  xRowProperties->setPropertyValue("Filter", Any(m_pImpl->m_sFilter));
867  }
868  catch (const Exception&)
869  {
870  TOOLS_WARN_EXCEPTION("sw.ui", "");
871  }
872  xRowSet->execute();
873  m_pImpl->m_xResultSet = xRowSet.get();
874  m_pImpl->m_xResultSet->first();
875  m_pImpl->m_nResultSetCursorPos = 1;
876  }
877  catch (const Exception&)
878  {
879  TOOLS_WARN_EXCEPTION("sw.ui", "SwMailMergeConfigItem::GetResultSet()");
880  }
881  }
882  return m_pImpl->m_xResultSet;
883 }
884 
886 {
887  m_pImpl->m_xConnection.clear();
888  if(m_pImpl->m_xResultSet.is())
889  {
890  ::comphelper::disposeComponent( m_pImpl->m_xResultSet );
891  }
892 }
893 
895 {
896  return m_pImpl->m_sFilter;
897 }
898 
899 void SwMailMergeConfigItem::SetFilter(OUString const & rFilter)
900 {
901  if(m_pImpl->m_sFilter == rFilter)
902  return;
903 
904  m_pImpl->m_sFilter = rFilter;
905  m_pImpl->SetModified();
906  Reference<XPropertySet> xRowProperties(m_pImpl->m_xResultSet, UNO_QUERY);
907  if(!xRowProperties.is())
908  return;
909 
910  try
911  {
912  xRowProperties->setPropertyValue("ApplyFilter", Any(!m_pImpl->m_sFilter.isEmpty()));
913  xRowProperties->setPropertyValue("Filter", Any(m_pImpl->m_sFilter));
914  uno::Reference<XRowSet> xRowSet( m_pImpl->m_xResultSet, UNO_QUERY_THROW );
915  xRowSet->execute();
916  }
917  catch (const Exception&)
918  {
919  TOOLS_WARN_EXCEPTION("sw.ui", "SwMailMergeConfigItem::SetFilter()");
920  }
921 }
922 
923 sal_Int32 SwMailMergeConfigItem::MoveResultSet(sal_Int32 nTarget)
924 {
925  if(!m_pImpl->m_xResultSet.is())
926  GetResultSet();
927  if(m_pImpl->m_xResultSet.is())
928  {
929  try
930  {
931  //no action if the resultset is already at the right position
932  if(m_pImpl->m_xResultSet->getRow() != nTarget)
933  {
934  if(nTarget > 0)
935  {
936  bool bMoved = m_pImpl->m_xResultSet->absolute(nTarget);
937  if(!bMoved)
938  {
939  if(nTarget > 1)
940  m_pImpl->m_xResultSet->last();
941  else if(nTarget == 1)
942  m_pImpl->m_xResultSet->first();
943  }
944  }
945  else if(nTarget == -1)
946  m_pImpl->m_xResultSet->last();
947  m_pImpl->m_nResultSetCursorPos = m_pImpl->m_xResultSet->getRow();
948  }
949  }
950  catch (const Exception&)
951  {
952  }
953  }
954  return m_pImpl->m_nResultSetCursorPos;
955 }
956 
957 bool SwMailMergeConfigItem::IsResultSetFirstLast(bool& bIsFirst, bool& bIsLast)
958 {
959  bool bRet = false;
960  if(!m_pImpl->m_xResultSet.is())
961  GetResultSet();
962  if(m_pImpl->m_xResultSet.is())
963  {
964  try
965  {
966  bIsFirst = m_pImpl->m_xResultSet->isFirst();
967  bIsLast = m_pImpl->m_xResultSet->isLast();
968  bRet = true;
969  }
970  catch (const Exception&)
971  {
972  }
973  }
974  return bRet;
975 }
976 
978 {
979  return m_pImpl->m_nResultSetCursorPos;
980 }
981 
982 bool SwMailMergeConfigItem::IsRecordIncluded(sal_uInt32 nRecord) const
983  { return nRecord > m_nBegin && nRecord <= m_nEnd; }
984 
985 bool SwMailMergeConfigItem::IsRecordExcluded(sal_uInt32 nRecord) const
986  { return m_aExcludedRecords.find(nRecord) != m_aExcludedRecords.end(); }
987 
988 void SwMailMergeConfigItem::ExcludeRecord(sal_Int32 nRecord, bool bExclude)
989 {
990  if(bExclude)
991  m_aExcludedRecords.insert(nRecord);
992  else
993  m_aExcludedRecords.erase(nRecord);
994 }
995 
996 uno::Sequence<uno::Any> SwMailMergeConfigItem::GetSelection() const
997 {
998  if(!m_pImpl->m_xResultSet.is())
999  GetResultSet();
1000  if(!m_pImpl->m_xResultSet.is())
1001  return {};
1002  m_pImpl->m_xResultSet->last();
1003  sal_uInt32 nResultSetSize = m_pImpl->m_xResultSet->getRow()+1;
1004  std::vector<uno::Any> vResult;
1005  for(sal_uInt32 nIdx=1; nIdx<nResultSetSize;++nIdx)
1006  if( !IsRecordExcluded(nIdx) && IsRecordIncluded(nIdx) )
1007  vResult.push_back(uno::Any(sal_uInt32(nIdx)));
1008  return comphelper::containerToSequence(vResult);
1009 }
1010 
1011 
1012 const uno::Sequence< OUString>&
1014 {
1015  return m_pImpl->m_aSavedDocuments;
1016 }
1017 
1019 {
1020  return m_pImpl->m_bIsOutputToLetter || !IsMailAvailable();
1021 }
1022 
1024 {
1025  if(m_pImpl->m_bIsOutputToLetter != bSet)
1026  {
1027  m_pImpl->m_bIsOutputToLetter = bSet;
1028  m_pImpl->SetModified();
1029  }
1030 }
1031 
1033 {
1034  return bInEMail ?
1035  m_pImpl->m_bIsIndividualGreetingLineInMail :
1036  m_pImpl->m_bIsIndividualGreetingLine;
1037 }
1038 
1040  bool bSet, bool bInEMail)
1041 {
1042  if(bInEMail)
1043  {
1044  if(m_pImpl->m_bIsIndividualGreetingLineInMail != bSet)
1045  {
1046  m_pImpl->m_bIsIndividualGreetingLineInMail = bSet;
1047  m_pImpl->SetModified();
1048  }
1049  }
1050  else
1051  {
1052  if(m_pImpl->m_bIsIndividualGreetingLine != bSet)
1053  {
1054  m_pImpl->m_bIsIndividualGreetingLine = bSet;
1055  m_pImpl->SetModified();
1056  }
1057  }
1058 }
1059 
1060 bool SwMailMergeConfigItem::IsGreetingLine(bool bInEMail) const
1061 {
1062  return bInEMail ? m_pImpl->m_bIsGreetingLineInMail : m_pImpl->m_bIsGreetingLine;
1063 }
1064 
1065 void SwMailMergeConfigItem::SetGreetingLine(bool bSet, bool bInEMail)
1066 {
1067  m_pImpl->m_bUserSettingWereOverwritten = false;
1068  if(bInEMail)
1069  {
1070  if(m_pImpl->m_bIsGreetingLineInMail != bSet)
1071  {
1072  m_pImpl->m_bIsGreetingLineInMail = bSet;
1073  m_pImpl->SetModified();
1074  }
1075  }
1076  else
1077  {
1078  if(m_pImpl->m_bIsGreetingLine != bSet)
1079  {
1080  m_pImpl->m_bIsGreetingLine = bSet;
1081  m_pImpl->SetModified();
1082  }
1083  }
1084 }
1085 
1087  Gender eType ) const
1088 {
1089  return m_pImpl->GetGreetings(eType);
1090 }
1091 
1093  Gender eType, const Sequence< OUString>& rSetGreetings)
1094 {
1095  m_pImpl->SetGreetings( eType, rSetGreetings);
1096 }
1097 
1099  SwMailMergeConfigItem::Gender eType) const
1100 {
1101  return m_pImpl->GetCurrentGreeting(eType);
1102 }
1103 
1105 {
1106  m_pImpl->SetCurrentGreeting(eType, nIndex);
1107 }
1108 
1110 {
1111  return m_pImpl->m_sFemaleGenderValue;
1112 }
1113 
1115 {
1116  if( m_pImpl->m_sFemaleGenderValue != rValue )
1117  {
1118  m_pImpl->m_sFemaleGenderValue = rValue;
1119  m_pImpl->SetModified();
1120  }
1121 }
1122 
1124  const SwDBData& rDBData ) const
1125 {
1126  Sequence< OUString> aRet;
1127  auto aAssignIter = std::find_if(m_pImpl->m_aAddressDataAssignments.begin(), m_pImpl->m_aAddressDataAssignments.end(),
1128  [&rDBData](const DBAddressDataAssignment& rAssignment) { return rAssignment.aDBData == rDBData; });
1129  if (aAssignIter != m_pImpl->m_aAddressDataAssignments.end())
1130  {
1131  aRet = aAssignIter->aDBColumnAssignments;
1132  }
1133  return aRet;
1134 }
1135 
1136 // returns the name that is assigned as e-mail column of the current data base
1137 OUString SwMailMergeConfigItem::GetAssignedColumn(sal_uInt32 nColumn) const
1138 {
1139  OUString sRet;
1140  Sequence< OUString> aAssignment = GetColumnAssignment( m_pImpl->m_aDBData );
1141  if(aAssignment.getLength() > sal::static_int_cast< sal_Int32, sal_uInt32>(nColumn) && !aAssignment[nColumn].isEmpty())
1142  sRet = aAssignment[nColumn];
1143  else if(nColumn < m_pImpl->m_AddressHeaderSA.size())
1144  sRet = m_pImpl->m_AddressHeaderSA[nColumn].first;
1145  return sRet;
1146 }
1147 
1149  const Sequence< OUString>& rList)
1150 {
1151  auto aAssignIter = std::find_if(m_pImpl->m_aAddressDataAssignments.begin(), m_pImpl->m_aAddressDataAssignments.end(),
1152  [&rDBData](const DBAddressDataAssignment& rAssignment) { return rAssignment.aDBData == rDBData; });
1153  if (aAssignIter != m_pImpl->m_aAddressDataAssignments.end())
1154  {
1155  if(aAssignIter->aDBColumnAssignments != rList)
1156  {
1157  aAssignIter->aDBColumnAssignments = rList;
1158  aAssignIter->bColumnAssignmentsChanged = true;
1159  }
1160  }
1161  else
1162  {
1163  DBAddressDataAssignment aAssignment;
1164  aAssignment.aDBData = rDBData;
1165  aAssignment.aDBColumnAssignments = rList;
1166  aAssignment.bColumnAssignmentsChanged = true;
1167  m_pImpl->m_aAddressDataAssignments.push_back(aAssignment);
1168  }
1169  m_pImpl->SetModified();
1170 }
1171 
1173 {
1174  bool bResult = true;
1175  Reference< XResultSet> xResultSet = GetResultSet();
1176  uno::Reference< XColumnsSupplier > xColsSupp( xResultSet, UNO_QUERY );
1177  if(!xColsSupp.is())
1178  return false;
1179  uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
1180 
1181  const std::vector<std::pair<OUString, int>>& rHeaders = GetDefaultAddressHeaders();
1182  Sequence< OUString> aAssignment =
1184  const OUString* pAssignment = aAssignment.getConstArray();
1185  const Sequence< OUString> aBlocks = GetAddressBlocks();
1186 
1187  if(aBlocks.getLength() <= m_pImpl->GetCurrentAddressBlockIndex())
1188  return false;
1189  SwAddressIterator aIter(aBlocks[m_pImpl->GetCurrentAddressBlockIndex()]);
1190  while(aIter.HasMore())
1191  {
1192  SwMergeAddressItem aItem = aIter.Next();
1193  if(aItem.bIsColumn)
1194  {
1195  OUString sConvertedColumn = aItem.sText;
1196  auto nSize = std::min(sal_uInt32(rHeaders.size()), sal_uInt32(aAssignment.getLength()));
1197  for(sal_uInt32 nColumn = 0; nColumn < nSize; ++nColumn)
1198  {
1199  if (rHeaders[nColumn].first == aItem.sText &&
1200  !pAssignment[nColumn].isEmpty())
1201  {
1202  sConvertedColumn = pAssignment[nColumn];
1203  break;
1204  }
1205  }
1206  //find out if the column exists in the data base
1207  if(!xCols->hasByName(sConvertedColumn))
1208  {
1209  bResult = false;
1210  break;
1211  }
1212  }
1213  }
1214  return bResult;
1215 }
1216 
1218 {
1219  bool bResult = true;
1220 
1221  if(!IsIndividualGreeting(false))
1222  return true;
1223 
1224  Reference< XResultSet> xResultSet = GetResultSet();
1225  uno::Reference< XColumnsSupplier > xColsSupp( xResultSet, UNO_QUERY );
1226  if(!xColsSupp.is())
1227  return false;
1228  const std::vector<std::pair<OUString, int>>& rHeaders = GetDefaultAddressHeaders();
1229  uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
1230 
1231  Sequence< OUString> aAssignment =
1233  const OUString* pAssignment = aAssignment.getConstArray();
1234 
1236  sal_Int32 nCurrentFemale = GetCurrentGreeting(SwMailMergeConfigItem::FEMALE);
1238  sal_Int32 nCurrentMale = GetCurrentGreeting(SwMailMergeConfigItem::MALE);
1239  OUString sMale, sFemale;
1240  if(rFemaleEntries.getLength() > nCurrentFemale)
1241  sFemale = rFemaleEntries[nCurrentFemale];
1242  if(rMaleEntries.getLength() > nCurrentMale)
1243  sMale = rMaleEntries[nCurrentMale];
1244 
1245  OUString sAddress = sFemale + sMale;
1246  SwAddressIterator aIter(sAddress);
1247  while(aIter.HasMore())
1248  {
1249  SwMergeAddressItem aItem = aIter.Next();
1250  if(aItem.bIsColumn)
1251  {
1252  OUString sConvertedColumn = aItem.sText;
1253  auto nSize = std::min(sal_uInt32(rHeaders.size()), sal_uInt32(aAssignment.getLength()));
1254  for(sal_uInt32 nColumn = 0; nColumn < nSize; ++nColumn)
1255  {
1256  if (rHeaders[nColumn].first == aItem.sText &&
1257  !pAssignment[nColumn].isEmpty())
1258  {
1259  sConvertedColumn = pAssignment[nColumn];
1260  break;
1261  }
1262  }
1263  //find out if the column exists in the data base
1264  if(!xCols->hasByName(sConvertedColumn))
1265  {
1266  bResult = false;
1267  break;
1268  }
1269  }
1270  }
1271  return bResult;
1272 }
1273 
1275 {
1276  return m_pImpl->m_sMailDisplayName;
1277 }
1278 
1280 {
1281  if(m_pImpl->m_sMailDisplayName != rName)
1282  {
1283  m_pImpl->m_sMailDisplayName = rName;
1284  m_pImpl->SetModified();
1285  }
1286 }
1287 
1289 {
1290  return m_pImpl->m_sMailAddress;
1291 }
1292 
1293 void SwMailMergeConfigItem::SetMailAddress(const OUString& rAddress)
1294 {
1295  if(m_pImpl->m_sMailAddress != rAddress )
1296  {
1297  m_pImpl->m_sMailAddress = rAddress;
1298  m_pImpl->SetModified();
1299  }
1300 }
1301 
1303 {
1304  return m_pImpl->m_bIsMailReplyTo;
1305 }
1306 
1308 {
1309  if(m_pImpl->m_bIsMailReplyTo != bSet)
1310  {
1311  m_pImpl->m_bIsMailReplyTo = bSet;
1312  m_pImpl->SetModified();
1313  }
1314 }
1315 
1317 {
1318  return m_pImpl->m_sMailReplyTo;
1319 }
1320 
1321 void SwMailMergeConfigItem::SetMailReplyTo(const OUString& rReplyTo)
1322 {
1323  if(m_pImpl->m_sMailReplyTo != rReplyTo)
1324  {
1325  m_pImpl->m_sMailReplyTo = rReplyTo;
1326  m_pImpl->SetModified();
1327  }
1328 }
1329 
1331 {
1332  return m_pImpl->m_sMailServer;
1333 }
1334 
1335 void SwMailMergeConfigItem::SetMailServer(const OUString& rAddress)
1336 {
1337  if(m_pImpl->m_sMailServer != rAddress)
1338  {
1339  m_pImpl->m_sMailServer = rAddress;
1340  m_pImpl->SetModified();
1341  }
1342 }
1343 
1345 {
1346  // provide appropriate TCP port, based on SSL/STARTTLS status, if current port is one of the defaults
1347  switch (m_pImpl->m_nMailPort)
1348  {
1349  case SECURE_PORT:
1350  case DEFAULT_PORT:
1351  return m_pImpl->m_bIsSecureConnection ? SECURE_PORT : DEFAULT_PORT;
1352  default:
1353  return m_pImpl->m_nMailPort;
1354  }
1355 }
1356 
1358 {
1359  if(m_pImpl->m_nMailPort != nSet)
1360  {
1361  m_pImpl->m_nMailPort = nSet;
1362  m_pImpl->SetModified();
1363  }
1364 }
1365 
1367 {
1368  return m_pImpl->m_bIsSecureConnection;
1369 }
1370 
1372 {
1373  if(m_pImpl->m_bIsSecureConnection != bSet)
1374  {
1375  m_pImpl->m_bIsSecureConnection = bSet;
1376  m_pImpl->SetModified();
1377  }
1378 }
1379 
1381 {
1382  return m_pImpl->m_bIsAuthentication;
1383 }
1384 
1386 {
1387  if(m_pImpl->m_bIsAuthentication != bSet)
1388  {
1389  m_pImpl->m_bIsAuthentication = bSet;
1390  m_pImpl->SetModified();
1391  }
1392 }
1393 
1395 {
1396  return m_pImpl->m_sMailUserName;
1397 }
1398 
1399 void SwMailMergeConfigItem::SetMailUserName(const OUString& rName)
1400 {
1401  if(m_pImpl->m_sMailUserName != rName)
1402  {
1403  m_pImpl->m_sMailUserName = rName;
1404  m_pImpl->SetModified();
1405  }
1406 }
1407 
1409 {
1410  return m_pImpl->m_sMailPassword;
1411 }
1412 
1413 void SwMailMergeConfigItem::SetMailPassword(const OUString& rPassword)
1414 {
1415  if(m_pImpl->m_sMailPassword != rPassword)
1416  {
1417  m_pImpl->m_sMailPassword = rPassword;
1418  m_pImpl->SetModified();
1419  }
1420 }
1421 
1423 {
1424  return m_pImpl->m_bIsSMPTAfterPOP;
1425 }
1426 
1428 {
1429  if( m_pImpl->m_bIsSMPTAfterPOP != bSet)
1430  {
1431  m_pImpl->m_bIsSMPTAfterPOP = bSet;
1432  m_pImpl->SetModified();
1433  }
1434 }
1435 
1437 {
1438  return m_pImpl->m_sInServerName;
1439 }
1440 
1441 void SwMailMergeConfigItem::SetInServerName(const OUString& rServer)
1442 {
1443  if(m_pImpl->m_sInServerName != rServer)
1444  {
1445  m_pImpl->m_sInServerName = rServer;
1446  m_pImpl->SetModified();
1447  }
1448 }
1449 
1451 {
1452  // provide appropriate TCP port as user toggles between POP/IMAP if current port is one of the defaults
1453  switch (m_pImpl->m_nInServerPort)
1454  {
1455  case POP_SECURE_PORT:
1456  case POP_PORT:
1457  case IMAP_SECURE_PORT:
1458  case IMAP_PORT:
1459  if ( m_pImpl->m_bInServerPOP )
1460  return m_pImpl->m_bIsSecureConnection ? POP_SECURE_PORT : POP_PORT;
1461  else
1462  return m_pImpl->m_bIsSecureConnection ? IMAP_SECURE_PORT : IMAP_PORT;
1463  default:
1464  return m_pImpl->m_nInServerPort;
1465  }
1466 }
1467 
1469 {
1470  if( m_pImpl->m_nInServerPort != nSet)
1471  {
1472  m_pImpl->m_nInServerPort = nSet;
1473  m_pImpl->SetModified();
1474  }
1475 }
1476 
1478 {
1479  return m_pImpl->m_bInServerPOP;
1480 }
1481 
1483 {
1484  if( m_pImpl->m_bInServerPOP != bSet)
1485  {
1486  m_pImpl->m_bInServerPOP = bSet;
1487  m_pImpl->SetModified();
1488  }
1489 }
1490 
1492 {
1493  return m_pImpl->m_sInServerUserName;
1494 }
1495 
1497 {
1498  if( m_pImpl->m_sInServerUserName != rName)
1499  {
1500  m_pImpl->m_sInServerUserName = rName;
1501  m_pImpl->SetModified();
1502  }
1503 }
1504 
1506 {
1507  return m_pImpl->m_sInServerPassword;
1508 }
1509 
1510 void SwMailMergeConfigItem::SetInServerPassword(const OUString& rPassword)
1511 {
1512  if(m_pImpl->m_sInServerPassword != rPassword)
1513  {
1514  m_pImpl->m_sInServerPassword = rPassword;
1515  m_pImpl->SetModified();
1516  }
1517 }
1518 
1520 {
1521  m_bGreetingInserted = false;
1522  m_bAddressInserted = false;
1523 }
1524 
1526 {
1527  return m_pImpl->m_bIsEMailSupported;
1528 }
1529 
1531 {
1532  m_pImpl->m_aMergeInfos.push_back(rInfo);
1533 }
1534 
1536 {
1537  assert(nDocument < m_pImpl->m_aMergeInfos.size());
1538  return m_pImpl->m_aMergeInfos[nDocument];
1539 }
1540 
1541 
1543 {
1544  if(m_pTargetView)
1545  return m_pImpl->m_aMergeInfos.size();
1546  else
1547  {
1548  sal_Int32 nRestore = GetResultSetPosition();
1549  MoveResultSet(-1);
1550  sal_Int32 nRet = GetResultSetPosition();
1551  MoveResultSet( nRestore );
1552  nRet -= m_aExcludedRecords.size();
1553  return nRet >= 0 ? nRet : 0;
1554  }
1555 }
1556 
1558 {
1559  SfxViewShell* pViewShell = SfxViewShell::GetFirst( false, checkSfxViewShell<SwView> );
1560  while(pViewShell)
1561  {
1562  if(pViewShell == pView)
1563  return pView;
1564 
1565  pViewShell = SfxViewShell::GetNext( *pViewShell, false, checkSfxViewShell<SwView> );
1566  }
1567  return nullptr;
1568 }
1569 
1571 {
1572  //make sure that the pointer is really valid - the document may have been closed manually
1573  if(m_pTargetView)
1574  {
1576  }
1577  return m_pTargetView;
1578 }
1579 
1581 {
1582  m_pTargetView = pView;
1583  //reset the document merge counter
1584  if(!m_pTargetView)
1585  {
1586  m_pImpl->m_aMergeInfos.clear();
1587  }
1588 }
1589 
1591 {
1593  return m_pSourceView;
1594 }
1595 
1596 namespace {
1597 
1598 //This implements XSelectionChangeListener and XDispatch because the
1599 //broadcaster uses this combo to determine if to send the database-changed
1600 //update. Its probably that listening to statusChanged at some other level is
1601 //equivalent to this. See the other call to SwXDispatch::GetDBChangeURL for
1602 //the broadcaster of the event.
1603 class DBChangeListener : public cppu::WeakImplHelper<css::view::XSelectionChangeListener, css::frame::XDispatch>
1604 {
1606 public:
1607  explicit DBChangeListener(SwMailMergeConfigItem& rParent)
1608  : m_rParent(rParent)
1609  {
1610  }
1611 
1612  virtual void SAL_CALL selectionChanged(const EventObject& /*rEvent*/) override
1613  {
1614  }
1615 
1616  virtual void SAL_CALL disposing(const EventObject&) override
1617  {
1618  m_rParent.stopDBChangeListening();
1619  }
1620 
1621  virtual void SAL_CALL dispatch(const css::util::URL& rURL, const css::uno::Sequence< css::beans::PropertyValue >& /*rArgs*/) override
1622  {
1623  if (rURL.Complete.equalsAscii(SwXDispatch::GetDBChangeURL()))
1624  m_rParent.updateCurrentDBDataFromDocument();
1625  }
1626 
1627  virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener >&, const css::util::URL&) override
1628  {
1629  }
1630 
1631  virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener >&, const css::util::URL&) override
1632  {
1633  }
1634 };
1635 
1636 }
1637 
1639 {
1640  if (m_xDBChangedListener.is())
1641  {
1642  uno::Reference<view::XSelectionSupplier> xSupplier = m_pSourceView->GetUNOObject();
1643  xSupplier->removeSelectionChangeListener(m_xDBChangedListener);
1644  m_xDBChangedListener.clear();
1645  }
1646 
1647  m_pSourceView = pView;
1648 
1649  if (!m_pSourceView)
1650  return;
1651 
1652  std::vector<OUString> aDBNameList;
1653  std::vector<OUString> aAllDBNames;
1654  m_pSourceView->GetWrtShell().GetAllUsedDB( aDBNameList, &aAllDBNames );
1655  if(!aDBNameList.empty())
1656  {
1657  // if fields are available there is usually no need of an addressblock and greeting
1658  if(!m_pImpl->m_bUserSettingWereOverwritten)
1659  {
1660  if( m_pImpl->m_bIsAddressBlock
1661  || m_pImpl->m_bIsGreetingLineInMail
1662  || m_pImpl->m_bIsGreetingLine )
1663  {
1664  //store user settings
1665  m_pImpl->m_bUserSettingWereOverwritten = true;
1666  m_pImpl->m_bIsAddressBlock_LastUserSetting = m_pImpl->m_bIsAddressBlock;
1667  m_pImpl->m_bIsGreetingLineInMail_LastUserSetting = m_pImpl->m_bIsGreetingLineInMail;
1668  m_pImpl->m_bIsGreetingLine_LastUserSetting = m_pImpl->m_bIsGreetingLine;
1669 
1670  //set all to false
1671  m_pImpl->m_bIsAddressBlock = false;
1672  m_pImpl->m_bIsGreetingLineInMail = false;
1673  m_pImpl->m_bIsGreetingLine = false;
1674 
1675  m_pImpl->SetModified();
1676  }
1677  }
1678  }
1679  else if( m_pImpl->m_bUserSettingWereOverwritten )
1680  {
1681  //restore last user settings:
1682  m_pImpl->m_bIsAddressBlock = m_pImpl->m_bIsAddressBlock_LastUserSetting;
1683  m_pImpl->m_bIsGreetingLineInMail = m_pImpl->m_bIsGreetingLineInMail_LastUserSetting;
1684  m_pImpl->m_bIsGreetingLine = m_pImpl->m_bIsGreetingLine_LastUserSetting;
1685 
1686  m_pImpl->m_bUserSettingWereOverwritten = false;
1687  }
1688 
1689  if (!m_xDBChangedListener.is())
1690  {
1691  m_xDBChangedListener.set(new DBChangeListener(*this));
1692  }
1693 
1694  uno::Reference<view::XSelectionSupplier> xSupplier = m_pSourceView->GetUNOObject();
1695  xSupplier->addSelectionChangeListener(m_xDBChangedListener);
1696 }
1697 
1699 {
1700  m_pImpl->SetCurrentAddressBlockIndex( nSet );
1701 }
1702 
1704 {
1705  return m_pImpl->GetCurrentAddressBlockIndex();
1706 }
1707 
1708 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
SwNodeOffset min(const SwNodeOffset &a, const SwNodeOffset &b)
Definition: nodeoffset.hxx:35
static const Sequence< OUString > & GetPropertyNames()
SwMergeAddressItem Next()
bool HasMore() const
bool IsHideEmptyParagraphs() const
static OUString lcl_CreateNodeName(Sequence< OUString > &rAssignments)
OUString const & GetMailServer() const
sal_Int32 nIndex
sal_Int32 nCommandType
Definition: swdbdata.hxx:32
static bool SetSetProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const OUString &rNode, const css::uno::Sequence< css::beans::PropertyValue > &rValues)
static css::uno::Sequence< OUString > GetNodeNames(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const OUString &rNode, ConfigNameFormat eFormat)
void SetGreetings(Gender eType, const css::uno::Sequence< OUString > &rBlocks)
void SetCurrentDBData(const SwDBData &rDBData)
void SetGreetingLine(bool bSet, bool bInEMail)
void Notify(SwFlyFrame *pFly, SwPageFrame *pOld, const SwRect &rOld, const SwRect *pOldRect=nullptr)
Notify the background based on the difference between old and new rectangle.
Definition: frmtool.cxx:3242
css::uno::Sequence< css::uno::Any > GetSelection() const
static css::uno::Reference< css::sdbcx::XColumnsSupplier > GetColumnSupplier(css::uno::Reference< css::sdbc::XConnection > const &xConnection, const OUString &rTableOrQuery, SwDBSelect eTableOrQuery=SwDBSelect::UNKNOWN)
Definition: dbmgr.cxx:1877
OUString const & GetMailAddress() const
void SetMailDisplayName(const OUString &rName)
std::vector< OUString > m_aFemaleGreetingLines
std::vector< OUString > m_aNeutralGreetingLines
void SetCurrentGreeting(Gender eType, sal_Int32 nIndex)
bool IsSecureConnection() const
void SetInServerPassword(const OUString &rPassword)
sal_Int32 findValue(const css::uno::Sequence< T1 > &_rList, const T2 &_rValue)
void SetMailServer(const OUString &rAddress)
void SetIndividualGreeting(bool bSet, bool bInEMail)
OUString & GetExcludeCountry() const
css::beans::PropertyValue makePropertyValue(const OUString &rName, T &&rValue)
OUString sDataSource
Definition: swdbdata.hxx:30
ConfigItemMode
css::uno::Reference< css::view::XSelectionChangeListener > m_xDBChangedListener
#define IMAP_SECURE_PORT
sal_Int32 GetCurrentAddressBlockIndex() const
void SetCurrentConnection(css::uno::Reference< css::sdbc::XDataSource > const &xSource, const SharedConnection &rConnection, css::uno::Reference< css::sdbcx::XColumnsSupplier > const &xColumnsSupplier, const SwDBData &rDBData)
std::vector< SwDocMergeInfo > m_aMergeInfos
void SetTargetView(SwView *pView)
const SwDBData & GetCurrentDBData() const
void SetMailReplyTo(bool bSet)
bool IsResultSetFirstLast(bool &bIsFirst, bool &bIsLast)
sal_Int16 GetMailPort() const
sal_Int32 GetCurrentGreeting(SwMailMergeConfigItem::Gender eType) const
constexpr OUStringLiteral cAddressDataAssignments
void SetMailPassword(const OUString &rPassword)
void SetInServerPOP(bool bSet)
const char cDBColumnAssignments[]
virtual DECL_LISTENERMULTIPLEXER_END void SAL_CALL selectionChanged(const css::lang::EventObject &aEvent) override
const char cDataTableName[]
void ClearModified()
Reference< XColumnsSupplier > m_xColumnsSupplier
void SetSMTPAfterPOP(bool bSet)
bool UCB_IsFile(const OUString &rURL)
SwWrtShell & GetWrtShell() const
Definition: view.hxx:413
virtual void Notify(const css::uno::Sequence< OUString > &aPropertyNames) override
OUString SwResId(TranslateId aId)
Definition: swmodule.cxx:164
sal_uInt16 sal_Unicode
NONE
css::uno::Reference< css::sdbcx::XColumnsSupplier > const & GetColumnsSupplier()
enumrange< T >::Iterator begin(enumrange< T >)
css::uno::Sequence< OUString > GetAddressBlocks() const
SwDocMergeInfo & GetDocumentMergeInfo(sal_uInt32 nDocument)
void SetMailAddress(const OUString &rAddress)
uno::Sequence< OUString > m_aSavedDocuments
void SetInServerPort(sal_Int16 nSet)
static SfxViewShell * GetNext(const SfxViewShell &rPrev, bool bOnlyVisible=true, const std::function< bool(const SfxViewShell *)> &isViewShell=nullptr)
void SetAuthentication(bool bSet)
SharedConnection const & GetConnection() const
css::uno::Sequence< OUString > GetGreetings(Gender eType) const
void AddMergedDocument(SwDocMergeInfo const &rInfo)
void updateCurrentDBDataFromDocument()
static void lcl_ConvertFromNumbers(OUString &rBlock, const std::vector< std::pair< OUString, int >> &rHeaders)
bool IsAuthentication() const
OUString const & GetInServerPassword() const
sal_Int16 GetInServerPort() const
#define SAL_N_ELEMENTS(arr)
static bool PutProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const css::uno::Sequence< OUString > &rNames, const css::uno::Sequence< css::uno::Any > &rValues, bool bAllLocales)
css::uno::Reference< css::sdbc::XResultSet > const & GetResultSet() const
sal_uInt32 GetMergedDocumentCount()
const char cDataCommandType[]
std::set< sal_Int32 > m_aExcludedRecords
const css::uno::Sequence< OUString > & GetSavedDocuments() const
static css::uno::Sequence< css::uno::Any > GetProperties(css::uno::Reference< css::container::XHierarchicalNameAccess > const &xHierarchyAccess, const css::uno::Sequence< OUString > &rNames, bool bAllLocales)
static void lcl_ConvertToNumbers(OUString &rBlock, const std::vector< std::pair< OUString, int >> &rHeaders)
const char cDataSourceName[]
const std::vector< std::pair< OUString, int > > & GetDefaultAddressHeaders() const
#define TOOLS_WARN_EXCEPTION(area, stream)
#define IMAP_PORT
void GetAllUsedDB(std::vector< OUString > &rDBNameList, std::vector< OUString > const *pAllDBNames)
Definition: edfld.cxx:301
int i
void SetFemaleGenderValue(const OUString &rValue)
void SetSecureConnection(bool bSet)
std::vector< std::pair< OUString, int > > m_AddressHeaderSA
static const char * GetDBChangeURL()
void ExcludeRecord(sal_Int32 nRecord, bool bExclude)
void SetAddressBlocks(const Sequence< OUString > &rBlocks, bool bConvertFromConfig=false)
void SetHideEmptyParagraphs(bool bSet)
bool IsGreetingFieldsAssigned() const
static css::uno::Reference< css::sdbc::XConnection > GetConnection(const OUString &rDataSource, css::uno::Reference< css::sdbc::XDataSource > &rxSource, const SwView *pView)
Definition: dbmgr.cxx:1854
void SetAddressBlock(bool bSet)
float u
bool IsRecordExcluded(sal_uInt32 nRecord) const
SwDBData const & GetDBData() const
Database information.
Definition: edfld.cxx:291
OUString const & GetMailReplyTo() const
sal_Int32 GetResultSetPosition() const
void SetFilter(OUString const &)
uno::Sequence< OUString > GetGreetings(SwMailMergeConfigItem::Gender eType, bool bConvertToConfig=false) const
void SetGreetings(SwMailMergeConfigItem::Gender eType, const uno::Sequence< OUString > &rBlocks, bool bConvertFromConfig=false)
static SwView * lcl_ExistsView(SwView *pView)
std::vector< OUString > m_aMaleGreetingLines
static SfxViewShell * GetFirst(bool bOnlyVisible=true, const std::function< bool(const SfxViewShell *)> &isViewShell=nullptr)
sal_Int32 MoveResultSet(sal_Int32 nTarget)
bool IsInServerPOP() const
void SetInServerName(const OUString &rServer)
css::uno::Sequence< OUString > GetColumnAssignment(const SwDBData &rDBData) const
OUString const & GetMailDisplayName() const
#define POP_PORT
sal_Int32 GetCurrentGreeting(Gender eType) const
#define DEFAULT_PORT
OUString const & GetInServerUserName() const
const PropertyValue * pValues
void SetCurrentAddressBlockIndex(sal_Int32 nSet)
void SetOutputToLetter(bool bSet)
void SetMailUserName(const OUString &rName)
bool IsIndividualGreeting(bool bInEMail) const
Reference< XResultSet > m_xResultSet
Reference< XMultiServiceFactory > getProcessServiceFactory()
bool IsMailAvailable() const
void SetSourceView(SwView *pView)
SharedConnection m_xConnection
css::uno::Sequence< DstElementType > containerToSequence(const SrcType &i_Container)
OUString GetAssignedColumn(sal_uInt32 nColumn) const
bool IsGreetingLine(bool bInEMail) const
void SetMailPort(sal_Int16 nSet)
std::vector< OUString > m_aAddressBlocks
std::unique_ptr< SwMailMergeConfigItem_Impl > m_pImpl
void SetColumnAssignment(const SwDBData &rDBData, const css::uno::Sequence< OUString > &)
#define POP_SECURE_PORT
css::uno::Reference< css::sdbc::XDataSource > const & GetSource() const
const OUString & GetFemaleGenderValue() const
bool IsIncludeCountry() const
void SetCurrentAddressBlockIndex(sal_Int32 nSet)
void SetAddressBlocks(const css::uno::Sequence< OUString > &rBlocks)
bool IsSMTPAfterPOP() const
void SetCountrySettings(bool bSet, const OUString &sCountry)
void SetInServerUserName(const OUString &rName)
bool IsRecordIncluded(sal_uInt32 nRecord) const
#define SAL_WARN(area, stream)
css::view::XSelectionSupplier * GetUNOObject()
Definition: view0.cxx:110
bool IsAddressBlock() const
void SetCurrentGreeting(SwMailMergeConfigItem::Gender eType, sal_Int32 nIndex)
sal_Int32 GetCurrentAddressBlockIndex() const
XSLTFilter & m_rParent
OUString & GetFilter() const
constexpr OUStringLiteral first
OUString const & GetMailPassword() const
bool IsMailReplyTo() const
bool IsAddressFieldsAssigned() const
OUString sCommand
Definition: swdbdata.hxx:31
virtual void ImplCommit() override
std::vector< DBAddressDataAssignment > m_aAddressDataAssignments
#define SECURE_PORT
OUString const & GetMailUserName() const
Definition: view.hxx:144
OUString const & GetInServerName() const
bool IsOutputToLetter() const
Reference< XDataSource > m_xSource
bool m_bDetectedRangeSegmentation false
Sequence< OUString > GetAddressBlocks(bool bConvertToConfig=false) const