LCOV - code coverage report
Current view: top level - framework/inc/services - pathsettings.hxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 16 16 100.0 %
Date: 2012-08-25 Functions: 5 5 100.0 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 7 14 50.0 %

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

Generated by: LCOV version 1.10