diff options
author | Mathias Bauer <mba@openoffice.org> | 2009-10-26 15:10:09 +0100 |
---|---|---|
committer | Mathias Bauer <mba@openoffice.org> | 2009-10-26 15:10:09 +0100 |
commit | acae9170ea69e3b54b31ebf0322b53e4818172a3 (patch) | |
tree | 0e09d99e023c913c2e88d65100a322925534c6b8 /unotools | |
parent | bd76a8cd10f3a734f4dc0489faa76bd4ce92866a (diff) |
#i103496#: shorten timespan when locale settings are inconsistent as they are stored at three different locations
Diffstat (limited to 'unotools')
-rw-r--r-- | unotools/inc/unotools/syslocaleoptions.hxx | 4 | ||||
-rw-r--r-- | unotools/source/config/syslocaleoptions.cxx | 115 | ||||
-rw-r--r-- | unotools/source/misc/syslocale.cxx | 59 |
3 files changed, 107 insertions, 71 deletions
diff --git a/unotools/inc/unotools/syslocaleoptions.hxx b/unotools/inc/unotools/syslocaleoptions.hxx index 2da102c161cc..6bb81fdd3ee0 100644 --- a/unotools/inc/unotools/syslocaleoptions.hxx +++ b/unotools/inc/unotools/syslocaleoptions.hxx @@ -107,11 +107,15 @@ public: const ::rtl::OUString& GetLocaleConfigString() const; void SetLocaleConfigString( const ::rtl::OUString& rStr ); com::sun::star::lang::Locale GetLocale() const; + com::sun::star::lang::Locale GetRealLocale() const; + LanguageType GetRealLanguage() const; /// The config string may be empty to denote the SYSTEM locale const ::rtl::OUString& GetUILocaleConfigString() const; void SetUILocaleConfigString( const ::rtl::OUString& rStr ); com::sun::star::lang::Locale GetUILocale() const; + com::sun::star::lang::Locale GetRealUILocale() const; + LanguageType GetRealUILanguage() const; /// The config string may be empty to denote the default currency of the locale const ::rtl::OUString& GetCurrencyConfigString() const; diff --git a/unotools/source/config/syslocaleoptions.cxx b/unotools/source/config/syslocaleoptions.cxx index 6c4071709e02..f358fe24df4f 100644 --- a/unotools/source/config/syslocaleoptions.cxx +++ b/unotools/source/config/syslocaleoptions.cxx @@ -62,8 +62,32 @@ namespace : public rtl::Static<Link, CurrencyChangeLink> {}; } +com::sun::star::lang::Locale lcl_str_to_locale( const ::rtl::OUString rStr ) +{ + com::sun::star::lang::Locale aRet; + if ( rStr.getLength() ) + { + aRet = com::sun::star::lang::Locale(); + sal_Int32 nSep = rStr.indexOf('-'); + if (nSep < 0) + aRet.Language = rStr; + else + { + aRet.Language = rStr.copy(0, nSep); + if (nSep < rStr.getLength()) + aRet.Country = rStr.copy(nSep+1, rStr.getLength() - (nSep+1)); + } + } + + return aRet; +} + class SvtSysLocaleOptions_Impl : public utl::ConfigItem { + Locale m_aRealLocale; + Locale m_aRealUILocale; + LanguageType m_eRealLanguage; + LanguageType m_eRealUILanguage; OUString m_aLocaleString; // en-US or de-DE or empty for SYSTEM OUString m_aUILocaleString; // en-US or de-DE or empty for SYSTEM OUString m_aCurrencyString; // USD-en-US or EUR-de-DE @@ -75,7 +99,9 @@ class SvtSysLocaleOptions_Impl : public utl::ConfigItem sal_Bool m_bROCurrency; sal_Bool m_bRODecimalSeparator; - static const Sequence< /* const */ OUString > GetPropertyNames(); + static const Sequence< /* const */ OUString > GetPropertyNames(); + void MakeRealLocale(); + void MakeRealUILocale(); public: SvtSysLocaleOptions_Impl(); @@ -100,6 +126,10 @@ public: void SetDecimalSeparatorAsLocale( sal_Bool bSet); sal_Bool IsReadOnly( SvtSysLocaleOptions::EOption eOption ) const; + const Locale& GetRealLocale() { return m_aRealLocale; } + const Locale& GetRealUILocale() { return m_aRealUILocale; } + LanguageType GetRealLanguage() { return m_eRealLanguage; } + LanguageType GetRealUILanguage() { return m_eRealUILanguage; } }; @@ -217,6 +247,9 @@ SvtSysLocaleOptions_Impl::SvtSysLocaleOptions_Impl() // UpdateMiscSettings_Impl(); EnableNotification( aNames ); } + + MakeRealLocale(); + MakeRealUILocale(); } @@ -226,6 +259,37 @@ SvtSysLocaleOptions_Impl::~SvtSysLocaleOptions_Impl() Commit(); } +void SvtSysLocaleOptions_Impl::MakeRealLocale() +{ + m_aRealLocale = lcl_str_to_locale( m_aLocaleString ); + if ( m_aRealLocale.Language.getLength() ) + { + m_eRealLanguage = MsLangId::convertLocaleToLanguage( m_aRealLocale ); + } + else + { + m_eRealLanguage = MsLangId::getSystemLanguage(); + MsLangId::convertLanguageToLocale( m_eRealLanguage, m_aRealLocale ); + } +} + +void SvtSysLocaleOptions_Impl::MakeRealUILocale() +{ + if ( !m_aRealUILocale.Language.getLength() ) + { + // as we can't switch UILocale at runtime, we only store changes in the configuration + m_aRealUILocale = lcl_str_to_locale( m_aUILocaleString ); + if ( m_aRealUILocale.Language.getLength() ) + { + m_eRealUILanguage = MsLangId::convertLocaleToLanguage( m_aRealUILocale ); + } + else + { + m_eRealUILanguage = MsLangId::getSystemUILanguage(); + MsLangId::convertLanguageToLocale( m_eRealUILanguage, m_aRealUILocale ); + } + } +} sal_Bool SvtSysLocaleOptions_Impl::IsReadOnly( SvtSysLocaleOptions::EOption eOption ) const { @@ -322,6 +386,8 @@ void SvtSysLocaleOptions_Impl::SetLocaleString( const OUString& rStr ) if (!m_bROLocale && rStr != m_aLocaleString ) { m_aLocaleString = rStr; + MakeRealLocale(); + MsLangId::setConfiguredSystemLanguage( m_eRealLanguage ); SetModified(); ULONG nHint = SYSLOCALEOPTIONS_HINT_LOCALE; if ( !m_aCurrencyString.getLength() ) @@ -335,8 +401,13 @@ void SvtSysLocaleOptions_Impl::SetUILocaleString( const OUString& rStr ) if (!m_bROUILocale && rStr != m_aUILocaleString ) { m_aUILocaleString = rStr; +/* + // as we can't switch UILocale at runtime, we only store changes in the configuration + MakeRealUILocale(); + MsLangId::setConfiguredSystemLanguage( m_eRealUILanguage ); SetModified(); NotifyListeners( SYSLOCALEOPTIONS_HINT_UILOCALE ); +*/ } } @@ -376,6 +447,7 @@ void SvtSysLocaleOptions_Impl::Notify( const Sequence< rtl::OUString >& seqPrope nHint |= SYSLOCALEOPTIONS_HINT_LOCALE; if ( !m_aCurrencyString.getLength() ) nHint |= SYSLOCALEOPTIONS_HINT_CURRENCY; + MakeRealLocale(); } if( seqPropertyNames[nProp] == PROPERTYNAME_UILOCALE ) { @@ -383,6 +455,7 @@ void SvtSysLocaleOptions_Impl::Notify( const Sequence< rtl::OUString >& seqPrope seqValues[nProp] >>= m_aUILocaleString; m_bROUILocale = seqROStates[nProp]; nHint |= SYSLOCALEOPTIONS_HINT_UILOCALE; + MakeRealUILocale(); } else if( seqPropertyNames[nProp] == PROPERTYNAME_CURRENCY ) { @@ -599,26 +672,6 @@ void SvtSysLocaleOptions::ConfigurationChanged( utl::ConfigurationBroadcaster* p ::utl::detail::Options::ConfigurationChanged( p, nHint ); } -com::sun::star::lang::Locale lcl_str_to_locale( const ::rtl::OUString rStr ) -{ - com::sun::star::lang::Locale aRet; - if ( rStr.getLength() ) - { - aRet = com::sun::star::lang::Locale(); - sal_Int32 nSep = rStr.indexOf('-'); - if (nSep < 0) - aRet.Language = rStr; - else - { - aRet.Language = rStr.copy(0, nSep); - if (nSep < rStr.getLength()) - aRet.Country = rStr.copy(nSep+1, rStr.getLength() - (nSep+1)); - } - } - - return aRet; -} - com::sun::star::lang::Locale SvtSysLocaleOptions::GetLocale() const { return lcl_str_to_locale( GetLocaleConfigString() ); @@ -628,3 +681,23 @@ com::sun::star::lang::Locale SvtSysLocaleOptions::GetUILocale() const { return lcl_str_to_locale( GetUILocaleConfigString() ); } + +com::sun::star::lang::Locale SvtSysLocaleOptions::GetRealLocale() const +{ + return pOptions->GetRealLocale(); +} + +com::sun::star::lang::Locale SvtSysLocaleOptions::GetRealUILocale() const +{ + return pOptions->GetRealUILocale(); +} + +LanguageType SvtSysLocaleOptions::GetRealLanguage() const +{ + return pOptions->GetRealLanguage(); +} + +LanguageType SvtSysLocaleOptions::GetRealUILanguage() const +{ + return pOptions->GetRealUILanguage(); +}
\ No newline at end of file diff --git a/unotools/source/misc/syslocale.cxx b/unotools/source/misc/syslocale.cxx index f108cd2ed3df..8e9d75c6ce0c 100644 --- a/unotools/source/misc/syslocale.cxx +++ b/unotools/source/misc/syslocale.cxx @@ -54,57 +54,19 @@ public: SvtSysLocaleOptions aSysLocaleOptions; LocaleDataWrapper* pLocaleData; CharClass* pCharClass; - com::sun::star::lang::Locale maLocale; - com::sun::star::lang::Locale maUILocale; - LanguageType meLanguage; - LanguageType meUILanguage; SvtSysLocale_Impl(); virtual ~SvtSysLocale_Impl(); CharClass* GetCharClass(); virtual void ConfigurationChanged( utl::ConfigurationBroadcaster*, sal_uInt32 ); - void GetLocale(); - void GetUILocale(); }; -void SvtSysLocale_Impl::GetLocale() -{ - // ask configuration - maLocale = aSysLocaleOptions.GetLocale(); - if ( maLocale.Language.getLength() ) - { - meLanguage = MsLangId::convertLocaleToLanguage( maLocale ); - } - else - { - meLanguage = MsLangId::getSystemLanguage(); - MsLangId::convertLanguageToLocale( meLanguage, maLocale ); - } -} - -void SvtSysLocale_Impl::GetUILocale() -{ - maLocale = aSysLocaleOptions.GetLocale(); - if ( maUILocale.Language.getLength() ) - { - meUILanguage = MsLangId::convertLocaleToLanguage( maUILocale ); - } - else - { - meUILanguage = MsLangId::getSystemUILanguage(); - MsLangId::convertLanguageToLocale( meUILanguage, maUILocale ); - } -} - // ----------------------------------------------------------------------- SvtSysLocale_Impl::SvtSysLocale_Impl() : pCharClass(NULL) { - GetLocale(); - GetUILocale(); - - pLocaleData = new LocaleDataWrapper( ::comphelper::getProcessServiceFactory(), maLocale ); + pLocaleData = new LocaleDataWrapper( ::comphelper::getProcessServiceFactory(), aSysLocaleOptions.GetRealLocale() ); // listen for further changes aSysLocaleOptions.AddListener( this ); @@ -121,7 +83,7 @@ SvtSysLocale_Impl::~SvtSysLocale_Impl() CharClass* SvtSysLocale_Impl::GetCharClass() { if ( !pCharClass ) - pCharClass = new CharClass(::comphelper::getProcessServiceFactory(), maLocale ); + pCharClass = new CharClass(::comphelper::getProcessServiceFactory(), aSysLocaleOptions.GetRealLocale() ); return pCharClass; } @@ -130,13 +92,10 @@ void SvtSysLocale_Impl::ConfigurationChanged( utl::ConfigurationBroadcaster*, sa MutexGuard aGuard( SvtSysLocale::GetMutex() ); if ( nHint & SYSLOCALEOPTIONS_HINT_LOCALE ) { - GetLocale(); - pLocaleData->setLocale( maLocale ); - GetCharClass()->setLocale( maLocale ); + com::sun::star::lang::Locale aLocale( aSysLocaleOptions.GetRealLocale() ); + pLocaleData->setLocale( aLocale ); + GetCharClass()->setLocale( aLocale ); } - - if ( nHint & SYSLOCALEOPTIONS_HINT_UILOCALE ) - GetUILocale(); } // ==================================================================== @@ -210,22 +169,22 @@ SvtSysLocaleOptions& SvtSysLocale::GetOptions() const com::sun::star::lang::Locale SvtSysLocale::GetLocale() const { - return pImpl->maLocale; + return pImpl->aSysLocaleOptions.GetRealLocale(); } LanguageType SvtSysLocale::GetLanguage() const { - return pImpl->meLanguage; + return pImpl->aSysLocaleOptions.GetRealLanguage(); } com::sun::star::lang::Locale SvtSysLocale::GetUILocale() const { - return pImpl->maUILocale; + return pImpl->aSysLocaleOptions.GetRealUILocale(); } LanguageType SvtSysLocale::GetUILanguage() const { - return pImpl->meUILanguage; + return pImpl->aSysLocaleOptions.GetRealUILanguage(); } |