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 <com/sun/star/lang/Locale.hpp>
21 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
22 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
23 #include <com/sun/star/configuration/theDefaultProvider.hpp>
24 #include <com/sun/star/container/XNameAccess.hpp>
25 #include <com/sun/star/container/XNameContainer.hpp>
26 #include <com/sun/star/container/XNameReplace.hpp>
27 #include <com/sun/star/util/theMacroExpander.hpp>
28 #include <rtl/uri.hxx>
29 #include <rtl/instance.hxx>
30 #include <osl/mutex.hxx>
31 #include <i18nlangtag/mslangid.hxx>
32 #include <i18nlangtag/languagetag.hxx>
33 #include <tools/debug.hxx>
34 #include <tools/string.hxx>
35 #include <unotools/lingucfg.hxx>
36 #include <unotools/linguprops.hxx>
37 #include <sal/macros.h>
39 #include <comphelper/processfactory.hxx>
41 #include <itemholder1.hxx>
43 using namespace com::sun::star
;
47 #define EXPAND_PROTOCOL "vnd.sun.star.expand:"
48 #define FILE_PROTOCOL "file:///"
52 class theSvtLinguConfigItemMutex
:
53 public rtl::Static
< osl::Mutex
, theSvtLinguConfigItemMutex
> {};
56 static sal_Bool
lcl_SetLocale( sal_Int16
&rLanguage
, const uno::Any
&rVal
)
58 sal_Bool bSucc
= sal_False
;
61 if (rVal
>>= aNew
) // conversion successful?
63 sal_Int16 nNew
= LanguageTag( aNew
).getLanguageType( false);
64 if (nNew
!= rLanguage
)
73 static inline const OUString
lcl_LanguageToCfgLocaleStr( sal_Int16 nLanguage
)
76 if (LANGUAGE_SYSTEM
!= nLanguage
)
77 aRes
= LanguageTag( nLanguage
).getBcp47();
81 static sal_Int16
lcl_CfgAnyToLanguage( const uno::Any
&rVal
)
85 return (aTmp
.isEmpty()) ? LANGUAGE_SYSTEM
: LanguageTag( aTmp
).getLanguageType();
88 SvtLinguOptions::SvtLinguOptions()
90 nDefaultLanguage
= LANGUAGE_NONE
;
91 nDefaultLanguage_CJK
= LANGUAGE_NONE
;
92 nDefaultLanguage_CTL
= LANGUAGE_NONE
;
95 bIsUseDictionaryList
=
96 bIsIgnoreControlCharacters
= sal_True
;
99 bIsSpellCapitalization
=
100 bIsSpellSpecial
= sal_True
;
104 bIsSpellUpperCase
= sal_False
;
106 // text conversion options
107 bIsIgnorePostPositionalWord
= sal_True
;
109 bIsShowEntriesRecentlyUsedFirst
=
110 bIsAutoReplaceUniqueEntries
= sal_False
;
111 bIsDirectionToSimplified
= sal_True
;
112 bIsUseCharacterVariants
=
113 bIsTranslateCommonTerms
=
114 bIsReverseMapping
= sal_False
;
116 bROIsDirectionToSimplified
=
117 bROIsUseCharacterVariants
=
118 bROIsTranslateCommonTerms
=
119 bROIsReverseMapping
= sal_False
;
121 // hyphenation options
122 bIsHyphSpecial
= sal_True
;
123 bIsHyphAuto
= sal_False
;
125 nHyphMinTrailing
= 2;
126 nHyphMinWordLength
= 0;
128 nDataFilesChangedCheckValue
= 0;
131 bIsGrammarAuto
= sal_False
,
132 bIsGrammarInteractive
= sal_False
;
136 class SvtLinguConfigItem
: public utl::ConfigItem
138 SvtLinguOptions aOpt
;
140 // disallow copy-constructor and assignment-operator for now
141 SvtLinguConfigItem( const SvtLinguConfigItem
& );
142 SvtLinguConfigItem
& operator = ( const SvtLinguConfigItem
& );
144 static sal_Bool
GetHdlByName( sal_Int32
&rnHdl
, const OUString
&rPropertyName
, sal_Bool bFullPropName
= sal_False
);
145 static const uno::Sequence
< OUString
> GetPropertyNames();
146 sal_Bool
LoadOptions( const uno::Sequence
< OUString
> &rProperyNames
);
147 sal_Bool
SaveOptions( const uno::Sequence
< OUString
> &rProperyNames
);
150 SvtLinguConfigItem();
151 virtual ~SvtLinguConfigItem();
154 virtual void Notify( const com::sun::star::uno::Sequence
< OUString
> &rPropertyNames
);
155 virtual void Commit();
157 // make some protected functions of utl::ConfigItem public
158 using utl::ConfigItem::GetNodeNames
;
159 using utl::ConfigItem::GetProperties
;
160 //using utl::ConfigItem::PutProperties;
161 //using utl::ConfigItem::SetSetProperties;
162 using utl::ConfigItem::ReplaceSetProperties
;
163 //using utl::ConfigItem::GetReadOnlyStates;
166 com::sun::star::uno::Any
167 GetProperty( const OUString
&rPropertyName
) const;
168 com::sun::star::uno::Any
169 GetProperty( sal_Int32 nPropertyHandle
) const;
171 sal_Bool
SetProperty( const OUString
&rPropertyName
,
172 const com::sun::star::uno::Any
&rValue
);
173 sal_Bool
SetProperty( sal_Int32 nPropertyHandle
,
174 const com::sun::star::uno::Any
&rValue
);
176 const SvtLinguOptions
& GetOptions() const;
178 sal_Bool
IsReadOnly( const OUString
&rPropertyName
) const;
179 sal_Bool
IsReadOnly( sal_Int32 nPropertyHandle
) const;
183 SvtLinguConfigItem::SvtLinguConfigItem() :
184 utl::ConfigItem( OUString("Office.Linguistic") )
186 const uno::Sequence
< OUString
> &rPropertyNames
= GetPropertyNames();
187 LoadOptions( rPropertyNames
);
190 // request notify events when properties change
191 EnableNotification( rPropertyNames
);
195 SvtLinguConfigItem::~SvtLinguConfigItem()
197 //! Commit (SaveOptions) will be called by the d-tor of the base called !
201 void SvtLinguConfigItem::Notify( const uno::Sequence
< OUString
> &rPropertyNames
)
203 LoadOptions( rPropertyNames
);
208 void SvtLinguConfigItem::Commit()
210 SaveOptions( GetPropertyNames() );
214 static struct NamesToHdl
216 const char *pFullPropName
; // full qualified name as used in configuration
217 const char *pPropName
; // property name only (atom) of above
218 sal_Int32 nHdl
; // numeric handle representing the property
221 {/* 0 */ "General/DefaultLocale", UPN_DEFAULT_LOCALE
, UPH_DEFAULT_LOCALE
},
222 {/* 1 */ "General/DictionaryList/ActiveDictionaries", UPN_ACTIVE_DICTIONARIES
, UPH_ACTIVE_DICTIONARIES
},
223 {/* 2 */ "General/DictionaryList/IsUseDictionaryList", UPN_IS_USE_DICTIONARY_LIST
, UPH_IS_USE_DICTIONARY_LIST
},
224 {/* 3 */ "General/IsIgnoreControlCharacters", UPN_IS_IGNORE_CONTROL_CHARACTERS
, UPH_IS_IGNORE_CONTROL_CHARACTERS
},
225 {/* 5 */ "General/DefaultLocale_CJK", UPN_DEFAULT_LOCALE_CJK
, UPH_DEFAULT_LOCALE_CJK
},
226 {/* 6 */ "General/DefaultLocale_CTL", UPN_DEFAULT_LOCALE_CTL
, UPH_DEFAULT_LOCALE_CTL
},
228 {/* 7 */ "SpellChecking/IsSpellUpperCase", UPN_IS_SPELL_UPPER_CASE
, UPH_IS_SPELL_UPPER_CASE
},
229 {/* 8 */ "SpellChecking/IsSpellWithDigits", UPN_IS_SPELL_WITH_DIGITS
, UPH_IS_SPELL_WITH_DIGITS
},
230 {/* 9 */ "SpellChecking/IsSpellCapitalization", UPN_IS_SPELL_CAPITALIZATION
, UPH_IS_SPELL_CAPITALIZATION
},
231 {/* 10 */ "SpellChecking/IsSpellAuto", UPN_IS_SPELL_AUTO
, UPH_IS_SPELL_AUTO
},
232 {/* 11 */ "SpellChecking/IsSpellSpecial", UPN_IS_SPELL_SPECIAL
, UPH_IS_SPELL_SPECIAL
},
233 {/* 14 */ "SpellChecking/IsReverseDirection", UPN_IS_WRAP_REVERSE
, UPH_IS_WRAP_REVERSE
},
235 {/* 15 */ "Hyphenation/MinLeading", UPN_HYPH_MIN_LEADING
, UPH_HYPH_MIN_LEADING
},
236 {/* 16 */ "Hyphenation/MinTrailing", UPN_HYPH_MIN_TRAILING
, UPH_HYPH_MIN_TRAILING
},
237 {/* 17 */ "Hyphenation/MinWordLength", UPN_HYPH_MIN_WORD_LENGTH
, UPH_HYPH_MIN_WORD_LENGTH
},
238 {/* 18 */ "Hyphenation/IsHyphSpecial", UPN_IS_HYPH_SPECIAL
, UPH_IS_HYPH_SPECIAL
},
239 {/* 19 */ "Hyphenation/IsHyphAuto", UPN_IS_HYPH_AUTO
, UPH_IS_HYPH_AUTO
},
241 {/* 20 */ "TextConversion/ActiveConversionDictionaries", UPN_ACTIVE_CONVERSION_DICTIONARIES
, UPH_ACTIVE_CONVERSION_DICTIONARIES
},
242 {/* 21 */ "TextConversion/IsIgnorePostPositionalWord", UPN_IS_IGNORE_POST_POSITIONAL_WORD
, UPH_IS_IGNORE_POST_POSITIONAL_WORD
},
243 {/* 22 */ "TextConversion/IsAutoCloseDialog", UPN_IS_AUTO_CLOSE_DIALOG
, UPH_IS_AUTO_CLOSE_DIALOG
},
244 {/* 23 */ "TextConversion/IsShowEntriesRecentlyUsedFirst", UPN_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST
, UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST
},
245 {/* 24 */ "TextConversion/IsAutoReplaceUniqueEntries", UPN_IS_AUTO_REPLACE_UNIQUE_ENTRIES
, UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES
},
246 {/* 25 */ "TextConversion/IsDirectionToSimplified", UPN_IS_DIRECTION_TO_SIMPLIFIED
, UPH_IS_DIRECTION_TO_SIMPLIFIED
},
247 {/* 26 */ "TextConversion/IsUseCharacterVariants", UPN_IS_USE_CHARACTER_VARIANTS
, UPH_IS_USE_CHARACTER_VARIANTS
},
248 {/* 27 */ "TextConversion/IsTranslateCommonTerms", UPN_IS_TRANSLATE_COMMON_TERMS
, UPH_IS_TRANSLATE_COMMON_TERMS
},
249 {/* 28 */ "TextConversion/IsReverseMapping", UPN_IS_REVERSE_MAPPING
, UPH_IS_REVERSE_MAPPING
},
251 {/* 29 */ "ServiceManager/DataFilesChangedCheckValue", UPN_DATA_FILES_CHANGED_CHECK_VALUE
, UPH_DATA_FILES_CHANGED_CHECK_VALUE
},
253 {/* 30 */ "GrammarChecking/IsAutoCheck", UPN_IS_GRAMMAR_AUTO
, UPH_IS_GRAMMAR_AUTO
},
254 {/* 31 */ "GrammarChecking/IsInteractiveCheck", UPN_IS_GRAMMAR_INTERACTIVE
, UPH_IS_GRAMMAR_INTERACTIVE
},
256 /* similar to entry 0 (thus no own configuration entry) but with different property name and type */
257 { NULL
, UPN_DEFAULT_LANGUAGE
, UPH_DEFAULT_LANGUAGE
},
263 const uno::Sequence
< OUString
> SvtLinguConfigItem::GetPropertyNames()
265 uno::Sequence
< OUString
> aNames
;
267 sal_Int32 nMax
= SAL_N_ELEMENTS(aNamesToHdl
);
269 aNames
.realloc( nMax
);
270 OUString
*pNames
= aNames
.getArray();
272 for (sal_Int32 i
= 0; i
< nMax
; ++i
)
274 const sal_Char
*pFullPropName
= aNamesToHdl
[i
].pFullPropName
;
276 pNames
[ nIdx
++ ] = OUString::createFromAscii( pFullPropName
);
278 aNames
.realloc( nIdx
);
283 sal_Bool
SvtLinguConfigItem::GetHdlByName(
285 const OUString
&rPropertyName
,
286 sal_Bool bFullPropName
)
288 NamesToHdl
*pEntry
= &aNamesToHdl
[0];
292 while (pEntry
&& pEntry
->pFullPropName
!= NULL
)
294 if (0 == rPropertyName
.compareToAscii( pEntry
->pFullPropName
))
296 rnHdl
= pEntry
->nHdl
;
301 return pEntry
&& pEntry
->pFullPropName
!= NULL
;
305 while (pEntry
&& pEntry
->pPropName
!= NULL
)
307 if (0 == rPropertyName
.compareToAscii( pEntry
->pPropName
))
309 rnHdl
= pEntry
->nHdl
;
314 return pEntry
&& pEntry
->pPropName
!= NULL
;
319 uno::Any
SvtLinguConfigItem::GetProperty( const OUString
&rPropertyName
) const
321 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
324 return GetHdlByName( nHdl
, rPropertyName
) ? GetProperty( nHdl
) : uno::Any();
328 uno::Any
SvtLinguConfigItem::GetProperty( sal_Int32 nPropertyHandle
) const
330 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
334 const sal_Int16
*pnVal
= 0;
335 const sal_Bool
*pbVal
= 0;
336 const sal_Int32
*pnInt32Val
= 0;
338 const SvtLinguOptions
&rOpt
= const_cast< SvtLinguConfigItem
* >(this)->aOpt
;
339 switch (nPropertyHandle
)
341 case UPH_IS_USE_DICTIONARY_LIST
: pbVal
= &rOpt
.bIsUseDictionaryList
; break;
342 case UPH_IS_IGNORE_CONTROL_CHARACTERS
: pbVal
= &rOpt
.bIsIgnoreControlCharacters
; break;
343 case UPH_IS_HYPH_AUTO
: pbVal
= &rOpt
.bIsHyphAuto
; break;
344 case UPH_IS_HYPH_SPECIAL
: pbVal
= &rOpt
.bIsHyphSpecial
; break;
345 case UPH_IS_SPELL_AUTO
: pbVal
= &rOpt
.bIsSpellAuto
; break;
346 case UPH_IS_SPELL_SPECIAL
: pbVal
= &rOpt
.bIsSpellSpecial
; break;
347 case UPH_IS_WRAP_REVERSE
: pbVal
= &rOpt
.bIsSpellReverse
; break;
348 case UPH_DEFAULT_LANGUAGE
: pnVal
= &rOpt
.nDefaultLanguage
; break;
349 case UPH_IS_SPELL_CAPITALIZATION
: pbVal
= &rOpt
.bIsSpellCapitalization
; break;
350 case UPH_IS_SPELL_WITH_DIGITS
: pbVal
= &rOpt
.bIsSpellWithDigits
; break;
351 case UPH_IS_SPELL_UPPER_CASE
: pbVal
= &rOpt
.bIsSpellUpperCase
; break;
352 case UPH_HYPH_MIN_LEADING
: pnVal
= &rOpt
.nHyphMinLeading
; break;
353 case UPH_HYPH_MIN_TRAILING
: pnVal
= &rOpt
.nHyphMinTrailing
; break;
354 case UPH_HYPH_MIN_WORD_LENGTH
: pnVal
= &rOpt
.nHyphMinWordLength
; break;
355 case UPH_ACTIVE_DICTIONARIES
:
357 aRes
<<= rOpt
.aActiveDics
;
360 case UPH_ACTIVE_CONVERSION_DICTIONARIES
:
362 aRes
<<= rOpt
.aActiveConvDics
;
365 case UPH_DEFAULT_LOCALE
:
367 lang::Locale
aLocale( LanguageTag( rOpt
.nDefaultLanguage
).getLocale( false ) );
368 aRes
.setValue( &aLocale
, ::getCppuType((lang::Locale
*)0 ));
371 case UPH_DEFAULT_LOCALE_CJK
:
373 lang::Locale
aLocale( LanguageTag( rOpt
.nDefaultLanguage_CJK
).getLocale( false ) );
374 aRes
.setValue( &aLocale
, ::getCppuType((lang::Locale
*)0 ));
377 case UPH_DEFAULT_LOCALE_CTL
:
379 lang::Locale
aLocale( LanguageTag( rOpt
.nDefaultLanguage_CTL
).getLocale( false ) );
380 aRes
.setValue( &aLocale
, ::getCppuType((lang::Locale
*)0 ));
383 case UPH_IS_IGNORE_POST_POSITIONAL_WORD
: pbVal
= &rOpt
.bIsIgnorePostPositionalWord
; break;
384 case UPH_IS_AUTO_CLOSE_DIALOG
: pbVal
= &rOpt
.bIsAutoCloseDialog
; break;
385 case UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST
: pbVal
= &rOpt
.bIsShowEntriesRecentlyUsedFirst
; break;
386 case UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES
: pbVal
= &rOpt
.bIsAutoReplaceUniqueEntries
; break;
388 case UPH_IS_DIRECTION_TO_SIMPLIFIED
: pbVal
= &rOpt
.bIsDirectionToSimplified
; break;
389 case UPH_IS_USE_CHARACTER_VARIANTS
: pbVal
= &rOpt
.bIsUseCharacterVariants
; break;
390 case UPH_IS_TRANSLATE_COMMON_TERMS
: pbVal
= &rOpt
.bIsTranslateCommonTerms
; break;
391 case UPH_IS_REVERSE_MAPPING
: pbVal
= &rOpt
.bIsReverseMapping
; break;
393 case UPH_DATA_FILES_CHANGED_CHECK_VALUE
: pnInt32Val
= &rOpt
.nDataFilesChangedCheckValue
; break;
394 case UPH_IS_GRAMMAR_AUTO
: pbVal
= &rOpt
.bIsGrammarAuto
; break;
395 case UPH_IS_GRAMMAR_INTERACTIVE
: pbVal
= &rOpt
.bIsGrammarInteractive
; break;
397 DBG_ASSERT( 0, "unexpected property handle" );
405 aRes
<<= *pnInt32Val
;
411 sal_Bool
SvtLinguConfigItem::SetProperty( const OUString
&rPropertyName
, const uno::Any
&rValue
)
413 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
415 sal_Bool bSucc
= sal_False
;
417 if (GetHdlByName( nHdl
, rPropertyName
))
418 bSucc
= SetProperty( nHdl
, rValue
);
423 sal_Bool
SvtLinguConfigItem::SetProperty( sal_Int32 nPropertyHandle
, const uno::Any
&rValue
)
425 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
427 sal_Bool bSucc
= sal_False
;
428 if (!rValue
.hasValue())
431 sal_Bool bMod
= sal_False
;
433 sal_Int16
*pnVal
= 0;
435 sal_Int32
*pnInt32Val
= 0;
437 SvtLinguOptions
&rOpt
= aOpt
;
438 switch (nPropertyHandle
)
440 case UPH_IS_USE_DICTIONARY_LIST
: pbVal
= &rOpt
.bIsUseDictionaryList
; break;
441 case UPH_IS_IGNORE_CONTROL_CHARACTERS
: pbVal
= &rOpt
.bIsIgnoreControlCharacters
; break;
442 case UPH_IS_HYPH_AUTO
: pbVal
= &rOpt
.bIsHyphAuto
; break;
443 case UPH_IS_HYPH_SPECIAL
: pbVal
= &rOpt
.bIsHyphSpecial
; break;
444 case UPH_IS_SPELL_AUTO
: pbVal
= &rOpt
.bIsSpellAuto
; break;
445 case UPH_IS_SPELL_SPECIAL
: pbVal
= &rOpt
.bIsSpellSpecial
; break;
446 case UPH_IS_WRAP_REVERSE
: pbVal
= &rOpt
.bIsSpellReverse
; break;
447 case UPH_DEFAULT_LANGUAGE
: pnVal
= &rOpt
.nDefaultLanguage
; break;
448 case UPH_IS_SPELL_CAPITALIZATION
: pbVal
= &rOpt
.bIsSpellCapitalization
; break;
449 case UPH_IS_SPELL_WITH_DIGITS
: pbVal
= &rOpt
.bIsSpellWithDigits
; break;
450 case UPH_IS_SPELL_UPPER_CASE
: pbVal
= &rOpt
.bIsSpellUpperCase
; break;
451 case UPH_HYPH_MIN_LEADING
: pnVal
= &rOpt
.nHyphMinLeading
; break;
452 case UPH_HYPH_MIN_TRAILING
: pnVal
= &rOpt
.nHyphMinTrailing
; break;
453 case UPH_HYPH_MIN_WORD_LENGTH
: pnVal
= &rOpt
.nHyphMinWordLength
; break;
454 case UPH_ACTIVE_DICTIONARIES
:
456 rValue
>>= rOpt
.aActiveDics
;
460 case UPH_ACTIVE_CONVERSION_DICTIONARIES
:
462 rValue
>>= rOpt
.aActiveConvDics
;
466 case UPH_DEFAULT_LOCALE
:
468 bSucc
= lcl_SetLocale( rOpt
.nDefaultLanguage
, rValue
);
472 case UPH_DEFAULT_LOCALE_CJK
:
474 bSucc
= lcl_SetLocale( rOpt
.nDefaultLanguage_CJK
, rValue
);
478 case UPH_DEFAULT_LOCALE_CTL
:
480 bSucc
= lcl_SetLocale( rOpt
.nDefaultLanguage_CTL
, rValue
);
484 case UPH_IS_IGNORE_POST_POSITIONAL_WORD
: pbVal
= &rOpt
.bIsIgnorePostPositionalWord
; break;
485 case UPH_IS_AUTO_CLOSE_DIALOG
: pbVal
= &rOpt
.bIsAutoCloseDialog
; break;
486 case UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST
: pbVal
= &rOpt
.bIsShowEntriesRecentlyUsedFirst
; break;
487 case UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES
: pbVal
= &rOpt
.bIsAutoReplaceUniqueEntries
; break;
489 case UPH_IS_DIRECTION_TO_SIMPLIFIED
: pbVal
= &rOpt
.bIsDirectionToSimplified
; break;
490 case UPH_IS_USE_CHARACTER_VARIANTS
: pbVal
= &rOpt
.bIsUseCharacterVariants
; break;
491 case UPH_IS_TRANSLATE_COMMON_TERMS
: pbVal
= &rOpt
.bIsTranslateCommonTerms
; break;
492 case UPH_IS_REVERSE_MAPPING
: pbVal
= &rOpt
.bIsReverseMapping
; break;
494 case UPH_DATA_FILES_CHANGED_CHECK_VALUE
: pnInt32Val
= &rOpt
.nDataFilesChangedCheckValue
; break;
495 case UPH_IS_GRAMMAR_AUTO
: pbVal
= &rOpt
.bIsGrammarAuto
; break;
496 case UPH_IS_GRAMMAR_INTERACTIVE
: pbVal
= &rOpt
.bIsGrammarInteractive
; break;
498 DBG_ASSERT( 0, "unexpected property handle" );
503 sal_Bool bNew
= sal_Bool();
516 sal_Int16 nNew
= sal_Int16();
529 sal_Int32 nNew
= sal_Int32();
532 if (nNew
!= *pnInt32Val
)
548 const SvtLinguOptions
& SvtLinguConfigItem::GetOptions() const
550 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
554 sal_Bool
SvtLinguConfigItem::LoadOptions( const uno::Sequence
< OUString
> &rProperyNames
)
556 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
558 sal_Bool bRes
= sal_False
;
560 const OUString
*pProperyNames
= rProperyNames
.getConstArray();
561 sal_Int32 nProps
= rProperyNames
.getLength();
563 const uno::Sequence
< uno::Any
> aValues
= GetProperties( rProperyNames
);
564 const uno::Sequence
< sal_Bool
> aROStates
= GetReadOnlyStates( rProperyNames
);
566 if (nProps
&& aValues
.getLength() == nProps
&& aROStates
.getLength() == nProps
)
568 SvtLinguOptions
&rOpt
= aOpt
;
570 const uno::Any
*pValue
= aValues
.getConstArray();
571 const sal_Bool
*pROStates
= aROStates
.getConstArray();
572 for (sal_Int32 i
= 0; i
< nProps
; ++i
)
574 const uno::Any
&rVal
= pValue
[i
];
575 sal_Int32 nPropertyHandle
;
576 GetHdlByName( nPropertyHandle
, pProperyNames
[i
], sal_True
);
577 switch ( nPropertyHandle
)
579 case UPH_DEFAULT_LOCALE
:
580 { rOpt
.bRODefaultLanguage
= pROStates
[i
]; rOpt
.nDefaultLanguage
= lcl_CfgAnyToLanguage( rVal
); } break;
581 case UPH_ACTIVE_DICTIONARIES
:
582 { rOpt
.bROActiveDics
= pROStates
[i
]; rVal
>>= rOpt
.aActiveDics
; } break;
583 case UPH_IS_USE_DICTIONARY_LIST
:
584 { rOpt
.bROIsUseDictionaryList
= pROStates
[i
]; rVal
>>= rOpt
.bIsUseDictionaryList
; } break;
585 case UPH_IS_IGNORE_CONTROL_CHARACTERS
:
586 { rOpt
.bROIsIgnoreControlCharacters
= pROStates
[i
]; rVal
>>= rOpt
.bIsIgnoreControlCharacters
; } break;
587 case UPH_DEFAULT_LOCALE_CJK
:
588 { rOpt
.bRODefaultLanguage_CJK
= pROStates
[i
]; rOpt
.nDefaultLanguage_CJK
= lcl_CfgAnyToLanguage( rVal
); } break;
589 case UPH_DEFAULT_LOCALE_CTL
:
590 { rOpt
.bRODefaultLanguage_CTL
= pROStates
[i
]; rOpt
.nDefaultLanguage_CTL
= lcl_CfgAnyToLanguage( rVal
); } break;
592 case UPH_IS_SPELL_UPPER_CASE
:
593 { rOpt
.bROIsSpellUpperCase
= pROStates
[i
]; rVal
>>= rOpt
.bIsSpellUpperCase
; } break;
594 case UPH_IS_SPELL_WITH_DIGITS
:
595 { rOpt
.bROIsSpellWithDigits
= pROStates
[i
]; rVal
>>= rOpt
.bIsSpellWithDigits
; } break;
596 case UPH_IS_SPELL_CAPITALIZATION
:
597 { rOpt
.bROIsSpellCapitalization
= pROStates
[i
]; rVal
>>= rOpt
.bIsSpellCapitalization
; } break;
598 case UPH_IS_SPELL_AUTO
:
599 { rOpt
.bROIsSpellAuto
= pROStates
[i
]; rVal
>>= rOpt
.bIsSpellAuto
; } break;
600 case UPH_IS_SPELL_SPECIAL
:
601 { rOpt
.bROIsSpellSpecial
= pROStates
[i
]; rVal
>>= rOpt
.bIsSpellSpecial
; } break;
602 case UPH_IS_WRAP_REVERSE
:
603 { rOpt
.bROIsSpellReverse
= pROStates
[i
]; rVal
>>= rOpt
.bIsSpellReverse
; } break;
605 case UPH_HYPH_MIN_LEADING
:
606 { rOpt
.bROHyphMinLeading
= pROStates
[i
]; rVal
>>= rOpt
.nHyphMinLeading
; } break;
607 case UPH_HYPH_MIN_TRAILING
:
608 { rOpt
.bROHyphMinTrailing
= pROStates
[i
]; rVal
>>= rOpt
.nHyphMinTrailing
; } break;
609 case UPH_HYPH_MIN_WORD_LENGTH
:
610 { rOpt
.bROHyphMinWordLength
= pROStates
[i
]; rVal
>>= rOpt
.nHyphMinWordLength
; } break;
611 case UPH_IS_HYPH_SPECIAL
:
612 { rOpt
.bROIsHyphSpecial
= pROStates
[i
]; rVal
>>= rOpt
.bIsHyphSpecial
; } break;
613 case UPH_IS_HYPH_AUTO
:
614 { rOpt
.bROIsHyphAuto
= pROStates
[i
]; rVal
>>= rOpt
.bIsHyphAuto
; } break;
616 case UPH_ACTIVE_CONVERSION_DICTIONARIES
: { rOpt
.bROActiveConvDics
= pROStates
[i
]; rVal
>>= rOpt
.aActiveConvDics
; } break;
618 case UPH_IS_IGNORE_POST_POSITIONAL_WORD
:
619 { rOpt
.bROIsIgnorePostPositionalWord
= pROStates
[i
]; rVal
>>= rOpt
.bIsIgnorePostPositionalWord
; } break;
620 case UPH_IS_AUTO_CLOSE_DIALOG
:
621 { rOpt
.bROIsAutoCloseDialog
= pROStates
[i
]; rVal
>>= rOpt
.bIsAutoCloseDialog
; } break;
622 case UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST
:
623 { rOpt
.bROIsShowEntriesRecentlyUsedFirst
= pROStates
[i
]; rVal
>>= rOpt
.bIsShowEntriesRecentlyUsedFirst
; } break;
624 case UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES
:
625 { rOpt
.bROIsAutoReplaceUniqueEntries
= pROStates
[i
]; rVal
>>= rOpt
.bIsAutoReplaceUniqueEntries
; } break;
627 case UPH_IS_DIRECTION_TO_SIMPLIFIED
:
628 { rOpt
.bROIsDirectionToSimplified
= pROStates
[i
];
629 if( ! (rVal
>>= rOpt
.bIsDirectionToSimplified
) )
631 //default is locale dependent:
632 if (MsLangId::isTraditionalChinese(rOpt
.nDefaultLanguage_CJK
))
634 rOpt
.bIsDirectionToSimplified
= sal_False
;
638 rOpt
.bIsDirectionToSimplified
= sal_True
;
642 case UPH_IS_USE_CHARACTER_VARIANTS
:
643 { rOpt
.bROIsUseCharacterVariants
= pROStates
[i
]; rVal
>>= rOpt
.bIsUseCharacterVariants
; } break;
644 case UPH_IS_TRANSLATE_COMMON_TERMS
:
645 { rOpt
.bROIsTranslateCommonTerms
= pROStates
[i
]; rVal
>>= rOpt
.bIsTranslateCommonTerms
; } break;
646 case UPH_IS_REVERSE_MAPPING
:
647 { rOpt
.bROIsReverseMapping
= pROStates
[i
]; rVal
>>= rOpt
.bIsReverseMapping
; } break;
649 case UPH_DATA_FILES_CHANGED_CHECK_VALUE
:
650 { rOpt
.bRODataFilesChangedCheckValue
= pROStates
[i
]; rVal
>>= rOpt
.nDataFilesChangedCheckValue
; } break;
652 case UPH_IS_GRAMMAR_AUTO
:
653 { rOpt
.bROIsGrammarAuto
= pROStates
[i
]; rVal
>>= rOpt
.bIsGrammarAuto
; }
655 case UPH_IS_GRAMMAR_INTERACTIVE
:
656 { rOpt
.bROIsGrammarInteractive
= pROStates
[i
]; rVal
>>= rOpt
.bIsGrammarInteractive
; }
660 DBG_ASSERT( 0, "unexpected case" );
666 DBG_ASSERT( bRes
, "LoadOptions failed" );
672 sal_Bool
SvtLinguConfigItem::SaveOptions( const uno::Sequence
< OUString
> &rProperyNames
)
677 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
679 sal_Bool bRet
= sal_False
;
680 const uno::Type
&rBOOL
= ::getBooleanCppuType();
681 const uno::Type
&rINT16
= ::getCppuType( (sal_Int16
*) NULL
);
682 const uno::Type
&rINT32
= ::getCppuType( (sal_Int32
*) NULL
);
684 sal_Int32 nProps
= rProperyNames
.getLength();
685 uno::Sequence
< uno::Any
> aValues( nProps
);
686 uno::Any
*pValue
= aValues
.getArray();
688 if (nProps
&& aValues
.getLength() == nProps
)
690 const SvtLinguOptions
&rOpt
= aOpt
;
692 OUString
aTmp( lcl_LanguageToCfgLocaleStr( rOpt
.nDefaultLanguage
) );
693 *pValue
++ = uno::makeAny( aTmp
); // 0
694 *pValue
++ = uno::makeAny( rOpt
.aActiveDics
); // 1
695 pValue
++->setValue( &rOpt
.bIsUseDictionaryList
, rBOOL
); // 2
696 pValue
++->setValue( &rOpt
.bIsIgnoreControlCharacters
, rBOOL
); // 3
697 aTmp
= lcl_LanguageToCfgLocaleStr( rOpt
.nDefaultLanguage_CJK
);
698 *pValue
++ = uno::makeAny( aTmp
); // 5
699 aTmp
= lcl_LanguageToCfgLocaleStr( rOpt
.nDefaultLanguage_CTL
);
700 *pValue
++ = uno::makeAny( aTmp
); // 6
702 pValue
++->setValue( &rOpt
.bIsSpellUpperCase
, rBOOL
); // 7
703 pValue
++->setValue( &rOpt
.bIsSpellWithDigits
, rBOOL
); // 8
704 pValue
++->setValue( &rOpt
.bIsSpellCapitalization
, rBOOL
); // 9
705 pValue
++->setValue( &rOpt
.bIsSpellAuto
, rBOOL
); // 10
706 pValue
++->setValue( &rOpt
.bIsSpellSpecial
, rBOOL
); // 11
707 pValue
++->setValue( &rOpt
.bIsSpellReverse
, rBOOL
); // 14
709 pValue
++->setValue( &rOpt
.nHyphMinLeading
, rINT16
); // 15
710 pValue
++->setValue( &rOpt
.nHyphMinTrailing
, rINT16
); // 16
711 pValue
++->setValue( &rOpt
.nHyphMinWordLength
, rINT16
); // 17
712 pValue
++->setValue( &rOpt
.bIsHyphSpecial
, rBOOL
); // 18
713 pValue
++->setValue( &rOpt
.bIsHyphAuto
, rBOOL
); // 19
715 *pValue
++ = uno::makeAny( rOpt
.aActiveConvDics
); // 20
717 pValue
++->setValue( &rOpt
.bIsIgnorePostPositionalWord
, rBOOL
); // 21
718 pValue
++->setValue( &rOpt
.bIsAutoCloseDialog
, rBOOL
); // 22
719 pValue
++->setValue( &rOpt
.bIsShowEntriesRecentlyUsedFirst
, rBOOL
); // 23
720 pValue
++->setValue( &rOpt
.bIsAutoReplaceUniqueEntries
, rBOOL
); // 24
722 pValue
++->setValue( &rOpt
.bIsDirectionToSimplified
, rBOOL
); // 25
723 pValue
++->setValue( &rOpt
.bIsUseCharacterVariants
, rBOOL
); // 26
724 pValue
++->setValue( &rOpt
.bIsTranslateCommonTerms
, rBOOL
); // 27
725 pValue
++->setValue( &rOpt
.bIsReverseMapping
, rBOOL
); // 28
727 pValue
++->setValue( &rOpt
.nDataFilesChangedCheckValue
, rINT32
); // 29
728 pValue
++->setValue( &rOpt
.bIsGrammarAuto
, rBOOL
); // 30
729 pValue
++->setValue( &rOpt
.bIsGrammarInteractive
, rBOOL
); // 31
731 bRet
|= PutProperties( rProperyNames
, aValues
);
740 sal_Bool
SvtLinguConfigItem::IsReadOnly( const OUString
&rPropertyName
) const
742 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
744 sal_Bool bReadOnly
= sal_False
;
746 if (GetHdlByName( nHdl
, rPropertyName
))
747 bReadOnly
= IsReadOnly( nHdl
);
751 sal_Bool
SvtLinguConfigItem::IsReadOnly( sal_Int32 nPropertyHandle
) const
753 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
755 sal_Bool bReadOnly
= sal_False
;
757 const SvtLinguOptions
&rOpt
= const_cast< SvtLinguConfigItem
* >(this)->aOpt
;
758 switch(nPropertyHandle
)
760 case UPH_IS_USE_DICTIONARY_LIST
: bReadOnly
= rOpt
.bROIsUseDictionaryList
; break;
761 case UPH_IS_IGNORE_CONTROL_CHARACTERS
: bReadOnly
= rOpt
.bROIsIgnoreControlCharacters
; break;
762 case UPH_IS_HYPH_AUTO
: bReadOnly
= rOpt
.bROIsHyphAuto
; break;
763 case UPH_IS_HYPH_SPECIAL
: bReadOnly
= rOpt
.bROIsHyphSpecial
; break;
764 case UPH_IS_SPELL_AUTO
: bReadOnly
= rOpt
.bROIsSpellAuto
; break;
765 case UPH_IS_SPELL_SPECIAL
: bReadOnly
= rOpt
.bROIsSpellSpecial
; break;
766 case UPH_IS_WRAP_REVERSE
: bReadOnly
= rOpt
.bROIsSpellReverse
; break;
767 case UPH_DEFAULT_LANGUAGE
: bReadOnly
= rOpt
.bRODefaultLanguage
; break;
768 case UPH_IS_SPELL_CAPITALIZATION
: bReadOnly
= rOpt
.bROIsSpellCapitalization
; break;
769 case UPH_IS_SPELL_WITH_DIGITS
: bReadOnly
= rOpt
.bROIsSpellWithDigits
; break;
770 case UPH_IS_SPELL_UPPER_CASE
: bReadOnly
= rOpt
.bROIsSpellUpperCase
; break;
771 case UPH_HYPH_MIN_LEADING
: bReadOnly
= rOpt
.bROHyphMinLeading
; break;
772 case UPH_HYPH_MIN_TRAILING
: bReadOnly
= rOpt
.bROHyphMinTrailing
; break;
773 case UPH_HYPH_MIN_WORD_LENGTH
: bReadOnly
= rOpt
.bROHyphMinWordLength
; break;
774 case UPH_ACTIVE_DICTIONARIES
: bReadOnly
= rOpt
.bROActiveDics
; break;
775 case UPH_ACTIVE_CONVERSION_DICTIONARIES
: bReadOnly
= rOpt
.bROActiveConvDics
; break;
776 case UPH_DEFAULT_LOCALE
: bReadOnly
= rOpt
.bRODefaultLanguage
; break;
777 case UPH_DEFAULT_LOCALE_CJK
: bReadOnly
= rOpt
.bRODefaultLanguage_CJK
; break;
778 case UPH_DEFAULT_LOCALE_CTL
: bReadOnly
= rOpt
.bRODefaultLanguage_CTL
; break;
779 case UPH_IS_IGNORE_POST_POSITIONAL_WORD
: bReadOnly
= rOpt
.bROIsIgnorePostPositionalWord
; break;
780 case UPH_IS_AUTO_CLOSE_DIALOG
: bReadOnly
= rOpt
.bROIsAutoCloseDialog
; break;
781 case UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST
: bReadOnly
= rOpt
.bROIsShowEntriesRecentlyUsedFirst
; break;
782 case UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES
: bReadOnly
= rOpt
.bROIsAutoReplaceUniqueEntries
; break;
783 case UPH_IS_DIRECTION_TO_SIMPLIFIED
: bReadOnly
= rOpt
.bROIsDirectionToSimplified
; break;
784 case UPH_IS_USE_CHARACTER_VARIANTS
: bReadOnly
= rOpt
.bROIsUseCharacterVariants
; break;
785 case UPH_IS_TRANSLATE_COMMON_TERMS
: bReadOnly
= rOpt
.bROIsTranslateCommonTerms
; break;
786 case UPH_IS_REVERSE_MAPPING
: bReadOnly
= rOpt
.bROIsReverseMapping
; break;
787 case UPH_DATA_FILES_CHANGED_CHECK_VALUE
: bReadOnly
= rOpt
.bRODataFilesChangedCheckValue
; break;
788 case UPH_IS_GRAMMAR_AUTO
: bReadOnly
= rOpt
.bROIsGrammarAuto
; break;
789 case UPH_IS_GRAMMAR_INTERACTIVE
: bReadOnly
= rOpt
.bROIsGrammarInteractive
; break;
791 DBG_ASSERT( 0, "unexpected property handle" );
796 //////////////////////////////////////////////////////////////////////
798 static SvtLinguConfigItem
*pCfgItem
= 0;
799 static sal_Int32 nCfgItemRefCount
= 0;
801 static const char aG_SupportedDictionaryFormats
[] = "SupportedDictionaryFormats";
802 static const char aG_Dictionaries
[] = "Dictionaries";
803 static const char aG_Locations
[] = "Locations";
804 static const char aG_Format
[] = "Format";
805 static const char aG_Locales
[] = "Locales";
806 static const char aG_DisabledDictionaries
[] = "DisabledDictionaries";
808 SvtLinguConfig::SvtLinguConfig()
810 // Global access, must be guarded (multithreading)
811 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
815 SvtLinguConfig::~SvtLinguConfig()
817 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
819 if (pCfgItem
&& pCfgItem
->IsModified())
822 if (--nCfgItemRefCount
<= 0)
830 SvtLinguConfigItem
& SvtLinguConfig::GetConfigItem()
832 // Global access, must be guarded (multithreading)
833 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
836 pCfgItem
= new SvtLinguConfigItem
;
837 ItemHolder1::holdConfigItem(E_LINGUCFG
);
842 uno::Sequence
< OUString
> SvtLinguConfig::GetNodeNames( const OUString
&rNode
)
844 return GetConfigItem().GetNodeNames( rNode
);
847 uno::Sequence
< uno::Any
> SvtLinguConfig::GetProperties( const uno::Sequence
< OUString
> &rNames
)
849 return GetConfigItem().GetProperties(rNames
);
852 sal_Bool
SvtLinguConfig::ReplaceSetProperties(
853 const OUString
&rNode
, uno::Sequence
< beans::PropertyValue
> rValues
)
855 return GetConfigItem().ReplaceSetProperties( rNode
, rValues
);
858 uno::Any
SvtLinguConfig::GetProperty( const OUString
&rPropertyName
) const
860 return GetConfigItem().GetProperty( rPropertyName
);
863 uno::Any
SvtLinguConfig::GetProperty( sal_Int32 nPropertyHandle
) const
865 return GetConfigItem().GetProperty( nPropertyHandle
);
868 sal_Bool
SvtLinguConfig::SetProperty( const OUString
&rPropertyName
, const uno::Any
&rValue
)
870 return GetConfigItem().SetProperty( rPropertyName
, rValue
);
873 sal_Bool
SvtLinguConfig::SetProperty( sal_Int32 nPropertyHandle
, const uno::Any
&rValue
)
875 return GetConfigItem().SetProperty( nPropertyHandle
, rValue
);
878 sal_Bool
SvtLinguConfig::GetOptions( SvtLinguOptions
&rOptions
) const
880 rOptions
= GetConfigItem().GetOptions();
884 sal_Bool
SvtLinguConfig::IsReadOnly( const OUString
&rPropertyName
) const
886 return GetConfigItem().IsReadOnly( rPropertyName
);
889 sal_Bool
SvtLinguConfig::GetElementNamesFor(
890 const OUString
&rNodeName
,
891 uno::Sequence
< OUString
> &rElementNames
) const
893 bool bSuccess
= false;
896 uno::Reference
< container::XNameAccess
> xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW
);
897 xNA
.set( xNA
->getByName(OUString("ServiceManager")), uno::UNO_QUERY_THROW
);
898 xNA
.set( xNA
->getByName( rNodeName
), uno::UNO_QUERY_THROW
);
899 rElementNames
= xNA
->getElementNames();
902 catch (uno::Exception
&)
908 sal_Bool
SvtLinguConfig::GetSupportedDictionaryFormatsFor(
909 const OUString
&rSetName
,
910 const OUString
&rSetEntry
,
911 uno::Sequence
< OUString
> &rFormatList
) const
913 if (rSetName
.isEmpty() || rSetEntry
.isEmpty())
915 bool bSuccess
= false;
918 uno::Reference
< container::XNameAccess
> xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW
);
919 xNA
.set( xNA
->getByName(OUString("ServiceManager")), uno::UNO_QUERY_THROW
);
920 xNA
.set( xNA
->getByName( rSetName
), uno::UNO_QUERY_THROW
);
921 xNA
.set( xNA
->getByName( rSetEntry
), uno::UNO_QUERY_THROW
);
922 if (xNA
->getByName( OUString(aG_SupportedDictionaryFormats
) ) >>= rFormatList
)
924 DBG_ASSERT( rFormatList
.getLength(), "supported dictionary format list is empty" );
926 catch (uno::Exception
&)
932 static bool lcl_GetFileUrlFromOrigin(
933 OUString
/*out*/ &rFileUrl
,
934 const OUString
&rOrigin
)
936 bool bSuccess
= false;
937 if (!rOrigin
.isEmpty())
939 OUString
aURL( rOrigin
);
940 if ( aURL
.startsWith( EXPAND_PROTOCOL
) )
943 OUString
aMacro( aURL
.copy( sizeof ( EXPAND_PROTOCOL
) -1 ) );
944 // decode uric class chars
945 aMacro
= Uri::decode( aMacro
, rtl_UriDecodeWithCharset
, RTL_TEXTENCODING_UTF8
);
946 // expand macro string
947 aURL
= util::theMacroExpander::get(
948 comphelper::getProcessComponentContext() )->expandMacros(
951 bool bIsFileUrl
= aURL
.startsWith( FILE_PROTOCOL
);
960 "unotools.config", "not a file URL, <" << aURL
<< ">" );
966 "unotools.config", "failed to get file URL, <" << aURL
<< ">" );
973 sal_Bool
SvtLinguConfig::GetDictionaryEntry(
974 const OUString
&rNodeName
,
975 SvtLinguConfigDictionaryEntry
&rDicEntry
) const
977 if (rNodeName
.isEmpty())
979 bool bSuccess
= false;
982 uno::Reference
< container::XNameAccess
> xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW
);
983 xNA
.set( xNA
->getByName(OUString("ServiceManager")), uno::UNO_QUERY_THROW
);
984 xNA
.set( xNA
->getByName(OUString(aG_Dictionaries
)), uno::UNO_QUERY_THROW
);
985 xNA
.set( xNA
->getByName( rNodeName
), uno::UNO_QUERY_THROW
);
987 // read group data...
988 uno::Sequence
< OUString
> aLocations
;
989 OUString aFormatName
;
990 uno::Sequence
< OUString
> aLocaleNames
;
991 bSuccess
= (xNA
->getByName( OUString(aG_Locations
) ) >>= aLocations
) &&
992 (xNA
->getByName( OUString(aG_Format
) ) >>= aFormatName
) &&
993 (xNA
->getByName( OUString(aG_Locales
) ) >>= aLocaleNames
);
994 DBG_ASSERT( aLocations
.getLength(), "Dictionary locations not set" );
995 DBG_ASSERT( !aFormatName
.isEmpty(), "Dictionary format name not set" );
996 DBG_ASSERT( aLocaleNames
.getLength(), "No locales set for the dictionary" );
998 // if sucessful continue
1001 // get file URL's for the locations
1002 for (sal_Int32 i
= 0; i
< aLocations
.getLength(); ++i
)
1004 OUString
&rLocation
= aLocations
[i
];
1005 if (!lcl_GetFileUrlFromOrigin( rLocation
, rLocation
))
1009 // if everything was fine return the result
1012 rDicEntry
.aLocations
= aLocations
;
1013 rDicEntry
.aFormatName
= aFormatName
;
1014 rDicEntry
.aLocaleNames
= aLocaleNames
;
1018 catch (uno::Exception
&)
1024 uno::Sequence
< OUString
> SvtLinguConfig::GetDisabledDictionaries() const
1026 uno::Sequence
< OUString
> aResult
;
1029 uno::Reference
< container::XNameAccess
> xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW
);
1030 xNA
.set( xNA
->getByName(OUString("ServiceManager")), uno::UNO_QUERY_THROW
);
1031 xNA
->getByName( OUString(aG_DisabledDictionaries
) ) >>= aResult
;
1033 catch (uno::Exception
&)
1039 std::vector
< SvtLinguConfigDictionaryEntry
> SvtLinguConfig::GetActiveDictionariesByFormat(
1040 const OUString
&rFormatName
)
1042 std::vector
< SvtLinguConfigDictionaryEntry
> aRes
;
1043 if (rFormatName
.isEmpty())
1048 uno::Sequence
< OUString
> aElementNames
;
1049 GetElementNamesFor( OUString(aG_Dictionaries
), aElementNames
);
1050 sal_Int32 nLen
= aElementNames
.getLength();
1051 const OUString
*pElementNames
= aElementNames
.getConstArray();
1053 SvtLinguConfigDictionaryEntry aDicEntry
;
1054 for (sal_Int32 i
= 0; i
< nLen
; ++i
)
1056 // does dictionary match the format we are looking for?
1057 if (GetDictionaryEntry( pElementNames
[i
], aDicEntry
) &&
1058 aDicEntry
.aFormatName
== rFormatName
)
1060 // check if it is active or not
1061 bool bDicIsActive
= true;
1062 const uno::Sequence
< OUString
> aDisabledDics( GetDisabledDictionaries() );
1063 for (sal_Int32 k
= 0; bDicIsActive
&& k
< aDisabledDics
.getLength(); ++k
)
1065 if (aDisabledDics
[k
] == pElementNames
[i
])
1066 bDicIsActive
= false;
1071 DBG_ASSERT( !aDicEntry
.aFormatName
.isEmpty(),
1072 "FormatName not set" );
1073 DBG_ASSERT( aDicEntry
.aLocations
.getLength(),
1074 "Locations not set" );
1075 DBG_ASSERT( aDicEntry
.aLocaleNames
.getLength(),
1076 "Locales not set" );
1077 aRes
.push_back( aDicEntry
);
1082 catch (uno::Exception
&)
1090 uno::Reference
< util::XChangesBatch
> SvtLinguConfig::GetMainUpdateAccess() const
1092 if (!m_xMainUpdateAccess
.is())
1096 // get configuration provider
1097 uno::Reference
< uno::XComponentContext
> xContext
= comphelper::getProcessComponentContext();
1098 uno::Reference
< lang::XMultiServiceFactory
> xConfigurationProvider
=
1099 configuration::theDefaultProvider::get( xContext
);
1101 // get configuration update access
1102 beans::PropertyValue aValue
;
1103 aValue
.Name
= OUString("nodepath");
1104 aValue
.Value
= uno::makeAny(OUString("org.openoffice.Office.Linguistic"));
1105 uno::Sequence
< uno::Any
> aProps(1);
1106 aProps
[0] <<= aValue
;
1107 m_xMainUpdateAccess
= uno::Reference
< util::XChangesBatch
>(
1108 xConfigurationProvider
->createInstanceWithArguments(
1109 OUString("com.sun.star.configuration.ConfigurationUpdateAccess"), aProps
),
1110 uno::UNO_QUERY_THROW
);
1112 catch (uno::Exception
&)
1117 return m_xMainUpdateAccess
;
1121 OUString
SvtLinguConfig::GetVendorImageUrl_Impl(
1122 const OUString
&rServiceImplName
,
1123 const OUString
&rImageName
) const
1128 uno::Reference
< container::XNameAccess
> xImagesNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW
);
1129 xImagesNA
.set( xImagesNA
->getByName(OUString("Images")), uno::UNO_QUERY_THROW
);
1131 uno::Reference
< container::XNameAccess
> xNA( xImagesNA
->getByName(OUString("ServiceNameEntries")), uno::UNO_QUERY_THROW
);
1132 xNA
.set( xNA
->getByName( rServiceImplName
), uno::UNO_QUERY_THROW
);
1133 uno::Any
aAny(xNA
->getByName(OUString("VendorImagesNode")));
1134 OUString aVendorImagesNode
;
1135 if (aAny
>>= aVendorImagesNode
)
1138 xNA
.set( xNA
->getByName(OUString("VendorImages")), uno::UNO_QUERY_THROW
);
1139 xNA
.set( xNA
->getByName( aVendorImagesNode
), uno::UNO_QUERY_THROW
);
1140 aAny
= xNA
->getByName( rImageName
);
1144 if (lcl_GetFileUrlFromOrigin( aTmp
, aTmp
))
1149 catch (uno::Exception
&)
1151 DBG_ASSERT( 0, "exception caught. GetVendorImageUrl_Impl failed" );
1157 OUString
SvtLinguConfig::GetSpellAndGrammarContextSuggestionImage(
1158 const OUString
&rServiceImplName
1162 if (!rServiceImplName
.isEmpty())
1164 OUString
aImageName( "SpellAndGrammarContextMenuSuggestionImage" );
1165 OUString
aPath( GetVendorImageUrl_Impl( rServiceImplName
, aImageName
) );
1172 OUString
SvtLinguConfig::GetSpellAndGrammarContextDictionaryImage(
1173 const OUString
&rServiceImplName
1177 if (!rServiceImplName
.isEmpty())
1179 OUString
aImageName( "SpellAndGrammarContextMenuDictionaryImage" );
1180 OUString
aPath( GetVendorImageUrl_Impl( rServiceImplName
, aImageName
) );
1186 OUString
SvtLinguConfig::GetSynonymsContextImage(
1187 const OUString
&rServiceImplName
1191 if (!rServiceImplName
.isEmpty())
1193 OUString
aImageName( "SynonymsContextMenuImage" );
1194 OUString
aPath( GetVendorImageUrl_Impl( rServiceImplName
, aImageName
) );
1200 bool SvtLinguConfig::HasGrammarChecker() const
1206 uno::Reference
< container::XNameAccess
> xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW
);
1207 xNA
.set( xNA
->getByName( OUString("ServiceManager") ), uno::UNO_QUERY_THROW
);
1208 xNA
.set( xNA
->getByName( OUString("GrammarCheckerList") ), uno::UNO_QUERY_THROW
);
1210 uno::Sequence
< OUString
> aElementNames( xNA
->getElementNames() );
1211 bRes
= aElementNames
.getLength() > 0;
1213 catch (const uno::Exception
&)
1220 //////////////////////////////////////////////////////////////////////
1222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */