update credits
[LibreOffice.git] / unotools / source / config / lingucfg.cxx
blob484869e7de36ec1110a8a0d49878214527fd6ba9
1 /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 /*
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;
45 using ::rtl::Uri;
47 #define EXPAND_PROTOCOL "vnd.sun.star.expand:"
48 #define FILE_PROTOCOL "file:///"
50 namespace
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;
60 lang::Locale aNew;
61 if (rVal >>= aNew) // conversion successful?
63 sal_Int16 nNew = LanguageTag( aNew ).getLanguageType( false);
64 if (nNew != rLanguage)
66 rLanguage = nNew;
67 bSucc = sal_True;
70 return bSucc;
73 static inline const OUString lcl_LanguageToCfgLocaleStr( sal_Int16 nLanguage )
75 OUString aRes;
76 if (LANGUAGE_SYSTEM != nLanguage)
77 aRes = LanguageTag( nLanguage ).getBcp47();
78 return aRes;
81 static sal_Int16 lcl_CfgAnyToLanguage( const uno::Any &rVal )
83 OUString aTmp;
84 rVal >>= aTmp;
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;
94 // general options
95 bIsUseDictionaryList =
96 bIsIgnoreControlCharacters = sal_True;
98 // spelling options
99 bIsSpellCapitalization =
100 bIsSpellSpecial = sal_True;
101 bIsSpellAuto =
102 bIsSpellReverse =
103 bIsSpellWithDigits =
104 bIsSpellUpperCase = sal_False;
106 // text conversion options
107 bIsIgnorePostPositionalWord = sal_True;
108 bIsAutoCloseDialog =
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;
124 nHyphMinLeading =
125 nHyphMinTrailing = 2;
126 nHyphMinWordLength = 0;
128 nDataFilesChangedCheckValue = 0;
130 //grammar options
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 );
149 public:
150 SvtLinguConfigItem();
151 virtual ~SvtLinguConfigItem();
153 // utl::ConfigItem
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 );
188 ClearModified();
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 );
204 NotifyListeners(0);
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
219 }aNamesToHdl[] =
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},
259 { NULL, NULL, -1}
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();
271 sal_Int32 nIdx = 0;
272 for (sal_Int32 i = 0; i < nMax; ++i)
274 const sal_Char *pFullPropName = aNamesToHdl[i].pFullPropName;
275 if (pFullPropName)
276 pNames[ nIdx++ ] = OUString::createFromAscii( pFullPropName );
278 aNames.realloc( nIdx );
280 return aNames;
283 sal_Bool SvtLinguConfigItem::GetHdlByName(
284 sal_Int32 &rnHdl,
285 const OUString &rPropertyName,
286 sal_Bool bFullPropName )
288 NamesToHdl *pEntry = &aNamesToHdl[0];
290 if (bFullPropName)
292 while (pEntry && pEntry->pFullPropName != NULL)
294 if (0 == rPropertyName.compareToAscii( pEntry->pFullPropName ))
296 rnHdl = pEntry->nHdl;
297 break;
299 ++pEntry;
301 return pEntry && pEntry->pFullPropName != NULL;
303 else
305 while (pEntry && pEntry->pPropName != NULL)
307 if (0 == rPropertyName.compareToAscii( pEntry->pPropName ))
309 rnHdl = pEntry->nHdl;
310 break;
312 ++pEntry;
314 return pEntry && pEntry->pPropName != NULL;
319 uno::Any SvtLinguConfigItem::GetProperty( const OUString &rPropertyName ) const
321 osl::MutexGuard aGuard(theSvtLinguConfigItemMutex::get());
323 sal_Int32 nHdl;
324 return GetHdlByName( nHdl, rPropertyName ) ? GetProperty( nHdl ) : uno::Any();
328 uno::Any SvtLinguConfigItem::GetProperty( sal_Int32 nPropertyHandle ) const
330 osl::MutexGuard aGuard(theSvtLinguConfigItemMutex::get());
332 uno::Any aRes;
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;
358 break;
360 case UPH_ACTIVE_CONVERSION_DICTIONARIES :
362 aRes <<= rOpt.aActiveConvDics;
363 break;
365 case UPH_DEFAULT_LOCALE :
367 lang::Locale aLocale( LanguageTag( rOpt.nDefaultLanguage ).getLocale( false ) );
368 aRes.setValue( &aLocale, ::getCppuType((lang::Locale*)0 ));
369 break;
371 case UPH_DEFAULT_LOCALE_CJK :
373 lang::Locale aLocale( LanguageTag( rOpt.nDefaultLanguage_CJK ).getLocale( false ) );
374 aRes.setValue( &aLocale, ::getCppuType((lang::Locale*)0 ));
375 break;
377 case UPH_DEFAULT_LOCALE_CTL :
379 lang::Locale aLocale( LanguageTag( rOpt.nDefaultLanguage_CTL ).getLocale( false ) );
380 aRes.setValue( &aLocale, ::getCppuType((lang::Locale*)0 ));
381 break;
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;
396 default :
397 DBG_ASSERT( 0, "unexpected property handle" );
400 if (pbVal)
401 aRes <<= *pbVal;
402 else if (pnVal)
403 aRes <<= *pnVal;
404 else if (pnInt32Val)
405 aRes <<= *pnInt32Val;
407 return aRes;
411 sal_Bool SvtLinguConfigItem::SetProperty( const OUString &rPropertyName, const uno::Any &rValue )
413 osl::MutexGuard aGuard(theSvtLinguConfigItemMutex::get());
415 sal_Bool bSucc = sal_False;
416 sal_Int32 nHdl;
417 if (GetHdlByName( nHdl, rPropertyName ))
418 bSucc = SetProperty( nHdl, rValue );
419 return bSucc;
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())
429 return bSucc;
431 sal_Bool bMod = sal_False;
433 sal_Int16 *pnVal = 0;
434 sal_Bool *pbVal = 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;
457 bMod = sal_True;
458 break;
460 case UPH_ACTIVE_CONVERSION_DICTIONARIES :
462 rValue >>= rOpt.aActiveConvDics;
463 bMod = sal_True;
464 break;
466 case UPH_DEFAULT_LOCALE :
468 bSucc = lcl_SetLocale( rOpt.nDefaultLanguage, rValue );
469 bMod = bSucc;
470 break;
472 case UPH_DEFAULT_LOCALE_CJK :
474 bSucc = lcl_SetLocale( rOpt.nDefaultLanguage_CJK, rValue );
475 bMod = bSucc;
476 break;
478 case UPH_DEFAULT_LOCALE_CTL :
480 bSucc = lcl_SetLocale( rOpt.nDefaultLanguage_CTL, rValue );
481 bMod = bSucc;
482 break;
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;
497 default :
498 DBG_ASSERT( 0, "unexpected property handle" );
501 if (pbVal)
503 sal_Bool bNew = sal_Bool();
504 if (rValue >>= bNew)
506 if (bNew != *pbVal)
508 *pbVal = bNew;
509 bMod = sal_True;
511 bSucc = sal_True;
514 else if (pnVal)
516 sal_Int16 nNew = sal_Int16();
517 if (rValue >>= nNew)
519 if (nNew != *pnVal)
521 *pnVal = nNew;
522 bMod = sal_True;
524 bSucc = sal_True;
527 else if (pnInt32Val)
529 sal_Int32 nNew = sal_Int32();
530 if (rValue >>= nNew)
532 if (nNew != *pnInt32Val)
534 *pnInt32Val = nNew;
535 bMod = sal_True;
537 bSucc = sal_True;
541 if (bMod)
542 SetModified();
544 NotifyListeners(0);
545 return bSucc;
548 const SvtLinguOptions& SvtLinguConfigItem::GetOptions() const
550 osl::MutexGuard aGuard(theSvtLinguConfigItemMutex::get());
551 return aOpt;
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;
636 else
638 rOpt.bIsDirectionToSimplified = sal_True;
641 } break;
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; }
654 break;
655 case UPH_IS_GRAMMAR_INTERACTIVE:
656 { rOpt.bROIsGrammarInteractive = pROStates[i]; rVal >>= rOpt.bIsGrammarInteractive; }
657 break;
659 default:
660 DBG_ASSERT( 0, "unexpected case" );
664 bRes = sal_True;
666 DBG_ASSERT( bRes, "LoadOptions failed" );
668 return bRes;
672 sal_Bool SvtLinguConfigItem::SaveOptions( const uno::Sequence< OUString > &rProperyNames )
674 if (!IsModified())
675 return sal_True;
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 );
734 if (bRet)
735 ClearModified();
737 return bRet;
740 sal_Bool SvtLinguConfigItem::IsReadOnly( const OUString &rPropertyName ) const
742 osl::MutexGuard aGuard(theSvtLinguConfigItemMutex::get());
744 sal_Bool bReadOnly = sal_False;
745 sal_Int32 nHdl;
746 if (GetHdlByName( nHdl, rPropertyName ))
747 bReadOnly = IsReadOnly( nHdl );
748 return bReadOnly;
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;
790 default :
791 DBG_ASSERT( 0, "unexpected property handle" );
793 return bReadOnly;
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());
812 ++nCfgItemRefCount;
815 SvtLinguConfig::~SvtLinguConfig()
817 osl::MutexGuard aGuard(theSvtLinguConfigItemMutex::get());
819 if (pCfgItem && pCfgItem->IsModified())
820 pCfgItem->Commit();
822 if (--nCfgItemRefCount <= 0)
824 if (pCfgItem)
825 delete pCfgItem;
826 pCfgItem = 0;
830 SvtLinguConfigItem & SvtLinguConfig::GetConfigItem()
832 // Global access, must be guarded (multithreading)
833 osl::MutexGuard aGuard(theSvtLinguConfigItemMutex::get());
834 if (!pCfgItem)
836 pCfgItem = new SvtLinguConfigItem;
837 ItemHolder1::holdConfigItem(E_LINGUCFG);
839 return *pCfgItem;
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();
881 return sal_True;
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();
900 bSuccess = true;
902 catch (uno::Exception &)
905 return bSuccess;
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())
914 return sal_False;
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)
923 bSuccess = true;
924 DBG_ASSERT( rFormatList.getLength(), "supported dictionary format list is empty" );
926 catch (uno::Exception &)
929 return bSuccess;
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 ) )
942 // cut 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(
949 aMacro );
951 bool bIsFileUrl = aURL.startsWith( FILE_PROTOCOL );
952 if (bIsFileUrl)
954 rFileUrl = aURL;
955 bSuccess = true;
957 else
959 SAL_WARN(
960 "unotools.config", "not a file URL, <" << aURL << ">" );
963 else
965 SAL_WARN(
966 "unotools.config", "failed to get file URL, <" << aURL << ">" );
969 return bSuccess;
973 sal_Bool SvtLinguConfig::GetDictionaryEntry(
974 const OUString &rNodeName,
975 SvtLinguConfigDictionaryEntry &rDicEntry ) const
977 if (rNodeName.isEmpty())
978 return sal_False;
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
999 if (bSuccess)
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 ))
1006 bSuccess = false;
1009 // if everything was fine return the result
1010 if (bSuccess)
1012 rDicEntry.aLocations = aLocations;
1013 rDicEntry.aFormatName = aFormatName;
1014 rDicEntry.aLocaleNames = aLocaleNames;
1018 catch (uno::Exception &)
1021 return bSuccess;
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 &)
1036 return aResult;
1039 std::vector< SvtLinguConfigDictionaryEntry > SvtLinguConfig::GetActiveDictionariesByFormat(
1040 const OUString &rFormatName )
1042 std::vector< SvtLinguConfigDictionaryEntry > aRes;
1043 if (rFormatName.isEmpty())
1044 return aRes;
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;
1069 if (bDicIsActive)
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 &)
1086 return aRes;
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
1125 OUString aRes;
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)
1137 xNA = xImagesNA;
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 );
1141 OUString aTmp;
1142 if (aAny >>= aTmp)
1144 if (lcl_GetFileUrlFromOrigin( aTmp, aTmp ))
1145 aRes = aTmp;
1149 catch (uno::Exception &)
1151 DBG_ASSERT( 0, "exception caught. GetVendorImageUrl_Impl failed" );
1153 return aRes;
1157 OUString SvtLinguConfig::GetSpellAndGrammarContextSuggestionImage(
1158 const OUString &rServiceImplName
1159 ) const
1161 OUString aRes;
1162 if (!rServiceImplName.isEmpty())
1164 OUString aImageName( "SpellAndGrammarContextMenuSuggestionImage" );
1165 OUString aPath( GetVendorImageUrl_Impl( rServiceImplName, aImageName ) );
1166 aRes = aPath;
1168 return aRes;
1172 OUString SvtLinguConfig::GetSpellAndGrammarContextDictionaryImage(
1173 const OUString &rServiceImplName
1174 ) const
1176 OUString aRes;
1177 if (!rServiceImplName.isEmpty())
1179 OUString aImageName( "SpellAndGrammarContextMenuDictionaryImage" );
1180 OUString aPath( GetVendorImageUrl_Impl( rServiceImplName, aImageName ) );
1181 aRes = aPath;
1183 return aRes;
1186 OUString SvtLinguConfig::GetSynonymsContextImage(
1187 const OUString &rServiceImplName
1188 ) const
1190 OUString aRes;
1191 if (!rServiceImplName.isEmpty())
1193 OUString aImageName( "SynonymsContextMenuImage" );
1194 OUString aPath( GetVendorImageUrl_Impl( rServiceImplName, aImageName ) );
1195 aRes = aPath;
1197 return aRes;
1200 bool SvtLinguConfig::HasGrammarChecker() const
1202 bool bRes = false;
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&)
1217 return bRes;
1220 //////////////////////////////////////////////////////////////////////
1222 /* vim:set shiftwidth=4 softtabstop=4 expandtab: */