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

Generated by: LCOV version 1.10