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