Branch data Line data Source code
1 : : /* -*- Mode: C++; tab-width: 4; indent-tabs-mode: nil; c-basic-offset: 4 -*- */
2 : : /*************************************************************************
3 : : *
4 : : * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER.
5 : : *
6 : : * Copyright 2000, 2010 Oracle and/or its affiliates.
7 : : *
8 : : * OpenOffice.org - a multi-platform office productivity suite
9 : : *
10 : : * This file is part of OpenOffice.org.
11 : : *
12 : : * OpenOffice.org is free software: you can redistribute it and/or modify
13 : : * it under the terms of the GNU Lesser General Public License version 3
14 : : * only, as published by the Free Software Foundation.
15 : : *
16 : : * OpenOffice.org is distributed in the hope that it will be useful,
17 : : * but WITHOUT ANY WARRANTY; without even the implied warranty of
18 : : * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
19 : : * GNU Lesser General Public License version 3 for more details
20 : : * (a copy is included in the LICENSE file that accompanied this code).
21 : : *
22 : : * You should have received a copy of the GNU Lesser General Public License
23 : : * version 3 along with OpenOffice.org. If not, see
24 : : * <http://www.openoffice.org/license.html>
25 : : * for a copy of the LGPLv3 License.
26 : : *
27 : : ************************************************************************/
28 : :
29 : :
30 : : #include "app.hxx"
31 : : #include "langselect.hxx"
32 : : #include "cmdlineargs.hxx"
33 : : #include <stdio.h>
34 : :
35 : : #include <rtl/string.hxx>
36 : : #include <rtl/bootstrap.hxx>
37 : : #include <unotools/pathoptions.hxx>
38 : : #include <tools/resid.hxx>
39 : : #include <tools/config.hxx>
40 : : #include <i18npool/mslangid.hxx>
41 : : #include <comphelper/processfactory.hxx>
42 : : #include <com/sun/star/configuration/theDefaultProvider.hpp>
43 : : #include <com/sun/star/container/XNameAccess.hpp>
44 : : #include <com/sun/star/lang/XComponent.hpp>
45 : : #include <com/sun/star/beans/NamedValue.hpp>
46 : : #include <com/sun/star/util/XChangesBatch.hpp>
47 : : #include <com/sun/star/uno/Any.hxx>
48 : : #include <com/sun/star/lang/XLocalizable.hpp>
49 : : #include <com/sun/star/lang/Locale.hpp>
50 : : #include "com/sun/star/util/XFlushable.hpp"
51 : : #include <rtl/locale.hxx>
52 : : #include <rtl/instance.hxx>
53 : : #include <osl/process.h>
54 : : #include <osl/file.hxx>
55 : :
56 : : using namespace com::sun::star::uno;
57 : : using namespace com::sun::star::lang;
58 : : using namespace com::sun::star::container;
59 : : using namespace com::sun::star::beans;
60 : : using namespace com::sun::star::util;
61 : :
62 : : using ::rtl::OUString;
63 : : using ::rtl::OUStringBuffer;
64 : : using ::rtl::OString;
65 : :
66 : : namespace desktop {
67 : :
68 : : static char const SOFFICE_BOOTSTRAP[] = "Bootstrap";
69 : : static char const SOFFICE_STARTLANG[] = "STARTLANG";
70 : :
71 : : sal_Bool LanguageSelection::bFoundLanguage = sal_False;
72 : 158 : OUString LanguageSelection::aFoundLanguage;
73 : : LanguageSelection::LanguageSelectionStatus LanguageSelection::m_eStatus = LS_STATUS_OK;
74 : :
75 : 158 : static sal_Bool existsURL( OUString const& sURL )
76 : : {
77 : : using namespace osl;
78 : 158 : DirectoryItem aDirItem;
79 : :
80 [ + - ]: 158 : if (!sURL.isEmpty())
81 [ + - ]: 158 : return ( DirectoryItem::get( sURL, aDirItem ) == DirectoryItem::E_None );
82 : :
83 [ + - ]: 158 : return sal_False;
84 : : }
85 : :
86 : : // locate soffice.ini/.rc file
87 : 158 : static OUString locateSofficeIniFile()
88 : : {
89 : 158 : OUString aUserDataPath;
90 : 158 : OUString aSofficeIniFileURL;
91 : :
92 : : // Retrieve the default file URL for the soffice.ini/rc
93 : 158 : rtl::Bootstrap().getIniName( aSofficeIniFileURL );
94 : :
95 [ + - ][ + - ]: 158 : if ( utl::Bootstrap::locateUserData( aUserDataPath ) == utl::Bootstrap::PATH_EXISTS )
96 : : {
97 : 158 : const char CONFIG_DIR[] = "/config";
98 : :
99 : 158 : sal_Int32 nIndex = aSofficeIniFileURL.lastIndexOf( '/');
100 [ + - ]: 158 : if ( nIndex > 0 )
101 : : {
102 : 158 : OUString aUserSofficeIniFileURL;
103 [ + - ]: 158 : OUStringBuffer aBuffer( aUserDataPath );
104 [ + - ]: 158 : aBuffer.appendAscii( CONFIG_DIR );
105 [ + - ]: 158 : aBuffer.append( aSofficeIniFileURL.copy( nIndex ));
106 [ + - ]: 158 : aUserSofficeIniFileURL = aBuffer.makeStringAndClear();
107 : :
108 [ - + ][ + - ]: 158 : if ( existsURL( aUserSofficeIniFileURL ))
109 [ - + ][ + - ]: 158 : return aUserSofficeIniFileURL;
110 : : }
111 : : }
112 : : // Fallback try to use the soffice.ini/rc from program folder
113 : 158 : return aSofficeIniFileURL;
114 : : }
115 : :
116 : 316 : Locale LanguageSelection::IsoStringToLocale(const OUString& str)
117 : : {
118 : 316 : Locale l;
119 : 316 : sal_Int32 index=0;
120 : 316 : l.Language = str.getToken(0, '-', index);
121 [ + - ]: 316 : if (index >= 0) l.Country = str.getToken(0, '-', index);
122 [ - + ]: 316 : if (index >= 0) l.Variant = str.getToken(0, '-', index);
123 : 316 : return l;
124 : : }
125 : :
126 : 158 : bool LanguageSelection::prepareLanguage()
127 : : {
128 : 158 : m_eStatus = LS_STATUS_OK;
129 : : Reference< XLocalizable > theConfigProvider(
130 : : com::sun::star::configuration::theDefaultProvider::get(
131 : : comphelper::getProcessComponentContext() ),
132 [ + - ][ + - ]: 158 : UNO_QUERY_THROW );
[ + - ]
133 : :
134 : 158 : sal_Bool bSuccess = sal_False;
135 : :
136 : : // #i42730#get the windows 16Bit locale - it should be preferred over the UI language
137 : : try
138 : : {
139 [ + - ][ + - ]: 158 : Reference< XPropertySet > xProp(getConfigAccess("org.openoffice.System/L10N/", sal_False), UNO_QUERY_THROW);
140 [ + - ][ + - ]: 158 : Any aWin16SysLocale = xProp->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("SystemLocale")));
[ + - ]
141 : 158 : ::rtl::OUString sWin16SysLocale;
142 : 158 : aWin16SysLocale >>= sWin16SysLocale;
143 [ + - ]: 158 : if( !sWin16SysLocale.isEmpty())
144 [ + - ][ # # ]: 158 : setDefaultLanguage(sWin16SysLocale);
145 : : }
146 [ # # ]: 0 : catch(const Exception&)
147 : : {
148 : 0 : m_eStatus = LS_STATUS_CONFIGURATIONACCESS_BROKEN;
149 : : }
150 : :
151 : : // #i32939# use system locale to set document default locale
152 : : try
153 : : {
154 : 158 : OUString usLocale;
155 : : Reference< XPropertySet > xLocaleProp(getConfigAccess(
156 [ + - ][ + - ]: 158 : "org.openoffice.System/L10N", sal_True), UNO_QUERY_THROW);
157 [ + - ][ + - ]: 158 : xLocaleProp->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("Locale"))) >>= usLocale;
[ + - ]
158 [ # # ][ + - ]: 158 : setDefaultLanguage(usLocale);
159 : : }
160 [ # # ]: 0 : catch (const Exception&)
161 : : {
162 : 0 : m_eStatus = LS_STATUS_CONFIGURATIONACCESS_BROKEN;
163 : : }
164 : :
165 : : // get the selected UI language as string
166 : 158 : bool bCmdLanguage( false );
167 : 158 : bool bIniLanguage( false );
168 [ + - ]: 158 : OUString aLocaleString = getUserUILanguage();
169 : :
170 [ + - ]: 158 : if ( aLocaleString.isEmpty() )
171 : : {
172 : 158 : OUString aEmpty;
173 : :
174 [ + - ]: 158 : const CommandLineArgs& rCmdLineArgs = Desktop::GetCommandLineArgs();
175 [ + - ]: 158 : aLocaleString = rCmdLineArgs.GetLanguage();
176 [ - + ][ + - ]: 158 : if (isInstalledLanguage(aLocaleString, sal_False))
177 : : {
178 : 0 : bCmdLanguage = true;
179 : 0 : bFoundLanguage = true;
180 : 0 : aFoundLanguage = aLocaleString;
181 : : }
182 : : else
183 : 158 : aLocaleString = aEmpty;
184 : :
185 [ + - ]: 158 : if ( !bCmdLanguage )
186 : : {
187 [ + - ]: 158 : OUString aSOfficeIniURL = locateSofficeIniFile();
188 [ + - ]: 158 : Config aConfig(aSOfficeIniURL);
189 [ + - ]: 158 : aConfig.SetGroup( SOFFICE_BOOTSTRAP );
190 [ + - ]: 158 : OString sLang = aConfig.ReadKey( SOFFICE_STARTLANG );
191 [ + - ]: 158 : aLocaleString = OUString( sLang.getStr(), sLang.getLength(), RTL_TEXTENCODING_ASCII_US );
192 [ - + ][ + - ]: 158 : if (isInstalledLanguage(aLocaleString, sal_False))
193 : : {
194 : 0 : bIniLanguage = true;
195 : 0 : bFoundLanguage = true;
196 : 0 : aFoundLanguage = aLocaleString;
197 : : }
198 : : else
199 [ + - ]: 158 : aLocaleString = aEmpty;
200 : 158 : }
201 : : }
202 : :
203 : : // user further fallbacks for the UI language
204 [ + - ]: 158 : if ( aLocaleString.isEmpty() )
205 [ + - ]: 158 : aLocaleString = getLanguageString();
206 : :
207 [ + - ]: 158 : if ( !aLocaleString.isEmpty() )
208 : : {
209 : : try
210 : : {
211 : : // prepare default config provider by localizing it to the selected locale
212 : : // this will ensure localized configuration settings to be selected accoring to the
213 : : // UI language.
214 : 158 : Locale loc = LanguageSelection::IsoStringToLocale(aLocaleString);
215 [ + - ][ + - ]: 158 : theConfigProvider->setLocale(loc);
216 : :
217 [ + - ][ + - ]: 158 : Reference< XPropertySet > xProp(getConfigAccess("org.openoffice.Setup/L10N/", sal_True), UNO_QUERY_THROW);
218 [ + - ]: 158 : if ( !bCmdLanguage )
219 : : {
220 : : // Store language only
221 [ + - ][ + - ]: 158 : xProp->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("ooLocale")), makeAny(aLocaleString));
[ + - ][ + - ]
222 [ + - ][ + - ]: 158 : Reference< XChangesBatch >(xProp, UNO_QUERY_THROW)->commitChanges();
[ + - ]
223 : : }
224 : :
225 [ - + ]: 158 : if ( bIniLanguage )
226 : : {
227 : : // Store language only
228 [ # # ][ # # ]: 0 : Reference< XPropertySet > xProp2(getConfigAccess("org.openoffice.Office.Linguistic/General/", sal_True), UNO_QUERY_THROW);
229 [ # # ][ # # ]: 0 : xProp2->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("UILocale")), makeAny(aLocaleString));
[ # # ][ # # ]
230 [ # # ][ # # ]: 0 : Reference< XChangesBatch >(xProp2, UNO_QUERY_THROW)->commitChanges();
[ # # ]
231 : : }
232 : :
233 [ + - ][ + - ]: 158 : MsLangId::setConfiguredSystemUILanguage( MsLangId::convertLocaleToLanguage(loc) );
234 : :
235 : 158 : OUString sLocale;
236 [ + - ][ + - ]: 158 : xProp->getPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("ooSetupSystemLocale"))) >>= sLocale;
[ + - ]
237 [ - + ]: 158 : if ( !sLocale.isEmpty() )
238 : : {
239 : 0 : loc = LanguageSelection::IsoStringToLocale(sLocale);
240 [ # # ][ # # ]: 0 : MsLangId::setConfiguredSystemLanguage( MsLangId::convertLocaleToLanguage(loc) );
241 : : }
242 : : else
243 [ + - ][ + - ]: 158 : MsLangId::setConfiguredSystemLanguage( MsLangId::getSystemLanguage() );
244 : :
245 : 158 : bSuccess = sal_True;
246 : : }
247 [ # # ]: 0 : catch ( const PropertyVetoException& )
248 : : {
249 : : // we are not allowed to change this
250 : : }
251 [ # # # # : 0 : catch (const Exception& e)
# ]
252 : : {
253 [ # # ]: 0 : OString aMsg = OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US);
254 : 0 : OSL_FAIL(aMsg.getStr());
255 : :
256 : : }
257 : : }
258 : :
259 : : // #i32939# setting of default document locale
260 : : // #i32939# this should not be based on the UI language
261 [ + - ]: 158 : setDefaultLanguage(aLocaleString);
262 : :
263 : 158 : return bSuccess;
264 : : }
265 : :
266 : 474 : void LanguageSelection::setDefaultLanguage(const OUString& sLocale)
267 : : {
268 : : // #i32939# setting of default document language
269 : : // See #i42730# for rules for determining source of settings
270 : :
271 : : // determine script type of locale
272 : 474 : LanguageType nLang = MsLangId::convertIsoStringToLanguage(sLocale);
273 : 474 : sal_uInt16 nScriptType = SvtLanguageOptions::GetScriptTypeOfLanguage(nLang);
274 : :
275 [ - - + ]: 474 : switch (nScriptType)
276 : : {
277 : : case SCRIPTTYPE_ASIAN:
278 : 0 : MsLangId::setConfiguredAsianFallback( nLang );
279 : 0 : break;
280 : : case SCRIPTTYPE_COMPLEX:
281 : 0 : MsLangId::setConfiguredComplexFallback( nLang );
282 : 0 : break;
283 : : default:
284 : 474 : MsLangId::setConfiguredWesternFallback( nLang );
285 : 474 : break;
286 : : }
287 : 474 : }
288 : :
289 : 316 : OUString LanguageSelection::getUserUILanguage()
290 : : {
291 : : // check whether the user has selected a specific language
292 [ + - ]: 316 : OUString aUserLanguage = getUserLanguage();
293 [ - + ]: 316 : if (!aUserLanguage.isEmpty() )
294 : : {
295 [ # # ][ # # ]: 0 : if (isInstalledLanguage(aUserLanguage))
296 : : {
297 : : // all is well
298 : 0 : bFoundLanguage = sal_True;
299 : 0 : aFoundLanguage = aUserLanguage;
300 : 0 : return aFoundLanguage;
301 : : }
302 : : else
303 : : {
304 : : // selected language is not/no longer installed
305 [ # # ]: 0 : resetUserLanguage();
306 : : }
307 : : }
308 : :
309 : 316 : return aUserLanguage;
310 : : }
311 : :
312 : 316 : OUString LanguageSelection::getLanguageString()
313 : : {
314 : : // did we already find a language?
315 [ + + ]: 316 : if (bFoundLanguage)
316 : 158 : return aFoundLanguage;
317 : :
318 : : // check whether the user has selected a specific language
319 [ + - ]: 158 : OUString aUserLanguage = getUserUILanguage();
320 [ - + ]: 158 : if (!aUserLanguage.isEmpty() )
321 : 0 : return aUserLanguage ;
322 : :
323 : : // try to use system default
324 [ + - ]: 158 : aUserLanguage = getSystemLanguage();
325 [ + - ]: 158 : if (!aUserLanguage.isEmpty() )
326 : : {
327 [ + - ][ + - ]: 158 : if (isInstalledLanguage(aUserLanguage, sal_False))
328 : : {
329 : : // great, system default language is available
330 : 158 : bFoundLanguage = sal_True;
331 : 158 : aFoundLanguage = aUserLanguage;
332 : 158 : return aFoundLanguage;
333 : : }
334 : : }
335 : : // fallback 1: en-US
336 [ # # ]: 0 : OUString usFB(RTL_CONSTASCII_USTRINGPARAM("en-US"));
337 [ # # ][ # # ]: 0 : if (isInstalledLanguage(usFB))
338 : : {
339 : 0 : bFoundLanguage = sal_True;
340 [ # # ]: 0 : aFoundLanguage = OUString(RTL_CONSTASCII_USTRINGPARAM("en-US"));
341 : 0 : return aFoundLanguage;
342 : : }
343 : :
344 : : // fallback didn't work use first installed language
345 [ # # ]: 0 : aUserLanguage = getFirstInstalledLanguage();
346 : :
347 : 0 : bFoundLanguage = sal_True;
348 : 0 : aFoundLanguage = aUserLanguage;
349 : 316 : return aFoundLanguage;
350 : : }
351 : :
352 : 1422 : Reference< XNameAccess > LanguageSelection::getConfigAccess(const sal_Char* pPath, sal_Bool bUpdate)
353 : : {
354 : 1422 : Reference< XNameAccess > xNameAccess;
355 : : try{
356 : 1422 : OUString sAccessSrvc;
357 [ + + ]: 1422 : if (bUpdate)
358 [ + - ]: 316 : sAccessSrvc = OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.configuration.ConfigurationUpdateAccess"));
359 : : else
360 [ + - ]: 1106 : sAccessSrvc = OUString(RTL_CONSTASCII_USTRINGPARAM("com.sun.star.configuration.ConfigurationAccess"));
361 : :
362 : 1422 : OUString sConfigURL = OUString::createFromAscii(pPath);
363 : :
364 : : Reference< XMultiServiceFactory > theConfigProvider(
365 : : com::sun::star::configuration::theDefaultProvider::get(
366 [ + - ][ + - ]: 1422 : comphelper::getProcessComponentContext() ) );
367 : :
368 : : // access the provider
369 [ + - ]: 1422 : Sequence< Any > theArgs(1);
370 [ + - ][ + - ]: 1422 : theArgs[ 0 ] <<= sConfigURL;
371 : : xNameAccess = Reference< XNameAccess > (
372 [ + - ]: 1422 : theConfigProvider->createInstanceWithArguments(
373 [ + - ][ + - ]: 1422 : sAccessSrvc, theArgs ), UNO_QUERY_THROW );
[ + - ][ + - ]
374 [ # # # # ]: 0 : } catch (const com::sun::star::uno::Exception& e)
375 : : {
376 [ # # ]: 0 : OString aMsg = OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US);
377 : 0 : OSL_FAIL(aMsg.getStr());
378 : : }
379 : 1422 : return xNameAccess;
380 : : }
381 : :
382 : 474 : Sequence< OUString > LanguageSelection::getInstalledLanguages()
383 : : {
384 [ + - ]: 474 : Sequence< OUString > seqLanguages;
385 [ + - ]: 474 : Reference< XNameAccess > xAccess = getConfigAccess("org.openoffice.Setup/Office/InstalledLocales", sal_False);
386 [ + - ]: 474 : if (!xAccess.is()) return seqLanguages;
387 [ + - ][ + - ]: 474 : seqLanguages = xAccess->getElementNames();
[ + - ][ + - ]
388 : 474 : return seqLanguages;
389 : : }
390 : :
391 : : // FIXME
392 : : // it's not very clever to handle language fallbacks here, but
393 : : // right now, there is no place that handles those fallbacks globally
394 : 316 : static Sequence< OUString > _getFallbackLocales(const OUString& aIsoLang)
395 : : {
396 : 316 : Sequence< OUString > seqFallbacks;
397 [ - + ]: 316 : if ( aIsoLang == "zh-HK" ) {
398 [ # # ][ # # ]: 0 : seqFallbacks = Sequence< OUString >(1);
[ # # ]
399 [ # # ][ # # ]: 0 : seqFallbacks[0] = OUString(RTL_CONSTASCII_USTRINGPARAM("zh-TW"));
400 : : }
401 : 316 : return seqFallbacks;
402 : : }
403 : :
404 : 474 : sal_Bool LanguageSelection::isInstalledLanguage(OUString& usLocale, sal_Bool bExact)
405 : : {
406 : 474 : sal_Bool bInstalled = sal_False;
407 [ + - ]: 474 : Sequence< OUString > seqLanguages = getInstalledLanguages();
408 [ + + ]: 790 : for (sal_Int32 i=0; i<seqLanguages.getLength(); i++)
409 : : {
410 [ + - ][ + + ]: 474 : if (usLocale.equals(seqLanguages[i]))
411 : : {
412 : 158 : bInstalled = sal_True;
413 : 158 : break;
414 : : }
415 : : }
416 : :
417 [ + + ][ + - ]: 474 : if (!bInstalled && !bExact)
418 : : {
419 : : // try fallback locales
420 [ + - ]: 316 : Sequence< OUString > seqFallbacks = _getFallbackLocales(usLocale);
421 [ - + ]: 316 : for (sal_Int32 j=0; j<seqFallbacks.getLength(); j++)
422 : : {
423 [ # # ]: 0 : for (sal_Int32 i=0; i<seqLanguages.getLength(); i++)
424 : : {
425 [ # # ][ # # ]: 0 : if (seqFallbacks[j].equals(seqLanguages[i]))
[ # # ]
426 : : {
427 : 0 : bInstalled = sal_True;
428 [ # # ]: 0 : usLocale = seqFallbacks[j];
429 : 0 : break;
430 : : }
431 : : }
432 [ + - ]: 316 : }
433 : : }
434 : :
435 [ + + ][ + - ]: 474 : if (!bInstalled && !bExact)
436 : : {
437 : : // no exact match was found, well try to find a substitute
438 [ + + ]: 632 : for (sal_Int32 i=0; i<seqLanguages.getLength(); i++)
439 : : {
440 [ + - ][ - + ]: 316 : if (usLocale.indexOf(seqLanguages[i]) == 0)
441 : : {
442 : : // requested locale starts with the installed locale
443 : : // (i.e. installed locale has index 0 in requested locale)
444 : 0 : bInstalled = sal_True;
445 [ # # ]: 0 : usLocale = seqLanguages[i];
446 : 0 : break;
447 : : }
448 : : }
449 : : }
450 [ + - ]: 474 : return bInstalled;
451 : : }
452 : :
453 : 0 : OUString LanguageSelection::getFirstInstalledLanguage()
454 : : {
455 : 0 : OUString aLanguage;
456 [ # # ]: 0 : Sequence< OUString > seqLanguages = getInstalledLanguages();
457 [ # # ]: 0 : if (seqLanguages.getLength() > 0)
458 [ # # ]: 0 : aLanguage = seqLanguages[0];
459 [ # # ]: 0 : return aLanguage;
460 : : }
461 : :
462 : 316 : OUString LanguageSelection::getUserLanguage()
463 : : {
464 : 316 : OUString aUserLanguage;
465 [ + - ]: 316 : Reference< XNameAccess > xAccess(getConfigAccess("org.openoffice.Office.Linguistic/General", sal_False));
466 [ + - ]: 316 : if (xAccess.is())
467 : : {
468 : : try
469 : : {
470 [ + - ][ + - ]: 316 : xAccess->getByName(OUString(RTL_CONSTASCII_USTRINGPARAM("UILocale"))) >>= aUserLanguage;
[ + - ]
[ # # # ]
471 : : }
472 [ # # ]: 0 : catch ( NoSuchElementException const & )
473 : : {
474 : 0 : m_eStatus = LS_STATUS_CONFIGURATIONACCESS_BROKEN;
475 : 0 : return OUString();
476 : : }
477 [ # # ]: 0 : catch ( WrappedTargetException const & )
478 : : {
479 : 0 : m_eStatus = LS_STATUS_CONFIGURATIONACCESS_BROKEN;
480 : 0 : return OUString();
481 : : }
482 : : }
483 : 316 : return aUserLanguage;
484 : : }
485 : :
486 : 158 : OUString LanguageSelection::getSystemLanguage()
487 : : {
488 : 158 : OUString aUserLanguage;
489 [ + - ]: 158 : Reference< XNameAccess > xAccess(getConfigAccess("org.openoffice.System/L10N", sal_False));
490 [ + - ]: 158 : if (xAccess.is())
491 : : {
492 : : try
493 : : {
494 [ + - ][ + - ]: 158 : xAccess->getByName(OUString(RTL_CONSTASCII_USTRINGPARAM("UILocale"))) >>= aUserLanguage;
[ + - ]
[ # # # ]
495 : : }
496 [ # # ]: 0 : catch ( NoSuchElementException const & )
497 : : {
498 : 0 : m_eStatus = LS_STATUS_CONFIGURATIONACCESS_BROKEN;
499 : 0 : return OUString();
500 : : }
501 [ # # ]: 0 : catch ( WrappedTargetException const & )
502 : : {
503 : 0 : m_eStatus = LS_STATUS_CONFIGURATIONACCESS_BROKEN;
504 : 0 : return OUString();
505 : : }
506 : : }
507 : 158 : return aUserLanguage;
508 : : }
509 : :
510 : :
511 : 0 : void LanguageSelection::resetUserLanguage()
512 : : {
513 : : try
514 : : {
515 [ # # ][ # # ]: 0 : Reference< XPropertySet > xProp(getConfigAccess("org.openoffice.Office.Linguistic/General", sal_True), UNO_QUERY_THROW);
516 [ # # ][ # # ]: 0 : xProp->setPropertyValue(OUString(RTL_CONSTASCII_USTRINGPARAM("UILocale")), makeAny(OUString()));
[ # # ][ # # ]
517 [ # # ][ # # ]: 0 : Reference< XChangesBatch >(xProp, UNO_QUERY_THROW)->commitChanges();
[ # # ]
518 : : }
519 : 0 : catch ( const PropertyVetoException& )
520 : : {
521 : : // we are not allowed to change this
522 : : }
523 [ # # # ]: 0 : catch (const Exception& e)
524 : : {
525 [ # # ]: 0 : OString aMsg = OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US);
526 : : OSL_FAIL(aMsg.getStr());
527 : 0 : m_eStatus = LS_STATUS_CONFIGURATIONACCESS_BROKEN;
528 : : }
529 : 0 : }
530 : :
531 : 0 : LanguageSelection::LanguageSelectionStatus LanguageSelection::getStatus()
532 : : {
533 : 0 : return m_eStatus;
534 : : }
535 : :
536 [ + - ][ + - ]: 474 : } // namespace desktop
537 : :
538 : : /* vim:set shiftwidth=4 softtabstop=4 expandtab: */
|