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/instance.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 #include <unomid.h>
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 const char cAddressDataAssignments[] = "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 
73 {
76  //if loaded the name of the node has to be saved
77  OUString sConfigNodeName;
78  //all created or changed assignments need to be stored
80 
82  bColumnAssignmentsChanged(false)
83  {}
84 };
85 
87 {
88  friend class SwMailMergeConfigItem;
91  Reference< XColumnsSupplier> m_xColumnsSupplier;
92  Reference< XResultSet> m_xResultSet;
94  OUString m_sFilter;
96 
97  std::vector<DBAddressDataAssignment> m_aAddressDataAssignments;
98  std::vector< OUString> m_aAddressBlocks;
102 
106 
109  std::vector< OUString> m_aFemaleGreetingLines;
111  std::vector< OUString> m_aMaleGreetingLines;
113  std::vector< OUString> m_aNeutralGreetingLines;
116  uno::Sequence< OUString> m_aSavedDocuments;
117 
120 
121  //mail settings
123  OUString m_sMailAddress;
124  OUString m_sMailReplyTo;
125  OUString m_sMailServer;
126  OUString m_sMailUserName;
127  OUString m_sMailPassword;
128 
130  OUString m_sInServerName;
131  sal_Int16 m_nInServerPort;
135 
136  sal_Int16 m_nMailPort;
140 
142 
143  std::vector<std::pair<OUString, int>> m_AddressHeaderSA;
144 
145  //these addresses are not stored in the configuration
146  std::vector< SwDocMergeInfo > m_aMergeInfos;
147 
148  //we do overwrite the usersettings in a special case
149  //then we do remind the usersettings here
154 
155  static const Sequence< OUString>& GetPropertyNames();
156 
157  virtual void ImplCommit() override;
158 
159 public:
161 
162  virtual void Notify( const css::uno::Sequence< OUString >& aPropertyNames ) override;
163  Sequence< OUString> GetAddressBlocks(bool bConvertToConfig = false) const;
164  void SetAddressBlocks(
165  const Sequence< OUString>& rBlocks,
166  bool bConvertFromConfig = false);
167  uno::Sequence< OUString>
169  bool bConvertToConfig = false) const;
171  const uno::Sequence< OUString>& rBlocks,
172  bool bConvertFromConfig = false);
173 
174  void SetCurrentAddressBlockIndex( sal_Int32 nSet );
175  sal_Int32 GetCurrentAddressBlockIndex() const
176  { return m_nCurrentAddressBlock; }
177  sal_Int32 GetCurrentGreeting(SwMailMergeConfigItem::Gender eType) const;
178  void SetCurrentGreeting(SwMailMergeConfigItem::Gender eType, sal_Int32 nIndex);
179 
180 };
181 
183  ConfigItem("Office.Writer/MailMergeWizard", ConfigItemMode::NONE),
184  m_nResultSetCursorPos(-1),
185  m_nCurrentAddressBlock(0),
186  m_bIsAddressBlock(true),
187  m_bIsHideEmptyParagraphs(false),
188  m_bIsOutputToLetter(true),
189  m_bIncludeCountry(false),
190  m_bIsGreetingLine(true),
191  m_bIsIndividualGreetingLine(false),
192  m_nCurrentFemaleGreeting(0),
193  m_nCurrentMaleGreeting(0),
194  m_nCurrentNeutralGreeting(0),
195  m_bIsGreetingLineInMail(false),
196  m_bIsIndividualGreetingLineInMail(false),
197  m_bIsSMPTAfterPOP(false),
198  m_nInServerPort( POP_SECURE_PORT ),
199  m_bInServerPOP( true ),
200  m_nMailPort(SECURE_PORT),
201  m_bIsMailReplyTo(false),
202  m_bIsSecureConnection(true),
203  m_bIsAuthentication(false),
204 
205  m_bIsEMailSupported(false),
206  m_bUserSettingWereOverwritten(false),
207  m_bIsAddressBlock_LastUserSetting(false),
208  m_bIsGreetingLineInMail_LastUserSetting(false),
209  m_bIsGreetingLine_LastUserSetting(false)
210 {
211  for (size_t i = 0; i < SAL_N_ELEMENTS(SA_ADDRESS_HEADER); ++i)
212  {
213  m_AddressHeaderSA.emplace_back(SwResId(SA_ADDRESS_HEADER[i].first), SA_ADDRESS_HEADER[i].second);
214  }
215 
216  const Sequence<OUString>& rNames = GetPropertyNames();
217  Sequence<Any> aValues = GetProperties(rNames);
218  const Any* pValues = aValues.getConstArray();
219  assert(aValues.getLength() == rNames.getLength());
220  if(aValues.getLength() == rNames.getLength())
221  {
222  for(int nProp = 0; nProp < rNames.getLength(); nProp++)
223  {
224  switch(nProp)
225  {
226  case 0: pValues[nProp] >>= m_bIsOutputToLetter; break;
227  case 1: pValues[nProp] >>= m_bIncludeCountry; break;
228  case 2: pValues[nProp] >>= m_sExcludeCountry; break;
229  case 3:
230  {
231  Sequence< OUString> aBlocks;
232  pValues[nProp] >>= aBlocks;
233  SetAddressBlocks(aBlocks, true);
234  }
235  break;
236  case 4: pValues[nProp] >>= m_bIsAddressBlock; break;
237  case 5: pValues[nProp] >>= m_bIsGreetingLine; break;
238  case 6: pValues[nProp] >>= m_bIsIndividualGreetingLine; break;
239  case 7 :
240  case 8 :
241  case 9 :
242  {
243  Sequence< OUString> aGreetings;
244  pValues[nProp] >>= aGreetings;
246  SwMailMergeConfigItem::FEMALE + nProp - 7), aGreetings, true);
247  }
248  break;
249 
250  case 10: pValues[nProp] >>= m_nCurrentFemaleGreeting; break;
251  case 11: pValues[nProp] >>= m_nCurrentMaleGreeting; break;
252  case 12: pValues[nProp] >>= m_nCurrentNeutralGreeting; break;
253  case 13: pValues[nProp] >>= m_sFemaleGenderValue; break;
254  case 14: pValues[nProp] >>= m_sMailDisplayName; break;
255  case 15: pValues[nProp] >>= m_sMailAddress; break;
256  case 16: pValues[nProp] >>= m_bIsMailReplyTo; break;
257  case 17: pValues[nProp] >>= m_sMailReplyTo; break;
258  case 18: pValues[nProp] >>= m_sMailServer; break;
259  case 19: pValues[nProp] >>= m_nMailPort; break;
260  case 20: pValues[nProp] >>= m_bIsSecureConnection; break;
261  case 21: pValues[nProp] >>= m_bIsAuthentication; break;
262  case 22: pValues[nProp] >>= m_sMailUserName; break;
263  case 23: pValues[nProp] >>= m_sMailPassword; break;
264  case 24 :pValues[nProp] >>= m_aDBData.sDataSource; break;
265  case 25 :pValues[nProp] >>= m_aDBData.sCommand; break;
266  case 26 :
267  {
268  short nTemp = 0;
269  if(pValues[nProp] >>= nTemp)
270  m_aDBData.nCommandType = nTemp;
271  }
272  break;
273  case 27: pValues[nProp] >>= m_sFilter; break;
274  case 28: pValues[nProp] >>= m_aSavedDocuments; break;
275  case 29:
276  pValues[nProp] >>= m_bIsEMailSupported;
277  break;
278  case 30: pValues[nProp] >>= m_bIsGreetingLineInMail; break;
279  case 31: pValues[nProp] >>= m_bIsIndividualGreetingLineInMail; break;
280  case 32: pValues[nProp] >>= m_bIsSMPTAfterPOP; break;
281  case 33: pValues[nProp] >>= m_sInServerName; break;
282  case 34: pValues[nProp] >>= m_nInServerPort; break;
283  case 35: pValues[nProp] >>= m_bInServerPOP; break;
284  case 36: pValues[nProp] >>= m_sInServerUserName; break;
285  case 37: pValues[nProp] >>= m_sInServerPassword; break;
286  case 38: pValues[nProp] >>= m_bIsHideEmptyParagraphs; break;
287  case 39: pValues[nProp] >>= m_nCurrentAddressBlock; break;
288  }
289  }
290  }
291  //read the list of data base assignments
293  if(aAssignments.hasElements())
294  {
295  //create a list of property names to load the URLs of all data bases
296  const OUString* pAssignments = aAssignments.getConstArray();
297  Sequence< OUString > aAssignProperties(4 * aAssignments.getLength());
298  OUString* pAssignProperties = aAssignProperties.getArray();
299  sal_Int32 nAssign;
300  for(nAssign = 0; nAssign < aAssignProperties.getLength(); nAssign += 4)
301  {
302  OUString sAssignPath = OUStringLiteral(cAddressDataAssignments) +
303  "/" +
304  pAssignments[nAssign / 4] +
305  "/";
306  pAssignProperties[nAssign] = sAssignPath;
307  pAssignProperties[nAssign] += cDataSourceName;
308  pAssignProperties[nAssign + 1] = sAssignPath;
309  pAssignProperties[nAssign + 1] += cDataTableName;
310  pAssignProperties[nAssign + 2] = sAssignPath;
311  pAssignProperties[nAssign + 2] += cDataCommandType;
312  pAssignProperties[nAssign + 3] = sAssignPath;
313  pAssignProperties[nAssign + 3] += cDBColumnAssignments;
314  }
315  Sequence<Any> aAssignValues = GetProperties(aAssignProperties);
316  const Any* pAssignValues = aAssignValues.getConstArray();
317  for(nAssign = 0; nAssign < aAssignValues.getLength(); nAssign += 4 )
318  {
319  DBAddressDataAssignment aAssignment;
320  pAssignValues[nAssign] >>= aAssignment.aDBData.sDataSource;
321  pAssignValues[nAssign + 1] >>= aAssignment.aDBData.sCommand;
322  pAssignValues[nAssign + 2] >>= aAssignment.aDBData.nCommandType;
323  pAssignValues[nAssign + 3] >>= aAssignment.aDBColumnAssignments;
324  aAssignment.sConfigNodeName = pAssignments[nAssign / 4];
325  m_aAddressDataAssignments.push_back(aAssignment);
326  }
327  }
328  //check if the saved documents still exist
329  if(m_aSavedDocuments.hasElements())
330  {
331  uno::Sequence< OUString > aTempDocuments(m_aSavedDocuments.getLength());
332  OUString* pTempDocuments = std::copy_if(m_aSavedDocuments.begin(), m_aSavedDocuments.end(), aTempDocuments.begin(),
333  [](const OUString& rDoc) { return SWUnoHelper::UCB_IsFile( rDoc ); });
334  sal_Int32 nIndex = static_cast<sal_Int32>(std::distance(aTempDocuments.begin(), pTempDocuments));
335  if(nIndex < m_aSavedDocuments.getLength())
336  {
337  m_aSavedDocuments = aTempDocuments;
338  m_aSavedDocuments.realloc(nIndex);
339  }
340  }
341 }
342 
344 {
345  if(m_aAddressBlocks.size() >= sal::static_int_cast<sal_uInt32, sal_Int32>(nSet))
346  {
347  m_nCurrentAddressBlock = nSet;
348  SetModified();
349  }
350 }
351 
352 static OUString lcl_CreateNodeName(Sequence<OUString>& rAssignments )
353 {
354  sal_Int32 nStart = rAssignments.getLength();
355  OUString sNewName;
356  //search if the name exists
357  while(true)
358  {
359  sNewName = "_" + OUString::number(nStart++);
360  if(comphelper::findValue(rAssignments, sNewName) == -1)
361  break;
362  }
363  // add the new name to the array of existing names
364  rAssignments.realloc(rAssignments.getLength() + 1);
365  rAssignments.getArray()[rAssignments.getLength() - 1] = sNewName;
366  return sNewName;
367 }
368 
369 static void lcl_ConvertToNumbers(OUString& rBlock, const std::vector<std::pair<OUString, int>>& rHeaders )
370 {
371  //convert the strings used for UI to numbers used for the configuration
372  OUString sBlock(rBlock.replaceAll("\n", "\\n"));
373  for (size_t i = 0; i < rHeaders.size(); ++i)
374  {
375  OUString sHeader = "<" + rHeaders[i].first + ">";
376  OUString sReplace = "<" + OUStringChar(sal_Unicode('0' + i)) + ">";
377  sBlock = sBlock.replaceAll(sHeader, sReplace);
378  }
379  rBlock = sBlock;
380 }
381 
382 static void lcl_ConvertFromNumbers(OUString& rBlock, const std::vector<std::pair<OUString, int>>& rHeaders)
383 {
384  //convert the numbers used for the configuration to strings used for UI to numbers
385  //doesn't use ReplaceAll to prevent expansion of numbers inside of the headers
386  SwAddressIterator aGreetingIter(rBlock.replaceAll("\\n", "\n"));
387  OUStringBuffer sBlock;
388  while(aGreetingIter.HasMore())
389  {
390  SwMergeAddressItem aNext = aGreetingIter.Next();
391  if(aNext.bIsColumn)
392  {
393  //the text should be 1 characters long
394  sal_Unicode cChar = aNext.sText[0];
395  if(cChar >= '0' && cChar <= 'c')
396  {
397  sBlock.append("<");
398  sal_uInt16 nHeader = cChar - '0';
399  if(nHeader < rHeaders.size())
400  sBlock.append(rHeaders[nHeader].first);
401  sBlock.append(">");
402  }
403  else
404  {
405  SAL_WARN("sw.ui", "parse error in address block or greeting line");
406  }
407  }
408  else
409  sBlock.append(aNext.sText);
410  }
411  rBlock = sBlock.makeStringAndClear();
412 }
413 
415 {
416  static Sequence<OUString> aNames {
417  "OutputToLetter", // 0
418  "IncludeCountry", // 1
419  "ExcludeCountry", // 2
420  "AddressBlockSettings", // 3
421  "IsAddressBlock", // 4
422  "IsGreetingLine", // 5
423  "IsIndividualGreetingLine", // 6
424  "FemaleGreetingLines", // 7
425  "MaleGreetingLines", // 8
426  "NeutralGreetingLines", // 9
427  "CurrentFemaleGreeting", // 10
428  "CurrentMaleGreeting", // 11
429  "CurrentNeutralGreeting", // 12
430  "FemaleGenderValue", // 13
431  "MailDisplayName", // 14
432  "MailAddress", // 15
433  "IsMailReplyTo", // 16
434  "MailReplyTo", // 17
435  "MailServer", // 18
436  "MailPort", // 19
437  "IsSecureConnection", // 20
438  "IsAuthentication", // 21
439  "MailUserName", // 22
440  "MailPassword", // 23
441  "DataSource/DataSourceName", // 24
442  "DataSource/DataTableName", // 25
443  "DataSource/DataCommandType",// 26
444  "Filter", // 27
445  "SavedDocuments", // 28
446  "EMailSupported", // 29
447  "IsEMailGreetingLine", //30
448  "IsEMailIndividualGreetingLine", //31
449  "IsSMPTAfterPOP", //32
450  "InServerName", //33
451  "InServerPort", //34
452  "InServerIsPOP", //35
453  "InServerUserName", //36
454  "InServerPassword", //37
455  "IsHideEmptyParagraphs", //38
456  "CurrentAddressBlock" //39
457  };
458  return aNames;
459 }
460 
461 void SwMailMergeConfigItem_Impl::Notify( const css::uno::Sequence< OUString >& ) {}
462 
464 {
466  Sequence<Any> aValues(aNames.getLength());
467  Any* pValues = aValues.getArray();
468 
469  for(int nProp = 0; nProp < aNames.getLength(); nProp++)
470  {
471  switch(nProp)
472  {
473  case 0: pValues[nProp] <<= m_bIsOutputToLetter; break;
474  case 1: pValues[nProp] <<= m_bIncludeCountry; break;
475  case 2: pValues[nProp] <<= m_sExcludeCountry; break;
476  case 3: pValues[nProp] <<= GetAddressBlocks(true); break;
477  case 4:
478  {
480  pValues[nProp] <<= m_bIsAddressBlock_LastUserSetting;
481  else
482  pValues[nProp] <<= m_bIsAddressBlock;
483  break;
484  }
485  case 5:
486  {
488  pValues[nProp] <<= m_bIsGreetingLine_LastUserSetting;
489  else
490  pValues[nProp] <<= m_bIsGreetingLine;
491  break;
492  }
493  case 6: pValues[nProp] <<= m_bIsIndividualGreetingLine; break;
494  case 7:
495  case 8:
496  case 9:
497  pValues[nProp] <<= GetGreetings(
499  SwMailMergeConfigItem::FEMALE + nProp - 7), true);
500  break;
501  case 10: pValues[nProp] <<= m_nCurrentFemaleGreeting; break;
502  case 11: pValues[nProp] <<= m_nCurrentMaleGreeting; break;
503  case 12: pValues[nProp] <<= m_nCurrentNeutralGreeting; break;
504  case 13: pValues[nProp] <<= m_sFemaleGenderValue; break;
505  case 14: pValues[nProp] <<= m_sMailDisplayName; break;
506  case 15: pValues[nProp] <<= m_sMailAddress; break;
507  case 16: pValues[nProp] <<= m_bIsMailReplyTo; break;
508  case 17: pValues[nProp] <<= m_sMailReplyTo; break;
509  case 18: pValues[nProp] <<= m_sMailServer; break;
510  case 19: pValues[nProp] <<= m_nMailPort; break;
511  case 20: pValues[nProp] <<= m_bIsSecureConnection; break;
512  case 21: pValues[nProp] <<= m_bIsAuthentication; break;
513  case 22: pValues[nProp] <<= m_sMailUserName; break;
514  case 23: pValues[nProp] <<= m_sMailPassword; break;
515  case 24 :pValues[nProp] <<= m_aDBData.sDataSource; break;
516  case 25 :pValues[nProp] <<= m_aDBData.sCommand; break;
517  case 26 :pValues[nProp] <<= static_cast<short>(m_aDBData.nCommandType); break;
518  case 27 :pValues[nProp] <<= m_sFilter; break;
519  case 28 :pValues[nProp] <<= m_aSavedDocuments; break;
520  case 29: pValues[nProp] <<= m_bIsEMailSupported; break;
521  case 30:
522  {
524  pValues[nProp] <<= m_bIsGreetingLineInMail_LastUserSetting;
525  else
526  pValues[nProp] <<= m_bIsGreetingLineInMail;
527  break;
528  }
529  case 31: pValues[nProp] <<= m_bIsIndividualGreetingLineInMail; break;
530  case 32: pValues[nProp] <<= m_bIsSMPTAfterPOP; break;
531  case 33: pValues[nProp] <<= m_sInServerName; break;
532  case 34: pValues[nProp] <<= m_nInServerPort; break;
533  case 35: pValues[nProp] <<= m_bInServerPOP; break;
534  case 36: pValues[nProp] <<= m_sInServerUserName; break;
535  case 37: pValues[nProp] <<= m_sInServerPassword; break;
536  case 38: pValues[nProp] <<= m_bIsHideEmptyParagraphs; break;
537  case 39: pValues[nProp] <<= m_nCurrentAddressBlock; break;
538  }
539  }
540  PutProperties(aNames, aValues);
541  //store the changed / new assignments
542 
543  //load the existing node names to find new names
545 
546  for(const auto& rAssignment : m_aAddressDataAssignments)
547  {
548  if(rAssignment.bColumnAssignmentsChanged)
549  {
550  //create a new node name
551  OUString sNewNode = !rAssignment.sConfigNodeName.isEmpty() ?
552  rAssignment.sConfigNodeName :
553  lcl_CreateNodeName(aAssignments);
554  OUString sSlash = "/";
555  OUString sNodePath = cAddressDataAssignments + sSlash + sNewNode + sSlash;
556  //only one new entry is written
557  Sequence< PropertyValue > aNewValues(4);
558  PropertyValue* pNewValues = aNewValues.getArray();
559  pNewValues[0].Name = sNodePath;
560  pNewValues[0].Name += cDataSourceName;
561  pNewValues[0].Value <<= rAssignment.aDBData.sDataSource;
562  pNewValues[1].Name = sNodePath;
563  pNewValues[1].Name += cDataTableName;
564  pNewValues[1].Value <<= rAssignment.aDBData.sCommand;
565  pNewValues[2].Name = sNodePath;
566  pNewValues[2].Name += cDataCommandType;
567  pNewValues[2].Value <<= rAssignment.aDBData.nCommandType;
568  pNewValues[3].Name = sNodePath;
569  pNewValues[3].Name += cDBColumnAssignments;
570  pNewValues[3].Value <<= rAssignment.aDBColumnAssignments;
571 
573  }
574  }
575 
577 }
578 
580  bool bConvertToConfig) const
581 {
583  std::transform(m_aAddressBlocks.begin(), m_aAddressBlocks.end(), aRet.begin(),
584  [this, bConvertToConfig](const OUString& rBlock) -> OUString {
585  OUString sBlock = rBlock;
586  if(bConvertToConfig)
588  return sBlock;
589  });
590  return aRet;
591 }
592 
594  const Sequence< OUString>& rBlocks,
595  bool bConvertFromConfig)
596 {
597  m_aAddressBlocks.clear();
598  std::transform(rBlocks.begin(), rBlocks.end(), std::back_inserter(m_aAddressBlocks),
599  [this, bConvertFromConfig](const OUString& rBlock) -> OUString {
600  OUString sBlock = rBlock;
601  if(bConvertFromConfig)
603  return sBlock;
604  });
606  SetModified();
607 }
608 
610  SwMailMergeConfigItem::Gender eType, bool bConvertToConfig) const
611 {
612  const std::vector< OUString>& rGreetings =
616  Sequence< OUString> aRet(rGreetings.size());
617  std::transform(rGreetings.begin(), rGreetings.end(), aRet.begin(),
618  [this, bConvertToConfig](const OUString& rGreeting) -> OUString {
619  OUString sGreeting = rGreeting;
620  if(bConvertToConfig)
622  return sGreeting;
623  });
624  return aRet;
625 }
626 
629  const Sequence< OUString>& rSetGreetings,
630  bool bConvertFromConfig)
631 {
632  std::vector< OUString>& rGreetings =
636 
637  rGreetings.clear();
638  std::transform(rSetGreetings.begin(), rSetGreetings.end(), std::back_inserter(rGreetings),
639  [this, bConvertFromConfig](const OUString& rGreeting) -> OUString {
640  OUString sGreeting = rGreeting;
641  if(bConvertFromConfig)
643  return sGreeting;
644  });
645  SetModified();
646 }
647 
649  SwMailMergeConfigItem::Gender eType) const
650 {
651  sal_Int32 nRet;
652  switch(eType)
653  {
656  default: nRet = m_nCurrentNeutralGreeting; break;
657  }
658  return nRet;
659 }
660 
662  SwMailMergeConfigItem::Gender eType, sal_Int32 nIndex)
663 {
664  bool bChanged = false;
665  switch(eType)
666  {
668  bChanged = m_nCurrentFemaleGreeting != nIndex;
669  m_nCurrentFemaleGreeting = nIndex;
670  break;
672  bChanged = m_nCurrentMaleGreeting != nIndex;
673  m_nCurrentMaleGreeting = nIndex;
674  break;
675  default:
676  bChanged = m_nCurrentNeutralGreeting != nIndex;
677  m_nCurrentNeutralGreeting = nIndex;
678  }
679  if(bChanged)
680  SetModified();
681 }
682 
685  m_bAddressInserted(false),
686  m_bGreetingInserted(false),
687  m_nGreetingMoves(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().GetDBDesc();
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  {
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", makeAny(m_pImpl->m_aDBData.sDataSource));
859  xRowProperties->setPropertyValue("Command", makeAny(m_pImpl->m_aDBData.sCommand));
860  xRowProperties->setPropertyValue("CommandType", makeAny(m_pImpl->m_aDBData.nCommandType));
861  xRowProperties->setPropertyValue("FetchSize", makeAny(sal_Int32(10)));
862  xRowProperties->setPropertyValue("ActiveConnection", makeAny(m_pImpl->m_xConnection.getTyped()));
863  try
864  {
865  xRowProperties->setPropertyValue("ApplyFilter", makeAny(!m_pImpl->m_sFilter.isEmpty()));
866  xRowProperties->setPropertyValue("Filter", makeAny(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  {
903  m_pImpl->m_sFilter = rFilter;
904  m_pImpl->SetModified();
905  Reference<XPropertySet> xRowProperties(m_pImpl->m_xResultSet, UNO_QUERY);
906  if(xRowProperties.is())
907  {
908  try
909  {
910  xRowProperties->setPropertyValue("ApplyFilter", makeAny(!m_pImpl->m_sFilter.isEmpty()));
911  xRowProperties->setPropertyValue("Filter", makeAny(m_pImpl->m_sFilter));
912  uno::Reference<XRowSet> xRowSet( m_pImpl->m_xResultSet, UNO_QUERY_THROW );
913  xRowSet->execute();
914  }
915  catch (const Exception&)
916  {
917  TOOLS_WARN_EXCEPTION("sw.ui", "SwMailMergeConfigItem::SetFilter()");
918  }
919  }
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::IsRecordExcluded(sal_Int32 nRecord) const
983  { return m_aExcludedRecords.find(nRecord) != m_aExcludedRecords.end(); }
984 
985 void SwMailMergeConfigItem::ExcludeRecord(sal_Int32 nRecord, bool bExclude)
986 {
987  if(bExclude)
988  m_aExcludedRecords.insert(nRecord);
989  else
990  m_aExcludedRecords.erase(nRecord);
991 }
992 
993 uno::Sequence<uno::Any> SwMailMergeConfigItem::GetSelection() const
994 {
995  if(!m_pImpl->m_xResultSet.is())
996  GetResultSet();
997  if(!m_pImpl->m_xResultSet.is())
998  return {};
999  m_pImpl->m_xResultSet->last();
1000  sal_Int32 nResultSetSize = m_pImpl->m_xResultSet->getRow()+1;
1001  std::vector<uno::Any> vResult;
1002  vResult.reserve(nResultSetSize);
1003  for(sal_Int32 nIdx=1; nIdx<nResultSetSize;++nIdx)
1004  if(!IsRecordExcluded(nIdx))
1005  vResult.push_back(uno::makeAny<sal_Int32>(nIdx));
1006  return comphelper::containerToSequence(vResult);
1007 }
1008 
1009 
1010 const uno::Sequence< OUString>&
1012 {
1013  return m_pImpl->m_aSavedDocuments;
1014 }
1015 
1017 {
1018  return m_pImpl->m_bIsOutputToLetter || !IsMailAvailable();
1019 }
1020 
1022 {
1023  if(m_pImpl->m_bIsOutputToLetter != bSet)
1024  {
1025  m_pImpl->m_bIsOutputToLetter = bSet;
1026  m_pImpl->SetModified();
1027  }
1028 }
1029 
1031 {
1032  return bInEMail ?
1033  m_pImpl->m_bIsIndividualGreetingLineInMail :
1034  m_pImpl->m_bIsIndividualGreetingLine;
1035 }
1036 
1038  bool bSet, bool bInEMail)
1039 {
1040  if(bInEMail)
1041  {
1042  if(m_pImpl->m_bIsIndividualGreetingLineInMail != bSet)
1043  {
1044  m_pImpl->m_bIsIndividualGreetingLineInMail = bSet;
1045  m_pImpl->SetModified();
1046  }
1047  }
1048  else
1049  {
1050  if(m_pImpl->m_bIsIndividualGreetingLine != bSet)
1051  {
1052  m_pImpl->m_bIsIndividualGreetingLine = bSet;
1053  m_pImpl->SetModified();
1054  }
1055  }
1056 }
1057 
1058 bool SwMailMergeConfigItem::IsGreetingLine(bool bInEMail) const
1059 {
1060  return bInEMail ? m_pImpl->m_bIsGreetingLineInMail : m_pImpl->m_bIsGreetingLine;
1061 }
1062 
1063 void SwMailMergeConfigItem::SetGreetingLine(bool bSet, bool bInEMail)
1064 {
1065  m_pImpl->m_bUserSettingWereOverwritten = false;
1066  if(bInEMail)
1067  {
1068  if(m_pImpl->m_bIsGreetingLineInMail != bSet)
1069  {
1070  m_pImpl->m_bIsGreetingLineInMail = bSet;
1071  m_pImpl->SetModified();
1072  }
1073  }
1074  else
1075  {
1076  if(m_pImpl->m_bIsGreetingLine != bSet)
1077  {
1078  m_pImpl->m_bIsGreetingLine = bSet;
1079  m_pImpl->SetModified();
1080  }
1081  }
1082 }
1083 
1085  Gender eType ) const
1086 {
1087  return m_pImpl->GetGreetings(eType);
1088 }
1089 
1091  Gender eType, const Sequence< OUString>& rSetGreetings)
1092 {
1093  m_pImpl->SetGreetings( eType, rSetGreetings);
1094 }
1095 
1097  SwMailMergeConfigItem::Gender eType) const
1098 {
1099  return m_pImpl->GetCurrentGreeting(eType);
1100 }
1101 
1103 {
1104  m_pImpl->SetCurrentGreeting(eType, nIndex);
1105 }
1106 
1108 {
1109  return m_pImpl->m_sFemaleGenderValue;
1110 }
1111 
1113 {
1114  if( m_pImpl->m_sFemaleGenderValue != rValue )
1115  {
1116  m_pImpl->m_sFemaleGenderValue = rValue;
1117  m_pImpl->SetModified();
1118  }
1119 }
1120 
1122  const SwDBData& rDBData ) const
1123 {
1124  Sequence< OUString> aRet;
1125  auto aAssignIter = std::find_if(m_pImpl->m_aAddressDataAssignments.begin(), m_pImpl->m_aAddressDataAssignments.end(),
1126  [&rDBData](const DBAddressDataAssignment& rAssignment) { return rAssignment.aDBData == rDBData; });
1127  if (aAssignIter != m_pImpl->m_aAddressDataAssignments.end())
1128  {
1129  aRet = aAssignIter->aDBColumnAssignments;
1130  }
1131  return aRet;
1132 }
1133 
1134 // returns the name that is assigned as e-mail column of the current data base
1135 OUString SwMailMergeConfigItem::GetAssignedColumn(sal_uInt32 nColumn) const
1136 {
1137  OUString sRet;
1138  Sequence< OUString> aAssignment = GetColumnAssignment( m_pImpl->m_aDBData );
1139  if(aAssignment.getLength() > sal::static_int_cast< sal_Int32, sal_uInt32>(nColumn) && !aAssignment[nColumn].isEmpty())
1140  sRet = aAssignment[nColumn];
1141  else if(nColumn < m_pImpl->m_AddressHeaderSA.size())
1142  sRet = m_pImpl->m_AddressHeaderSA[nColumn].first;
1143  return sRet;
1144 }
1145 
1147  const Sequence< OUString>& rList)
1148 {
1149  auto aAssignIter = std::find_if(m_pImpl->m_aAddressDataAssignments.begin(), m_pImpl->m_aAddressDataAssignments.end(),
1150  [&rDBData](const DBAddressDataAssignment& rAssignment) { return rAssignment.aDBData == rDBData; });
1151  if (aAssignIter != m_pImpl->m_aAddressDataAssignments.end())
1152  {
1153  if(aAssignIter->aDBColumnAssignments != rList)
1154  {
1155  aAssignIter->aDBColumnAssignments = rList;
1156  aAssignIter->bColumnAssignmentsChanged = true;
1157  }
1158  }
1159  else
1160  {
1161  DBAddressDataAssignment aAssignment;
1162  aAssignment.aDBData = rDBData;
1163  aAssignment.aDBColumnAssignments = rList;
1164  aAssignment.bColumnAssignmentsChanged = true;
1165  m_pImpl->m_aAddressDataAssignments.push_back(aAssignment);
1166  }
1167  m_pImpl->SetModified();
1168 }
1169 
1171 {
1172  bool bResult = true;
1173  Reference< XResultSet> xResultSet = GetResultSet();
1174  uno::Reference< XColumnsSupplier > xColsSupp( xResultSet, UNO_QUERY );
1175  if(!xColsSupp.is())
1176  return false;
1177  uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
1178 
1179  const std::vector<std::pair<OUString, int>>& rHeaders = GetDefaultAddressHeaders();
1180  Sequence< OUString> aAssignment =
1182  const OUString* pAssignment = aAssignment.getConstArray();
1183  const Sequence< OUString> aBlocks = GetAddressBlocks();
1184 
1185  if(aBlocks.getLength() <= m_pImpl->GetCurrentAddressBlockIndex())
1186  return false;
1187  SwAddressIterator aIter(aBlocks[m_pImpl->GetCurrentAddressBlockIndex()]);
1188  while(aIter.HasMore())
1189  {
1190  SwMergeAddressItem aItem = aIter.Next();
1191  if(aItem.bIsColumn)
1192  {
1193  OUString sConvertedColumn = aItem.sText;
1194  auto nSize = std::min(sal_uInt32(rHeaders.size()), sal_uInt32(aAssignment.getLength()));
1195  for(sal_uInt32 nColumn = 0; nColumn < nSize; ++nColumn)
1196  {
1197  if (rHeaders[nColumn].first == aItem.sText &&
1198  !pAssignment[nColumn].isEmpty())
1199  {
1200  sConvertedColumn = pAssignment[nColumn];
1201  break;
1202  }
1203  }
1204  //find out if the column exists in the data base
1205  if(!xCols->hasByName(sConvertedColumn))
1206  {
1207  bResult = false;
1208  break;
1209  }
1210  }
1211  }
1212  return bResult;
1213 }
1214 
1216 {
1217  bool bResult = true;
1218 
1219  if(!IsIndividualGreeting(false))
1220  return true;
1221 
1222  Reference< XResultSet> xResultSet = GetResultSet();
1223  uno::Reference< XColumnsSupplier > xColsSupp( xResultSet, UNO_QUERY );
1224  if(!xColsSupp.is())
1225  return false;
1226  const std::vector<std::pair<OUString, int>>& rHeaders = GetDefaultAddressHeaders();
1227  uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
1228 
1229  Sequence< OUString> aAssignment =
1231  const OUString* pAssignment = aAssignment.getConstArray();
1232 
1234  sal_Int32 nCurrentFemale = GetCurrentGreeting(SwMailMergeConfigItem::FEMALE);
1236  sal_Int32 nCurrentMale = GetCurrentGreeting(SwMailMergeConfigItem::MALE);
1237  OUString sMale, sFemale;
1238  if(rFemaleEntries.getLength() > nCurrentFemale)
1239  sFemale = rFemaleEntries[nCurrentFemale];
1240  if(rMaleEntries.getLength() > nCurrentMale)
1241  sMale = rMaleEntries[nCurrentMale];
1242 
1243  OUString sAddress = sFemale + sMale;
1244  SwAddressIterator aIter(sAddress);
1245  while(aIter.HasMore())
1246  {
1247  SwMergeAddressItem aItem = aIter.Next();
1248  if(aItem.bIsColumn)
1249  {
1250  OUString sConvertedColumn = aItem.sText;
1251  auto nSize = std::min(sal_uInt32(rHeaders.size()), sal_uInt32(aAssignment.getLength()));
1252  for(sal_uInt32 nColumn = 0; nColumn < nSize; ++nColumn)
1253  {
1254  if (rHeaders[nColumn].first == aItem.sText &&
1255  !pAssignment[nColumn].isEmpty())
1256  {
1257  sConvertedColumn = pAssignment[nColumn];
1258  break;
1259  }
1260  }
1261  //find out if the column exists in the data base
1262  if(!xCols->hasByName(sConvertedColumn))
1263  {
1264  bResult = false;
1265  break;
1266  }
1267  }
1268  }
1269  return bResult;
1270 }
1271 
1273 {
1274  return m_pImpl->m_sMailDisplayName;
1275 }
1276 
1278 {
1279  if(m_pImpl->m_sMailDisplayName != rName)
1280  {
1281  m_pImpl->m_sMailDisplayName = rName;
1282  m_pImpl->SetModified();
1283  }
1284 }
1285 
1287 {
1288  return m_pImpl->m_sMailAddress;
1289 }
1290 
1291 void SwMailMergeConfigItem::SetMailAddress(const OUString& rAddress)
1292 {
1293  if(m_pImpl->m_sMailAddress != rAddress )
1294  {
1295  m_pImpl->m_sMailAddress = rAddress;
1296  m_pImpl->SetModified();
1297  }
1298 }
1299 
1301 {
1302  return m_pImpl->m_bIsMailReplyTo;
1303 }
1304 
1306 {
1307  if(m_pImpl->m_bIsMailReplyTo != bSet)
1308  {
1309  m_pImpl->m_bIsMailReplyTo = bSet;
1310  m_pImpl->SetModified();
1311  }
1312 }
1313 
1315 {
1316  return m_pImpl->m_sMailReplyTo;
1317 }
1318 
1319 void SwMailMergeConfigItem::SetMailReplyTo(const OUString& rReplyTo)
1320 {
1321  if(m_pImpl->m_sMailReplyTo != rReplyTo)
1322  {
1323  m_pImpl->m_sMailReplyTo = rReplyTo;
1324  m_pImpl->SetModified();
1325  }
1326 }
1327 
1329 {
1330  return m_pImpl->m_sMailServer;
1331 }
1332 
1333 void SwMailMergeConfigItem::SetMailServer(const OUString& rAddress)
1334 {
1335  if(m_pImpl->m_sMailServer != rAddress)
1336  {
1337  m_pImpl->m_sMailServer = rAddress;
1338  m_pImpl->SetModified();
1339  }
1340 }
1341 
1343 {
1344  // provide appropriate TCP port, based on SSL/STARTTLS status, if current port is one of the defaults
1345  switch (m_pImpl->m_nMailPort)
1346  {
1347  case SECURE_PORT:
1348  case DEFAULT_PORT:
1349  return m_pImpl->m_bIsSecureConnection ? SECURE_PORT : DEFAULT_PORT;
1350  break;
1351  default:
1352  return m_pImpl->m_nMailPort;
1353  }
1354 }
1355 
1357 {
1358  if(m_pImpl->m_nMailPort != nSet)
1359  {
1360  m_pImpl->m_nMailPort = nSet;
1361  m_pImpl->SetModified();
1362  }
1363 }
1364 
1366 {
1367  return m_pImpl->m_bIsSecureConnection;
1368 }
1369 
1371 {
1372  if(m_pImpl->m_bIsSecureConnection != bSet)
1373  {
1374  m_pImpl->m_bIsSecureConnection = bSet;
1375  m_pImpl->SetModified();
1376  }
1377 }
1378 
1380 {
1381  return m_pImpl->m_bIsAuthentication;
1382 }
1383 
1385 {
1386  if(m_pImpl->m_bIsAuthentication != bSet)
1387  {
1388  m_pImpl->m_bIsAuthentication = bSet;
1389  m_pImpl->SetModified();
1390  }
1391 }
1392 
1394 {
1395  return m_pImpl->m_sMailUserName;
1396 }
1397 
1398 void SwMailMergeConfigItem::SetMailUserName(const OUString& rName)
1399 {
1400  if(m_pImpl->m_sMailUserName != rName)
1401  {
1402  m_pImpl->m_sMailUserName = rName;
1403  m_pImpl->SetModified();
1404  }
1405 }
1406 
1408 {
1409  return m_pImpl->m_sMailPassword;
1410 }
1411 
1412 void SwMailMergeConfigItem::SetMailPassword(const OUString& rPassword)
1413 {
1414  if(m_pImpl->m_sMailPassword != rPassword)
1415  {
1416  m_pImpl->m_sMailPassword = rPassword;
1417  m_pImpl->SetModified();
1418  }
1419 }
1420 
1422 {
1423  return m_pImpl->m_bIsSMPTAfterPOP;
1424 }
1425 
1427 {
1428  if( m_pImpl->m_bIsSMPTAfterPOP != bSet)
1429  {
1430  m_pImpl->m_bIsSMPTAfterPOP = bSet;
1431  m_pImpl->SetModified();
1432  }
1433 }
1434 
1436 {
1437  return m_pImpl->m_sInServerName;
1438 }
1439 
1440 void SwMailMergeConfigItem::SetInServerName(const OUString& rServer)
1441 {
1442  if(m_pImpl->m_sInServerName != rServer)
1443  {
1444  m_pImpl->m_sInServerName = rServer;
1445  m_pImpl->SetModified();
1446  }
1447 }
1448 
1450 {
1451  // provide appropriate TCP port as user toggles between POP/IMAP if current port is one of the defaults
1452  switch (m_pImpl->m_nInServerPort)
1453  {
1454  case POP_SECURE_PORT:
1455  case POP_PORT:
1456  case IMAP_SECURE_PORT:
1457  case IMAP_PORT:
1458  if ( m_pImpl->m_bInServerPOP )
1459  return m_pImpl->m_bIsSecureConnection ? POP_SECURE_PORT : POP_PORT;
1460  else
1461  return m_pImpl->m_bIsSecureConnection ? IMAP_SECURE_PORT : IMAP_PORT;
1462  break;
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 //This implements XSelectionChangeListener and XDispatch because the
1597 //broadcaster uses this combo to determine if to send the database-changed
1598 //update. Its probably that listening to statusChanged at some other level is
1599 //equivalent to this. See the other call to SwXDispatch::GetDBChangeURL for
1600 //the broadcaster of the event.
1601 class DBChangeListener : public cppu::WeakImplHelper<css::view::XSelectionChangeListener, css::frame::XDispatch>
1602 {
1604 public:
1606  : m_rParent(rParent)
1607  {
1608  }
1609 
1610  virtual void SAL_CALL selectionChanged(const EventObject& /*rEvent*/) override
1611  {
1612  }
1613 
1614  virtual void SAL_CALL disposing(const EventObject&) override
1615  {
1616  m_rParent.stopDBChangeListening();
1617  }
1618 
1619  virtual void SAL_CALL dispatch(const css::util::URL& rURL, const css::uno::Sequence< css::beans::PropertyValue >& /*rArgs*/) override
1620  {
1621  if (rURL.Complete.equalsAscii(SwXDispatch::GetDBChangeURL()))
1622  m_rParent.updateCurrentDBDataFromDocument();
1623  }
1624 
1625  virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener >&, const css::util::URL&) override
1626  {
1627  }
1628 
1629  virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener >&, const css::util::URL&) override
1630  {
1631  }
1632 };
1633 
1635 {
1636  if (m_xDBChangedListener.is())
1637  {
1638  uno::Reference<view::XSelectionSupplier> xSupplier = m_pSourceView->GetUNOObject();
1639  xSupplier->removeSelectionChangeListener(m_xDBChangedListener);
1640  m_xDBChangedListener.clear();
1641  }
1642 
1643  m_pSourceView = pView;
1644 
1645  if (!m_pSourceView)
1646  return;
1647 
1648  std::vector<OUString> aDBNameList;
1649  std::vector<OUString> aAllDBNames;
1650  m_pSourceView->GetWrtShell().GetAllUsedDB( aDBNameList, &aAllDBNames );
1651  if(!aDBNameList.empty())
1652  {
1653  // if fields are available there is usually no need of an addressblock and greeting
1654  if(!m_pImpl->m_bUserSettingWereOverwritten)
1655  {
1656  if( m_pImpl->m_bIsAddressBlock
1657  || m_pImpl->m_bIsGreetingLineInMail
1658  || m_pImpl->m_bIsGreetingLine )
1659  {
1660  //store user settings
1661  m_pImpl->m_bUserSettingWereOverwritten = true;
1662  m_pImpl->m_bIsAddressBlock_LastUserSetting = m_pImpl->m_bIsAddressBlock;
1663  m_pImpl->m_bIsGreetingLineInMail_LastUserSetting = m_pImpl->m_bIsGreetingLineInMail;
1664  m_pImpl->m_bIsGreetingLine_LastUserSetting = m_pImpl->m_bIsGreetingLine;
1665 
1666  //set all to false
1667  m_pImpl->m_bIsAddressBlock = false;
1668  m_pImpl->m_bIsGreetingLineInMail = false;
1669  m_pImpl->m_bIsGreetingLine = false;
1670 
1671  m_pImpl->SetModified();
1672  }
1673  }
1674  }
1675  else if( m_pImpl->m_bUserSettingWereOverwritten )
1676  {
1677  //restore last user settings:
1678  m_pImpl->m_bIsAddressBlock = m_pImpl->m_bIsAddressBlock_LastUserSetting;
1679  m_pImpl->m_bIsGreetingLineInMail = m_pImpl->m_bIsGreetingLineInMail_LastUserSetting;
1680  m_pImpl->m_bIsGreetingLine = m_pImpl->m_bIsGreetingLine_LastUserSetting;
1681 
1682  m_pImpl->m_bUserSettingWereOverwritten = false;
1683  }
1684 
1685  if (!m_xDBChangedListener.is())
1686  {
1687  m_xDBChangedListener.set(new DBChangeListener(*this));
1688  }
1689 
1690  uno::Reference<view::XSelectionSupplier> xSupplier = m_pSourceView->GetUNOObject();
1691  xSupplier->addSelectionChangeListener(m_xDBChangedListener);
1692 }
1693 
1695 {
1696  m_pImpl->SetCurrentAddressBlockIndex( nSet );
1697 }
1698 
1700 {
1701  return m_pImpl->GetCurrentAddressBlockIndex();
1702 }
1703 
1704 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
virtual void SAL_CALL dispatch(const css::util::URL &rURL, const css::uno::Sequence< css::beans::PropertyValue > &) override
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 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:2987
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:1929
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
void SetMailPassword(const OUString &rPassword)
void SetInServerPOP(bool bSet)
static const sal_Char * GetDBChangeURL()
const char cDBColumnAssignments[]
const char cDataTableName[]
Reference< XColumnsSupplier > m_xColumnsSupplier
void SetSMTPAfterPOP(bool bSet)
virtual void SAL_CALL disposing(const EventObject &) override
bool UCB_IsFile(const OUString &rURL)
SwWrtShell & GetWrtShell() const
Definition: view.hxx:400
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
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
SwMailMergeConfigItem & m_rParent
bool IsRecordExcluded(sal_Int32 nRecord) 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)
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:313
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
void ExcludeRecord(sal_Int32 nRecord, bool bExclude)
void SetAddressBlocks(const Sequence< OUString > &rBlocks, bool bConvertFromConfig=false)
int i
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:1906
void SetAddressBlock(bool bSet)
const SwDBData & GetDBDesc() const
Definition: edfld.cxx:303
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:190
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
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)
DBChangeListener(SwMailMergeConfigItem &rParent)
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
virtual void SAL_CALL selectionChanged(const EventObject &) override
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)
virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener > &, const css::util::URL &) override
void SAL_CALL first(const css::awt::SpinEvent &rEvent) override
#define SAL_WARN(area, stream)
css::view::XSelectionSupplier * GetUNOObject()
Definition: view0.cxx:119
bool IsAddressBlock() const
void SetCurrentGreeting(SwMailMergeConfigItem::Gender eType, sal_Int32 nIndex)
sal_Int32 GetCurrentAddressBlockIndex() const
const char cAddressDataAssignments[]
OUString & GetFilter() const
OUString const & GetMailPassword() const
bool IsMailReplyTo() const
virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener > &, const css::util::URL &) override
bool IsAddressFieldsAssigned() const
OUString sCommand
Definition: swdbdata.hxx:31
virtual void ImplCommit() override
Sequence< OUString > aDBColumnAssignments
std::vector< DBAddressDataAssignment > m_aAddressDataAssignments
#define SECURE_PORT
OUString const & GetMailUserName() const
Definition: view.hxx:146
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)