1*40df464eSAndrew Rist /**************************************************************
2cdf0e10cSrcweir *
3*40df464eSAndrew Rist * Licensed to the Apache Software Foundation (ASF) under one
4*40df464eSAndrew Rist * or more contributor license agreements. See the NOTICE file
5*40df464eSAndrew Rist * distributed with this work for additional information
6*40df464eSAndrew Rist * regarding copyright ownership. The ASF licenses this file
7*40df464eSAndrew Rist * to you under the Apache License, Version 2.0 (the
8*40df464eSAndrew Rist * "License"); you may not use this file except in compliance
9*40df464eSAndrew Rist * with the License. You may obtain a copy of the License at
10*40df464eSAndrew Rist *
11*40df464eSAndrew Rist * http://www.apache.org/licenses/LICENSE-2.0
12*40df464eSAndrew Rist *
13*40df464eSAndrew Rist * Unless required by applicable law or agreed to in writing,
14*40df464eSAndrew Rist * software distributed under the License is distributed on an
15*40df464eSAndrew Rist * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16*40df464eSAndrew Rist * KIND, either express or implied. See the License for the
17*40df464eSAndrew Rist * specific language governing permissions and limitations
18*40df464eSAndrew Rist * under the License.
19*40df464eSAndrew Rist *
20*40df464eSAndrew Rist *************************************************************/
21*40df464eSAndrew Rist
22*40df464eSAndrew Rist
23cdf0e10cSrcweir
24cdf0e10cSrcweir // MARKER(update_precomp.py): autogen include statement, do not remove
25cdf0e10cSrcweir #include "precompiled_svl.hxx"
26cdf0e10cSrcweir
27cdf0e10cSrcweir #include <svl/srchcfg.hxx>
28cdf0e10cSrcweir #include <svl/svarray.hxx>
29cdf0e10cSrcweir #include <com/sun/star/uno/Any.hxx>
30cdf0e10cSrcweir #include <com/sun/star/uno/Sequence.hxx>
31cdf0e10cSrcweir #include <com/sun/star/beans/PropertyValue.hpp>
32cdf0e10cSrcweir #include <tools/debug.hxx>
33cdf0e10cSrcweir #include <unotools/configpathes.hxx>
34cdf0e10cSrcweir
35cdf0e10cSrcweir //-----------------------------------------------------------------------------
36cdf0e10cSrcweir using namespace utl;
37cdf0e10cSrcweir using namespace rtl;
38cdf0e10cSrcweir using namespace com::sun::star;
39cdf0e10cSrcweir using namespace com::sun::star::uno;
40cdf0e10cSrcweir using namespace com::sun::star::beans;
41cdf0e10cSrcweir
42cdf0e10cSrcweir #define C2U(cChar) OUString::createFromAscii(cChar)
43cdf0e10cSrcweir
44cdf0e10cSrcweir //-----------------------------------------------------------------------------
45cdf0e10cSrcweir typedef SvxSearchEngineData* SvxSearchEngineDataPtr;
46cdf0e10cSrcweir SV_DECL_PTRARR_DEL(SvxSearchEngineArr, SvxSearchEngineDataPtr, 2, 2)
47cdf0e10cSrcweir SV_IMPL_PTRARR(SvxSearchEngineArr, SvxSearchEngineDataPtr);
48cdf0e10cSrcweir //-----------------------------------------------------------------------------
49cdf0e10cSrcweir struct SvxSearchConfig_Impl
50cdf0e10cSrcweir {
51cdf0e10cSrcweir SvxSearchEngineArr aEngineArr;
52cdf0e10cSrcweir };
53cdf0e10cSrcweir /* -----------------------------19.03.01 14:00--------------------------------
54cdf0e10cSrcweir
55cdf0e10cSrcweir ---------------------------------------------------------------------------*/
operator ==(const SvxSearchEngineData & rData)56cdf0e10cSrcweir sal_Bool SvxSearchEngineData::operator==(const SvxSearchEngineData& rData)
57cdf0e10cSrcweir {
58cdf0e10cSrcweir return sEngineName == rData.sEngineName &&
59cdf0e10cSrcweir sAndPrefix == rData.sAndPrefix &&
60cdf0e10cSrcweir sAndSuffix == rData.sAndSuffix &&
61cdf0e10cSrcweir sAndSeparator == rData.sAndSeparator &&
62cdf0e10cSrcweir nAndCaseMatch == rData.nAndCaseMatch &&
63cdf0e10cSrcweir sOrPrefix == rData.sOrPrefix &&
64cdf0e10cSrcweir sOrSuffix == rData.sOrSuffix &&
65cdf0e10cSrcweir sOrSeparator == rData.sOrSeparator &&
66cdf0e10cSrcweir nOrCaseMatch == rData.nOrCaseMatch &&
67cdf0e10cSrcweir sExactPrefix == rData.sExactPrefix &&
68cdf0e10cSrcweir sExactSuffix == rData.sExactSuffix &&
69cdf0e10cSrcweir sExactSeparator == rData.sExactSeparator &&
70cdf0e10cSrcweir nExactCaseMatch == rData.nExactCaseMatch;
71cdf0e10cSrcweir }
72cdf0e10cSrcweir /* -----------------------------16.01.01 15:36--------------------------------
73cdf0e10cSrcweir
74cdf0e10cSrcweir ---------------------------------------------------------------------------*/
lcl_GetSearchPropertyNames_Impl()75cdf0e10cSrcweir const Sequence<OUString>& lcl_GetSearchPropertyNames_Impl()
76cdf0e10cSrcweir {
77cdf0e10cSrcweir static Sequence<OUString> aNames;
78cdf0e10cSrcweir if(!aNames.getLength())
79cdf0e10cSrcweir {
80cdf0e10cSrcweir aNames.realloc(12);
81cdf0e10cSrcweir OUString* pNames = aNames.getArray();
82cdf0e10cSrcweir pNames[0] = C2U("And/ooInetPrefix");
83cdf0e10cSrcweir pNames[1] = C2U("And/ooInetSuffix");
84cdf0e10cSrcweir pNames[2] = C2U("And/ooInetSeparator");
85cdf0e10cSrcweir pNames[3] = C2U("And/ooInetCaseMatch");
86cdf0e10cSrcweir pNames[4] = C2U("Or/ooInetPrefix");
87cdf0e10cSrcweir pNames[5] = C2U("Or/ooInetSuffix");
88cdf0e10cSrcweir pNames[6] = C2U("Or/ooInetSeparator");
89cdf0e10cSrcweir pNames[7] = C2U("Or/ooInetCaseMatch");
90cdf0e10cSrcweir pNames[8] = C2U("Exact/ooInetPrefix");
91cdf0e10cSrcweir pNames[9] = C2U("Exact/ooInetSuffix");
92cdf0e10cSrcweir pNames[10] = C2U("Exact/ooInetSeparator");
93cdf0e10cSrcweir pNames[11] = C2U("Exact/ooInetCaseMatch");
94cdf0e10cSrcweir }
95cdf0e10cSrcweir return aNames;
96cdf0e10cSrcweir }
97cdf0e10cSrcweir // ---------------------------------------------------------------------------
SvxSearchConfig(sal_Bool bEnableNotify)98cdf0e10cSrcweir SvxSearchConfig::SvxSearchConfig(sal_Bool bEnableNotify) :
99cdf0e10cSrcweir utl::ConfigItem(C2U("Inet/SearchEngines"), CONFIG_MODE_DELAYED_UPDATE),
100cdf0e10cSrcweir pImpl(new SvxSearchConfig_Impl)
101cdf0e10cSrcweir {
102cdf0e10cSrcweir if(bEnableNotify)
103cdf0e10cSrcweir {
104cdf0e10cSrcweir //request notifications from the node
105cdf0e10cSrcweir Sequence<OUString> aEnable(1);
106cdf0e10cSrcweir EnableNotification(aEnable);
107cdf0e10cSrcweir }
108cdf0e10cSrcweir Load();
109cdf0e10cSrcweir }
110cdf0e10cSrcweir /* -----------------------------16.01.01 15:36--------------------------------
111cdf0e10cSrcweir
112cdf0e10cSrcweir ---------------------------------------------------------------------------*/
~SvxSearchConfig()113cdf0e10cSrcweir SvxSearchConfig::~SvxSearchConfig()
114cdf0e10cSrcweir {
115cdf0e10cSrcweir delete pImpl;
116cdf0e10cSrcweir }
117cdf0e10cSrcweir /* -----------------------------17.01.01 09:57--------------------------------
118cdf0e10cSrcweir
119cdf0e10cSrcweir ---------------------------------------------------------------------------*/
Load()120cdf0e10cSrcweir void SvxSearchConfig::Load()
121cdf0e10cSrcweir {
122cdf0e10cSrcweir pImpl->aEngineArr.DeleteAndDestroy(0, pImpl->aEngineArr.Count());
123cdf0e10cSrcweir Sequence<OUString> aNodeNames = GetNodeNames(OUString());
124cdf0e10cSrcweir const OUString* pNodeNames = aNodeNames.getConstArray();
125cdf0e10cSrcweir for(sal_Int32 nNode = 0; nNode < aNodeNames.getLength(); nNode++)
126cdf0e10cSrcweir {
127cdf0e10cSrcweir SvxSearchEngineDataPtr pNew = new SvxSearchEngineData;
128cdf0e10cSrcweir pNew->sEngineName = pNodeNames[nNode];
129cdf0e10cSrcweir const Sequence<OUString>& rPropNames = lcl_GetSearchPropertyNames_Impl();
130cdf0e10cSrcweir const OUString* pPropNames = rPropNames.getConstArray();
131cdf0e10cSrcweir Sequence<OUString> aPropertyNames(rPropNames.getLength());
132cdf0e10cSrcweir OUString* pPropertyNames = aPropertyNames.getArray();
133cdf0e10cSrcweir const OUString sSlash(C2U("/"));
134cdf0e10cSrcweir sal_Int32 nProp;
135cdf0e10cSrcweir for(nProp = 0; nProp < rPropNames.getLength(); nProp++)
136cdf0e10cSrcweir {
137cdf0e10cSrcweir pPropertyNames[nProp] = wrapConfigurationElementName(pNodeNames[nNode]);
138cdf0e10cSrcweir pPropertyNames[nProp] += sSlash;
139cdf0e10cSrcweir pPropertyNames[nProp] += pPropNames[nProp];
140cdf0e10cSrcweir }
141cdf0e10cSrcweir Sequence<Any> aValues = GetProperties(aPropertyNames);
142cdf0e10cSrcweir const Any* pValues = aValues.getConstArray();
143cdf0e10cSrcweir for(nProp = 0; nProp < rPropNames.getLength(); nProp++)
144cdf0e10cSrcweir {
145cdf0e10cSrcweir switch(nProp)
146cdf0e10cSrcweir {
147cdf0e10cSrcweir case 0 : pValues[nProp] >>= pNew->sAndPrefix; break;
148cdf0e10cSrcweir case 1 : pValues[nProp] >>= pNew->sAndSuffix; break;
149cdf0e10cSrcweir case 2 : pValues[nProp] >>= pNew->sAndSeparator; break;
150cdf0e10cSrcweir case 3 : pValues[nProp] >>= pNew->nAndCaseMatch; break;
151cdf0e10cSrcweir
152cdf0e10cSrcweir case 4 : pValues[nProp] >>= pNew->sOrPrefix; break;
153cdf0e10cSrcweir case 5 : pValues[nProp] >>= pNew->sOrSuffix; break;
154cdf0e10cSrcweir case 6 : pValues[nProp] >>= pNew->sOrSeparator; break;
155cdf0e10cSrcweir case 7 : pValues[nProp] >>= pNew->nOrCaseMatch; break;
156cdf0e10cSrcweir
157cdf0e10cSrcweir case 8 : pValues[nProp] >>= pNew->sExactPrefix; break;
158cdf0e10cSrcweir case 9 : pValues[nProp] >>= pNew->sExactSuffix; break;
159cdf0e10cSrcweir case 10: pValues[nProp] >>= pNew->sExactSeparator; break;
160cdf0e10cSrcweir case 11: pValues[nProp] >>= pNew->nExactCaseMatch; break;
161cdf0e10cSrcweir }
162cdf0e10cSrcweir }
163cdf0e10cSrcweir pImpl->aEngineArr.Insert(pNew, pImpl->aEngineArr.Count());
164cdf0e10cSrcweir }
165cdf0e10cSrcweir }
166cdf0e10cSrcweir /* -----------------------------17.01.01 09:57--------------------------------
167cdf0e10cSrcweir
168cdf0e10cSrcweir ---------------------------------------------------------------------------*/
Notify(const Sequence<OUString> &)169cdf0e10cSrcweir void SvxSearchConfig::Notify( const Sequence<OUString>& )
170cdf0e10cSrcweir {
171cdf0e10cSrcweir Load();
172cdf0e10cSrcweir }
173cdf0e10cSrcweir /* -----------------------------16.01.01 15:36--------------------------------
174cdf0e10cSrcweir
175cdf0e10cSrcweir ---------------------------------------------------------------------------*/
Commit()176cdf0e10cSrcweir void SvxSearchConfig::Commit()
177cdf0e10cSrcweir {
178cdf0e10cSrcweir OUString sNode;
179cdf0e10cSrcweir if(!pImpl->aEngineArr.Count())
180cdf0e10cSrcweir ClearNodeSet(sNode);
181cdf0e10cSrcweir else
182cdf0e10cSrcweir {
183cdf0e10cSrcweir Sequence<PropertyValue> aSetValues(12 * pImpl->aEngineArr.Count());
184cdf0e10cSrcweir PropertyValue* pSetValues = aSetValues.getArray();
185cdf0e10cSrcweir
186cdf0e10cSrcweir const Sequence<OUString>& rPropNames = lcl_GetSearchPropertyNames_Impl();
187cdf0e10cSrcweir const OUString* pPropNames = rPropNames.getConstArray();
188cdf0e10cSrcweir const OUString sSlash(C2U("/"));
189cdf0e10cSrcweir for(sal_uInt16 i = 0; i < pImpl->aEngineArr.Count(); i++)
190cdf0e10cSrcweir {
191cdf0e10cSrcweir SvxSearchEngineDataPtr pSave = pImpl->aEngineArr[i];
192cdf0e10cSrcweir for(sal_Int16 nProp = 0; nProp < rPropNames.getLength(); nProp++)
193cdf0e10cSrcweir {
194cdf0e10cSrcweir OUString sTmpName = sSlash;
195cdf0e10cSrcweir sTmpName += wrapConfigurationElementName(pSave->sEngineName);
196cdf0e10cSrcweir sTmpName += sSlash;
197cdf0e10cSrcweir sTmpName += pPropNames[nProp];
198cdf0e10cSrcweir pSetValues[nProp].Name = sTmpName;
199cdf0e10cSrcweir switch(nProp)
200cdf0e10cSrcweir {
201cdf0e10cSrcweir case 0 : pSetValues[nProp].Value <<= pSave->sAndPrefix; break;
202cdf0e10cSrcweir case 1 : pSetValues[nProp].Value <<= pSave->sAndSuffix; break;
203cdf0e10cSrcweir case 2 : pSetValues[nProp].Value <<= pSave->sAndSeparator; break;
204cdf0e10cSrcweir case 3 : pSetValues[nProp].Value <<= pSave->nAndCaseMatch; break;
205cdf0e10cSrcweir
206cdf0e10cSrcweir case 4 : pSetValues[nProp].Value <<= pSave->sOrPrefix; break;
207cdf0e10cSrcweir case 5 : pSetValues[nProp].Value <<= pSave->sOrSuffix; break;
208cdf0e10cSrcweir case 6 : pSetValues[nProp].Value <<= pSave->sOrSeparator; break;
209cdf0e10cSrcweir case 7 : pSetValues[nProp].Value <<= pSave->nOrCaseMatch; break;
210cdf0e10cSrcweir
211cdf0e10cSrcweir case 8 : pSetValues[nProp].Value <<= pSave->sExactPrefix; break;
212cdf0e10cSrcweir case 9 : pSetValues[nProp].Value <<= pSave->sExactSuffix; break;
213cdf0e10cSrcweir case 10: pSetValues[nProp].Value <<= pSave->sExactSeparator; break;
214cdf0e10cSrcweir case 11: pSetValues[nProp].Value <<= pSave->nExactCaseMatch; break;
215cdf0e10cSrcweir }
216cdf0e10cSrcweir }
217cdf0e10cSrcweir pSetValues+= 12;
218cdf0e10cSrcweir }
219cdf0e10cSrcweir ReplaceSetProperties(sNode, aSetValues);
220cdf0e10cSrcweir }
221cdf0e10cSrcweir }
222cdf0e10cSrcweir /* -----------------------------19.03.01 10:02--------------------------------
223cdf0e10cSrcweir
224cdf0e10cSrcweir ---------------------------------------------------------------------------*/
Count()225cdf0e10cSrcweir sal_uInt16 SvxSearchConfig::Count()
226cdf0e10cSrcweir {
227cdf0e10cSrcweir return pImpl->aEngineArr.Count();
228cdf0e10cSrcweir }
229cdf0e10cSrcweir /* -----------------------------19.03.01 10:02--------------------------------
230cdf0e10cSrcweir
231cdf0e10cSrcweir ---------------------------------------------------------------------------*/
GetData(sal_uInt16 nPos)232cdf0e10cSrcweir const SvxSearchEngineData& SvxSearchConfig::GetData(sal_uInt16 nPos)
233cdf0e10cSrcweir {
234cdf0e10cSrcweir DBG_ASSERT(nPos < pImpl->aEngineArr.Count(), "wrong array index");
235cdf0e10cSrcweir return *pImpl->aEngineArr[nPos];
236cdf0e10cSrcweir }
237cdf0e10cSrcweir /* -----------------------------19.03.01 10:38--------------------------------
238cdf0e10cSrcweir
239cdf0e10cSrcweir ---------------------------------------------------------------------------*/
GetData(const rtl::OUString & rEngineName)240cdf0e10cSrcweir const SvxSearchEngineData* SvxSearchConfig::GetData(const rtl::OUString& rEngineName)
241cdf0e10cSrcweir {
242cdf0e10cSrcweir for(sal_uInt16 nPos = 0; nPos < pImpl->aEngineArr.Count(); nPos++)
243cdf0e10cSrcweir {
244cdf0e10cSrcweir if(pImpl->aEngineArr[nPos]->sEngineName == rEngineName)
245cdf0e10cSrcweir return pImpl->aEngineArr[nPos];
246cdf0e10cSrcweir }
247cdf0e10cSrcweir return 0;
248cdf0e10cSrcweir }
249cdf0e10cSrcweir /* -----------------------------19.03.01 10:02--------------------------------
250cdf0e10cSrcweir
251cdf0e10cSrcweir ---------------------------------------------------------------------------*/
SetData(const SvxSearchEngineData & rData)252cdf0e10cSrcweir void SvxSearchConfig::SetData(const SvxSearchEngineData& rData)
253cdf0e10cSrcweir {
254cdf0e10cSrcweir for(sal_uInt16 nPos = 0; nPos < pImpl->aEngineArr.Count(); nPos++)
255cdf0e10cSrcweir {
256cdf0e10cSrcweir if(pImpl->aEngineArr[nPos]->sEngineName == rData.sEngineName)
257cdf0e10cSrcweir {
258cdf0e10cSrcweir if((*pImpl->aEngineArr[nPos]) == rData)
259cdf0e10cSrcweir return;
260cdf0e10cSrcweir pImpl->aEngineArr.DeleteAndDestroy(nPos, 1);
261cdf0e10cSrcweir break;
262cdf0e10cSrcweir }
263cdf0e10cSrcweir }
264cdf0e10cSrcweir SvxSearchEngineDataPtr pInsert = new SvxSearchEngineData(rData);
265cdf0e10cSrcweir pImpl->aEngineArr.Insert(pInsert, pImpl->aEngineArr.Count());
266cdf0e10cSrcweir SetModified();
267cdf0e10cSrcweir }
268cdf0e10cSrcweir /* -----------------------------19.03.01 10:38--------------------------------
269cdf0e10cSrcweir
270cdf0e10cSrcweir ---------------------------------------------------------------------------*/
RemoveData(const rtl::OUString & rEngineName)271cdf0e10cSrcweir void SvxSearchConfig::RemoveData(const rtl::OUString& rEngineName)
272cdf0e10cSrcweir {
273cdf0e10cSrcweir for(sal_uInt16 nPos = 0; nPos < pImpl->aEngineArr.Count(); nPos++)
274cdf0e10cSrcweir {
275cdf0e10cSrcweir if(pImpl->aEngineArr[nPos]->sEngineName == rEngineName)
276cdf0e10cSrcweir {
277cdf0e10cSrcweir pImpl->aEngineArr.DeleteAndDestroy(nPos, 1);
278cdf0e10cSrcweir SetModified();
279cdf0e10cSrcweir return ;
280cdf0e10cSrcweir }
281cdf0e10cSrcweir }
282cdf0e10cSrcweir }
283cdf0e10cSrcweir
284