LCOV - code coverage report
Current view: top level - sw/source/uibase/dbui - mmconfigitem.cxx (source / functions) Hit Total Coverage
Test: commit 10e77ab3ff6f4314137acd6e2702a6e5c1ce1fae Lines: 180 836 21.5 %
Date: 2014-11-03 Functions: 18 113 15.9 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10