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

Generated by: LCOV version 1.10