LCOV - code coverage report
Current view: top level - libreoffice/framework/inc/services - pathsettings.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 4 16 25.0 %
Date: 2012-12-27 Functions: 3 5 60.0 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10