xref: /aoo41x/main/svl/source/config/srchcfg.cxx (revision cdf0e10c)
1*cdf0e10cSrcweir /*************************************************************************
2*cdf0e10cSrcweir  *
3*cdf0e10cSrcweir  * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
4*cdf0e10cSrcweir  *
5*cdf0e10cSrcweir  * Copyright 2000, 2010 Oracle and/or its affiliates.
6*cdf0e10cSrcweir  *
7*cdf0e10cSrcweir  * OpenOffice.org - a multi-platform office productivity suite
8*cdf0e10cSrcweir  *
9*cdf0e10cSrcweir  * This file is part of OpenOffice.org.
10*cdf0e10cSrcweir  *
11*cdf0e10cSrcweir  * OpenOffice.org is free software: you can redistribute it and/or modify
12*cdf0e10cSrcweir  * it under the terms of the GNU Lesser General Public License version 3
13*cdf0e10cSrcweir  * only, as published by the Free Software Foundation.
14*cdf0e10cSrcweir  *
15*cdf0e10cSrcweir  * OpenOffice.org is distributed in the hope that it will be useful,
16*cdf0e10cSrcweir  * but WITHOUT ANY WARRANTY; without even the implied warranty of
17*cdf0e10cSrcweir  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
18*cdf0e10cSrcweir  * GNU Lesser General Public License version 3 for more details
19*cdf0e10cSrcweir  * (a copy is included in the LICENSE file that accompanied this code).
20*cdf0e10cSrcweir  *
21*cdf0e10cSrcweir  * You should have received a copy of the GNU Lesser General Public License
22*cdf0e10cSrcweir  * version 3 along with OpenOffice.org.  If not, see
23*cdf0e10cSrcweir  * <http://www.openoffice.org/license.html>
24*cdf0e10cSrcweir  * for a copy of the LGPLv3 License.
25*cdf0e10cSrcweir  *
26*cdf0e10cSrcweir  ************************************************************************/
27*cdf0e10cSrcweir 
28*cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
29*cdf0e10cSrcweir #include "precompiled_svl.hxx"
30*cdf0e10cSrcweir 
31*cdf0e10cSrcweir #include <svl/srchcfg.hxx>
32*cdf0e10cSrcweir #include <svl/svarray.hxx>
33*cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
34*cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
35*cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
36*cdf0e10cSrcweir #include <tools/debug.hxx>
37*cdf0e10cSrcweir #include <unotools/configpathes.hxx>
38*cdf0e10cSrcweir 
39*cdf0e10cSrcweir //-----------------------------------------------------------------------------
40*cdf0e10cSrcweir using namespace utl;
41*cdf0e10cSrcweir using namespace rtl;
42*cdf0e10cSrcweir using namespace com::sun::star;
43*cdf0e10cSrcweir using namespace com::sun::star::uno;
44*cdf0e10cSrcweir using namespace com::sun::star::beans;
45*cdf0e10cSrcweir 
46*cdf0e10cSrcweir #define C2U(cChar) OUString::createFromAscii(cChar)
47*cdf0e10cSrcweir 
48*cdf0e10cSrcweir //-----------------------------------------------------------------------------
49*cdf0e10cSrcweir typedef SvxSearchEngineData* SvxSearchEngineDataPtr;
50*cdf0e10cSrcweir SV_DECL_PTRARR_DEL(SvxSearchEngineArr, SvxSearchEngineDataPtr, 2, 2)
51*cdf0e10cSrcweir SV_IMPL_PTRARR(SvxSearchEngineArr, SvxSearchEngineDataPtr);
52*cdf0e10cSrcweir //-----------------------------------------------------------------------------
53*cdf0e10cSrcweir struct SvxSearchConfig_Impl
54*cdf0e10cSrcweir {
55*cdf0e10cSrcweir     SvxSearchEngineArr   aEngineArr;
56*cdf0e10cSrcweir };
57*cdf0e10cSrcweir /* -----------------------------19.03.01 14:00--------------------------------
58*cdf0e10cSrcweir 
59*cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
60*cdf0e10cSrcweir sal_Bool SvxSearchEngineData::operator==(const SvxSearchEngineData& rData)
61*cdf0e10cSrcweir {
62*cdf0e10cSrcweir     return sEngineName      == rData.sEngineName     &&
63*cdf0e10cSrcweir             sAndPrefix       == rData.sAndPrefix      &&
64*cdf0e10cSrcweir             sAndSuffix       == rData.sAndSuffix      &&
65*cdf0e10cSrcweir             sAndSeparator    == rData.sAndSeparator   &&
66*cdf0e10cSrcweir             nAndCaseMatch    == rData.nAndCaseMatch   &&
67*cdf0e10cSrcweir             sOrPrefix        == rData.sOrPrefix       &&
68*cdf0e10cSrcweir             sOrSuffix        == rData.sOrSuffix       &&
69*cdf0e10cSrcweir             sOrSeparator     == rData.sOrSeparator    &&
70*cdf0e10cSrcweir             nOrCaseMatch     == rData.nOrCaseMatch    &&
71*cdf0e10cSrcweir             sExactPrefix     == rData.sExactPrefix    &&
72*cdf0e10cSrcweir             sExactSuffix     == rData.sExactSuffix    &&
73*cdf0e10cSrcweir             sExactSeparator  == rData.sExactSeparator &&
74*cdf0e10cSrcweir             nExactCaseMatch  == rData.nExactCaseMatch;
75*cdf0e10cSrcweir }
76*cdf0e10cSrcweir /* -----------------------------16.01.01 15:36--------------------------------
77*cdf0e10cSrcweir 
78*cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
79*cdf0e10cSrcweir const Sequence<OUString>& lcl_GetSearchPropertyNames_Impl()
80*cdf0e10cSrcweir {
81*cdf0e10cSrcweir     static Sequence<OUString> aNames;
82*cdf0e10cSrcweir     if(!aNames.getLength())
83*cdf0e10cSrcweir     {
84*cdf0e10cSrcweir         aNames.realloc(12);
85*cdf0e10cSrcweir         OUString* pNames = aNames.getArray();
86*cdf0e10cSrcweir         pNames[0] = C2U("And/ooInetPrefix");
87*cdf0e10cSrcweir         pNames[1] = C2U("And/ooInetSuffix");
88*cdf0e10cSrcweir         pNames[2] = C2U("And/ooInetSeparator");
89*cdf0e10cSrcweir         pNames[3] = C2U("And/ooInetCaseMatch");
90*cdf0e10cSrcweir         pNames[4] = C2U("Or/ooInetPrefix");
91*cdf0e10cSrcweir         pNames[5] = C2U("Or/ooInetSuffix");
92*cdf0e10cSrcweir         pNames[6] = C2U("Or/ooInetSeparator");
93*cdf0e10cSrcweir         pNames[7] = C2U("Or/ooInetCaseMatch");
94*cdf0e10cSrcweir         pNames[8] = C2U("Exact/ooInetPrefix");
95*cdf0e10cSrcweir         pNames[9] = C2U("Exact/ooInetSuffix");
96*cdf0e10cSrcweir         pNames[10] = C2U("Exact/ooInetSeparator");
97*cdf0e10cSrcweir         pNames[11] = C2U("Exact/ooInetCaseMatch");
98*cdf0e10cSrcweir     }
99*cdf0e10cSrcweir     return aNames;
100*cdf0e10cSrcweir }
101*cdf0e10cSrcweir // ---------------------------------------------------------------------------
102*cdf0e10cSrcweir SvxSearchConfig::SvxSearchConfig(sal_Bool bEnableNotify) :
103*cdf0e10cSrcweir     utl::ConfigItem(C2U("Inet/SearchEngines"), CONFIG_MODE_DELAYED_UPDATE),
104*cdf0e10cSrcweir     pImpl(new SvxSearchConfig_Impl)
105*cdf0e10cSrcweir {
106*cdf0e10cSrcweir 	if(bEnableNotify)
107*cdf0e10cSrcweir     {
108*cdf0e10cSrcweir         //request notifications from the node
109*cdf0e10cSrcweir         Sequence<OUString> aEnable(1);
110*cdf0e10cSrcweir         EnableNotification(aEnable);
111*cdf0e10cSrcweir     }
112*cdf0e10cSrcweir 	Load();
113*cdf0e10cSrcweir }
114*cdf0e10cSrcweir /* -----------------------------16.01.01 15:36--------------------------------
115*cdf0e10cSrcweir 
116*cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
117*cdf0e10cSrcweir SvxSearchConfig::~SvxSearchConfig()
118*cdf0e10cSrcweir {
119*cdf0e10cSrcweir 	delete pImpl;
120*cdf0e10cSrcweir }
121*cdf0e10cSrcweir /* -----------------------------17.01.01 09:57--------------------------------
122*cdf0e10cSrcweir 
123*cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
124*cdf0e10cSrcweir void SvxSearchConfig::Load()
125*cdf0e10cSrcweir {
126*cdf0e10cSrcweir     pImpl->aEngineArr.DeleteAndDestroy(0, pImpl->aEngineArr.Count());
127*cdf0e10cSrcweir     Sequence<OUString> aNodeNames = GetNodeNames(OUString());
128*cdf0e10cSrcweir     const OUString* pNodeNames = aNodeNames.getConstArray();
129*cdf0e10cSrcweir     for(sal_Int32 nNode = 0; nNode < aNodeNames.getLength(); nNode++)
130*cdf0e10cSrcweir     {
131*cdf0e10cSrcweir         SvxSearchEngineDataPtr pNew = new SvxSearchEngineData;
132*cdf0e10cSrcweir         pNew->sEngineName = pNodeNames[nNode];
133*cdf0e10cSrcweir         const Sequence<OUString>& rPropNames = lcl_GetSearchPropertyNames_Impl();
134*cdf0e10cSrcweir         const OUString* pPropNames = rPropNames.getConstArray();
135*cdf0e10cSrcweir         Sequence<OUString> aPropertyNames(rPropNames.getLength());
136*cdf0e10cSrcweir         OUString* pPropertyNames = aPropertyNames.getArray();
137*cdf0e10cSrcweir         const OUString sSlash(C2U("/"));
138*cdf0e10cSrcweir         sal_Int32 nProp;
139*cdf0e10cSrcweir         for(nProp = 0; nProp < rPropNames.getLength(); nProp++)
140*cdf0e10cSrcweir         {
141*cdf0e10cSrcweir             pPropertyNames[nProp] = wrapConfigurationElementName(pNodeNames[nNode]);
142*cdf0e10cSrcweir             pPropertyNames[nProp] += sSlash;
143*cdf0e10cSrcweir             pPropertyNames[nProp] += pPropNames[nProp];
144*cdf0e10cSrcweir         }
145*cdf0e10cSrcweir         Sequence<Any> aValues = GetProperties(aPropertyNames);
146*cdf0e10cSrcweir         const Any* pValues = aValues.getConstArray();
147*cdf0e10cSrcweir         for(nProp = 0; nProp < rPropNames.getLength(); nProp++)
148*cdf0e10cSrcweir         {
149*cdf0e10cSrcweir             switch(nProp)
150*cdf0e10cSrcweir             {
151*cdf0e10cSrcweir                 case 0 : pValues[nProp] >>= pNew->sAndPrefix;      break;
152*cdf0e10cSrcweir                 case 1 : pValues[nProp] >>= pNew->sAndSuffix;      break;
153*cdf0e10cSrcweir                 case 2 : pValues[nProp] >>= pNew->sAndSeparator;   break;
154*cdf0e10cSrcweir                 case 3 : pValues[nProp] >>= pNew->nAndCaseMatch;   break;
155*cdf0e10cSrcweir 
156*cdf0e10cSrcweir                 case 4 : pValues[nProp] >>= pNew->sOrPrefix;       break;
157*cdf0e10cSrcweir                 case 5 : pValues[nProp] >>= pNew->sOrSuffix;       break;
158*cdf0e10cSrcweir                 case 6 : pValues[nProp] >>= pNew->sOrSeparator;    break;
159*cdf0e10cSrcweir                 case 7 : pValues[nProp] >>= pNew->nOrCaseMatch;    break;
160*cdf0e10cSrcweir 
161*cdf0e10cSrcweir                 case 8 : pValues[nProp] >>= pNew->sExactPrefix;    break;
162*cdf0e10cSrcweir                 case 9 : pValues[nProp] >>= pNew->sExactSuffix;    break;
163*cdf0e10cSrcweir                 case 10: pValues[nProp] >>= pNew->sExactSeparator; break;
164*cdf0e10cSrcweir                 case 11: pValues[nProp] >>= pNew->nExactCaseMatch; break;
165*cdf0e10cSrcweir             }
166*cdf0e10cSrcweir         }
167*cdf0e10cSrcweir         pImpl->aEngineArr.Insert(pNew, pImpl->aEngineArr.Count());
168*cdf0e10cSrcweir     }
169*cdf0e10cSrcweir }
170*cdf0e10cSrcweir /* -----------------------------17.01.01 09:57--------------------------------
171*cdf0e10cSrcweir 
172*cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
173*cdf0e10cSrcweir void    SvxSearchConfig::Notify( const Sequence<OUString>& )
174*cdf0e10cSrcweir {
175*cdf0e10cSrcweir 	Load();
176*cdf0e10cSrcweir }
177*cdf0e10cSrcweir /* -----------------------------16.01.01 15:36--------------------------------
178*cdf0e10cSrcweir 
179*cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
180*cdf0e10cSrcweir void SvxSearchConfig::Commit()
181*cdf0e10cSrcweir {
182*cdf0e10cSrcweir     OUString sNode;
183*cdf0e10cSrcweir     if(!pImpl->aEngineArr.Count())
184*cdf0e10cSrcweir         ClearNodeSet(sNode);
185*cdf0e10cSrcweir     else
186*cdf0e10cSrcweir     {
187*cdf0e10cSrcweir         Sequence<PropertyValue> aSetValues(12 * pImpl->aEngineArr.Count());
188*cdf0e10cSrcweir 		PropertyValue* pSetValues = aSetValues.getArray();
189*cdf0e10cSrcweir 
190*cdf0e10cSrcweir         const Sequence<OUString>& rPropNames = lcl_GetSearchPropertyNames_Impl();
191*cdf0e10cSrcweir         const OUString* pPropNames = rPropNames.getConstArray();
192*cdf0e10cSrcweir         const OUString sSlash(C2U("/"));
193*cdf0e10cSrcweir         for(sal_uInt16 i = 0; i < pImpl->aEngineArr.Count(); i++)
194*cdf0e10cSrcweir 		{
195*cdf0e10cSrcweir             SvxSearchEngineDataPtr pSave = pImpl->aEngineArr[i];
196*cdf0e10cSrcweir             for(sal_Int16 nProp = 0; nProp < rPropNames.getLength(); nProp++)
197*cdf0e10cSrcweir             {
198*cdf0e10cSrcweir                 OUString sTmpName = sSlash;
199*cdf0e10cSrcweir                 sTmpName += wrapConfigurationElementName(pSave->sEngineName);
200*cdf0e10cSrcweir                 sTmpName += sSlash;
201*cdf0e10cSrcweir                 sTmpName += pPropNames[nProp];
202*cdf0e10cSrcweir                 pSetValues[nProp].Name = sTmpName;
203*cdf0e10cSrcweir                 switch(nProp)
204*cdf0e10cSrcweir                 {
205*cdf0e10cSrcweir                     case 0 : pSetValues[nProp].Value <<= pSave->sAndPrefix;      break;
206*cdf0e10cSrcweir                     case 1 : pSetValues[nProp].Value <<= pSave->sAndSuffix;      break;
207*cdf0e10cSrcweir                     case 2 : pSetValues[nProp].Value <<= pSave->sAndSeparator;   break;
208*cdf0e10cSrcweir                     case 3 : pSetValues[nProp].Value <<= pSave->nAndCaseMatch;   break;
209*cdf0e10cSrcweir 
210*cdf0e10cSrcweir                     case 4 : pSetValues[nProp].Value <<= pSave->sOrPrefix;       break;
211*cdf0e10cSrcweir                     case 5 : pSetValues[nProp].Value <<= pSave->sOrSuffix;       break;
212*cdf0e10cSrcweir                     case 6 : pSetValues[nProp].Value <<= pSave->sOrSeparator;    break;
213*cdf0e10cSrcweir                     case 7 : pSetValues[nProp].Value <<= pSave->nOrCaseMatch;    break;
214*cdf0e10cSrcweir 
215*cdf0e10cSrcweir                     case 8 : pSetValues[nProp].Value <<= pSave->sExactPrefix;    break;
216*cdf0e10cSrcweir                     case 9 : pSetValues[nProp].Value <<= pSave->sExactSuffix;    break;
217*cdf0e10cSrcweir                     case 10: pSetValues[nProp].Value <<= pSave->sExactSeparator; break;
218*cdf0e10cSrcweir                     case 11: pSetValues[nProp].Value <<= pSave->nExactCaseMatch; break;
219*cdf0e10cSrcweir                 }
220*cdf0e10cSrcweir             }
221*cdf0e10cSrcweir             pSetValues+= 12;
222*cdf0e10cSrcweir         }
223*cdf0e10cSrcweir 		ReplaceSetProperties(sNode, aSetValues);
224*cdf0e10cSrcweir     }
225*cdf0e10cSrcweir }
226*cdf0e10cSrcweir /* -----------------------------19.03.01 10:02--------------------------------
227*cdf0e10cSrcweir 
228*cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
229*cdf0e10cSrcweir sal_uInt16 SvxSearchConfig::Count()
230*cdf0e10cSrcweir {
231*cdf0e10cSrcweir     return pImpl->aEngineArr.Count();
232*cdf0e10cSrcweir }
233*cdf0e10cSrcweir /* -----------------------------19.03.01 10:02--------------------------------
234*cdf0e10cSrcweir 
235*cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
236*cdf0e10cSrcweir const SvxSearchEngineData&  SvxSearchConfig::GetData(sal_uInt16 nPos)
237*cdf0e10cSrcweir {
238*cdf0e10cSrcweir     DBG_ASSERT(nPos < pImpl->aEngineArr.Count(), "wrong array index");
239*cdf0e10cSrcweir     return *pImpl->aEngineArr[nPos];
240*cdf0e10cSrcweir }
241*cdf0e10cSrcweir /* -----------------------------19.03.01 10:38--------------------------------
242*cdf0e10cSrcweir 
243*cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
244*cdf0e10cSrcweir const SvxSearchEngineData*  SvxSearchConfig::GetData(const rtl::OUString& rEngineName)
245*cdf0e10cSrcweir {
246*cdf0e10cSrcweir     for(sal_uInt16 nPos = 0; nPos < pImpl->aEngineArr.Count(); nPos++)
247*cdf0e10cSrcweir     {
248*cdf0e10cSrcweir         if(pImpl->aEngineArr[nPos]->sEngineName == rEngineName)
249*cdf0e10cSrcweir             return pImpl->aEngineArr[nPos];
250*cdf0e10cSrcweir     }
251*cdf0e10cSrcweir     return 0;
252*cdf0e10cSrcweir }
253*cdf0e10cSrcweir /* -----------------------------19.03.01 10:02--------------------------------
254*cdf0e10cSrcweir 
255*cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
256*cdf0e10cSrcweir void  SvxSearchConfig::SetData(const SvxSearchEngineData& rData)
257*cdf0e10cSrcweir {
258*cdf0e10cSrcweir     for(sal_uInt16 nPos = 0; nPos < pImpl->aEngineArr.Count(); nPos++)
259*cdf0e10cSrcweir     {
260*cdf0e10cSrcweir         if(pImpl->aEngineArr[nPos]->sEngineName == rData.sEngineName)
261*cdf0e10cSrcweir         {
262*cdf0e10cSrcweir             if((*pImpl->aEngineArr[nPos]) == rData)
263*cdf0e10cSrcweir                 return;
264*cdf0e10cSrcweir             pImpl->aEngineArr.DeleteAndDestroy(nPos, 1);
265*cdf0e10cSrcweir             break;
266*cdf0e10cSrcweir         }
267*cdf0e10cSrcweir     }
268*cdf0e10cSrcweir     SvxSearchEngineDataPtr pInsert = new SvxSearchEngineData(rData);
269*cdf0e10cSrcweir     pImpl->aEngineArr.Insert(pInsert, pImpl->aEngineArr.Count());
270*cdf0e10cSrcweir     SetModified();
271*cdf0e10cSrcweir }
272*cdf0e10cSrcweir /* -----------------------------19.03.01 10:38--------------------------------
273*cdf0e10cSrcweir 
274*cdf0e10cSrcweir  ---------------------------------------------------------------------------*/
275*cdf0e10cSrcweir void SvxSearchConfig::RemoveData(const rtl::OUString& rEngineName)
276*cdf0e10cSrcweir {
277*cdf0e10cSrcweir     for(sal_uInt16 nPos = 0; nPos < pImpl->aEngineArr.Count(); nPos++)
278*cdf0e10cSrcweir     {
279*cdf0e10cSrcweir         if(pImpl->aEngineArr[nPos]->sEngineName == rEngineName)
280*cdf0e10cSrcweir         {
281*cdf0e10cSrcweir             pImpl->aEngineArr.DeleteAndDestroy(nPos, 1);
282*cdf0e10cSrcweir             SetModified();
283*cdf0e10cSrcweir             return ;
284*cdf0e10cSrcweir         }
285*cdf0e10cSrcweir     }
286*cdf0e10cSrcweir }
287*cdf0e10cSrcweir 
288