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 const char cAddressDataAssignments[] = "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_pSourceView(nullptr),
692  m_pTargetView(nullptr)
693 {
694 }
695 
697 {
698  if (m_xDBChangedListener.is())
699  {
700  uno::Reference<view::XSelectionSupplier> xSupplier = m_pSourceView->GetUNOObject();
701  xSupplier->removeSelectionChangeListener(m_xDBChangedListener);
702  m_xDBChangedListener.clear();
703  }
704 }
705 
707 {
708  const SwDBData& rDBData = m_pSourceView->GetWrtShell().GetDBDesc();
709  SetCurrentDBData(rDBData);
710 }
711 
713 {
715 }
716 
718 {
719  if(m_pImpl->IsModified())
720  m_pImpl->Commit();
721 }
722 
723 const std::vector<std::pair<OUString, int>>& SwMailMergeConfigItem::GetDefaultAddressHeaders() const
724 {
725  return m_pImpl->m_AddressHeaderSA;
726 }
727 
729  const Sequence< OUString>& rBlocks)
730 {
731  m_pImpl->SetAddressBlocks(rBlocks);
732 }
733 
735 {
736  return m_pImpl->GetAddressBlocks();
737 }
738 
740 {
741  return m_pImpl->m_bIsAddressBlock && IsOutputToLetter();
742 }
743 
745 {
746  m_pImpl->m_bUserSettingWereOverwritten = false;
747  if(m_pImpl->m_bIsAddressBlock != bSet)
748  {
749  m_pImpl->m_bIsAddressBlock = bSet;
750  m_pImpl->SetModified();
751  }
752 }
753 
755 {
756  return m_pImpl->m_bIsHideEmptyParagraphs;
757 }
758 
760 {
761  if(m_pImpl->m_bIsHideEmptyParagraphs != bSet)
762  {
763  m_pImpl->m_bIsHideEmptyParagraphs = bSet;
764  m_pImpl->SetModified();
765  }
766 }
767 
769 {
770  return m_pImpl->m_bIncludeCountry;
771 }
772 
774 {
775  return m_pImpl->m_sExcludeCountry;
776 }
777 
778 void SwMailMergeConfigItem::SetCountrySettings(bool bSet, const OUString& rCountry)
779 {
780  if(m_pImpl->m_sExcludeCountry != rCountry ||
781  m_pImpl->m_bIncludeCountry != bSet)
782  {
783  m_pImpl->m_bIncludeCountry = bSet;
784  m_pImpl->m_sExcludeCountry = bSet ? rCountry : OUString();
785  m_pImpl->SetModified();
786  }
787 }
788 
790  Reference< XDataSource> const & xSource,
791  const SharedConnection& rConnection,
792  Reference< XColumnsSupplier> const & xColumnsSupplier,
793  const SwDBData& rDBData)
794 {
795  m_pImpl->m_xSource = xSource ;
796  m_pImpl->m_xConnection = rConnection ;
797  m_pImpl->m_xColumnsSupplier = xColumnsSupplier;
798  m_pImpl->m_aDBData = rDBData;
799  m_pImpl->m_xResultSet = nullptr;
800  m_pImpl->m_nResultSetCursorPos = 0;
801  m_pImpl->SetModified();
802 }
803 
805 {
806  return m_pImpl->m_xSource;
807 }
808 
810 {
811  return m_pImpl->m_xConnection;
812 }
813 
814 Reference< XColumnsSupplier> const & SwMailMergeConfigItem::GetColumnsSupplier()
815 {
816  if(!m_pImpl->m_xColumnsSupplier.is() && m_pImpl->m_xConnection.is())
817  {
818  m_pImpl->m_xColumnsSupplier = SwDBManager::GetColumnSupplier(m_pImpl->m_xConnection,
819  m_pImpl->m_aDBData.sCommand,
820  m_pImpl->m_aDBData.nCommandType == CommandType::TABLE ?
822  }
823  return m_pImpl->m_xColumnsSupplier;
824 }
825 
827 {
828  return m_pImpl->m_aDBData;
829 }
830 
832 {
833  if(m_pImpl->m_aDBData != rDBData)
834  {
835  m_pImpl->m_aDBData = rDBData;
836  m_pImpl->m_xConnection.clear();
837  m_pImpl->m_xSource = nullptr;
838  m_pImpl->m_xResultSet = nullptr;
839  m_pImpl->m_xColumnsSupplier = nullptr;
840  m_pImpl->SetModified();
841  }
842 }
843 
844 Reference< XResultSet> const & SwMailMergeConfigItem::GetResultSet() const
845 {
846  if(!m_pImpl->m_xConnection.is() && !m_pImpl->m_aDBData.sDataSource.isEmpty())
847  {
848  m_pImpl->m_xConnection.reset(
849  SwDBManager::GetConnection(m_pImpl->m_aDBData.sDataSource, m_pImpl->m_xSource, m_pSourceView),
851  );
852  }
853  if(!m_pImpl->m_xResultSet.is() && m_pImpl->m_xConnection.is())
854  {
855  try
856  {
857  Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
858 
859  Reference<XRowSet> xRowSet( xMgr->createInstance("com.sun.star.sdb.RowSet"), UNO_QUERY );
860  Reference<XPropertySet> xRowProperties(xRowSet, UNO_QUERY);
861  xRowProperties->setPropertyValue("DataSourceName", makeAny(m_pImpl->m_aDBData.sDataSource));
862  xRowProperties->setPropertyValue("Command", makeAny(m_pImpl->m_aDBData.sCommand));
863  xRowProperties->setPropertyValue("CommandType", makeAny(m_pImpl->m_aDBData.nCommandType));
864  xRowProperties->setPropertyValue("FetchSize", makeAny(sal_Int32(10)));
865  xRowProperties->setPropertyValue("ActiveConnection", makeAny(m_pImpl->m_xConnection.getTyped()));
866  try
867  {
868  xRowProperties->setPropertyValue("ApplyFilter", makeAny(!m_pImpl->m_sFilter.isEmpty()));
869  xRowProperties->setPropertyValue("Filter", makeAny(m_pImpl->m_sFilter));
870  }
871  catch (const Exception&)
872  {
873  TOOLS_WARN_EXCEPTION("sw.ui", "");
874  }
875  xRowSet->execute();
876  m_pImpl->m_xResultSet = xRowSet.get();
877  m_pImpl->m_xResultSet->first();
878  m_pImpl->m_nResultSetCursorPos = 1;
879  }
880  catch (const Exception&)
881  {
882  TOOLS_WARN_EXCEPTION("sw.ui", "SwMailMergeConfigItem::GetResultSet()");
883  }
884  }
885  return m_pImpl->m_xResultSet;
886 }
887 
889 {
890  m_pImpl->m_xConnection.clear();
891  if(m_pImpl->m_xResultSet.is())
892  {
893  ::comphelper::disposeComponent( m_pImpl->m_xResultSet );
894  }
895 }
896 
898 {
899  return m_pImpl->m_sFilter;
900 }
901 
902 void SwMailMergeConfigItem::SetFilter(OUString const & rFilter)
903 {
904  if(m_pImpl->m_sFilter == rFilter)
905  return;
906 
907  m_pImpl->m_sFilter = rFilter;
908  m_pImpl->SetModified();
909  Reference<XPropertySet> xRowProperties(m_pImpl->m_xResultSet, UNO_QUERY);
910  if(!xRowProperties.is())
911  return;
912 
913  try
914  {
915  xRowProperties->setPropertyValue("ApplyFilter", makeAny(!m_pImpl->m_sFilter.isEmpty()));
916  xRowProperties->setPropertyValue("Filter", makeAny(m_pImpl->m_sFilter));
917  uno::Reference<XRowSet> xRowSet( m_pImpl->m_xResultSet, UNO_QUERY_THROW );
918  xRowSet->execute();
919  }
920  catch (const Exception&)
921  {
922  TOOLS_WARN_EXCEPTION("sw.ui", "SwMailMergeConfigItem::SetFilter()");
923  }
924 }
925 
926 sal_Int32 SwMailMergeConfigItem::MoveResultSet(sal_Int32 nTarget)
927 {
928  if(!m_pImpl->m_xResultSet.is())
929  GetResultSet();
930  if(m_pImpl->m_xResultSet.is())
931  {
932  try
933  {
934  //no action if the resultset is already at the right position
935  if(m_pImpl->m_xResultSet->getRow() != nTarget)
936  {
937  if(nTarget > 0)
938  {
939  bool bMoved = m_pImpl->m_xResultSet->absolute(nTarget);
940  if(!bMoved)
941  {
942  if(nTarget > 1)
943  m_pImpl->m_xResultSet->last();
944  else if(nTarget == 1)
945  m_pImpl->m_xResultSet->first();
946  }
947  }
948  else if(nTarget == -1)
949  m_pImpl->m_xResultSet->last();
950  m_pImpl->m_nResultSetCursorPos = m_pImpl->m_xResultSet->getRow();
951  }
952  }
953  catch (const Exception&)
954  {
955  }
956  }
957  return m_pImpl->m_nResultSetCursorPos;
958 }
959 
960 bool SwMailMergeConfigItem::IsResultSetFirstLast(bool& bIsFirst, bool& bIsLast)
961 {
962  bool bRet = false;
963  if(!m_pImpl->m_xResultSet.is())
964  GetResultSet();
965  if(m_pImpl->m_xResultSet.is())
966  {
967  try
968  {
969  bIsFirst = m_pImpl->m_xResultSet->isFirst();
970  bIsLast = m_pImpl->m_xResultSet->isLast();
971  bRet = true;
972  }
973  catch (const Exception&)
974  {
975  }
976  }
977  return bRet;
978 }
979 
981 {
982  return m_pImpl->m_nResultSetCursorPos;
983 }
984 
985 bool SwMailMergeConfigItem::IsRecordExcluded(sal_Int32 nRecord) const
986  { return m_aExcludedRecords.find(nRecord) != m_aExcludedRecords.end(); }
987 
988 void SwMailMergeConfigItem::ExcludeRecord(sal_Int32 nRecord, bool bExclude)
989 {
990  if(bExclude)
991  m_aExcludedRecords.insert(nRecord);
992  else
993  m_aExcludedRecords.erase(nRecord);
994 }
995 
996 uno::Sequence<uno::Any> SwMailMergeConfigItem::GetSelection() const
997 {
998  if(!m_pImpl->m_xResultSet.is())
999  GetResultSet();
1000  if(!m_pImpl->m_xResultSet.is())
1001  return {};
1002  m_pImpl->m_xResultSet->last();
1003  sal_Int32 nResultSetSize = m_pImpl->m_xResultSet->getRow()+1;
1004  std::vector<uno::Any> vResult;
1005  vResult.reserve(nResultSetSize);
1006  for(sal_Int32 nIdx=1; nIdx<nResultSetSize;++nIdx)
1007  if(!IsRecordExcluded(nIdx))
1008  vResult.push_back(uno::makeAny<sal_Int32>(nIdx));
1009  return comphelper::containerToSequence(vResult);
1010 }
1011 
1012 
1013 const uno::Sequence< OUString>&
1015 {
1016  return m_pImpl->m_aSavedDocuments;
1017 }
1018 
1020 {
1021  return m_pImpl->m_bIsOutputToLetter || !IsMailAvailable();
1022 }
1023 
1025 {
1026  if(m_pImpl->m_bIsOutputToLetter != bSet)
1027  {
1028  m_pImpl->m_bIsOutputToLetter = bSet;
1029  m_pImpl->SetModified();
1030  }
1031 }
1032 
1034 {
1035  return bInEMail ?
1036  m_pImpl->m_bIsIndividualGreetingLineInMail :
1037  m_pImpl->m_bIsIndividualGreetingLine;
1038 }
1039 
1041  bool bSet, bool bInEMail)
1042 {
1043  if(bInEMail)
1044  {
1045  if(m_pImpl->m_bIsIndividualGreetingLineInMail != bSet)
1046  {
1047  m_pImpl->m_bIsIndividualGreetingLineInMail = bSet;
1048  m_pImpl->SetModified();
1049  }
1050  }
1051  else
1052  {
1053  if(m_pImpl->m_bIsIndividualGreetingLine != bSet)
1054  {
1055  m_pImpl->m_bIsIndividualGreetingLine = bSet;
1056  m_pImpl->SetModified();
1057  }
1058  }
1059 }
1060 
1061 bool SwMailMergeConfigItem::IsGreetingLine(bool bInEMail) const
1062 {
1063  return bInEMail ? m_pImpl->m_bIsGreetingLineInMail : m_pImpl->m_bIsGreetingLine;
1064 }
1065 
1066 void SwMailMergeConfigItem::SetGreetingLine(bool bSet, bool bInEMail)
1067 {
1068  m_pImpl->m_bUserSettingWereOverwritten = false;
1069  if(bInEMail)
1070  {
1071  if(m_pImpl->m_bIsGreetingLineInMail != bSet)
1072  {
1073  m_pImpl->m_bIsGreetingLineInMail = bSet;
1074  m_pImpl->SetModified();
1075  }
1076  }
1077  else
1078  {
1079  if(m_pImpl->m_bIsGreetingLine != bSet)
1080  {
1081  m_pImpl->m_bIsGreetingLine = bSet;
1082  m_pImpl->SetModified();
1083  }
1084  }
1085 }
1086 
1088  Gender eType ) const
1089 {
1090  return m_pImpl->GetGreetings(eType);
1091 }
1092 
1094  Gender eType, const Sequence< OUString>& rSetGreetings)
1095 {
1096  m_pImpl->SetGreetings( eType, rSetGreetings);
1097 }
1098 
1100  SwMailMergeConfigItem::Gender eType) const
1101 {
1102  return m_pImpl->GetCurrentGreeting(eType);
1103 }
1104 
1106 {
1107  m_pImpl->SetCurrentGreeting(eType, nIndex);
1108 }
1109 
1111 {
1112  return m_pImpl->m_sFemaleGenderValue;
1113 }
1114 
1116 {
1117  if( m_pImpl->m_sFemaleGenderValue != rValue )
1118  {
1119  m_pImpl->m_sFemaleGenderValue = rValue;
1120  m_pImpl->SetModified();
1121  }
1122 }
1123 
1125  const SwDBData& rDBData ) const
1126 {
1127  Sequence< OUString> aRet;
1128  auto aAssignIter = std::find_if(m_pImpl->m_aAddressDataAssignments.begin(), m_pImpl->m_aAddressDataAssignments.end(),
1129  [&rDBData](const DBAddressDataAssignment& rAssignment) { return rAssignment.aDBData == rDBData; });
1130  if (aAssignIter != m_pImpl->m_aAddressDataAssignments.end())
1131  {
1132  aRet = aAssignIter->aDBColumnAssignments;
1133  }
1134  return aRet;
1135 }
1136 
1137 // returns the name that is assigned as e-mail column of the current data base
1138 OUString SwMailMergeConfigItem::GetAssignedColumn(sal_uInt32 nColumn) const
1139 {
1140  OUString sRet;
1141  Sequence< OUString> aAssignment = GetColumnAssignment( m_pImpl->m_aDBData );
1142  if(aAssignment.getLength() > sal::static_int_cast< sal_Int32, sal_uInt32>(nColumn) && !aAssignment[nColumn].isEmpty())
1143  sRet = aAssignment[nColumn];
1144  else if(nColumn < m_pImpl->m_AddressHeaderSA.size())
1145  sRet = m_pImpl->m_AddressHeaderSA[nColumn].first;
1146  return sRet;
1147 }
1148 
1150  const Sequence< OUString>& rList)
1151 {
1152  auto aAssignIter = std::find_if(m_pImpl->m_aAddressDataAssignments.begin(), m_pImpl->m_aAddressDataAssignments.end(),
1153  [&rDBData](const DBAddressDataAssignment& rAssignment) { return rAssignment.aDBData == rDBData; });
1154  if (aAssignIter != m_pImpl->m_aAddressDataAssignments.end())
1155  {
1156  if(aAssignIter->aDBColumnAssignments != rList)
1157  {
1158  aAssignIter->aDBColumnAssignments = rList;
1159  aAssignIter->bColumnAssignmentsChanged = true;
1160  }
1161  }
1162  else
1163  {
1164  DBAddressDataAssignment aAssignment;
1165  aAssignment.aDBData = rDBData;
1166  aAssignment.aDBColumnAssignments = rList;
1167  aAssignment.bColumnAssignmentsChanged = true;
1168  m_pImpl->m_aAddressDataAssignments.push_back(aAssignment);
1169  }
1170  m_pImpl->SetModified();
1171 }
1172 
1174 {
1175  bool bResult = true;
1176  Reference< XResultSet> xResultSet = GetResultSet();
1177  uno::Reference< XColumnsSupplier > xColsSupp( xResultSet, UNO_QUERY );
1178  if(!xColsSupp.is())
1179  return false;
1180  uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
1181 
1182  const std::vector<std::pair<OUString, int>>& rHeaders = GetDefaultAddressHeaders();
1183  Sequence< OUString> aAssignment =
1185  const OUString* pAssignment = aAssignment.getConstArray();
1186  const Sequence< OUString> aBlocks = GetAddressBlocks();
1187 
1188  if(aBlocks.getLength() <= m_pImpl->GetCurrentAddressBlockIndex())
1189  return false;
1190  SwAddressIterator aIter(aBlocks[m_pImpl->GetCurrentAddressBlockIndex()]);
1191  while(aIter.HasMore())
1192  {
1193  SwMergeAddressItem aItem = aIter.Next();
1194  if(aItem.bIsColumn)
1195  {
1196  OUString sConvertedColumn = aItem.sText;
1197  auto nSize = std::min(sal_uInt32(rHeaders.size()), sal_uInt32(aAssignment.getLength()));
1198  for(sal_uInt32 nColumn = 0; nColumn < nSize; ++nColumn)
1199  {
1200  if (rHeaders[nColumn].first == aItem.sText &&
1201  !pAssignment[nColumn].isEmpty())
1202  {
1203  sConvertedColumn = pAssignment[nColumn];
1204  break;
1205  }
1206  }
1207  //find out if the column exists in the data base
1208  if(!xCols->hasByName(sConvertedColumn))
1209  {
1210  bResult = false;
1211  break;
1212  }
1213  }
1214  }
1215  return bResult;
1216 }
1217 
1219 {
1220  bool bResult = true;
1221 
1222  if(!IsIndividualGreeting(false))
1223  return true;
1224 
1225  Reference< XResultSet> xResultSet = GetResultSet();
1226  uno::Reference< XColumnsSupplier > xColsSupp( xResultSet, UNO_QUERY );
1227  if(!xColsSupp.is())
1228  return false;
1229  const std::vector<std::pair<OUString, int>>& rHeaders = GetDefaultAddressHeaders();
1230  uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
1231 
1232  Sequence< OUString> aAssignment =
1234  const OUString* pAssignment = aAssignment.getConstArray();
1235 
1237  sal_Int32 nCurrentFemale = GetCurrentGreeting(SwMailMergeConfigItem::FEMALE);
1239  sal_Int32 nCurrentMale = GetCurrentGreeting(SwMailMergeConfigItem::MALE);
1240  OUString sMale, sFemale;
1241  if(rFemaleEntries.getLength() > nCurrentFemale)
1242  sFemale = rFemaleEntries[nCurrentFemale];
1243  if(rMaleEntries.getLength() > nCurrentMale)
1244  sMale = rMaleEntries[nCurrentMale];
1245 
1246  OUString sAddress = sFemale + sMale;
1247  SwAddressIterator aIter(sAddress);
1248  while(aIter.HasMore())
1249  {
1250  SwMergeAddressItem aItem = aIter.Next();
1251  if(aItem.bIsColumn)
1252  {
1253  OUString sConvertedColumn = aItem.sText;
1254  auto nSize = std::min(sal_uInt32(rHeaders.size()), sal_uInt32(aAssignment.getLength()));
1255  for(sal_uInt32 nColumn = 0; nColumn < nSize; ++nColumn)
1256  {
1257  if (rHeaders[nColumn].first == aItem.sText &&
1258  !pAssignment[nColumn].isEmpty())
1259  {
1260  sConvertedColumn = pAssignment[nColumn];
1261  break;
1262  }
1263  }
1264  //find out if the column exists in the data base
1265  if(!xCols->hasByName(sConvertedColumn))
1266  {
1267  bResult = false;
1268  break;
1269  }
1270  }
1271  }
1272  return bResult;
1273 }
1274 
1276 {
1277  return m_pImpl->m_sMailDisplayName;
1278 }
1279 
1281 {
1282  if(m_pImpl->m_sMailDisplayName != rName)
1283  {
1284  m_pImpl->m_sMailDisplayName = rName;
1285  m_pImpl->SetModified();
1286  }
1287 }
1288 
1290 {
1291  return m_pImpl->m_sMailAddress;
1292 }
1293 
1294 void SwMailMergeConfigItem::SetMailAddress(const OUString& rAddress)
1295 {
1296  if(m_pImpl->m_sMailAddress != rAddress )
1297  {
1298  m_pImpl->m_sMailAddress = rAddress;
1299  m_pImpl->SetModified();
1300  }
1301 }
1302 
1304 {
1305  return m_pImpl->m_bIsMailReplyTo;
1306 }
1307 
1309 {
1310  if(m_pImpl->m_bIsMailReplyTo != bSet)
1311  {
1312  m_pImpl->m_bIsMailReplyTo = bSet;
1313  m_pImpl->SetModified();
1314  }
1315 }
1316 
1318 {
1319  return m_pImpl->m_sMailReplyTo;
1320 }
1321 
1322 void SwMailMergeConfigItem::SetMailReplyTo(const OUString& rReplyTo)
1323 {
1324  if(m_pImpl->m_sMailReplyTo != rReplyTo)
1325  {
1326  m_pImpl->m_sMailReplyTo = rReplyTo;
1327  m_pImpl->SetModified();
1328  }
1329 }
1330 
1332 {
1333  return m_pImpl->m_sMailServer;
1334 }
1335 
1336 void SwMailMergeConfigItem::SetMailServer(const OUString& rAddress)
1337 {
1338  if(m_pImpl->m_sMailServer != rAddress)
1339  {
1340  m_pImpl->m_sMailServer = rAddress;
1341  m_pImpl->SetModified();
1342  }
1343 }
1344 
1346 {
1347  // provide appropriate TCP port, based on SSL/STARTTLS status, if current port is one of the defaults
1348  switch (m_pImpl->m_nMailPort)
1349  {
1350  case SECURE_PORT:
1351  case DEFAULT_PORT:
1352  return m_pImpl->m_bIsSecureConnection ? SECURE_PORT : DEFAULT_PORT;
1353  break;
1354  default:
1355  return m_pImpl->m_nMailPort;
1356  }
1357 }
1358 
1360 {
1361  if(m_pImpl->m_nMailPort != nSet)
1362  {
1363  m_pImpl->m_nMailPort = nSet;
1364  m_pImpl->SetModified();
1365  }
1366 }
1367 
1369 {
1370  return m_pImpl->m_bIsSecureConnection;
1371 }
1372 
1374 {
1375  if(m_pImpl->m_bIsSecureConnection != bSet)
1376  {
1377  m_pImpl->m_bIsSecureConnection = bSet;
1378  m_pImpl->SetModified();
1379  }
1380 }
1381 
1383 {
1384  return m_pImpl->m_bIsAuthentication;
1385 }
1386 
1388 {
1389  if(m_pImpl->m_bIsAuthentication != bSet)
1390  {
1391  m_pImpl->m_bIsAuthentication = bSet;
1392  m_pImpl->SetModified();
1393  }
1394 }
1395 
1397 {
1398  return m_pImpl->m_sMailUserName;
1399 }
1400 
1401 void SwMailMergeConfigItem::SetMailUserName(const OUString& rName)
1402 {
1403  if(m_pImpl->m_sMailUserName != rName)
1404  {
1405  m_pImpl->m_sMailUserName = rName;
1406  m_pImpl->SetModified();
1407  }
1408 }
1409 
1411 {
1412  return m_pImpl->m_sMailPassword;
1413 }
1414 
1415 void SwMailMergeConfigItem::SetMailPassword(const OUString& rPassword)
1416 {
1417  if(m_pImpl->m_sMailPassword != rPassword)
1418  {
1419  m_pImpl->m_sMailPassword = rPassword;
1420  m_pImpl->SetModified();
1421  }
1422 }
1423 
1425 {
1426  return m_pImpl->m_bIsSMPTAfterPOP;
1427 }
1428 
1430 {
1431  if( m_pImpl->m_bIsSMPTAfterPOP != bSet)
1432  {
1433  m_pImpl->m_bIsSMPTAfterPOP = bSet;
1434  m_pImpl->SetModified();
1435  }
1436 }
1437 
1439 {
1440  return m_pImpl->m_sInServerName;
1441 }
1442 
1443 void SwMailMergeConfigItem::SetInServerName(const OUString& rServer)
1444 {
1445  if(m_pImpl->m_sInServerName != rServer)
1446  {
1447  m_pImpl->m_sInServerName = rServer;
1448  m_pImpl->SetModified();
1449  }
1450 }
1451 
1453 {
1454  // provide appropriate TCP port as user toggles between POP/IMAP if current port is one of the defaults
1455  switch (m_pImpl->m_nInServerPort)
1456  {
1457  case POP_SECURE_PORT:
1458  case POP_PORT:
1459  case IMAP_SECURE_PORT:
1460  case IMAP_PORT:
1461  if ( m_pImpl->m_bInServerPOP )
1462  return m_pImpl->m_bIsSecureConnection ? POP_SECURE_PORT : POP_PORT;
1463  else
1464  return m_pImpl->m_bIsSecureConnection ? IMAP_SECURE_PORT : IMAP_PORT;
1465  break;
1466  default:
1467  return m_pImpl->m_nInServerPort;
1468  }
1469 }
1470 
1472 {
1473  if( m_pImpl->m_nInServerPort != nSet)
1474  {
1475  m_pImpl->m_nInServerPort = nSet;
1476  m_pImpl->SetModified();
1477  }
1478 }
1479 
1481 {
1482  return m_pImpl->m_bInServerPOP;
1483 }
1484 
1486 {
1487  if( m_pImpl->m_bInServerPOP != bSet)
1488  {
1489  m_pImpl->m_bInServerPOP = bSet;
1490  m_pImpl->SetModified();
1491  }
1492 }
1493 
1495 {
1496  return m_pImpl->m_sInServerUserName;
1497 }
1498 
1500 {
1501  if( m_pImpl->m_sInServerUserName != rName)
1502  {
1503  m_pImpl->m_sInServerUserName = rName;
1504  m_pImpl->SetModified();
1505  }
1506 }
1507 
1509 {
1510  return m_pImpl->m_sInServerPassword;
1511 }
1512 
1513 void SwMailMergeConfigItem::SetInServerPassword(const OUString& rPassword)
1514 {
1515  if(m_pImpl->m_sInServerPassword != rPassword)
1516  {
1517  m_pImpl->m_sInServerPassword = rPassword;
1518  m_pImpl->SetModified();
1519  }
1520 }
1521 
1523 {
1524  m_bGreetingInserted = false;
1525  m_bAddressInserted = false;
1526 }
1527 
1529 {
1530  return m_pImpl->m_bIsEMailSupported;
1531 }
1532 
1534 {
1535  m_pImpl->m_aMergeInfos.push_back(rInfo);
1536 }
1537 
1539 {
1540  assert(nDocument < m_pImpl->m_aMergeInfos.size());
1541  return m_pImpl->m_aMergeInfos[nDocument];
1542 }
1543 
1544 
1546 {
1547  if(m_pTargetView)
1548  return m_pImpl->m_aMergeInfos.size();
1549  else
1550  {
1551  sal_Int32 nRestore = GetResultSetPosition();
1552  MoveResultSet(-1);
1553  sal_Int32 nRet = GetResultSetPosition();
1554  MoveResultSet( nRestore );
1555  nRet -= m_aExcludedRecords.size();
1556  return nRet >= 0 ? nRet : 0;
1557  }
1558 }
1559 
1561 {
1562  SfxViewShell* pViewShell = SfxViewShell::GetFirst( false, checkSfxViewShell<SwView> );
1563  while(pViewShell)
1564  {
1565  if(pViewShell == pView)
1566  return pView;
1567 
1568  pViewShell = SfxViewShell::GetNext( *pViewShell, false, checkSfxViewShell<SwView> );
1569  }
1570  return nullptr;
1571 }
1572 
1574 {
1575  //make sure that the pointer is really valid - the document may have been closed manually
1576  if(m_pTargetView)
1577  {
1579  }
1580  return m_pTargetView;
1581 }
1582 
1584 {
1585  m_pTargetView = pView;
1586  //reset the document merge counter
1587  if(!m_pTargetView)
1588  {
1589  m_pImpl->m_aMergeInfos.clear();
1590  }
1591 }
1592 
1594 {
1596  return m_pSourceView;
1597 }
1598 
1599 namespace {
1600 
1601 //This implements XSelectionChangeListener and XDispatch because the
1602 //broadcaster uses this combo to determine if to send the database-changed
1603 //update. Its probably that listening to statusChanged at some other level is
1604 //equivalent to this. See the other call to SwXDispatch::GetDBChangeURL for
1605 //the broadcaster of the event.
1606 class DBChangeListener : public cppu::WeakImplHelper<css::view::XSelectionChangeListener, css::frame::XDispatch>
1607 {
1609 public:
1610  explicit DBChangeListener(SwMailMergeConfigItem& rParent)
1611  : m_rParent(rParent)
1612  {
1613  }
1614 
1615  virtual void SAL_CALL selectionChanged(const EventObject& /*rEvent*/) override
1616  {
1617  }
1618 
1619  virtual void SAL_CALL disposing(const EventObject&) override
1620  {
1621  m_rParent.stopDBChangeListening();
1622  }
1623 
1624  virtual void SAL_CALL dispatch(const css::util::URL& rURL, const css::uno::Sequence< css::beans::PropertyValue >& /*rArgs*/) override
1625  {
1626  if (rURL.Complete.equalsAscii(SwXDispatch::GetDBChangeURL()))
1627  m_rParent.updateCurrentDBDataFromDocument();
1628  }
1629 
1630  virtual void SAL_CALL addStatusListener(const css::uno::Reference< css::frame::XStatusListener >&, const css::util::URL&) override
1631  {
1632  }
1633 
1634  virtual void SAL_CALL removeStatusListener(const css::uno::Reference< css::frame::XStatusListener >&, const css::util::URL&) override
1635  {
1636  }
1637 };
1638 
1639 }
1640 
1642 {
1643  if (m_xDBChangedListener.is())
1644  {
1645  uno::Reference<view::XSelectionSupplier> xSupplier = m_pSourceView->GetUNOObject();
1646  xSupplier->removeSelectionChangeListener(m_xDBChangedListener);
1647  m_xDBChangedListener.clear();
1648  }
1649 
1650  m_pSourceView = pView;
1651 
1652  if (!m_pSourceView)
1653  return;
1654 
1655  std::vector<OUString> aDBNameList;
1656  std::vector<OUString> aAllDBNames;
1657  m_pSourceView->GetWrtShell().GetAllUsedDB( aDBNameList, &aAllDBNames );
1658  if(!aDBNameList.empty())
1659  {
1660  // if fields are available there is usually no need of an addressblock and greeting
1661  if(!m_pImpl->m_bUserSettingWereOverwritten)
1662  {
1663  if( m_pImpl->m_bIsAddressBlock
1664  || m_pImpl->m_bIsGreetingLineInMail
1665  || m_pImpl->m_bIsGreetingLine )
1666  {
1667  //store user settings
1668  m_pImpl->m_bUserSettingWereOverwritten = true;
1669  m_pImpl->m_bIsAddressBlock_LastUserSetting = m_pImpl->m_bIsAddressBlock;
1670  m_pImpl->m_bIsGreetingLineInMail_LastUserSetting = m_pImpl->m_bIsGreetingLineInMail;
1671  m_pImpl->m_bIsGreetingLine_LastUserSetting = m_pImpl->m_bIsGreetingLine;
1672 
1673  //set all to false
1674  m_pImpl->m_bIsAddressBlock = false;
1675  m_pImpl->m_bIsGreetingLineInMail = false;
1676  m_pImpl->m_bIsGreetingLine = false;
1677 
1678  m_pImpl->SetModified();
1679  }
1680  }
1681  }
1682  else if( m_pImpl->m_bUserSettingWereOverwritten )
1683  {
1684  //restore last user settings:
1685  m_pImpl->m_bIsAddressBlock = m_pImpl->m_bIsAddressBlock_LastUserSetting;
1686  m_pImpl->m_bIsGreetingLineInMail = m_pImpl->m_bIsGreetingLineInMail_LastUserSetting;
1687  m_pImpl->m_bIsGreetingLine = m_pImpl->m_bIsGreetingLine_LastUserSetting;
1688 
1689  m_pImpl->m_bUserSettingWereOverwritten = false;
1690  }
1691 
1692  if (!m_xDBChangedListener.is())
1693  {
1694  m_xDBChangedListener.set(new DBChangeListener(*this));
1695  }
1696 
1697  uno::Reference<view::XSelectionSupplier> xSupplier = m_pSourceView->GetUNOObject();
1698  xSupplier->addSelectionChangeListener(m_xDBChangedListener);
1699 }
1700 
1702 {
1703  m_pImpl->SetCurrentAddressBlockIndex( nSet );
1704 }
1705 
1707 {
1708  return m_pImpl->GetCurrentAddressBlockIndex();
1709 }
1710 
1711 /* 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:3107
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:1959
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)
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:398
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
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
::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:310
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:1936
void SetAddressBlock(bool bSet)
const SwDBData & GetDBDesc() const
Definition: edfld.cxx:300
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:165
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)
#define SAL_WARN(area, stream)
css::view::XSelectionSupplier * GetUNOObject()
Definition: view0.cxx:108
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
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
const char first[]
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)