LCOV - code coverage report
Current view: top level - usr/local/src/libreoffice/unotools/source/config - syslocaleoptions.cxx (source / functions) Hit Total Coverage
Test: libreoffice_filtered.info Lines: 207 325 63.7 %
Date: 2013-07-09 Functions: 32 49 65.3 %
Legend: Lines: hit not hit

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

Generated by: LCOV version 1.10