1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: srchcfg.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svx.hxx"
34 #ifndef _SVX_SRCHNCFG_HXX
35 #include <srchcfg.hxx>
37 #include <svtools/svarray.hxx>
38 #include <com/sun/star/uno/Any.hxx>
39 #include <com/sun/star/uno/Sequence.hxx>
40 #include <com/sun/star/beans/PropertyValue.hpp>
41 #include <tools/debug.hxx>
42 #include <unotools/configpathes.hxx>
44 //-----------------------------------------------------------------------------
47 using namespace com::sun::star
;
48 using namespace com::sun::star::uno
;
49 using namespace com::sun::star::beans
;
51 #define C2U(cChar) OUString::createFromAscii(cChar)
53 //-----------------------------------------------------------------------------
54 typedef SvxSearchEngineData
* SvxSearchEngineDataPtr
;
55 SV_DECL_PTRARR_DEL(SvxSearchEngineArr
, SvxSearchEngineDataPtr
, 2, 2)
56 SV_IMPL_PTRARR(SvxSearchEngineArr
, SvxSearchEngineDataPtr
);
57 //-----------------------------------------------------------------------------
58 struct SvxSearchConfig_Impl
60 SvxSearchEngineArr aEngineArr
;
62 /* -----------------------------19.03.01 14:00--------------------------------
64 ---------------------------------------------------------------------------*/
65 sal_Bool
SvxSearchEngineData::operator==(const SvxSearchEngineData
& rData
)
67 return sEngineName
== rData
.sEngineName
&&
68 sAndPrefix
== rData
.sAndPrefix
&&
69 sAndSuffix
== rData
.sAndSuffix
&&
70 sAndSeparator
== rData
.sAndSeparator
&&
71 nAndCaseMatch
== rData
.nAndCaseMatch
&&
72 sOrPrefix
== rData
.sOrPrefix
&&
73 sOrSuffix
== rData
.sOrSuffix
&&
74 sOrSeparator
== rData
.sOrSeparator
&&
75 nOrCaseMatch
== rData
.nOrCaseMatch
&&
76 sExactPrefix
== rData
.sExactPrefix
&&
77 sExactSuffix
== rData
.sExactSuffix
&&
78 sExactSeparator
== rData
.sExactSeparator
&&
79 nExactCaseMatch
== rData
.nExactCaseMatch
;
81 /* -----------------------------16.01.01 15:36--------------------------------
83 ---------------------------------------------------------------------------*/
84 const Sequence
<OUString
>& lcl_GetSearchPropertyNames_Impl()
86 static Sequence
<OUString
> aNames
;
87 if(!aNames
.getLength())
90 OUString
* pNames
= aNames
.getArray();
91 pNames
[0] = C2U("And/ooInetPrefix");
92 pNames
[1] = C2U("And/ooInetSuffix");
93 pNames
[2] = C2U("And/ooInetSeparator");
94 pNames
[3] = C2U("And/ooInetCaseMatch");
95 pNames
[4] = C2U("Or/ooInetPrefix");
96 pNames
[5] = C2U("Or/ooInetSuffix");
97 pNames
[6] = C2U("Or/ooInetSeparator");
98 pNames
[7] = C2U("Or/ooInetCaseMatch");
99 pNames
[8] = C2U("Exact/ooInetPrefix");
100 pNames
[9] = C2U("Exact/ooInetSuffix");
101 pNames
[10] = C2U("Exact/ooInetSeparator");
102 pNames
[11] = C2U("Exact/ooInetCaseMatch");
106 // ---------------------------------------------------------------------------
107 SvxSearchConfig::SvxSearchConfig(sal_Bool bEnableNotify
) :
108 utl::ConfigItem(C2U("Inet/SearchEngines"), CONFIG_MODE_DELAYED_UPDATE
),
109 pImpl(new SvxSearchConfig_Impl
)
113 //request notifications from the node
114 Sequence
<OUString
> aEnable(1);
115 EnableNotification(aEnable
);
119 /* -----------------------------16.01.01 15:36--------------------------------
121 ---------------------------------------------------------------------------*/
122 SvxSearchConfig::~SvxSearchConfig()
126 /* -----------------------------17.01.01 09:57--------------------------------
128 ---------------------------------------------------------------------------*/
129 void SvxSearchConfig::Load()
131 pImpl
->aEngineArr
.DeleteAndDestroy(0, pImpl
->aEngineArr
.Count());
132 Sequence
<OUString
> aNodeNames
= GetNodeNames(OUString());
133 const OUString
* pNodeNames
= aNodeNames
.getConstArray();
134 for(sal_Int32 nNode
= 0; nNode
< aNodeNames
.getLength(); nNode
++)
136 SvxSearchEngineDataPtr pNew
= new SvxSearchEngineData
;
137 pNew
->sEngineName
= pNodeNames
[nNode
];
138 const Sequence
<OUString
>& rPropNames
= lcl_GetSearchPropertyNames_Impl();
139 const OUString
* pPropNames
= rPropNames
.getConstArray();
140 Sequence
<OUString
> aPropertyNames(rPropNames
.getLength());
141 OUString
* pPropertyNames
= aPropertyNames
.getArray();
142 const OUString
sSlash(C2U("/"));
144 for(nProp
= 0; nProp
< rPropNames
.getLength(); nProp
++)
146 pPropertyNames
[nProp
] = wrapConfigurationElementName(pNodeNames
[nNode
]);
147 pPropertyNames
[nProp
] += sSlash
;
148 pPropertyNames
[nProp
] += pPropNames
[nProp
];
150 Sequence
<Any
> aValues
= GetProperties(aPropertyNames
);
151 const Any
* pValues
= aValues
.getConstArray();
152 for(nProp
= 0; nProp
< rPropNames
.getLength(); nProp
++)
156 case 0 : pValues
[nProp
] >>= pNew
->sAndPrefix
; break;
157 case 1 : pValues
[nProp
] >>= pNew
->sAndSuffix
; break;
158 case 2 : pValues
[nProp
] >>= pNew
->sAndSeparator
; break;
159 case 3 : pValues
[nProp
] >>= pNew
->nAndCaseMatch
; break;
161 case 4 : pValues
[nProp
] >>= pNew
->sOrPrefix
; break;
162 case 5 : pValues
[nProp
] >>= pNew
->sOrSuffix
; break;
163 case 6 : pValues
[nProp
] >>= pNew
->sOrSeparator
; break;
164 case 7 : pValues
[nProp
] >>= pNew
->nOrCaseMatch
; break;
166 case 8 : pValues
[nProp
] >>= pNew
->sExactPrefix
; break;
167 case 9 : pValues
[nProp
] >>= pNew
->sExactSuffix
; break;
168 case 10: pValues
[nProp
] >>= pNew
->sExactSeparator
; break;
169 case 11: pValues
[nProp
] >>= pNew
->nExactCaseMatch
; break;
172 pImpl
->aEngineArr
.Insert(pNew
, pImpl
->aEngineArr
.Count());
175 /* -----------------------------17.01.01 09:57--------------------------------
177 ---------------------------------------------------------------------------*/
178 void SvxSearchConfig::Notify( const Sequence
<OUString
>& )
182 /* -----------------------------16.01.01 15:36--------------------------------
184 ---------------------------------------------------------------------------*/
185 void SvxSearchConfig::Commit()
188 if(!pImpl
->aEngineArr
.Count())
192 Sequence
<PropertyValue
> aSetValues(12 * pImpl
->aEngineArr
.Count());
193 PropertyValue
* pSetValues
= aSetValues
.getArray();
195 const Sequence
<OUString
>& rPropNames
= lcl_GetSearchPropertyNames_Impl();
196 const OUString
* pPropNames
= rPropNames
.getConstArray();
197 const OUString
sSlash(C2U("/"));
198 for(sal_uInt16 i
= 0; i
< pImpl
->aEngineArr
.Count(); i
++)
200 SvxSearchEngineDataPtr pSave
= pImpl
->aEngineArr
[i
];
201 for(sal_Int16 nProp
= 0; nProp
< rPropNames
.getLength(); nProp
++)
203 OUString sTmpName
= sSlash
;
204 sTmpName
+= wrapConfigurationElementName(pSave
->sEngineName
);
206 sTmpName
+= pPropNames
[nProp
];
207 pSetValues
[nProp
].Name
= sTmpName
;
210 case 0 : pSetValues
[nProp
].Value
<<= pSave
->sAndPrefix
; break;
211 case 1 : pSetValues
[nProp
].Value
<<= pSave
->sAndSuffix
; break;
212 case 2 : pSetValues
[nProp
].Value
<<= pSave
->sAndSeparator
; break;
213 case 3 : pSetValues
[nProp
].Value
<<= pSave
->nAndCaseMatch
; break;
215 case 4 : pSetValues
[nProp
].Value
<<= pSave
->sOrPrefix
; break;
216 case 5 : pSetValues
[nProp
].Value
<<= pSave
->sOrSuffix
; break;
217 case 6 : pSetValues
[nProp
].Value
<<= pSave
->sOrSeparator
; break;
218 case 7 : pSetValues
[nProp
].Value
<<= pSave
->nOrCaseMatch
; break;
220 case 8 : pSetValues
[nProp
].Value
<<= pSave
->sExactPrefix
; break;
221 case 9 : pSetValues
[nProp
].Value
<<= pSave
->sExactSuffix
; break;
222 case 10: pSetValues
[nProp
].Value
<<= pSave
->sExactSeparator
; break;
223 case 11: pSetValues
[nProp
].Value
<<= pSave
->nExactCaseMatch
; break;
228 ReplaceSetProperties(sNode
, aSetValues
);
231 /* -----------------------------19.03.01 10:02--------------------------------
233 ---------------------------------------------------------------------------*/
234 sal_uInt16
SvxSearchConfig::Count()
236 return pImpl
->aEngineArr
.Count();
238 /* -----------------------------19.03.01 10:02--------------------------------
240 ---------------------------------------------------------------------------*/
241 const SvxSearchEngineData
& SvxSearchConfig::GetData(sal_uInt16 nPos
)
243 DBG_ASSERT(nPos
< pImpl
->aEngineArr
.Count(), "wrong array index");
244 return *pImpl
->aEngineArr
[nPos
];
246 /* -----------------------------19.03.01 10:38--------------------------------
248 ---------------------------------------------------------------------------*/
249 const SvxSearchEngineData
* SvxSearchConfig::GetData(const rtl::OUString
& rEngineName
)
251 for(sal_uInt16 nPos
= 0; nPos
< pImpl
->aEngineArr
.Count(); nPos
++)
253 if(pImpl
->aEngineArr
[nPos
]->sEngineName
== rEngineName
)
254 return pImpl
->aEngineArr
[nPos
];
258 /* -----------------------------19.03.01 10:02--------------------------------
260 ---------------------------------------------------------------------------*/
261 void SvxSearchConfig::SetData(const SvxSearchEngineData
& rData
)
263 for(sal_uInt16 nPos
= 0; nPos
< pImpl
->aEngineArr
.Count(); nPos
++)
265 if(pImpl
->aEngineArr
[nPos
]->sEngineName
== rData
.sEngineName
)
267 if((*pImpl
->aEngineArr
[nPos
]) == rData
)
269 pImpl
->aEngineArr
.DeleteAndDestroy(nPos
, 1);
273 SvxSearchEngineDataPtr pInsert
= new SvxSearchEngineData(rData
);
274 pImpl
->aEngineArr
.Insert(pInsert
, pImpl
->aEngineArr
.Count());
277 /* -----------------------------19.03.01 10:38--------------------------------
279 ---------------------------------------------------------------------------*/
280 void SvxSearchConfig::RemoveData(const rtl::OUString
& rEngineName
)
282 for(sal_uInt16 nPos
= 0; nPos
< pImpl
->aEngineArr
.Count(); nPos
++)
284 if(pImpl
->aEngineArr
[nPos
]->sEngineName
== rEngineName
)
286 pImpl
->aEngineArr
.DeleteAndDestroy(nPos
, 1);