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 <sal/config.h>
22 #include <boost/noncopyable.hpp>
23 #include <com/sun/star/lang/Locale.hpp>
24 #include <com/sun/star/lang/XMultiServiceFactory.hpp>
25 #include <com/sun/star/lang/XSingleServiceFactory.hpp>
26 #include <com/sun/star/configuration/theDefaultProvider.hpp>
27 #include <com/sun/star/container/XNameAccess.hpp>
28 #include <com/sun/star/container/XNameContainer.hpp>
29 #include <com/sun/star/container/XNameReplace.hpp>
30 #include <com/sun/star/util/theMacroExpander.hpp>
31 #include <rtl/uri.hxx>
32 #include <rtl/instance.hxx>
33 #include <osl/mutex.hxx>
34 #include <i18nlangtag/mslangid.hxx>
35 #include <i18nlangtag/languagetag.hxx>
36 #include <tools/debug.hxx>
37 #include <unotools/lingucfg.hxx>
38 #include <unotools/linguprops.hxx>
39 #include <sal/macros.h>
41 #include <comphelper/processfactory.hxx>
43 #include "itemholder1.hxx"
45 using namespace com::sun::star
;
49 #define EXPAND_PROTOCOL "vnd.sun.star.expand:"
50 #define FILE_PROTOCOL "file:///"
54 class theSvtLinguConfigItemMutex
:
55 public rtl::Static
< osl::Mutex
, theSvtLinguConfigItemMutex
> {};
58 static bool lcl_SetLocale( sal_Int16
&rLanguage
, const uno::Any
&rVal
)
63 if (rVal
>>= aNew
) // conversion successful?
65 sal_Int16 nNew
= LanguageTag::convertToLanguageType( aNew
, false);
66 if (nNew
!= rLanguage
)
75 static inline const OUString
lcl_LanguageToCfgLocaleStr( sal_Int16 nLanguage
)
78 if (LANGUAGE_SYSTEM
!= nLanguage
)
79 aRes
= LanguageTag::convertToBcp47( nLanguage
);
83 static sal_Int16
lcl_CfgAnyToLanguage( const uno::Any
&rVal
)
87 return (aTmp
.isEmpty()) ? LANGUAGE_SYSTEM
: LanguageTag::convertToLanguageTypeWithFallback( aTmp
);
90 SvtLinguOptions::SvtLinguOptions()
91 : bROActiveDics(false)
92 , bROActiveConvDics(false)
95 , nHyphMinWordLength(0)
96 , bROHyphMinLeading(false)
97 , bROHyphMinTrailing(false)
98 , bROHyphMinWordLength(false)
99 , nDefaultLanguage(LANGUAGE_NONE
)
100 , nDefaultLanguage_CJK(LANGUAGE_NONE
)
101 , nDefaultLanguage_CTL(LANGUAGE_NONE
)
102 , bRODefaultLanguage(false)
103 , bRODefaultLanguage_CJK(false)
104 , bRODefaultLanguage_CTL(false)
105 , bIsSpellSpecial(true)
106 , bIsSpellAuto(false)
107 , bIsSpellReverse(false)
108 , bROIsSpellSpecial(false)
109 , bROIsSpellAuto(false)
110 , bROIsSpellReverse(false)
111 , bIsHyphSpecial(true)
113 , bROIsHyphSpecial(false)
114 , bROIsHyphAuto(false)
115 , bIsUseDictionaryList(true)
116 , bIsIgnoreControlCharacters(true)
117 , bROIsUseDictionaryList(false)
118 , bROIsIgnoreControlCharacters(false)
119 , bIsSpellWithDigits(false)
120 , bIsSpellUpperCase(false)
121 , bIsSpellCapitalization(true)
122 , bROIsSpellWithDigits(false)
123 , bROIsSpellUpperCase(false)
124 , bROIsSpellCapitalization(false)
125 , bIsIgnorePostPositionalWord(true)
126 , bIsAutoCloseDialog(false)
127 , bIsShowEntriesRecentlyUsedFirst(false)
128 , bIsAutoReplaceUniqueEntries(false)
129 , bIsDirectionToSimplified(true)
130 , bIsUseCharacterVariants(false)
131 , bIsTranslateCommonTerms(false)
132 , bIsReverseMapping(false)
133 , bROIsIgnorePostPositionalWord(false)
134 , bROIsAutoCloseDialog(false)
135 , bROIsShowEntriesRecentlyUsedFirst(false)
136 , bROIsAutoReplaceUniqueEntries(false)
137 , bROIsDirectionToSimplified(false)
138 , bROIsUseCharacterVariants(false)
139 , bROIsTranslateCommonTerms(false)
140 , bROIsReverseMapping(false)
141 , nDataFilesChangedCheckValue(0)
142 , bRODataFilesChangedCheckValue(false)
143 , bIsGrammarAuto(false)
144 , bIsGrammarInteractive(false)
145 , bROIsGrammarAuto(false)
146 , bROIsGrammarInteractive(false)
150 class SvtLinguConfigItem
: public utl::ConfigItem
, private boost::noncopyable
152 SvtLinguOptions aOpt
;
154 static bool GetHdlByName( sal_Int32
&rnHdl
, const OUString
&rPropertyName
, bool bFullPropName
= false );
155 static const uno::Sequence
< OUString
> GetPropertyNames();
156 bool LoadOptions( const uno::Sequence
< OUString
> &rProperyNames
);
157 bool SaveOptions( const uno::Sequence
< OUString
> &rProperyNames
);
160 SvtLinguConfigItem();
161 virtual ~SvtLinguConfigItem();
164 virtual void Notify( const com::sun::star::uno::Sequence
< OUString
> &rPropertyNames
) SAL_OVERRIDE
;
165 virtual void Commit() SAL_OVERRIDE
;
167 // make some protected functions of utl::ConfigItem public
168 using utl::ConfigItem::GetNodeNames
;
169 using utl::ConfigItem::GetProperties
;
170 //using utl::ConfigItem::PutProperties;
171 //using utl::ConfigItem::SetSetProperties;
172 using utl::ConfigItem::ReplaceSetProperties
;
173 //using utl::ConfigItem::GetReadOnlyStates;
175 com::sun::star::uno::Any
176 GetProperty( const OUString
&rPropertyName
) const;
177 com::sun::star::uno::Any
178 GetProperty( sal_Int32 nPropertyHandle
) const;
180 bool SetProperty( const OUString
&rPropertyName
,
181 const com::sun::star::uno::Any
&rValue
);
182 bool SetProperty( sal_Int32 nPropertyHandle
,
183 const com::sun::star::uno::Any
&rValue
);
185 const SvtLinguOptions
& GetOptions() const;
187 bool IsReadOnly( const OUString
&rPropertyName
) const;
188 bool IsReadOnly( sal_Int32 nPropertyHandle
) const;
191 SvtLinguConfigItem::SvtLinguConfigItem() :
192 utl::ConfigItem( OUString("Office.Linguistic") )
194 const uno::Sequence
< OUString
> &rPropertyNames
= GetPropertyNames();
195 LoadOptions( rPropertyNames
);
198 // request notify events when properties change
199 EnableNotification( rPropertyNames
);
202 SvtLinguConfigItem::~SvtLinguConfigItem()
204 //! Commit (SaveOptions) will be called by the d-tor of the base called !
207 void SvtLinguConfigItem::Notify( const uno::Sequence
< OUString
> &rPropertyNames
)
209 LoadOptions( rPropertyNames
);
213 void SvtLinguConfigItem::Commit()
215 SaveOptions( GetPropertyNames() );
218 static struct NamesToHdl
220 const char *pFullPropName
; // full qualified name as used in configuration
221 const char *pPropName
; // property name only (atom) of above
222 sal_Int32 nHdl
; // numeric handle representing the property
225 {/* 0 */ "General/DefaultLocale", UPN_DEFAULT_LOCALE
, UPH_DEFAULT_LOCALE
},
226 {/* 1 */ "General/DictionaryList/ActiveDictionaries", UPN_ACTIVE_DICTIONARIES
, UPH_ACTIVE_DICTIONARIES
},
227 {/* 2 */ "General/DictionaryList/IsUseDictionaryList", UPN_IS_USE_DICTIONARY_LIST
, UPH_IS_USE_DICTIONARY_LIST
},
228 {/* 3 */ "General/IsIgnoreControlCharacters", UPN_IS_IGNORE_CONTROL_CHARACTERS
, UPH_IS_IGNORE_CONTROL_CHARACTERS
},
229 {/* 5 */ "General/DefaultLocale_CJK", UPN_DEFAULT_LOCALE_CJK
, UPH_DEFAULT_LOCALE_CJK
},
230 {/* 6 */ "General/DefaultLocale_CTL", UPN_DEFAULT_LOCALE_CTL
, UPH_DEFAULT_LOCALE_CTL
},
232 {/* 7 */ "SpellChecking/IsSpellUpperCase", UPN_IS_SPELL_UPPER_CASE
, UPH_IS_SPELL_UPPER_CASE
},
233 {/* 8 */ "SpellChecking/IsSpellWithDigits", UPN_IS_SPELL_WITH_DIGITS
, UPH_IS_SPELL_WITH_DIGITS
},
234 {/* 9 */ "SpellChecking/IsSpellCapitalization", UPN_IS_SPELL_CAPITALIZATION
, UPH_IS_SPELL_CAPITALIZATION
},
235 {/* 10 */ "SpellChecking/IsSpellAuto", UPN_IS_SPELL_AUTO
, UPH_IS_SPELL_AUTO
},
236 {/* 11 */ "SpellChecking/IsSpellSpecial", UPN_IS_SPELL_SPECIAL
, UPH_IS_SPELL_SPECIAL
},
237 {/* 14 */ "SpellChecking/IsReverseDirection", UPN_IS_WRAP_REVERSE
, UPH_IS_WRAP_REVERSE
},
239 {/* 15 */ "Hyphenation/MinLeading", UPN_HYPH_MIN_LEADING
, UPH_HYPH_MIN_LEADING
},
240 {/* 16 */ "Hyphenation/MinTrailing", UPN_HYPH_MIN_TRAILING
, UPH_HYPH_MIN_TRAILING
},
241 {/* 17 */ "Hyphenation/MinWordLength", UPN_HYPH_MIN_WORD_LENGTH
, UPH_HYPH_MIN_WORD_LENGTH
},
242 {/* 18 */ "Hyphenation/IsHyphSpecial", UPN_IS_HYPH_SPECIAL
, UPH_IS_HYPH_SPECIAL
},
243 {/* 19 */ "Hyphenation/IsHyphAuto", UPN_IS_HYPH_AUTO
, UPH_IS_HYPH_AUTO
},
245 {/* 20 */ "TextConversion/ActiveConversionDictionaries", UPN_ACTIVE_CONVERSION_DICTIONARIES
, UPH_ACTIVE_CONVERSION_DICTIONARIES
},
246 {/* 21 */ "TextConversion/IsIgnorePostPositionalWord", UPN_IS_IGNORE_POST_POSITIONAL_WORD
, UPH_IS_IGNORE_POST_POSITIONAL_WORD
},
247 {/* 22 */ "TextConversion/IsAutoCloseDialog", UPN_IS_AUTO_CLOSE_DIALOG
, UPH_IS_AUTO_CLOSE_DIALOG
},
248 {/* 23 */ "TextConversion/IsShowEntriesRecentlyUsedFirst", UPN_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST
, UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST
},
249 {/* 24 */ "TextConversion/IsAutoReplaceUniqueEntries", UPN_IS_AUTO_REPLACE_UNIQUE_ENTRIES
, UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES
},
250 {/* 25 */ "TextConversion/IsDirectionToSimplified", UPN_IS_DIRECTION_TO_SIMPLIFIED
, UPH_IS_DIRECTION_TO_SIMPLIFIED
},
251 {/* 26 */ "TextConversion/IsUseCharacterVariants", UPN_IS_USE_CHARACTER_VARIANTS
, UPH_IS_USE_CHARACTER_VARIANTS
},
252 {/* 27 */ "TextConversion/IsTranslateCommonTerms", UPN_IS_TRANSLATE_COMMON_TERMS
, UPH_IS_TRANSLATE_COMMON_TERMS
},
253 {/* 28 */ "TextConversion/IsReverseMapping", UPN_IS_REVERSE_MAPPING
, UPH_IS_REVERSE_MAPPING
},
255 {/* 29 */ "ServiceManager/DataFilesChangedCheckValue", UPN_DATA_FILES_CHANGED_CHECK_VALUE
, UPH_DATA_FILES_CHANGED_CHECK_VALUE
},
257 {/* 30 */ "GrammarChecking/IsAutoCheck", UPN_IS_GRAMMAR_AUTO
, UPH_IS_GRAMMAR_AUTO
},
258 {/* 31 */ "GrammarChecking/IsInteractiveCheck", UPN_IS_GRAMMAR_INTERACTIVE
, UPH_IS_GRAMMAR_INTERACTIVE
},
260 /* similar to entry 0 (thus no own configuration entry) but with different property name and type */
261 { NULL
, UPN_DEFAULT_LANGUAGE
, UPH_DEFAULT_LANGUAGE
},
266 const uno::Sequence
< OUString
> SvtLinguConfigItem::GetPropertyNames()
268 uno::Sequence
< OUString
> aNames
;
270 sal_Int32 nMax
= SAL_N_ELEMENTS(aNamesToHdl
);
272 aNames
.realloc( nMax
);
273 OUString
*pNames
= aNames
.getArray();
275 for (sal_Int32 i
= 0; i
< nMax
; ++i
)
277 const sal_Char
*pFullPropName
= aNamesToHdl
[i
].pFullPropName
;
279 pNames
[ nIdx
++ ] = OUString::createFromAscii( pFullPropName
);
281 aNames
.realloc( nIdx
);
286 bool SvtLinguConfigItem::GetHdlByName(
288 const OUString
&rPropertyName
,
291 NamesToHdl
*pEntry
= &aNamesToHdl
[0];
295 while (pEntry
&& pEntry
->pFullPropName
!= NULL
)
297 if (rPropertyName
.equalsAscii( pEntry
->pFullPropName
))
299 rnHdl
= pEntry
->nHdl
;
304 return pEntry
&& pEntry
->pFullPropName
!= NULL
;
308 while (pEntry
&& pEntry
->pPropName
!= NULL
)
310 if (rPropertyName
.equalsAscii( pEntry
->pPropName
))
312 rnHdl
= pEntry
->nHdl
;
317 return pEntry
&& pEntry
->pPropName
!= NULL
;
321 uno::Any
SvtLinguConfigItem::GetProperty( const OUString
&rPropertyName
) const
323 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
326 return GetHdlByName( nHdl
, rPropertyName
) ? GetProperty( nHdl
) : uno::Any();
329 uno::Any
SvtLinguConfigItem::GetProperty( sal_Int32 nPropertyHandle
) const
331 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
335 const sal_Int16
*pnVal
= 0;
336 const bool *pbVal
= 0;
337 const sal_Int32
*pnInt32Val
= 0;
339 const SvtLinguOptions
&rOpt
= const_cast< SvtLinguConfigItem
* >(this)->aOpt
;
340 switch (nPropertyHandle
)
342 case UPH_IS_USE_DICTIONARY_LIST
: pbVal
= &rOpt
.bIsUseDictionaryList
; break;
343 case UPH_IS_IGNORE_CONTROL_CHARACTERS
: pbVal
= &rOpt
.bIsIgnoreControlCharacters
; break;
344 case UPH_IS_HYPH_AUTO
: pbVal
= &rOpt
.bIsHyphAuto
; break;
345 case UPH_IS_HYPH_SPECIAL
: pbVal
= &rOpt
.bIsHyphSpecial
; break;
346 case UPH_IS_SPELL_AUTO
: pbVal
= &rOpt
.bIsSpellAuto
; break;
347 case UPH_IS_SPELL_SPECIAL
: pbVal
= &rOpt
.bIsSpellSpecial
; break;
348 case UPH_IS_WRAP_REVERSE
: pbVal
= &rOpt
.bIsSpellReverse
; break;
349 case UPH_DEFAULT_LANGUAGE
: pnVal
= &rOpt
.nDefaultLanguage
; break;
350 case UPH_IS_SPELL_CAPITALIZATION
: pbVal
= &rOpt
.bIsSpellCapitalization
; break;
351 case UPH_IS_SPELL_WITH_DIGITS
: pbVal
= &rOpt
.bIsSpellWithDigits
; break;
352 case UPH_IS_SPELL_UPPER_CASE
: pbVal
= &rOpt
.bIsSpellUpperCase
; break;
353 case UPH_HYPH_MIN_LEADING
: pnVal
= &rOpt
.nHyphMinLeading
; break;
354 case UPH_HYPH_MIN_TRAILING
: pnVal
= &rOpt
.nHyphMinTrailing
; break;
355 case UPH_HYPH_MIN_WORD_LENGTH
: pnVal
= &rOpt
.nHyphMinWordLength
; break;
356 case UPH_ACTIVE_DICTIONARIES
:
358 aRes
<<= rOpt
.aActiveDics
;
361 case UPH_ACTIVE_CONVERSION_DICTIONARIES
:
363 aRes
<<= rOpt
.aActiveConvDics
;
366 case UPH_DEFAULT_LOCALE
:
368 lang::Locale
aLocale( LanguageTag::convertToLocale( rOpt
.nDefaultLanguage
, false) );
369 aRes
.setValue( &aLocale
, ::getCppuType((lang::Locale
*)0 ));
372 case UPH_DEFAULT_LOCALE_CJK
:
374 lang::Locale
aLocale( LanguageTag::convertToLocale( rOpt
.nDefaultLanguage_CJK
, false) );
375 aRes
.setValue( &aLocale
, ::getCppuType((lang::Locale
*)0 ));
378 case UPH_DEFAULT_LOCALE_CTL
:
380 lang::Locale
aLocale( LanguageTag::convertToLocale( rOpt
.nDefaultLanguage_CTL
, false) );
381 aRes
.setValue( &aLocale
, ::getCppuType((lang::Locale
*)0 ));
384 case UPH_IS_IGNORE_POST_POSITIONAL_WORD
: pbVal
= &rOpt
.bIsIgnorePostPositionalWord
; break;
385 case UPH_IS_AUTO_CLOSE_DIALOG
: pbVal
= &rOpt
.bIsAutoCloseDialog
; break;
386 case UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST
: pbVal
= &rOpt
.bIsShowEntriesRecentlyUsedFirst
; break;
387 case UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES
: pbVal
= &rOpt
.bIsAutoReplaceUniqueEntries
; break;
389 case UPH_IS_DIRECTION_TO_SIMPLIFIED
: pbVal
= &rOpt
.bIsDirectionToSimplified
; break;
390 case UPH_IS_USE_CHARACTER_VARIANTS
: pbVal
= &rOpt
.bIsUseCharacterVariants
; break;
391 case UPH_IS_TRANSLATE_COMMON_TERMS
: pbVal
= &rOpt
.bIsTranslateCommonTerms
; break;
392 case UPH_IS_REVERSE_MAPPING
: pbVal
= &rOpt
.bIsReverseMapping
; break;
394 case UPH_DATA_FILES_CHANGED_CHECK_VALUE
: pnInt32Val
= &rOpt
.nDataFilesChangedCheckValue
; break;
395 case UPH_IS_GRAMMAR_AUTO
: pbVal
= &rOpt
.bIsGrammarAuto
; break;
396 case UPH_IS_GRAMMAR_INTERACTIVE
: pbVal
= &rOpt
.bIsGrammarInteractive
; break;
398 DBG_ASSERT( false, "unexpected property handle" );
406 aRes
<<= *pnInt32Val
;
411 bool SvtLinguConfigItem::SetProperty( const OUString
&rPropertyName
, const uno::Any
&rValue
)
413 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
417 if (GetHdlByName( nHdl
, rPropertyName
))
418 bSucc
= SetProperty( nHdl
, rValue
);
422 bool SvtLinguConfigItem::SetProperty( sal_Int32 nPropertyHandle
, const uno::Any
&rValue
)
424 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
427 if (!rValue
.hasValue())
432 sal_Int16
*pnVal
= 0;
434 sal_Int32
*pnInt32Val
= 0;
436 SvtLinguOptions
&rOpt
= aOpt
;
437 switch (nPropertyHandle
)
439 case UPH_IS_USE_DICTIONARY_LIST
: pbVal
= &rOpt
.bIsUseDictionaryList
; break;
440 case UPH_IS_IGNORE_CONTROL_CHARACTERS
: pbVal
= &rOpt
.bIsIgnoreControlCharacters
; break;
441 case UPH_IS_HYPH_AUTO
: pbVal
= &rOpt
.bIsHyphAuto
; break;
442 case UPH_IS_HYPH_SPECIAL
: pbVal
= &rOpt
.bIsHyphSpecial
; break;
443 case UPH_IS_SPELL_AUTO
: pbVal
= &rOpt
.bIsSpellAuto
; break;
444 case UPH_IS_SPELL_SPECIAL
: pbVal
= &rOpt
.bIsSpellSpecial
; break;
445 case UPH_IS_WRAP_REVERSE
: pbVal
= &rOpt
.bIsSpellReverse
; break;
446 case UPH_DEFAULT_LANGUAGE
: pnVal
= &rOpt
.nDefaultLanguage
; break;
447 case UPH_IS_SPELL_CAPITALIZATION
: pbVal
= &rOpt
.bIsSpellCapitalization
; break;
448 case UPH_IS_SPELL_WITH_DIGITS
: pbVal
= &rOpt
.bIsSpellWithDigits
; break;
449 case UPH_IS_SPELL_UPPER_CASE
: pbVal
= &rOpt
.bIsSpellUpperCase
; break;
450 case UPH_HYPH_MIN_LEADING
: pnVal
= &rOpt
.nHyphMinLeading
; break;
451 case UPH_HYPH_MIN_TRAILING
: pnVal
= &rOpt
.nHyphMinTrailing
; break;
452 case UPH_HYPH_MIN_WORD_LENGTH
: pnVal
= &rOpt
.nHyphMinWordLength
; break;
453 case UPH_ACTIVE_DICTIONARIES
:
455 rValue
>>= rOpt
.aActiveDics
;
459 case UPH_ACTIVE_CONVERSION_DICTIONARIES
:
461 rValue
>>= rOpt
.aActiveConvDics
;
465 case UPH_DEFAULT_LOCALE
:
467 bSucc
= lcl_SetLocale( rOpt
.nDefaultLanguage
, rValue
);
471 case UPH_DEFAULT_LOCALE_CJK
:
473 bSucc
= lcl_SetLocale( rOpt
.nDefaultLanguage_CJK
, rValue
);
477 case UPH_DEFAULT_LOCALE_CTL
:
479 bSucc
= lcl_SetLocale( rOpt
.nDefaultLanguage_CTL
, rValue
);
483 case UPH_IS_IGNORE_POST_POSITIONAL_WORD
: pbVal
= &rOpt
.bIsIgnorePostPositionalWord
; break;
484 case UPH_IS_AUTO_CLOSE_DIALOG
: pbVal
= &rOpt
.bIsAutoCloseDialog
; break;
485 case UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST
: pbVal
= &rOpt
.bIsShowEntriesRecentlyUsedFirst
; break;
486 case UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES
: pbVal
= &rOpt
.bIsAutoReplaceUniqueEntries
; break;
488 case UPH_IS_DIRECTION_TO_SIMPLIFIED
: pbVal
= &rOpt
.bIsDirectionToSimplified
; break;
489 case UPH_IS_USE_CHARACTER_VARIANTS
: pbVal
= &rOpt
.bIsUseCharacterVariants
; break;
490 case UPH_IS_TRANSLATE_COMMON_TERMS
: pbVal
= &rOpt
.bIsTranslateCommonTerms
; break;
491 case UPH_IS_REVERSE_MAPPING
: pbVal
= &rOpt
.bIsReverseMapping
; break;
493 case UPH_DATA_FILES_CHANGED_CHECK_VALUE
: pnInt32Val
= &rOpt
.nDataFilesChangedCheckValue
; break;
494 case UPH_IS_GRAMMAR_AUTO
: pbVal
= &rOpt
.bIsGrammarAuto
; break;
495 case UPH_IS_GRAMMAR_INTERACTIVE
: pbVal
= &rOpt
.bIsGrammarInteractive
; break;
497 DBG_ASSERT( false, "unexpected property handle" );
515 sal_Int16 nNew
= sal_Int16();
528 sal_Int32 nNew
= sal_Int32();
531 if (nNew
!= *pnInt32Val
)
547 const SvtLinguOptions
& SvtLinguConfigItem::GetOptions() const
549 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
553 bool SvtLinguConfigItem::LoadOptions( const uno::Sequence
< OUString
> &rProperyNames
)
555 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
559 const OUString
*pProperyNames
= rProperyNames
.getConstArray();
560 sal_Int32 nProps
= rProperyNames
.getLength();
562 const uno::Sequence
< uno::Any
> aValues
= GetProperties( rProperyNames
);
563 const uno::Sequence
< sal_Bool
> aROStates
= GetReadOnlyStates( rProperyNames
);
565 if (nProps
&& aValues
.getLength() == nProps
&& aROStates
.getLength() == nProps
)
567 SvtLinguOptions
&rOpt
= aOpt
;
569 const uno::Any
*pValue
= aValues
.getConstArray();
570 const sal_Bool
*pROStates
= aROStates
.getConstArray();
571 for (sal_Int32 i
= 0; i
< nProps
; ++i
)
573 const uno::Any
&rVal
= pValue
[i
];
574 sal_Int32 nPropertyHandle
;
575 GetHdlByName( nPropertyHandle
, pProperyNames
[i
], true );
576 switch ( nPropertyHandle
)
578 case UPH_DEFAULT_LOCALE
:
579 { rOpt
.bRODefaultLanguage
= pROStates
[i
]; rOpt
.nDefaultLanguage
= lcl_CfgAnyToLanguage( rVal
); } break;
580 case UPH_ACTIVE_DICTIONARIES
:
581 { rOpt
.bROActiveDics
= pROStates
[i
]; rVal
>>= rOpt
.aActiveDics
; } break;
582 case UPH_IS_USE_DICTIONARY_LIST
:
583 { rOpt
.bROIsUseDictionaryList
= pROStates
[i
]; rVal
>>= rOpt
.bIsUseDictionaryList
; } break;
584 case UPH_IS_IGNORE_CONTROL_CHARACTERS
:
585 { rOpt
.bROIsIgnoreControlCharacters
= pROStates
[i
]; rVal
>>= rOpt
.bIsIgnoreControlCharacters
; } break;
586 case UPH_DEFAULT_LOCALE_CJK
:
587 { rOpt
.bRODefaultLanguage_CJK
= pROStates
[i
]; rOpt
.nDefaultLanguage_CJK
= lcl_CfgAnyToLanguage( rVal
); } break;
588 case UPH_DEFAULT_LOCALE_CTL
:
589 { rOpt
.bRODefaultLanguage_CTL
= pROStates
[i
]; rOpt
.nDefaultLanguage_CTL
= lcl_CfgAnyToLanguage( rVal
); } break;
591 case UPH_IS_SPELL_UPPER_CASE
:
592 { rOpt
.bROIsSpellUpperCase
= pROStates
[i
]; rVal
>>= rOpt
.bIsSpellUpperCase
; } break;
593 case UPH_IS_SPELL_WITH_DIGITS
:
594 { rOpt
.bROIsSpellWithDigits
= pROStates
[i
]; rVal
>>= rOpt
.bIsSpellWithDigits
; } break;
595 case UPH_IS_SPELL_CAPITALIZATION
:
596 { rOpt
.bROIsSpellCapitalization
= pROStates
[i
]; rVal
>>= rOpt
.bIsSpellCapitalization
; } break;
597 case UPH_IS_SPELL_AUTO
:
598 { rOpt
.bROIsSpellAuto
= pROStates
[i
]; rVal
>>= rOpt
.bIsSpellAuto
; } break;
599 case UPH_IS_SPELL_SPECIAL
:
600 { rOpt
.bROIsSpellSpecial
= pROStates
[i
]; rVal
>>= rOpt
.bIsSpellSpecial
; } break;
601 case UPH_IS_WRAP_REVERSE
:
602 { rOpt
.bROIsSpellReverse
= pROStates
[i
]; rVal
>>= rOpt
.bIsSpellReverse
; } break;
604 case UPH_HYPH_MIN_LEADING
:
605 { rOpt
.bROHyphMinLeading
= pROStates
[i
]; rVal
>>= rOpt
.nHyphMinLeading
; } break;
606 case UPH_HYPH_MIN_TRAILING
:
607 { rOpt
.bROHyphMinTrailing
= pROStates
[i
]; rVal
>>= rOpt
.nHyphMinTrailing
; } break;
608 case UPH_HYPH_MIN_WORD_LENGTH
:
609 { rOpt
.bROHyphMinWordLength
= pROStates
[i
]; rVal
>>= rOpt
.nHyphMinWordLength
; } break;
610 case UPH_IS_HYPH_SPECIAL
:
611 { rOpt
.bROIsHyphSpecial
= pROStates
[i
]; rVal
>>= rOpt
.bIsHyphSpecial
; } break;
612 case UPH_IS_HYPH_AUTO
:
613 { rOpt
.bROIsHyphAuto
= pROStates
[i
]; rVal
>>= rOpt
.bIsHyphAuto
; } break;
615 case UPH_ACTIVE_CONVERSION_DICTIONARIES
: { rOpt
.bROActiveConvDics
= pROStates
[i
]; rVal
>>= rOpt
.aActiveConvDics
; } break;
617 case UPH_IS_IGNORE_POST_POSITIONAL_WORD
:
618 { rOpt
.bROIsIgnorePostPositionalWord
= pROStates
[i
]; rVal
>>= rOpt
.bIsIgnorePostPositionalWord
; } break;
619 case UPH_IS_AUTO_CLOSE_DIALOG
:
620 { rOpt
.bROIsAutoCloseDialog
= pROStates
[i
]; rVal
>>= rOpt
.bIsAutoCloseDialog
; } break;
621 case UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST
:
622 { rOpt
.bROIsShowEntriesRecentlyUsedFirst
= pROStates
[i
]; rVal
>>= rOpt
.bIsShowEntriesRecentlyUsedFirst
; } break;
623 case UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES
:
624 { rOpt
.bROIsAutoReplaceUniqueEntries
= pROStates
[i
]; rVal
>>= rOpt
.bIsAutoReplaceUniqueEntries
; } break;
626 case UPH_IS_DIRECTION_TO_SIMPLIFIED
:
627 { rOpt
.bROIsDirectionToSimplified
= pROStates
[i
];
628 if( ! (rVal
>>= rOpt
.bIsDirectionToSimplified
) )
630 //default is locale dependent:
631 if (MsLangId::isTraditionalChinese(rOpt
.nDefaultLanguage_CJK
))
633 rOpt
.bIsDirectionToSimplified
= false;
637 rOpt
.bIsDirectionToSimplified
= true;
641 case UPH_IS_USE_CHARACTER_VARIANTS
:
642 { rOpt
.bROIsUseCharacterVariants
= pROStates
[i
]; rVal
>>= rOpt
.bIsUseCharacterVariants
; } break;
643 case UPH_IS_TRANSLATE_COMMON_TERMS
:
644 { rOpt
.bROIsTranslateCommonTerms
= pROStates
[i
]; rVal
>>= rOpt
.bIsTranslateCommonTerms
; } break;
645 case UPH_IS_REVERSE_MAPPING
:
646 { rOpt
.bROIsReverseMapping
= pROStates
[i
]; rVal
>>= rOpt
.bIsReverseMapping
; } break;
648 case UPH_DATA_FILES_CHANGED_CHECK_VALUE
:
649 { rOpt
.bRODataFilesChangedCheckValue
= pROStates
[i
]; rVal
>>= rOpt
.nDataFilesChangedCheckValue
; } break;
651 case UPH_IS_GRAMMAR_AUTO
:
652 { rOpt
.bROIsGrammarAuto
= pROStates
[i
]; rVal
>>= rOpt
.bIsGrammarAuto
; }
654 case UPH_IS_GRAMMAR_INTERACTIVE
:
655 { rOpt
.bROIsGrammarInteractive
= pROStates
[i
]; rVal
>>= rOpt
.bIsGrammarInteractive
; }
659 DBG_ASSERT( false, "unexpected case" );
665 DBG_ASSERT( bRes
, "LoadOptions failed" );
670 bool SvtLinguConfigItem::SaveOptions( const uno::Sequence
< OUString
> &rProperyNames
)
675 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
678 const uno::Type
&rBOOL
= ::getBooleanCppuType();
679 const uno::Type
&rINT16
= ::getCppuType( (sal_Int16
*) NULL
);
680 const uno::Type
&rINT32
= ::getCppuType( (sal_Int32
*) NULL
);
682 sal_Int32 nProps
= rProperyNames
.getLength();
683 uno::Sequence
< uno::Any
> aValues( nProps
);
684 uno::Any
*pValue
= aValues
.getArray();
686 if (nProps
&& aValues
.getLength() == nProps
)
688 const SvtLinguOptions
&rOpt
= aOpt
;
690 OUString
aTmp( lcl_LanguageToCfgLocaleStr( rOpt
.nDefaultLanguage
) );
691 *pValue
++ = uno::makeAny( aTmp
); // 0
692 *pValue
++ = uno::makeAny( rOpt
.aActiveDics
); // 1
693 pValue
++->setValue( &rOpt
.bIsUseDictionaryList
, rBOOL
); // 2
694 pValue
++->setValue( &rOpt
.bIsIgnoreControlCharacters
, rBOOL
); // 3
695 aTmp
= lcl_LanguageToCfgLocaleStr( rOpt
.nDefaultLanguage_CJK
);
696 *pValue
++ = uno::makeAny( aTmp
); // 5
697 aTmp
= lcl_LanguageToCfgLocaleStr( rOpt
.nDefaultLanguage_CTL
);
698 *pValue
++ = uno::makeAny( aTmp
); // 6
700 pValue
++->setValue( &rOpt
.bIsSpellUpperCase
, rBOOL
); // 7
701 pValue
++->setValue( &rOpt
.bIsSpellWithDigits
, rBOOL
); // 8
702 pValue
++->setValue( &rOpt
.bIsSpellCapitalization
, rBOOL
); // 9
703 pValue
++->setValue( &rOpt
.bIsSpellAuto
, rBOOL
); // 10
704 pValue
++->setValue( &rOpt
.bIsSpellSpecial
, rBOOL
); // 11
705 pValue
++->setValue( &rOpt
.bIsSpellReverse
, rBOOL
); // 14
707 pValue
++->setValue( &rOpt
.nHyphMinLeading
, rINT16
); // 15
708 pValue
++->setValue( &rOpt
.nHyphMinTrailing
, rINT16
); // 16
709 pValue
++->setValue( &rOpt
.nHyphMinWordLength
, rINT16
); // 17
710 pValue
++->setValue( &rOpt
.bIsHyphSpecial
, rBOOL
); // 18
711 pValue
++->setValue( &rOpt
.bIsHyphAuto
, rBOOL
); // 19
713 *pValue
++ = uno::makeAny( rOpt
.aActiveConvDics
); // 20
715 pValue
++->setValue( &rOpt
.bIsIgnorePostPositionalWord
, rBOOL
); // 21
716 pValue
++->setValue( &rOpt
.bIsAutoCloseDialog
, rBOOL
); // 22
717 pValue
++->setValue( &rOpt
.bIsShowEntriesRecentlyUsedFirst
, rBOOL
); // 23
718 pValue
++->setValue( &rOpt
.bIsAutoReplaceUniqueEntries
, rBOOL
); // 24
720 pValue
++->setValue( &rOpt
.bIsDirectionToSimplified
, rBOOL
); // 25
721 pValue
++->setValue( &rOpt
.bIsUseCharacterVariants
, rBOOL
); // 26
722 pValue
++->setValue( &rOpt
.bIsTranslateCommonTerms
, rBOOL
); // 27
723 pValue
++->setValue( &rOpt
.bIsReverseMapping
, rBOOL
); // 28
725 pValue
++->setValue( &rOpt
.nDataFilesChangedCheckValue
, rINT32
); // 29
726 pValue
++->setValue( &rOpt
.bIsGrammarAuto
, rBOOL
); // 30
727 pValue
++->setValue( &rOpt
.bIsGrammarInteractive
, rBOOL
); // 31
729 bRet
|= PutProperties( rProperyNames
, aValues
);
738 bool SvtLinguConfigItem::IsReadOnly( const OUString
&rPropertyName
) const
740 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
742 bool bReadOnly
= false;
744 if (GetHdlByName( nHdl
, rPropertyName
))
745 bReadOnly
= IsReadOnly( nHdl
);
749 bool SvtLinguConfigItem::IsReadOnly( sal_Int32 nPropertyHandle
) const
751 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
753 bool bReadOnly
= false;
755 const SvtLinguOptions
&rOpt
= const_cast< SvtLinguConfigItem
* >(this)->aOpt
;
756 switch(nPropertyHandle
)
758 case UPH_IS_USE_DICTIONARY_LIST
: bReadOnly
= rOpt
.bROIsUseDictionaryList
; break;
759 case UPH_IS_IGNORE_CONTROL_CHARACTERS
: bReadOnly
= rOpt
.bROIsIgnoreControlCharacters
; break;
760 case UPH_IS_HYPH_AUTO
: bReadOnly
= rOpt
.bROIsHyphAuto
; break;
761 case UPH_IS_HYPH_SPECIAL
: bReadOnly
= rOpt
.bROIsHyphSpecial
; break;
762 case UPH_IS_SPELL_AUTO
: bReadOnly
= rOpt
.bROIsSpellAuto
; break;
763 case UPH_IS_SPELL_SPECIAL
: bReadOnly
= rOpt
.bROIsSpellSpecial
; break;
764 case UPH_IS_WRAP_REVERSE
: bReadOnly
= rOpt
.bROIsSpellReverse
; break;
765 case UPH_DEFAULT_LANGUAGE
: bReadOnly
= rOpt
.bRODefaultLanguage
; break;
766 case UPH_IS_SPELL_CAPITALIZATION
: bReadOnly
= rOpt
.bROIsSpellCapitalization
; break;
767 case UPH_IS_SPELL_WITH_DIGITS
: bReadOnly
= rOpt
.bROIsSpellWithDigits
; break;
768 case UPH_IS_SPELL_UPPER_CASE
: bReadOnly
= rOpt
.bROIsSpellUpperCase
; break;
769 case UPH_HYPH_MIN_LEADING
: bReadOnly
= rOpt
.bROHyphMinLeading
; break;
770 case UPH_HYPH_MIN_TRAILING
: bReadOnly
= rOpt
.bROHyphMinTrailing
; break;
771 case UPH_HYPH_MIN_WORD_LENGTH
: bReadOnly
= rOpt
.bROHyphMinWordLength
; break;
772 case UPH_ACTIVE_DICTIONARIES
: bReadOnly
= rOpt
.bROActiveDics
; break;
773 case UPH_ACTIVE_CONVERSION_DICTIONARIES
: bReadOnly
= rOpt
.bROActiveConvDics
; break;
774 case UPH_DEFAULT_LOCALE
: bReadOnly
= rOpt
.bRODefaultLanguage
; break;
775 case UPH_DEFAULT_LOCALE_CJK
: bReadOnly
= rOpt
.bRODefaultLanguage_CJK
; break;
776 case UPH_DEFAULT_LOCALE_CTL
: bReadOnly
= rOpt
.bRODefaultLanguage_CTL
; break;
777 case UPH_IS_IGNORE_POST_POSITIONAL_WORD
: bReadOnly
= rOpt
.bROIsIgnorePostPositionalWord
; break;
778 case UPH_IS_AUTO_CLOSE_DIALOG
: bReadOnly
= rOpt
.bROIsAutoCloseDialog
; break;
779 case UPH_IS_SHOW_ENTRIES_RECENTLY_USED_FIRST
: bReadOnly
= rOpt
.bROIsShowEntriesRecentlyUsedFirst
; break;
780 case UPH_IS_AUTO_REPLACE_UNIQUE_ENTRIES
: bReadOnly
= rOpt
.bROIsAutoReplaceUniqueEntries
; break;
781 case UPH_IS_DIRECTION_TO_SIMPLIFIED
: bReadOnly
= rOpt
.bROIsDirectionToSimplified
; break;
782 case UPH_IS_USE_CHARACTER_VARIANTS
: bReadOnly
= rOpt
.bROIsUseCharacterVariants
; break;
783 case UPH_IS_TRANSLATE_COMMON_TERMS
: bReadOnly
= rOpt
.bROIsTranslateCommonTerms
; break;
784 case UPH_IS_REVERSE_MAPPING
: bReadOnly
= rOpt
.bROIsReverseMapping
; break;
785 case UPH_DATA_FILES_CHANGED_CHECK_VALUE
: bReadOnly
= rOpt
.bRODataFilesChangedCheckValue
; break;
786 case UPH_IS_GRAMMAR_AUTO
: bReadOnly
= rOpt
.bROIsGrammarAuto
; break;
787 case UPH_IS_GRAMMAR_INTERACTIVE
: bReadOnly
= rOpt
.bROIsGrammarInteractive
; break;
789 DBG_ASSERT( false, "unexpected property handle" );
794 static SvtLinguConfigItem
*pCfgItem
= 0;
795 static sal_Int32 nCfgItemRefCount
= 0;
797 static const char aG_SupportedDictionaryFormats
[] = "SupportedDictionaryFormats";
798 static const char aG_Dictionaries
[] = "Dictionaries";
799 static const char aG_Locations
[] = "Locations";
800 static const char aG_Format
[] = "Format";
801 static const char aG_Locales
[] = "Locales";
802 static const char aG_DisabledDictionaries
[] = "DisabledDictionaries";
804 SvtLinguConfig::SvtLinguConfig()
806 // Global access, must be guarded (multithreading)
807 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
811 SvtLinguConfig::~SvtLinguConfig()
813 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
815 if (pCfgItem
&& pCfgItem
->IsModified())
818 if (--nCfgItemRefCount
<= 0)
826 SvtLinguConfigItem
& SvtLinguConfig::GetConfigItem()
828 // Global access, must be guarded (multithreading)
829 osl::MutexGuard
aGuard(theSvtLinguConfigItemMutex::get());
832 pCfgItem
= new SvtLinguConfigItem
;
833 ItemHolder1::holdConfigItem(E_LINGUCFG
);
838 uno::Sequence
< OUString
> SvtLinguConfig::GetNodeNames( const OUString
&rNode
)
840 return GetConfigItem().GetNodeNames( rNode
);
843 uno::Sequence
< uno::Any
> SvtLinguConfig::GetProperties( const uno::Sequence
< OUString
> &rNames
)
845 return GetConfigItem().GetProperties(rNames
);
848 bool SvtLinguConfig::ReplaceSetProperties(
849 const OUString
&rNode
, const uno::Sequence
< beans::PropertyValue
>& rValues
)
851 return GetConfigItem().ReplaceSetProperties( rNode
, rValues
);
854 uno::Any
SvtLinguConfig::GetProperty( const OUString
&rPropertyName
) const
856 return GetConfigItem().GetProperty( rPropertyName
);
859 uno::Any
SvtLinguConfig::GetProperty( sal_Int32 nPropertyHandle
) const
861 return GetConfigItem().GetProperty( nPropertyHandle
);
864 bool SvtLinguConfig::SetProperty( const OUString
&rPropertyName
, const uno::Any
&rValue
)
866 return GetConfigItem().SetProperty( rPropertyName
, rValue
);
869 bool SvtLinguConfig::SetProperty( sal_Int32 nPropertyHandle
, const uno::Any
&rValue
)
871 return GetConfigItem().SetProperty( nPropertyHandle
, rValue
);
874 bool SvtLinguConfig::GetOptions( SvtLinguOptions
&rOptions
) const
876 rOptions
= GetConfigItem().GetOptions();
880 bool SvtLinguConfig::IsReadOnly( const OUString
&rPropertyName
) const
882 return GetConfigItem().IsReadOnly( rPropertyName
);
885 bool SvtLinguConfig::GetElementNamesFor(
886 const OUString
&rNodeName
,
887 uno::Sequence
< OUString
> &rElementNames
) const
889 bool bSuccess
= false;
892 uno::Reference
< container::XNameAccess
> xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW
);
893 xNA
.set( xNA
->getByName("ServiceManager"), uno::UNO_QUERY_THROW
);
894 xNA
.set( xNA
->getByName( rNodeName
), uno::UNO_QUERY_THROW
);
895 rElementNames
= xNA
->getElementNames();
898 catch (uno::Exception
&)
904 bool SvtLinguConfig::GetSupportedDictionaryFormatsFor(
905 const OUString
&rSetName
,
906 const OUString
&rSetEntry
,
907 uno::Sequence
< OUString
> &rFormatList
) const
909 if (rSetName
.isEmpty() || rSetEntry
.isEmpty())
911 bool bSuccess
= false;
914 uno::Reference
< container::XNameAccess
> xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW
);
915 xNA
.set( xNA
->getByName("ServiceManager"), uno::UNO_QUERY_THROW
);
916 xNA
.set( xNA
->getByName( rSetName
), uno::UNO_QUERY_THROW
);
917 xNA
.set( xNA
->getByName( rSetEntry
), uno::UNO_QUERY_THROW
);
918 if (xNA
->getByName( OUString(aG_SupportedDictionaryFormats
) ) >>= rFormatList
)
920 DBG_ASSERT( rFormatList
.getLength(), "supported dictionary format list is empty" );
922 catch (uno::Exception
&)
928 static bool lcl_GetFileUrlFromOrigin(
929 OUString
/*out*/ &rFileUrl
,
930 const OUString
&rOrigin
)
932 bool bSuccess
= false;
933 if (!rOrigin
.isEmpty())
935 OUString
aURL( rOrigin
);
936 if ( aURL
.startsWith( EXPAND_PROTOCOL
) )
939 OUString
aMacro( aURL
.copy( sizeof ( EXPAND_PROTOCOL
) -1 ) );
940 // decode uric class chars
941 aMacro
= Uri::decode( aMacro
, rtl_UriDecodeWithCharset
, RTL_TEXTENCODING_UTF8
);
942 // expand macro string
943 aURL
= util::theMacroExpander::get(
944 comphelper::getProcessComponentContext() )->expandMacros(
947 bool bIsFileUrl
= aURL
.startsWith( FILE_PROTOCOL
);
956 "unotools.config", "not a file URL, <" << aURL
<< ">" );
962 "unotools.config", "failed to get file URL, <" << aURL
<< ">" );
968 bool SvtLinguConfig::GetDictionaryEntry(
969 const OUString
&rNodeName
,
970 SvtLinguConfigDictionaryEntry
&rDicEntry
) const
972 if (rNodeName
.isEmpty())
974 bool bSuccess
= false;
977 uno::Reference
< container::XNameAccess
> xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW
);
978 xNA
.set( xNA
->getByName("ServiceManager"), uno::UNO_QUERY_THROW
);
979 xNA
.set( xNA
->getByName(OUString(aG_Dictionaries
)), uno::UNO_QUERY_THROW
);
980 xNA
.set( xNA
->getByName( rNodeName
), uno::UNO_QUERY_THROW
);
982 // read group data...
983 uno::Sequence
< OUString
> aLocations
;
984 OUString aFormatName
;
985 uno::Sequence
< OUString
> aLocaleNames
;
986 bSuccess
= (xNA
->getByName( OUString(aG_Locations
) ) >>= aLocations
) &&
987 (xNA
->getByName( OUString(aG_Format
) ) >>= aFormatName
) &&
988 (xNA
->getByName( OUString(aG_Locales
) ) >>= aLocaleNames
);
989 DBG_ASSERT( aLocations
.getLength(), "Dictionary locations not set" );
990 DBG_ASSERT( !aFormatName
.isEmpty(), "Dictionary format name not set" );
991 DBG_ASSERT( aLocaleNames
.getLength(), "No locales set for the dictionary" );
993 // if successful continue
996 // get file URL's for the locations
997 for (sal_Int32 i
= 0; i
< aLocations
.getLength(); ++i
)
999 OUString
&rLocation
= aLocations
[i
];
1000 if (!lcl_GetFileUrlFromOrigin( rLocation
, rLocation
))
1004 // if everything was fine return the result
1007 rDicEntry
.aLocations
= aLocations
;
1008 rDicEntry
.aFormatName
= aFormatName
;
1009 rDicEntry
.aLocaleNames
= aLocaleNames
;
1013 catch (uno::Exception
&)
1019 uno::Sequence
< OUString
> SvtLinguConfig::GetDisabledDictionaries() const
1021 uno::Sequence
< OUString
> aResult
;
1024 uno::Reference
< container::XNameAccess
> xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW
);
1025 xNA
.set( xNA
->getByName("ServiceManager"), uno::UNO_QUERY_THROW
);
1026 xNA
->getByName( OUString(aG_DisabledDictionaries
) ) >>= aResult
;
1028 catch (uno::Exception
&)
1034 std::vector
< SvtLinguConfigDictionaryEntry
> SvtLinguConfig::GetActiveDictionariesByFormat(
1035 const OUString
&rFormatName
)
1037 std::vector
< SvtLinguConfigDictionaryEntry
> aRes
;
1038 if (rFormatName
.isEmpty())
1043 uno::Sequence
< OUString
> aElementNames
;
1044 GetElementNamesFor( OUString(aG_Dictionaries
), aElementNames
);
1045 sal_Int32 nLen
= aElementNames
.getLength();
1046 const OUString
*pElementNames
= aElementNames
.getConstArray();
1048 const uno::Sequence
< OUString
> aDisabledDics( GetDisabledDictionaries() );
1050 SvtLinguConfigDictionaryEntry aDicEntry
;
1051 for (sal_Int32 i
= 0; i
< nLen
; ++i
)
1053 // does dictionary match the format we are looking for?
1054 if (GetDictionaryEntry( pElementNames
[i
], aDicEntry
) &&
1055 aDicEntry
.aFormatName
== rFormatName
)
1057 // check if it is active or not
1058 bool bDicIsActive
= true;
1059 for (sal_Int32 k
= 0; bDicIsActive
&& k
< aDisabledDics
.getLength(); ++k
)
1061 if (aDisabledDics
[k
] == pElementNames
[i
])
1062 bDicIsActive
= false;
1067 DBG_ASSERT( !aDicEntry
.aFormatName
.isEmpty(),
1068 "FormatName not set" );
1069 DBG_ASSERT( aDicEntry
.aLocations
.getLength(),
1070 "Locations not set" );
1071 DBG_ASSERT( aDicEntry
.aLocaleNames
.getLength(),
1072 "Locales not set" );
1073 aRes
.push_back( aDicEntry
);
1078 catch (uno::Exception
&)
1085 uno::Reference
< util::XChangesBatch
> SvtLinguConfig::GetMainUpdateAccess() const
1087 if (!m_xMainUpdateAccess
.is())
1091 // get configuration provider
1092 uno::Reference
< uno::XComponentContext
> xContext
= comphelper::getProcessComponentContext();
1093 uno::Reference
< lang::XMultiServiceFactory
> xConfigurationProvider
=
1094 configuration::theDefaultProvider::get( xContext
);
1096 // get configuration update access
1097 beans::PropertyValue aValue
;
1098 aValue
.Name
= "nodepath";
1099 aValue
.Value
= uno::makeAny(OUString("org.openoffice.Office.Linguistic"));
1100 uno::Sequence
< uno::Any
> aProps(1);
1101 aProps
[0] <<= aValue
;
1102 m_xMainUpdateAccess
= uno::Reference
< util::XChangesBatch
>(
1103 xConfigurationProvider
->createInstanceWithArguments(
1104 OUString("com.sun.star.configuration.ConfigurationUpdateAccess"), aProps
),
1105 uno::UNO_QUERY_THROW
);
1107 catch (uno::Exception
&)
1112 return m_xMainUpdateAccess
;
1115 OUString
SvtLinguConfig::GetVendorImageUrl_Impl(
1116 const OUString
&rServiceImplName
,
1117 const OUString
&rImageName
) const
1122 uno::Reference
< container::XNameAccess
> xImagesNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW
);
1123 xImagesNA
.set( xImagesNA
->getByName("Images"), uno::UNO_QUERY_THROW
);
1125 uno::Reference
< container::XNameAccess
> xNA( xImagesNA
->getByName("ServiceNameEntries"), uno::UNO_QUERY_THROW
);
1126 xNA
.set( xNA
->getByName( rServiceImplName
), uno::UNO_QUERY_THROW
);
1127 uno::Any
aAny(xNA
->getByName("VendorImagesNode"));
1128 OUString aVendorImagesNode
;
1129 if (aAny
>>= aVendorImagesNode
)
1132 xNA
.set( xNA
->getByName("VendorImages"), uno::UNO_QUERY_THROW
);
1133 xNA
.set( xNA
->getByName( aVendorImagesNode
), uno::UNO_QUERY_THROW
);
1134 aAny
= xNA
->getByName( rImageName
);
1138 if (lcl_GetFileUrlFromOrigin( aTmp
, aTmp
))
1143 catch (uno::Exception
&)
1145 DBG_ASSERT( false, "exception caught. GetVendorImageUrl_Impl failed" );
1150 OUString
SvtLinguConfig::GetSpellAndGrammarContextSuggestionImage(
1151 const OUString
&rServiceImplName
1155 if (!rServiceImplName
.isEmpty())
1157 OUString
aImageName( "SpellAndGrammarContextMenuSuggestionImage" );
1158 OUString
aPath( GetVendorImageUrl_Impl( rServiceImplName
, aImageName
) );
1164 OUString
SvtLinguConfig::GetSpellAndGrammarContextDictionaryImage(
1165 const OUString
&rServiceImplName
1169 if (!rServiceImplName
.isEmpty())
1171 OUString
aImageName( "SpellAndGrammarContextMenuDictionaryImage" );
1172 OUString
aPath( GetVendorImageUrl_Impl( rServiceImplName
, aImageName
) );
1178 OUString
SvtLinguConfig::GetSynonymsContextImage(
1179 const OUString
&rServiceImplName
1183 if (!rServiceImplName
.isEmpty())
1185 OUString
aImageName( "SynonymsContextMenuImage" );
1186 OUString
aPath( GetVendorImageUrl_Impl( rServiceImplName
, aImageName
) );
1192 bool SvtLinguConfig::HasGrammarChecker() const
1198 uno::Reference
< container::XNameAccess
> xNA( GetMainUpdateAccess(), uno::UNO_QUERY_THROW
);
1199 xNA
.set( xNA
->getByName("ServiceManager"), uno::UNO_QUERY_THROW
);
1200 xNA
.set( xNA
->getByName("GrammarCheckerList"), uno::UNO_QUERY_THROW
);
1202 uno::Sequence
< OUString
> aElementNames( xNA
->getElementNames() );
1203 bRes
= aElementNames
.getLength() > 0;
1205 catch (const uno::Exception
&)
1212 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */