LCOV - code coverage report
Current view: top level - unotools/source/config - pathoptions.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 181 375 48.3 %
Date: 2012-08-25 Functions: 42 115 36.5 %
Legend: Lines: hit not hit | Branches: + taken - not taken # not executed Branches: 146 462 31.6 %

           Branch data     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                 :            : #include <unotools/pathoptions.hxx>
      21                 :            : #include <unotools/configitem.hxx>
      22                 :            : #include <unotools/configmgr.hxx>
      23                 :            : #include <tools/urlobj.hxx>
      24                 :            : #include <com/sun/star/uno/Any.hxx>
      25                 :            : #include <com/sun/star/uno/Sequence.hxx>
      26                 :            : #include <osl/mutex.hxx>
      27                 :            : #include <osl/file.hxx>
      28                 :            : #include <unotools/localfilehelper.hxx>
      29                 :            : #include <unotools/bootstrap.hxx>
      30                 :            : 
      31                 :            : #include <unotools/ucbhelper.hxx>
      32                 :            : #include <comphelper/processfactory.hxx>
      33                 :            : #include <comphelper/componentcontext.hxx>
      34                 :            : #include <com/sun/star/beans/XFastPropertySet.hpp>
      35                 :            : #include <com/sun/star/beans/XPropertySet.hpp>
      36                 :            : #include <com/sun/star/beans/PropertyAttribute.hpp>
      37                 :            : #include <com/sun/star/beans/XPropertySetInfo.hpp>
      38                 :            : #include <com/sun/star/util/PathSubstitution.hpp>
      39                 :            : #include <com/sun/star/util/XStringSubstitution.hpp>
      40                 :            : #include <com/sun/star/lang/XMultiServiceFactory.hpp>
      41                 :            : #include <com/sun/star/util/XMacroExpander.hpp>
      42                 :            : #include <rtl/instance.hxx>
      43                 :            : 
      44                 :            : #include <itemholder1.hxx>
      45                 :            : 
      46                 :            : #include <vector>
      47                 :            : #include <boost/unordered_map.hpp>
      48                 :            : 
      49                 :            : using namespace osl;
      50                 :            : using namespace utl;
      51                 :            : using namespace com::sun::star::uno;
      52                 :            : using namespace com::sun::star::beans;
      53                 :            : using namespace com::sun::star::util;
      54                 :            : using namespace com::sun::star::lang;
      55                 :            : 
      56                 :            : using ::rtl::OUString;
      57                 :            : using ::rtl::OString;
      58                 :            : using ::rtl::OStringToOUString;
      59                 :            : 
      60                 :            : #define SEARCHPATH_DELIMITER  ';'
      61                 :            : #define SIGN_STARTVARIABLE    OUString( "$("  )
      62                 :            : #define SIGN_ENDVARIABLE      OUString( ")" )
      63                 :            : 
      64                 :            : // Supported variables by the old SvtPathOptions implementation
      65                 :            : #define SUBSTITUTE_INSTPATH   "$(instpath)"
      66                 :            : #define SUBSTITUTE_PROGPATH   "$(progpath)"
      67                 :            : #define SUBSTITUTE_USERPATH   "$(userpath)"
      68                 :            : #define SUBSTITUTE_PATH       "$(path)"
      69                 :            : 
      70                 :            : #define STRPOS_NOTFOUND       -1
      71                 :            : 
      72                 :            : struct OUStringHashCode
      73                 :            : {
      74                 :          0 :     size_t operator()( const ::rtl::OUString& sString ) const
      75                 :            :     {
      76                 :          0 :         return sString.hashCode();
      77                 :            :     }
      78                 :            : };
      79                 :            : 
      80                 :            : enum VarNameProperty
      81                 :            : {
      82                 :            :     VAR_NEEDS_SYSTEM_PATH,
      83                 :            :     VAR_NEEDS_FILEURL
      84                 :            : };
      85                 :            : 
      86         [ +  - ]:        466 : class NameToHandleMap : public ::boost::unordered_map<  ::rtl::OUString, sal_Int32, OUStringHashCode, ::std::equal_to< ::rtl::OUString > >
      87                 :            : {
      88                 :            :     public:
      89                 :            :         inline void free() { NameToHandleMap().swap( *this ); }
      90                 :            : };
      91                 :            : 
      92         [ +  - ]:        466 : class EnumToHandleMap : public ::boost::unordered_map< sal_Int32, sal_Int32, boost::hash< sal_Int32 >, std::equal_to< sal_Int32 > >
      93                 :            : {
      94                 :            :     public:
      95                 :            :         inline void free() { EnumToHandleMap().swap( *this ); }
      96                 :            : };
      97                 :            : 
      98         [ +  - ]:        466 : class VarNameToEnumMap : public ::boost::unordered_map< OUString, VarNameProperty, OUStringHashCode, ::std::equal_to< OUString > >
      99                 :            : {
     100                 :            :     public:
     101                 :            :         inline void free() { VarNameToEnumMap().swap( *this ); }
     102                 :            : };
     103                 :            : 
     104                 :            : 
     105                 :            : // class SvtPathOptions_Impl ---------------------------------------------
     106 [ +  - ][ +  - ]:        233 : class SvtPathOptions_Impl
         [ +  - ][ +  - ]
     107                 :            : {
     108                 :            :     private:
     109                 :            :         // Local variables to return const references
     110                 :            :         std::vector< String >               m_aPathArray;
     111                 :            :         Reference< XFastPropertySet >       m_xPathSettings;
     112                 :            :         Reference< XStringSubstitution >    m_xSubstVariables;
     113                 :            :         Reference< XMacroExpander >         m_xMacroExpander;
     114                 :            :         mutable EnumToHandleMap             m_aMapEnumToPropHandle;
     115                 :            :         VarNameToEnumMap                    m_aMapVarNamesToEnum;
     116                 :            : 
     117                 :            :         ::com::sun::star::lang::Locale      m_aLocale;
     118                 :            :         String                              m_aEmptyString;
     119                 :            :         mutable ::osl::Mutex                m_aMutex;
     120                 :            : 
     121                 :            :     public:
     122                 :            :                         SvtPathOptions_Impl();
     123                 :            : 
     124                 :            :         // get the paths, not const because of using a mutex
     125                 :            :         const String&   GetPath( SvtPathOptions::Paths );
     126                 :        153 :         const String&   GetAddinPath() { return GetPath( SvtPathOptions::PATH_ADDIN ); }
     127                 :         73 :         const String&   GetAutoCorrectPath() { return GetPath( SvtPathOptions::PATH_AUTOCORRECT ); }
     128                 :          2 :         const String&   GetAutoTextPath() { return GetPath( SvtPathOptions::PATH_AUTOTEXT ); }
     129                 :        154 :         const String&   GetBackupPath() { return GetPath( SvtPathOptions::PATH_BACKUP ); }
     130                 :       1786 :         const String&   GetBasicPath() { return GetPath( SvtPathOptions::PATH_BASIC ); }
     131                 :          0 :         const String&   GetBitmapPath() { return GetPath( SvtPathOptions::PATH_BITMAP ); }
     132                 :        230 :         const String&   GetConfigPath() { return GetPath( SvtPathOptions::PATH_CONFIG ); }
     133                 :          0 :         const String&   GetDictionaryPath() { return GetPath( SvtPathOptions::PATH_DICTIONARY ); }
     134                 :          0 :         const String&   GetFavoritesPath() { return GetPath( SvtPathOptions::PATH_FAVORITES ); }
     135                 :          0 :         const String&   GetFilterPath() { return GetPath( SvtPathOptions::PATH_FILTER ); }
     136                 :          0 :         const String&   GetGalleryPath() { return GetPath( SvtPathOptions::PATH_GALLERY ); }
     137                 :          0 :         const String&   GetGraphicPath() { return GetPath( SvtPathOptions::PATH_GRAPHIC ); }
     138                 :         62 :         const String&   GetHelpPath() { return GetPath( SvtPathOptions::PATH_HELP ); }
     139                 :          0 :         const String&   GetLinguisticPath() { return GetPath( SvtPathOptions::PATH_LINGUISTIC ); }
     140                 :          0 :         const String&   GetModulePath() { return GetPath( SvtPathOptions::PATH_MODULE ); }
     141                 :       2062 :         const String&   GetPalettePath() { return GetPath( SvtPathOptions::PATH_PALETTE ); }
     142                 :          0 :         const String&   GetPluginPath() { return GetPath( SvtPathOptions::PATH_PLUGIN ); }
     143                 :          0 :         const String&   GetStoragePath() { return GetPath( SvtPathOptions::PATH_STORAGE ); }
     144                 :        158 :         const String&   GetTempPath() { return GetPath( SvtPathOptions::PATH_TEMP ); }
     145                 :          6 :         const String&   GetTemplatePath() { return GetPath( SvtPathOptions::PATH_TEMPLATE ); }
     146                 :        236 :         const String&   GetUserConfigPath() { return GetPath( SvtPathOptions::PATH_USERCONFIG ); }
     147                 :        131 :         const String&   GetWorkPath() { return GetPath( SvtPathOptions::PATH_WORK ); }
     148                 :          0 :         const String&   GetUIConfigPath() { return GetPath( SvtPathOptions::PATH_UICONFIG ); }
     149                 :          0 :         const String&   GetFingerprintPath() { return GetPath( SvtPathOptions::PATH_FINGERPRINT ); }
     150                 :            : 
     151                 :            :         // set the paths
     152                 :            :         void            SetPath( SvtPathOptions::Paths, const String& rNewPath );
     153                 :          0 :         void            SetAddinPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_ADDIN, rPath ); }
     154                 :          0 :         void            SetAutoCorrectPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_AUTOCORRECT, rPath ); }
     155                 :          0 :         void            SetAutoTextPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_AUTOTEXT, rPath ); }
     156                 :          0 :         void            SetBackupPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_BACKUP, rPath ); }
     157                 :          0 :         void            SetBasicPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_BASIC, rPath ); }
     158                 :          0 :         void            SetBitmapPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_BITMAP, rPath ); }
     159                 :          0 :         void            SetConfigPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_CONFIG, rPath ); }
     160                 :          0 :         void            SetDictionaryPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_DICTIONARY, rPath ); }
     161                 :          0 :         void            SetFavoritesPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_FAVORITES, rPath ); }
     162                 :          0 :         void            SetFilterPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_FILTER, rPath ); }
     163                 :          0 :         void            SetGalleryPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_GALLERY, rPath ); }
     164                 :          0 :         void            SetGraphicPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_GRAPHIC, rPath ); }
     165                 :          0 :         void            SetHelpPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_HELP, rPath ); }
     166                 :          0 :         void            SetLinguisticPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_LINGUISTIC, rPath ); }
     167                 :          0 :         void            SetModulePath( const String& rPath ) { SetPath( SvtPathOptions::PATH_MODULE, rPath ); }
     168                 :          0 :         void            SetPalettePath( const String& rPath ) { SetPath( SvtPathOptions::PATH_PALETTE, rPath ); }
     169                 :          0 :         void            SetPluginPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_PLUGIN, rPath ); }
     170                 :          0 :         void            SetStoragePath( const String& rPath ) { SetPath( SvtPathOptions::PATH_STORAGE, rPath ); }
     171                 :          0 :         void            SetTempPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_TEMP, rPath ); }
     172                 :          2 :         void            SetTemplatePath( const String& rPath ) { SetPath( SvtPathOptions::PATH_TEMPLATE, rPath ); }
     173                 :          0 :         void            SetUserConfigPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_USERCONFIG, rPath ); }
     174                 :          0 :         void            SetWorkPath( const String& rPath ) { SetPath( SvtPathOptions::PATH_WORK, rPath ); }
     175                 :            : 
     176                 :            :         rtl::OUString   SubstVar( const rtl::OUString& rVar ) const;
     177                 :            :         rtl::OUString   ExpandMacros( const rtl::OUString& rPath ) const;
     178                 :            :         rtl::OUString   UsePathVariables( const rtl::OUString& rPath ) const;
     179                 :            : 
     180                 :          0 :         ::com::sun::star::lang::Locale  GetLocale() const { return m_aLocale; }
     181                 :            : };
     182                 :            : 
     183                 :            : // global ----------------------------------------------------------------
     184                 :            : 
     185                 :            : static SvtPathOptions_Impl* pOptions = NULL;
     186                 :            : static sal_Int32 nRefCount = 0;
     187                 :            : 
     188                 :            : // functions -------------------------------------------------------------
     189                 :            : struct PropertyStruct
     190                 :            : {
     191                 :            :     const char*             pPropName;  // The ascii name of the Office path
     192                 :            :     SvtPathOptions::Paths   ePath;      // The enum value used by SvtPathOptions
     193                 :            : };
     194                 :            : 
     195                 :            : struct VarNameAttribute
     196                 :            : {
     197                 :            :     const char*             pVarName;       // The name of the path variable
     198                 :            :     VarNameProperty         eVarProperty;   // Which return value is needed by this path variable
     199                 :            : };
     200                 :            : 
     201                 :            : static PropertyStruct aPropNames[] =
     202                 :            : {
     203                 :            :     { "Addin",          SvtPathOptions::PATH_ADDIN          },
     204                 :            :     { "AutoCorrect",    SvtPathOptions::PATH_AUTOCORRECT    },
     205                 :            :     { "AutoText",       SvtPathOptions::PATH_AUTOTEXT       },
     206                 :            :     { "Backup",         SvtPathOptions::PATH_BACKUP         },
     207                 :            :     { "Basic",          SvtPathOptions::PATH_BASIC          },
     208                 :            :     { "Bitmap",         SvtPathOptions::PATH_BITMAP         },
     209                 :            :     { "Config",         SvtPathOptions::PATH_CONFIG         },
     210                 :            :     { "Dictionary",     SvtPathOptions::PATH_DICTIONARY     },
     211                 :            :     { "Favorite",       SvtPathOptions::PATH_FAVORITES      },
     212                 :            :     { "Filter",         SvtPathOptions::PATH_FILTER         },
     213                 :            :     { "Gallery",        SvtPathOptions::PATH_GALLERY        },
     214                 :            :     { "Graphic",        SvtPathOptions::PATH_GRAPHIC        },
     215                 :            :     { "Help",           SvtPathOptions::PATH_HELP           },
     216                 :            :     { "Linguistic",     SvtPathOptions::PATH_LINGUISTIC     },
     217                 :            :     { "Module",         SvtPathOptions::PATH_MODULE         },
     218                 :            :     { "Palette",        SvtPathOptions::PATH_PALETTE        },
     219                 :            :     { "Plugin",         SvtPathOptions::PATH_PLUGIN         },
     220                 :            :     { "Storage",        SvtPathOptions::PATH_STORAGE        },
     221                 :            :     { "Temp",           SvtPathOptions::PATH_TEMP           },
     222                 :            :     { "Template",       SvtPathOptions::PATH_TEMPLATE       },
     223                 :            :     { "UserConfig",     SvtPathOptions::PATH_USERCONFIG     },
     224                 :            :     { "Work",           SvtPathOptions::PATH_WORK           },
     225                 :            :     { "UIConfig",       SvtPathOptions::PATH_UICONFIG       },
     226                 :            :     { "Fingerprint",    SvtPathOptions::PATH_FINGERPRINT    }
     227                 :            : };
     228                 :            : 
     229                 :            : static VarNameAttribute aVarNameAttribute[] =
     230                 :            : {
     231                 :            :     { SUBSTITUTE_INSTPATH,  VAR_NEEDS_SYSTEM_PATH },    // $(instpath)
     232                 :            :     { SUBSTITUTE_PROGPATH,  VAR_NEEDS_SYSTEM_PATH },    // $(progpath)
     233                 :            :     { SUBSTITUTE_USERPATH,  VAR_NEEDS_SYSTEM_PATH },    // $(userpath)
     234                 :            :     { SUBSTITUTE_PATH,      VAR_NEEDS_SYSTEM_PATH },    // $(path)
     235                 :            : };
     236                 :            : 
     237                 :            : // class SvtPathOptions_Impl ---------------------------------------------
     238                 :            : 
     239                 :       5053 : const String& SvtPathOptions_Impl::GetPath( SvtPathOptions::Paths ePath )
     240                 :            : {
     241         [ -  + ]:       5053 :     if ( ePath >= SvtPathOptions::PATH_COUNT )
     242                 :          0 :         return m_aEmptyString;
     243                 :            : 
     244         [ +  - ]:       5053 :     ::osl::MutexGuard aGuard( m_aMutex );
     245                 :            : 
     246                 :            :     try
     247                 :            :     {
     248                 :       5053 :         OUString    aPathValue;
     249                 :       5053 :         OUString    aResult;
     250         [ +  - ]:       5053 :         sal_Int32   nHandle = m_aMapEnumToPropHandle[ (sal_Int32)ePath ];
     251                 :            : 
     252                 :            :         // Substitution is done by the service itself using the substition service
     253 [ +  - ][ +  - ]:       5053 :         Any         a = m_xPathSettings->getFastPropertyValue( nHandle );
     254                 :       5053 :         a >>= aPathValue;
     255 [ +  - ][ +  + ]:       5053 :         if( ePath == SvtPathOptions::PATH_ADDIN     ||
         [ +  - ][ +  - ]
         [ -  + ][ +  + ]
     256                 :            :             ePath == SvtPathOptions::PATH_FILTER    ||
     257                 :            :             ePath == SvtPathOptions::PATH_HELP      ||
     258                 :            :             ePath == SvtPathOptions::PATH_MODULE    ||
     259                 :            :             ePath == SvtPathOptions::PATH_PLUGIN    ||
     260                 :            :             ePath == SvtPathOptions::PATH_STORAGE
     261                 :            :           )
     262                 :            :         {
     263                 :            :             // These office paths have to be converted to system pates
     264         [ +  - ]:        215 :             utl::LocalFileHelper::ConvertURLToPhysicalName( aPathValue, aResult );
     265                 :        215 :             aPathValue = aResult;
     266                 :            :         }
     267                 :            : 
     268 [ +  - ][ +  - ]:       5053 :         m_aPathArray[ ePath ] = aPathValue;
     269 [ +  - ][ #  # ]:       5053 :         return m_aPathArray[ ePath ];
     270                 :            :     }
     271         [ #  # ]:          0 :     catch (UnknownPropertyException &)
     272                 :            :     {
     273                 :            :     }
     274                 :            : 
     275         [ +  - ]:       5053 :     return m_aEmptyString;
     276                 :            : }
     277                 :            : 
     278                 :          2 : void SvtPathOptions_Impl::SetPath( SvtPathOptions::Paths ePath, const String& rNewPath )
     279                 :            : {
     280         [ +  - ]:          2 :     ::osl::MutexGuard aGuard( m_aMutex );
     281                 :            : 
     282         [ +  - ]:          2 :     if ( ePath < SvtPathOptions::PATH_COUNT )
     283                 :            :     {
     284                 :          2 :         OUString    aResult;
     285                 :          2 :         OUString    aNewValue;
     286                 :          2 :         Any         a;
     287                 :            : 
     288         [ -  + ]:          2 :         switch ( ePath )
     289                 :            :         {
     290                 :            :             case SvtPathOptions::PATH_ADDIN:
     291                 :            :             case SvtPathOptions::PATH_FILTER:
     292                 :            :             case SvtPathOptions::PATH_HELP:
     293                 :            :             case SvtPathOptions::PATH_MODULE:
     294                 :            :             case SvtPathOptions::PATH_PLUGIN:
     295                 :            :             case SvtPathOptions::PATH_STORAGE:
     296                 :            :             {
     297                 :            :                 // These office paths have to be convert back to UCB-URL's
     298 [ #  # ][ #  # ]:          0 :                 utl::LocalFileHelper::ConvertPhysicalNameToURL( rNewPath, aResult );
     299                 :          0 :                 aNewValue = aResult;
     300                 :            :             }
     301                 :          0 :             break;
     302                 :            : 
     303                 :            :             default:
     304         [ +  - ]:          2 :                 aNewValue = rNewPath;
     305                 :            :         }
     306                 :            : 
     307                 :            :         // Resubstitution is done by the service itself using the substition service
     308         [ +  - ]:          2 :         a <<= aNewValue;
     309                 :            :         try
     310                 :            :         {
     311 [ +  - ][ +  - ]:          2 :             m_xPathSettings->setFastPropertyValue( m_aMapEnumToPropHandle[ (sal_Int32)ePath], a );
         [ -  + ][ -  + ]
     312                 :            :         }
     313         [ +  - ]:          2 :         catch (const Exception&)
     314                 :            :         {
     315                 :          2 :         }
     316         [ +  - ]:          2 :     }
     317                 :          2 : }
     318                 :            : 
     319                 :            : //-------------------------------------------------------------------------
     320                 :            : 
     321                 :          0 : OUString SvtPathOptions_Impl::ExpandMacros( const rtl::OUString& rPath ) const
     322                 :            : {
     323                 :          0 :     ::rtl::OUString sExpanded( rPath );
     324                 :            : 
     325         [ #  # ]:          0 :     const INetURLObject aParser( rPath );
     326         [ #  # ]:          0 :     if ( aParser.GetProtocol() == INET_PROT_VND_SUN_STAR_EXPAND )
     327 [ #  # ][ #  # ]:          0 :         sExpanded = m_xMacroExpander->expandMacros( aParser.GetURLPath( INetURLObject::DECODE_WITH_CHARSET ) );
                 [ #  # ]
     328                 :            : 
     329         [ #  # ]:          0 :     return sExpanded;
     330                 :            : }
     331                 :            : 
     332                 :            : //-------------------------------------------------------------------------
     333                 :            : 
     334                 :          0 : OUString SvtPathOptions_Impl::UsePathVariables( const OUString& rPath ) const
     335                 :            : {
     336                 :          0 :     return m_xSubstVariables->reSubstituteVariables( rPath );
     337                 :            : }
     338                 :            : 
     339                 :            : // -----------------------------------------------------------------------
     340                 :            : 
     341                 :        670 : OUString SvtPathOptions_Impl::SubstVar( const OUString& rVar ) const
     342                 :            : {
     343                 :            :     // Don't work at parameter-string directly. Copy it.
     344                 :        670 :     OUString aWorkText = rVar;
     345                 :            : 
     346                 :            :     // Convert the returned path to system path!
     347                 :        670 :     sal_Bool bConvertLocal = sal_False;
     348                 :            : 
     349                 :            :     // Search for first occure of "$(...".
     350                 :        670 :     sal_Int32 nPosition = aWorkText.indexOf( SIGN_STARTVARIABLE );  // = first position of "$(" in string
     351                 :        670 :     sal_Int32 nLength   = 0;                                        // = count of letters from "$(" to ")" in string
     352                 :            : 
     353                 :            :     // Have we found any variable like "$(...)"?
     354         [ +  + ]:        670 :     if ( nPosition != STRPOS_NOTFOUND )
     355                 :            :     {
     356                 :            :         // Yes; Get length of found variable.
     357                 :            :         // If no ")" was found - nLength is set to 0 by default! see before.
     358                 :        214 :         sal_Int32 nEndPosition = aWorkText.indexOf( SIGN_ENDVARIABLE, nPosition );
     359         [ +  - ]:        214 :         if ( nEndPosition != STRPOS_NOTFOUND )
     360                 :        214 :             nLength = nEndPosition - nPosition + 1;
     361                 :            :     }
     362                 :            : 
     363                 :            :     // Is there another path variable?
     364 [ +  + ][ +  - ]:        884 :     while ( ( nPosition != STRPOS_NOTFOUND ) && ( nLength > 0 ) )
                 [ +  + ]
     365                 :            :     {
     366                 :            :         // YES; Get the next variable for replace.
     367                 :        214 :         OUString aSubString = aWorkText.copy( nPosition, nLength );
     368                 :        214 :         aSubString = aSubString.toAsciiLowerCase();
     369                 :            : 
     370                 :            :         // Look for special variable that needs a system path.
     371         [ +  - ]:        214 :         VarNameToEnumMap::const_iterator pIter = m_aMapVarNamesToEnum.find( aSubString );
     372 [ +  - ][ +  + ]:        214 :         if ( pIter != m_aMapVarNamesToEnum.end() )
     373                 :          8 :             bConvertLocal = sal_True;
     374                 :            : 
     375                 :        214 :         nPosition += nLength;
     376                 :            : 
     377                 :            :         // We must control index in string before call something at OUString!
     378                 :            :         // The OUString-implementation don't do it for us :-( but the result is not defined otherwise.
     379         [ +  + ]:        214 :         if ( nPosition + 1 > aWorkText.getLength() )
     380                 :            :         {
     381                 :            :             // Position is out of range. Break loop!
     382                 :        122 :             nPosition = STRPOS_NOTFOUND;
     383                 :        122 :             nLength = 0;
     384                 :            :         }
     385                 :            :         else
     386                 :            :         {
     387                 :            :             // Else; Position is valid. Search for next variable.
     388                 :         92 :             nPosition = aWorkText.indexOf( SIGN_STARTVARIABLE, nPosition );
     389                 :            :             // Have we found any variable like "$(...)"?
     390         [ -  + ]:         92 :             if ( nPosition != STRPOS_NOTFOUND )
     391                 :            :             {
     392                 :            :                 // Yes; Get length of found variable. If no ")" was found - nLength must set to 0!
     393                 :          0 :                 nLength = 0;
     394                 :          0 :                 sal_Int32 nEndPosition = aWorkText.indexOf( SIGN_ENDVARIABLE, nPosition );
     395         [ #  # ]:          0 :                 if ( nEndPosition != STRPOS_NOTFOUND )
     396                 :          0 :                     nLength = nEndPosition - nPosition + 1;
     397                 :            :             }
     398                 :            :         }
     399                 :        214 :     }
     400                 :            : 
     401 [ +  - ][ +  - ]:        670 :     aWorkText = m_xSubstVariables->substituteVariables( rVar, sal_False );
     402                 :            : 
     403         [ +  + ]:        670 :     if ( bConvertLocal )
     404                 :            :     {
     405                 :            :         // Convert the URL to a system path for special path variables
     406                 :          8 :         rtl::OUString aReturn;
     407         [ +  - ]:          8 :         utl::LocalFileHelper::ConvertURLToPhysicalName( aWorkText, aReturn );
     408                 :          8 :         return aReturn;
     409                 :            :     }
     410                 :            : 
     411                 :        670 :     return aWorkText;
     412                 :            : }
     413                 :            : 
     414                 :            : // -----------------------------------------------------------------------
     415                 :            : 
     416                 :        233 : SvtPathOptions_Impl::SvtPathOptions_Impl() :
     417 [ +  - ][ +  - ]:        233 :     m_aPathArray( (sal_Int32)SvtPathOptions::PATH_COUNT )
         [ +  - ][ +  - ]
     418                 :            : {
     419         [ +  - ]:        233 :     Reference< XMultiServiceFactory > xSMgr = comphelper::getProcessServiceFactory();
     420                 :            : 
     421                 :            :     // Create necessary services
     422         [ +  - ]:        233 :     m_xPathSettings = Reference< XFastPropertySet >( xSMgr->createInstance(
     423                 :        233 :                                                     ::rtl::OUString( "com.sun.star.util.PathSettings" )),
     424 [ +  - ][ +  - ]:        233 :                                                 UNO_QUERY );
                 [ +  - ]
     425         [ -  + ]:        233 :     if ( !m_xPathSettings.is() )
     426                 :            :     {
     427                 :            :         // #112719#: check for existance
     428                 :            :         OSL_FAIL( "SvtPathOptions_Impl::SvtPathOptions_Impl(): #112719# happened again!" );
     429                 :            :         throw RuntimeException(
     430                 :            :             ::rtl::OUString( "Service com.sun.star.util.PathSettings cannot be created" ),
     431         [ #  # ]:          0 :             Reference< XInterface >() );
     432                 :            :     }
     433                 :            : 
     434         [ +  - ]:        233 :     ::comphelper::ComponentContext aContext( xSMgr );
     435 [ +  - ][ +  - ]:        233 :     m_xSubstVariables.set( PathSubstitution::create(aContext.getUNOContext()) );
                 [ +  - ]
     436 [ +  - ][ +  - ]:        233 :     m_xMacroExpander.set( aContext.getSingleton( "com.sun.star.util.theMacroExpander" ), UNO_QUERY_THROW );
     437                 :            : 
     438                 :            :     // Create temporary hash map to have a mapping between property names and property handles
     439         [ +  - ]:        233 :     Reference< XPropertySet > xPropertySet = Reference< XPropertySet >( m_xPathSettings, UNO_QUERY );
     440 [ +  - ][ +  - ]:        233 :     Reference< XPropertySetInfo > xPropSetInfo = xPropertySet->getPropertySetInfo();
     441 [ +  - ][ +  - ]:        233 :     Sequence< Property > aPathPropSeq = xPropSetInfo->getProperties();
     442                 :            : 
     443         [ +  - ]:        233 :     NameToHandleMap aTempHashMap;
     444         [ +  + ]:      22601 :     for ( sal_Int32 n = 0; n < aPathPropSeq.getLength(); n++ )
     445                 :            :     {
     446         [ +  - ]:      22368 :         const com::sun::star::beans::Property& aProperty = aPathPropSeq[n];
     447         [ +  - ]:      22368 :         aTempHashMap.insert( NameToHandleMap::value_type( aProperty.Name, aProperty.Handle ));
     448                 :            :     }
     449                 :            : 
     450                 :            :     // Create mapping between internal enum (SvtPathOptions::Paths) and property handle
     451                 :        233 :     sal_Int32 nCount = sizeof( aPropNames ) / sizeof( PropertyStruct );
     452                 :            :     sal_Int32 i;
     453         [ +  + ]:       5825 :     for ( i = 0; i < nCount; i++ )
     454                 :            :     {
     455                 :            :         NameToHandleMap::const_iterator pIter =
     456         [ +  - ]:       5592 :             aTempHashMap.find( rtl::OUString::createFromAscii( aPropNames[i].pPropName ));
     457                 :            : 
     458 [ +  - ][ +  - ]:       5592 :         if ( pIter != aTempHashMap.end() )
     459                 :            :         {
     460         [ +  - ]:       5592 :             sal_Int32 nHandle   = pIter->second;
     461                 :       5592 :             sal_Int32 nEnum     = aPropNames[i].ePath;
     462 [ +  - ][ +  - ]:       5592 :             m_aMapEnumToPropHandle.insert( EnumToHandleMap::value_type( nEnum, nHandle ));
     463                 :            :         }
     464                 :            :     }
     465                 :            : 
     466                 :            :     // Create hash map for path variables that need a system path as a return value!
     467                 :        233 :     nCount = sizeof( aVarNameAttribute ) / sizeof( VarNameAttribute );
     468         [ +  + ]:       1165 :     for ( i = 0; i < nCount; i++ )
     469                 :            :     {
     470                 :            :         m_aMapVarNamesToEnum.insert( VarNameToEnumMap::value_type(
     471                 :            :                 OUString::createFromAscii( aVarNameAttribute[i].pVarName ),
     472         [ +  - ]:        932 :                 aVarNameAttribute[i].eVarProperty ));
     473                 :            :     }
     474                 :            : 
     475                 :            :     // Set language type!
     476         [ +  - ]:        233 :     OUString aLocaleStr( ConfigManager::getLocale() );
     477                 :        233 :     sal_Int32 nIndex = 0;
     478                 :        233 :     m_aLocale.Language = aLocaleStr.getToken(0, '-', nIndex );
     479                 :        233 :     m_aLocale.Country = aLocaleStr.getToken(0, '-', nIndex );
     480 [ +  - ][ +  - ]:        233 :     m_aLocale.Variant = aLocaleStr.getToken(0, '-', nIndex );
                 [ +  - ]
     481                 :        233 : }
     482                 :            : 
     483                 :            : // -----------------------------------------------------------------------
     484                 :            : 
     485                 :            : // class SvtPathOptions --------------------------------------------------
     486                 :            : 
     487                 :            : namespace { struct lclMutex : public rtl::Static< ::osl::Mutex, lclMutex > {}; }
     488                 :            : 
     489                 :       6234 : SvtPathOptions::SvtPathOptions()
     490                 :            : {
     491                 :            :     // Global access, must be guarded (multithreading)
     492 [ +  - ][ +  - ]:       6234 :     ::osl::MutexGuard aGuard( lclMutex::get() );
     493         [ +  + ]:       6234 :     if ( !pOptions )
     494                 :            :     {
     495 [ +  - ][ +  - ]:        233 :         pOptions = new SvtPathOptions_Impl;
     496         [ +  - ]:        233 :         ItemHolder1::holdConfigItem(E_PATHOPTIONS);
     497                 :            :     }
     498                 :       6234 :     ++nRefCount;
     499         [ +  - ]:       6234 :     pImp = pOptions;
     500                 :       6234 : }
     501                 :            : 
     502                 :            : // -----------------------------------------------------------------------
     503                 :            : 
     504                 :       6234 : SvtPathOptions::~SvtPathOptions()
     505                 :            : {
     506                 :            :     // Global access, must be guarded (multithreading)
     507 [ +  - ][ +  - ]:       6234 :     ::osl::MutexGuard aGuard( lclMutex::get() );
     508         [ +  + ]:       6234 :     if ( !--nRefCount )
     509                 :            :     {
     510 [ +  - ][ +  - ]:        233 :         DELETEZ( pOptions );
     511         [ +  - ]:       6234 :     }
     512         [ -  + ]:       6625 : }
     513                 :            : 
     514                 :            : // -----------------------------------------------------------------------
     515                 :            : 
     516                 :        153 : const String& SvtPathOptions::GetAddinPath() const
     517                 :            : {
     518                 :        153 :     return pImp->GetAddinPath();
     519                 :            : }
     520                 :            : 
     521                 :            : // -----------------------------------------------------------------------
     522                 :            : 
     523                 :         73 : const String& SvtPathOptions::GetAutoCorrectPath() const
     524                 :            : {
     525                 :         73 :     return pImp->GetAutoCorrectPath();
     526                 :            : }
     527                 :            : 
     528                 :            : // -----------------------------------------------------------------------
     529                 :            : 
     530                 :          2 : const String& SvtPathOptions::GetAutoTextPath() const
     531                 :            : {
     532                 :          2 :     return pImp->GetAutoTextPath();
     533                 :            : }
     534                 :            : 
     535                 :            : // -----------------------------------------------------------------------
     536                 :            : 
     537                 :        154 : const String& SvtPathOptions::GetBackupPath() const
     538                 :            : {
     539                 :        154 :     return pImp->GetBackupPath();
     540                 :            : }
     541                 :            : 
     542                 :            : // -----------------------------------------------------------------------
     543                 :            : 
     544                 :       1786 : const String& SvtPathOptions::GetBasicPath() const
     545                 :            : {
     546                 :       1786 :     return pImp->GetBasicPath();
     547                 :            : }
     548                 :            : 
     549                 :            : // -----------------------------------------------------------------------
     550                 :            : 
     551                 :          0 : const String& SvtPathOptions::GetBitmapPath() const
     552                 :            : {
     553                 :          0 :     return pImp->GetBitmapPath();
     554                 :            : }
     555                 :            : 
     556                 :            : // -----------------------------------------------------------------------
     557                 :            : 
     558                 :        230 : const String& SvtPathOptions::GetConfigPath() const
     559                 :            : {
     560                 :        230 :     return pImp->GetConfigPath();
     561                 :            : }
     562                 :            : 
     563                 :            : // -----------------------------------------------------------------------
     564                 :            : 
     565                 :          0 : const String& SvtPathOptions::GetDictionaryPath() const
     566                 :            : {
     567                 :          0 :     return pImp->GetDictionaryPath();
     568                 :            : }
     569                 :            : 
     570                 :            : // -----------------------------------------------------------------------
     571                 :            : 
     572                 :          0 : const String& SvtPathOptions::GetFavoritesPath() const
     573                 :            : {
     574                 :          0 :     return pImp->GetFavoritesPath();
     575                 :            : }
     576                 :            : 
     577                 :            : // -----------------------------------------------------------------------
     578                 :            : 
     579                 :          0 : const String& SvtPathOptions::GetFilterPath() const
     580                 :            : {
     581                 :          0 :     return pImp->GetFilterPath();
     582                 :            : }
     583                 :            : 
     584                 :            : // -----------------------------------------------------------------------
     585                 :            : 
     586                 :          0 : const String& SvtPathOptions::GetGalleryPath() const
     587                 :            : {
     588                 :          0 :     return pImp->GetGalleryPath();
     589                 :            : }
     590                 :            : 
     591                 :            : // -----------------------------------------------------------------------
     592                 :            : 
     593                 :          0 : const String& SvtPathOptions::GetGraphicPath() const
     594                 :            : {
     595                 :          0 :     return pImp->GetGraphicPath();
     596                 :            : }
     597                 :            : 
     598                 :            : // -----------------------------------------------------------------------
     599                 :            : 
     600                 :         62 : const String& SvtPathOptions::GetHelpPath() const
     601                 :            : {
     602                 :         62 :     return pImp->GetHelpPath();
     603                 :            : }
     604                 :            : 
     605                 :            : // -----------------------------------------------------------------------
     606                 :            : 
     607                 :          0 : const String& SvtPathOptions::GetLinguisticPath() const
     608                 :            : {
     609                 :          0 :     return pImp->GetLinguisticPath();
     610                 :            : }
     611                 :            : 
     612                 :            : // -----------------------------------------------------------------------
     613                 :            : 
     614                 :          0 : const String& SvtPathOptions::GetFingerprintPath() const
     615                 :            : {
     616                 :          0 :     return pImp->GetFingerprintPath();
     617                 :            : }
     618                 :            : 
     619                 :            : // -----------------------------------------------------------------------
     620                 :            : 
     621                 :          0 : const String& SvtPathOptions::GetModulePath() const
     622                 :            : {
     623                 :          0 :     return pImp->GetModulePath();
     624                 :            : }
     625                 :            : 
     626                 :            : // -----------------------------------------------------------------------
     627                 :            : 
     628                 :       2062 : const String& SvtPathOptions::GetPalettePath() const
     629                 :            : {
     630                 :       2062 :     return pImp->GetPalettePath();
     631                 :            : }
     632                 :            : 
     633                 :            : // -----------------------------------------------------------------------
     634                 :            : 
     635                 :          0 : const String& SvtPathOptions::GetPluginPath() const
     636                 :            : {
     637                 :          0 :     return pImp->GetPluginPath();
     638                 :            : }
     639                 :            : 
     640                 :            : // -----------------------------------------------------------------------
     641                 :            : 
     642                 :          0 : const String& SvtPathOptions::GetStoragePath() const
     643                 :            : {
     644                 :          0 :     return pImp->GetStoragePath();
     645                 :            : }
     646                 :            : 
     647                 :            : // -----------------------------------------------------------------------
     648                 :            : 
     649                 :        158 : const String& SvtPathOptions::GetTempPath() const
     650                 :            : {
     651                 :        158 :     return pImp->GetTempPath();
     652                 :            : }
     653                 :            : 
     654                 :            : // -----------------------------------------------------------------------
     655                 :            : 
     656                 :          6 : const String& SvtPathOptions::GetTemplatePath() const
     657                 :            : {
     658                 :          6 :     return pImp->GetTemplatePath();
     659                 :            : }
     660                 :            : 
     661                 :            : // -----------------------------------------------------------------------
     662                 :            : 
     663                 :        236 : const String& SvtPathOptions::GetUserConfigPath() const
     664                 :            : {
     665                 :        236 :     return pImp->GetUserConfigPath();
     666                 :            : }
     667                 :            : 
     668                 :          0 : const String& SvtPathOptions::GetUIConfigPath() const
     669                 :            : {
     670                 :          0 :     return pImp->GetUIConfigPath();
     671                 :            : }
     672                 :            : 
     673                 :            : // -----------------------------------------------------------------------
     674                 :            : 
     675                 :        131 : const String& SvtPathOptions::GetWorkPath() const
     676                 :            : {
     677                 :        131 :     return pImp->GetWorkPath();
     678                 :            : }
     679                 :            : 
     680                 :            : // -----------------------------------------------------------------------
     681                 :            : 
     682                 :          0 : void SvtPathOptions::SetAddinPath( const String& rPath )
     683                 :            : {
     684                 :          0 :     pImp->SetAddinPath( rPath );
     685                 :          0 : }
     686                 :            : 
     687                 :            : // -----------------------------------------------------------------------
     688                 :            : 
     689                 :          0 : void SvtPathOptions::SetAutoCorrectPath( const String& rPath )
     690                 :            : {
     691                 :          0 :     pImp->SetAutoCorrectPath( rPath );
     692                 :          0 : }
     693                 :            : 
     694                 :            : // -----------------------------------------------------------------------
     695                 :            : 
     696                 :          0 : void SvtPathOptions::SetAutoTextPath( const String& rPath )
     697                 :            : {
     698                 :          0 :     pImp->SetAutoTextPath( rPath );
     699                 :          0 : }
     700                 :            : 
     701                 :            : // -----------------------------------------------------------------------
     702                 :            : 
     703                 :          0 : void SvtPathOptions::SetBackupPath( const String& rPath )
     704                 :            : {
     705                 :          0 :     pImp->SetBackupPath( rPath );
     706                 :          0 : }
     707                 :            : 
     708                 :            : // -----------------------------------------------------------------------
     709                 :            : 
     710                 :          0 : void SvtPathOptions::SetBasicPath( const String& rPath )
     711                 :            : {
     712                 :          0 :     pImp->SetBasicPath( rPath );
     713                 :          0 : }
     714                 :            : 
     715                 :            : // -----------------------------------------------------------------------
     716                 :            : 
     717                 :          0 : void SvtPathOptions::SetBitmapPath( const String& rPath )
     718                 :            : {
     719                 :          0 :     pImp->SetBitmapPath( rPath );
     720                 :          0 : }
     721                 :            : 
     722                 :            : // -----------------------------------------------------------------------
     723                 :            : 
     724                 :          0 : void SvtPathOptions::SetConfigPath( const String& rPath )
     725                 :            : {
     726                 :          0 :     pImp->SetConfigPath( rPath );
     727                 :          0 : }
     728                 :            : 
     729                 :            : // -----------------------------------------------------------------------
     730                 :            : 
     731                 :          0 : void SvtPathOptions::SetDictionaryPath( const String& rPath )
     732                 :            : {
     733                 :          0 :     pImp->SetDictionaryPath( rPath );
     734                 :          0 : }
     735                 :            : 
     736                 :            : // -----------------------------------------------------------------------
     737                 :            : 
     738                 :          0 : void SvtPathOptions::SetFavoritesPath( const String& rPath )
     739                 :            : {
     740                 :          0 :     pImp->SetFavoritesPath( rPath );
     741                 :          0 : }
     742                 :            : 
     743                 :            : // -----------------------------------------------------------------------
     744                 :            : 
     745                 :          0 : void SvtPathOptions::SetFilterPath( const String& rPath )
     746                 :            : {
     747                 :          0 :     pImp->SetFilterPath( rPath );
     748                 :          0 : }
     749                 :            : 
     750                 :            : // -----------------------------------------------------------------------
     751                 :            : 
     752                 :          0 : void SvtPathOptions::SetGalleryPath( const String& rPath )
     753                 :            : {
     754                 :          0 :     pImp->SetGalleryPath( rPath );
     755                 :          0 : }
     756                 :            : 
     757                 :            : // -----------------------------------------------------------------------
     758                 :            : 
     759                 :          0 : void SvtPathOptions::SetGraphicPath( const String& rPath )
     760                 :            : {
     761                 :          0 :     pImp->SetGraphicPath( rPath );
     762                 :          0 : }
     763                 :            : 
     764                 :            : // -----------------------------------------------------------------------
     765                 :            : 
     766                 :          0 : void SvtPathOptions::SetHelpPath( const String& rPath )
     767                 :            : {
     768                 :          0 :     pImp->SetHelpPath( rPath );
     769                 :          0 : }
     770                 :            : 
     771                 :            : // -----------------------------------------------------------------------
     772                 :            : 
     773                 :          0 : void SvtPathOptions::SetLinguisticPath( const String& rPath )
     774                 :            : {
     775                 :          0 :     pImp->SetLinguisticPath( rPath );
     776                 :          0 : }
     777                 :            : 
     778                 :            : // -----------------------------------------------------------------------
     779                 :            : 
     780                 :          0 : void SvtPathOptions::SetModulePath( const String& rPath )
     781                 :            : {
     782                 :          0 :     pImp->SetModulePath( rPath );
     783                 :          0 : }
     784                 :            : 
     785                 :            : // -----------------------------------------------------------------------
     786                 :            : 
     787                 :          0 : void SvtPathOptions::SetPalettePath( const String& rPath )
     788                 :            : {
     789                 :          0 :     pImp->SetPalettePath( rPath );
     790                 :          0 : }
     791                 :            : 
     792                 :            : // -----------------------------------------------------------------------
     793                 :            : 
     794                 :          0 : void SvtPathOptions::SetPluginPath( const String& rPath )
     795                 :            : {
     796                 :          0 :     pImp->SetPluginPath( rPath );
     797                 :          0 : }
     798                 :            : 
     799                 :            : // -----------------------------------------------------------------------
     800                 :            : 
     801                 :          0 : void SvtPathOptions::SetStoragePath( const String& rPath )
     802                 :            : {
     803                 :          0 :     pImp->SetStoragePath( rPath );
     804                 :          0 : }
     805                 :            : 
     806                 :            : // -----------------------------------------------------------------------
     807                 :            : 
     808                 :          0 : void SvtPathOptions::SetTempPath( const String& rPath )
     809                 :            : {
     810                 :          0 :     pImp->SetTempPath( rPath );
     811                 :          0 : }
     812                 :            : 
     813                 :            : // -----------------------------------------------------------------------
     814                 :            : 
     815                 :          2 : void SvtPathOptions::SetTemplatePath( const String& rPath )
     816                 :            : {
     817                 :          2 :     pImp->SetTemplatePath( rPath );
     818                 :          2 : }
     819                 :            : 
     820                 :            : // -----------------------------------------------------------------------
     821                 :            : 
     822                 :          0 : void SvtPathOptions::SetUserConfigPath( const String& rPath )
     823                 :            : {
     824                 :          0 :     pImp->SetUserConfigPath( rPath );
     825                 :          0 : }
     826                 :            : 
     827                 :            : // -----------------------------------------------------------------------
     828                 :            : 
     829                 :          0 : void SvtPathOptions::SetWorkPath( const String& rPath )
     830                 :            : {
     831                 :          0 :     pImp->SetWorkPath( rPath );
     832                 :          0 : }
     833                 :            : 
     834                 :            : // -----------------------------------------------------------------------
     835                 :            : 
     836                 :        666 : String SvtPathOptions::SubstituteVariable( const String& rVar ) const
     837                 :            : {
     838 [ +  - ][ +  - ]:        666 :     String aRet = pImp->SubstVar( rVar );
     839                 :        666 :     return aRet;
     840                 :            : }
     841                 :            : 
     842                 :            : // -----------------------------------------------------------------------
     843                 :            : 
     844                 :          0 : String SvtPathOptions::ExpandMacros( const String& rPath ) const
     845                 :            : {
     846 [ #  # ][ #  # ]:          0 :     return pImp->ExpandMacros( rPath );
     847                 :            : }
     848                 :            : 
     849                 :            : // -----------------------------------------------------------------------
     850                 :            : 
     851                 :          0 : String SvtPathOptions::UseVariable( const String& rPath ) const
     852                 :            : {
     853 [ #  # ][ #  # ]:          0 :     String aRet = pImp->UsePathVariables( rPath );
     854                 :          0 :     return aRet;
     855                 :            : }
     856                 :            : 
     857                 :            : // -----------------------------------------------------------------------
     858                 :            : 
     859                 :          4 : sal_Bool SvtPathOptions::SearchFile( String& rIniFile, Paths ePath )
     860                 :            : {
     861                 :            :     // check parameter: empty inifile name?
     862         [ -  + ]:          4 :     if ( !rIniFile.Len() )
     863                 :            :     {
     864                 :            :         SAL_WARN( "unotools.config", "SvtPathOptions::SearchFile(): invalid parameter" );
     865                 :          0 :         return sal_False;
     866                 :            :     }
     867                 :            : 
     868 [ +  - ][ +  - ]:          4 :     rtl::OUString aIniFile = pImp->SubstVar( rIniFile );
     869                 :          4 :     sal_Bool bRet = sal_False;
     870                 :            : 
     871         [ -  + ]:          4 :     switch ( ePath )
     872                 :            :     {
     873                 :            :         case PATH_USERCONFIG:
     874                 :            :         {
     875                 :            :             // path is a URL
     876                 :          0 :             bRet = sal_True;
     877 [ #  # ][ #  # ]:          0 :             INetURLObject aObj( GetUserConfigPath() );
                 [ #  # ]
     878                 :            : 
     879                 :          0 :             sal_Int32 nIniIndex = 0;
     880         [ #  # ]:          0 :             do
     881                 :            :             {
     882                 :          0 :                 rtl::OUString aToken = aIniFile.getToken( 0, '/', nIniIndex );
     883         [ #  # ]:          0 :                 aObj.insertName(aToken);
     884                 :            :             }
     885                 :            :             while ( nIniIndex >= 0 );
     886                 :            : 
     887 [ #  # ][ #  # ]:          0 :             if ( !::utl::UCBContentHelper::Exists( aObj.GetMainURL( INetURLObject::NO_DECODE ) ) )
                 [ #  # ]
     888                 :            :             {
     889 [ #  # ][ #  # ]:          0 :                 aObj.SetSmartURL( GetConfigPath() );
                 [ #  # ]
     890         [ #  # ]:          0 :                 aObj.insertName( aIniFile );
     891 [ #  # ][ #  # ]:          0 :                 bRet = ::utl::UCBContentHelper::Exists( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
     892                 :            :             }
     893                 :            : 
     894         [ #  # ]:          0 :             if ( bRet )
     895 [ #  # ][ #  # ]:          0 :                 rIniFile = aObj.GetMainURL( INetURLObject::NO_DECODE );
     896                 :            : 
     897         [ #  # ]:          0 :             break;
     898                 :            :         }
     899                 :            : 
     900                 :            :         default:
     901                 :            :         {
     902                 :          4 :             rtl::OUString aPath;
     903   [ -  -  -  -  :          4 :             switch ( ePath )
          -  -  -  -  -  
          -  -  -  -  -  
          -  -  -  -  -  
          +  -  -  -  -  
                   -  - ]
     904                 :            :             {
     905 [ #  # ][ #  # ]:          0 :                 case PATH_ADDIN:        aPath = GetAddinPath();         break;
     906 [ #  # ][ #  # ]:          0 :                 case PATH_AUTOCORRECT:  aPath = GetAutoCorrectPath();   break;
     907 [ #  # ][ #  # ]:          0 :                 case PATH_AUTOTEXT:     aPath = GetAutoTextPath();      break;
     908 [ #  # ][ #  # ]:          0 :                 case PATH_BACKUP:       aPath = GetBackupPath();        break;
     909 [ #  # ][ #  # ]:          0 :                 case PATH_BASIC:        aPath = GetBasicPath();         break;
     910 [ #  # ][ #  # ]:          0 :                 case PATH_BITMAP:       aPath = GetBitmapPath();        break;
     911 [ #  # ][ #  # ]:          0 :                 case PATH_CONFIG:       aPath = GetConfigPath();        break;
     912 [ #  # ][ #  # ]:          0 :                 case PATH_DICTIONARY:   aPath = GetDictionaryPath();    break;
     913 [ #  # ][ #  # ]:          0 :                 case PATH_FAVORITES:    aPath = GetFavoritesPath();     break;
     914 [ #  # ][ #  # ]:          0 :                 case PATH_FILTER:       aPath = GetFilterPath();        break;
     915 [ #  # ][ #  # ]:          0 :                 case PATH_GALLERY:      aPath = GetGalleryPath();       break;
     916 [ #  # ][ #  # ]:          0 :                 case PATH_GRAPHIC:      aPath = GetGraphicPath();       break;
     917 [ #  # ][ #  # ]:          0 :                 case PATH_HELP:         aPath = GetHelpPath();          break;
     918 [ #  # ][ #  # ]:          0 :                 case PATH_LINGUISTIC:   aPath = GetLinguisticPath();    break;
     919 [ #  # ][ #  # ]:          0 :                 case PATH_MODULE:       aPath = GetModulePath();        break;
     920 [ #  # ][ #  # ]:          0 :                 case PATH_PALETTE:      aPath = GetPalettePath();       break;
     921 [ #  # ][ #  # ]:          0 :                 case PATH_PLUGIN:       aPath = GetPluginPath();        break;
     922 [ #  # ][ #  # ]:          0 :                 case PATH_STORAGE:      aPath = GetStoragePath();       break;
     923 [ #  # ][ #  # ]:          0 :                 case PATH_TEMP:         aPath = GetTempPath();          break;
     924 [ +  - ][ +  - ]:          4 :                 case PATH_TEMPLATE:     aPath = GetTemplatePath();      break;
     925 [ #  # ][ #  # ]:          0 :                 case PATH_WORK:         aPath = GetWorkPath();          break;
     926 [ #  # ][ #  # ]:          0 :                 case PATH_UICONFIG:     aPath = GetUIConfigPath();      break;
     927 [ #  # ][ #  # ]:          0 :                 case PATH_FINGERPRINT:  aPath = GetFingerprintPath();   break;
     928                 :          0 :                 case PATH_USERCONFIG:/*-Wall???*/           break;
     929                 :          0 :                 case PATH_COUNT: /*-Wall???*/ break;
     930                 :            :             }
     931                 :            : 
     932                 :          4 :             sal_Int32 nPathIndex = 0;
     933         [ +  + ]:         16 :             do
     934                 :            :             {
     935                 :         16 :                 sal_Bool bIsURL = sal_True;
     936                 :         16 :                 rtl::OUString aPathToken = aPath.getToken( 0, SEARCHPATH_DELIMITER, nPathIndex );
     937         [ +  - ]:         16 :                 INetURLObject aObj( aPathToken );
     938         [ -  + ]:         16 :                 if ( aObj.HasError() )
     939                 :            :                 {
     940                 :          0 :                     bIsURL = sal_False;
     941                 :          0 :                     rtl::OUString aURL;
     942 [ #  # ][ #  # ]:          0 :                     if ( LocalFileHelper::ConvertPhysicalNameToURL( aPathToken, aURL ) )
     943         [ #  # ]:          0 :                         aObj.SetURL( aURL );
     944                 :            :                 }
     945         [ +  + ]:         16 :                 if ( aObj.GetProtocol() == INET_PROT_VND_SUN_STAR_EXPAND )
     946                 :            :                 {
     947 [ +  - ][ +  - ]:          4 :                     ::comphelper::ComponentContext aContext( ::comphelper::getProcessServiceFactory() );
     948 [ +  - ][ +  - ]:          4 :                     Reference< XMacroExpander > xMacroExpander( aContext.getSingleton( "com.sun.star.util.theMacroExpander" ), UNO_QUERY );
     949                 :            :                     OSL_ENSURE( xMacroExpander.is(), "SvtPathOptions::SearchFile: unable to access the MacroExpander singleton!" );
     950         [ +  - ]:          4 :                     if ( xMacroExpander.is() )
     951                 :            :                     {
     952 [ +  - ][ +  - ]:          4 :                         const ::rtl::OUString sExpandedPath = xMacroExpander->expandMacros( aObj.GetURLPath( INetURLObject::DECODE_WITH_CHARSET ) );
                 [ +  - ]
     953         [ +  - ]:          4 :                         aObj.SetURL( sExpandedPath );
     954         [ +  - ]:          4 :                     }
     955                 :            :                 }
     956                 :            : 
     957                 :         16 :                 sal_Int32 nIniIndex = 0;
     958         [ -  + ]:         16 :                 do
     959                 :            :                 {
     960                 :         16 :                     rtl::OUString aToken = aIniFile.getToken( 0, '/', nIniIndex );
     961         [ +  - ]:         16 :                     aObj.insertName(aToken);
     962                 :            :                 }
     963                 :            :                 while ( nIniIndex >= 0 );
     964                 :            : 
     965 [ +  - ][ +  - ]:         16 :                 bRet = ::utl::UCBContentHelper::Exists( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
     966                 :            : 
     967         [ -  + ]:         16 :                 if ( bRet )
     968                 :            :                 {
     969         [ #  # ]:          0 :                     if ( !bIsURL )
     970                 :            :                     {
     971         [ #  # ]:          0 :                         rtl::OUString sTmp(rIniFile);
     972                 :            :                         ::utl::LocalFileHelper::ConvertURLToPhysicalName(
     973 [ #  # ][ #  # ]:          0 :                                             aObj.GetMainURL( INetURLObject::NO_DECODE ), sTmp );
     974         [ #  # ]:          0 :                         rIniFile = sTmp;
     975                 :            :                     }
     976                 :            :                     else
     977 [ #  # ][ #  # ]:         16 :                         rIniFile = aObj.GetMainURL( INetURLObject::NO_DECODE );
     978                 :            :                     break;
     979 [ +  - ][ -  + ]:         16 :                 }
                 [ +  - ]
     980                 :            :             }
     981                 :          4 :             while ( nPathIndex >= 0 );
     982                 :            :         }
     983                 :            :     }
     984                 :            : 
     985                 :          4 :     return bRet;
     986                 :            : }
     987                 :            : 
     988                 :            : // -----------------------------------------------------------------------
     989                 :            : 
     990                 :          0 : ::com::sun::star::lang::Locale SvtPathOptions::GetLocale() const
     991                 :            : {
     992                 :          0 :     return pImp->GetLocale();
     993                 :            : }
     994                 :            : 
     995                 :            : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10