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: pathsettings.hxx,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 #ifndef __FRAMEWORK_SERVICES_PATHSETTINGS_HXX_
32 #define __FRAMEWORK_SERVICES_PATHSETTINGS_HXX_
34 //_________________________________________________________________________________________________________________
36 //_________________________________________________________________________________________________________________
38 #include <threadhelp/threadhelpbase.hxx>
39 #include <macros/generic.hxx>
40 #include <macros/xinterface.hxx>
41 #include <macros/xtypeprovider.hxx>
42 #include <macros/xserviceinfo.hxx>
44 #include <properties.h>
47 //_________________________________________________________________________________________________________________
49 //_________________________________________________________________________________________________________________
50 #include <com/sun/star/lang/XServiceInfo.hpp>
51 #include <com/sun/star/lang/XTypeProvider.hpp>
52 #include <com/sun/star/util/XStringSubstitution.hpp>
53 #include <com/sun/star/util/XChangesListener.hpp>
54 #include <com/sun/star/container/XNameAccess.hpp>
56 //_________________________________________________________________________________________________________________
58 //_________________________________________________________________________________________________________________
59 #include <cppuhelper/propshlp.hxx>
60 #include <cppuhelper/interfacecontainer.hxx>
61 #include <cppuhelper/weak.hxx>
62 #include <unotools/configitem.hxx>
63 #include <comphelper/sequenceasvector.hxx>
65 /* enable it if you whish to migrate old user settings (using the old cfg schema) on demand ....
66 disable it in case only the new schema must be used.
68 #define MIGRATE_OLD_USER_PATHES
73 class PathSettings
: public css::lang::XTypeProvider
,
74 public css::lang::XServiceInfo
,
75 public css::util::XChangesListener
, // => XEventListener
77 // Order is neccessary for right initialization!
78 private ThreadHelpBase
,
79 public ::cppu::OBroadcastHelper
,
80 public ::cppu::OPropertySetHelper
, // => XPropertySet / XFastPropertySet / XMultiPropertySet
81 public ::cppu::OWeakObject
// => XWeak, XInterface
92 , bIsSinglePath (sal_False
)
93 , bIsReadonly (sal_False
)
96 PathInfo(const PathInfo
& rCopy
)
101 void takeOver(const PathInfo
& rCopy
)
103 sPathName
= rCopy
.sPathName
;
104 lInternalPaths
= rCopy
.lInternalPaths
;
105 lUserPaths
= rCopy
.lUserPaths
;
106 sWritePath
= rCopy
.sWritePath
;
107 bIsSinglePath
= rCopy
.bIsSinglePath
;
108 bIsReadonly
= rCopy
.bIsReadonly
;
111 /// an internal name describing this path
112 ::rtl::OUString sPathName
;
114 /// contains all paths, which are used internaly - but are not visible for the user.
115 OUStringList lInternalPaths
;
117 /// contains all paths configured by the user
118 OUStringList lUserPaths
;
120 /// this special path is used to generate feature depending content there
121 ::rtl::OUString sWritePath
;
123 /// indicates real single pathes, which uses WritePath property only
124 sal_Bool bIsSinglePath
;
126 /// simple handling of finalized/mandatory states ... => we know one state READONLY only .-)
127 sal_Bool bIsReadonly
;
130 typedef BaseHash
< PathSettings::PathInfo
> PathHash
;
140 // ______________________________________
145 /** reference to factory, which has create this instance. */
146 css::uno::Reference
< css::lang::XMultiServiceFactory
> m_xSMGR
;
148 /** list of all path variables and her corresponding values. */
149 PathSettings::PathHash m_lPaths
;
151 /** describes all properties available on our interface.
152 Will be generated on demand based on our path list m_lPaths. */
153 css::uno::Sequence
< css::beans::Property
> m_lPropDesc
;
155 /** helper needed to (re-)substitute all internal save path values. */
156 css::uno::Reference
< css::util::XStringSubstitution
> m_xSubstitution
;
158 /** provides access to the old configuration schema (which will be migrated on demand). */
159 css::uno::Reference
< css::container::XNameAccess
> m_xCfgOld
;
161 /** provides access to the new configuration schema. */
162 css::uno::Reference
< css::container::XNameAccess
> m_xCfgNew
;
164 ::cppu::OPropertyArrayHelper
* m_pPropHelp
;
166 ::sal_Bool m_bIgnoreEvents
;
168 // ___________________________________________
173 /** initialize a new instance of this class.
174 Attention: It's neccessary for right function of this class, that the order of base
175 classes is the right one. Because we transfer information from one base to another
176 during this ctor runs! */
177 PathSettings(const css::uno::Reference
< css::lang::XMultiServiceFactory
>& xSMGR
);
179 /** free all used ressources ... if it was not already done. */
180 virtual ~PathSettings();
182 /** declaration of XInterface, XTypeProvider, XServiceInfo */
183 FWK_DECLARE_XINTERFACE
184 FWK_DECLARE_XTYPEPROVIDER
187 // css::util::XChangesListener
188 virtual void SAL_CALL
changesOccurred(const css::util::ChangesEvent
& aEvent
) throw (css::uno::RuntimeException
);
190 // css::lang::XEventListener
191 virtual void SAL_CALL
disposing(const css::lang::EventObject
& aSource
)
192 throw(css::uno::RuntimeException
);
194 using ::cppu::OPropertySetHelper::disposing
;
196 // ___________________________________________
201 /** read all configured paths and create all needed internal structures. */
204 /** read a path info using the old cfg schema.
205 This is needed for "migration on demand" reasons only.
206 Can be removed for next major release .-) */
207 OUStringList
impl_readOldFormat(const ::rtl::OUString
& sPath
);
209 /** read a path info using the new cfg schema. */
210 PathSettings::PathInfo
impl_readNewFormat(const ::rtl::OUString
& sPath
);
212 /** filter "real user defined paths" from the old configuration schema
213 and set it as UserPaths on the new schema.
214 Can be removed with new major release ... */
215 #ifdef MIGRATE_OLD_USER_PATHES
216 void impl_mergeOldUserPaths( PathSettings::PathInfo
& rPath
,
217 const OUStringList
& lOld
);
220 /** reload one path directly from the new configuration schema (because
221 it was updated by any external code) */
222 PathSettings::EChangeOp
impl_updatePath(const ::rtl::OUString
& sPath
,
223 sal_Bool bNotifyListener
);
225 /** replace all might existing placeholder variables inside the given path ...
226 or check if the given path value uses paths, which can be replaced with predefined
227 placeholder variables ...
229 void impl_subst( OUStringList
& lVals
,
230 const css::uno::Reference
< css::util::XStringSubstitution
>& xSubst
,
233 void impl_subst(PathSettings::PathInfo
& aPath
,
237 /** converts our new string list schema to the old ";" seperated schema ... */
238 ::rtl::OUString
impl_convertPath2OldStyle(const PathSettings::PathInfo
& rPath
) const;
239 OUStringList
impl_convertOldStyle2Path(const ::rtl::OUString
& sOldStylePath
) const;
241 /** remove still known paths from the given lList argument.
242 So real user defined paths can be extracted from the list of
245 void impl_purgeKnownPaths(const PathSettings::PathInfo
& rPath
,
246 OUStringList
& lList
);
248 /** rebuild the member m_lPropDesc using the path list m_lPaths. */
249 void impl_rebuildPropertyDescriptor();
251 /** provides direct access to the list of path values
252 using it's internal property id.
254 css::uno::Any
impl_getPathValue( sal_Int32 nID
) const;
255 void impl_setPathValue( sal_Int32 nID
,
256 const css::uno::Any
& aVal
);
258 /** check the given handle and return the corresponding PathInfo reference.
259 These reference can be used then directly to manipulate these path. */
260 PathSettings::PathInfo
* impl_getPathAccess (sal_Int32 nHandle
);
261 const PathSettings::PathInfo
* impl_getPathAccessConst(sal_Int32 nHandle
) const;
263 /** it checks, if the given path value seams to be a valid URL or system path. */
264 sal_Bool
impl_isValidPath(const ::rtl::OUString
& sPath
) const;
265 sal_Bool
impl_isValidPath(const OUStringList
& lPath
) const;
267 void impl_storePath(const PathSettings::PathInfo
& aPath
);
269 css::uno::Sequence
< sal_Int32
> impl_mapPathName2IDList(const ::rtl::OUString
& sPath
);
271 void impl_notifyPropListener( PathSettings::EChangeOp eOp
,
272 const ::rtl::OUString
& sPath
,
273 const PathSettings::PathInfo
* pPathOld
,
274 const PathSettings::PathInfo
* pPathNew
);
277 // OPropertySetHelper
278 virtual sal_Bool SAL_CALL
convertFastPropertyValue ( css::uno::Any
& aConvertedValue
,
279 css::uno::Any
& aOldValue
,
281 const css::uno::Any
& aValue
) throw(css::lang::IllegalArgumentException
);
282 virtual void SAL_CALL
setFastPropertyValue_NoBroadcast( sal_Int32 nHandle
,
283 const css::uno::Any
& aValue
) throw(css::uno::Exception
);
284 using cppu::OPropertySetHelper::getFastPropertyValue
;
285 virtual void SAL_CALL
getFastPropertyValue ( css::uno::Any
& aValue
,
286 sal_Int32 nHandle
) const;
287 virtual ::cppu::IPropertyArrayHelper
& SAL_CALL
getInfoHelper ( );
288 virtual css::uno::Reference
< css::beans::XPropertySetInfo
> SAL_CALL
getPropertySetInfo ( ) throw(::com::sun::star::uno::RuntimeException
);
290 /** factory methods to guarantee right (but on demand) initialized members ... */
291 css::uno::Reference
< css::util::XStringSubstitution
> fa_getSubstitution();
292 css::uno::Reference
< css::container::XNameAccess
> fa_getCfgOld();
293 css::uno::Reference
< css::container::XNameAccess
> fa_getCfgNew();
296 } // namespace framework
298 #endif // __FRAMEWORK_SERVICES_PATHSETTINGS_HXX_