Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*
3 : : * This file is part of the LibreOffice project.
4 : : *
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/.
8 : : *
9 : : * This file incorporates work covered by the following license notice:
10 : : *
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 .
18 : : */
19 : :
20 : : #include <com/sun/star/uno/Sequence.hxx>
21 : : #include <rtl/ustrbuf.hxx>
22 : : #include <rtl/instance.hxx>
23 : : #include <rtl/logfile.hxx>
24 : : #include <i18npool/mslangid.hxx>
25 : : #include <tools/string.hxx>
26 : : #include <tools/debug.hxx>
27 : : #include <unotools/syslocaleoptions.hxx>
28 : : #include <unotools/configmgr.hxx>
29 : : #include <unotools/configitem.hxx>
30 : : #include <com/sun/star/uno/Any.hxx>
31 : :
32 : : #include "itemholder1.hxx"
33 : :
34 : : #define CFG_READONLY_DEFAULT sal_False
35 : :
36 : : using namespace osl;
37 : : using namespace utl;
38 : : using namespace com::sun::star::uno;
39 : : using namespace com::sun::star::lang;
40 : :
41 : : using ::rtl::OUString;
42 : :
43 : : SvtSysLocaleOptions_Impl* SvtSysLocaleOptions::pOptions = NULL;
44 : : sal_Int32 SvtSysLocaleOptions::nRefCount = 0;
45 : : namespace
46 : : {
47 : : struct CurrencyChangeLink
48 : : : public rtl::Static<Link, CurrencyChangeLink> {};
49 : : }
50 : :
51 : 742 : com::sun::star::lang::Locale lcl_str_to_locale( const ::rtl::OUString rStr )
52 : : {
53 : 742 : com::sun::star::lang::Locale aRet;
54 [ + + ]: 742 : if ( !rStr.isEmpty() )
55 : : {
56 : 368 : aRet = com::sun::star::lang::Locale();
57 : 368 : sal_Int32 nSep = rStr.indexOf('-');
58 [ - + ]: 368 : if (nSep < 0)
59 : 0 : aRet.Language = rStr;
60 : : else
61 : : {
62 : 368 : aRet.Language = rStr.copy(0, nSep);
63 [ + - ]: 368 : if (nSep < rStr.getLength())
64 : 368 : aRet.Country = rStr.copy(nSep+1, rStr.getLength() - (nSep+1));
65 : : }
66 : : }
67 : :
68 : 742 : return aRet;
69 : : }
70 : :
71 : : class SvtSysLocaleOptions_Impl : public utl::ConfigItem
72 : : {
73 : : Locale m_aRealLocale;
74 : : Locale m_aRealUILocale;
75 : : LanguageType m_eRealLanguage;
76 : : LanguageType m_eRealUILanguage;
77 : : OUString m_aLocaleString; // en-US or de-DE or empty for SYSTEM
78 : : OUString m_aUILocaleString; // en-US or de-DE or empty for SYSTEM
79 : : OUString m_aCurrencyString; // USD-en-US or EUR-de-DE
80 : : sal_Bool m_bDecimalSeparator; //use decimal separator same as locale
81 : :
82 : : sal_Bool m_bROLocale;
83 : : sal_Bool m_bROUILocale;
84 : : sal_Bool m_bROCurrency;
85 : : sal_Bool m_bRODecimalSeparator;
86 : :
87 : : static const Sequence< /* const */ OUString > GetPropertyNames();
88 : : void MakeRealLocale();
89 : : void MakeRealUILocale();
90 : :
91 : : public:
92 : : SvtSysLocaleOptions_Impl();
93 : : virtual ~SvtSysLocaleOptions_Impl();
94 : :
95 : : virtual void Notify( const com::sun::star::uno::Sequence< rtl::OUString >& aPropertyNames );
96 : : virtual void Commit();
97 : :
98 : 73 : const OUString& GetLocaleString() const
99 : 73 : { return m_aLocaleString; }
100 : : void SetLocaleString( const OUString& rStr );
101 : :
102 : : const OUString& GetUILocaleString() const
103 : : { return m_aUILocaleString; }
104 : : void SetUILocaleString( const OUString& rStr );
105 : :
106 : 36 : const OUString& GetCurrencyString() const
107 : 36 : { return m_aCurrencyString; }
108 : : void SetCurrencyString( const OUString& rStr );
109 : :
110 : 251 : sal_Bool IsDecimalSeparatorAsLocale() const { return m_bDecimalSeparator;}
111 : : void SetDecimalSeparatorAsLocale( sal_Bool bSet);
112 : :
113 : : sal_Bool IsReadOnly( SvtSysLocaleOptions::EOption eOption ) const;
114 : 482 : const Locale& GetRealLocale() { return m_aRealLocale; }
115 : 1006 : const Locale& GetRealUILocale() { return m_aRealUILocale; }
116 : 1906510 : LanguageType GetRealLanguage() { return m_eRealLanguage; }
117 : 602661 : LanguageType GetRealUILanguage() { return m_eRealUILanguage; }
118 : : };
119 : :
120 : :
121 : : #define ROOTNODE_SYSLOCALE OUString(RTL_CONSTASCII_USTRINGPARAM("Setup/L10N"))
122 : :
123 : : #define PROPERTYNAME_LOCALE OUString(RTL_CONSTASCII_USTRINGPARAM("ooSetupSystemLocale"))
124 : : #define PROPERTYNAME_UILOCALE OUString(RTL_CONSTASCII_USTRINGPARAM("ooLocale"))
125 : : #define PROPERTYNAME_CURRENCY OUString(RTL_CONSTASCII_USTRINGPARAM("ooSetupCurrency"))
126 : : #define PROPERTYNAME_DECIMALSEPARATOR OUString(RTL_CONSTASCII_USTRINGPARAM("DecimalSeparatorAsLocale"))
127 : :
128 : : #define PROPERTYHANDLE_LOCALE 0
129 : : #define PROPERTYHANDLE_UILOCALE 1
130 : : #define PROPERTYHANDLE_CURRENCY 2
131 : : #define PROPERTYHANDLE_DECIMALSEPARATOR 3
132 : :
133 : : #define PROPERTYCOUNT 4
134 : :
135 : 281 : const Sequence< OUString > SvtSysLocaleOptions_Impl::GetPropertyNames()
136 : : {
137 : : const OUString pProperties[] =
138 : : {
139 : : PROPERTYNAME_LOCALE,
140 : : PROPERTYNAME_UILOCALE,
141 : : PROPERTYNAME_CURRENCY,
142 : : PROPERTYNAME_DECIMALSEPARATOR
143 [ + - ][ + - ]: 1405 : };
[ + - ][ + - ]
[ # # # # ]
144 [ + - ]: 281 : const Sequence< OUString > seqPropertyNames( pProperties, PROPERTYCOUNT );
145 [ + + ][ # # ]: 1405 : return seqPropertyNames;
146 : : }
147 : :
148 : : // -----------------------------------------------------------------------
149 : :
150 : 266 : SvtSysLocaleOptions_Impl::SvtSysLocaleOptions_Impl()
151 : : : ConfigItem( ROOTNODE_SYSLOCALE )
152 : : , m_bDecimalSeparator( sal_True )
153 : : , m_bROLocale(CFG_READONLY_DEFAULT)
154 : : , m_bROUILocale(CFG_READONLY_DEFAULT)
155 : : , m_bROCurrency(CFG_READONLY_DEFAULT)
156 [ + - ]: 266 : , m_bRODecimalSeparator(sal_False)
157 : :
158 : : {
159 [ + - ][ + - ]: 266 : if ( IsValidConfigMgr() )
160 : : {
161 [ + - ]: 266 : const Sequence< OUString > aNames = GetPropertyNames();
162 [ + - ]: 266 : Sequence< Any > aValues = GetProperties( aNames );
163 [ + - ]: 266 : Sequence< sal_Bool > aROStates = GetReadOnlyStates( aNames );
164 : 266 : const Any* pValues = aValues.getConstArray();
165 : 266 : const sal_Bool* pROStates = aROStates.getConstArray();
166 : : DBG_ASSERT( aValues.getLength() == aNames.getLength(), "GetProperties failed" );
167 : : DBG_ASSERT( aROStates.getLength() == aNames.getLength(), "GetReadOnlyStates failed" );
168 [ + - ][ + - ]: 266 : if ( aValues.getLength() == aNames.getLength() && aROStates.getLength() == aNames.getLength() )
[ + - ]
169 : : {
170 [ + + ]: 1330 : for ( sal_Int32 nProp = 0; nProp < aNames.getLength(); nProp++ )
171 : : {
172 [ + - ]: 1064 : if ( pValues[nProp].hasValue() )
173 : : {
174 [ + + + + : 1064 : switch ( nProp )
- ]
175 : : {
176 : : case PROPERTYHANDLE_LOCALE :
177 : : {
178 : 266 : OUString aStr;
179 [ + - ]: 266 : if ( pValues[nProp] >>= aStr )
180 : 266 : m_aLocaleString = aStr;
181 : : else
182 : : {
183 : : SAL_WARN( "unotools.config", "Wrong property type!" );
184 : : }
185 : 266 : m_bROLocale = pROStates[nProp];
186 : : }
187 : 266 : break;
188 : : case PROPERTYHANDLE_UILOCALE :
189 : : {
190 : 266 : OUString aStr;
191 [ + - ]: 266 : if ( pValues[nProp] >>= aStr )
192 : 266 : m_aUILocaleString = aStr;
193 : : else
194 : : {
195 : : SAL_WARN( "unotools.config", "Wrong property type!" );
196 : : }
197 : 266 : m_bROUILocale = pROStates[nProp];
198 : : }
199 : 266 : break;
200 : : case PROPERTYHANDLE_CURRENCY :
201 : : {
202 : 266 : OUString aStr;
203 [ + - ]: 266 : if ( pValues[nProp] >>= aStr )
204 : 266 : m_aCurrencyString = aStr;
205 : : else
206 : : {
207 : : SAL_WARN( "unotools.config", "Wrong property type!" );
208 : : }
209 : 266 : m_bROCurrency = pROStates[nProp];
210 : : }
211 : 266 : break;
212 : : case PROPERTYHANDLE_DECIMALSEPARATOR:
213 : : {
214 : 266 : sal_Bool bValue = sal_Bool();
215 [ + - ]: 266 : if ( pValues[nProp] >>= bValue )
216 : 266 : m_bDecimalSeparator = bValue;
217 : : else
218 : : {
219 : : SAL_WARN( "unotools.config", "Wrong property type!" );
220 : : }
221 : 266 : m_bRODecimalSeparator = pROStates[nProp];
222 : : }
223 : 1064 : break;
224 : : default:
225 : : SAL_WARN( "unotools.config", "Wrong property type!" );
226 : : }
227 : : }
228 : : }
229 : : }
230 [ + - ][ + - ]: 266 : EnableNotification( aNames );
[ + - ][ + - ]
231 : : }
232 : :
233 [ + - ]: 266 : MakeRealLocale();
234 [ + - ]: 266 : MakeRealUILocale();
235 : 266 : }
236 : :
237 : :
238 : 165 : SvtSysLocaleOptions_Impl::~SvtSysLocaleOptions_Impl()
239 : : {
240 [ + - ][ + + ]: 165 : if ( IsModified() )
241 [ + - ]: 15 : Commit();
242 [ - + ]: 330 : }
243 : :
244 : 371 : void SvtSysLocaleOptions_Impl::MakeRealLocale()
245 : : {
246 : 371 : m_aRealLocale = lcl_str_to_locale( m_aLocaleString );
247 [ + + ]: 371 : if ( !m_aRealLocale.Language.isEmpty() )
248 : : {
249 : 105 : m_eRealLanguage = MsLangId::convertLocaleToLanguage( m_aRealLocale );
250 : : }
251 : : else
252 : : {
253 : 266 : m_eRealLanguage = MsLangId::getSystemLanguage();
254 : 266 : MsLangId::convertLanguageToLocale( m_eRealLanguage, m_aRealLocale );
255 : : }
256 : 371 : }
257 : :
258 : 371 : void SvtSysLocaleOptions_Impl::MakeRealUILocale()
259 : : {
260 : : // as we can't switch UILocale at runtime, we only store changes in the configuration
261 : 371 : m_aRealUILocale = lcl_str_to_locale( m_aUILocaleString );
262 [ + + ]: 371 : if ( !m_aRealUILocale.Language.isEmpty() )
263 : : {
264 : 263 : m_eRealUILanguage = MsLangId::convertLocaleToLanguage( m_aRealUILocale );
265 : : }
266 : : else
267 : : {
268 : 108 : m_eRealUILanguage = MsLangId::getSystemUILanguage();
269 : 108 : MsLangId::convertLanguageToLocale( m_eRealUILanguage, m_aRealUILocale );
270 : : }
271 : 371 : }
272 : :
273 : 0 : sal_Bool SvtSysLocaleOptions_Impl::IsReadOnly( SvtSysLocaleOptions::EOption eOption ) const
274 : : {
275 : 0 : sal_Bool bReadOnly = CFG_READONLY_DEFAULT;
276 [ # # # # ]: 0 : switch(eOption)
277 : : {
278 : : case SvtSysLocaleOptions::E_LOCALE :
279 : : {
280 : 0 : bReadOnly = m_bROLocale;
281 : 0 : break;
282 : : }
283 : : case SvtSysLocaleOptions::E_UILOCALE :
284 : : {
285 : 0 : bReadOnly = m_bROUILocale;
286 : 0 : break;
287 : : }
288 : : case SvtSysLocaleOptions::E_CURRENCY :
289 : : {
290 : 0 : bReadOnly = m_bROCurrency;
291 : 0 : break;
292 : : }
293 : : }
294 : 0 : return bReadOnly;
295 : : }
296 : :
297 : :
298 : 15 : void SvtSysLocaleOptions_Impl::Commit()
299 : : {
300 [ + - ]: 15 : const Sequence< OUString > aOrgNames = GetPropertyNames();
301 : 15 : sal_Int32 nOrgCount = aOrgNames.getLength();
302 : :
303 [ + - ]: 15 : Sequence< OUString > aNames( nOrgCount );
304 [ + - ]: 15 : Sequence< Any > aValues( nOrgCount );
305 : :
306 [ + - ]: 15 : OUString* pNames = aNames.getArray();
307 [ + - ]: 15 : Any* pValues = aValues.getArray();
308 : 15 : sal_Int32 nRealCount = 0;
309 : :
310 [ + + ]: 75 : for ( sal_Int32 nProp = 0; nProp < nOrgCount; nProp++ )
311 : : {
312 [ + + + + : 60 : switch ( nProp )
- ]
313 : : {
314 : : case PROPERTYHANDLE_LOCALE :
315 : : {
316 [ + - ]: 15 : if (!m_bROLocale)
317 : : {
318 : 15 : pNames[nRealCount] = aOrgNames[nProp];
319 [ + - ]: 15 : pValues[nRealCount] <<= m_aLocaleString;
320 : 15 : ++nRealCount;
321 : : }
322 : : }
323 : 15 : break;
324 : : case PROPERTYHANDLE_UILOCALE :
325 : : {
326 [ + - ]: 15 : if (!m_bROUILocale)
327 : : {
328 : 15 : pNames[nRealCount] = aOrgNames[nProp];
329 [ + - ]: 15 : pValues[nRealCount] <<= m_aUILocaleString;
330 : 15 : ++nRealCount;
331 : : }
332 : : }
333 : 15 : break;
334 : : case PROPERTYHANDLE_CURRENCY :
335 : : {
336 [ + - ]: 15 : if (!m_bROCurrency)
337 : : {
338 : 15 : pNames[nRealCount] = aOrgNames[nProp];
339 [ + - ]: 15 : pValues[nRealCount] <<= m_aCurrencyString;
340 : 15 : ++nRealCount;
341 : : }
342 : : }
343 : 15 : break;
344 : : case PROPERTYHANDLE_DECIMALSEPARATOR:
345 [ + - ]: 15 : if( !m_bRODecimalSeparator )
346 : : {
347 : 15 : pNames[nRealCount] = aOrgNames[nProp];
348 [ + - ]: 15 : pValues[nRealCount] <<= m_bDecimalSeparator;
349 : 15 : ++nRealCount;
350 : : }
351 : 15 : break;
352 : : default:
353 : : SAL_WARN( "unotools.config", "invalid index to save a path" );
354 : : }
355 : : }
356 [ + - ]: 15 : aNames.realloc(nRealCount);
357 [ + - ]: 15 : aValues.realloc(nRealCount);
358 [ + - ]: 15 : PutProperties( aNames, aValues );
359 [ + - ][ + - ]: 15 : ClearModified();
[ + - ][ + - ]
360 : 15 : }
361 : :
362 : :
363 : 919 : void SvtSysLocaleOptions_Impl::SetLocaleString( const OUString& rStr )
364 : : {
365 [ + - ][ + + ]: 919 : if (!m_bROLocale && rStr != m_aLocaleString )
[ + + ]
366 : : {
367 : 105 : m_aLocaleString = rStr;
368 : 105 : MakeRealLocale();
369 : 105 : MsLangId::setConfiguredSystemLanguage( m_eRealLanguage );
370 : 105 : SetModified();
371 : 105 : sal_uLong nHint = SYSLOCALEOPTIONS_HINT_LOCALE;
372 [ + - ]: 105 : if ( m_aCurrencyString.isEmpty() )
373 : 105 : nHint |= SYSLOCALEOPTIONS_HINT_CURRENCY;
374 : 105 : NotifyListeners( nHint );
375 : : }
376 : 919 : }
377 : :
378 : 919 : void SvtSysLocaleOptions_Impl::SetUILocaleString( const OUString& rStr )
379 : : {
380 [ + - ][ + + ]: 919 : if (!m_bROUILocale && rStr != m_aUILocaleString )
[ + + ]
381 : : {
382 : 105 : m_aUILocaleString = rStr;
383 : :
384 : : // as we can't switch UILocale at runtime, we only store changes in the configuration
385 : 105 : MakeRealUILocale();
386 : 105 : MsLangId::setConfiguredSystemLanguage( m_eRealUILanguage );
387 : 105 : SetModified();
388 : 105 : NotifyListeners( SYSLOCALEOPTIONS_HINT_UILOCALE );
389 : : }
390 : 919 : }
391 : :
392 : 0 : void SvtSysLocaleOptions_Impl::SetCurrencyString( const OUString& rStr )
393 : : {
394 [ # # ][ # # ]: 0 : if (!m_bROCurrency && rStr != m_aCurrencyString )
[ # # ]
395 : : {
396 : 0 : m_aCurrencyString = rStr;
397 : 0 : SetModified();
398 : 0 : NotifyListeners( SYSLOCALEOPTIONS_HINT_CURRENCY );
399 : : }
400 : 0 : }
401 : :
402 : 0 : void SvtSysLocaleOptions_Impl::SetDecimalSeparatorAsLocale( sal_Bool bSet)
403 : : {
404 [ # # ]: 0 : if(bSet != m_bDecimalSeparator)
405 : : {
406 : 0 : m_bDecimalSeparator = bSet;
407 : 0 : SetModified();
408 : 0 : NotifyListeners( SYSLOCALEOPTIONS_HINT_DECSEP );
409 : : }
410 : 0 : }
411 : :
412 : 0 : void SvtSysLocaleOptions_Impl::Notify( const Sequence< rtl::OUString >& seqPropertyNames )
413 : : {
414 : 0 : sal_uLong nHint = 0;
415 [ # # ]: 0 : Sequence< Any > seqValues = GetProperties( seqPropertyNames );
416 [ # # ]: 0 : Sequence< sal_Bool > seqROStates = GetReadOnlyStates( seqPropertyNames );
417 : 0 : sal_Int32 nCount = seqPropertyNames.getLength();
418 [ # # ]: 0 : for( sal_Int32 nProp = 0; nProp < nCount; ++nProp )
419 : : {
420 [ # # ][ # # ]: 0 : if( seqPropertyNames[nProp] == PROPERTYNAME_LOCALE )
421 : : {
422 : : DBG_ASSERT( seqValues[nProp].getValueTypeClass() == TypeClass_STRING, "Locale property type" );
423 [ # # ]: 0 : seqValues[nProp] >>= m_aLocaleString;
424 [ # # ]: 0 : m_bROLocale = seqROStates[nProp];
425 : 0 : nHint |= SYSLOCALEOPTIONS_HINT_LOCALE;
426 [ # # ]: 0 : if ( m_aCurrencyString.isEmpty() )
427 : 0 : nHint |= SYSLOCALEOPTIONS_HINT_CURRENCY;
428 [ # # ]: 0 : MakeRealLocale();
429 : : }
430 [ # # ][ # # ]: 0 : if( seqPropertyNames[nProp] == PROPERTYNAME_UILOCALE )
431 : : {
432 : : DBG_ASSERT( seqValues[nProp].getValueTypeClass() == TypeClass_STRING, "Locale property type" );
433 [ # # ]: 0 : seqValues[nProp] >>= m_aUILocaleString;
434 [ # # ]: 0 : m_bROUILocale = seqROStates[nProp];
435 : 0 : nHint |= SYSLOCALEOPTIONS_HINT_UILOCALE;
436 [ # # ]: 0 : MakeRealUILocale();
437 : : }
438 [ # # ][ # # ]: 0 : else if( seqPropertyNames[nProp] == PROPERTYNAME_CURRENCY )
439 : : {
440 : : DBG_ASSERT( seqValues[nProp].getValueTypeClass() == TypeClass_STRING, "Currency property type" );
441 [ # # ]: 0 : seqValues[nProp] >>= m_aCurrencyString;
442 [ # # ]: 0 : m_bROCurrency = seqROStates[nProp];
443 : 0 : nHint |= SYSLOCALEOPTIONS_HINT_CURRENCY;
444 : : }
445 [ # # ][ # # ]: 0 : else if( seqPropertyNames[nProp] == PROPERTYNAME_DECIMALSEPARATOR )
446 : : {
447 [ # # ]: 0 : seqValues[nProp] >>= m_bDecimalSeparator;
448 [ # # ]: 0 : m_bRODecimalSeparator = seqROStates[nProp];
449 : : }
450 : : }
451 [ # # ]: 0 : if ( nHint )
452 [ # # ][ # # ]: 0 : NotifyListeners( nHint );
[ # # ]
453 : 0 : }
454 : :
455 : : // ====================================================================
456 : :
457 : 2543 : SvtSysLocaleOptions::SvtSysLocaleOptions()
458 : : {
459 [ + - ][ + - ]: 2543 : MutexGuard aGuard( GetMutex() );
460 [ + + ]: 2543 : if ( !pOptions )
461 : : {
462 : : RTL_LOGFILE_CONTEXT(aLog, "svl ( ??? ) ::SvtSysLocaleOptions_Impl::ctor()");
463 [ + - ][ + - ]: 266 : pOptions = new SvtSysLocaleOptions_Impl;
464 : :
465 [ + - ]: 266 : ItemHolder1::holdConfigItem(E_SYSLOCALEOPTIONS);
466 : : }
467 : 2543 : ++nRefCount;
468 [ + - ][ + - ]: 2543 : pOptions->AddListener(this);
469 : 2543 : }
470 : :
471 : :
472 : 2424 : SvtSysLocaleOptions::~SvtSysLocaleOptions()
473 : : {
474 [ + - ][ + - ]: 2424 : MutexGuard aGuard( GetMutex() );
475 [ + - ]: 2424 : pOptions->RemoveListener(this);
476 [ + + ]: 2424 : if ( !--nRefCount )
477 : : {
478 [ + - ][ + - ]: 165 : delete pOptions;
479 : 165 : pOptions = NULL;
480 [ + - ]: 2424 : }
481 [ - + ]: 2690 : }
482 : :
483 : :
484 : : // static
485 : 7411 : Mutex& SvtSysLocaleOptions::GetMutex()
486 : : {
487 : : static Mutex* pMutex = NULL;
488 [ + + ]: 7411 : if( !pMutex )
489 : : {
490 [ + - ][ + - ]: 266 : MutexGuard aGuard( Mutex::getGlobalMutex() );
491 [ + - ]: 266 : if( !pMutex )
492 : : {
493 : : // #i77768# Due to a static reference in the toolkit lib
494 : : // we need a mutex that lives longer than the svl library.
495 : : // Otherwise the dtor would use a destructed mutex!!
496 [ + - ][ + - ]: 266 : pMutex = new Mutex;
497 [ + - ]: 266 : }
498 : : }
499 : 7411 : return *pMutex;
500 : : }
501 : :
502 : :
503 : 0 : sal_Bool SvtSysLocaleOptions::IsModified()
504 : : {
505 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetMutex() );
506 [ # # ][ # # ]: 0 : return pOptions->IsModified();
507 : : }
508 : :
509 : :
510 : 0 : void SvtSysLocaleOptions::Commit()
511 : : {
512 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetMutex() );
513 [ # # ][ # # ]: 0 : pOptions->Commit();
514 : 0 : }
515 : :
516 : :
517 : 0 : void SvtSysLocaleOptions::BlockBroadcasts( bool bBlock )
518 : : {
519 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetMutex() );
520 [ # # ][ # # ]: 0 : pOptions->BlockBroadcasts( bBlock );
521 : 0 : }
522 : :
523 : :
524 : 73 : const OUString& SvtSysLocaleOptions::GetLocaleConfigString() const
525 : : {
526 [ + - ][ + - ]: 73 : MutexGuard aGuard( GetMutex() );
527 [ + - ]: 73 : return pOptions->GetLocaleString();
528 : : }
529 : :
530 : 919 : void SvtSysLocaleOptions::SetLocaleConfigString( const OUString& rStr )
531 : : {
532 [ + - ][ + - ]: 919 : MutexGuard aGuard( GetMutex() );
533 [ + - ][ + - ]: 919 : pOptions->SetLocaleString( rStr );
534 : 919 : }
535 : :
536 : 919 : void SvtSysLocaleOptions::SetUILocaleConfigString( const OUString& rStr )
537 : : {
538 [ + - ][ + - ]: 919 : MutexGuard aGuard( GetMutex() );
539 [ + - ][ + - ]: 919 : pOptions->SetUILocaleString( rStr );
540 : 919 : }
541 : :
542 : 36 : const OUString& SvtSysLocaleOptions::GetCurrencyConfigString() const
543 : : {
544 [ + - ][ + - ]: 36 : MutexGuard aGuard( GetMutex() );
545 [ + - ]: 36 : return pOptions->GetCurrencyString();
546 : : }
547 : :
548 : :
549 : 0 : void SvtSysLocaleOptions::SetCurrencyConfigString( const OUString& rStr )
550 : : {
551 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetMutex() );
552 [ # # ][ # # ]: 0 : pOptions->SetCurrencyString( rStr );
553 : 0 : }
554 : :
555 : 251 : sal_Bool SvtSysLocaleOptions::IsDecimalSeparatorAsLocale() const
556 : : {
557 [ + - ][ + - ]: 251 : MutexGuard aGuard( GetMutex() );
558 [ + - ]: 251 : return pOptions->IsDecimalSeparatorAsLocale();
559 : : }
560 : :
561 : 0 : void SvtSysLocaleOptions::SetDecimalSeparatorAsLocale( sal_Bool bSet)
562 : : {
563 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetMutex() );
564 [ # # ][ # # ]: 0 : pOptions->SetDecimalSeparatorAsLocale(bSet);
565 : 0 : }
566 : :
567 : :
568 : 0 : sal_Bool SvtSysLocaleOptions::IsReadOnly( EOption eOption ) const
569 : : {
570 [ # # ][ # # ]: 0 : MutexGuard aGuard( GetMutex() );
571 [ # # ]: 0 : return pOptions->IsReadOnly( eOption );
572 : : }
573 : :
574 : : // static
575 : 36 : void SvtSysLocaleOptions::GetCurrencyAbbrevAndLanguage( String& rAbbrev,
576 : : LanguageType& eLang, const ::rtl::OUString& rConfigString )
577 : : {
578 : 36 : sal_Int32 nDelim = rConfigString.indexOf( '-' );
579 [ - + ]: 36 : if ( nDelim >= 0 )
580 : : {
581 [ # # ]: 0 : rAbbrev = rConfigString.copy( 0, nDelim );
582 [ # # ]: 0 : String aIsoStr( rConfigString.copy( nDelim+1 ) );
583 [ # # ][ # # ]: 0 : eLang = MsLangId::convertIsoStringToLanguage( aIsoStr );
[ # # ]
584 : : }
585 : : else
586 : : {
587 : 36 : rAbbrev = rConfigString;
588 [ - + ]: 36 : eLang = (rAbbrev.Len() ? LANGUAGE_NONE : LANGUAGE_SYSTEM);
589 : : }
590 : 36 : }
591 : :
592 : :
593 : : // static
594 : 0 : ::rtl::OUString SvtSysLocaleOptions::CreateCurrencyConfigString(
595 : : const String& rAbbrev, LanguageType eLang )
596 : : {
597 [ # # ][ # # ]: 0 : String aIsoStr( MsLangId::convertLanguageToIsoString( eLang ) );
598 [ # # ]: 0 : if ( aIsoStr.Len() )
599 : : {
600 : 0 : ::rtl::OUStringBuffer aStr( rAbbrev.Len() + 1 + aIsoStr.Len() );
601 [ # # ][ # # ]: 0 : aStr.append( rAbbrev );
602 [ # # ]: 0 : aStr.append( sal_Unicode('-') );
603 [ # # ][ # # ]: 0 : aStr.append( aIsoStr );
604 [ # # ]: 0 : return aStr.makeStringAndClear();
605 : : }
606 : : else
607 [ # # ][ # # ]: 0 : return rAbbrev;
608 : : }
609 : :
610 : :
611 : : // static
612 : 36 : void SvtSysLocaleOptions::SetCurrencyChangeLink( const Link& rLink )
613 : : {
614 [ + - ][ + - ]: 36 : MutexGuard aGuard( GetMutex() );
615 : : DBG_ASSERT( !CurrencyChangeLink::get().IsSet(), "SvtSysLocaleOptions::SetCurrencyChangeLink: already set" );
616 [ + - ][ + - ]: 36 : CurrencyChangeLink::get() = rLink;
617 : 36 : }
618 : :
619 : :
620 : : // static
621 : 210 : const Link& SvtSysLocaleOptions::GetCurrencyChangeLink()
622 : : {
623 [ + - ][ + - ]: 210 : MutexGuard aGuard( GetMutex() );
624 [ + - ][ + - ]: 210 : return CurrencyChangeLink::get();
625 : : }
626 : :
627 : :
628 : 420 : void SvtSysLocaleOptions::ConfigurationChanged( utl::ConfigurationBroadcaster* p, sal_uInt32 nHint )
629 : : {
630 [ + + ]: 420 : if ( nHint & SYSLOCALEOPTIONS_HINT_CURRENCY )
631 : : {
632 : 210 : const Link& rLink = GetCurrencyChangeLink();
633 [ - + ]: 210 : if ( rLink.IsSet() )
634 : 0 : rLink.Call( NULL );
635 : : }
636 : :
637 : 420 : ::utl::detail::Options::ConfigurationChanged( p, nHint );
638 : 420 : }
639 : :
640 : 0 : com::sun::star::lang::Locale SvtSysLocaleOptions::GetLocale() const
641 : : {
642 : 0 : return lcl_str_to_locale( GetLocaleConfigString() );
643 : : }
644 : :
645 : 482 : com::sun::star::lang::Locale SvtSysLocaleOptions::GetRealLocale() const
646 : : {
647 : 482 : return pOptions->GetRealLocale();
648 : : }
649 : :
650 : 1006 : com::sun::star::lang::Locale SvtSysLocaleOptions::GetRealUILocale() const
651 : : {
652 : 1006 : return pOptions->GetRealUILocale();
653 : : }
654 : :
655 : 1906510 : LanguageType SvtSysLocaleOptions::GetRealLanguage() const
656 : : {
657 : 1906510 : return pOptions->GetRealLanguage();
658 : : }
659 : :
660 : 602661 : LanguageType SvtSysLocaleOptions::GetRealUILanguage() const
661 : : {
662 : 602661 : return pOptions->GetRealUILanguage();
663 : : }
664 : :
665 : :
666 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|