Line data Source code
1 : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : /*
3 : * This file is part of the LibreOffice project.
4 : *
5 : * This Source Code Form is subject to the terms of the Mozilla Public
6 : * License, v. 2.0. If a copy of the MPL was not distributed with this
7 : * file, You can obtain one at http://mozilla.org/MPL/2.0/.
8 : *
9 : * This file incorporates work covered by the following license notice:
10 : *
11 : * Licensed to the Apache Software Foundation (ASF) under one or more
12 : * contributor license agreements. See the NOTICE file distributed
13 : * with this work for additional information regarding copyright
14 : * ownership. The ASF licenses this file to you under the Apache
15 : * License, Version 2.0 (the "License"); you may not use this file
16 : * except in compliance with the License. You may obtain a copy of
17 : * the License at http://www.apache.org/licenses/LICENSE-2.0 .
18 : */
19 :
20 : #ifndef __FRAMEWORK_SERVICES_PATHSETTINGS_HXX_
21 : #define __FRAMEWORK_SERVICES_PATHSETTINGS_HXX_
22 :
23 : #include <threadhelp/threadhelpbase.hxx>
24 : #include <macros/generic.hxx>
25 : #include <macros/xinterface.hxx>
26 : #include <macros/xtypeprovider.hxx>
27 : #include <macros/xserviceinfo.hxx>
28 : #include <stdtypes.h>
29 : #include <properties.h>
30 :
31 : #include <com/sun/star/container/XNameAccess.hpp>
32 : #include <com/sun/star/lang/XServiceInfo.hpp>
33 : #include <com/sun/star/lang/XTypeProvider.hpp>
34 : #include <com/sun/star/util/XStringSubstitution.hpp>
35 : #include <com/sun/star/util/XChangesListener.hpp>
36 : #include <com/sun/star/util/XPathSettings.hpp>
37 :
38 : #include <cppuhelper/propshlp.hxx>
39 : #include <cppuhelper/interfacecontainer.hxx>
40 : #include <cppuhelper/weak.hxx>
41 : #include <unotools/configitem.hxx>
42 : #include <comphelper/sequenceasvector.hxx>
43 :
44 : /* enable it if you whish to migrate old user settings (using the old cfg schema) on demand ....
45 : disable it in case only the new schema must be used.
46 : */
47 :
48 : namespace framework
49 : {
50 :
51 : class PathSettings : public css::lang::XTypeProvider ,
52 : public css::lang::XServiceInfo ,
53 : public css::util::XChangesListener , // => XEventListener
54 : public css::util::XPathSettings , // => XPropertySet
55 : // base classes
56 : // Order is necessary for right initialization!
57 : private ThreadHelpBase ,
58 : public ::cppu::OBroadcastHelper ,
59 : public ::cppu::OPropertySetHelper , // => XPropertySet / XFastPropertySet / XMultiPropertySet
60 : public ::cppu::OWeakObject // => XWeak, XInterface
61 : {
62 15936 : struct PathInfo
63 : {
64 : public:
65 :
66 9576 : PathInfo()
67 : : sPathName ()
68 : , lInternalPaths()
69 : , lUserPaths ()
70 : , sWritePath ()
71 : , bIsSinglePath (sal_False)
72 9576 : , bIsReadonly (sal_False)
73 9576 : {}
74 :
75 0 : PathInfo(const PathInfo& rCopy)
76 0 : {
77 0 : takeOver(rCopy);
78 0 : }
79 :
80 0 : void takeOver(const PathInfo& rCopy)
81 : {
82 0 : sPathName = rCopy.sPathName;
83 0 : lInternalPaths = rCopy.lInternalPaths;
84 0 : lUserPaths = rCopy.lUserPaths;
85 0 : sWritePath = rCopy.sWritePath;
86 0 : bIsSinglePath = rCopy.bIsSinglePath;
87 0 : bIsReadonly = rCopy.bIsReadonly;
88 0 : }
89 :
90 : /// an internal name describing this path
91 : OUString sPathName;
92 :
93 : /// contains all paths, which are used internaly - but are not visible for the user.
94 : OUStringList lInternalPaths;
95 :
96 : /// contains all paths configured by the user
97 : OUStringList lUserPaths;
98 :
99 : /// this special path is used to generate feature depending content there
100 : OUString sWritePath;
101 :
102 : /// indicates real single paths, which uses WritePath property only
103 : sal_Bool bIsSinglePath;
104 :
105 : /// simple handling of finalized/mandatory states ... => we know one state READONLY only .-)
106 : sal_Bool bIsReadonly;
107 : };
108 :
109 : typedef BaseHash< PathSettings::PathInfo > PathHash;
110 :
111 : enum EChangeOp
112 : {
113 : E_UNDEFINED,
114 : E_ADDED,
115 : E_CHANGED,
116 : E_REMOVED
117 : };
118 :
119 : // ______________________________________
120 : // member
121 :
122 : private:
123 :
124 : /** reference to factory, which has create this instance. */
125 : css::uno::Reference< css::uno::XComponentContext > m_xContext;
126 :
127 : /** list of all path variables and her corresponding values. */
128 : PathSettings::PathHash m_lPaths;
129 :
130 : /** describes all properties available on our interface.
131 : Will be generated on demand based on our path list m_lPaths. */
132 : css::uno::Sequence< css::beans::Property > m_lPropDesc;
133 :
134 : /** helper needed to (re-)substitute all internal save path values. */
135 : css::uno::Reference< css::util::XStringSubstitution > m_xSubstitution;
136 :
137 : /** provides access to the old configuration schema (which will be migrated on demand). */
138 : css::uno::Reference< css::container::XNameAccess > m_xCfgOld;
139 :
140 : /** provides access to the new configuration schema. */
141 : css::uno::Reference< css::container::XNameAccess > m_xCfgNew;
142 :
143 : /** helper to listen for configuration changes without ownership cycle problems */
144 : css::uno::Reference< css::util::XChangesListener > m_xCfgNewListener;
145 :
146 : ::cppu::OPropertyArrayHelper* m_pPropHelp;
147 :
148 : ::sal_Bool m_bIgnoreEvents;
149 :
150 : // ___________________________________________
151 : // interface
152 :
153 : public:
154 :
155 : /** initialize a new instance of this class.
156 : Attention: It's neccessary for right function of this class, that the order of base
157 : classes is the right one. Because we transfer information from one base to another
158 : during this ctor runs! */
159 : PathSettings(const css::uno::Reference< css::uno::XComponentContext >& xContext);
160 :
161 : /** free all used resources ... if it was not already done. */
162 : virtual ~PathSettings();
163 :
164 : /** declaration of XInterface, XTypeProvider, XServiceInfo */
165 : FWK_DECLARE_XINTERFACE
166 : FWK_DECLARE_XTYPEPROVIDER
167 : DECLARE_XSERVICEINFO
168 :
169 : // css::util::XChangesListener
170 : virtual void SAL_CALL changesOccurred(const css::util::ChangesEvent& aEvent) throw (css::uno::RuntimeException);
171 :
172 : // css::lang::XEventListener
173 : virtual void SAL_CALL disposing(const css::lang::EventObject& aSource)
174 : throw(css::uno::RuntimeException);
175 :
176 : using ::cppu::OPropertySetHelper::disposing;
177 :
178 :
179 : /**
180 : * XPathSettings attribute methods
181 : */
182 0 : virtual OUString SAL_CALL getAddin() throw (css::uno::RuntimeException)
183 0 : { return getStringProperty("Addin"); }
184 0 : virtual void SAL_CALL setAddin(const OUString& p1) throw (css::uno::RuntimeException)
185 0 : { setStringProperty("Addin", p1); }
186 0 : virtual OUString SAL_CALL getAutoCorrect() throw (css::uno::RuntimeException)
187 0 : { return getStringProperty("AutoCorrect"); }
188 0 : virtual void SAL_CALL setAutoCorrect(const OUString& p1) throw (css::uno::RuntimeException)
189 0 : { setStringProperty("AutoCorrect", p1); }
190 0 : virtual OUString SAL_CALL getAutoText() throw (css::uno::RuntimeException)
191 0 : { return getStringProperty("AutoText"); }
192 0 : virtual void SAL_CALL setAutoText(const OUString& p1) throw (css::uno::RuntimeException)
193 0 : { setStringProperty("AutoText", p1); }
194 0 : virtual OUString SAL_CALL getBackup() throw (css::uno::RuntimeException)
195 0 : { return getStringProperty("Backup"); }
196 0 : virtual void SAL_CALL setBackup(const OUString& p1) throw (css::uno::RuntimeException)
197 0 : { setStringProperty("Backup", p1); }
198 0 : virtual OUString SAL_CALL getBasic() throw (css::uno::RuntimeException)
199 0 : { return getStringProperty("Basic"); }
200 0 : virtual void SAL_CALL setBasic(const OUString& p1) throw (css::uno::RuntimeException)
201 0 : { setStringProperty("Basic", p1); }
202 0 : virtual OUString SAL_CALL getBitmap() throw (css::uno::RuntimeException)
203 0 : { return getStringProperty("Bitmap"); }
204 0 : virtual void SAL_CALL setBitmap(const OUString& p1) throw (css::uno::RuntimeException)
205 0 : { setStringProperty("Bitmap", p1); }
206 0 : virtual OUString SAL_CALL getConfig() throw (css::uno::RuntimeException)
207 0 : { return getStringProperty("Config"); }
208 0 : virtual void SAL_CALL setConfig(const OUString& p1) throw (css::uno::RuntimeException)
209 0 : { setStringProperty("Config", p1); }
210 0 : virtual OUString SAL_CALL getDictionary() throw (css::uno::RuntimeException)
211 0 : { return getStringProperty("Dictionary"); }
212 0 : virtual void SAL_CALL setDictionary(const OUString& p1) throw (css::uno::RuntimeException)
213 0 : { setStringProperty("Dictionary", p1); }
214 0 : virtual OUString SAL_CALL getFavorite() throw (css::uno::RuntimeException)
215 0 : { return getStringProperty("Favorite"); }
216 0 : virtual void SAL_CALL setFavorite(const OUString& p1) throw (css::uno::RuntimeException)
217 0 : { setStringProperty("Favorite", p1); }
218 0 : virtual OUString SAL_CALL getFilter() throw (css::uno::RuntimeException)
219 0 : { return getStringProperty("Filter"); }
220 0 : virtual void SAL_CALL setFilter(const OUString& p1) throw (css::uno::RuntimeException)
221 0 : { setStringProperty("Filter", p1); }
222 0 : virtual OUString SAL_CALL getGallery() throw (css::uno::RuntimeException)
223 0 : { return getStringProperty("Gallery"); }
224 0 : virtual void SAL_CALL setGallery(const OUString& p1) throw (css::uno::RuntimeException)
225 0 : { setStringProperty("Gallery", p1); }
226 0 : virtual OUString SAL_CALL getGraphic() throw (css::uno::RuntimeException)
227 0 : { return getStringProperty("Graphic"); }
228 0 : virtual void SAL_CALL setGraphic(const OUString& p1) throw (css::uno::RuntimeException)
229 0 : { setStringProperty("Graphic", p1); }
230 0 : virtual OUString SAL_CALL getHelp() throw (css::uno::RuntimeException)
231 0 : { return getStringProperty("Help"); }
232 0 : virtual void SAL_CALL setHelp(const OUString& p1) throw (css::uno::RuntimeException)
233 0 : { setStringProperty("Help", p1); }
234 0 : virtual OUString SAL_CALL getLinguistic() throw (css::uno::RuntimeException)
235 0 : { return getStringProperty("Linguistic"); }
236 0 : virtual void SAL_CALL setLinguistic(const OUString& p1) throw (css::uno::RuntimeException)
237 0 : { setStringProperty("Linguistic", p1); }
238 0 : virtual OUString SAL_CALL getModule() throw (css::uno::RuntimeException)
239 0 : { return getStringProperty("Module"); }
240 0 : virtual void SAL_CALL setModule(const OUString& p1) throw (css::uno::RuntimeException)
241 0 : { setStringProperty("Module", p1); }
242 0 : virtual OUString SAL_CALL getPalette() throw (css::uno::RuntimeException)
243 0 : { return getStringProperty("Palette"); }
244 0 : virtual void SAL_CALL setPalette(const OUString& p1) throw (css::uno::RuntimeException)
245 0 : { setStringProperty("Palette", p1); }
246 0 : virtual OUString SAL_CALL getPlugin() throw (css::uno::RuntimeException)
247 0 : { return getStringProperty("Plugin"); }
248 0 : virtual void SAL_CALL setPlugin(const OUString& p1) throw (css::uno::RuntimeException)
249 0 : { setStringProperty("Plugin", p1); }
250 0 : virtual OUString SAL_CALL getStorage() throw (css::uno::RuntimeException)
251 0 : { return getStringProperty("Storage"); }
252 0 : virtual void SAL_CALL setStorage(const OUString& p1) throw (css::uno::RuntimeException)
253 0 : { setStringProperty("Storage", p1); }
254 0 : virtual OUString SAL_CALL getTemp() throw (css::uno::RuntimeException)
255 0 : { return getStringProperty("Temp"); }
256 0 : virtual void SAL_CALL setTemp(const OUString& p1) throw (css::uno::RuntimeException)
257 0 : { setStringProperty("Temp", p1); }
258 0 : virtual OUString SAL_CALL getTemplate() throw (css::uno::RuntimeException)
259 0 : { return getStringProperty("Template"); }
260 0 : virtual void SAL_CALL setTemplate(const OUString& p1) throw (css::uno::RuntimeException)
261 0 : { setStringProperty("Template", p1); }
262 0 : virtual OUString SAL_CALL getUIConfig() throw (css::uno::RuntimeException)
263 0 : { return getStringProperty("UIConfig"); }
264 0 : virtual void SAL_CALL setUIConfig(const OUString& p1) throw (css::uno::RuntimeException)
265 0 : { setStringProperty("UIConfig", p1); }
266 0 : virtual OUString SAL_CALL getUserConfig() throw (css::uno::RuntimeException)
267 0 : { return getStringProperty("UserConfig"); }
268 0 : virtual void SAL_CALL setUserConfig(const OUString& p1) throw (css::uno::RuntimeException)
269 0 : { setStringProperty("UserConfig", p1); }
270 0 : virtual OUString SAL_CALL getUserDictionary() throw (css::uno::RuntimeException)
271 0 : { return getStringProperty("UserDictionary"); }
272 0 : virtual void SAL_CALL setUserDictionary(const OUString& p1) throw (css::uno::RuntimeException)
273 0 : { setStringProperty("UserDictionary", p1); }
274 0 : virtual OUString SAL_CALL getWork() throw (css::uno::RuntimeException)
275 0 : { return getStringProperty("Work"); }
276 0 : virtual void SAL_CALL setWork(const OUString& p1) throw (css::uno::RuntimeException)
277 0 : { setStringProperty("Work", p1); }
278 59 : virtual OUString SAL_CALL getBasePathShareLayer() throw (css::uno::RuntimeException)
279 59 : { return getStringProperty("UIConfig"); }
280 0 : virtual void SAL_CALL setBasePathShareLayer(const OUString& p1) throw (css::uno::RuntimeException)
281 0 : { setStringProperty("UIConfig", p1); }
282 59 : virtual OUString SAL_CALL getBasePathUserLayer() throw (css::uno::RuntimeException)
283 59 : { return getStringProperty("UserConfig"); }
284 0 : virtual void SAL_CALL setBasePathUserLayer(const OUString& p1) throw (css::uno::RuntimeException)
285 0 : { setStringProperty("UserConfig", p1); }
286 :
287 :
288 :
289 : /**
290 : * overrides to resolve inheritance ambiguity
291 : */
292 0 : virtual void SAL_CALL setPropertyValue(const OUString& p1, const css::uno::Any& p2)
293 : throw (css::beans::UnknownPropertyException, css::beans::PropertyVetoException, css::lang::IllegalArgumentException, css::lang::WrappedTargetException, css::uno::RuntimeException)
294 0 : { ::cppu::OPropertySetHelper::setPropertyValue(p1, p2); }
295 579 : virtual css::uno::Any SAL_CALL getPropertyValue(const OUString& p1)
296 : throw (com::sun::star::beans::UnknownPropertyException, com::sun::star::lang::WrappedTargetException, com::sun::star::uno::RuntimeException)
297 579 : { return ::cppu::OPropertySetHelper::getPropertyValue(p1); }
298 0 : virtual void SAL_CALL addPropertyChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XPropertyChangeListener>& p2)
299 : throw (com::sun::star::beans::UnknownPropertyException, com::sun::star::lang::WrappedTargetException, com::sun::star::uno::RuntimeException)
300 0 : { ::cppu::OPropertySetHelper::addPropertyChangeListener(p1, p2); }
301 0 : virtual void SAL_CALL removePropertyChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XPropertyChangeListener>& p2)
302 : throw (com::sun::star::beans::UnknownPropertyException, com::sun::star::lang::WrappedTargetException, com::sun::star::uno::RuntimeException)
303 0 : { ::cppu::OPropertySetHelper::removePropertyChangeListener(p1, p2); }
304 0 : virtual void SAL_CALL addVetoableChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XVetoableChangeListener>& p2)
305 : throw (com::sun::star::beans::UnknownPropertyException, com::sun::star::lang::WrappedTargetException, com::sun::star::uno::RuntimeException)
306 0 : { ::cppu::OPropertySetHelper::addVetoableChangeListener(p1, p2); }
307 0 : virtual void SAL_CALL removeVetoableChangeListener(const OUString& p1, const css::uno::Reference<css::beans::XVetoableChangeListener>& p2)
308 : throw (com::sun::star::beans::UnknownPropertyException, com::sun::star::lang::WrappedTargetException, com::sun::star::uno::RuntimeException)
309 0 : { ::cppu::OPropertySetHelper::removeVetoableChangeListener(p1, p2); }
310 :
311 :
312 : // ___________________________________________
313 : // helper
314 :
315 : private:
316 :
317 : OUString getStringProperty(const OUString& p1)
318 : throw(css::uno::RuntimeException);
319 :
320 : void setStringProperty(const OUString& p1, const OUString& p2)
321 : throw(css::uno::RuntimeException);
322 :
323 : /** read all configured paths and create all needed internal structures. */
324 : void impl_readAll();
325 :
326 : /** read a path info using the old cfg schema.
327 : This is needed for "migration on demand" reasons only.
328 : Can be removed for next major release .-) */
329 : OUStringList impl_readOldFormat(const OUString& sPath);
330 :
331 : /** read a path info using the new cfg schema. */
332 : PathSettings::PathInfo impl_readNewFormat(const OUString& sPath);
333 :
334 : /** filter "real user defined paths" from the old configuration schema
335 : and set it as UserPaths on the new schema.
336 : Can be removed with new major release ... */
337 :
338 : void impl_mergeOldUserPaths( PathSettings::PathInfo& rPath,
339 : const OUStringList& lOld );
340 :
341 : /** reload one path directly from the new configuration schema (because
342 : it was updated by any external code) */
343 : PathSettings::EChangeOp impl_updatePath(const OUString& sPath ,
344 : sal_Bool bNotifyListener);
345 :
346 : /** replace all might existing placeholder variables inside the given path ...
347 : or check if the given path value uses paths, which can be replaced with predefined
348 : placeholder variables ...
349 : */
350 : void impl_subst( OUStringList& lVals ,
351 : const css::uno::Reference< css::util::XStringSubstitution >& xSubst ,
352 : sal_Bool bReSubst);
353 :
354 : void impl_subst(PathSettings::PathInfo& aPath ,
355 : sal_Bool bReSubst);
356 :
357 :
358 : /** converts our new string list schema to the old ";" separated schema ... */
359 : OUString impl_convertPath2OldStyle(const PathSettings::PathInfo& rPath ) const;
360 : OUStringList impl_convertOldStyle2Path(const OUString& sOldStylePath) const;
361 :
362 : /** remove still known paths from the given lList argument.
363 : So real user defined paths can be extracted from the list of
364 : fix internal paths !
365 : */
366 : void impl_purgeKnownPaths(const PathSettings::PathInfo& rPath,
367 : OUStringList& lList);
368 :
369 : /** rebuild the member m_lPropDesc using the path list m_lPaths. */
370 : void impl_rebuildPropertyDescriptor();
371 :
372 : /** provides direct access to the list of path values
373 : using it's internal property id.
374 : */
375 : css::uno::Any impl_getPathValue( sal_Int32 nID ) const;
376 : void impl_setPathValue( sal_Int32 nID ,
377 : const css::uno::Any& aVal);
378 :
379 : /** check the given handle and return the corresponding PathInfo reference.
380 : These reference can be used then directly to manipulate these path. */
381 : PathSettings::PathInfo* impl_getPathAccess (sal_Int32 nHandle);
382 : const PathSettings::PathInfo* impl_getPathAccessConst(sal_Int32 nHandle) const;
383 :
384 : /** it checks, if the given path value seams to be a valid URL or system path. */
385 : sal_Bool impl_isValidPath(const OUString& sPath) const;
386 : sal_Bool impl_isValidPath(const OUStringList& lPath) const;
387 :
388 : void impl_storePath(const PathSettings::PathInfo& aPath);
389 :
390 : css::uno::Sequence< sal_Int32 > impl_mapPathName2IDList(const OUString& sPath);
391 :
392 : void impl_notifyPropListener( PathSettings::EChangeOp eOp ,
393 : const OUString& sPath ,
394 : const PathSettings::PathInfo* pPathOld,
395 : const PathSettings::PathInfo* pPathNew);
396 :
397 :
398 : // OPropertySetHelper
399 : virtual sal_Bool SAL_CALL convertFastPropertyValue ( css::uno::Any& aConvertedValue ,
400 : css::uno::Any& aOldValue ,
401 : sal_Int32 nHandle ,
402 : const css::uno::Any& aValue ) throw(css::lang::IllegalArgumentException);
403 : virtual void SAL_CALL setFastPropertyValue_NoBroadcast( sal_Int32 nHandle ,
404 : const css::uno::Any& aValue ) throw(css::uno::Exception);
405 : using cppu::OPropertySetHelper::getFastPropertyValue;
406 : virtual void SAL_CALL getFastPropertyValue ( css::uno::Any& aValue ,
407 : sal_Int32 nHandle ) const;
408 : virtual ::cppu::IPropertyArrayHelper& SAL_CALL getInfoHelper ( );
409 : virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo ( ) throw(::css::uno::RuntimeException);
410 :
411 : /** factory methods to guarantee right (but on demand) initialized members ... */
412 : css::uno::Reference< css::util::XStringSubstitution > fa_getSubstitution();
413 : css::uno::Reference< css::container::XNameAccess > fa_getCfgOld();
414 : css::uno::Reference< css::container::XNameAccess > fa_getCfgNew();
415 : };
416 :
417 : } // namespace framework
418 :
419 : #endif // __FRAMEWORK_SERVICES_PATHSETTINGS_HXX_
420 :
421 : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|