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