1 /*************************************************************************
3 * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 * Copyright 2008 by Sun Microsystems, Inc.
7 * OpenOffice.org - a multi-platform office productivity suite
9 * $RCSfile: pathoptions.cxx,v $
12 * This file is part of OpenOffice.org.
14 * OpenOffice.org is free software: you can redistribute it and/or modify
15 * it under the terms of the GNU Lesser General Public License version 3
16 * only, as published by the Free Software Foundation.
18 * OpenOffice.org is distributed in the hope that it will be useful,
19 * but WITHOUT ANY WARRANTY; without even the implied warranty of
20 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
21 * GNU Lesser General Public License version 3 for more details
22 * (a copy is included in the LICENSE file that accompanied this code).
24 * You should have received a copy of the GNU Lesser General Public License
25 * version 3 along with OpenOffice.org. If not, see
26 * <http://www.openoffice.org/license.html>
27 * for a copy of the LGPLv3 License.
29 ************************************************************************/
31 // MARKER(update_precomp.py): autogen include statement, do not remove
32 #include "precompiled_svtools.hxx"
36 #include <svtools/pathoptions.hxx>
37 #include <unotools/configitem.hxx>
38 #include <unotools/configmgr.hxx>
39 #include <tools/debug.hxx>
40 #include <tools/resmgr.hxx>
41 #include <tools/urlobj.hxx>
42 #include <com/sun/star/uno/Any.hxx>
43 #include <com/sun/star/uno/Sequence.hxx>
44 #include <osl/mutex.hxx>
45 #include <osl/file.hxx>
46 #include <unotools/localfilehelper.hxx>
47 #include <unotools/bootstrap.hxx>
49 #include <unotools/ucbhelper.hxx>
50 #include <vos/process.hxx>
51 #include <comphelper/processfactory.hxx>
52 #include <com/sun/star/beans/XFastPropertySet.hpp>
53 #include <com/sun/star/beans/XPropertySet.hpp>
54 #include <com/sun/star/beans/PropertyAttribute.hpp>
55 #include <com/sun/star/beans/XPropertySetInfo.hpp>
56 #include <com/sun/star/util/XStringSubstitution.hpp>
57 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
58 #include <rtl/instance.hxx>
60 #include <itemholder1.hxx>
68 using namespace com::sun::star::uno
;
69 using namespace com::sun::star::beans
;
70 using namespace com::sun::star::util
;
71 using namespace com::sun::star::lang
;
73 // define ----------------------------------------------------------------
75 #define SEARCHPATH_DELIMITER ';'
77 #define ASCII_STR(s) OUString( RTL_CONSTASCII_USTRINGPARAM(s) )
79 #define SIGN_STARTVARIABLE ASCII_STR("$(")
80 #define SIGN_ENDVARIABLE ASCII_STR(")")
82 // Supported variables by the old SvtPathOptions implementation
83 #define SUBSTITUTE_INST "$(inst)"
84 #define SUBSTITUTE_PROG "$(prog)"
85 #define SUBSTITUTE_USER "$(user)"
86 #define SUBSTITUTE_INSTPATH "$(instpath)"
87 #define SUBSTITUTE_PROGPATH "$(progpath)"
88 #define SUBSTITUTE_USERPATH "$(userpath)"
89 #define SUBSTITUTE_INSTURL "$(insturl)"
90 #define SUBSTITUTE_PROGURL "$(progurl)"
91 #define SUBSTITUTE_USERURL "$(userurl)"
92 #define SUBSTITUTE_PATH "$(path)"
93 //#define SUBSTITUTE_LANG "$(lang)"
94 #define SUBSTITUTE_LANGID "$(langid)"
95 #define SUBSTITUTE_VLANG "$(vlang)"
96 #define SUBSTITUTE_WORKDIRURL "$(workdirurl)"
98 #define STRPOS_NOTFOUND -1
100 struct OUStringHashCode
102 size_t operator()( const ::rtl::OUString
& sString
) const
104 return sString
.hashCode();
110 VAR_NEEDS_SYSTEM_PATH
,
114 class NameToHandleMap
: public ::std::hash_map
< ::rtl::OUString
, sal_Int32
, OUStringHashCode
, ::std::equal_to
< ::rtl::OUString
> >
117 inline void free() { NameToHandleMap().swap( *this ); }
120 class EnumToHandleMap
: public ::std::hash_map
< sal_Int32
, sal_Int32
, std::hash
< sal_Int32
>, std::equal_to
< sal_Int32
> >
123 inline void free() { EnumToHandleMap().swap( *this ); }
126 class VarNameToEnumMap
: public ::std::hash_map
< OUString
, VarNameProperty
, OUStringHashCode
, ::std::equal_to
< OUString
> >
129 inline void free() { VarNameToEnumMap().swap( *this ); }
133 // class SvtPathOptions_Impl ---------------------------------------------
134 class SvtPathOptions_Impl
137 // Local variables to return const references
138 std::vector
< String
> m_aPathArray
;
139 Reference
< XFastPropertySet
> m_xPathSettings
;
140 Reference
< XStringSubstitution
> m_xSubstVariables
;
141 mutable EnumToHandleMap m_aMapEnumToPropHandle
;
142 VarNameToEnumMap m_aMapVarNamesToEnum
;
144 ::com::sun::star::lang::Locale m_aLocale
;
145 String m_aEmptyString
;
146 mutable ::osl::Mutex m_aMutex
;
149 SvtPathOptions_Impl();
151 // get the pathes, not const because of using a mutex
152 const String
& GetPath( SvtPathOptions::Pathes
);
153 const String
& GetAddinPath() { return GetPath( SvtPathOptions::PATH_ADDIN
); }
154 const String
& GetAutoCorrectPath() { return GetPath( SvtPathOptions::PATH_AUTOCORRECT
); }
155 const String
& GetAutoTextPath() { return GetPath( SvtPathOptions::PATH_AUTOTEXT
); }
156 const String
& GetBackupPath() { return GetPath( SvtPathOptions::PATH_BACKUP
); }
157 const String
& GetBasicPath() { return GetPath( SvtPathOptions::PATH_BASIC
); }
158 const String
& GetBitmapPath() { return GetPath( SvtPathOptions::PATH_BITMAP
); }
159 const String
& GetConfigPath() { return GetPath( SvtPathOptions::PATH_CONFIG
); }
160 const String
& GetDictionaryPath() { return GetPath( SvtPathOptions::PATH_DICTIONARY
); }
161 const String
& GetFavoritesPath() { return GetPath( SvtPathOptions::PATH_FAVORITES
); }
162 const String
& GetFilterPath() { return GetPath( SvtPathOptions::PATH_FILTER
); }
163 const String
& GetGalleryPath() { return GetPath( SvtPathOptions::PATH_GALLERY
); }
164 const String
& GetGraphicPath() { return GetPath( SvtPathOptions::PATH_GRAPHIC
); }
165 const String
& GetHelpPath() { return GetPath( SvtPathOptions::PATH_HELP
); }
166 const String
& GetLinguisticPath() { return GetPath( SvtPathOptions::PATH_LINGUISTIC
); }
167 const String
& GetModulePath() { return GetPath( SvtPathOptions::PATH_MODULE
); }
168 const String
& GetPalettePath() { return GetPath( SvtPathOptions::PATH_PALETTE
); }
169 const String
& GetPluginPath() { return GetPath( SvtPathOptions::PATH_PLUGIN
); }
170 const String
& GetStoragePath() { return GetPath( SvtPathOptions::PATH_STORAGE
); }
171 const String
& GetTempPath() { return GetPath( SvtPathOptions::PATH_TEMP
); }
172 const String
& GetTemplatePath() { return GetPath( SvtPathOptions::PATH_TEMPLATE
); }
173 const String
& GetUserConfigPath() { return GetPath( SvtPathOptions::PATH_USERCONFIG
); }
174 const String
& GetWorkPath() { return GetPath( SvtPathOptions::PATH_WORK
); }
175 const String
& GetUIConfigPath() { return GetPath( SvtPathOptions::PATH_UICONFIG
); }
176 const String
& GetFingerprintPath() { return GetPath( SvtPathOptions::PATH_FINGERPRINT
); }
179 void SetPath( SvtPathOptions::Pathes
, const String
& rNewPath
);
180 void SetAddinPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_ADDIN
, rPath
); }
181 void SetAutoCorrectPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_AUTOCORRECT
, rPath
); }
182 void SetAutoTextPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_AUTOTEXT
, rPath
); }
183 void SetBackupPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_BACKUP
, rPath
); }
184 void SetBasicPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_BASIC
, rPath
); }
185 void SetBitmapPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_BITMAP
, rPath
); }
186 void SetConfigPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_CONFIG
, rPath
); }
187 void SetDictionaryPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_DICTIONARY
, rPath
); }
188 void SetFavoritesPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_FAVORITES
, rPath
); }
189 void SetFilterPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_FILTER
, rPath
); }
190 void SetGalleryPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_GALLERY
, rPath
); }
191 void SetGraphicPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_GRAPHIC
, rPath
); }
192 void SetHelpPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_HELP
, rPath
); }
193 void SetLinguisticPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_LINGUISTIC
, rPath
); }
194 void SetModulePath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_MODULE
, rPath
); }
195 void SetPalettePath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_PALETTE
, rPath
); }
196 void SetPluginPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_PLUGIN
, rPath
); }
197 void SetStoragePath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_STORAGE
, rPath
); }
198 void SetTempPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_TEMP
, rPath
); }
199 void SetTemplatePath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_TEMPLATE
, rPath
); }
200 void SetUserConfigPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_USERCONFIG
, rPath
); }
201 void SetWorkPath( const String
& rPath
) { SetPath( SvtPathOptions::PATH_WORK
, rPath
); }
203 rtl::OUString
SubstVar( const rtl::OUString
& rVar
);
204 rtl::OUString
SubstituteAndConvert( const rtl::OUString
& rPath
);
205 rtl::OUString
UsePathVariables( const rtl::OUString
& rPath
);
207 ::com::sun::star::lang::Locale
GetLocale() const { return m_aLocale
; }
209 BOOL
IsPathReadonly(SvtPathOptions::Pathes ePath
)const;
212 // global ----------------------------------------------------------------
214 static SvtPathOptions_Impl
* pOptions
= NULL
;
215 static sal_Int32 nRefCount
= 0;
217 // functions -------------------------------------------------------------
218 struct PropertyStruct
220 const char* pPropName
; // The ascii name of the Office path
221 SvtPathOptions::Pathes ePath
; // The enum value used by SvtPathOptions
224 struct VarNameAttribute
226 const char* pVarName
; // The name of the path variable
227 VarNameProperty eVarProperty
; // Which return value is needed by this path variable
230 static PropertyStruct aPropNames
[] =
232 { "Addin", SvtPathOptions::PATH_ADDIN
},
233 { "AutoCorrect", SvtPathOptions::PATH_AUTOCORRECT
},
234 { "AutoText", SvtPathOptions::PATH_AUTOTEXT
},
235 { "Backup", SvtPathOptions::PATH_BACKUP
},
236 { "Basic", SvtPathOptions::PATH_BASIC
},
237 { "Bitmap", SvtPathOptions::PATH_BITMAP
},
238 { "Config", SvtPathOptions::PATH_CONFIG
},
239 { "Dictionary", SvtPathOptions::PATH_DICTIONARY
},
240 { "Favorite", SvtPathOptions::PATH_FAVORITES
},
241 { "Filter", SvtPathOptions::PATH_FILTER
},
242 { "Gallery", SvtPathOptions::PATH_GALLERY
},
243 { "Graphic", SvtPathOptions::PATH_GRAPHIC
},
244 { "Help", SvtPathOptions::PATH_HELP
},
245 { "Linguistic", SvtPathOptions::PATH_LINGUISTIC
},
246 { "Module", SvtPathOptions::PATH_MODULE
},
247 { "Palette", SvtPathOptions::PATH_PALETTE
},
248 { "Plugin", SvtPathOptions::PATH_PLUGIN
},
249 { "Storage", SvtPathOptions::PATH_STORAGE
},
250 { "Temp", SvtPathOptions::PATH_TEMP
},
251 { "Template", SvtPathOptions::PATH_TEMPLATE
},
252 { "UserConfig", SvtPathOptions::PATH_USERCONFIG
},
253 { "Work", SvtPathOptions::PATH_WORK
},
254 { "UIConfig", SvtPathOptions::PATH_UICONFIG
},
255 { "Fingerprint", SvtPathOptions::PATH_FINGERPRINT
}
258 static VarNameAttribute aVarNameAttribute
[] =
260 { SUBSTITUTE_INSTPATH
, VAR_NEEDS_SYSTEM_PATH
}, // $(instpath)
261 { SUBSTITUTE_PROGPATH
, VAR_NEEDS_SYSTEM_PATH
}, // $(progpath)
262 { SUBSTITUTE_USERPATH
, VAR_NEEDS_SYSTEM_PATH
}, // $(userpath)
263 { SUBSTITUTE_PATH
, VAR_NEEDS_SYSTEM_PATH
}, // $(path)
268 static Sequence
< OUString
> GetPathPropertyNames()
270 const int nCount
= sizeof( aPropNames
) / sizeof( PropertyStruct
);
271 Sequence
< OUString
> aNames( nCount
);
272 OUString
* pNames
= aNames
.getArray();
273 for ( int i
= 0; i
< nCount
; i
++ )
274 pNames
[i
] = OUString::createFromAscii( aPropNames
[i
].pPropName
);
280 // class SvtPathOptions_Impl ---------------------------------------------
282 const String
& SvtPathOptions_Impl::GetPath( SvtPathOptions::Pathes ePath
)
284 ::osl::MutexGuard
aGuard( m_aMutex
);
286 if ( ePath
< SvtPathOptions::PATH_COUNT
)
290 sal_Int32 nHandle
= m_aMapEnumToPropHandle
[ (sal_Int32
)ePath
];
292 // Substitution is done by the service itself using the substition service
293 Any a
= m_xPathSettings
->getFastPropertyValue( nHandle
);
295 if( ePath
== SvtPathOptions::PATH_ADDIN
||
296 ePath
== SvtPathOptions::PATH_FILTER
||
297 ePath
== SvtPathOptions::PATH_HELP
||
298 ePath
== SvtPathOptions::PATH_MODULE
||
299 ePath
== SvtPathOptions::PATH_PLUGIN
||
300 ePath
== SvtPathOptions::PATH_STORAGE
303 // These office paths have to be converted to system pathes
304 utl::LocalFileHelper::ConvertURLToPhysicalName( aPathValue
, aResult
);
305 // FIXME: The initial value (not modified by SetPath) is just a path, so the URL-conversion fails.
306 // The best solution is to fix the module xmlhelp to accept the URL. Then we could remove
307 // all these ugly conversions.
308 if ( aResult
.Len() != 0 )
309 aPathValue
= aResult
;
312 m_aPathArray
[ ePath
] = aPathValue
;
313 return m_aPathArray
[ ePath
];
316 return m_aEmptyString
;
318 // -----------------------------------------------------------------------
319 BOOL
SvtPathOptions_Impl::IsPathReadonly(SvtPathOptions::Pathes ePath
)const
321 ::osl::MutexGuard
aGuard( m_aMutex
);
322 BOOL bReadonly
= FALSE
;
323 if ( ePath
< SvtPathOptions::PATH_COUNT
)
325 Reference
<XPropertySet
> xPrSet(m_xPathSettings
, UNO_QUERY
);
328 Reference
<XPropertySetInfo
> xInfo
= xPrSet
->getPropertySetInfo();
329 const char* pA
= aPropNames
[ePath
].pPropName
;
330 ::rtl::OUString sU
= OUString::createFromAscii(pA
);
331 Property aProperty
= xInfo
->getPropertyByName(sU
);
332 bReadonly
= 0 != (aProperty
.Attributes
& PropertyAttribute::READONLY
);
337 // -----------------------------------------------------------------------
339 void SvtPathOptions_Impl::SetPath( SvtPathOptions::Pathes ePath
, const String
& rNewPath
)
341 ::osl::MutexGuard
aGuard( m_aMutex
);
343 if ( ePath
< SvtPathOptions::PATH_COUNT
)
351 case SvtPathOptions::PATH_ADDIN
:
352 case SvtPathOptions::PATH_FILTER
:
353 case SvtPathOptions::PATH_HELP
:
354 case SvtPathOptions::PATH_MODULE
:
355 case SvtPathOptions::PATH_PLUGIN
:
356 case SvtPathOptions::PATH_STORAGE
:
358 // These office paths have to be convert back to UCB-URL's
359 utl::LocalFileHelper::ConvertPhysicalNameToURL( rNewPath
, aResult
);
365 aNewValue
= rNewPath
;
368 // Resubstitution is done by the service itself using the substition service
372 m_xPathSettings
->setFastPropertyValue( m_aMapEnumToPropHandle
[ (sal_Int32
)ePath
], a
);
374 catch (const Exception
&)
380 // -----------------------------------------------------------------------
382 OUString
SvtPathOptions_Impl::SubstituteAndConvert( const rtl::OUString
& rPath
)
384 return SubstVar( rPath
);
387 //-------------------------------------------------------------------------
389 OUString
SvtPathOptions_Impl::UsePathVariables( const OUString
& rPath
)
391 return m_xSubstVariables
->reSubstituteVariables( rPath
);
394 // -----------------------------------------------------------------------
396 OUString
SvtPathOptions_Impl::SubstVar( const OUString
& rVar
)
398 // Don't work at parameter-string directly. Copy it.
399 OUString aWorkText
= rVar
;
401 // Convert the returned path to system path!
402 BOOL bConvertLocal
= FALSE
;
404 // Search for first occure of "$(...".
405 sal_Int32 nPosition
= aWorkText
.indexOf( SIGN_STARTVARIABLE
); // = first position of "$(" in string
406 sal_Int32 nLength
= 0; // = count of letters from "$(" to ")" in string
408 // Have we found any variable like "$(...)"?
409 if ( nPosition
!= STRPOS_NOTFOUND
)
411 // Yes; Get length of found variable.
412 // If no ")" was found - nLength is set to 0 by default! see before.
413 sal_Int32 nEndPosition
= aWorkText
.indexOf( SIGN_ENDVARIABLE
, nPosition
);
414 if ( nEndPosition
!= STRPOS_NOTFOUND
)
415 nLength
= nEndPosition
- nPosition
+ 1;
418 // Is there another path variable?
419 while ( ( nPosition
!= STRPOS_NOTFOUND
) && ( nLength
> 0 ) )
421 // YES; Get the next variable for replace.
422 OUString aReplacement
;
423 OUString aSubString
= aWorkText
.copy( nPosition
, nLength
);
424 aSubString
= aSubString
.toAsciiLowerCase();
426 // Look for special variable that needs a system path.
427 VarNameToEnumMap::const_iterator pIter
= m_aMapVarNamesToEnum
.find( aSubString
);
428 if ( pIter
!= m_aMapVarNamesToEnum
.end() )
429 bConvertLocal
= TRUE
;
431 nPosition
+= nLength
;
433 // We must control index in string before call something at OUString!
434 // The OUString-implementation don't do it for us :-( but the result is not defined otherwise.
435 if ( nPosition
+ 1 > aWorkText
.getLength() )
437 // Position is out of range. Break loop!
438 nPosition
= STRPOS_NOTFOUND
;
443 // Else; Position is valid. Search for next variable.
444 nPosition
= aWorkText
.indexOf( SIGN_STARTVARIABLE
, nPosition
);
445 // Have we found any variable like "$(...)"?
446 if ( nPosition
!= STRPOS_NOTFOUND
)
448 // Yes; Get length of found variable. If no ")" was found - nLength must set to 0!
450 sal_Int32 nEndPosition
= aWorkText
.indexOf( SIGN_ENDVARIABLE
, nPosition
);
451 if ( nEndPosition
!= STRPOS_NOTFOUND
)
452 nLength
= nEndPosition
- nPosition
+ 1;
457 aWorkText
= m_xSubstVariables
->substituteVariables( rVar
, sal_False
);
461 // Convert the URL to a system path for special path variables
463 utl::LocalFileHelper::ConvertURLToPhysicalName( aWorkText
, aReturn
);
470 // -----------------------------------------------------------------------
472 SvtPathOptions_Impl::SvtPathOptions_Impl() :
473 m_aPathArray( (sal_Int32
)SvtPathOptions::PATH_COUNT
)
475 Reference
< XMultiServiceFactory
> xSMgr
= comphelper::getProcessServiceFactory();
477 // Create necessary services
478 m_xPathSettings
= Reference
< XFastPropertySet
>( xSMgr
->createInstance(
479 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
480 "com.sun.star.util.PathSettings" ))),
482 if ( !m_xPathSettings
.is() )
484 // #112719#: check for existance
485 DBG_ERROR( "SvtPathOptions_Impl::SvtPathOptions_Impl(): #112719# happened again!" );
486 throw RuntimeException(
487 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Service com.sun.star.util.PathSettings cannot be created" )),
488 Reference
< XInterface
>() );
491 m_xSubstVariables
= Reference
< XStringSubstitution
>( xSMgr
->createInstance(
492 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM(
493 "com.sun.star.util.PathSubstitution" ))),
495 if ( !m_xSubstVariables
.is() )
497 // #112719#: check for existance
498 DBG_ERROR( "SvtPathOptions_Impl::SvtPathOptions_Impl(): #112719# happened again!" );
499 throw RuntimeException(
500 ::rtl::OUString( RTL_CONSTASCII_USTRINGPARAM( "Service com.sun.star.util.PathSubstitution cannot be created" )),
501 Reference
< XInterface
>() );
504 // Create temporary hash map to have a mapping between property names and property handles
505 Reference
< XPropertySet
> xPropertySet
= Reference
< XPropertySet
>( m_xPathSettings
, UNO_QUERY
);
506 Reference
< XPropertySetInfo
> xPropSetInfo
= xPropertySet
->getPropertySetInfo();
507 Sequence
< Property
> aPathPropSeq
= xPropSetInfo
->getProperties();
509 NameToHandleMap aTempHashMap
;
510 for ( sal_Int32 n
= 0; n
< aPathPropSeq
.getLength(); n
++ )
512 const com::sun::star::beans::Property
& aProperty
= aPathPropSeq
[n
];
513 aTempHashMap
.insert( NameToHandleMap::value_type( aProperty
.Name
, aProperty
.Handle
));
516 // Create mapping between internal enum (SvtPathOptions::Pathes) and property handle
517 sal_Int32 nCount
= sizeof( aPropNames
) / sizeof( PropertyStruct
);
519 for ( i
= 0; i
< nCount
; i
++ )
521 NameToHandleMap::const_iterator pIter
=
522 aTempHashMap
.find( rtl::OUString::createFromAscii( aPropNames
[i
].pPropName
));
524 if ( pIter
!= aTempHashMap
.end() )
526 sal_Int32 nHandle
= pIter
->second
;
527 sal_Int32 nEnum
= aPropNames
[i
].ePath
;
528 m_aMapEnumToPropHandle
.insert( EnumToHandleMap::value_type( nEnum
, nHandle
));
532 // Create hash map for path variables that need a system path as a return value!
533 nCount
= sizeof( aVarNameAttribute
) / sizeof( VarNameAttribute
);
534 for ( i
= 0; i
< nCount
; i
++ )
536 m_aMapVarNamesToEnum
.insert( VarNameToEnumMap::value_type(
537 OUString::createFromAscii( aVarNameAttribute
[i
].pVarName
),
538 aVarNameAttribute
[i
].eVarProperty
));
541 // Set language type!
542 Any aLocale
= ConfigManager::GetConfigManager()->GetDirectConfigProperty( ConfigManager::LOCALE
);
544 if ( aLocale
>>= aLocaleStr
)
546 sal_Int32 nIndex
= 0;
547 m_aLocale
.Language
= aLocaleStr
.getToken(0, '-', nIndex
);
548 m_aLocale
.Country
= aLocaleStr
.getToken(0, '-', nIndex
);
549 m_aLocale
.Variant
= aLocaleStr
.getToken(0, '-', nIndex
);
553 DBG_ERRORFILE( "wrong any type" );
554 m_aLocale
.Language
= OStringToOUString(OString("en"), RTL_TEXTENCODING_UTF8
);
555 m_aLocale
.Country
= OStringToOUString(OString("US"), RTL_TEXTENCODING_UTF8
);
556 m_aLocale
.Variant
= OStringToOUString(OString(""), RTL_TEXTENCODING_UTF8
);
560 // -----------------------------------------------------------------------
562 // class SvtPathOptions --------------------------------------------------
564 namespace { struct lclMutex
: public rtl::Static
< ::osl::Mutex
, lclMutex
> {}; }
566 SvtPathOptions::SvtPathOptions()
568 // Global access, must be guarded (multithreading)
569 ::osl::MutexGuard
aGuard( lclMutex::get() );
572 pOptions
= new SvtPathOptions_Impl
;
573 ItemHolder1::holdConfigItem(E_PATHOPTIONS
);
579 // -----------------------------------------------------------------------
581 SvtPathOptions::~SvtPathOptions()
583 // Global access, must be guarded (multithreading)
584 ::osl::MutexGuard
aGuard( lclMutex::get() );
591 // -----------------------------------------------------------------------
593 const String
& SvtPathOptions::GetAddinPath() const
595 return pImp
->GetAddinPath();
598 // -----------------------------------------------------------------------
600 const String
& SvtPathOptions::GetAutoCorrectPath() const
602 return pImp
->GetAutoCorrectPath();
605 // -----------------------------------------------------------------------
607 const String
& SvtPathOptions::GetAutoTextPath() const
609 return pImp
->GetAutoTextPath();
612 // -----------------------------------------------------------------------
614 const String
& SvtPathOptions::GetBackupPath() const
616 return pImp
->GetBackupPath();
619 // -----------------------------------------------------------------------
621 const String
& SvtPathOptions::GetBasicPath() const
623 return pImp
->GetBasicPath();
626 // -----------------------------------------------------------------------
628 const String
& SvtPathOptions::GetBitmapPath() const
630 return pImp
->GetBitmapPath();
633 // -----------------------------------------------------------------------
635 const String
& SvtPathOptions::GetConfigPath() const
637 return pImp
->GetConfigPath();
640 // -----------------------------------------------------------------------
642 const String
& SvtPathOptions::GetDictionaryPath() const
644 return pImp
->GetDictionaryPath();
647 // -----------------------------------------------------------------------
649 const String
& SvtPathOptions::GetFavoritesPath() const
651 return pImp
->GetFavoritesPath();
654 // -----------------------------------------------------------------------
656 const String
& SvtPathOptions::GetFilterPath() const
658 return pImp
->GetFilterPath();
661 // -----------------------------------------------------------------------
663 const String
& SvtPathOptions::GetGalleryPath() const
665 return pImp
->GetGalleryPath();
668 // -----------------------------------------------------------------------
670 const String
& SvtPathOptions::GetGraphicPath() const
672 return pImp
->GetGraphicPath();
675 // -----------------------------------------------------------------------
677 const String
& SvtPathOptions::GetHelpPath() const
679 return pImp
->GetHelpPath();
682 // -----------------------------------------------------------------------
684 const String
& SvtPathOptions::GetLinguisticPath() const
686 return pImp
->GetLinguisticPath();
689 // -----------------------------------------------------------------------
691 const String
& SvtPathOptions::GetFingerprintPath() const
693 return pImp
->GetFingerprintPath();
696 // -----------------------------------------------------------------------
698 const String
& SvtPathOptions::GetModulePath() const
700 return pImp
->GetModulePath();
703 // -----------------------------------------------------------------------
705 const String
& SvtPathOptions::GetPalettePath() const
707 return pImp
->GetPalettePath();
710 // -----------------------------------------------------------------------
712 const String
& SvtPathOptions::GetPluginPath() const
714 return pImp
->GetPluginPath();
717 // -----------------------------------------------------------------------
719 const String
& SvtPathOptions::GetStoragePath() const
721 return pImp
->GetStoragePath();
724 // -----------------------------------------------------------------------
726 const String
& SvtPathOptions::GetTempPath() const
728 return pImp
->GetTempPath();
731 // -----------------------------------------------------------------------
733 const String
& SvtPathOptions::GetTemplatePath() const
735 return pImp
->GetTemplatePath();
738 // -----------------------------------------------------------------------
740 const String
& SvtPathOptions::GetUserConfigPath() const
742 return pImp
->GetUserConfigPath();
745 const String
& SvtPathOptions::GetUIConfigPath() const
747 return pImp
->GetUIConfigPath();
750 // -----------------------------------------------------------------------
752 const String
& SvtPathOptions::GetWorkPath() const
754 return pImp
->GetWorkPath();
757 // -----------------------------------------------------------------------
759 void SvtPathOptions::SetAddinPath( const String
& rPath
)
761 pImp
->SetAddinPath( rPath
);
764 // -----------------------------------------------------------------------
766 void SvtPathOptions::SetAutoCorrectPath( const String
& rPath
)
768 pImp
->SetAutoCorrectPath( rPath
);
771 // -----------------------------------------------------------------------
773 void SvtPathOptions::SetAutoTextPath( const String
& rPath
)
775 pImp
->SetAutoTextPath( rPath
);
778 // -----------------------------------------------------------------------
780 void SvtPathOptions::SetBackupPath( const String
& rPath
)
782 pImp
->SetBackupPath( rPath
);
785 // -----------------------------------------------------------------------
787 void SvtPathOptions::SetBasicPath( const String
& rPath
)
789 pImp
->SetBasicPath( rPath
);
792 // -----------------------------------------------------------------------
794 void SvtPathOptions::SetBitmapPath( const String
& rPath
)
796 pImp
->SetBitmapPath( rPath
);
799 // -----------------------------------------------------------------------
801 void SvtPathOptions::SetConfigPath( const String
& rPath
)
803 pImp
->SetConfigPath( rPath
);
806 // -----------------------------------------------------------------------
808 void SvtPathOptions::SetDictionaryPath( const String
& rPath
)
810 pImp
->SetDictionaryPath( rPath
);
813 // -----------------------------------------------------------------------
815 void SvtPathOptions::SetFavoritesPath( const String
& rPath
)
817 pImp
->SetFavoritesPath( rPath
);
820 // -----------------------------------------------------------------------
822 void SvtPathOptions::SetFilterPath( const String
& rPath
)
824 pImp
->SetFilterPath( rPath
);
827 // -----------------------------------------------------------------------
829 void SvtPathOptions::SetGalleryPath( const String
& rPath
)
831 pImp
->SetGalleryPath( rPath
);
834 // -----------------------------------------------------------------------
836 void SvtPathOptions::SetGraphicPath( const String
& rPath
)
838 pImp
->SetGraphicPath( rPath
);
841 // -----------------------------------------------------------------------
843 void SvtPathOptions::SetHelpPath( const String
& rPath
)
845 pImp
->SetHelpPath( rPath
);
848 // -----------------------------------------------------------------------
850 void SvtPathOptions::SetLinguisticPath( const String
& rPath
)
852 pImp
->SetLinguisticPath( rPath
);
855 // -----------------------------------------------------------------------
857 void SvtPathOptions::SetModulePath( const String
& rPath
)
859 pImp
->SetModulePath( rPath
);
862 // -----------------------------------------------------------------------
864 void SvtPathOptions::SetPalettePath( const String
& rPath
)
866 pImp
->SetPalettePath( rPath
);
869 // -----------------------------------------------------------------------
871 void SvtPathOptions::SetPluginPath( const String
& rPath
)
873 pImp
->SetPluginPath( rPath
);
876 // -----------------------------------------------------------------------
878 void SvtPathOptions::SetStoragePath( const String
& rPath
)
880 pImp
->SetStoragePath( rPath
);
883 // -----------------------------------------------------------------------
885 void SvtPathOptions::SetTempPath( const String
& rPath
)
887 pImp
->SetTempPath( rPath
);
890 // -----------------------------------------------------------------------
892 void SvtPathOptions::SetTemplatePath( const String
& rPath
)
894 pImp
->SetTemplatePath( rPath
);
897 // -----------------------------------------------------------------------
899 void SvtPathOptions::SetUserConfigPath( const String
& rPath
)
901 pImp
->SetUserConfigPath( rPath
);
904 // -----------------------------------------------------------------------
906 void SvtPathOptions::SetWorkPath( const String
& rPath
)
908 pImp
->SetWorkPath( rPath
);
911 // -----------------------------------------------------------------------
913 String
SvtPathOptions::SubstituteVariable( const String
& rVar
)
915 String aRet
= pImp
->SubstituteAndConvert( rVar
);
919 String
SvtPathOptions::UseVariable( const String
& rPath
)
921 String aRet
= pImp
->UsePathVariables( rPath
);
925 // -----------------------------------------------------------------------
927 sal_Bool
SvtPathOptions::SearchFile( String
& rIniFile
, Pathes ePath
)
929 // check parameter: empty inifile name?
930 if ( !rIniFile
.Len() )
932 DBG_ERRORFILE( "SvtPathOptions::SearchFile(): invalid parameter" );
936 String aIniFile
= pImp
->SubstVar( rIniFile
);
937 sal_Bool bRet
= sal_False
;
941 case PATH_USERCONFIG
:
945 INetURLObject
aObj( GetUserConfigPath() );
946 xub_StrLen i
, nCount
= aIniFile
.GetTokenCount( '/' );
947 for ( i
= 0; i
< nCount
; ++i
)
948 aObj
.insertName( aIniFile
.GetToken( i
, '/' ) );
950 if ( !::utl::UCBContentHelper::Exists( aObj
.GetMainURL( INetURLObject::NO_DECODE
) ) )
952 aObj
.SetSmartURL( GetConfigPath() );
953 aObj
.insertName( aIniFile
);
954 bRet
= ::utl::UCBContentHelper::Exists( aObj
.GetMainURL( INetURLObject::NO_DECODE
) );
958 rIniFile
= aObj
.GetMainURL( INetURLObject::NO_DECODE
);
968 case PATH_ADDIN
: aPath
= GetAddinPath(); break;
969 case PATH_AUTOCORRECT
: aPath
= GetAutoCorrectPath(); break;
970 case PATH_AUTOTEXT
: aPath
= GetAutoTextPath(); break;
971 case PATH_BACKUP
: aPath
= GetBackupPath(); break;
972 case PATH_BASIC
: aPath
= GetBasicPath(); break;
973 case PATH_BITMAP
: aPath
= GetBitmapPath(); break;
974 case PATH_CONFIG
: aPath
= GetConfigPath(); break;
975 case PATH_DICTIONARY
: aPath
= GetDictionaryPath(); break;
976 case PATH_FAVORITES
: aPath
= GetFavoritesPath(); break;
977 case PATH_FILTER
: aPath
= GetFilterPath(); break;
978 case PATH_GALLERY
: aPath
= GetGalleryPath(); break;
979 case PATH_GRAPHIC
: aPath
= GetGraphicPath(); break;
980 case PATH_HELP
: aPath
= GetHelpPath(); break;
981 case PATH_LINGUISTIC
: aPath
= GetLinguisticPath(); break;
982 case PATH_MODULE
: aPath
= GetModulePath(); break;
983 case PATH_PALETTE
: aPath
= GetPalettePath(); break;
984 case PATH_PLUGIN
: aPath
= GetPluginPath(); break;
985 case PATH_STORAGE
: aPath
= GetStoragePath(); break;
986 case PATH_TEMP
: aPath
= GetTempPath(); break;
987 case PATH_TEMPLATE
: aPath
= GetTemplatePath(); break;
988 case PATH_WORK
: aPath
= GetWorkPath(); break;
989 case PATH_UICONFIG
: aPath
= GetUIConfigPath(); break;
990 case PATH_FINGERPRINT
: aPath
= GetFingerprintPath(); break;
991 case PATH_USERCONFIG
:/*-Wall???*/ break;
992 case PATH_COUNT
: /*-Wall???*/ break;
995 sal_uInt16 j
, nIdx
= 0, nTokenCount
= aPath
.GetTokenCount( SEARCHPATH_DELIMITER
);
996 for ( j
= 0; j
< nTokenCount
; ++j
)
999 String aPathToken
= aPath
.GetToken( 0, SEARCHPATH_DELIMITER
, nIdx
);
1000 INetURLObject
aObj( aPathToken
);
1001 if ( aObj
.HasError() )
1005 if ( LocalFileHelper::ConvertPhysicalNameToURL( aPathToken
, aURL
) )
1006 aObj
.SetURL( aURL
);
1009 xub_StrLen i
, nCount
= aIniFile
.GetTokenCount( '/' );
1010 for ( i
= 0; i
< nCount
; ++i
)
1011 aObj
.insertName( aIniFile
.GetToken( i
, '/' ) );
1012 bRet
= ::utl::UCBContentHelper::Exists( aObj
.GetMainURL( INetURLObject::NO_DECODE
) );
1017 ::utl::LocalFileHelper::ConvertURLToPhysicalName(
1018 aObj
.GetMainURL( INetURLObject::NO_DECODE
), rIniFile
);
1020 rIniFile
= aObj
.GetMainURL( INetURLObject::NO_DECODE
);
1030 // -----------------------------------------------------------------------
1032 ::com::sun::star::lang::Locale
SvtPathOptions::GetLocale() const
1034 return pImp
->GetLocale();
1036 // -----------------------------------------------------------------------
1037 BOOL
SvtPathOptions::IsPathReadonly(Pathes ePath
)const
1039 return pImp
->IsPathReadonly(ePath
);
1041 // -----------------------------------------------------------------------
1042 const String
& SvtPathOptions::GetPath(Pathes ePath
)const
1044 return pImp
->GetPath(ePath
);
1046 // -----------------------------------------------------------------------
1047 void SvtPathOptions::SetPath( SvtPathOptions::Pathes ePath
, const String
& rNewPath
)
1049 pImp
->SetPath(ePath
, rNewPath
);
1052 // class PathService -----------------------------------------------------
1053 #include <com/sun/star/frame/XConfigManager.hpp>
1054 #include <com/sun/star/lang/XServiceInfo.hpp>
1055 #include <cppuhelper/implbase2.hxx>
1057 class PathService
: public ::cppu::WeakImplHelper2
< ::com::sun::star::frame::XConfigManager
, ::com::sun::star::lang::XServiceInfo
>
1059 virtual ::rtl::OUString SAL_CALL
getImplementationName( ) throw(::com::sun::star::uno::RuntimeException
);
1060 virtual sal_Bool SAL_CALL
supportsService( const ::rtl::OUString
& ServiceName
) throw(::com::sun::star::uno::RuntimeException
);
1061 virtual ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
1062 getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException
);
1063 virtual ::rtl::OUString SAL_CALL
substituteVariables( const ::rtl::OUString
& sText
) throw(::com::sun::star::uno::RuntimeException
);
1064 virtual void SAL_CALL
addPropertyChangeListener( const ::rtl::OUString
& sKeyName
, const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyChangeListener
>& xListener
) throw(::com::sun::star::uno::RuntimeException
);
1065 virtual void SAL_CALL
removePropertyChangeListener( const ::rtl::OUString
& sKeyName
, const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyChangeListener
>& xListener
) throw(::com::sun::star::uno::RuntimeException
);
1066 virtual void SAL_CALL
flush( ) throw(::com::sun::star::uno::RuntimeException
);
1069 // class PathService -----------------------------------------------------
1071 void SAL_CALL
PathService::addPropertyChangeListener( const ::rtl::OUString
&, const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyChangeListener
>& ) throw(::com::sun::star::uno::RuntimeException
) {}
1072 void SAL_CALL
PathService::removePropertyChangeListener( const ::rtl::OUString
&, const ::com::sun::star::uno::Reference
< ::com::sun::star::beans::XPropertyChangeListener
>& ) throw(::com::sun::star::uno::RuntimeException
) {}
1073 void SAL_CALL
PathService::flush( ) throw(::com::sun::star::uno::RuntimeException
) {}
1075 ::rtl::OUString SAL_CALL
PathService::substituteVariables( const ::rtl::OUString
& sText
) throw(::com::sun::star::uno::RuntimeException
)
1077 return SvtPathOptions().SubstituteVariable( sText
);
1080 ::rtl::OUString SAL_CALL
PathService::getImplementationName( ) throw(::com::sun::star::uno::RuntimeException
)
1082 return OUString::createFromAscii("com.sun.star.comp.svtools.PathService");
1085 sal_Bool SAL_CALL
PathService::supportsService( const ::rtl::OUString
& ServiceName
) throw(::com::sun::star::uno::RuntimeException
)
1087 if ( ServiceName
.compareToAscii("com.sun.star.config.SpecialConfigManager") == COMPARE_EQUAL
)
1093 ::com::sun::star::uno::Sequence
< ::rtl::OUString
> SAL_CALL
PathService::getSupportedServiceNames( ) throw(::com::sun::star::uno::RuntimeException
)
1095 Sequence
< OUString
> aRet(1);
1096 *aRet
.getArray() = OUString::createFromAscii("com.sun.star.config.SpecialConfigManager");