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