1f8e07b45SAndrew Rist /**************************************************************
2cdf0e10cSrcweir  *
3f8e07b45SAndrew Rist  * Licensed to the Apache Software Foundation (ASF) under one
4f8e07b45SAndrew Rist  * or more contributor license agreements.  See the NOTICE file
5f8e07b45SAndrew Rist  * distributed with this work for additional information
6f8e07b45SAndrew Rist  * regarding copyright ownership.  The ASF licenses this file
7f8e07b45SAndrew Rist  * to you under the Apache License, Version 2.0 (the
8f8e07b45SAndrew Rist  * "License"); you may not use this file except in compliance
9f8e07b45SAndrew Rist  * with the License.  You may obtain a copy of the License at
10f8e07b45SAndrew Rist  *
11f8e07b45SAndrew Rist  *   http://www.apache.org/licenses/LICENSE-2.0
12f8e07b45SAndrew Rist  *
13f8e07b45SAndrew Rist  * Unless required by applicable law or agreed to in writing,
14f8e07b45SAndrew Rist  * software distributed under the License is distributed on an
15f8e07b45SAndrew Rist  * "AS IS" BASIS, WITHOUT WARRANTIES OR CONDITIONS OF ANY
16f8e07b45SAndrew Rist  * KIND, either express or implied.  See the License for the
17f8e07b45SAndrew Rist  * specific language governing permissions and limitations
18f8e07b45SAndrew Rist  * under the License.
19f8e07b45SAndrew Rist  *
20f8e07b45SAndrew Rist  *************************************************************/
21f8e07b45SAndrew Rist 
22f8e07b45SAndrew Rist 
23cdf0e10cSrcweir 
24cdf0e10cSrcweir #ifndef __FRAMEWORK_SERVICES_PATHSETTINGS_HXX_
25cdf0e10cSrcweir #define __FRAMEWORK_SERVICES_PATHSETTINGS_HXX_
26cdf0e10cSrcweir 
27cdf0e10cSrcweir //_________________________________________________________________________________________________________________
28cdf0e10cSrcweir //	my own includes
29cdf0e10cSrcweir //_________________________________________________________________________________________________________________
30cdf0e10cSrcweir 
31cdf0e10cSrcweir #include <threadhelp/threadhelpbase.hxx>
32cdf0e10cSrcweir #include <macros/generic.hxx>
33cdf0e10cSrcweir #include <macros/xinterface.hxx>
34cdf0e10cSrcweir #include <macros/xtypeprovider.hxx>
35cdf0e10cSrcweir #include <macros/xserviceinfo.hxx>
36cdf0e10cSrcweir #include <stdtypes.h>
37cdf0e10cSrcweir #include <properties.h>
38cdf0e10cSrcweir #include <stdtypes.h>
39cdf0e10cSrcweir 
40cdf0e10cSrcweir //_________________________________________________________________________________________________________________
41cdf0e10cSrcweir //	interface includes
42cdf0e10cSrcweir //_________________________________________________________________________________________________________________
43cdf0e10cSrcweir #include <com/sun/star/lang/XServiceInfo.hpp>
44cdf0e10cSrcweir #include <com/sun/star/lang/XTypeProvider.hpp>
45cdf0e10cSrcweir #include <com/sun/star/util/XStringSubstitution.hpp>
46cdf0e10cSrcweir #include <com/sun/star/util/XChangesListener.hpp>
47cdf0e10cSrcweir #include <com/sun/star/container/XNameAccess.hpp>
48cdf0e10cSrcweir 
49cdf0e10cSrcweir //_________________________________________________________________________________________________________________
50cdf0e10cSrcweir //	other includes
51cdf0e10cSrcweir //_________________________________________________________________________________________________________________
52cdf0e10cSrcweir #include <cppuhelper/propshlp.hxx>
53cdf0e10cSrcweir #include <cppuhelper/interfacecontainer.hxx>
54cdf0e10cSrcweir #include <cppuhelper/weak.hxx>
55cdf0e10cSrcweir #include <unotools/configitem.hxx>
56cdf0e10cSrcweir #include <comphelper/sequenceasvector.hxx>
57cdf0e10cSrcweir 
58cdf0e10cSrcweir /* enable it if you whish to migrate old user settings (using the old cfg schema) on demand ....
59cdf0e10cSrcweir    disable it in case only the new schema must be used.
60cdf0e10cSrcweir  */
61cdf0e10cSrcweir #define MIGRATE_OLD_USER_PATHES
62cdf0e10cSrcweir 
63cdf0e10cSrcweir namespace framework
64cdf0e10cSrcweir {
65cdf0e10cSrcweir 
66cdf0e10cSrcweir class PathSettings : public  css::lang::XTypeProvider             ,
67cdf0e10cSrcweir                      public  css::lang::XServiceInfo              ,
68cdf0e10cSrcweir                      public  css::util::XChangesListener          , // => XEventListener
69cdf0e10cSrcweir                      // base classes
7007a3d7f1SPedro Giffuni                      // Order is necessary for right initialization!
71cdf0e10cSrcweir                      private ThreadHelpBase                       ,
72cdf0e10cSrcweir                      public  ::cppu::OBroadcastHelper             ,
73cdf0e10cSrcweir                      public  ::cppu::OPropertySetHelper           , // => XPropertySet / XFastPropertySet / XMultiPropertySet
74cdf0e10cSrcweir                      public  ::cppu::OWeakObject                    // => XWeak, XInterface
75cdf0e10cSrcweir {
76cdf0e10cSrcweir     struct PathInfo
77cdf0e10cSrcweir     {
78cdf0e10cSrcweir         public:
79cdf0e10cSrcweir 
PathInfoframework::PathSettings::PathInfo80cdf0e10cSrcweir             PathInfo()
81cdf0e10cSrcweir                 : sPathName     ()
82cdf0e10cSrcweir                 , lInternalPaths()
83cdf0e10cSrcweir                 , lUserPaths    ()
84cdf0e10cSrcweir                 , sWritePath    ()
85cdf0e10cSrcweir                 , bIsSinglePath (sal_False)
86cdf0e10cSrcweir                 , bIsReadonly   (sal_False)
87cdf0e10cSrcweir             {}
88cdf0e10cSrcweir 
PathInfoframework::PathSettings::PathInfo89cdf0e10cSrcweir             PathInfo(const PathInfo& rCopy)
90cdf0e10cSrcweir             {
91cdf0e10cSrcweir                 takeOver(rCopy);
92cdf0e10cSrcweir             }
93cdf0e10cSrcweir 
takeOverframework::PathSettings::PathInfo94cdf0e10cSrcweir             void takeOver(const PathInfo& rCopy)
95cdf0e10cSrcweir             {
96cdf0e10cSrcweir                 sPathName      = rCopy.sPathName;
97cdf0e10cSrcweir                 lInternalPaths = rCopy.lInternalPaths;
98cdf0e10cSrcweir                 lUserPaths     = rCopy.lUserPaths;
99cdf0e10cSrcweir                 sWritePath     = rCopy.sWritePath;
100cdf0e10cSrcweir                 bIsSinglePath  = rCopy.bIsSinglePath;
101cdf0e10cSrcweir                 bIsReadonly    = rCopy.bIsReadonly;
102cdf0e10cSrcweir             }
103cdf0e10cSrcweir 
104cdf0e10cSrcweir             /// an internal name describing this path
105cdf0e10cSrcweir             ::rtl::OUString sPathName;
106cdf0e10cSrcweir 
10706fea5ebSmseidel             /// contains all paths, which are used internally - but are not visible for the user.
108cdf0e10cSrcweir             OUStringList lInternalPaths;
109cdf0e10cSrcweir 
110cdf0e10cSrcweir             /// contains all paths configured by the user
111cdf0e10cSrcweir             OUStringList lUserPaths;
112cdf0e10cSrcweir 
113cdf0e10cSrcweir             /// this special path is used to generate feature depending content there
114cdf0e10cSrcweir             ::rtl::OUString sWritePath;
115cdf0e10cSrcweir 
11607a3d7f1SPedro Giffuni             /// indicates real single paths, which uses WritePath property only
117cdf0e10cSrcweir             sal_Bool bIsSinglePath;
118cdf0e10cSrcweir 
119cdf0e10cSrcweir             /// simple handling of finalized/mandatory states ... => we know one state READONLY only .-)
120cdf0e10cSrcweir             sal_Bool bIsReadonly;
121cdf0e10cSrcweir     };
122cdf0e10cSrcweir 
123cdf0e10cSrcweir     typedef BaseHash< PathSettings::PathInfo > PathHash;
124cdf0e10cSrcweir 
125cdf0e10cSrcweir     enum EChangeOp
126cdf0e10cSrcweir     {
127cdf0e10cSrcweir         E_UNDEFINED,
128cdf0e10cSrcweir         E_ADDED,
129cdf0e10cSrcweir         E_CHANGED,
130cdf0e10cSrcweir         E_REMOVED
131cdf0e10cSrcweir     };
132cdf0e10cSrcweir 
133cdf0e10cSrcweir     // ______________________________________
134cdf0e10cSrcweir     // member
135cdf0e10cSrcweir 
136cdf0e10cSrcweir     private:
137cdf0e10cSrcweir 
138cdf0e10cSrcweir         /** reference to factory, which has create this instance. */
139cdf0e10cSrcweir         css::uno::Reference< css::lang::XMultiServiceFactory > m_xSMGR;
140cdf0e10cSrcweir 
141cdf0e10cSrcweir         /** list of all path variables and her corresponding values. */
142cdf0e10cSrcweir         PathSettings::PathHash m_lPaths;
143cdf0e10cSrcweir 
144cdf0e10cSrcweir         /** describes all properties available on our interface.
145cdf0e10cSrcweir             Will be generated on demand based on our path list m_lPaths. */
146cdf0e10cSrcweir         css::uno::Sequence< css::beans::Property > m_lPropDesc;
147cdf0e10cSrcweir 
148cdf0e10cSrcweir         /** helper needed to (re-)substitute all internal save path values. */
149cdf0e10cSrcweir         css::uno::Reference< css::util::XStringSubstitution > m_xSubstitution;
150cdf0e10cSrcweir 
151cdf0e10cSrcweir         /** provides access to the old configuration schema (which will be migrated on demand). */
152cdf0e10cSrcweir         css::uno::Reference< css::container::XNameAccess > m_xCfgOld;
153cdf0e10cSrcweir 
154cdf0e10cSrcweir         /** provides access to the new configuration schema. */
155cdf0e10cSrcweir         css::uno::Reference< css::container::XNameAccess > m_xCfgNew;
156cdf0e10cSrcweir 
157cdf0e10cSrcweir         ::cppu::OPropertyArrayHelper* m_pPropHelp;
158cdf0e10cSrcweir 
159cdf0e10cSrcweir 		::sal_Bool m_bIgnoreEvents;
160cdf0e10cSrcweir 
161cdf0e10cSrcweir     // ___________________________________________
162cdf0e10cSrcweir     // interface
163cdf0e10cSrcweir 
164cdf0e10cSrcweir     public:
165cdf0e10cSrcweir 
166cdf0e10cSrcweir         /** initialize a new instance of this class.
16707a3d7f1SPedro Giffuni             Attention: It's necessary for right function of this class, that the order of base
168cdf0e10cSrcweir             classes is the right one. Because we transfer information from one base to another
169cdf0e10cSrcweir             during this ctor runs! */
170cdf0e10cSrcweir         PathSettings(const css::uno::Reference< css::lang::XMultiServiceFactory >& xSMGR);
171cdf0e10cSrcweir 
172cdf0e10cSrcweir         /** free all used ressources ... if it was not already done. */
173cdf0e10cSrcweir         virtual ~PathSettings();
174cdf0e10cSrcweir 
175cdf0e10cSrcweir         /** declaration of XInterface, XTypeProvider, XServiceInfo */
176cdf0e10cSrcweir 		FWK_DECLARE_XINTERFACE
177cdf0e10cSrcweir 		FWK_DECLARE_XTYPEPROVIDER
178cdf0e10cSrcweir 		DECLARE_XSERVICEINFO
179cdf0e10cSrcweir 
180cdf0e10cSrcweir         // css::util::XChangesListener
181cdf0e10cSrcweir         virtual void SAL_CALL changesOccurred(const css::util::ChangesEvent& aEvent) throw (css::uno::RuntimeException);
182cdf0e10cSrcweir 
183cdf0e10cSrcweir         // css::lang::XEventListener
184cdf0e10cSrcweir         virtual void SAL_CALL disposing(const css::lang::EventObject& aSource)
185cdf0e10cSrcweir             throw(css::uno::RuntimeException);
186cdf0e10cSrcweir 
187cdf0e10cSrcweir 		using ::cppu::OPropertySetHelper::disposing;
188cdf0e10cSrcweir 
189cdf0e10cSrcweir     // ___________________________________________
190cdf0e10cSrcweir     // helper
191cdf0e10cSrcweir 
192cdf0e10cSrcweir     private:
193cdf0e10cSrcweir 
194cdf0e10cSrcweir         /** read all configured paths and create all needed internal structures. */
195cdf0e10cSrcweir         void impl_readAll();
196cdf0e10cSrcweir 
197cdf0e10cSrcweir         /** read a path info using the old cfg schema.
198cdf0e10cSrcweir             This is needed for "migration on demand" reasons only.
199cdf0e10cSrcweir             Can be removed for next major release .-) */
200cdf0e10cSrcweir         OUStringList impl_readOldFormat(const ::rtl::OUString& sPath);
201cdf0e10cSrcweir 
202cdf0e10cSrcweir         /** read a path info using the new cfg schema. */
203cdf0e10cSrcweir         PathSettings::PathInfo impl_readNewFormat(const ::rtl::OUString& sPath);
204cdf0e10cSrcweir 
205cdf0e10cSrcweir         /** filter "real user defined paths" from the old configuration schema
206cdf0e10cSrcweir             and set it as UserPaths on the new schema.
207cdf0e10cSrcweir             Can be removed with new major release ... */
208cdf0e10cSrcweir         #ifdef MIGRATE_OLD_USER_PATHES
209cdf0e10cSrcweir         void impl_mergeOldUserPaths(      PathSettings::PathInfo& rPath,
210cdf0e10cSrcweir                                      const OUStringList&           lOld );
211cdf0e10cSrcweir         #endif
212cdf0e10cSrcweir 
213cdf0e10cSrcweir         /** reload one path directly from the new configuration schema (because
214cdf0e10cSrcweir             it was updated by any external code) */
215cdf0e10cSrcweir         PathSettings::EChangeOp impl_updatePath(const ::rtl::OUString& sPath          ,
216cdf0e10cSrcweir                                                       sal_Bool         bNotifyListener);
217cdf0e10cSrcweir 
218cdf0e10cSrcweir         /** replace all might existing placeholder variables inside the given path ...
219cdf0e10cSrcweir             or check if the given path value uses paths, which can be replaced with predefined
220cdf0e10cSrcweir             placeholder variables ...
221cdf0e10cSrcweir          */
222cdf0e10cSrcweir         void impl_subst(      OUStringList&                                          lVals   ,
223cdf0e10cSrcweir                         const css::uno::Reference< css::util::XStringSubstitution >& xSubst  ,
224cdf0e10cSrcweir                               sal_Bool                                               bReSubst);
225cdf0e10cSrcweir 
226cdf0e10cSrcweir         void impl_subst(PathSettings::PathInfo& aPath   ,
227cdf0e10cSrcweir                         sal_Bool                bReSubst);
228cdf0e10cSrcweir 
229cdf0e10cSrcweir 
23007a3d7f1SPedro Giffuni         /** converts our new string list schema to the old ";" separated schema ... */
231cdf0e10cSrcweir         ::rtl::OUString impl_convertPath2OldStyle(const PathSettings::PathInfo& rPath        ) const;
232cdf0e10cSrcweir         OUStringList    impl_convertOldStyle2Path(const ::rtl::OUString&        sOldStylePath) const;
233cdf0e10cSrcweir 
234cdf0e10cSrcweir         /** remove still known paths from the given lList argument.
235cdf0e10cSrcweir             So real user defined paths can be extracted from the list of
236cdf0e10cSrcweir             fix internal paths !
237cdf0e10cSrcweir          */
238cdf0e10cSrcweir         void impl_purgeKnownPaths(const PathSettings::PathInfo& rPath,
239cdf0e10cSrcweir                                          OUStringList&           lList);
240cdf0e10cSrcweir 
241cdf0e10cSrcweir         /** rebuild the member m_lPropDesc using the path list m_lPaths. */
242cdf0e10cSrcweir         void impl_rebuildPropertyDescriptor();
243cdf0e10cSrcweir 
244cdf0e10cSrcweir         /** provides direct access to the list of path values
245cdf0e10cSrcweir             using it's internal property id.
246cdf0e10cSrcweir          */
247cdf0e10cSrcweir         css::uno::Any impl_getPathValue(      sal_Int32      nID ) const;
248cdf0e10cSrcweir         void          impl_setPathValue(      sal_Int32      nID ,
249cdf0e10cSrcweir                                         const css::uno::Any& aVal);
250cdf0e10cSrcweir 
251cdf0e10cSrcweir         /** check the given handle and return the corresponding PathInfo reference.
252cdf0e10cSrcweir             These reference can be used then directly to manipulate these path. */
253cdf0e10cSrcweir               PathSettings::PathInfo* impl_getPathAccess     (sal_Int32 nHandle);
254cdf0e10cSrcweir         const PathSettings::PathInfo* impl_getPathAccessConst(sal_Int32 nHandle) const;
255cdf0e10cSrcweir 
256*cfd52e18Smseidel         /** it checks, if the given path value seems to be a valid URL or system path. */
257cdf0e10cSrcweir         sal_Bool impl_isValidPath(const ::rtl::OUString& sPath) const;
258cdf0e10cSrcweir         sal_Bool impl_isValidPath(const OUStringList&    lPath) const;
259cdf0e10cSrcweir 
260cdf0e10cSrcweir         void impl_storePath(const PathSettings::PathInfo& aPath);
261cdf0e10cSrcweir 
262cdf0e10cSrcweir         css::uno::Sequence< sal_Int32 > impl_mapPathName2IDList(const ::rtl::OUString& sPath);
263cdf0e10cSrcweir 
264cdf0e10cSrcweir         void impl_notifyPropListener(      PathSettings::EChangeOp eOp     ,
265cdf0e10cSrcweir                                            const ::rtl::OUString&        sPath   ,
266cdf0e10cSrcweir                                            const PathSettings::PathInfo* pPathOld,
267cdf0e10cSrcweir                                            const PathSettings::PathInfo* pPathNew);
268cdf0e10cSrcweir 
269cdf0e10cSrcweir 
270cdf0e10cSrcweir 		//	OPropertySetHelper
271cdf0e10cSrcweir         virtual sal_Bool                                            SAL_CALL convertFastPropertyValue        (       css::uno::Any&  aConvertedValue ,
272cdf0e10cSrcweir                                                                                                                      css::uno::Any&  aOldValue       ,
273cdf0e10cSrcweir                                                                                                                      sal_Int32       nHandle         ,
274cdf0e10cSrcweir                                                                                                                const css::uno::Any&  aValue          ) throw(css::lang::IllegalArgumentException);
275cdf0e10cSrcweir 		virtual void                                                SAL_CALL setFastPropertyValue_NoBroadcast(       sal_Int32       nHandle         ,
276cdf0e10cSrcweir                                                                                                                const css::uno::Any&  aValue          ) throw(css::uno::Exception);
277cdf0e10cSrcweir 		using cppu::OPropertySetHelper::getFastPropertyValue;
278cdf0e10cSrcweir         virtual void                                                SAL_CALL getFastPropertyValue            (       css::uno::Any&  aValue          ,
279cdf0e10cSrcweir                                                                                                                      sal_Int32       nHandle         ) const;
280cdf0e10cSrcweir         virtual ::cppu::IPropertyArrayHelper&                       SAL_CALL getInfoHelper                   (                                       );
281cdf0e10cSrcweir         virtual css::uno::Reference< css::beans::XPropertySetInfo > SAL_CALL getPropertySetInfo              (                                       ) throw(::com::sun::star::uno::RuntimeException);
282cdf0e10cSrcweir 
283cdf0e10cSrcweir         /** factory methods to guarantee right (but on demand) initialized members ... */
284cdf0e10cSrcweir         css::uno::Reference< css::util::XStringSubstitution > fa_getSubstitution();
285cdf0e10cSrcweir         css::uno::Reference< css::container::XNameAccess >    fa_getCfgOld();
286cdf0e10cSrcweir         css::uno::Reference< css::container::XNameAccess >    fa_getCfgNew();
287cdf0e10cSrcweir };
288cdf0e10cSrcweir 
289cdf0e10cSrcweir } // namespace framework
290cdf0e10cSrcweir 
291cdf0e10cSrcweir #endif // __FRAMEWORK_SERVICES_PATHSETTINGS_HXX_
292