LCOV - code coverage report
Current view: top level - sw/source/uibase/dbui - mmconfigitem.cxx (source / functions) Hit Total Coverage
Test: commit c8344322a7af75b84dd3ca8f78b05543a976dfd5 Lines: 177 833 21.2 %
Date: 2015-06-13 12:38:46 Functions: 18 113 15.9 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <mmconfigitem.hxx>
      21             : #include <swtypes.hxx>
      22             : #include <osl/diagnose.h>
      23             : #include <com/sun/star/uno/Any.hxx>
      24             : #include <com/sun/star/beans/PropertyValue.hpp>
      25             : #include <com/sun/star/sdb/XCompletedConnection.hpp>
      26             : #include <com/sun/star/sdbc/XDataSource.hpp>
      27             : #include <com/sun/star/sdbcx/XColumnsSupplier.hpp>
      28             : #include <com/sun/star/mail/MailServiceType.hpp>
      29             : #include <com/sun/star/mail/XMailService.hpp>
      30             : #include <com/sun/star/mail/MailServiceProvider.hpp>
      31             : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      32             : #include <com/sun/star/beans/XPropertySet.hpp>
      33             : #include <com/sun/star/sdbc/XRowSet.hpp>
      34             : #include <comphelper/processfactory.hxx>
      35             : #include <comphelper/types.hxx>
      36             : #include <com/sun/star/sdb/CommandType.hpp>
      37             : #include <rtl/instance.hxx>
      38             : #include <unotools/configitem.hxx>
      39             : #include <mailmergehelper.hxx>
      40             : #include <swunohelper.hxx>
      41             : #include <dbmgr.hxx>
      42             : #include <view.hxx>
      43             : #include <wrtsh.hxx>
      44             : #include <dbui.hrc>
      45             : #include <vector>
      46             : #include <unomid.h>
      47             : 
      48             : using namespace utl;
      49             : using namespace ::com::sun::star;
      50             : using namespace ::com::sun::star::uno;
      51             : using namespace ::com::sun::star::lang;
      52             : using namespace ::com::sun::star::beans;
      53             : using namespace ::com::sun::star::sdb;
      54             : using namespace ::com::sun::star::sdbc;
      55             : using namespace ::com::sun::star::sdbcx;
      56             : 
      57             : const char* cAddressDataAssignments     = "AddressDataAssignments";
      58             : const char* cDBColumnAssignments        = "DBColumnAssignments";
      59             : const char* cDataSourceName             = "DataSource/DataSourceName";
      60             : const char* cDataTableName              = "DataSource/DataTableName" ;
      61             : const char* cDataCommandType            = "DataSource/DataCommandType";
      62             : 
      63             : #define SECURE_PORT     465
      64             : #define DEFAULT_PORT    25
      65             : #define POP_PORT        110
      66             : 
      67          15 : struct DBAddressDataAssignment
      68             : {
      69             :     SwDBData                            aDBData;
      70             :     Sequence< OUString>           aDBColumnAssignments;
      71             :     //if loaded the name of the node has to be saved
      72             :     OUString                     sConfigNodeName;
      73             :     //all created or changed assignments need to be stored
      74             :     bool                                bColumnAssignmentsChanged;
      75             : 
      76           5 :     DBAddressDataAssignment() :
      77           5 :         bColumnAssignmentsChanged(false)
      78           5 :         {}
      79             : };
      80             : 
      81             : class SwMailMergeConfigItem_Impl : public utl::ConfigItem
      82             : {
      83             :     friend class SwMailMergeConfigItem;
      84             :     Reference< XDataSource>                 xSource;
      85             :     SharedConnection                        xConnection;
      86             :     Reference< XColumnsSupplier>            xColumnsSupplier;
      87             :     Reference< XStatement>                  xStatement;
      88             :     Reference< XResultSet>                  xResultSet;
      89             :     SwDBData                                aDBData;
      90             :     OUString                         sFilter;
      91             :     sal_Int32                               nResultSetCursorPos;
      92             : 
      93             :     ::std::vector<DBAddressDataAssignment>  aAddressDataAssignments;
      94             :     ::std::vector< OUString>         aAddressBlocks;
      95             :     sal_Int32                               nCurrentAddressBlock;
      96             :     bool                                bIsAddressBlock;
      97             :     bool                                bIsHideEmptyParagraphs;
      98             : 
      99             :     bool                                bIsOutputToLetter;
     100             :     bool                                bIncludeCountry;
     101             :     OUString                         sExcludeCountry;
     102             : 
     103             :     bool                                bIsGreetingLine;
     104             :     bool                                bIsIndividualGreetingLine;
     105             :     ::std::vector< OUString>         aFemaleGreetingLines;
     106             :     sal_Int32                               nCurrentFemaleGreeting;
     107             :     ::std::vector< OUString>         aMaleGreetingLines;
     108             :     sal_Int32                               nCurrentMaleGreeting;
     109             :     ::std::vector< OUString>         aNeutralGreetingLines;
     110             :     sal_Int32                               nCurrentNeutralGreeting;
     111             :     OUString                         sFemaleGenderValue;
     112             :     uno::Sequence< OUString>         aSavedDocuments;
     113             : 
     114             :     bool                                bIsGreetingLineInMail;
     115             :     bool                                bIsIndividualGreetingLineInMail;
     116             : 
     117             :     //mail settings
     118             :     OUString                         sMailDisplayName;
     119             :     OUString                         sMailAddress;
     120             :     OUString                         sMailReplyTo;
     121             :     OUString                         sMailServer;
     122             :     OUString                         sMailUserName;
     123             :     OUString                         sMailPassword;
     124             : 
     125             :     bool                                bIsSMPTAfterPOP;
     126             :     OUString                         sInServerName;
     127             :     sal_Int16                               nInServerPort;
     128             :     bool                                bInServerPOP;
     129             :     OUString                         sInServerUserName;
     130             :     OUString                         sInServerPassword;
     131             : 
     132             :     sal_Int16                               nMailPort;
     133             :     bool                                bIsMailReplyTo;
     134             :     bool                                bIsDefaultPort;
     135             :     bool                                bIsSecureConnection;
     136             :     bool                                bIsAuthentication;
     137             : 
     138             :     bool                                bIsEMailSupported;
     139             : 
     140             :     ResStringArray                          m_AddressHeaderSA;
     141             : 
     142             :     //these addresses are not stored in the configuration
     143             :     ::std::vector< SwDocMergeInfo >         aMergeInfos;
     144             : 
     145             :     //we do overwrite the usersettings in a special case
     146             :     //than we do remind the usersettings here
     147             :     bool                                bUserSettingWereOverwritten;
     148             :     bool                                bIsAddressBlock_LastUserSetting;
     149             :     bool                                bIsGreetingLineInMail_LastUserSetting;
     150             :     bool                                bIsGreetingLine_LastUserSetting;
     151             : 
     152             :     static const Sequence< OUString>&       GetPropertyNames();
     153             : 
     154             :     virtual void ImplCommit() SAL_OVERRIDE;
     155             : 
     156             : public:
     157             :     SwMailMergeConfigItem_Impl();
     158             :     virtual ~SwMailMergeConfigItem_Impl();
     159             : 
     160             :     virtual void Notify( const ::com::sun::star::uno::Sequence< OUString >& aPropertyNames ) SAL_OVERRIDE;
     161             :     const           Sequence< OUString>
     162             :                         GetAddressBlocks(bool bConvertToConfig = false) const;
     163             :     void                SetAddressBlocks(
     164             :                                 const Sequence< OUString>& rBlocks,
     165             :                                 bool bConvertFromConfig = false);
     166             :     const uno::Sequence< OUString>
     167             :                         GetGreetings(SwMailMergeConfigItem::Gender eType,
     168             :                                         bool bConvertToConfig = false) const;
     169             :     void                SetGreetings(SwMailMergeConfigItem::Gender eType,
     170             :                                     const uno::Sequence< OUString>& rBlocks,
     171             :                                     bool bConvertFromConfig = false);
     172             : 
     173             :     void                SetCurrentAddressBlockIndex( sal_Int32 nSet );
     174           0 :     sal_Int32           GetCurrentAddressBlockIndex() const
     175           0 :                         {   return nCurrentAddressBlock; }
     176             :     sal_Int32           GetCurrentGreeting(SwMailMergeConfigItem::Gender eType) const;
     177             :     void                SetCurrentGreeting(SwMailMergeConfigItem::Gender eType, sal_Int32 nIndex);
     178             : 
     179             : };
     180             : 
     181           5 : SwMailMergeConfigItem_Impl::SwMailMergeConfigItem_Impl() :
     182             :     ConfigItem("Office.Writer/MailMergeWizard", ConfigItemMode::ImmediateUpdate),
     183             :         nResultSetCursorPos(-1),
     184             :         nCurrentAddressBlock(0),
     185             :         bIsAddressBlock(true),
     186             :         bIsHideEmptyParagraphs(false),
     187             :         bIsOutputToLetter(true),
     188             :         bIncludeCountry(false),
     189             :         bIsGreetingLine(true),
     190             :         bIsIndividualGreetingLine(false),
     191             :         nCurrentFemaleGreeting(0),
     192             :         nCurrentMaleGreeting(0),
     193             :         nCurrentNeutralGreeting(0),
     194             :         bIsGreetingLineInMail(false),
     195             :         bIsIndividualGreetingLineInMail(false),
     196             :         bIsSMPTAfterPOP(false),
     197             :         nInServerPort( POP_PORT ),
     198             :         bInServerPOP( true ),
     199             :         nMailPort(0),
     200             :         bIsMailReplyTo(false),
     201             :         bIsDefaultPort(false),
     202             :         bIsSecureConnection(false),
     203             :         bIsAuthentication(false),
     204             : 
     205             :         bIsEMailSupported(false),
     206             :         m_AddressHeaderSA( SW_RES( SA_ADDRESS_HEADER )),
     207             :         bUserSettingWereOverwritten(false),
     208             :         bIsAddressBlock_LastUserSetting(false),
     209             :         bIsGreetingLineInMail_LastUserSetting(false),
     210           5 :         bIsGreetingLine_LastUserSetting(false)
     211             : {
     212           5 :     const Sequence<OUString>& rNames = GetPropertyNames();
     213           5 :     Sequence<Any> aValues = GetProperties(rNames);
     214           5 :     const Any* pValues = aValues.getConstArray();
     215             :     assert(aValues.getLength() == rNames.getLength());
     216           5 :     if(aValues.getLength() == rNames.getLength())
     217             :     {
     218         205 :         for(int nProp = 0; nProp < rNames.getLength(); nProp++)
     219             :         {
     220         200 :             switch(nProp)
     221             :             {
     222           5 :                 case 0: pValues[nProp] >>= bIsOutputToLetter;  break;
     223           5 :                 case 1: pValues[nProp] >>= bIncludeCountry; break;
     224           5 :                 case 2: pValues[nProp] >>= sExcludeCountry; break;
     225             :                 case 3:
     226             :                 {
     227           5 :                     Sequence< OUString> aBlocks;
     228           5 :                     pValues[nProp] >>= aBlocks;
     229           5 :                     SetAddressBlocks(aBlocks, true);
     230             :                 }
     231           5 :                 break;
     232           5 :                 case 4: pValues[nProp] >>= bIsAddressBlock; break;
     233           5 :                 case 5: pValues[nProp] >>= bIsGreetingLine;   break;
     234           5 :                 case 6: pValues[nProp] >>= bIsIndividualGreetingLine; break;
     235             :                 case 7 :
     236             :                 case 8 :
     237             :                 case 9 :
     238             :                 {
     239          15 :                     Sequence< OUString> aGreetings;
     240          15 :                     pValues[nProp] >>= aGreetings;
     241             :                     SetGreetings(SwMailMergeConfigItem::Gender(
     242          15 :                             SwMailMergeConfigItem::FEMALE + nProp - 7), aGreetings, true);
     243             :                 }
     244          15 :                 break;
     245             : 
     246           5 :                 case 10: pValues[nProp] >>= nCurrentFemaleGreeting;     break;
     247           5 :                 case 11: pValues[nProp] >>= nCurrentMaleGreeting;       break;
     248           5 :                 case 12: pValues[nProp] >>= nCurrentNeutralGreeting;    break;
     249           5 :                 case 13: pValues[nProp] >>= sFemaleGenderValue;   break;
     250           5 :                 case 14: pValues[nProp] >>= sMailDisplayName;     break;
     251           5 :                 case 15: pValues[nProp] >>= sMailAddress;         break;
     252           5 :                 case 16: pValues[nProp] >>= bIsMailReplyTo;       break;
     253           5 :                 case 17: pValues[nProp] >>= sMailReplyTo;         break;
     254           5 :                 case 18: pValues[nProp] >>= sMailServer;          break;
     255           5 :                 case 19: bIsDefaultPort = !(pValues[nProp] >>= nMailPort); break;
     256           5 :                 case 20: pValues[nProp] >>= bIsSecureConnection;           break;
     257           5 :                 case 21: pValues[nProp] >>= bIsAuthentication;             break;
     258           5 :                 case 22: pValues[nProp] >>= sMailUserName;                 break;
     259           5 :                 case 23: pValues[nProp] >>= sMailPassword;                 break;
     260           5 :                 case 24 :pValues[nProp] >>= aDBData.sDataSource;           break;
     261           5 :                 case 25 :pValues[nProp] >>= aDBData.sCommand;              break;
     262             :                 case 26 :
     263             :                 {
     264           5 :                     short nTemp = 0;
     265           5 :                     if(pValues[nProp] >>= nTemp)
     266           5 :                         aDBData.nCommandType = nTemp;
     267             :                 }
     268           5 :                 break;
     269           5 :                 case 27: pValues[nProp] >>= sFilter; break;
     270           5 :                 case 28: pValues[nProp] >>= aSavedDocuments; break;
     271             :                 case 29:
     272           5 :                     pValues[nProp] >>= bIsEMailSupported;
     273           5 :                 break;
     274           5 :                 case 30: pValues[nProp] >>= bIsGreetingLineInMail; break;
     275           5 :                 case 31: pValues[nProp] >>= bIsIndividualGreetingLineInMail; break;
     276           5 :                 case 32: pValues[nProp] >>= bIsSMPTAfterPOP; break;
     277           5 :                 case 33: pValues[nProp] >>= sInServerName;    break;
     278           5 :                 case 34: pValues[nProp] >>= nInServerPort;    break;
     279           5 :                 case 35: pValues[nProp] >>= bInServerPOP; break;
     280           5 :                 case 36: pValues[nProp] >>= sInServerUserName; break;
     281           5 :                 case 37: pValues[nProp] >>= sInServerPassword; break;
     282           5 :                 case 38: pValues[nProp] >>= bIsHideEmptyParagraphs; break;
     283           5 :                 case 39: pValues[nProp] >>= nCurrentAddressBlock; break;
     284             :             }
     285             :         }
     286             :     }
     287             :     //read the list of data base assignments
     288           5 :     Sequence<OUString> aAssignments = GetNodeNames(OUString::createFromAscii(cAddressDataAssignments));
     289           5 :     if(aAssignments.getLength())
     290             :     {
     291             :         //create a list of property names to load the URLs of all data bases
     292           5 :         const OUString* pAssignments = aAssignments.getConstArray();
     293           5 :         Sequence< OUString > aAssignProperties(4 * aAssignments.getLength());
     294           5 :         OUString* pAssignProperties = aAssignProperties.getArray();
     295             :         sal_Int32 nAssign;
     296          10 :         for(nAssign = 0; nAssign < aAssignProperties.getLength(); nAssign += 4)
     297             :         {
     298           5 :             OUString sAssignPath = OUString::createFromAscii(cAddressDataAssignments);
     299           5 :             sAssignPath += "/";
     300           5 :             sAssignPath += pAssignments[nAssign / 4];
     301           5 :             sAssignPath += "/";
     302           5 :             pAssignProperties[nAssign] = sAssignPath;
     303           5 :             pAssignProperties[nAssign] += OUString::createFromAscii(cDataSourceName);
     304           5 :             pAssignProperties[nAssign + 1] = sAssignPath;
     305           5 :             pAssignProperties[nAssign + 1] += OUString::createFromAscii(cDataTableName);
     306           5 :             pAssignProperties[nAssign + 2] = sAssignPath;
     307           5 :             pAssignProperties[nAssign + 2] += OUString::createFromAscii(cDataCommandType);
     308           5 :             pAssignProperties[nAssign + 3] = sAssignPath;
     309           5 :             pAssignProperties[nAssign + 3] += OUString::createFromAscii(cDBColumnAssignments);
     310           5 :         }
     311          10 :         Sequence<Any> aAssignValues = GetProperties(aAssignProperties);
     312           5 :         const Any* pAssignValues = aAssignValues.getConstArray();
     313          10 :         for(nAssign = 0; nAssign < aAssignValues.getLength(); nAssign += 4 )
     314             :         {
     315           5 :             DBAddressDataAssignment aAssignment;
     316           5 :             pAssignValues[nAssign] >>=      aAssignment.aDBData.sDataSource;
     317           5 :             pAssignValues[nAssign + 1] >>=  aAssignment.aDBData.sCommand;
     318           5 :             pAssignValues[nAssign + 2] >>=  aAssignment.aDBData.nCommandType;
     319           5 :             pAssignValues[nAssign + 3] >>=  aAssignment.aDBColumnAssignments;
     320           5 :             aAssignment.sConfigNodeName = pAssignments[nAssign / 4];
     321           5 :             aAddressDataAssignments.push_back(aAssignment);
     322          10 :         }
     323             :     }
     324             :     //check if the saved documents still exist
     325           5 :     if(aSavedDocuments.getLength())
     326             :     {
     327           0 :         uno::Sequence< OUString > aTempDocuments(aSavedDocuments.getLength());
     328           0 :         OUString* pTempDocuments = aTempDocuments.getArray();
     329           0 :         sal_Int32 nIndex = 0;
     330           0 :         for(sal_Int32 i = 0; i < aSavedDocuments.getLength(); ++i)
     331             :         {
     332           0 :             if(SWUnoHelper::UCB_IsFile( aSavedDocuments[i] ))
     333             :             {
     334           0 :                 pTempDocuments[nIndex++] = aSavedDocuments[i];
     335             :             }
     336             :         }
     337           0 :         if(nIndex < aSavedDocuments.getLength())
     338             :         {
     339           0 :             aSavedDocuments = aTempDocuments;
     340           0 :             aSavedDocuments.realloc(nIndex);
     341           0 :         }
     342           5 :     }
     343             : 
     344           5 : }
     345             : 
     346          10 : SwMailMergeConfigItem_Impl::~SwMailMergeConfigItem_Impl()
     347             : {
     348          10 : }
     349             : 
     350           0 : void SwMailMergeConfigItem_Impl::SetCurrentAddressBlockIndex( sal_Int32 nSet )
     351             : {
     352           0 :     if(aAddressBlocks.size() >= sal::static_int_cast<sal_uInt32, sal_Int32>(nSet))
     353             :     {
     354           0 :         nCurrentAddressBlock = nSet;
     355           0 :         SetModified();
     356             :     }
     357           0 : }
     358             : 
     359           0 : static OUString lcl_CreateNodeName(Sequence<OUString>& rAssignments )
     360             : {
     361           0 :     const OUString* pNames = rAssignments.getConstArray();
     362           0 :     sal_Int32 nStart = rAssignments.getLength();
     363           0 :     OUString sNewName;
     364             :     bool bFound;
     365           0 :     do
     366             :     {
     367           0 :         bFound = false;
     368           0 :         sNewName = "_";
     369           0 :         sNewName += OUString::number(nStart);
     370             :         //search if the name exists
     371           0 :         for(sal_Int32 nAssign = 0; nAssign < rAssignments.getLength(); ++nAssign)
     372             :         {
     373           0 :             if(pNames[nAssign] == sNewName)
     374             :             {
     375           0 :                 bFound = true;
     376           0 :                 ++nStart;
     377           0 :                 break;
     378             :             }
     379             :         }
     380             :     }
     381             :     while(bFound);
     382             :     // add the new name to the array of existing names
     383           0 :     rAssignments.realloc(rAssignments.getLength() + 1);
     384           0 :     rAssignments.getArray()[rAssignments.getLength() - 1] = sNewName;
     385           0 :     return sNewName;
     386             : }
     387             : 
     388           0 : static void lcl_ConvertToNumbers(OUString& rBlock, const ResStringArray& rHeaders )
     389             : {
     390             :     //convert the strings used for UI to numbers used for the configuration
     391           0 :     OUString sBlock(rBlock.replaceAll("\n", OUString("\\n")));
     392           0 :     for(sal_uInt32 i = 0; i < rHeaders.Count(); ++i)
     393             :     {
     394           0 :         OUString sHeader = "<" + rHeaders.GetString( i ) + ">";
     395           0 :         OUString sReplace = "<" + OUString('0' + i) + ">";
     396           0 :         sBlock = sBlock.replaceAll(sHeader, sReplace);
     397           0 :     }
     398           0 :     rBlock = sBlock;
     399           0 : }
     400             : 
     401          50 : static void lcl_ConvertFromNumbers(OUString& rBlock, const ResStringArray& rHeaders)
     402             : {
     403             :     //convert the numbers used for the configuration to strings used for UI to numbers
     404             :     //doesn't use ReplaceAll to prevent expansion of numbers inside of the headers
     405          50 :     OUString sBlock(rBlock.replaceAll("\\n", OUString('\n')));
     406         100 :     SwAddressIterator aGreetingIter(sBlock);
     407          50 :     sBlock.clear();
     408         390 :     while(aGreetingIter.HasMore())
     409             :     {
     410         290 :         SwMergeAddressItem aNext = aGreetingIter.Next();
     411         290 :         if(aNext.bIsColumn)
     412             :         {
     413             :             //the text should be 1 characters long
     414         140 :             sal_Unicode cChar = aNext.sText[0];
     415         140 :             if(cChar >= '0' && cChar <= 'c')
     416             :             {
     417         140 :                 sBlock += "<";
     418         140 :                 sal_uInt16 nHeader = cChar - '0';
     419         140 :                 if(nHeader < rHeaders.Count())
     420         140 :                     sBlock += rHeaders.GetString( nHeader );
     421         140 :                 sBlock += ">";
     422             :             }
     423             :             else
     424             :             {
     425             :                 SAL_WARN("sw.ui", "parse error in address block or greeting line");
     426             :             }
     427             :         }
     428             :         else
     429         150 :             sBlock += aNext.sText;
     430         290 :     }
     431         100 :     rBlock = sBlock;
     432          50 : }
     433             : 
     434           5 : const Sequence<OUString>& SwMailMergeConfigItem_Impl::GetPropertyNames()
     435             : {
     436           5 :     static Sequence<OUString> aNames;
     437           5 :     if(!aNames.getLength())
     438             :     {
     439             :         static const char* aPropNames[] =
     440             :         {
     441             :             "OutputToLetter",           // 0
     442             :             "IncludeCountry",           // 1
     443             :             "ExcludeCountry",           // 2
     444             :             "AddressBlockSettings",     // 3
     445             :             "IsAddressBlock",          // 4
     446             :             "IsGreetingLine",           // 5
     447             :             "IsIndividualGreetingLine", // 6
     448             :             "FemaleGreetingLines",      // 7
     449             :             "MaleGreetingLines",        // 8
     450             :             "NeutralGreetingLines",     // 9
     451             :             "CurrentFemaleGreeting",    // 10
     452             :             "CurrentMaleGreeting",      // 11
     453             :             "CurrentNeutralGreeting",   // 12
     454             :             "FemaleGenderValue",        // 13
     455             :             "MailDisplayName",          // 14
     456             :             "MailAddress",              // 15
     457             :             "IsMailReplyTo",            // 16
     458             :             "MailReplyTo",              // 17
     459             :             "MailServer",               // 18
     460             :             "MailPort",                 // 19
     461             :             "IsSecureConnection",       // 20
     462             :             "IsAuthentication",         // 21
     463             :             "MailUserName",             // 22
     464             :             "MailPassword",             // 23
     465             :             "DataSource/DataSourceName",// 24
     466             :             "DataSource/DataTableName", // 25
     467             :             "DataSource/DataCommandType",// 26
     468             :             "Filter",                   // 27
     469             :             "SavedDocuments",           // 28
     470             :             "EMailSupported",            // 29
     471             :             "IsEMailGreetingLine",              //30
     472             :             "IsEMailIndividualGreetingLine",     //31
     473             :             "IsSMPTAfterPOP",                    //32
     474             :             "InServerName",                      //33
     475             :             "InServerPort",                      //34
     476             :             "InServerIsPOP",                     //35
     477             :             "InServerUserName",                  //36
     478             :             "InServerPassword",                   //37
     479             :             "IsHideEmptyParagraphs",             //38
     480             :             "CurrentAddressBlock"               //39
     481             : 
     482             :         };
     483           1 :         const int nCount = sizeof(aPropNames)/sizeof(const char*);
     484           1 :         aNames.realloc(nCount);
     485           1 :         OUString* pNames = aNames.getArray();
     486          41 :         for(int i = 0; i < nCount; i++)
     487          40 :             pNames[i] = OUString::createFromAscii(aPropNames[i]);
     488             :     }
     489           5 :     return aNames;
     490             : }
     491             : 
     492           0 : void SwMailMergeConfigItem_Impl::Notify( const ::com::sun::star::uno::Sequence< OUString >& ) {}
     493             : 
     494           0 : void  SwMailMergeConfigItem_Impl::ImplCommit()
     495             : {
     496           0 :     Sequence<OUString> aNames = GetPropertyNames();
     497           0 :     Sequence<Any> aValues(aNames.getLength());
     498           0 :     Any* pValues = aValues.getArray();
     499             : 
     500           0 :     for(int nProp = 0; nProp < aNames.getLength(); nProp++)
     501             :     {
     502           0 :         switch(nProp)
     503             :         {
     504           0 :             case 0: pValues[nProp] <<= bIsOutputToLetter; break;
     505           0 :             case 1: pValues[nProp] <<= bIncludeCountry; break;
     506           0 :             case 2: pValues[nProp] <<= sExcludeCountry; break;
     507           0 :             case 3: pValues[nProp] <<= GetAddressBlocks(true); break;
     508             :             case 4:
     509             :                 {
     510           0 :                     if( bUserSettingWereOverwritten)
     511           0 :                         pValues[nProp] <<= bIsAddressBlock_LastUserSetting;
     512             :                     else
     513           0 :                         pValues[nProp] <<= bIsAddressBlock;
     514           0 :                     break;
     515             :                 }
     516             :             case 5:
     517             :                 {
     518           0 :                     if( bUserSettingWereOverwritten)
     519           0 :                         pValues[nProp] <<= bIsGreetingLine_LastUserSetting;
     520             :                     else
     521           0 :                         pValues[nProp] <<= bIsGreetingLine;
     522           0 :                     break;
     523             :                 }
     524           0 :             case 6: pValues[nProp] <<= bIsIndividualGreetingLine;  break;
     525             :             case 7:
     526             :             case 8:
     527             :             case 9:
     528           0 :                 pValues[nProp] <<= GetGreetings(
     529             :                         SwMailMergeConfigItem::Gender(
     530           0 :                             SwMailMergeConfigItem::FEMALE + nProp - 7), true);
     531           0 :             break;
     532           0 :             case 10: pValues[nProp] <<= nCurrentFemaleGreeting;     break;
     533           0 :             case 11: pValues[nProp] <<= nCurrentMaleGreeting;       break;
     534           0 :             case 12: pValues[nProp] <<= nCurrentNeutralGreeting;    break;
     535           0 :             case 13: pValues[nProp] <<= sFemaleGenderValue;     break;
     536           0 :             case 14: pValues[nProp] <<= sMailDisplayName;     break;
     537           0 :             case 15: pValues[nProp] <<= sMailAddress;         break;
     538           0 :             case 16: pValues[nProp] <<= bIsMailReplyTo;        break;
     539           0 :             case 17: pValues[nProp] <<= sMailReplyTo;         break;
     540           0 :             case 18: pValues[nProp] <<= sMailServer;          break;
     541           0 :             case 19: if(!bIsDefaultPort)
     542           0 :                         pValues[nProp] <<= nMailPort;
     543           0 :             break;
     544           0 :             case 20: pValues[nProp] <<= bIsSecureConnection;  break;
     545           0 :             case 21: pValues[nProp] <<= bIsAuthentication;    break;
     546           0 :             case 22: pValues[nProp] <<= sMailUserName;        break;
     547           0 :             case 23: pValues[nProp] <<= sMailPassword;        break;
     548           0 :             case 24 :pValues[nProp] <<= aDBData.sDataSource;           break;
     549           0 :             case 25 :pValues[nProp] <<= aDBData.sCommand;              break;
     550           0 :             case 26 :pValues[nProp] <<= (short)aDBData.nCommandType;   break;
     551           0 :             case 27 :pValues[nProp] <<= sFilter; break;
     552           0 :             case 28 :pValues[nProp] <<= aSavedDocuments; break;
     553           0 :             case 29: pValues[nProp] <<= bIsEMailSupported; break;
     554             :             case 30:
     555             :                 {
     556           0 :                     if( bUserSettingWereOverwritten)
     557           0 :                         pValues[nProp] <<= bIsGreetingLineInMail_LastUserSetting;
     558             :                     else
     559           0 :                         pValues[nProp] <<= bIsGreetingLineInMail;
     560           0 :                     break;
     561             :                 }
     562           0 :             case 31: pValues[nProp] <<= bIsIndividualGreetingLineInMail; break;
     563           0 :             case 32: pValues[nProp] <<= bIsSMPTAfterPOP; break;
     564           0 :             case 33: pValues[nProp] <<= sInServerName;    break;
     565           0 :             case 34: pValues[nProp] <<= nInServerPort;    break;
     566           0 :             case 35: pValues[nProp] <<= bInServerPOP; break;
     567           0 :             case 36: pValues[nProp] <<= sInServerUserName; break;
     568           0 :             case 37: pValues[nProp] <<= sInServerPassword; break;
     569           0 :             case 38: pValues[nProp] <<= bIsHideEmptyParagraphs; break;
     570           0 :             case 39: pValues[nProp] <<= nCurrentAddressBlock; break;
     571             :         }
     572             :     }
     573           0 :     PutProperties(aNames, aValues);
     574             :     //store the changed / new assignments
     575             : 
     576             :     //load the existing node names to find new names
     577           0 :     Sequence<OUString> aAssignments = GetNodeNames(OUString::createFromAscii(cAddressDataAssignments));
     578             : 
     579           0 :     ::std::vector<DBAddressDataAssignment>::iterator aAssignIter;
     580           0 :     for(aAssignIter = aAddressDataAssignments.begin();
     581           0 :                 aAssignIter != aAddressDataAssignments.end(); ++aAssignIter)
     582             :     {
     583           0 :         if(aAssignIter->bColumnAssignmentsChanged)
     584             :         {
     585             :             //create a new node name
     586           0 :             OUString sNewNode = !aAssignIter->sConfigNodeName.isEmpty() ?
     587           0 :                         aAssignIter->sConfigNodeName :
     588           0 :                         lcl_CreateNodeName(aAssignments);
     589           0 :             OUString sSlash = "/";
     590           0 :             OUString sNodePath = OUString::createFromAscii(cAddressDataAssignments);
     591           0 :             sNodePath += sSlash;
     592           0 :             sNodePath += sNewNode;
     593           0 :             sNodePath += sSlash;
     594             :             //only one new entry is written
     595           0 :             Sequence< PropertyValue > aNewValues(4);
     596           0 :             PropertyValue* pNewValues = aNewValues.getArray();
     597           0 :             pNewValues[0].Name = sNodePath;
     598           0 :             pNewValues[0].Name += OUString::createFromAscii(cDataSourceName);
     599           0 :             pNewValues[0].Value <<= aAssignIter->aDBData.sDataSource;
     600           0 :             pNewValues[1].Name = sNodePath;
     601           0 :             pNewValues[1].Name += OUString::createFromAscii(cDataTableName);
     602           0 :             pNewValues[1].Value <<= aAssignIter->aDBData.sCommand;
     603           0 :             pNewValues[2].Name = sNodePath;
     604           0 :             pNewValues[2].Name += OUString::createFromAscii(cDataCommandType);
     605           0 :             pNewValues[2].Value <<= aAssignIter->aDBData.nCommandType;
     606           0 :             pNewValues[3].Name = sNodePath;
     607           0 :             pNewValues[3].Name += OUString::createFromAscii(cDBColumnAssignments);
     608           0 :             pNewValues[3].Value <<= aAssignIter->aDBColumnAssignments;
     609             : 
     610           0 :             SetSetProperties(OUString::createFromAscii(cAddressDataAssignments), aNewValues);
     611             :         }
     612             :     }
     613             : 
     614           0 :     bUserSettingWereOverwritten = false;
     615           0 : }
     616             : 
     617           0 : const Sequence< OUString> SwMailMergeConfigItem_Impl::GetAddressBlocks(
     618             :         bool bConvertToConfig) const
     619             : {
     620           0 :     Sequence< OUString> aRet(aAddressBlocks.size());
     621           0 :     OUString* pRet = aRet.getArray();
     622           0 :     for(size_t nBlock = 0; nBlock < aAddressBlocks.size(); nBlock++)
     623             :     {
     624           0 :         pRet[nBlock] = aAddressBlocks[nBlock];
     625           0 :         if(bConvertToConfig)
     626           0 :             lcl_ConvertToNumbers(pRet[nBlock], m_AddressHeaderSA);
     627             :     }
     628           0 :     return aRet;
     629             : }
     630             : 
     631           5 : void SwMailMergeConfigItem_Impl::SetAddressBlocks(
     632             :         const Sequence< OUString>& rBlocks,
     633             :         bool bConvertFromConfig)
     634             : {
     635           5 :     aAddressBlocks.clear();
     636          25 :     for(sal_Int32 nBlock = 0; nBlock < rBlocks.getLength(); nBlock++)
     637             :     {
     638          20 :         OUString sBlock = rBlocks[nBlock];
     639          20 :         if(bConvertFromConfig)
     640          20 :             lcl_ConvertFromNumbers(sBlock, m_AddressHeaderSA);
     641          20 :         aAddressBlocks.push_back(sBlock);
     642          20 :     }
     643           5 :     nCurrentAddressBlock = 0;
     644           5 :     SetModified();
     645           5 : }
     646             : 
     647           0 : const Sequence< OUString>   SwMailMergeConfigItem_Impl::GetGreetings(
     648             :         SwMailMergeConfigItem::Gender eType, bool bConvertToConfig) const
     649             : {
     650             :     const ::std::vector< OUString>& rGreetings =
     651             :             eType == SwMailMergeConfigItem::FEMALE ? aFemaleGreetingLines :
     652             :             eType == SwMailMergeConfigItem::MALE ? aMaleGreetingLines :
     653           0 :                                 aNeutralGreetingLines;
     654           0 :     Sequence< OUString> aRet(rGreetings.size());
     655           0 :     OUString* pRet = aRet.getArray();
     656           0 :     for(size_t nGreeting = 0; nGreeting < rGreetings.size(); nGreeting++)
     657             :     {
     658           0 :         pRet[nGreeting] = rGreetings[nGreeting];
     659           0 :         if(bConvertToConfig)
     660           0 :             lcl_ConvertToNumbers(pRet[nGreeting], m_AddressHeaderSA);
     661             :     }
     662           0 :     return aRet;
     663             : }
     664             : 
     665          15 : void  SwMailMergeConfigItem_Impl::SetGreetings(
     666             :         SwMailMergeConfigItem::Gender eType,
     667             :         const Sequence< OUString>& rSetGreetings,
     668             :         bool bConvertFromConfig)
     669             : {
     670             :     ::std::vector< OUString>& rGreetings =
     671             :             eType == SwMailMergeConfigItem::FEMALE ? aFemaleGreetingLines :
     672             :             eType == SwMailMergeConfigItem::MALE ? aMaleGreetingLines :
     673          15 :                                 aNeutralGreetingLines;
     674             : 
     675          15 :     rGreetings.clear();
     676          45 :     for(sal_Int32 nGreeting = 0; nGreeting < rSetGreetings.getLength(); nGreeting++)
     677             :     {
     678          30 :         OUString sGreeting = rSetGreetings[nGreeting];
     679          30 :         if(bConvertFromConfig)
     680          30 :             lcl_ConvertFromNumbers(sGreeting, m_AddressHeaderSA);
     681          30 :         rGreetings.push_back(sGreeting);
     682          30 :     }
     683          15 :     SetModified();
     684          15 : }
     685             : 
     686           0 : sal_Int32 SwMailMergeConfigItem_Impl::GetCurrentGreeting(
     687             :                             SwMailMergeConfigItem::Gender eType) const
     688             : {
     689             :     sal_Int32 nRet;
     690           0 :     switch(eType)
     691             :     {
     692           0 :         case SwMailMergeConfigItem::FEMALE: nRet = nCurrentFemaleGreeting ; break;
     693           0 :         case SwMailMergeConfigItem::MALE:   nRet = nCurrentMaleGreeting   ; break;
     694           0 :         default:                       nRet = nCurrentNeutralGreeting; break;
     695             :     }
     696           0 :     return nRet;
     697             : }
     698             : 
     699           0 : void SwMailMergeConfigItem_Impl::SetCurrentGreeting(
     700             :         SwMailMergeConfigItem::Gender eType, sal_Int32 nIndex)
     701             : {
     702           0 :     bool bChanged = false;
     703           0 :     switch(eType)
     704             :     {
     705             :         case SwMailMergeConfigItem::FEMALE:
     706           0 :             bChanged = nCurrentFemaleGreeting != nIndex;
     707           0 :             nCurrentFemaleGreeting = nIndex;
     708           0 :         break;
     709             :         case SwMailMergeConfigItem::MALE:
     710           0 :             bChanged = nCurrentMaleGreeting != nIndex;
     711           0 :             nCurrentMaleGreeting = nIndex;
     712           0 :         break;
     713             :         default:
     714           0 :             bChanged = nCurrentNeutralGreeting != nIndex;
     715           0 :             nCurrentNeutralGreeting = nIndex;
     716             :     }
     717           0 :     if(bChanged)
     718           0 :         SetModified();
     719           0 : }
     720             : 
     721             : namespace
     722             : {
     723             :     static SwMailMergeConfigItem_Impl* pOptions = NULL;
     724             :     static sal_Int32            nRefCount = 0;
     725             : 
     726             :     class theMailMergeConfigMutex : public rtl::Static<osl::Mutex, theMailMergeConfigMutex> {};
     727             : }
     728             : 
     729           5 : SwMailMergeConfigItem::SwMailMergeConfigItem() :
     730             :     m_bAddressInserted(false),
     731             :     m_bMergeDone(false),
     732             :     m_bGreetingInserted(false),
     733             :     m_nGreetingMoves(0),
     734             :     m_nStartPrint(0),
     735             :     m_nEndPrint(0),
     736             :     m_pSourceView(0),
     737           5 :     m_pTargetView(0)
     738             : {
     739             :     // Global access, must be guarded (multithreading)
     740           5 :     ::osl::MutexGuard aGuard( theMailMergeConfigMutex::get() );
     741           5 :     if ( !pOptions )
     742           5 :         pOptions = new SwMailMergeConfigItem_Impl;
     743           5 :     ++nRefCount;
     744           5 :     m_pImpl = pOptions;
     745           5 : }
     746             : 
     747          10 : SwMailMergeConfigItem::~SwMailMergeConfigItem()
     748             : {
     749             :     // Global access, must be guarded (multithreading)
     750           5 :     ::osl::MutexGuard aGuard( theMailMergeConfigMutex::get() );
     751           5 :     if ( !--nRefCount )
     752             :     {
     753           5 :         DELETEZ( pOptions );
     754           5 :     }
     755           5 : }
     756             : 
     757           0 : void  SwMailMergeConfigItem::Commit()
     758             : {
     759           0 :     if(m_pImpl->IsModified())
     760           0 :         m_pImpl->Commit();
     761           0 : }
     762             : 
     763           0 : const ResStringArray&   SwMailMergeConfigItem::GetDefaultAddressHeaders() const
     764             : {
     765           0 :     return m_pImpl->m_AddressHeaderSA;
     766             : }
     767             : 
     768           0 : void SwMailMergeConfigItem::SetAddressBlocks(
     769             :         const Sequence< OUString>& rBlocks)
     770             : {
     771           0 :     m_pImpl->SetAddressBlocks(rBlocks);
     772           0 : }
     773             : 
     774           0 : const Sequence< OUString> SwMailMergeConfigItem::GetAddressBlocks() const
     775             : {
     776           0 :     return m_pImpl->GetAddressBlocks();
     777             : }
     778             : 
     779           0 : bool SwMailMergeConfigItem::IsAddressBlock()const
     780             : {
     781           0 :     return m_pImpl->bIsAddressBlock && IsOutputToLetter();
     782             : }
     783             : 
     784           0 : void     SwMailMergeConfigItem::SetAddressBlock(bool bSet)
     785             : {
     786           0 :     m_pImpl->bUserSettingWereOverwritten = false;
     787           0 :     if(m_pImpl->bIsAddressBlock != bSet)
     788             :     {
     789           0 :         m_pImpl->bIsAddressBlock = bSet;
     790           0 :         m_pImpl->SetModified();
     791             :     }
     792           0 : }
     793             : 
     794           0 : bool SwMailMergeConfigItem::IsHideEmptyParagraphs() const
     795             : {
     796           0 :     return m_pImpl->bIsHideEmptyParagraphs;
     797             : }
     798             : 
     799           0 : void SwMailMergeConfigItem::SetHideEmptyParagraphs(bool bSet)
     800             : {
     801           0 :     if(m_pImpl->bIsHideEmptyParagraphs != bSet)
     802             :     {
     803           0 :         m_pImpl->bIsHideEmptyParagraphs = bSet;
     804           0 :         m_pImpl->SetModified();
     805             :     }
     806           0 : }
     807             : 
     808           0 : bool SwMailMergeConfigItem::IsIncludeCountry() const
     809             : {
     810           0 :     return m_pImpl->bIncludeCountry;
     811             : }
     812             : 
     813           0 : OUString& SwMailMergeConfigItem::GetExcludeCountry() const
     814             : {
     815           0 :     return m_pImpl->sExcludeCountry;
     816             : }
     817             : 
     818           0 : void SwMailMergeConfigItem::SetCountrySettings(bool bSet, const OUString& rCountry)
     819             : {
     820           0 :     if(m_pImpl->sExcludeCountry != rCountry ||
     821           0 :         m_pImpl->bIncludeCountry != bSet)
     822             :     {
     823           0 :         m_pImpl->bIncludeCountry = bSet;
     824           0 :         m_pImpl->sExcludeCountry = bSet ? rCountry : OUString();
     825           0 :         m_pImpl->SetModified();
     826             :     }
     827           0 : }
     828             : 
     829           0 : void SwMailMergeConfigItem::SetCurrentConnection(
     830             :         Reference< XDataSource>       xSource,
     831             :         const SharedConnection&       rConnection,
     832             :         Reference< XColumnsSupplier>  xColumnsSupplier,
     833             :         const SwDBData& rDBData)
     834             : {
     835           0 :         m_pImpl->xSource            = xSource         ;
     836           0 :         m_pImpl->xConnection        = rConnection     ;
     837           0 :         m_pImpl->xColumnsSupplier   = xColumnsSupplier;
     838           0 :         m_pImpl->aDBData = rDBData;
     839           0 :         m_pImpl->xResultSet         = 0;
     840           0 :         m_pImpl->nResultSetCursorPos = 0;
     841           0 :         m_pImpl->SetModified();
     842           0 : }
     843             : 
     844           0 : Reference< XDataSource>  SwMailMergeConfigItem::GetSource()
     845             : {
     846           0 :     return m_pImpl->xSource;
     847             : }
     848             : 
     849           0 : SharedConnection SwMailMergeConfigItem::GetConnection()
     850             : {
     851           0 :     return m_pImpl->xConnection;
     852             : }
     853             : 
     854           0 : Reference< XColumnsSupplier> SwMailMergeConfigItem::GetColumnsSupplier()
     855             : {
     856           0 :     if(!m_pImpl->xColumnsSupplier.is() && m_pImpl->xConnection.is())
     857             :     {
     858           0 :         m_pImpl->xColumnsSupplier = SwDBManager::GetColumnSupplier(m_pImpl->xConnection,
     859             :                                 m_pImpl->aDBData.sCommand,
     860           0 :                                 m_pImpl->aDBData.nCommandType == CommandType::TABLE ?
     861           0 :                                         SwDBSelect::TABLE : SwDBSelect::QUERY );
     862             :     }
     863           0 :     return m_pImpl->xColumnsSupplier;
     864             : }
     865             : 
     866           0 : const SwDBData&    SwMailMergeConfigItem::GetCurrentDBData() const
     867             : {
     868           0 :     return m_pImpl->aDBData;
     869             : }
     870             : 
     871           0 : void SwMailMergeConfigItem::SetCurrentDBData( const SwDBData& rDBData)
     872             : {
     873           0 :     if(m_pImpl->aDBData != rDBData)
     874             :     {
     875           0 :         m_pImpl->aDBData = rDBData;
     876           0 :         m_pImpl->xConnection.clear();
     877           0 :         m_pImpl->xSource = 0;
     878           0 :         m_pImpl->xColumnsSupplier = 0;
     879           0 :         m_pImpl->SetModified();
     880             :     }
     881           0 : }
     882             : 
     883           0 : Reference< XResultSet>   SwMailMergeConfigItem::GetResultSet() const
     884             : {
     885           0 :     if(!m_pImpl->xConnection.is() && !m_pImpl->aDBData.sDataSource.isEmpty())
     886             :     {
     887             :         m_pImpl->xConnection.reset(
     888             :             SwDBManager::GetConnection( m_pImpl->aDBData.sDataSource, m_pImpl->xSource ),
     889             :             SharedConnection::TakeOwnership
     890           0 :         );
     891             :     }
     892           0 :     if(!m_pImpl->xResultSet.is() && m_pImpl->xConnection.is())
     893             :     {
     894             :         try
     895             :         {
     896           0 :             Reference< XMultiServiceFactory > xMgr( ::comphelper::getProcessServiceFactory() );
     897             : 
     898           0 :             Reference<XRowSet> xRowSet( xMgr->createInstance("com.sun.star.sdb.RowSet"), UNO_QUERY );
     899           0 :             Reference<XPropertySet> xRowProperties(xRowSet, UNO_QUERY);
     900           0 :             xRowProperties->setPropertyValue("DataSourceName", makeAny(m_pImpl->aDBData.sDataSource));
     901           0 :             xRowProperties->setPropertyValue("Command", makeAny(m_pImpl->aDBData.sCommand));
     902           0 :             xRowProperties->setPropertyValue("CommandType", makeAny(m_pImpl->aDBData.nCommandType));
     903           0 :             xRowProperties->setPropertyValue("FetchSize", makeAny((sal_Int32)10));
     904           0 :             xRowProperties->setPropertyValue("ActiveConnection", makeAny(m_pImpl->xConnection.getTyped()));
     905             :             try
     906             :             {
     907           0 :                 xRowProperties->setPropertyValue("ApplyFilter", makeAny(!m_pImpl->sFilter.isEmpty()));
     908           0 :                 xRowProperties->setPropertyValue("Filter", makeAny(m_pImpl->sFilter));
     909             :             }
     910           0 :             catch (const Exception& e)
     911             :             {
     912             :                 SAL_WARN("sw.ui", "exception caught: " << e.Message);
     913             :             }
     914           0 :             xRowSet->execute();
     915           0 :             m_pImpl->xResultSet = xRowSet.get();
     916           0 :             m_pImpl->xResultSet->first();
     917           0 :             m_pImpl->nResultSetCursorPos = 1;
     918             :         }
     919           0 :         catch (const Exception& e)
     920             :         {
     921             :             SAL_WARN("sw.ui", "exception caught in: SwMailMergeConfigItem::GetResultSet() " << e.Message);
     922             :         }
     923             :     }
     924           0 :     return m_pImpl->xResultSet;
     925             : }
     926             : 
     927           0 : void SwMailMergeConfigItem::DisposeResultSet()
     928             : {
     929           0 :     m_pImpl->xConnection.clear();
     930           0 :     if(m_pImpl->xResultSet.is())
     931             :     {
     932           0 :         ::comphelper::disposeComponent( m_pImpl->xResultSet );
     933             :     }
     934           0 : }
     935             : 
     936           0 : OUString&    SwMailMergeConfigItem::GetFilter() const
     937             : {
     938           0 :     return m_pImpl->sFilter;
     939             : }
     940             : 
     941           0 : void  SwMailMergeConfigItem::SetFilter(OUString& rFilter)
     942             : {
     943           0 :     if(m_pImpl->sFilter != rFilter)
     944             :     {
     945           0 :         m_pImpl->sFilter = rFilter;
     946           0 :         m_pImpl->SetModified();
     947           0 :         Reference<XPropertySet> xRowProperties(m_pImpl->xResultSet, UNO_QUERY);
     948           0 :         if(xRowProperties.is())
     949             :         {
     950             :             try
     951             :             {
     952           0 :                 xRowProperties->setPropertyValue("ApplyFilter", makeAny(!m_pImpl->sFilter.isEmpty()));
     953           0 :                 xRowProperties->setPropertyValue("Filter", makeAny(m_pImpl->sFilter));
     954           0 :                 uno::Reference<XRowSet> xRowSet( m_pImpl->xResultSet, UNO_QUERY_THROW );
     955           0 :                 xRowSet->execute();
     956             :             }
     957           0 :             catch (const Exception& e)
     958             :             {
     959             :                 SAL_WARN("sw.ui", "exception caught in SwMailMergeConfigItem::SetFilter(): " << e.Message);
     960             :             }
     961           0 :         }
     962             :     }
     963           0 : }
     964             : 
     965           0 : sal_Int32 SwMailMergeConfigItem::MoveResultSet(sal_Int32 nTarget)
     966             : {
     967           0 :     if(!m_pImpl->xResultSet.is())
     968           0 :         GetResultSet();
     969           0 :     if(m_pImpl->xResultSet.is())
     970             :     {
     971             :         try
     972             :         {
     973             :             //no action if the resultset is already at the right position
     974           0 :             if(m_pImpl->xResultSet->getRow() != nTarget)
     975             :             {
     976           0 :                 if(nTarget > 0)
     977             :                 {
     978           0 :                     bool bMoved = m_pImpl->xResultSet->absolute(nTarget);
     979           0 :                     if(!bMoved)
     980             :                     {
     981           0 :                         if(nTarget > 1)
     982           0 :                             m_pImpl->xResultSet->last();
     983           0 :                         else if(nTarget == 1)
     984           0 :                             m_pImpl->xResultSet->first();
     985             :                     }
     986             :                 }
     987           0 :                 else if(nTarget == -1)
     988           0 :                     m_pImpl->xResultSet->last();
     989           0 :                 m_pImpl->nResultSetCursorPos = m_pImpl->xResultSet->getRow();
     990             :             }
     991             :         }
     992           0 :         catch (const Exception&)
     993             :         {
     994             :         }
     995             :     }
     996           0 :     return m_pImpl->nResultSetCursorPos;
     997             : }
     998             : 
     999           0 : bool SwMailMergeConfigItem::IsResultSetFirstLast(bool& bIsFirst, bool& bIsLast)
    1000             : {
    1001           0 :     bool bRet = false;
    1002           0 :     if(!m_pImpl->xResultSet.is())
    1003           0 :         GetResultSet();
    1004           0 :     if(m_pImpl->xResultSet.is())
    1005             :     {
    1006             :         try
    1007             :         {
    1008           0 :             bIsFirst = m_pImpl->xResultSet->isFirst();
    1009           0 :             bIsLast = m_pImpl->xResultSet->isLast();
    1010           0 :             bRet = true;
    1011             :         }
    1012           0 :         catch (const Exception&)
    1013             :         {
    1014             :         }
    1015             :     }
    1016           0 :     return bRet;
    1017             : }
    1018             : 
    1019           0 : sal_Int32 SwMailMergeConfigItem::GetResultSetPosition() const
    1020             : {
    1021           0 :     return m_pImpl->nResultSetCursorPos;
    1022             : }
    1023             : 
    1024           0 : bool SwMailMergeConfigItem::IsRecordExcluded(sal_Int32 nRecord)
    1025             : {
    1026           0 :     bool bRet = false;
    1027           0 :     if(nRecord > 0 && nRecord < m_aSelection.getLength())
    1028             :     {
    1029           0 :         sal_Int32 nTemp = 0;
    1030           0 :         m_aSelection[nRecord - 1] >>= nTemp;
    1031           0 :         bRet = nTemp < 1;
    1032             :     }
    1033           0 :     return bRet;
    1034             : }
    1035             : 
    1036           0 : void SwMailMergeConfigItem::ExcludeRecord(sal_Int32 nRecord, bool bExclude)
    1037             : {
    1038             :     //nRecord is based on 1
    1039             :     //the selection array contains Anys for all records
    1040             :     //excluded records  contain a '-1'
    1041           0 :     if(!m_aSelection.getLength() || nRecord > m_aSelection.getLength())
    1042             :     {
    1043           0 :         if(bExclude)
    1044             :         {
    1045             :             //if no selection array is available we need to create one containing the
    1046             :             //entries for all available records
    1047           0 :             if(!m_pImpl->xResultSet.is())
    1048           0 :                 GetResultSet();
    1049           0 :             if(m_pImpl->xResultSet.is())
    1050             :             {
    1051           0 :                 m_pImpl->xResultSet->last();
    1052           0 :                 sal_Int32 nEnd = m_pImpl->xResultSet->getRow();
    1053           0 :                 sal_Int32 nStart = m_aSelection.getLength();
    1054           0 :                 m_aSelection.realloc(nEnd);
    1055           0 :                 Any* pSelection = m_aSelection.getArray();
    1056           0 :                 for(sal_Int32 nIndex = nStart; nIndex < nEnd; ++nIndex)
    1057             :                 {
    1058           0 :                     if((nRecord - 1) != nIndex)
    1059           0 :                         pSelection[nIndex] <<= nIndex + 1;
    1060             :                     else
    1061           0 :                         pSelection[nIndex] <<= (sal_Int32) -1;
    1062             :                 }
    1063             :             }
    1064             :         }
    1065             :     }
    1066             :     else
    1067             :     {
    1068           0 :         if(nRecord > 0 && m_aSelection.getLength() > nRecord)
    1069             :         {
    1070           0 :             m_aSelection[nRecord - 1] <<= bExclude ? -1 : nRecord;
    1071             :         }
    1072             :     }
    1073           0 : }
    1074             : 
    1075             : const uno::Sequence< OUString>&
    1076           0 :                     SwMailMergeConfigItem::GetSavedDocuments() const
    1077             : {
    1078           0 :     return m_pImpl->aSavedDocuments;
    1079             : }
    1080             : 
    1081           0 : void SwMailMergeConfigItem::AddSavedDocument(const OUString& rName)
    1082             : {
    1083           0 :     const OUString* pDocs = m_pImpl->aSavedDocuments.getConstArray();
    1084           0 :     bool bFound = false;
    1085           0 :     for(sal_Int32 nDoc = 0; nDoc < m_pImpl->aSavedDocuments.getLength(); ++nDoc)
    1086             :     {
    1087           0 :         if(pDocs[nDoc] == rName)
    1088             :         {
    1089           0 :             bFound = true;
    1090           0 :             break;
    1091             :         }
    1092             :     }
    1093           0 :     if(!bFound)
    1094             :     {
    1095           0 :         m_pImpl->aSavedDocuments.realloc(m_pImpl->aSavedDocuments.getLength() + 1);
    1096           0 :         m_pImpl->aSavedDocuments[m_pImpl->aSavedDocuments.getLength() - 1] = rName;
    1097             :     }
    1098           0 : }
    1099             : 
    1100           0 : bool SwMailMergeConfigItem::IsOutputToLetter()const
    1101             : {
    1102           0 :     return m_pImpl->bIsOutputToLetter || !IsMailAvailable();
    1103             : }
    1104             : 
    1105           0 : void SwMailMergeConfigItem::SetOutputToLetter(bool bSet)
    1106             : {
    1107           0 :     if(m_pImpl->bIsOutputToLetter != bSet)
    1108             :     {
    1109           0 :         m_pImpl->bIsOutputToLetter = bSet;
    1110           0 :         m_pImpl->SetModified();
    1111             :     }
    1112           0 : }
    1113             : 
    1114           0 : bool SwMailMergeConfigItem::IsIndividualGreeting(bool bInEMail) const
    1115             : {
    1116             :     return bInEMail ?
    1117             :             m_pImpl->bIsIndividualGreetingLineInMail :
    1118           0 :             m_pImpl->bIsIndividualGreetingLine;
    1119             : }
    1120             : 
    1121           0 : void     SwMailMergeConfigItem::SetIndividualGreeting(
    1122             :                                         bool bSet, bool bInEMail)
    1123             : {
    1124           0 :     if(bInEMail)
    1125             :     {
    1126           0 :         if(m_pImpl->bIsIndividualGreetingLineInMail != bSet)
    1127             :         {
    1128           0 :             m_pImpl->bIsIndividualGreetingLineInMail = bSet;
    1129           0 :             m_pImpl->SetModified();
    1130             :         }
    1131             :     }
    1132             :     else
    1133             :     {
    1134           0 :         if(m_pImpl->bIsIndividualGreetingLine != bSet)
    1135             :         {
    1136           0 :             m_pImpl->bIsIndividualGreetingLine = bSet;
    1137           0 :             m_pImpl->SetModified();
    1138             :         }
    1139             :     }
    1140           0 : }
    1141             : 
    1142           0 : bool SwMailMergeConfigItem::IsGreetingLine(bool bInEMail) const
    1143             : {
    1144           0 :     return bInEMail ? m_pImpl->bIsGreetingLineInMail : m_pImpl->bIsGreetingLine;
    1145             : }
    1146             : 
    1147           0 : void     SwMailMergeConfigItem::SetGreetingLine(bool bSet, bool bInEMail)
    1148             : {
    1149           0 :     m_pImpl->bUserSettingWereOverwritten = false;
    1150           0 :     if(bInEMail)
    1151             :     {
    1152           0 :         if(m_pImpl->bIsGreetingLineInMail != bSet)
    1153             :         {
    1154           0 :             m_pImpl->bIsGreetingLineInMail = bSet;
    1155           0 :             m_pImpl->SetModified();
    1156             :         }
    1157             :     }
    1158             :     else
    1159             :     {
    1160           0 :         if(m_pImpl->bIsGreetingLine != bSet)
    1161             :         {
    1162           0 :             m_pImpl->bIsGreetingLine = bSet;
    1163           0 :             m_pImpl->SetModified();
    1164             :         }
    1165             :     }
    1166           0 : }
    1167             : 
    1168           0 : const Sequence< OUString>   SwMailMergeConfigItem::GetGreetings(
    1169             :         Gender eType ) const
    1170             : {
    1171           0 :     return m_pImpl->GetGreetings(eType);
    1172             : }
    1173             : 
    1174           0 : void  SwMailMergeConfigItem::SetGreetings(
    1175             :         Gender eType, const Sequence< OUString>& rSetGreetings)
    1176             : {
    1177           0 :     m_pImpl->SetGreetings( eType, rSetGreetings);
    1178           0 : }
    1179             : 
    1180           0 : sal_Int32 SwMailMergeConfigItem::GetCurrentGreeting(
    1181             :                         SwMailMergeConfigItem::Gender eType) const
    1182             : {
    1183           0 :     return m_pImpl->GetCurrentGreeting(eType);
    1184             : }
    1185             : 
    1186           0 : void SwMailMergeConfigItem::SetCurrentGreeting(Gender eType, sal_Int32 nIndex)
    1187             : {
    1188           0 :     m_pImpl->SetCurrentGreeting(eType, nIndex);
    1189           0 : }
    1190             : 
    1191           0 : const OUString& SwMailMergeConfigItem::GetFemaleGenderValue() const
    1192             : {
    1193           0 :     return m_pImpl->sFemaleGenderValue;
    1194             : }
    1195             : 
    1196           0 : void SwMailMergeConfigItem::SetFemaleGenderValue(const OUString& rValue)
    1197             : {
    1198           0 :     if( m_pImpl->sFemaleGenderValue != rValue )
    1199             :     {
    1200           0 :         m_pImpl->sFemaleGenderValue = rValue;
    1201           0 :         m_pImpl->SetModified();
    1202             :     }
    1203           0 : }
    1204             : 
    1205           0 : Sequence< OUString> SwMailMergeConfigItem::GetColumnAssignment(
    1206             :                 const SwDBData& rDBData ) const
    1207             : {
    1208           0 :     Sequence< OUString> aRet;
    1209           0 :     ::std::vector<DBAddressDataAssignment>::iterator aAssignIter;
    1210           0 :     for(aAssignIter = m_pImpl->aAddressDataAssignments.begin();
    1211           0 :                 aAssignIter != m_pImpl->aAddressDataAssignments.end(); ++aAssignIter)
    1212             :     {
    1213           0 :         if(aAssignIter->aDBData == rDBData)
    1214             :         {
    1215           0 :             aRet = aAssignIter->aDBColumnAssignments;
    1216           0 :             break;
    1217             :         }
    1218             :     }
    1219           0 :     return aRet;
    1220             : }
    1221             : 
    1222             : // returns the name that is assigned as e-mail column of the current data base
    1223           0 : OUString     SwMailMergeConfigItem::GetAssignedColumn(sal_uInt32 nColumn) const
    1224             : {
    1225           0 :     OUString sRet;
    1226           0 :     Sequence< OUString> aAssignment = GetColumnAssignment( m_pImpl->aDBData );
    1227           0 :     if(aAssignment.getLength() > sal::static_int_cast< sal_Int32, sal_uInt32>(nColumn) && !aAssignment[nColumn].isEmpty())
    1228           0 :         sRet = aAssignment[nColumn];
    1229           0 :     else if(nColumn < m_pImpl->m_AddressHeaderSA.Count())
    1230           0 :         sRet = m_pImpl->m_AddressHeaderSA.GetString(nColumn);
    1231           0 :     return sRet;
    1232             : }
    1233             : 
    1234           0 : void SwMailMergeConfigItem::SetColumnAssignment( const SwDBData& rDBData,
    1235             :                             const Sequence< OUString>& rList)
    1236             : {
    1237           0 :     ::std::vector<DBAddressDataAssignment>::iterator aAssignIter;
    1238           0 :     bool bFound = false;
    1239           0 :     for(aAssignIter = m_pImpl->aAddressDataAssignments.begin();
    1240           0 :                 aAssignIter != m_pImpl->aAddressDataAssignments.end(); ++aAssignIter)
    1241             :     {
    1242           0 :         if(aAssignIter->aDBData == rDBData)
    1243             :         {
    1244           0 :             if(aAssignIter->aDBColumnAssignments != rList)
    1245             :             {
    1246           0 :                 aAssignIter->aDBColumnAssignments = rList;
    1247           0 :                 aAssignIter->bColumnAssignmentsChanged = true;
    1248             :             }
    1249           0 :             bFound = true;
    1250           0 :             break;
    1251             :         }
    1252             :     }
    1253           0 :     if(!bFound)
    1254             :     {
    1255           0 :         DBAddressDataAssignment aAssignment;
    1256           0 :         aAssignment.aDBData = rDBData;
    1257           0 :         aAssignment.aDBColumnAssignments = rList;
    1258           0 :         aAssignment.bColumnAssignmentsChanged = true;
    1259           0 :         m_pImpl->aAddressDataAssignments.push_back(aAssignment);
    1260             :     }
    1261           0 :     m_pImpl->SetModified();
    1262           0 : }
    1263             : 
    1264           0 : bool SwMailMergeConfigItem::IsAddressFieldsAssigned() const
    1265             : {
    1266           0 :     bool bResult = true;
    1267           0 :     Reference< XResultSet> xResultSet = GetResultSet();
    1268           0 :     uno::Reference< XColumnsSupplier > xColsSupp( xResultSet, UNO_QUERY );
    1269           0 :     if(!xColsSupp.is())
    1270           0 :         return false;
    1271           0 :     uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
    1272             : 
    1273           0 :     const ResStringArray& rHeaders = GetDefaultAddressHeaders();
    1274             :     Sequence< OUString> aAssignment =
    1275           0 :                         GetColumnAssignment( GetCurrentDBData() );
    1276           0 :     const OUString* pAssignment = aAssignment.getConstArray();
    1277           0 :     const Sequence< OUString> aBlocks = GetAddressBlocks();
    1278             : 
    1279           0 :     if(aBlocks.getLength() <= m_pImpl->GetCurrentAddressBlockIndex())
    1280           0 :         return false;
    1281           0 :     SwAddressIterator aIter(aBlocks[m_pImpl->GetCurrentAddressBlockIndex()]);
    1282           0 :     while(aIter.HasMore())
    1283             :     {
    1284           0 :         SwMergeAddressItem aItem = aIter.Next();
    1285           0 :         if(aItem.bIsColumn)
    1286             :         {
    1287           0 :             OUString sConvertedColumn = aItem.sText;
    1288           0 :             for(sal_uInt16 nColumn = 0;
    1289           0 :                     nColumn < rHeaders.Count() && nColumn < aAssignment.getLength();
    1290             :                                                                                 ++nColumn)
    1291             :             {
    1292           0 :                 if (rHeaders.GetString(nColumn).equals(aItem.sText) &&
    1293           0 :                     !pAssignment[nColumn].isEmpty())
    1294             :                 {
    1295           0 :                     sConvertedColumn = pAssignment[nColumn];
    1296           0 :                     break;
    1297             :                 }
    1298             :             }
    1299             :             //find out if the column exists in the data base
    1300           0 :             if(!xCols->hasByName(sConvertedColumn))
    1301             :             {
    1302           0 :                 bResult = false;
    1303           0 :                 break;
    1304           0 :             }
    1305             :         }
    1306           0 :     }
    1307           0 :     return bResult;
    1308             : }
    1309             : 
    1310           0 : bool SwMailMergeConfigItem::IsGreetingFieldsAssigned() const
    1311             : {
    1312           0 :     bool bResult = true;
    1313             : 
    1314           0 :     if(!IsIndividualGreeting(false))
    1315           0 :         return true;
    1316             : 
    1317           0 :     Reference< XResultSet> xResultSet = GetResultSet();
    1318           0 :     uno::Reference< XColumnsSupplier > xColsSupp( xResultSet, UNO_QUERY );
    1319           0 :     if(!xColsSupp.is())
    1320           0 :         return false;
    1321           0 :     const ResStringArray& rHeaders = GetDefaultAddressHeaders();
    1322           0 :     uno::Reference<container::XNameAccess> xCols = xColsSupp->getColumns();
    1323             : 
    1324             :     Sequence< OUString> aAssignment =
    1325           0 :                         GetColumnAssignment( GetCurrentDBData() );
    1326           0 :     const OUString* pAssignment = aAssignment.getConstArray();
    1327             : 
    1328           0 :     const Sequence< OUString> rFemaleEntries = GetGreetings(SwMailMergeConfigItem::FEMALE);
    1329           0 :     sal_Int32 nCurrentFemale = GetCurrentGreeting(SwMailMergeConfigItem::FEMALE);
    1330           0 :     const Sequence< OUString> rMaleEntries = GetGreetings(SwMailMergeConfigItem::MALE);
    1331           0 :     sal_Int32 nCurrentMale = GetCurrentGreeting(SwMailMergeConfigItem::MALE);
    1332           0 :     OUString sMale, sFemale;
    1333           0 :     if(rFemaleEntries.getLength() > nCurrentFemale)
    1334           0 :         sFemale = rFemaleEntries[nCurrentFemale];
    1335           0 :     if(rMaleEntries.getLength() > nCurrentMale)
    1336           0 :         sMale = rMaleEntries[nCurrentMale];
    1337             : 
    1338           0 :     OUString sAddress( sFemale );
    1339           0 :     sAddress += sMale;
    1340           0 :     SwAddressIterator aIter(sAddress);
    1341           0 :     while(aIter.HasMore())
    1342             :     {
    1343           0 :         SwMergeAddressItem aItem = aIter.Next();
    1344           0 :         if(aItem.bIsColumn)
    1345             :         {
    1346           0 :             OUString sConvertedColumn = aItem.sText;
    1347           0 :             for(sal_uInt16 nColumn = 0;
    1348           0 :                     nColumn < rHeaders.Count() && nColumn < aAssignment.getLength();
    1349             :                                                                                 ++nColumn)
    1350             :             {
    1351           0 :                 if (rHeaders.GetString(nColumn).equals(aItem.sText) &&
    1352           0 :                     !pAssignment[nColumn].isEmpty())
    1353             :                 {
    1354           0 :                     sConvertedColumn = pAssignment[nColumn];
    1355           0 :                     break;
    1356             :                 }
    1357             :             }
    1358             :             //find out if the column exists in the data base
    1359           0 :             if(!xCols->hasByName(sConvertedColumn))
    1360             :             {
    1361           0 :                 bResult = false;
    1362           0 :                 break;
    1363           0 :             }
    1364             :         }
    1365           0 :     }
    1366           0 :     return bResult;
    1367             : }
    1368             : 
    1369           0 : OUString     SwMailMergeConfigItem::GetMailDisplayName() const
    1370             : {
    1371           0 :     return m_pImpl->sMailDisplayName;
    1372             : }
    1373             : 
    1374           0 : void SwMailMergeConfigItem::SetMailDisplayName(const OUString& rName)
    1375             : {
    1376           0 :     if(m_pImpl->sMailDisplayName != rName)
    1377             :     {
    1378           0 :         m_pImpl->sMailDisplayName = rName;
    1379           0 :         m_pImpl->SetModified();
    1380             :     }
    1381           0 : }
    1382             : 
    1383           0 : OUString     SwMailMergeConfigItem::GetMailAddress() const
    1384             : {
    1385           0 :     return m_pImpl->sMailAddress;
    1386             : }
    1387             : 
    1388           0 : void SwMailMergeConfigItem::SetMailAddress(const OUString& rAddress)
    1389             : {
    1390           0 :     if(m_pImpl->sMailAddress != rAddress )
    1391             :     {
    1392           0 :         m_pImpl->sMailAddress = rAddress;
    1393           0 :         m_pImpl->SetModified();
    1394             :     }
    1395           0 : }
    1396             : 
    1397           0 : bool SwMailMergeConfigItem::IsMailReplyTo() const
    1398             : {
    1399           0 :     return m_pImpl->bIsMailReplyTo;
    1400             : }
    1401             : 
    1402           0 : void  SwMailMergeConfigItem::SetMailReplyTo(bool bSet)
    1403             : {
    1404           0 :     if(m_pImpl->bIsMailReplyTo != bSet)
    1405             :     {
    1406           0 :         m_pImpl->bIsMailReplyTo = bSet;
    1407           0 :         m_pImpl->SetModified();
    1408             :     }
    1409           0 : }
    1410             : 
    1411           0 : OUString     SwMailMergeConfigItem::GetMailReplyTo() const
    1412             : {
    1413           0 :     return m_pImpl->sMailReplyTo;
    1414             : }
    1415             : 
    1416           0 : void SwMailMergeConfigItem::SetMailReplyTo(const OUString& rReplyTo)
    1417             : {
    1418           0 :     if(m_pImpl->sMailReplyTo != rReplyTo)
    1419             :     {
    1420           0 :         m_pImpl->sMailReplyTo = rReplyTo;
    1421           0 :         m_pImpl->SetModified();
    1422             :     }
    1423           0 : }
    1424             : 
    1425           0 : OUString  SwMailMergeConfigItem::GetMailServer() const
    1426             : {
    1427           0 :     return m_pImpl->sMailServer;
    1428             : }
    1429             : 
    1430           0 : void SwMailMergeConfigItem::SetMailServer(const OUString& rAddress)
    1431             : {
    1432           0 :     if(m_pImpl->sMailServer != rAddress)
    1433             :     {
    1434           0 :         m_pImpl->sMailServer = rAddress;
    1435           0 :         m_pImpl->SetModified();
    1436             :     }
    1437           0 : }
    1438             : 
    1439           0 : sal_Int16 SwMailMergeConfigItem::GetMailPort() const
    1440             : {
    1441             :     return m_pImpl->bIsDefaultPort ?
    1442             :              (m_pImpl->bIsSecureConnection ? SECURE_PORT : DEFAULT_PORT) :
    1443           0 :              m_pImpl->nMailPort;
    1444             : }
    1445             : 
    1446           0 : void     SwMailMergeConfigItem::SetMailPort(sal_Int16 nSet)
    1447             : {
    1448           0 :     if(m_pImpl->nMailPort != nSet || m_pImpl->bIsDefaultPort)
    1449             :     {
    1450           0 :         m_pImpl->nMailPort = nSet;
    1451           0 :         m_pImpl->bIsDefaultPort = false;
    1452           0 :         m_pImpl->SetModified();
    1453             :     }
    1454           0 : }
    1455             : 
    1456           0 : bool SwMailMergeConfigItem::IsSecureConnection() const
    1457             : {
    1458           0 :     return m_pImpl->bIsSecureConnection;
    1459             : }
    1460             : 
    1461           0 : void     SwMailMergeConfigItem::SetSecureConnection(bool bSet)
    1462             : {
    1463           0 :     if(m_pImpl->bIsSecureConnection != bSet)
    1464             :     {
    1465           0 :         m_pImpl->bIsSecureConnection = bSet;
    1466           0 :         m_pImpl->SetModified();
    1467             :     }
    1468           0 : }
    1469             : 
    1470           0 : bool SwMailMergeConfigItem::IsAuthentication() const
    1471             : {
    1472           0 :     return m_pImpl->bIsAuthentication;
    1473             : }
    1474             : 
    1475           0 : void SwMailMergeConfigItem::SetAuthentication(bool bSet)
    1476             : {
    1477           0 :     if(m_pImpl->bIsAuthentication != bSet)
    1478             :     {
    1479           0 :         m_pImpl->bIsAuthentication = bSet;
    1480           0 :         m_pImpl->SetModified();
    1481             :     }
    1482           0 : }
    1483             : 
    1484           0 : OUString     SwMailMergeConfigItem::GetMailUserName() const
    1485             : {
    1486           0 :     return m_pImpl->sMailUserName;
    1487             : }
    1488             : 
    1489           0 : void SwMailMergeConfigItem::SetMailUserName(const OUString& rName)
    1490             : {
    1491           0 :     if(m_pImpl->sMailUserName != rName)
    1492             :     {
    1493           0 :         m_pImpl->sMailUserName = rName;
    1494           0 :         m_pImpl->SetModified();
    1495             :     }
    1496           0 : }
    1497             : 
    1498           0 : OUString     SwMailMergeConfigItem::GetMailPassword() const
    1499             : {
    1500           0 :     return m_pImpl->sMailPassword;
    1501             : }
    1502             : 
    1503           0 : void SwMailMergeConfigItem::SetMailPassword(const OUString& rPassword)
    1504             : {
    1505           0 :     if(m_pImpl->sMailPassword != rPassword)
    1506             :     {
    1507           0 :         m_pImpl->sMailPassword = rPassword;
    1508           0 :         m_pImpl->SetModified();
    1509             :     }
    1510           0 : }
    1511             : 
    1512           0 : bool SwMailMergeConfigItem::IsSMTPAfterPOP() const
    1513             : {
    1514           0 :     return m_pImpl->bIsSMPTAfterPOP;
    1515             : }
    1516             : 
    1517           0 : void SwMailMergeConfigItem::SetSMTPAfterPOP(bool bSet)
    1518             : {
    1519           0 :     if( m_pImpl->bIsSMPTAfterPOP != bSet)
    1520             :     {
    1521           0 :         m_pImpl->bIsSMPTAfterPOP = bSet;
    1522           0 :         m_pImpl->SetModified();
    1523             :     }
    1524           0 : }
    1525             : 
    1526           0 : OUString     SwMailMergeConfigItem::GetInServerName() const
    1527             : {
    1528           0 :     return m_pImpl->sInServerName;
    1529             : }
    1530             : 
    1531           0 : void SwMailMergeConfigItem::SetInServerName(const OUString& rServer)
    1532             : {
    1533           0 :     if(m_pImpl->sInServerName != rServer)
    1534             :     {
    1535           0 :         m_pImpl->sInServerName = rServer;
    1536           0 :         m_pImpl->SetModified();
    1537             :     }
    1538           0 : }
    1539             : 
    1540           0 : sal_Int16           SwMailMergeConfigItem::GetInServerPort() const
    1541             : {
    1542           0 :     return m_pImpl->nInServerPort;
    1543             : }
    1544             : 
    1545           0 : void SwMailMergeConfigItem::SetInServerPort(sal_Int16 nSet)
    1546             : {
    1547           0 :     if( m_pImpl->nInServerPort != nSet)
    1548             :     {
    1549           0 :         m_pImpl->nInServerPort = nSet;
    1550           0 :         m_pImpl->SetModified();
    1551             :     }
    1552           0 : }
    1553             : 
    1554           0 : bool SwMailMergeConfigItem::IsInServerPOP() const
    1555             : {
    1556           0 :     return m_pImpl->bInServerPOP;
    1557             : }
    1558             : 
    1559           0 : void SwMailMergeConfigItem::SetInServerPOP(bool bSet)
    1560             : {
    1561           0 :     if( m_pImpl->bInServerPOP != bSet)
    1562             :     {
    1563           0 :         m_pImpl->bInServerPOP = bSet;
    1564           0 :         m_pImpl->SetModified();
    1565             :     }
    1566           0 : }
    1567             : 
    1568           0 : OUString     SwMailMergeConfigItem::GetInServerUserName() const
    1569             : {
    1570           0 :     return m_pImpl->sInServerUserName;
    1571             : }
    1572             : 
    1573           0 : void SwMailMergeConfigItem::SetInServerUserName(const OUString& rName)
    1574             : {
    1575           0 :     if( m_pImpl->sInServerUserName != rName)
    1576             :     {
    1577           0 :         m_pImpl->sInServerUserName = rName;
    1578           0 :         m_pImpl->SetModified();
    1579             :     }
    1580           0 : }
    1581             : 
    1582           0 : OUString     SwMailMergeConfigItem::GetInServerPassword() const
    1583             : {
    1584           0 :     return m_pImpl->sInServerPassword;
    1585             : }
    1586             : 
    1587           0 : void SwMailMergeConfigItem::SetInServerPassword(const OUString& rPassword)
    1588             : {
    1589           0 :     if(m_pImpl->sInServerPassword != rPassword)
    1590             :     {
    1591           0 :         m_pImpl->sInServerPassword = rPassword;
    1592           0 :         m_pImpl->SetModified();
    1593             :     }
    1594           0 : }
    1595             : 
    1596           0 : void SwMailMergeConfigItem::DocumentReloaded()
    1597             : {
    1598           0 :     m_bMergeDone = false;
    1599           0 :     m_bGreetingInserted = false;
    1600           0 :     m_bAddressInserted = false;
    1601           0 :     m_rAddressBlockFrame.clear();
    1602           0 : }
    1603             : 
    1604           0 : bool SwMailMergeConfigItem::IsMailAvailable() const
    1605             : {
    1606           0 :     return m_pImpl->bIsEMailSupported;
    1607             : }
    1608             : 
    1609          44 : void SwMailMergeConfigItem::AddMergedDocument(SwDocMergeInfo& rInfo)
    1610             : {
    1611          44 :     m_pImpl->aMergeInfos.push_back(rInfo);
    1612          44 : }
    1613             : 
    1614           0 : SwDocMergeInfo& SwMailMergeConfigItem::GetDocumentMergeInfo(sal_uInt32 nDocument)
    1615             : {
    1616             :     assert(nDocument < m_pImpl->aMergeInfos.size());
    1617           0 :     return m_pImpl->aMergeInfos[nDocument];
    1618             : }
    1619             : 
    1620           0 : sal_uInt32 SwMailMergeConfigItem::GetMergedDocumentCount() const
    1621             : {
    1622           0 :     return m_pImpl->aMergeInfos.size();
    1623             : }
    1624             : 
    1625           5 : static SwView* lcl_ExistsView(SwView* pView)
    1626             : {
    1627           5 :     const TypeId aType(TYPE(SwView));
    1628           5 :     SfxViewShell* pViewShell = SfxViewShell::GetFirst( &aType, false );
    1629          42 :     while(pViewShell)
    1630             :     {
    1631          37 :         if(pViewShell == pView)
    1632           5 :             return pView;
    1633             : 
    1634          32 :         pViewShell = SfxViewShell::GetNext( *pViewShell, &aType, false );
    1635             :     }
    1636           0 :     return 0;
    1637             : }
    1638             : 
    1639           5 : SwView*  SwMailMergeConfigItem::GetTargetView()
    1640             : {
    1641             :     //make sure that the pointer is really valid - the document may have been closed manually
    1642           5 :     if(m_pTargetView)
    1643             :     {
    1644           5 :         m_pTargetView = lcl_ExistsView(m_pTargetView);
    1645             :     }
    1646           5 :     return m_pTargetView;
    1647             : }
    1648             : 
    1649           5 : void  SwMailMergeConfigItem::SetTargetView(SwView* pView)
    1650             : {
    1651           5 :     m_pTargetView = pView;
    1652             :     //reset the document merge counter
    1653           5 :     if(!m_pTargetView)
    1654             :     {
    1655           0 :         m_pImpl->aMergeInfos.clear();
    1656             :     }
    1657           5 : }
    1658             : 
    1659           0 : SwView* SwMailMergeConfigItem::GetSourceView()
    1660             : {
    1661           0 :     m_pSourceView = lcl_ExistsView(m_pSourceView);
    1662           0 :     return m_pSourceView;
    1663             : }
    1664             : 
    1665           0 : void SwMailMergeConfigItem::SetSourceView(SwView* pView)
    1666             : {
    1667           0 :     m_pSourceView = pView;
    1668             : 
    1669           0 :     if(pView)
    1670             :     {
    1671           0 :         std::vector<OUString> aDBNameList;
    1672           0 :         std::vector<OUString> aAllDBNames;
    1673           0 :         pView->GetWrtShell().GetAllUsedDB( aDBNameList, &aAllDBNames );
    1674           0 :         if(!aDBNameList.empty())
    1675             :         {
    1676             :             // if fields are available there is usually no need of an addressblock and greeting
    1677           0 :             if(!m_pImpl->bUserSettingWereOverwritten)
    1678             :             {
    1679           0 :                 if( m_pImpl->bIsAddressBlock
    1680           0 :                     || m_pImpl->bIsGreetingLineInMail
    1681           0 :                     || m_pImpl->bIsGreetingLine )
    1682             :                 {
    1683             :                     //store user settings
    1684           0 :                     m_pImpl->bUserSettingWereOverwritten = true;
    1685           0 :                     m_pImpl->bIsAddressBlock_LastUserSetting = m_pImpl->bIsAddressBlock;
    1686           0 :                     m_pImpl->bIsGreetingLineInMail_LastUserSetting = m_pImpl->bIsGreetingLineInMail;
    1687           0 :                     m_pImpl->bIsGreetingLine_LastUserSetting = m_pImpl->bIsGreetingLine;
    1688             : 
    1689             :                     //set all to false
    1690           0 :                     m_pImpl->bIsAddressBlock = false;
    1691           0 :                     m_pImpl->bIsGreetingLineInMail = false;
    1692           0 :                     m_pImpl->bIsGreetingLine = false;
    1693             : 
    1694           0 :                     m_pImpl->SetModified();
    1695             :                 }
    1696             :             }
    1697             :         }
    1698           0 :         else if( m_pImpl->bUserSettingWereOverwritten )
    1699             :         {
    1700             :             //restore last user settings:
    1701           0 :             m_pImpl->bIsAddressBlock = m_pImpl->bIsAddressBlock_LastUserSetting;
    1702           0 :             m_pImpl->bIsGreetingLineInMail = m_pImpl->bIsGreetingLineInMail_LastUserSetting;
    1703           0 :             m_pImpl->bIsGreetingLine = m_pImpl->bIsGreetingLine_LastUserSetting;
    1704             : 
    1705           0 :             m_pImpl->bUserSettingWereOverwritten = false;
    1706           0 :         }
    1707             :     }
    1708           0 : }
    1709             : 
    1710           0 : void SwMailMergeConfigItem::SetCurrentAddressBlockIndex( sal_Int32 nSet )
    1711             : {
    1712           0 :     m_pImpl->SetCurrentAddressBlockIndex( nSet );
    1713           0 : }
    1714             : 
    1715           0 : sal_Int32 SwMailMergeConfigItem::GetCurrentAddressBlockIndex() const
    1716             : {
    1717           0 :     return m_pImpl->GetCurrentAddressBlockIndex();
    1718         177 : }
    1719             : 
    1720             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.11