summaryrefslogtreecommitdiff
path: root/unotools
diff options
context:
space:
mode:
authorMathias Bauer <mba@openoffice.org>2010-01-12 08:29:31 +0100
committerMathias Bauer <mba@openoffice.org>2010-01-12 08:29:31 +0100
commit5a03ff2c5391d9a25d0bfbb1e4b3f1312df1c70b (patch)
tree6f6a031f32ee21b156ace59e401c2225ef026b26 /unotools
parentcf1210e40b872191ba433636480293eabc017d95 (diff)
#i107450#: code from svx/source/options moved to other libs
Diffstat (limited to 'unotools')
-rw-r--r--unotools/inc/unotools/syslocale.hxx7
-rw-r--r--unotools/source/misc/syslocale.cxx27
2 files changed, 34 insertions, 0 deletions
diff --git a/unotools/inc/unotools/syslocale.hxx b/unotools/inc/unotools/syslocale.hxx
index adce66b7e84a..5b7834832689 100644
--- a/unotools/inc/unotools/syslocale.hxx
+++ b/unotools/inc/unotools/syslocale.hxx
@@ -36,6 +36,7 @@
#include <unotools/charclass.hxx>
#include <sal/types.h>
#include <i18npool/lang.h>
+#include <rtl/textenc.h>
class SvtSysLocale_Impl;
class SvtSysLocaleOptions;
@@ -79,6 +80,12 @@ public:
LanguageType GetLanguage() const;
com::sun::star::lang::Locale GetUILocale() const;
LanguageType GetUILanguage() const;
+
+ /** Get the best MIME encoding matching the system locale, or if that isn't
+ determinable one that matches the UI locale, or UTF8 if everything else
+ fails.
+ */
+ static rtl_TextEncoding GetBestMimeEncoding();
};
#endif // INCLUDED_SVTOOLS_SYSLOCALE_HXX
diff --git a/unotools/source/misc/syslocale.cxx b/unotools/source/misc/syslocale.cxx
index 8e9d75c6ce0c..9b131f2a76cc 100644
--- a/unotools/source/misc/syslocale.cxx
+++ b/unotools/source/misc/syslocale.cxx
@@ -39,6 +39,9 @@
#include <unotools/localedatawrapper.hxx>
#include <comphelper/processfactory.hxx>
#include <i18npool/mslangid.hxx>
+#include <rtl/tencinfo.h>
+#include <rtl/locale.h>
+#include <osl/nlsupport.h>
using namespace osl;
using namespace com::sun::star;
@@ -187,4 +190,28 @@ LanguageType SvtSysLocale::GetUILanguage() const
return pImpl->aSysLocaleOptions.GetRealUILanguage();
}
+//------------------------------------------------------------------------
+
+// static
+rtl_TextEncoding SvtSysLocale::GetBestMimeEncoding()
+{
+ const sal_Char* pCharSet = rtl_getBestMimeCharsetFromTextEncoding(
+ gsl_getSystemTextEncoding() );
+ if ( !pCharSet )
+ {
+ // If the system locale is unknown to us, e.g. LC_ALL=xx, match the UI
+ // language if possible.
+ ::com::sun::star::lang::Locale aLocale( SvtSysLocale().GetUILocale() );
+ rtl_Locale * pLocale = rtl_locale_register( aLocale.Language.getStr(),
+ aLocale.Country.getStr(), aLocale.Variant.getStr() );
+ rtl_TextEncoding nEnc = osl_getTextEncodingFromLocale( pLocale );
+ pCharSet = rtl_getBestMimeCharsetFromTextEncoding( nEnc );
+ }
+ rtl_TextEncoding nRet;
+ if ( pCharSet )
+ nRet = rtl_getTextEncodingFromMimeCharset( pCharSet );
+ else
+ nRet = RTL_TEXTENCODING_UTF8;
+ return nRet;
+}