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 <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>
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>
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
;
57 #define SEARCHPATH_DELIMITER ';'
58 #define SIGN_STARTVARIABLE OUString( "$(" )
59 #define SIGN_ENDVARIABLE OUString( ")" )
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)"
67 #define STRPOS_NOTFOUND -1
71 VAR_NEEDS_SYSTEM_PATH
,
75 typedef boost::unordered_map
<OUString
, sal_Int32
, OUStringHash
> NameToHandleMap
;
77 typedef boost::unordered_map
<sal_Int32
, sal_Int32
> EnumToHandleMap
;
79 typedef boost::unordered_map
<OUString
, VarNameProperty
, OUStringHash
>
82 // class SvtPathOptions_Impl ---------------------------------------------
83 class SvtPathOptions_Impl
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
;
94 LanguageTag m_aLanguageTag
;
95 OUString m_aEmptyString
;
96 mutable ::osl::Mutex m_aMutex
;
99 SvtPathOptions_Impl();
101 // get the paths, not const because of using a mutex
102 const OUString
& GetPath( SvtPathOptions::Paths
);
103 const OUString
& GetAddinPath() { return GetPath( SvtPathOptions::PATH_ADDIN
); }
104 const OUString
& GetAutoCorrectPath() { return GetPath( SvtPathOptions::PATH_AUTOCORRECT
); }
105 const OUString
& GetAutoTextPath() { return GetPath( SvtPathOptions::PATH_AUTOTEXT
); }
106 const OUString
& GetBackupPath() { return GetPath( SvtPathOptions::PATH_BACKUP
); }
107 const OUString
& GetBasicPath() { return GetPath( SvtPathOptions::PATH_BASIC
); }
108 const OUString
& GetBitmapPath() { return GetPath( SvtPathOptions::PATH_BITMAP
); }
109 const OUString
& GetConfigPath() { return GetPath( SvtPathOptions::PATH_CONFIG
); }
110 const OUString
& GetDictionaryPath() { return GetPath( SvtPathOptions::PATH_DICTIONARY
); }
111 const OUString
& GetFavoritesPath() { return GetPath( SvtPathOptions::PATH_FAVORITES
); }
112 const OUString
& GetFilterPath() { return GetPath( SvtPathOptions::PATH_FILTER
); }
113 const OUString
& GetGalleryPath() { return GetPath( SvtPathOptions::PATH_GALLERY
); }
114 const OUString
& GetGraphicPath() { return GetPath( SvtPathOptions::PATH_GRAPHIC
); }
115 const OUString
& GetHelpPath() { return GetPath( SvtPathOptions::PATH_HELP
); }
116 const OUString
& GetLinguisticPath() { return GetPath( SvtPathOptions::PATH_LINGUISTIC
); }
117 const OUString
& GetModulePath() { return GetPath( SvtPathOptions::PATH_MODULE
); }
118 const OUString
& GetPalettePath() { return GetPath( SvtPathOptions::PATH_PALETTE
); }
119 const OUString
& GetPluginPath() { return GetPath( SvtPathOptions::PATH_PLUGIN
); }
120 const OUString
& GetStoragePath() { return GetPath( SvtPathOptions::PATH_STORAGE
); }
121 const OUString
& GetTempPath() { return GetPath( SvtPathOptions::PATH_TEMP
); }
122 const OUString
& GetTemplatePath() { return GetPath( SvtPathOptions::PATH_TEMPLATE
); }
123 const OUString
& GetUserConfigPath() { return GetPath( SvtPathOptions::PATH_USERCONFIG
); }
124 const OUString
& GetWorkPath() { return GetPath( SvtPathOptions::PATH_WORK
); }
125 const OUString
& GetUIConfigPath() { return GetPath( SvtPathOptions::PATH_UICONFIG
); }
126 const OUString
& GetFingerprintPath() { return GetPath( SvtPathOptions::PATH_FINGERPRINT
); }
129 void SetPath( SvtPathOptions::Paths
, const OUString
& rNewPath
);
130 void SetAddinPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_ADDIN
, rPath
); }
131 void SetAutoCorrectPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_AUTOCORRECT
, rPath
); }
132 void SetAutoTextPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_AUTOTEXT
, rPath
); }
133 void SetBackupPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_BACKUP
, rPath
); }
134 void SetBasicPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_BASIC
, rPath
); }
135 void SetBitmapPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_BITMAP
, rPath
); }
136 void SetConfigPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_CONFIG
, rPath
); }
137 void SetDictionaryPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_DICTIONARY
, rPath
); }
138 void SetFavoritesPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_FAVORITES
, rPath
); }
139 void SetFilterPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_FILTER
, rPath
); }
140 void SetGalleryPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_GALLERY
, rPath
); }
141 void SetGraphicPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_GRAPHIC
, rPath
); }
142 void SetHelpPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_HELP
, rPath
); }
143 void SetLinguisticPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_LINGUISTIC
, rPath
); }
144 void SetModulePath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_MODULE
, rPath
); }
145 void SetPalettePath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_PALETTE
, rPath
); }
146 void SetPluginPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_PLUGIN
, rPath
); }
147 void SetStoragePath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_STORAGE
, rPath
); }
148 void SetTempPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_TEMP
, rPath
); }
149 void SetTemplatePath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_TEMPLATE
, rPath
); }
150 void SetUserConfigPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_USERCONFIG
, rPath
); }
151 void SetWorkPath( const OUString
& rPath
) { SetPath( SvtPathOptions::PATH_WORK
, rPath
); }
153 OUString
SubstVar( const OUString
& rVar
) const;
154 OUString
ExpandMacros( const OUString
& rPath
) const;
155 OUString
UsePathVariables( const OUString
& rPath
) const;
157 const LanguageTag
& GetLanguageTag() const { return m_aLanguageTag
; }
160 // global ----------------------------------------------------------------
162 static SvtPathOptions_Impl
* pOptions
= NULL
;
163 static sal_Int32 nRefCount
= 0;
165 // functions -------------------------------------------------------------
166 struct PropertyStruct
168 const char* pPropName
; // The ascii name of the Office path
169 SvtPathOptions::Paths ePath
; // The enum value used by SvtPathOptions
172 struct VarNameAttribute
174 const char* pVarName
; // The name of the path variable
175 VarNameProperty eVarProperty
; // Which return value is needed by this path variable
178 static const PropertyStruct aPropNames
[] =
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
}
206 static const VarNameAttribute aVarNameAttribute
[] =
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)
214 // class SvtPathOptions_Impl ---------------------------------------------
216 const OUString
& SvtPathOptions_Impl::GetPath( SvtPathOptions::Paths ePath
)
218 if ( ePath
>= SvtPathOptions::PATH_COUNT
)
219 return m_aEmptyString
;
221 ::osl::MutexGuard
aGuard( m_aMutex
);
227 sal_Int32 nHandle
= m_aMapEnumToPropHandle
[ (sal_Int32
)ePath
];
229 // Substitution is done by the service itself using the substition service
230 Any a
= m_xPathSettings
->getFastPropertyValue( nHandle
);
232 if( ePath
== SvtPathOptions::PATH_ADDIN
||
233 ePath
== SvtPathOptions::PATH_FILTER
||
234 ePath
== SvtPathOptions::PATH_HELP
||
235 ePath
== SvtPathOptions::PATH_MODULE
||
236 ePath
== SvtPathOptions::PATH_PLUGIN
||
237 ePath
== SvtPathOptions::PATH_STORAGE
240 // These office paths have to be converted to system pates
241 utl::LocalFileHelper::ConvertURLToPhysicalName( aPathValue
, aResult
);
242 aPathValue
= aResult
;
245 m_aPathArray
[ ePath
] = aPathValue
;
246 return m_aPathArray
[ ePath
];
248 catch (UnknownPropertyException
&)
252 return m_aEmptyString
;
255 void SvtPathOptions_Impl::SetPath( SvtPathOptions::Paths ePath
, const OUString
& rNewPath
)
257 ::osl::MutexGuard
aGuard( m_aMutex
);
259 if ( ePath
< SvtPathOptions::PATH_COUNT
)
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
:
274 // These office paths have to be convert back to UCB-URL's
275 utl::LocalFileHelper::ConvertPhysicalNameToURL( rNewPath
, aResult
);
281 aNewValue
= rNewPath
;
284 // Resubstitution is done by the service itself using the substition service
288 m_xPathSettings
->setFastPropertyValue( m_aMapEnumToPropHandle
[ (sal_Int32
)ePath
], a
);
290 catch (const Exception
& e
)
292 SAL_WARN("unotools.config", "SetPath: exception: " << e
.Message
);
297 OUString
SvtPathOptions_Impl::ExpandMacros( const OUString
& rPath
) const
299 OUString
sExpanded( rPath
);
301 const INetURLObject
aParser( rPath
);
302 if ( aParser
.GetProtocol() == INET_PROT_VND_SUN_STAR_EXPAND
)
303 sExpanded
= m_xMacroExpander
->expandMacros( aParser
.GetURLPath( INetURLObject::DECODE_WITH_CHARSET
) );
308 OUString
SvtPathOptions_Impl::UsePathVariables( const OUString
& rPath
) const
310 return m_xSubstVariables
->reSubstituteVariables( rPath
);
313 OUString
SvtPathOptions_Impl::SubstVar( const OUString
& rVar
) const
315 // Don't work at parameter-string directly. Copy it.
316 OUString aWorkText
= rVar
;
318 // Convert the returned path to system path!
319 bool bConvertLocal
= false;
321 // Search for first occurrence of "$(...".
322 sal_Int32 nPosition
= aWorkText
.indexOf( SIGN_STARTVARIABLE
); // = first position of "$(" in string
323 sal_Int32 nLength
= 0; // = count of letters from "$(" to ")" in string
325 // Have we found any variable like "$(...)"?
326 if ( nPosition
!= STRPOS_NOTFOUND
)
328 // Yes; Get length of found variable.
329 // If no ")" was found - nLength is set to 0 by default! see before.
330 sal_Int32 nEndPosition
= aWorkText
.indexOf( SIGN_ENDVARIABLE
, nPosition
);
331 if ( nEndPosition
!= STRPOS_NOTFOUND
)
332 nLength
= nEndPosition
- nPosition
+ 1;
335 // Is there another path variable?
336 while ( ( nPosition
!= STRPOS_NOTFOUND
) && ( nLength
> 0 ) )
338 // YES; Get the next variable for replace.
339 OUString aSubString
= aWorkText
.copy( nPosition
, nLength
);
340 aSubString
= aSubString
.toAsciiLowerCase();
342 // Look for special variable that needs a system path.
343 VarNameToEnumMap::const_iterator pIter
= m_aMapVarNamesToEnum
.find( aSubString
);
344 if ( pIter
!= m_aMapVarNamesToEnum
.end() )
345 bConvertLocal
= true;
347 nPosition
+= nLength
;
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 if ( nPosition
+ 1 > aWorkText
.getLength() )
353 // Position is out of range. Break loop!
354 nPosition
= STRPOS_NOTFOUND
;
359 // Else; Position is valid. Search for next variable.
360 nPosition
= aWorkText
.indexOf( SIGN_STARTVARIABLE
, nPosition
);
361 // Have we found any variable like "$(...)"?
362 if ( nPosition
!= STRPOS_NOTFOUND
)
364 // Yes; Get length of found variable. If no ")" was found - nLength must set to 0!
366 sal_Int32 nEndPosition
= aWorkText
.indexOf( SIGN_ENDVARIABLE
, nPosition
);
367 if ( nEndPosition
!= STRPOS_NOTFOUND
)
368 nLength
= nEndPosition
- nPosition
+ 1;
373 aWorkText
= m_xSubstVariables
->substituteVariables( rVar
, false );
377 // Convert the URL to a system path for special path variables
379 utl::LocalFileHelper::ConvertURLToPhysicalName( aWorkText
, aReturn
);
386 SvtPathOptions_Impl::SvtPathOptions_Impl() :
387 m_aPathArray( (sal_Int32
)SvtPathOptions::PATH_COUNT
),
388 m_aLanguageTag( LANGUAGE_DONTKNOW
)
390 Reference
< XComponentContext
> xContext
= comphelper::getProcessComponentContext();
392 // Create necessary services
393 Reference
< XPathSettings
> xPathSettings
= thePathSettings::get(xContext
);
394 m_xPathSettings
.set( xPathSettings
, UNO_QUERY_THROW
);
395 m_xSubstVariables
.set( PathSubstitution::create(xContext
) );
396 m_xMacroExpander
= theMacroExpander::get(xContext
);
398 // Create temporary hash map to have a mapping between property names and property handles
399 Reference
< XPropertySetInfo
> xPropSetInfo
= xPathSettings
->getPropertySetInfo();
400 Sequence
< Property
> aPathPropSeq
= xPropSetInfo
->getProperties();
402 NameToHandleMap aTempHashMap
;
403 for ( sal_Int32 n
= 0; n
< aPathPropSeq
.getLength(); n
++ )
405 const com::sun::star::beans::Property
& aProperty
= aPathPropSeq
[n
];
406 aTempHashMap
.insert( NameToHandleMap::value_type( aProperty
.Name
, aProperty
.Handle
));
409 // Create mapping between internal enum (SvtPathOptions::Paths) and property handle
410 sal_Int32 nCount
= sizeof( aPropNames
) / sizeof( PropertyStruct
);
412 for ( i
= 0; i
< nCount
; i
++ )
414 NameToHandleMap::const_iterator pIter
=
415 aTempHashMap
.find( OUString::createFromAscii( aPropNames
[i
].pPropName
));
417 if ( pIter
!= aTempHashMap
.end() )
419 sal_Int32 nHandle
= pIter
->second
;
420 sal_Int32 nEnum
= aPropNames
[i
].ePath
;
421 m_aMapEnumToPropHandle
.insert( EnumToHandleMap::value_type( nEnum
, nHandle
));
425 // Create hash map for path variables that need a system path as a return value!
426 nCount
= sizeof( aVarNameAttribute
) / sizeof( VarNameAttribute
);
427 for ( i
= 0; i
< nCount
; i
++ )
429 m_aMapVarNamesToEnum
.insert( VarNameToEnumMap::value_type(
430 OUString::createFromAscii( aVarNameAttribute
[i
].pVarName
),
431 aVarNameAttribute
[i
].eVarProperty
));
434 // Set language type!
435 m_aLanguageTag
.reset( ConfigManager::getLocale() );
438 // class SvtPathOptions --------------------------------------------------
440 namespace { struct lclMutex
: public rtl::Static
< ::osl::Mutex
, lclMutex
> {}; }
442 SvtPathOptions::SvtPathOptions()
444 // Global access, must be guarded (multithreading)
445 ::osl::MutexGuard
aGuard( lclMutex::get() );
448 pOptions
= new SvtPathOptions_Impl
;
449 ItemHolder1::holdConfigItem(E_PATHOPTIONS
);
455 SvtPathOptions::~SvtPathOptions()
457 // Global access, must be guarded (multithreading)
458 ::osl::MutexGuard
aGuard( lclMutex::get() );
465 const OUString
& SvtPathOptions::GetAddinPath() const
467 return pImp
->GetAddinPath();
470 const OUString
& SvtPathOptions::GetAutoCorrectPath() const
472 return pImp
->GetAutoCorrectPath();
475 const OUString
& SvtPathOptions::GetAutoTextPath() const
477 return pImp
->GetAutoTextPath();
480 const OUString
& SvtPathOptions::GetBackupPath() const
482 return pImp
->GetBackupPath();
485 const OUString
& SvtPathOptions::GetBasicPath() const
487 return pImp
->GetBasicPath();
490 const OUString
& SvtPathOptions::GetBitmapPath() const
492 return pImp
->GetBitmapPath();
495 const OUString
& SvtPathOptions::GetConfigPath() const
497 return pImp
->GetConfigPath();
500 const OUString
& SvtPathOptions::GetDictionaryPath() const
502 return pImp
->GetDictionaryPath();
505 const OUString
& SvtPathOptions::GetFavoritesPath() const
507 return pImp
->GetFavoritesPath();
510 const OUString
& SvtPathOptions::GetFilterPath() const
512 return pImp
->GetFilterPath();
515 const OUString
& SvtPathOptions::GetGalleryPath() const
517 return pImp
->GetGalleryPath();
520 const OUString
& SvtPathOptions::GetGraphicPath() const
522 return pImp
->GetGraphicPath();
525 const OUString
& SvtPathOptions::GetHelpPath() const
527 return pImp
->GetHelpPath();
530 const OUString
& SvtPathOptions::GetLinguisticPath() const
532 return pImp
->GetLinguisticPath();
535 const OUString
& SvtPathOptions::GetFingerprintPath() const
537 return pImp
->GetFingerprintPath();
540 const OUString
& SvtPathOptions::GetModulePath() const
542 return pImp
->GetModulePath();
545 const OUString
& SvtPathOptions::GetPalettePath() const
547 return pImp
->GetPalettePath();
550 const OUString
& SvtPathOptions::GetPluginPath() const
552 return pImp
->GetPluginPath();
555 const OUString
& SvtPathOptions::GetStoragePath() const
557 return pImp
->GetStoragePath();
560 const OUString
& SvtPathOptions::GetTempPath() const
562 return pImp
->GetTempPath();
565 const OUString
& SvtPathOptions::GetTemplatePath() const
567 return pImp
->GetTemplatePath();
570 const OUString
& SvtPathOptions::GetUserConfigPath() const
572 return pImp
->GetUserConfigPath();
575 const OUString
& SvtPathOptions::GetUIConfigPath() const
577 return pImp
->GetUIConfigPath();
580 const OUString
& SvtPathOptions::GetWorkPath() const
582 return pImp
->GetWorkPath();
585 void SvtPathOptions::SetAddinPath( const OUString
& rPath
)
587 pImp
->SetAddinPath( rPath
);
590 void SvtPathOptions::SetAutoCorrectPath( const OUString
& rPath
)
592 pImp
->SetAutoCorrectPath( rPath
);
595 void SvtPathOptions::SetAutoTextPath( const OUString
& rPath
)
597 pImp
->SetAutoTextPath( rPath
);
600 void SvtPathOptions::SetBackupPath( const OUString
& rPath
)
602 pImp
->SetBackupPath( rPath
);
605 void SvtPathOptions::SetBasicPath( const OUString
& rPath
)
607 pImp
->SetBasicPath( rPath
);
610 void SvtPathOptions::SetBitmapPath( const OUString
& rPath
)
612 pImp
->SetBitmapPath( rPath
);
615 void SvtPathOptions::SetConfigPath( const OUString
& rPath
)
617 pImp
->SetConfigPath( rPath
);
620 void SvtPathOptions::SetDictionaryPath( const OUString
& rPath
)
622 pImp
->SetDictionaryPath( rPath
);
625 void SvtPathOptions::SetFavoritesPath( const OUString
& rPath
)
627 pImp
->SetFavoritesPath( rPath
);
630 void SvtPathOptions::SetFilterPath( const OUString
& rPath
)
632 pImp
->SetFilterPath( rPath
);
635 void SvtPathOptions::SetGalleryPath( const OUString
& rPath
)
637 pImp
->SetGalleryPath( rPath
);
640 void SvtPathOptions::SetGraphicPath( const OUString
& rPath
)
642 pImp
->SetGraphicPath( rPath
);
645 void SvtPathOptions::SetHelpPath( const OUString
& rPath
)
647 pImp
->SetHelpPath( rPath
);
650 void SvtPathOptions::SetLinguisticPath( const OUString
& rPath
)
652 pImp
->SetLinguisticPath( rPath
);
655 void SvtPathOptions::SetModulePath( const OUString
& rPath
)
657 pImp
->SetModulePath( rPath
);
660 void SvtPathOptions::SetPalettePath( const OUString
& rPath
)
662 pImp
->SetPalettePath( rPath
);
665 void SvtPathOptions::SetPluginPath( const OUString
& rPath
)
667 pImp
->SetPluginPath( rPath
);
670 void SvtPathOptions::SetStoragePath( const OUString
& rPath
)
672 pImp
->SetStoragePath( rPath
);
675 void SvtPathOptions::SetTempPath( const OUString
& rPath
)
677 pImp
->SetTempPath( rPath
);
680 void SvtPathOptions::SetTemplatePath( const OUString
& rPath
)
682 pImp
->SetTemplatePath( rPath
);
685 void SvtPathOptions::SetUserConfigPath( const OUString
& rPath
)
687 pImp
->SetUserConfigPath( rPath
);
690 void SvtPathOptions::SetWorkPath( const OUString
& rPath
)
692 pImp
->SetWorkPath( rPath
);
695 OUString
SvtPathOptions::SubstituteVariable( const OUString
& rVar
) const
697 return pImp
->SubstVar( rVar
);
700 OUString
SvtPathOptions::ExpandMacros( const OUString
& rPath
) const
702 return pImp
->ExpandMacros( rPath
);
705 OUString
SvtPathOptions::UseVariable( const OUString
& rPath
) const
707 return pImp
->UsePathVariables( rPath
);
710 bool SvtPathOptions::SearchFile( OUString
& rIniFile
, Paths ePath
)
712 // check parameter: empty inifile name?
713 if ( rIniFile
.isEmpty() )
715 SAL_WARN( "unotools.config", "SvtPathOptions::SearchFile(): invalid parameter" );
719 OUString aIniFile
= pImp
->SubstVar( rIniFile
);
724 case PATH_USERCONFIG
:
728 INetURLObject
aObj( GetUserConfigPath() );
730 sal_Int32 nIniIndex
= 0;
733 OUString aToken
= aIniFile
.getToken( 0, '/', nIniIndex
);
734 aObj
.insertName(aToken
);
736 while ( nIniIndex
>= 0 );
738 if ( !::utl::UCBContentHelper::Exists( aObj
.GetMainURL( INetURLObject::NO_DECODE
) ) )
740 aObj
.SetSmartURL( GetConfigPath() );
741 aObj
.insertName( aIniFile
);
742 bRet
= ::utl::UCBContentHelper::Exists( aObj
.GetMainURL( INetURLObject::NO_DECODE
) );
746 rIniFile
= aObj
.GetMainURL( INetURLObject::NO_DECODE
);
756 case PATH_ADDIN
: aPath
= GetAddinPath(); break;
757 case PATH_AUTOCORRECT
: aPath
= GetAutoCorrectPath(); break;
758 case PATH_AUTOTEXT
: aPath
= GetAutoTextPath(); break;
759 case PATH_BACKUP
: aPath
= GetBackupPath(); break;
760 case PATH_BASIC
: aPath
= GetBasicPath(); break;
761 case PATH_BITMAP
: aPath
= GetBitmapPath(); break;
762 case PATH_CONFIG
: aPath
= GetConfigPath(); break;
763 case PATH_DICTIONARY
: aPath
= GetDictionaryPath(); break;
764 case PATH_FAVORITES
: aPath
= GetFavoritesPath(); break;
765 case PATH_FILTER
: aPath
= GetFilterPath(); break;
766 case PATH_GALLERY
: aPath
= GetGalleryPath(); break;
767 case PATH_GRAPHIC
: aPath
= GetGraphicPath(); break;
768 case PATH_HELP
: aPath
= GetHelpPath(); break;
769 case PATH_LINGUISTIC
: aPath
= GetLinguisticPath(); break;
770 case PATH_MODULE
: aPath
= GetModulePath(); break;
771 case PATH_PALETTE
: aPath
= GetPalettePath(); break;
772 case PATH_PLUGIN
: aPath
= GetPluginPath(); break;
773 case PATH_STORAGE
: aPath
= GetStoragePath(); break;
774 case PATH_TEMP
: aPath
= GetTempPath(); break;
775 case PATH_TEMPLATE
: aPath
= GetTemplatePath(); break;
776 case PATH_WORK
: aPath
= GetWorkPath(); break;
777 case PATH_UICONFIG
: aPath
= GetUIConfigPath(); break;
778 case PATH_FINGERPRINT
: aPath
= GetFingerprintPath(); break;
779 case PATH_USERCONFIG
:/*-Wall???*/ break;
780 case PATH_COUNT
: /*-Wall???*/ break;
783 sal_Int32 nPathIndex
= 0;
787 OUString aPathToken
= aPath
.getToken( 0, SEARCHPATH_DELIMITER
, nPathIndex
);
788 INetURLObject
aObj( aPathToken
);
789 if ( aObj
.HasError() )
793 if ( LocalFileHelper::ConvertPhysicalNameToURL( aPathToken
, aURL
) )
796 if ( aObj
.GetProtocol() == INET_PROT_VND_SUN_STAR_EXPAND
)
798 Reference
< XMacroExpander
> xMacroExpander
= theMacroExpander::get( ::comphelper::getProcessComponentContext() );
799 const OUString sExpandedPath
= xMacroExpander
->expandMacros( aObj
.GetURLPath( INetURLObject::DECODE_WITH_CHARSET
) );
800 aObj
.SetURL( sExpandedPath
);
803 sal_Int32 nIniIndex
= 0;
806 OUString aToken
= aIniFile
.getToken( 0, '/', nIniIndex
);
807 aObj
.insertName(aToken
);
809 while ( nIniIndex
>= 0 );
811 bRet
= ::utl::UCBContentHelper::Exists( aObj
.GetMainURL( INetURLObject::NO_DECODE
) );
817 OUString
sTmp(rIniFile
);
818 ::utl::LocalFileHelper::ConvertURLToPhysicalName(
819 aObj
.GetMainURL( INetURLObject::NO_DECODE
), sTmp
);
823 rIniFile
= aObj
.GetMainURL( INetURLObject::NO_DECODE
);
827 while ( nPathIndex
>= 0 );
834 const LanguageTag
& SvtPathOptions::GetLanguageTag() const
836 return pImp
->GetLanguageTag();
839 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */