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