LCOV - code coverage report
Current view: top level - unotools/source/config - pathoptions.cxx (source / functions) Hit Total Coverage
Test: commit e02a6cb2c3e2b23b203b422e4e0680877f232636 Lines: 0 363 0.0 %
Date: 2014-04-14 Functions: 0 108 0.0 %
Legend: Lines: hit not hit

          Line data    Source code
       1             : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
       2             : /*
       3             :  * This file is part of the LibreOffice project.
       4             :  *
       5             :  * This Source Code Form is subject to the terms of the Mozilla Public
       6             :  * License, v. 2.0. If a copy of the MPL was not distributed with this
       7             :  * file, You can obtain one at http://mozilla.org/MPL/2.0/.
       8             :  *
       9             :  * This file incorporates work covered by the following license notice:
      10             :  *
      11             :  *   Licensed to the Apache Software Foundation (ASF) under one or more
      12             :  *   contributor license agreements. See the NOTICE file distributed
      13             :  *   with this work for additional information regarding copyright
      14             :  *   ownership. The ASF licenses this file to you under the Apache
      15             :  *   License, Version 2.0 (the "License"); you may not use this file
      16             :  *   except in compliance with the License. You may obtain a copy of
      17             :  *   the License at http://www.apache.org/licenses/LICENSE-2.0 .
      18             :  */
      19             : 
      20             : #include <unotools/pathoptions.hxx>
      21             : #include <unotools/configitem.hxx>
      22             : #include <unotools/configmgr.hxx>
      23             : #include <tools/urlobj.hxx>
      24             : #include <tools/solar.h>
      25             : #include <com/sun/star/uno/Any.hxx>
      26             : #include <com/sun/star/uno/Sequence.hxx>
      27             : #include <osl/mutex.hxx>
      28             : #include <osl/file.hxx>
      29             : #include <unotools/localfilehelper.hxx>
      30             : #include <unotools/bootstrap.hxx>
      31             : 
      32             : #include <unotools/ucbhelper.hxx>
      33             : #include <comphelper/processfactory.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/lang/XMultiServiceFactory.hpp>
      39             : #include <com/sun/star/util/thePathSettings.hpp>
      40             : #include <com/sun/star/util/PathSubstitution.hpp>
      41             : #include <com/sun/star/util/XStringSubstitution.hpp>
      42             : #include <com/sun/star/util/theMacroExpander.hpp>
      43             : #include <rtl/instance.hxx>
      44             : 
      45             : #include <itemholder1.hxx>
      46             : 
      47             : #include <vector>
      48             : #include <boost/unordered_map.hpp>
      49             : 
      50             : using namespace osl;
      51             : using namespace utl;
      52             : using namespace com::sun::star::uno;
      53             : using namespace com::sun::star::beans;
      54             : using namespace com::sun::star::util;
      55             : using namespace com::sun::star::lang;
      56             : 
      57             : #define SEARCHPATH_DELIMITER  ';'
      58             : #define SIGN_STARTVARIABLE    OUString( "$("  )
      59             : #define SIGN_ENDVARIABLE      OUString( ")" )
      60             : 
      61             : // Supported variables by the old SvtPathOptions implementation
      62             : #define SUBSTITUTE_INSTPATH   "$(instpath)"
      63             : #define SUBSTITUTE_PROGPATH   "$(progpath)"
      64             : #define SUBSTITUTE_USERPATH   "$(userpath)"
      65             : #define SUBSTITUTE_PATH       "$(path)"
      66             : 
      67             : #define STRPOS_NOTFOUND       -1
      68             : 
      69             : enum VarNameProperty
      70             : {
      71             :     VAR_NEEDS_SYSTEM_PATH,
      72             :     VAR_NEEDS_FILEURL
      73             : };
      74             : 
      75             : typedef boost::unordered_map<OUString, sal_Int32, OUStringHash> NameToHandleMap;
      76             : 
      77             : typedef boost::unordered_map<sal_Int32, sal_Int32> EnumToHandleMap;
      78             : 
      79             : typedef boost::unordered_map<OUString, VarNameProperty, OUStringHash>
      80             :     VarNameToEnumMap;
      81             : 
      82             : // class SvtPathOptions_Impl ---------------------------------------------
      83           0 : class SvtPathOptions_Impl
      84             : {
      85             :     private:
      86             :         // Local variables to return const references
      87             :         std::vector< OUString >             m_aPathArray;
      88             :         Reference< XFastPropertySet >       m_xPathSettings;
      89             :         Reference< XStringSubstitution >    m_xSubstVariables;
      90             :         Reference< XMacroExpander >         m_xMacroExpander;
      91             :         mutable EnumToHandleMap             m_aMapEnumToPropHandle;
      92             :         VarNameToEnumMap                    m_aMapVarNamesToEnum;
      93             : 
      94             :         LanguageTag                         m_aLanguageTag;
      95             :         OUString                            m_aEmptyString;
      96             :         mutable ::osl::Mutex                m_aMutex;
      97             : 
      98             :     public:
      99             :                         SvtPathOptions_Impl();
     100             : 
     101             :         // get the paths, not const because of using a mutex
     102             :         const OUString& GetPath( SvtPathOptions::Paths );
     103           0 :         const OUString& GetAddinPath() { return GetPath( SvtPathOptions::PATH_ADDIN ); }
     104           0 :         const OUString& GetAutoCorrectPath() { return GetPath( SvtPathOptions::PATH_AUTOCORRECT ); }
     105           0 :         const OUString& GetAutoTextPath() { return GetPath( SvtPathOptions::PATH_AUTOTEXT ); }
     106           0 :         const OUString& GetBackupPath() { return GetPath( SvtPathOptions::PATH_BACKUP ); }
     107           0 :         const OUString& GetBasicPath() { return GetPath( SvtPathOptions::PATH_BASIC ); }
     108           0 :         const OUString& GetBitmapPath() { return GetPath( SvtPathOptions::PATH_BITMAP ); }
     109           0 :         const OUString& GetConfigPath() { return GetPath( SvtPathOptions::PATH_CONFIG ); }
     110           0 :         const OUString& GetDictionaryPath() { return GetPath( SvtPathOptions::PATH_DICTIONARY ); }
     111           0 :         const OUString& GetFavoritesPath() { return GetPath( SvtPathOptions::PATH_FAVORITES ); }
     112           0 :         const OUString& GetFilterPath() { return GetPath( SvtPathOptions::PATH_FILTER ); }
     113           0 :         const OUString& GetGalleryPath() { return GetPath( SvtPathOptions::PATH_GALLERY ); }
     114           0 :         const OUString& GetGraphicPath() { return GetPath( SvtPathOptions::PATH_GRAPHIC ); }
     115           0 :         const OUString& GetHelpPath() { return GetPath( SvtPathOptions::PATH_HELP ); }
     116           0 :         const OUString& GetLinguisticPath() { return GetPath( SvtPathOptions::PATH_LINGUISTIC ); }
     117           0 :         const OUString& GetModulePath() { return GetPath( SvtPathOptions::PATH_MODULE ); }
     118           0 :         const OUString& GetPalettePath() { return GetPath( SvtPathOptions::PATH_PALETTE ); }
     119           0 :         const OUString& GetPluginPath() { return GetPath( SvtPathOptions::PATH_PLUGIN ); }
     120           0 :         const OUString& GetStoragePath() { return GetPath( SvtPathOptions::PATH_STORAGE ); }
     121           0 :         const OUString& GetTempPath() { return GetPath( SvtPathOptions::PATH_TEMP ); }
     122           0 :         const OUString& GetTemplatePath() { return GetPath( SvtPathOptions::PATH_TEMPLATE ); }
     123           0 :         const OUString& GetUserConfigPath() { return GetPath( SvtPathOptions::PATH_USERCONFIG ); }
     124           0 :         const OUString& GetWorkPath() { return GetPath( SvtPathOptions::PATH_WORK ); }
     125           0 :         const OUString& GetUIConfigPath() { return GetPath( SvtPathOptions::PATH_UICONFIG ); }
     126           0 :         const OUString& GetFingerprintPath() { return GetPath( SvtPathOptions::PATH_FINGERPRINT ); }
     127             : 
     128             :         // set the paths
     129             :         void            SetPath( SvtPathOptions::Paths, const OUString& rNewPath );
     130           0 :         void            SetAddinPath( const OUString& rPath ) { SetPath( SvtPathOptions::PATH_ADDIN, rPath ); }
     131           0 :         void            SetAutoCorrectPath( const OUString& rPath ) { SetPath( SvtPathOptions::PATH_AUTOCORRECT, rPath ); }
     132           0 :         void            SetAutoTextPath( const OUString& rPath ) { SetPath( SvtPathOptions::PATH_AUTOTEXT, rPath ); }
     133           0 :         void            SetBackupPath( const OUString& rPath ) { SetPath( SvtPathOptions::PATH_BACKUP, rPath ); }
     134           0 :         void            SetBasicPath( const OUString& rPath ) { SetPath( SvtPathOptions::PATH_BASIC, rPath ); }
     135           0 :         void            SetBitmapPath( const OUString& rPath ) { SetPath( SvtPathOptions::PATH_BITMAP, rPath ); }
     136           0 :         void            SetConfigPath( const OUString& rPath ) { SetPath( SvtPathOptions::PATH_CONFIG, rPath ); }
     137           0 :         void            SetDictionaryPath( const OUString& rPath ) { SetPath( SvtPathOptions::PATH_DICTIONARY, rPath ); }
     138           0 :         void            SetFavoritesPath( const OUString& rPath ) { SetPath( SvtPathOptions::PATH_FAVORITES, rPath ); }
     139           0 :         void            SetFilterPath( const OUString& rPath ) { SetPath( SvtPathOptions::PATH_FILTER, rPath ); }
     140           0 :         void            SetGalleryPath( const OUString& rPath ) { SetPath( SvtPathOptions::PATH_GALLERY, rPath ); }
     141           0 :         void            SetGraphicPath( const OUString& rPath ) { SetPath( SvtPathOptions::PATH_GRAPHIC, rPath ); }
     142           0 :         void            SetHelpPath( const OUString& rPath ) { SetPath( SvtPathOptions::PATH_HELP, rPath ); }
     143           0 :         void            SetLinguisticPath( const OUString& rPath ) { SetPath( SvtPathOptions::PATH_LINGUISTIC, rPath ); }
     144           0 :         void            SetModulePath( const OUString& rPath ) { SetPath( SvtPathOptions::PATH_MODULE, rPath ); }
     145           0 :         void            SetPalettePath( const OUString& rPath ) { SetPath( SvtPathOptions::PATH_PALETTE, rPath ); }
     146           0 :         void            SetPluginPath( const OUString& rPath ) { SetPath( SvtPathOptions::PATH_PLUGIN, rPath ); }
     147           0 :         void            SetStoragePath( const OUString& rPath ) { SetPath( SvtPathOptions::PATH_STORAGE, rPath ); }
     148           0 :         void            SetTempPath( const OUString& rPath ) { SetPath( SvtPathOptions::PATH_TEMP, rPath ); }
     149           0 :         void            SetTemplatePath( const OUString& rPath ) { SetPath( SvtPathOptions::PATH_TEMPLATE, rPath ); }
     150           0 :         void            SetUserConfigPath( const OUString& rPath ) { SetPath( SvtPathOptions::PATH_USERCONFIG, rPath ); }
     151           0 :         void            SetWorkPath( const OUString& rPath ) { SetPath( SvtPathOptions::PATH_WORK, rPath ); }
     152             : 
     153             :         OUString   SubstVar( const OUString& rVar ) const;
     154             :         OUString   ExpandMacros( const OUString& rPath ) const;
     155             :         OUString   UsePathVariables( const OUString& rPath ) const;
     156             : 
     157           0 :         const LanguageTag& GetLanguageTag() const { return m_aLanguageTag; }
     158             : };
     159             : 
     160             : // global ----------------------------------------------------------------
     161             : 
     162             : static SvtPathOptions_Impl* pOptions = NULL;
     163             : static sal_Int32 nRefCount = 0;
     164             : 
     165             : // functions -------------------------------------------------------------
     166             : struct PropertyStruct
     167             : {
     168             :     const char*             pPropName;  // The ascii name of the Office path
     169             :     SvtPathOptions::Paths   ePath;      // The enum value used by SvtPathOptions
     170             : };
     171             : 
     172             : struct VarNameAttribute
     173             : {
     174             :     const char*             pVarName;       // The name of the path variable
     175             :     VarNameProperty         eVarProperty;   // Which return value is needed by this path variable
     176             : };
     177             : 
     178             : static const PropertyStruct aPropNames[] =
     179             : {
     180             :     { "Addin",          SvtPathOptions::PATH_ADDIN          },
     181             :     { "AutoCorrect",    SvtPathOptions::PATH_AUTOCORRECT    },
     182             :     { "AutoText",       SvtPathOptions::PATH_AUTOTEXT       },
     183             :     { "Backup",         SvtPathOptions::PATH_BACKUP         },
     184             :     { "Basic",          SvtPathOptions::PATH_BASIC          },
     185             :     { "Bitmap",         SvtPathOptions::PATH_BITMAP         },
     186             :     { "Config",         SvtPathOptions::PATH_CONFIG         },
     187             :     { "Dictionary",     SvtPathOptions::PATH_DICTIONARY     },
     188             :     { "Favorite",       SvtPathOptions::PATH_FAVORITES      },
     189             :     { "Filter",         SvtPathOptions::PATH_FILTER         },
     190             :     { "Gallery",        SvtPathOptions::PATH_GALLERY        },
     191             :     { "Graphic",        SvtPathOptions::PATH_GRAPHIC        },
     192             :     { "Help",           SvtPathOptions::PATH_HELP           },
     193             :     { "Linguistic",     SvtPathOptions::PATH_LINGUISTIC     },
     194             :     { "Module",         SvtPathOptions::PATH_MODULE         },
     195             :     { "Palette",        SvtPathOptions::PATH_PALETTE        },
     196             :     { "Plugin",         SvtPathOptions::PATH_PLUGIN         },
     197             :     { "Storage",        SvtPathOptions::PATH_STORAGE        },
     198             :     { "Temp",           SvtPathOptions::PATH_TEMP           },
     199             :     { "Template",       SvtPathOptions::PATH_TEMPLATE       },
     200             :     { "UserConfig",     SvtPathOptions::PATH_USERCONFIG     },
     201             :     { "Work",           SvtPathOptions::PATH_WORK           },
     202             :     { "UIConfig",       SvtPathOptions::PATH_UICONFIG       },
     203             :     { "Fingerprint",    SvtPathOptions::PATH_FINGERPRINT    }
     204             : };
     205             : 
     206             : static const VarNameAttribute aVarNameAttribute[] =
     207             : {
     208             :     { SUBSTITUTE_INSTPATH,  VAR_NEEDS_SYSTEM_PATH },    // $(instpath)
     209             :     { SUBSTITUTE_PROGPATH,  VAR_NEEDS_SYSTEM_PATH },    // $(progpath)
     210             :     { SUBSTITUTE_USERPATH,  VAR_NEEDS_SYSTEM_PATH },    // $(userpath)
     211             :     { SUBSTITUTE_PATH,      VAR_NEEDS_SYSTEM_PATH },    // $(path)
     212             : };
     213             : 
     214             : // class SvtPathOptions_Impl ---------------------------------------------
     215             : 
     216           0 : const OUString& SvtPathOptions_Impl::GetPath( SvtPathOptions::Paths ePath )
     217             : {
     218           0 :     if ( ePath >= SvtPathOptions::PATH_COUNT )
     219           0 :         return m_aEmptyString;
     220             : 
     221           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     222             : 
     223             :     try
     224             :     {
     225           0 :         OUString    aPathValue;
     226           0 :         OUString    aResult;
     227           0 :         sal_Int32   nHandle = m_aMapEnumToPropHandle[ (sal_Int32)ePath ];
     228             : 
     229             :         // Substitution is done by the service itself using the substition service
     230           0 :         Any         a = m_xPathSettings->getFastPropertyValue( nHandle );
     231           0 :         a >>= aPathValue;
     232           0 :         if( ePath == SvtPathOptions::PATH_ADDIN     ||
     233           0 :             ePath == SvtPathOptions::PATH_FILTER    ||
     234           0 :             ePath == SvtPathOptions::PATH_HELP      ||
     235           0 :             ePath == SvtPathOptions::PATH_MODULE    ||
     236           0 :             ePath == SvtPathOptions::PATH_PLUGIN    ||
     237             :             ePath == SvtPathOptions::PATH_STORAGE
     238             :           )
     239             :         {
     240             :             // These office paths have to be converted to system pates
     241           0 :             utl::LocalFileHelper::ConvertURLToPhysicalName( aPathValue, aResult );
     242           0 :             aPathValue = aResult;
     243             :         }
     244             : 
     245           0 :         m_aPathArray[ ePath ] = aPathValue;
     246           0 :         return m_aPathArray[ ePath ];
     247             :     }
     248           0 :     catch (UnknownPropertyException &)
     249             :     {
     250             :     }
     251             : 
     252           0 :     return m_aEmptyString;
     253             : }
     254             : 
     255           0 : void SvtPathOptions_Impl::SetPath( SvtPathOptions::Paths ePath, const OUString& rNewPath )
     256             : {
     257           0 :     ::osl::MutexGuard aGuard( m_aMutex );
     258             : 
     259           0 :     if ( ePath < SvtPathOptions::PATH_COUNT )
     260             :     {
     261           0 :         OUString    aResult;
     262           0 :         OUString    aNewValue;
     263           0 :         Any         a;
     264             : 
     265           0 :         switch ( ePath )
     266             :         {
     267             :             case SvtPathOptions::PATH_ADDIN:
     268             :             case SvtPathOptions::PATH_FILTER:
     269             :             case SvtPathOptions::PATH_HELP:
     270             :             case SvtPathOptions::PATH_MODULE:
     271             :             case SvtPathOptions::PATH_PLUGIN:
     272             :             case SvtPathOptions::PATH_STORAGE:
     273             :             {
     274             :                 // These office paths have to be convert back to UCB-URL's
     275           0 :                 utl::LocalFileHelper::ConvertPhysicalNameToURL( rNewPath, aResult );
     276           0 :                 aNewValue = aResult;
     277             :             }
     278           0 :             break;
     279             : 
     280             :             default:
     281           0 :                 aNewValue = rNewPath;
     282             :         }
     283             : 
     284             :         // Resubstitution is done by the service itself using the substition service
     285           0 :         a <<= aNewValue;
     286             :         try
     287             :         {
     288           0 :             m_xPathSettings->setFastPropertyValue( m_aMapEnumToPropHandle[ (sal_Int32)ePath], a );
     289             :         }
     290           0 :         catch (const Exception& e)
     291             :         {
     292             :             SAL_WARN("unotools.config", "SetPath: exception: " << e.Message);
     293           0 :         }
     294           0 :     }
     295           0 : }
     296             : 
     297           0 : OUString SvtPathOptions_Impl::ExpandMacros( const OUString& rPath ) const
     298             : {
     299           0 :     OUString sExpanded( rPath );
     300             : 
     301           0 :     const INetURLObject aParser( rPath );
     302           0 :     if ( aParser.GetProtocol() == INET_PROT_VND_SUN_STAR_EXPAND )
     303           0 :         sExpanded = m_xMacroExpander->expandMacros( aParser.GetURLPath( INetURLObject::DECODE_WITH_CHARSET ) );
     304             : 
     305           0 :     return sExpanded;
     306             : }
     307             : 
     308           0 : OUString SvtPathOptions_Impl::UsePathVariables( const OUString& rPath ) const
     309             : {
     310           0 :     return m_xSubstVariables->reSubstituteVariables( rPath );
     311             : }
     312             : 
     313           0 : OUString SvtPathOptions_Impl::SubstVar( const OUString& rVar ) const
     314             : {
     315             :     // Don't work at parameter-string directly. Copy it.
     316           0 :     OUString aWorkText = rVar;
     317             : 
     318             :     // Convert the returned path to system path!
     319           0 :     bool bConvertLocal = false;
     320             : 
     321             :     // Search for first occurrence of "$(...".
     322           0 :     sal_Int32 nPosition = aWorkText.indexOf( SIGN_STARTVARIABLE );  // = first position of "$(" in string
     323           0 :     sal_Int32 nLength   = 0;                                        // = count of letters from "$(" to ")" in string
     324             : 
     325             :     // Have we found any variable like "$(...)"?
     326           0 :     if ( nPosition != STRPOS_NOTFOUND )
     327             :     {
     328             :         // Yes; Get length of found variable.
     329             :         // If no ")" was found - nLength is set to 0 by default! see before.
     330           0 :         sal_Int32 nEndPosition = aWorkText.indexOf( SIGN_ENDVARIABLE, nPosition );
     331           0 :         if ( nEndPosition != STRPOS_NOTFOUND )
     332           0 :             nLength = nEndPosition - nPosition + 1;
     333             :     }
     334             : 
     335             :     // Is there another path variable?
     336           0 :     while ( ( nPosition != STRPOS_NOTFOUND ) && ( nLength > 0 ) )
     337             :     {
     338             :         // YES; Get the next variable for replace.
     339           0 :         OUString aSubString = aWorkText.copy( nPosition, nLength );
     340           0 :         aSubString = aSubString.toAsciiLowerCase();
     341             : 
     342             :         // Look for special variable that needs a system path.
     343           0 :         VarNameToEnumMap::const_iterator pIter = m_aMapVarNamesToEnum.find( aSubString );
     344           0 :         if ( pIter != m_aMapVarNamesToEnum.end() )
     345           0 :             bConvertLocal = true;
     346             : 
     347           0 :         nPosition += nLength;
     348             : 
     349             :         // We must control index in string before call something at OUString!
     350             :         // The OUString-implementation don't do it for us :-( but the result is not defined otherwise.
     351           0 :         if ( nPosition + 1 > aWorkText.getLength() )
     352             :         {
     353             :             // Position is out of range. Break loop!
     354           0 :             nPosition = STRPOS_NOTFOUND;
     355           0 :             nLength = 0;
     356             :         }
     357             :         else
     358             :         {
     359             :             // Else; Position is valid. Search for next variable.
     360           0 :             nPosition = aWorkText.indexOf( SIGN_STARTVARIABLE, nPosition );
     361             :             // Have we found any variable like "$(...)"?
     362           0 :             if ( nPosition != STRPOS_NOTFOUND )
     363             :             {
     364             :                 // Yes; Get length of found variable. If no ")" was found - nLength must set to 0!
     365           0 :                 nLength = 0;
     366           0 :                 sal_Int32 nEndPosition = aWorkText.indexOf( SIGN_ENDVARIABLE, nPosition );
     367           0 :                 if ( nEndPosition != STRPOS_NOTFOUND )
     368           0 :                     nLength = nEndPosition - nPosition + 1;
     369             :             }
     370             :         }
     371           0 :     }
     372             : 
     373           0 :     aWorkText = m_xSubstVariables->substituteVariables( rVar, false );
     374             : 
     375           0 :     if ( bConvertLocal )
     376             :     {
     377             :         // Convert the URL to a system path for special path variables
     378           0 :         OUString aReturn;
     379           0 :         utl::LocalFileHelper::ConvertURLToPhysicalName( aWorkText, aReturn );
     380           0 :         return aReturn;
     381             :     }
     382             : 
     383           0 :     return aWorkText;
     384             : }
     385             : 
     386           0 : SvtPathOptions_Impl::SvtPathOptions_Impl() :
     387             :     m_aPathArray( (sal_Int32)SvtPathOptions::PATH_COUNT ),
     388           0 :     m_aLanguageTag( LANGUAGE_DONTKNOW )
     389             : {
     390           0 :     Reference< XComponentContext > xContext = comphelper::getProcessComponentContext();
     391             : 
     392             :     // Create necessary services
     393           0 :     Reference< XPathSettings > xPathSettings = thePathSettings::get(xContext);
     394           0 :     m_xPathSettings.set( xPathSettings, UNO_QUERY_THROW );
     395           0 :     m_xSubstVariables.set( PathSubstitution::create(xContext) );
     396           0 :     m_xMacroExpander = theMacroExpander::get(xContext);
     397             : 
     398             :     // Create temporary hash map to have a mapping between property names and property handles
     399           0 :     Reference< XPropertySetInfo > xPropSetInfo = xPathSettings->getPropertySetInfo();
     400           0 :     Sequence< Property > aPathPropSeq = xPropSetInfo->getProperties();
     401             : 
     402           0 :     NameToHandleMap aTempHashMap;
     403           0 :     for ( sal_Int32 n = 0; n < aPathPropSeq.getLength(); n++ )
     404             :     {
     405           0 :         const com::sun::star::beans::Property& aProperty = aPathPropSeq[n];
     406           0 :         aTempHashMap.insert( NameToHandleMap::value_type( aProperty.Name, aProperty.Handle ));
     407             :     }
     408             : 
     409             :     // Create mapping between internal enum (SvtPathOptions::Paths) and property handle
     410           0 :     sal_Int32 nCount = sizeof( aPropNames ) / sizeof( PropertyStruct );
     411             :     sal_Int32 i;
     412           0 :     for ( i = 0; i < nCount; i++ )
     413             :     {
     414             :         NameToHandleMap::const_iterator pIter =
     415           0 :             aTempHashMap.find( OUString::createFromAscii( aPropNames[i].pPropName ));
     416             : 
     417           0 :         if ( pIter != aTempHashMap.end() )
     418             :         {
     419           0 :             sal_Int32 nHandle   = pIter->second;
     420           0 :             sal_Int32 nEnum     = aPropNames[i].ePath;
     421           0 :             m_aMapEnumToPropHandle.insert( EnumToHandleMap::value_type( nEnum, nHandle ));
     422             :         }
     423             :     }
     424             : 
     425             :     // Create hash map for path variables that need a system path as a return value!
     426           0 :     nCount = sizeof( aVarNameAttribute ) / sizeof( VarNameAttribute );
     427           0 :     for ( i = 0; i < nCount; i++ )
     428             :     {
     429             :         m_aMapVarNamesToEnum.insert( VarNameToEnumMap::value_type(
     430             :                 OUString::createFromAscii( aVarNameAttribute[i].pVarName ),
     431           0 :                 aVarNameAttribute[i].eVarProperty ));
     432             :     }
     433             : 
     434             :     // Set language type!
     435           0 :     m_aLanguageTag.reset( ConfigManager::getLocale() );
     436           0 : }
     437             : 
     438             : // class SvtPathOptions --------------------------------------------------
     439             : 
     440             : namespace { struct lclMutex : public rtl::Static< ::osl::Mutex, lclMutex > {}; }
     441             : 
     442           0 : SvtPathOptions::SvtPathOptions()
     443             : {
     444             :     // Global access, must be guarded (multithreading)
     445           0 :     ::osl::MutexGuard aGuard( lclMutex::get() );
     446           0 :     if ( !pOptions )
     447             :     {
     448           0 :         pOptions = new SvtPathOptions_Impl;
     449           0 :         ItemHolder1::holdConfigItem(E_PATHOPTIONS);
     450             :     }
     451           0 :     ++nRefCount;
     452           0 :     pImp = pOptions;
     453           0 : }
     454             : 
     455           0 : SvtPathOptions::~SvtPathOptions()
     456             : {
     457             :     // Global access, must be guarded (multithreading)
     458           0 :     ::osl::MutexGuard aGuard( lclMutex::get() );
     459           0 :     if ( !--nRefCount )
     460             :     {
     461           0 :         DELETEZ( pOptions );
     462           0 :     }
     463           0 : }
     464             : 
     465           0 : const OUString& SvtPathOptions::GetAddinPath() const
     466             : {
     467           0 :     return pImp->GetAddinPath();
     468             : }
     469             : 
     470           0 : const OUString& SvtPathOptions::GetAutoCorrectPath() const
     471             : {
     472           0 :     return pImp->GetAutoCorrectPath();
     473             : }
     474             : 
     475           0 : const OUString& SvtPathOptions::GetAutoTextPath() const
     476             : {
     477           0 :     return pImp->GetAutoTextPath();
     478             : }
     479             : 
     480           0 : const OUString& SvtPathOptions::GetBackupPath() const
     481             : {
     482           0 :     return pImp->GetBackupPath();
     483             : }
     484             : 
     485           0 : const OUString& SvtPathOptions::GetBasicPath() const
     486             : {
     487           0 :     return pImp->GetBasicPath();
     488             : }
     489             : 
     490           0 : const OUString& SvtPathOptions::GetBitmapPath() const
     491             : {
     492           0 :     return pImp->GetBitmapPath();
     493             : }
     494             : 
     495           0 : const OUString& SvtPathOptions::GetConfigPath() const
     496             : {
     497           0 :     return pImp->GetConfigPath();
     498             : }
     499             : 
     500           0 : const OUString& SvtPathOptions::GetDictionaryPath() const
     501             : {
     502           0 :     return pImp->GetDictionaryPath();
     503             : }
     504             : 
     505           0 : const OUString& SvtPathOptions::GetFavoritesPath() const
     506             : {
     507           0 :     return pImp->GetFavoritesPath();
     508             : }
     509             : 
     510           0 : const OUString& SvtPathOptions::GetFilterPath() const
     511             : {
     512           0 :     return pImp->GetFilterPath();
     513             : }
     514             : 
     515           0 : const OUString& SvtPathOptions::GetGalleryPath() const
     516             : {
     517           0 :     return pImp->GetGalleryPath();
     518             : }
     519             : 
     520           0 : const OUString& SvtPathOptions::GetGraphicPath() const
     521             : {
     522           0 :     return pImp->GetGraphicPath();
     523             : }
     524             : 
     525           0 : const OUString& SvtPathOptions::GetHelpPath() const
     526             : {
     527           0 :     return pImp->GetHelpPath();
     528             : }
     529             : 
     530           0 : const OUString& SvtPathOptions::GetLinguisticPath() const
     531             : {
     532           0 :     return pImp->GetLinguisticPath();
     533             : }
     534             : 
     535           0 : const OUString& SvtPathOptions::GetFingerprintPath() const
     536             : {
     537           0 :     return pImp->GetFingerprintPath();
     538             : }
     539             : 
     540           0 : const OUString& SvtPathOptions::GetModulePath() const
     541             : {
     542           0 :     return pImp->GetModulePath();
     543             : }
     544             : 
     545           0 : const OUString& SvtPathOptions::GetPalettePath() const
     546             : {
     547           0 :     return pImp->GetPalettePath();
     548             : }
     549             : 
     550           0 : const OUString& SvtPathOptions::GetPluginPath() const
     551             : {
     552           0 :     return pImp->GetPluginPath();
     553             : }
     554             : 
     555           0 : const OUString& SvtPathOptions::GetStoragePath() const
     556             : {
     557           0 :     return pImp->GetStoragePath();
     558             : }
     559             : 
     560           0 : const OUString& SvtPathOptions::GetTempPath() const
     561             : {
     562           0 :     return pImp->GetTempPath();
     563             : }
     564             : 
     565           0 : const OUString& SvtPathOptions::GetTemplatePath() const
     566             : {
     567           0 :     return pImp->GetTemplatePath();
     568             : }
     569             : 
     570           0 : const OUString& SvtPathOptions::GetUserConfigPath() const
     571             : {
     572           0 :     return pImp->GetUserConfigPath();
     573             : }
     574             : 
     575           0 : const OUString& SvtPathOptions::GetUIConfigPath() const
     576             : {
     577           0 :     return pImp->GetUIConfigPath();
     578             : }
     579             : 
     580           0 : const OUString& SvtPathOptions::GetWorkPath() const
     581             : {
     582           0 :     return pImp->GetWorkPath();
     583             : }
     584             : 
     585           0 : void SvtPathOptions::SetAddinPath( const OUString& rPath )
     586             : {
     587           0 :     pImp->SetAddinPath( rPath );
     588           0 : }
     589             : 
     590           0 : void SvtPathOptions::SetAutoCorrectPath( const OUString& rPath )
     591             : {
     592           0 :     pImp->SetAutoCorrectPath( rPath );
     593           0 : }
     594             : 
     595           0 : void SvtPathOptions::SetAutoTextPath( const OUString& rPath )
     596             : {
     597           0 :     pImp->SetAutoTextPath( rPath );
     598           0 : }
     599             : 
     600           0 : void SvtPathOptions::SetBackupPath( const OUString& rPath )
     601             : {
     602           0 :     pImp->SetBackupPath( rPath );
     603           0 : }
     604             : 
     605           0 : void SvtPathOptions::SetBasicPath( const OUString& rPath )
     606             : {
     607           0 :     pImp->SetBasicPath( rPath );
     608           0 : }
     609             : 
     610           0 : void SvtPathOptions::SetBitmapPath( const OUString& rPath )
     611             : {
     612           0 :     pImp->SetBitmapPath( rPath );
     613           0 : }
     614             : 
     615           0 : void SvtPathOptions::SetConfigPath( const OUString& rPath )
     616             : {
     617           0 :     pImp->SetConfigPath( rPath );
     618           0 : }
     619             : 
     620           0 : void SvtPathOptions::SetDictionaryPath( const OUString& rPath )
     621             : {
     622           0 :     pImp->SetDictionaryPath( rPath );
     623           0 : }
     624             : 
     625           0 : void SvtPathOptions::SetFavoritesPath( const OUString& rPath )
     626             : {
     627           0 :     pImp->SetFavoritesPath( rPath );
     628           0 : }
     629             : 
     630           0 : void SvtPathOptions::SetFilterPath( const OUString& rPath )
     631             : {
     632           0 :     pImp->SetFilterPath( rPath );
     633           0 : }
     634             : 
     635           0 : void SvtPathOptions::SetGalleryPath( const OUString& rPath )
     636             : {
     637           0 :     pImp->SetGalleryPath( rPath );
     638           0 : }
     639             : 
     640           0 : void SvtPathOptions::SetGraphicPath( const OUString& rPath )
     641             : {
     642           0 :     pImp->SetGraphicPath( rPath );
     643           0 : }
     644             : 
     645           0 : void SvtPathOptions::SetHelpPath( const OUString& rPath )
     646             : {
     647           0 :     pImp->SetHelpPath( rPath );
     648           0 : }
     649             : 
     650           0 : void SvtPathOptions::SetLinguisticPath( const OUString& rPath )
     651             : {
     652           0 :     pImp->SetLinguisticPath( rPath );
     653           0 : }
     654             : 
     655           0 : void SvtPathOptions::SetModulePath( const OUString& rPath )
     656             : {
     657           0 :     pImp->SetModulePath( rPath );
     658           0 : }
     659             : 
     660           0 : void SvtPathOptions::SetPalettePath( const OUString& rPath )
     661             : {
     662           0 :     pImp->SetPalettePath( rPath );
     663           0 : }
     664             : 
     665           0 : void SvtPathOptions::SetPluginPath( const OUString& rPath )
     666             : {
     667           0 :     pImp->SetPluginPath( rPath );
     668           0 : }
     669             : 
     670           0 : void SvtPathOptions::SetStoragePath( const OUString& rPath )
     671             : {
     672           0 :     pImp->SetStoragePath( rPath );
     673           0 : }
     674             : 
     675           0 : void SvtPathOptions::SetTempPath( const OUString& rPath )
     676             : {
     677           0 :     pImp->SetTempPath( rPath );
     678           0 : }
     679             : 
     680           0 : void SvtPathOptions::SetTemplatePath( const OUString& rPath )
     681             : {
     682           0 :     pImp->SetTemplatePath( rPath );
     683           0 : }
     684             : 
     685           0 : void SvtPathOptions::SetUserConfigPath( const OUString& rPath )
     686             : {
     687           0 :     pImp->SetUserConfigPath( rPath );
     688           0 : }
     689             : 
     690           0 : void SvtPathOptions::SetWorkPath( const OUString& rPath )
     691             : {
     692           0 :     pImp->SetWorkPath( rPath );
     693           0 : }
     694             : 
     695           0 : OUString SvtPathOptions::SubstituteVariable( const OUString& rVar ) const
     696             : {
     697           0 :     return pImp->SubstVar( rVar );
     698             : }
     699             : 
     700           0 : OUString SvtPathOptions::ExpandMacros( const OUString& rPath ) const
     701             : {
     702           0 :     return pImp->ExpandMacros( rPath );
     703             : }
     704             : 
     705           0 : OUString SvtPathOptions::UseVariable( const OUString& rPath ) const
     706             : {
     707           0 :     return pImp->UsePathVariables( rPath );
     708             : }
     709             : 
     710           0 : bool SvtPathOptions::SearchFile( OUString& rIniFile, Paths ePath )
     711             : {
     712             :     // check parameter: empty inifile name?
     713           0 :     if ( rIniFile.isEmpty() )
     714             :     {
     715             :         SAL_WARN( "unotools.config", "SvtPathOptions::SearchFile(): invalid parameter" );
     716           0 :         return false;
     717             :     }
     718             : 
     719           0 :     OUString aIniFile = pImp->SubstVar( rIniFile );
     720           0 :     bool bRet = false;
     721             : 
     722           0 :     switch ( ePath )
     723             :     {
     724             :         case PATH_USERCONFIG:
     725             :         {
     726             :             // path is a URL
     727           0 :             bRet = true;
     728           0 :             INetURLObject aObj( GetUserConfigPath() );
     729             : 
     730           0 :             sal_Int32 nIniIndex = 0;
     731           0 :             do
     732             :             {
     733           0 :                 OUString aToken = aIniFile.getToken( 0, '/', nIniIndex );
     734           0 :                 aObj.insertName(aToken);
     735             :             }
     736           0 :             while ( nIniIndex >= 0 );
     737             : 
     738           0 :             if ( !::utl::UCBContentHelper::Exists( aObj.GetMainURL( INetURLObject::NO_DECODE ) ) )
     739             :             {
     740           0 :                 aObj.SetSmartURL( GetConfigPath() );
     741           0 :                 aObj.insertName( aIniFile );
     742           0 :                 bRet = ::utl::UCBContentHelper::Exists( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
     743             :             }
     744             : 
     745           0 :             if ( bRet )
     746           0 :                 rIniFile = aObj.GetMainURL( INetURLObject::NO_DECODE );
     747             : 
     748           0 :             break;
     749             :         }
     750             : 
     751             :         default:
     752             :         {
     753           0 :             OUString aPath;
     754           0 :             switch ( ePath )
     755             :             {
     756           0 :                 case PATH_ADDIN:        aPath = GetAddinPath();         break;
     757           0 :                 case PATH_AUTOCORRECT:  aPath = GetAutoCorrectPath();   break;
     758           0 :                 case PATH_AUTOTEXT:     aPath = GetAutoTextPath();      break;
     759           0 :                 case PATH_BACKUP:       aPath = GetBackupPath();        break;
     760           0 :                 case PATH_BASIC:        aPath = GetBasicPath();         break;
     761           0 :                 case PATH_BITMAP:       aPath = GetBitmapPath();        break;
     762           0 :                 case PATH_CONFIG:       aPath = GetConfigPath();        break;
     763           0 :                 case PATH_DICTIONARY:   aPath = GetDictionaryPath();    break;
     764           0 :                 case PATH_FAVORITES:    aPath = GetFavoritesPath();     break;
     765           0 :                 case PATH_FILTER:       aPath = GetFilterPath();        break;
     766           0 :                 case PATH_GALLERY:      aPath = GetGalleryPath();       break;
     767           0 :                 case PATH_GRAPHIC:      aPath = GetGraphicPath();       break;
     768           0 :                 case PATH_HELP:         aPath = GetHelpPath();          break;
     769           0 :                 case PATH_LINGUISTIC:   aPath = GetLinguisticPath();    break;
     770           0 :                 case PATH_MODULE:       aPath = GetModulePath();        break;
     771           0 :                 case PATH_PALETTE:      aPath = GetPalettePath();       break;
     772           0 :                 case PATH_PLUGIN:       aPath = GetPluginPath();        break;
     773           0 :                 case PATH_STORAGE:      aPath = GetStoragePath();       break;
     774           0 :                 case PATH_TEMP:         aPath = GetTempPath();          break;
     775           0 :                 case PATH_TEMPLATE:     aPath = GetTemplatePath();      break;
     776           0 :                 case PATH_WORK:         aPath = GetWorkPath();          break;
     777           0 :                 case PATH_UICONFIG:     aPath = GetUIConfigPath();      break;
     778           0 :                 case PATH_FINGERPRINT:  aPath = GetFingerprintPath();   break;
     779           0 :                 case PATH_USERCONFIG:/*-Wall???*/           break;
     780           0 :                 case PATH_COUNT: /*-Wall???*/ break;
     781             :             }
     782             : 
     783           0 :             sal_Int32 nPathIndex = 0;
     784           0 :             do
     785             :             {
     786           0 :                 bool bIsURL = true;
     787           0 :                 OUString aPathToken = aPath.getToken( 0, SEARCHPATH_DELIMITER, nPathIndex );
     788           0 :                 INetURLObject aObj( aPathToken );
     789           0 :                 if ( aObj.HasError() )
     790             :                 {
     791           0 :                     bIsURL = false;
     792           0 :                     OUString aURL;
     793           0 :                     if ( LocalFileHelper::ConvertPhysicalNameToURL( aPathToken, aURL ) )
     794           0 :                         aObj.SetURL( aURL );
     795             :                 }
     796           0 :                 if ( aObj.GetProtocol() == INET_PROT_VND_SUN_STAR_EXPAND )
     797             :                 {
     798           0 :                     Reference< XMacroExpander > xMacroExpander = theMacroExpander::get( ::comphelper::getProcessComponentContext() );
     799           0 :                     const OUString sExpandedPath = xMacroExpander->expandMacros( aObj.GetURLPath( INetURLObject::DECODE_WITH_CHARSET ) );
     800           0 :                     aObj.SetURL( sExpandedPath );
     801             :                 }
     802             : 
     803           0 :                 sal_Int32 nIniIndex = 0;
     804           0 :                 do
     805             :                 {
     806           0 :                     OUString aToken = aIniFile.getToken( 0, '/', nIniIndex );
     807           0 :                     aObj.insertName(aToken);
     808             :                 }
     809           0 :                 while ( nIniIndex >= 0 );
     810             : 
     811           0 :                 bRet = ::utl::UCBContentHelper::Exists( aObj.GetMainURL( INetURLObject::NO_DECODE ) );
     812             : 
     813           0 :                 if ( bRet )
     814             :                 {
     815           0 :                     if ( !bIsURL )
     816             :                     {
     817           0 :                         OUString sTmp(rIniFile);
     818             :                         ::utl::LocalFileHelper::ConvertURLToPhysicalName(
     819           0 :                                             aObj.GetMainURL( INetURLObject::NO_DECODE ), sTmp );
     820           0 :                         rIniFile = sTmp;
     821             :                     }
     822             :                     else
     823           0 :                         rIniFile = aObj.GetMainURL( INetURLObject::NO_DECODE );
     824           0 :                     break;
     825           0 :                 }
     826             :             }
     827           0 :             while ( nPathIndex >= 0 );
     828             :         }
     829             :     }
     830             : 
     831           0 :     return bRet;
     832             : }
     833             : 
     834           0 : const LanguageTag& SvtPathOptions::GetLanguageTag() const
     835             : {
     836           0 :     return pImp->GetLanguageTag();
     837             : }
     838             : 
     839             : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */

Generated by: LCOV version 1.10