xref: /aoo41x/main/svl/source/config/srchcfg.cxx (revision 40df464e)
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_svl.hxx"
26 
27 #include <svl/srchcfg.hxx>
28 #include <svl/svarray.hxx>
29 #include <com/sun/star/uno/Any.hxx>
30 #include <com/sun/star/uno/Sequence.hxx>
31 #include <com/sun/star/beans/PropertyValue.hpp>
32 #include <tools/debug.hxx>
33 #include <unotools/configpathes.hxx>
34 
35 //-----------------------------------------------------------------------------
36 using namespace utl;
37 using namespace rtl;
38 using namespace com::sun::star;
39 using namespace com::sun::star::uno;
40 using namespace com::sun::star::beans;
41 
42 #define C2U(cChar) OUString::createFromAscii(cChar)
43 
44 //-----------------------------------------------------------------------------
45 typedef SvxSearchEngineData* SvxSearchEngineDataPtr;
46 SV_DECL_PTRARR_DEL(SvxSearchEngineArr, SvxSearchEngineDataPtr, 2, 2)
47 SV_IMPL_PTRARR(SvxSearchEngineArr, SvxSearchEngineDataPtr);
48 //-----------------------------------------------------------------------------
49 struct SvxSearchConfig_Impl
50 {
51     SvxSearchEngineArr   aEngineArr;
52 };
53 /* -----------------------------19.03.01 14:00--------------------------------
54 
55  ---------------------------------------------------------------------------*/
operator ==(const SvxSearchEngineData & rData)56 sal_Bool SvxSearchEngineData::operator==(const SvxSearchEngineData& rData)
57 {
58     return sEngineName      == rData.sEngineName     &&
59             sAndPrefix       == rData.sAndPrefix      &&
60             sAndSuffix       == rData.sAndSuffix      &&
61             sAndSeparator    == rData.sAndSeparator   &&
62             nAndCaseMatch    == rData.nAndCaseMatch   &&
63             sOrPrefix        == rData.sOrPrefix       &&
64             sOrSuffix        == rData.sOrSuffix       &&
65             sOrSeparator     == rData.sOrSeparator    &&
66             nOrCaseMatch     == rData.nOrCaseMatch    &&
67             sExactPrefix     == rData.sExactPrefix    &&
68             sExactSuffix     == rData.sExactSuffix    &&
69             sExactSeparator  == rData.sExactSeparator &&
70             nExactCaseMatch  == rData.nExactCaseMatch;
71 }
72 /* -----------------------------16.01.01 15:36--------------------------------
73 
74  ---------------------------------------------------------------------------*/
lcl_GetSearchPropertyNames_Impl()75 const Sequence<OUString>& lcl_GetSearchPropertyNames_Impl()
76 {
77     static Sequence<OUString> aNames;
78     if(!aNames.getLength())
79     {
80         aNames.realloc(12);
81         OUString* pNames = aNames.getArray();
82         pNames[0] = C2U("And/ooInetPrefix");
83         pNames[1] = C2U("And/ooInetSuffix");
84         pNames[2] = C2U("And/ooInetSeparator");
85         pNames[3] = C2U("And/ooInetCaseMatch");
86         pNames[4] = C2U("Or/ooInetPrefix");
87         pNames[5] = C2U("Or/ooInetSuffix");
88         pNames[6] = C2U("Or/ooInetSeparator");
89         pNames[7] = C2U("Or/ooInetCaseMatch");
90         pNames[8] = C2U("Exact/ooInetPrefix");
91         pNames[9] = C2U("Exact/ooInetSuffix");
92         pNames[10] = C2U("Exact/ooInetSeparator");
93         pNames[11] = C2U("Exact/ooInetCaseMatch");
94     }
95     return aNames;
96 }
97 // ---------------------------------------------------------------------------
SvxSearchConfig(sal_Bool bEnableNotify)98 SvxSearchConfig::SvxSearchConfig(sal_Bool bEnableNotify) :
99     utl::ConfigItem(C2U("Inet/SearchEngines"), CONFIG_MODE_DELAYED_UPDATE),
100     pImpl(new SvxSearchConfig_Impl)
101 {
102 	if(bEnableNotify)
103     {
104         //request notifications from the node
105         Sequence<OUString> aEnable(1);
106         EnableNotification(aEnable);
107     }
108 	Load();
109 }
110 /* -----------------------------16.01.01 15:36--------------------------------
111 
112  ---------------------------------------------------------------------------*/
~SvxSearchConfig()113 SvxSearchConfig::~SvxSearchConfig()
114 {
115 	delete pImpl;
116 }
117 /* -----------------------------17.01.01 09:57--------------------------------
118 
119  ---------------------------------------------------------------------------*/
Load()120 void SvxSearchConfig::Load()
121 {
122     pImpl->aEngineArr.DeleteAndDestroy(0, pImpl->aEngineArr.Count());
123     Sequence<OUString> aNodeNames = GetNodeNames(OUString());
124     const OUString* pNodeNames = aNodeNames.getConstArray();
125     for(sal_Int32 nNode = 0; nNode < aNodeNames.getLength(); nNode++)
126     {
127         SvxSearchEngineDataPtr pNew = new SvxSearchEngineData;
128         pNew->sEngineName = pNodeNames[nNode];
129         const Sequence<OUString>& rPropNames = lcl_GetSearchPropertyNames_Impl();
130         const OUString* pPropNames = rPropNames.getConstArray();
131         Sequence<OUString> aPropertyNames(rPropNames.getLength());
132         OUString* pPropertyNames = aPropertyNames.getArray();
133         const OUString sSlash(C2U("/"));
134         sal_Int32 nProp;
135         for(nProp = 0; nProp < rPropNames.getLength(); nProp++)
136         {
137             pPropertyNames[nProp] = wrapConfigurationElementName(pNodeNames[nNode]);
138             pPropertyNames[nProp] += sSlash;
139             pPropertyNames[nProp] += pPropNames[nProp];
140         }
141         Sequence<Any> aValues = GetProperties(aPropertyNames);
142         const Any* pValues = aValues.getConstArray();
143         for(nProp = 0; nProp < rPropNames.getLength(); nProp++)
144         {
145             switch(nProp)
146             {
147                 case 0 : pValues[nProp] >>= pNew->sAndPrefix;      break;
148                 case 1 : pValues[nProp] >>= pNew->sAndSuffix;      break;
149                 case 2 : pValues[nProp] >>= pNew->sAndSeparator;   break;
150                 case 3 : pValues[nProp] >>= pNew->nAndCaseMatch;   break;
151 
152                 case 4 : pValues[nProp] >>= pNew->sOrPrefix;       break;
153                 case 5 : pValues[nProp] >>= pNew->sOrSuffix;       break;
154                 case 6 : pValues[nProp] >>= pNew->sOrSeparator;    break;
155                 case 7 : pValues[nProp] >>= pNew->nOrCaseMatch;    break;
156 
157                 case 8 : pValues[nProp] >>= pNew->sExactPrefix;    break;
158                 case 9 : pValues[nProp] >>= pNew->sExactSuffix;    break;
159                 case 10: pValues[nProp] >>= pNew->sExactSeparator; break;
160                 case 11: pValues[nProp] >>= pNew->nExactCaseMatch; break;
161             }
162         }
163         pImpl->aEngineArr.Insert(pNew, pImpl->aEngineArr.Count());
164     }
165 }
166 /* -----------------------------17.01.01 09:57--------------------------------
167 
168  ---------------------------------------------------------------------------*/
Notify(const Sequence<OUString> &)169 void    SvxSearchConfig::Notify( const Sequence<OUString>& )
170 {
171 	Load();
172 }
173 /* -----------------------------16.01.01 15:36--------------------------------
174 
175  ---------------------------------------------------------------------------*/
Commit()176 void SvxSearchConfig::Commit()
177 {
178     OUString sNode;
179     if(!pImpl->aEngineArr.Count())
180         ClearNodeSet(sNode);
181     else
182     {
183         Sequence<PropertyValue> aSetValues(12 * pImpl->aEngineArr.Count());
184 		PropertyValue* pSetValues = aSetValues.getArray();
185 
186         const Sequence<OUString>& rPropNames = lcl_GetSearchPropertyNames_Impl();
187         const OUString* pPropNames = rPropNames.getConstArray();
188         const OUString sSlash(C2U("/"));
189         for(sal_uInt16 i = 0; i < pImpl->aEngineArr.Count(); i++)
190 		{
191             SvxSearchEngineDataPtr pSave = pImpl->aEngineArr[i];
192             for(sal_Int16 nProp = 0; nProp < rPropNames.getLength(); nProp++)
193             {
194                 OUString sTmpName = sSlash;
195                 sTmpName += wrapConfigurationElementName(pSave->sEngineName);
196                 sTmpName += sSlash;
197                 sTmpName += pPropNames[nProp];
198                 pSetValues[nProp].Name = sTmpName;
199                 switch(nProp)
200                 {
201                     case 0 : pSetValues[nProp].Value <<= pSave->sAndPrefix;      break;
202                     case 1 : pSetValues[nProp].Value <<= pSave->sAndSuffix;      break;
203                     case 2 : pSetValues[nProp].Value <<= pSave->sAndSeparator;   break;
204                     case 3 : pSetValues[nProp].Value <<= pSave->nAndCaseMatch;   break;
205 
206                     case 4 : pSetValues[nProp].Value <<= pSave->sOrPrefix;       break;
207                     case 5 : pSetValues[nProp].Value <<= pSave->sOrSuffix;       break;
208                     case 6 : pSetValues[nProp].Value <<= pSave->sOrSeparator;    break;
209                     case 7 : pSetValues[nProp].Value <<= pSave->nOrCaseMatch;    break;
210 
211                     case 8 : pSetValues[nProp].Value <<= pSave->sExactPrefix;    break;
212                     case 9 : pSetValues[nProp].Value <<= pSave->sExactSuffix;    break;
213                     case 10: pSetValues[nProp].Value <<= pSave->sExactSeparator; break;
214                     case 11: pSetValues[nProp].Value <<= pSave->nExactCaseMatch; break;
215                 }
216             }
217             pSetValues+= 12;
218         }
219 		ReplaceSetProperties(sNode, aSetValues);
220     }
221 }
222 /* -----------------------------19.03.01 10:02--------------------------------
223 
224  ---------------------------------------------------------------------------*/
Count()225 sal_uInt16 SvxSearchConfig::Count()
226 {
227     return pImpl->aEngineArr.Count();
228 }
229 /* -----------------------------19.03.01 10:02--------------------------------
230 
231  ---------------------------------------------------------------------------*/
GetData(sal_uInt16 nPos)232 const SvxSearchEngineData&  SvxSearchConfig::GetData(sal_uInt16 nPos)
233 {
234     DBG_ASSERT(nPos < pImpl->aEngineArr.Count(), "wrong array index");
235     return *pImpl->aEngineArr[nPos];
236 }
237 /* -----------------------------19.03.01 10:38--------------------------------
238 
239  ---------------------------------------------------------------------------*/
GetData(const rtl::OUString & rEngineName)240 const SvxSearchEngineData*  SvxSearchConfig::GetData(const rtl::OUString& rEngineName)
241 {
242     for(sal_uInt16 nPos = 0; nPos < pImpl->aEngineArr.Count(); nPos++)
243     {
244         if(pImpl->aEngineArr[nPos]->sEngineName == rEngineName)
245             return pImpl->aEngineArr[nPos];
246     }
247     return 0;
248 }
249 /* -----------------------------19.03.01 10:02--------------------------------
250 
251  ---------------------------------------------------------------------------*/
SetData(const SvxSearchEngineData & rData)252 void  SvxSearchConfig::SetData(const SvxSearchEngineData& rData)
253 {
254     for(sal_uInt16 nPos = 0; nPos < pImpl->aEngineArr.Count(); nPos++)
255     {
256         if(pImpl->aEngineArr[nPos]->sEngineName == rData.sEngineName)
257         {
258             if((*pImpl->aEngineArr[nPos]) == rData)
259                 return;
260             pImpl->aEngineArr.DeleteAndDestroy(nPos, 1);
261             break;
262         }
263     }
264     SvxSearchEngineDataPtr pInsert = new SvxSearchEngineData(rData);
265     pImpl->aEngineArr.Insert(pInsert, pImpl->aEngineArr.Count());
266     SetModified();
267 }
268 /* -----------------------------19.03.01 10:38--------------------------------
269 
270  ---------------------------------------------------------------------------*/
RemoveData(const rtl::OUString & rEngineName)271 void SvxSearchConfig::RemoveData(const rtl::OUString& rEngineName)
272 {
273     for(sal_uInt16 nPos = 0; nPos < pImpl->aEngineArr.Count(); nPos++)
274     {
275         if(pImpl->aEngineArr[nPos]->sEngineName == rEngineName)
276         {
277             pImpl->aEngineArr.DeleteAndDestroy(nPos, 1);
278             SetModified();
279             return ;
280         }
281     }
282 }
283 
284