1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
3 * This file is part of the LibreOffice project.
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/.
9 * This file incorporates work covered by the following license notice:
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 .
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>
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/lang/XMultiServiceFactory.hpp>
39 #include <com/sun/star/util/PathSettings.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>
45 #include <itemholder1.hxx>
48 #include <boost/unordered_map.hpp>
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
;
58 #define SEARCHPATH_DELIMITER ';'
59 #define SIGN_STARTVARIABLE OUString( "$(" )
60 #define SIGN_ENDVARIABLE OUString( ")" )
62 // Supported variables by the old SvtPathOptions implementation
63 #define SUBSTITUTE_INSTPATH "$(instpath)"
64 #define SUBSTITUTE_PROGPATH "$(progpath)"
65 #define SUBSTITUTE_USERPATH "$(userpath)"
66 #define SUBSTITUTE_PATH "$(path)"
68 #define STRPOS_NOTFOUND -1
70 struct OUStringHashCode
72 size_t operator()( const OUString
& sString
) const
74 return sString
.hashCode();
80 VAR_NEEDS_SYSTEM_PATH
,
84 class NameToHandleMap
: public ::boost::unordered_map
< OUString
, sal_Int32
, OUStringHashCode
, ::std::equal_to
< OUString
> >
87 inline void free() { NameToHandleMap().swap( *this ); }
90 class EnumToHandleMap
: public ::boost::unordered_map
< sal_Int32
, sal_Int32
, boost::hash
< sal_Int32
>, std::equal_to
< sal_Int32
> >
93 inline void free() { EnumToHandleMap().swap( *this ); }
96 class VarNameToEnumMap
: public ::boost::unordered_map
< OUString
, VarNameProperty
, OUStringHashCode
, ::std::equal_to
< OUString
> >
99 inline void free() { VarNameToEnumMap().swap( *this ); }
103 // class SvtPathOptions_Impl ---------------------------------------------
104 class SvtPathOptions_Impl
107 // Local variables to return const references
108 std::vector
< String
> m_aPathArray
;
109 Reference
< XFastPropertySet
> m_xPathSettings
;
110 Reference
< XStringSubstitution
> m_xSubstVariables
;
111 Reference
< XMacroExpander
> m_xMacroExpander
;
112 mutable EnumToHandleMap m_aMapEnumToPropHandle
;
113 VarNameToEnumMap m_aMapVarNamesToEnum
;
115 LanguageTag m_aLanguageTag
;
116 String m_aEmptyString
;
117 mutable ::osl::Mutex m_aMutex
;
120 SvtPathOptions_Impl();
122 // get the paths, not const because of using a mutex
123 const String
& GetPath( SvtPathOptions::Paths
);
124 const String
& GetAddinPath() { return GetPath( SvtPathOptions::PATH_ADDIN
); }
125 const String
& GetAutoCorrectPath() { return GetPath( SvtPathOptions::PATH_AUTOCORRECT
); }
126 const String
& GetAutoTextPath() { return GetPath( SvtPathOptions::PATH_AUTOTEXT
); }
127 const String
& GetBackupPath() { return GetPath( SvtPathOptions::PATH_BACKUP
); }
128 const String
& GetBasicPath() { return GetPath( SvtPathOptions::PATH_BASIC
); }
129 const String
& GetBitmapPath() { return GetPath( SvtPathOptions::PATH_BITMAP
); }
130 const String
& GetConfigPath() { return GetPath( SvtPathOptions::PATH_CONFIG
); }
131 const String
& GetDictionaryPath() { return GetPath( SvtPathOptions::PATH_DICTIONARY
); }
132 const String
& GetFavoritesPath() { return GetPath( SvtPathOptions::PATH_FAVORITES
); }
133 const String
& GetFilterPath() { return GetPath( SvtPathOptions::PATH_FILTER
); }
134 const String
& GetGalleryPath() { return GetPath( SvtPathOptions::PATH_GALLERY
); }
135 const String
& GetGraphicPath() { return GetPath( SvtPathOptions::PATH_GRAPHIC
); }
136 const String
& GetHelpPath() { return GetPath( SvtPathOptions::PATH_HELP
); }
137 const String
& GetLinguisticPath() { return GetPath( SvtPathOptions::PATH_LINGUISTIC
); }
138 const String
& GetModulePath() { return GetPath( SvtPathOptions::PATH_MODULE
); }
139 const String
& GetPalettePath() { return GetPath( SvtPathOptions::PATH_PALETTE
); }
140 const String
& GetPluginPath() { return GetPath( SvtPathOptions::PATH_PLUGIN
); }
141 const String
& GetStoragePath() { return GetPath( SvtPathOptions::PATH_STORAGE
); }
142 const String
& GetTempPath() { return GetPath( SvtPathOptions::PATH_TEMP
); }
143 const String
& GetTemplatePath() { return GetPath( SvtPathOptions::PATH_TEMPLATE
); }
144 const String
& GetUserConfigPath() { return GetPath( SvtPathOptions::PATH_USERCONFIG
); }
145 const String
& GetWorkPath() { return GetPath( SvtPathOptions::PATH_WORK
); }
146 const String
& GetUIConfigPath() { return GetPath( SvtPathOptions::PATH_UICONFIG
); }
147 const String
& GetFingerprintPath() { return GetPath( SvtPathOptions::PATH_FINGERPRINT
); }
150 void SetPath( SvtPathOptions::Paths
, const String
& rNewPath
);
151 void SetAddinPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_ADDIN
, rPath
); }
152 void SetAutoCorrectPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_AUTOCORRECT
, rPath
); }
153 void SetAutoTextPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_AUTOTEXT
, rPath
); }
154 void SetBackupPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_BACKUP
, rPath
); }
155 void SetBasicPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_BASIC
, rPath
); }
156 void SetBitmapPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_BITMAP
, rPath
); }
157 void SetConfigPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_CONFIG
, rPath
); }
158 void SetDictionaryPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_DICTIONARY
, rPath
); }
159 void SetFavoritesPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_FAVORITES
, rPath
); }
160 void SetFilterPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_FILTER
, rPath
); }
161 void SetGalleryPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_GALLERY
, rPath
); }
162 void SetGraphicPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_GRAPHIC
, rPath
); }
163 void SetHelpPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_HELP
, rPath
); }
164 void SetLinguisticPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_LINGUISTIC
, rPath
); }
165 void SetModulePath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_MODULE
, rPath
); }
166 void SetPalettePath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_PALETTE
, rPath
); }
167 void SetPluginPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_PLUGIN
, rPath
); }
168 void SetStoragePath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_STORAGE
, rPath
); }
169 void SetTempPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_TEMP
, rPath
); }
170 void SetTemplatePath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_TEMPLATE
, rPath
); }
171 void SetUserConfigPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_USERCONFIG
, rPath
); }
172 void SetWorkPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_WORK
, rPath
); }
174 OUString
SubstVar( const OUString
& rVar
) const;
175 OUString
ExpandMacros( const OUString
& rPath
) const;
176 OUString
UsePathVariables( const OUString
& rPath
) const;
178 const LanguageTag
& GetLanguageTag() const { return m_aLanguageTag
; }
181 // global ----------------------------------------------------------------
183 static SvtPathOptions_Impl
* pOptions
= NULL
;
184 static sal_Int32 nRefCount
= 0;
186 // functions -------------------------------------------------------------
187 struct PropertyStruct
189 const char* pPropName
; // The ascii name of the Office path
190 SvtPathOptions::Paths ePath
; // The enum value used by SvtPathOptions
193 struct VarNameAttribute
195 const char* pVarName
; // The name of the path variable
196 VarNameProperty eVarProperty
; // Which return value is needed by this path variable
199 static PropertyStruct aPropNames
[] =
201 { "Addin", SvtPathOptions::PATH_ADDIN
},
202 { "AutoCorrect", SvtPathOptions::PATH_AUTOCORRECT
},
203 { "AutoText", SvtPathOptions::PATH_AUTOTEXT
},
204 { "Backup", SvtPathOptions::PATH_BACKUP
},
205 { "Basic", SvtPathOptions::PATH_BASIC
},
206 { "Bitmap", SvtPathOptions::PATH_BITMAP
},
207 { "Config", SvtPathOptions::PATH_CONFIG
},
208 { "Dictionary", SvtPathOptions::PATH_DICTIONARY
},
209 { "Favorite", SvtPathOptions::PATH_FAVORITES
},
210 { "Filter", SvtPathOptions::PATH_FILTER
},
211 { "Gallery", SvtPathOptions::PATH_GALLERY
},
212 { "Graphic", SvtPathOptions::PATH_GRAPHIC
},
213 { "Help", SvtPathOptions::PATH_HELP
},
214 { "Linguistic", SvtPathOptions::PATH_LINGUISTIC
},
215 { "Module", SvtPathOptions::PATH_MODULE
},
216 { "Palette", SvtPathOptions::PATH_PALETTE
},
217 { "Plugin", SvtPathOptions::PATH_PLUGIN
},
218 { "Storage", SvtPathOptions::PATH_STORAGE
},
219 { "Temp", SvtPathOptions::PATH_TEMP
},
220 { "Template", SvtPathOptions::PATH_TEMPLATE
},
221 { "UserConfig", SvtPathOptions::PATH_USERCONFIG
},
222 { "Work", SvtPathOptions::PATH_WORK
},
223 { "UIConfig", SvtPathOptions::PATH_UICONFIG
},
224 { "Fingerprint", SvtPathOptions::PATH_FINGERPRINT
}
227 static VarNameAttribute aVarNameAttribute
[] =
229 { SUBSTITUTE_INSTPATH
, VAR_NEEDS_SYSTEM_PATH
}, // $(instpath)
230 { SUBSTITUTE_PROGPATH
, VAR_NEEDS_SYSTEM_PATH
}, // $(progpath)
231 { SUBSTITUTE_USERPATH
, VAR_NEEDS_SYSTEM_PATH
}, // $(userpath)
232 { SUBSTITUTE_PATH
, VAR_NEEDS_SYSTEM_PATH
}, // $(path)
235 // class SvtPathOptions_Impl ---------------------------------------------
237 const String
& SvtPathOptions_Impl::GetPath( SvtPathOptions::Paths ePath
)
239 if ( ePath
>= SvtPathOptions::PATH_COUNT
)
240 return m_aEmptyString
;
242 ::osl::MutexGuard
aGuard( m_aMutex
);
248 sal_Int32 nHandle
= m_aMapEnumToPropHandle
[ (sal_Int32
)ePath
];
250 // Substitution is done by the service itself using the substition service
251 Any a
= m_xPathSettings
->getFastPropertyValue( nHandle
);
253 if( ePath
== SvtPathOptions::PATH_ADDIN
||
254 ePath
== SvtPathOptions::PATH_FILTER
||
255 ePath
== SvtPathOptions::PATH_HELP
||
256 ePath
== SvtPathOptions::PATH_MODULE
||
257 ePath
== SvtPathOptions::PATH_PLUGIN
||
258 ePath
== SvtPathOptions::PATH_STORAGE
261 // These office paths have to be converted to system pates
262 utl::LocalFileHelper::ConvertURLToPhysicalName( aPathValue
, aResult
);
263 aPathValue
= aResult
;
266 m_aPathArray
[ ePath
] = aPathValue
;
267 return m_aPathArray
[ ePath
];
269 catch (UnknownPropertyException
&)
273 return m_aEmptyString
;
276 void SvtPathOptions_Impl::SetPath( SvtPathOptions::Paths ePath
, const String
& rNewPath
)
278 ::osl::MutexGuard
aGuard( m_aMutex
);
280 if ( ePath
< SvtPathOptions::PATH_COUNT
)
288 case SvtPathOptions::PATH_ADDIN
:
289 case SvtPathOptions::PATH_FILTER
:
290 case SvtPathOptions::PATH_HELP
:
291 case SvtPathOptions::PATH_MODULE
:
292 case SvtPathOptions::PATH_PLUGIN
:
293 case SvtPathOptions::PATH_STORAGE
:
295 // These office paths have to be convert back to UCB-URL's
296 utl::LocalFileHelper::ConvertPhysicalNameToURL( rNewPath
, aResult
);
302 aNewValue
= rNewPath
;
305 // Resubstitution is done by the service itself using the substition service
309 m_xPathSettings
->setFastPropertyValue( m_aMapEnumToPropHandle
[ (sal_Int32
)ePath
], a
);
311 catch (const Exception
&)
317 //-------------------------------------------------------------------------
319 OUString
SvtPathOptions_Impl::ExpandMacros( const OUString
& rPath
) const
321 OUString
sExpanded( rPath
);
323 const INetURLObject
aParser( rPath
);
324 if ( aParser
.GetProtocol() == INET_PROT_VND_SUN_STAR_EXPAND
)
325 sExpanded
= m_xMacroExpander
->expandMacros( aParser
.GetURLPath( INetURLObject::DECODE_WITH_CHARSET
) );
330 //-------------------------------------------------------------------------
332 OUString
SvtPathOptions_Impl::UsePathVariables( const OUString
& rPath
) const
334 return m_xSubstVariables
->reSubstituteVariables( rPath
);
337 // -----------------------------------------------------------------------
339 OUString
SvtPathOptions_Impl::SubstVar( const OUString
& rVar
) const
341 // Don't work at parameter-string directly. Copy it.
342 OUString aWorkText
= rVar
;
344 // Convert the returned path to system path!
345 sal_Bool bConvertLocal
= sal_False
;
347 // Search for first occure of "$(...".
348 sal_Int32 nPosition
= aWorkText
.indexOf( SIGN_STARTVARIABLE
); // = first position of "$(" in string
349 sal_Int32 nLength
= 0; // = count of letters from "$(" to ")" in string
351 // Have we found any variable like "$(...)"?
352 if ( nPosition
!= STRPOS_NOTFOUND
)
354 // Yes; Get length of found variable.
355 // If no ")" was found - nLength is set to 0 by default! see before.
356 sal_Int32 nEndPosition
= aWorkText
.indexOf( SIGN_ENDVARIABLE
, nPosition
);
357 if ( nEndPosition
!= STRPOS_NOTFOUND
)
358 nLength
= nEndPosition
- nPosition
+ 1;
361 // Is there another path variable?
362 while ( ( nPosition
!= STRPOS_NOTFOUND
) && ( nLength
> 0 ) )
364 // YES; Get the next variable for replace.
365 OUString aSubString
= aWorkText
.copy( nPosition
, nLength
);
366 aSubString
= aSubString
.toAsciiLowerCase();
368 // Look for special variable that needs a system path.
369 VarNameToEnumMap::const_iterator pIter
= m_aMapVarNamesToEnum
.find( aSubString
);
370 if ( pIter
!= m_aMapVarNamesToEnum
.end() )
371 bConvertLocal
= sal_True
;
373 nPosition
+= nLength
;
375 // We must control index in string before call something at OUString!
376 // The OUString-implementation don't do it for us :-( but the result is not defined otherwise.
377 if ( nPosition
+ 1 > aWorkText
.getLength() )
379 // Position is out of range. Break loop!
380 nPosition
= STRPOS_NOTFOUND
;
385 // Else; Position is valid. Search for next variable.
386 nPosition
= aWorkText
.indexOf( SIGN_STARTVARIABLE
, nPosition
);
387 // Have we found any variable like "$(...)"?
388 if ( nPosition
!= STRPOS_NOTFOUND
)
390 // Yes; Get length of found variable. If no ")" was found - nLength must set to 0!
392 sal_Int32 nEndPosition
= aWorkText
.indexOf( SIGN_ENDVARIABLE
, nPosition
);
393 if ( nEndPosition
!= STRPOS_NOTFOUND
)
394 nLength
= nEndPosition
- nPosition
+ 1;
399 aWorkText
= m_xSubstVariables
->substituteVariables( rVar
, sal_False
);
403 // Convert the URL to a system path for special path variables
405 utl::LocalFileHelper::ConvertURLToPhysicalName( aWorkText
, aReturn
);
412 // -----------------------------------------------------------------------
414 SvtPathOptions_Impl::SvtPathOptions_Impl() :
415 m_aPathArray( (sal_Int32
)SvtPathOptions::PATH_COUNT
),
416 m_aLanguageTag( LANGUAGE_DONTKNOW
)
418 Reference
< XComponentContext
> xContext
= comphelper::getProcessComponentContext();
420 // Create necessary services
421 Reference
< XPathSettings
> xPathSettings
= PathSettings::create(xContext
);
422 m_xPathSettings
.set( xPathSettings
, UNO_QUERY_THROW
);
423 m_xSubstVariables
.set( PathSubstitution::create(xContext
) );
424 m_xMacroExpander
= theMacroExpander::get(xContext
);
426 // Create temporary hash map to have a mapping between property names and property handles
427 Reference
< XPropertySetInfo
> xPropSetInfo
= xPathSettings
->getPropertySetInfo();
428 Sequence
< Property
> aPathPropSeq
= xPropSetInfo
->getProperties();
430 NameToHandleMap aTempHashMap
;
431 for ( sal_Int32 n
= 0; n
< aPathPropSeq
.getLength(); n
++ )
433 const com::sun::star::beans::Property
& aProperty
= aPathPropSeq
[n
];
434 aTempHashMap
.insert( NameToHandleMap::value_type( aProperty
.Name
, aProperty
.Handle
));
437 // Create mapping between internal enum (SvtPathOptions::Paths) and property handle
438 sal_Int32 nCount
= sizeof( aPropNames
) / sizeof( PropertyStruct
);
440 for ( i
= 0; i
< nCount
; i
++ )
442 NameToHandleMap::const_iterator pIter
=
443 aTempHashMap
.find( OUString::createFromAscii( aPropNames
[i
].pPropName
));
445 if ( pIter
!= aTempHashMap
.end() )
447 sal_Int32 nHandle
= pIter
->second
;
448 sal_Int32 nEnum
= aPropNames
[i
].ePath
;
449 m_aMapEnumToPropHandle
.insert( EnumToHandleMap::value_type( nEnum
, nHandle
));
453 // Create hash map for path variables that need a system path as a return value!
454 nCount
= sizeof( aVarNameAttribute
) / sizeof( VarNameAttribute
);
455 for ( i
= 0; i
< nCount
; i
++ )
457 m_aMapVarNamesToEnum
.insert( VarNameToEnumMap::value_type(
458 OUString::createFromAscii( aVarNameAttribute
[i
].pVarName
),
459 aVarNameAttribute
[i
].eVarProperty
));
462 // Set language type!
463 m_aLanguageTag
.reset( ConfigManager::getLocale() );
466 // -----------------------------------------------------------------------
468 // class SvtPathOptions --------------------------------------------------
470 namespace { struct lclMutex
: public rtl::Static
< ::osl::Mutex
, lclMutex
> {}; }
472 SvtPathOptions::SvtPathOptions()
474 // Global access, must be guarded (multithreading)
475 ::osl::MutexGuard
aGuard( lclMutex::get() );
478 pOptions
= new SvtPathOptions_Impl
;
479 ItemHolder1::holdConfigItem(E_PATHOPTIONS
);
485 // -----------------------------------------------------------------------
487 SvtPathOptions::~SvtPathOptions()
489 // Global access, must be guarded (multithreading)
490 ::osl::MutexGuard
aGuard( lclMutex::get() );
497 // -----------------------------------------------------------------------
499 const String
& SvtPathOptions::GetAddinPath() const
501 return pImp
->GetAddinPath();
504 // -----------------------------------------------------------------------
506 const String
& SvtPathOptions::GetAutoCorrectPath() const
508 return pImp
->GetAutoCorrectPath();
511 // -----------------------------------------------------------------------
513 const String
& SvtPathOptions::GetAutoTextPath() const
515 return pImp
->GetAutoTextPath();
518 // -----------------------------------------------------------------------
520 const String
& SvtPathOptions::GetBackupPath() const
522 return pImp
->GetBackupPath();
525 // -----------------------------------------------------------------------
527 const String
& SvtPathOptions::GetBasicPath() const
529 return pImp
->GetBasicPath();
532 // -----------------------------------------------------------------------
534 const String
& SvtPathOptions::GetBitmapPath() const
536 return pImp
->GetBitmapPath();
539 // -----------------------------------------------------------------------
541 const String
& SvtPathOptions::GetConfigPath() const
543 return pImp
->GetConfigPath();
546 // -----------------------------------------------------------------------
548 const String
& SvtPathOptions::GetDictionaryPath() const
550 return pImp
->GetDictionaryPath();
553 // -----------------------------------------------------------------------
555 const String
& SvtPathOptions::GetFavoritesPath() const
557 return pImp
->GetFavoritesPath();
560 // -----------------------------------------------------------------------
562 const String
& SvtPathOptions::GetFilterPath() const
564 return pImp
->GetFilterPath();
567 // -----------------------------------------------------------------------
569 const String
& SvtPathOptions::GetGalleryPath() const
571 return pImp
->GetGalleryPath();
574 // -----------------------------------------------------------------------
576 const String
& SvtPathOptions::GetGraphicPath() const
578 return pImp
->GetGraphicPath();
581 // -----------------------------------------------------------------------
583 const String
& SvtPathOptions::GetHelpPath() const
585 return pImp
->GetHelpPath();
588 // -----------------------------------------------------------------------
590 const String
& SvtPathOptions::GetLinguisticPath() const
592 return pImp
->GetLinguisticPath();
595 // -----------------------------------------------------------------------
597 const String
& SvtPathOptions::GetFingerprintPath() const
599 return pImp
->GetFingerprintPath();
602 // -----------------------------------------------------------------------
604 const String
& SvtPathOptions::GetModulePath() const
606 return pImp
->GetModulePath();
609 // -----------------------------------------------------------------------
611 const String
& SvtPathOptions::GetPalettePath() const
613 return pImp
->GetPalettePath();
616 // -----------------------------------------------------------------------
618 const String
& SvtPathOptions::GetPluginPath() const
620 return pImp
->GetPluginPath();
623 // -----------------------------------------------------------------------
625 const String
& SvtPathOptions::GetStoragePath() const
627 return pImp
->GetStoragePath();
630 // -----------------------------------------------------------------------
632 const String
& SvtPathOptions::GetTempPath() const
634 return pImp
->GetTempPath();
637 // -----------------------------------------------------------------------
639 const String
& SvtPathOptions::GetTemplatePath() const
641 return pImp
->GetTemplatePath();
644 // -----------------------------------------------------------------------
646 const String
& SvtPathOptions::GetUserConfigPath() const
648 return pImp
->GetUserConfigPath();
651 const String
& SvtPathOptions::GetUIConfigPath() const
653 return pImp
->GetUIConfigPath();
656 // -----------------------------------------------------------------------
658 const String
& SvtPathOptions::GetWorkPath() const
660 return pImp
->GetWorkPath();
663 // -----------------------------------------------------------------------
665 void SvtPathOptions::SetAddinPath( const String
& rPath
)
667 pImp
->SetAddinPath( rPath
);
670 // -----------------------------------------------------------------------
672 void SvtPathOptions::SetAutoCorrectPath( const String
& rPath
)
674 pImp
->SetAutoCorrectPath( rPath
);
677 // -----------------------------------------------------------------------
679 void SvtPathOptions::SetAutoTextPath( const String
& rPath
)
681 pImp
->SetAutoTextPath( rPath
);
684 // -----------------------------------------------------------------------
686 void SvtPathOptions::SetBackupPath( const String
& rPath
)
688 pImp
->SetBackupPath( rPath
);
691 // -----------------------------------------------------------------------
693 void SvtPathOptions::SetBasicPath( const String
& rPath
)
695 pImp
->SetBasicPath( rPath
);
698 // -----------------------------------------------------------------------
700 void SvtPathOptions::SetBitmapPath( const String
& rPath
)
702 pImp
->SetBitmapPath( rPath
);
705 // -----------------------------------------------------------------------
707 void SvtPathOptions::SetConfigPath( const String
& rPath
)
709 pImp
->SetConfigPath( rPath
);
712 // -----------------------------------------------------------------------
714 void SvtPathOptions::SetDictionaryPath( const String
& rPath
)
716 pImp
->SetDictionaryPath( rPath
);
719 // -----------------------------------------------------------------------
721 void SvtPathOptions::SetFavoritesPath( const String
& rPath
)
723 pImp
->SetFavoritesPath( rPath
);
726 // -----------------------------------------------------------------------
728 void SvtPathOptions::SetFilterPath( const String
& rPath
)
730 pImp
->SetFilterPath( rPath
);
733 // -----------------------------------------------------------------------
735 void SvtPathOptions::SetGalleryPath( const String
& rPath
)
737 pImp
->SetGalleryPath( rPath
);
740 // -----------------------------------------------------------------------
742 void SvtPathOptions::SetGraphicPath( const String
& rPath
)
744 pImp
->SetGraphicPath( rPath
);
747 // -----------------------------------------------------------------------
749 void SvtPathOptions::SetHelpPath( const String
& rPath
)
751 pImp
->SetHelpPath( rPath
);
754 // -----------------------------------------------------------------------
756 void SvtPathOptions::SetLinguisticPath( const String
& rPath
)
758 pImp
->SetLinguisticPath( rPath
);
761 // -----------------------------------------------------------------------
763 void SvtPathOptions::SetModulePath( const String
& rPath
)
765 pImp
->SetModulePath( rPath
);
768 // -----------------------------------------------------------------------
770 void SvtPathOptions::SetPalettePath( const String
& rPath
)
772 pImp
->SetPalettePath( rPath
);
775 // -----------------------------------------------------------------------
777 void SvtPathOptions::SetPluginPath( const String
& rPath
)
779 pImp
->SetPluginPath( rPath
);
782 // -----------------------------------------------------------------------
784 void SvtPathOptions::SetStoragePath( const String
& rPath
)
786 pImp
->SetStoragePath( rPath
);
789 // -----------------------------------------------------------------------
791 void SvtPathOptions::SetTempPath( const String
& rPath
)
793 pImp
->SetTempPath( rPath
);
796 // -----------------------------------------------------------------------
798 void SvtPathOptions::SetTemplatePath( const String
& rPath
)
800 pImp
->SetTemplatePath( rPath
);
803 // -----------------------------------------------------------------------
805 void SvtPathOptions::SetUserConfigPath( const String
& rPath
)
807 pImp
->SetUserConfigPath( rPath
);
810 // -----------------------------------------------------------------------
812 void SvtPathOptions::SetWorkPath( const String
& rPath
)
814 pImp
->SetWorkPath( rPath
);
817 // -----------------------------------------------------------------------
819 String
SvtPathOptions::SubstituteVariable( const String
& rVar
) const
821 String aRet
= pImp
->SubstVar( rVar
);
825 // -----------------------------------------------------------------------
827 String
SvtPathOptions::ExpandMacros( const String
& rPath
) const
829 return pImp
->ExpandMacros( rPath
);
832 // -----------------------------------------------------------------------
834 String
SvtPathOptions::UseVariable( const String
& rPath
) const
836 String aRet
= pImp
->UsePathVariables( rPath
);
840 // -----------------------------------------------------------------------
842 sal_Bool
SvtPathOptions::SearchFile( String
& rIniFile
, Paths ePath
)
844 // check parameter: empty inifile name?
845 if ( !rIniFile
.Len() )
847 SAL_WARN( "unotools.config", "SvtPathOptions::SearchFile(): invalid parameter" );
851 OUString aIniFile
= pImp
->SubstVar( rIniFile
);
852 sal_Bool bRet
= sal_False
;
856 case PATH_USERCONFIG
:
860 INetURLObject
aObj( GetUserConfigPath() );
862 sal_Int32 nIniIndex
= 0;
865 OUString aToken
= aIniFile
.getToken( 0, '/', nIniIndex
);
866 aObj
.insertName(aToken
);
868 while ( nIniIndex
>= 0 );
870 if ( !::utl::UCBContentHelper::Exists( aObj
.GetMainURL( INetURLObject::NO_DECODE
) ) )
872 aObj
.SetSmartURL( GetConfigPath() );
873 aObj
.insertName( aIniFile
);
874 bRet
= ::utl::UCBContentHelper::Exists( aObj
.GetMainURL( INetURLObject::NO_DECODE
) );
878 rIniFile
= aObj
.GetMainURL( INetURLObject::NO_DECODE
);
888 case PATH_ADDIN
: aPath
= GetAddinPath(); break;
889 case PATH_AUTOCORRECT
: aPath
= GetAutoCorrectPath(); break;
890 case PATH_AUTOTEXT
: aPath
= GetAutoTextPath(); break;
891 case PATH_BACKUP
: aPath
= GetBackupPath(); break;
892 case PATH_BASIC
: aPath
= GetBasicPath(); break;
893 case PATH_BITMAP
: aPath
= GetBitmapPath(); break;
894 case PATH_CONFIG
: aPath
= GetConfigPath(); break;
895 case PATH_DICTIONARY
: aPath
= GetDictionaryPath(); break;
896 case PATH_FAVORITES
: aPath
= GetFavoritesPath(); break;
897 case PATH_FILTER
: aPath
= GetFilterPath(); break;
898 case PATH_GALLERY
: aPath
= GetGalleryPath(); break;
899 case PATH_GRAPHIC
: aPath
= GetGraphicPath(); break;
900 case PATH_HELP
: aPath
= GetHelpPath(); break;
901 case PATH_LINGUISTIC
: aPath
= GetLinguisticPath(); break;
902 case PATH_MODULE
: aPath
= GetModulePath(); break;
903 case PATH_PALETTE
: aPath
= GetPalettePath(); break;
904 case PATH_PLUGIN
: aPath
= GetPluginPath(); break;
905 case PATH_STORAGE
: aPath
= GetStoragePath(); break;
906 case PATH_TEMP
: aPath
= GetTempPath(); break;
907 case PATH_TEMPLATE
: aPath
= GetTemplatePath(); break;
908 case PATH_WORK
: aPath
= GetWorkPath(); break;
909 case PATH_UICONFIG
: aPath
= GetUIConfigPath(); break;
910 case PATH_FINGERPRINT
: aPath
= GetFingerprintPath(); break;
911 case PATH_USERCONFIG
:/*-Wall???*/ break;
912 case PATH_COUNT
: /*-Wall???*/ break;
915 sal_Int32 nPathIndex
= 0;
918 sal_Bool bIsURL
= sal_True
;
919 OUString aPathToken
= aPath
.getToken( 0, SEARCHPATH_DELIMITER
, nPathIndex
);
920 INetURLObject
aObj( aPathToken
);
921 if ( aObj
.HasError() )
925 if ( LocalFileHelper::ConvertPhysicalNameToURL( aPathToken
, aURL
) )
928 if ( aObj
.GetProtocol() == INET_PROT_VND_SUN_STAR_EXPAND
)
930 Reference
< XMacroExpander
> xMacroExpander
= theMacroExpander::get( ::comphelper::getProcessComponentContext() );
931 const OUString sExpandedPath
= xMacroExpander
->expandMacros( aObj
.GetURLPath( INetURLObject::DECODE_WITH_CHARSET
) );
932 aObj
.SetURL( sExpandedPath
);
935 sal_Int32 nIniIndex
= 0;
938 OUString aToken
= aIniFile
.getToken( 0, '/', nIniIndex
);
939 aObj
.insertName(aToken
);
941 while ( nIniIndex
>= 0 );
943 bRet
= ::utl::UCBContentHelper::Exists( aObj
.GetMainURL( INetURLObject::NO_DECODE
) );
949 OUString
sTmp(rIniFile
);
950 ::utl::LocalFileHelper::ConvertURLToPhysicalName(
951 aObj
.GetMainURL( INetURLObject::NO_DECODE
), sTmp
);
955 rIniFile
= aObj
.GetMainURL( INetURLObject::NO_DECODE
);
959 while ( nPathIndex
>= 0 );
966 // -----------------------------------------------------------------------
968 const LanguageTag
& SvtPathOptions::GetLanguageTag() const
970 return pImp
->GetLanguageTag();
973 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */