summaryrefslogtreecommitdiff
path: root/desktop/source/app/langselect.cxx
diff options
context:
space:
mode:
authorCarsten Driesner <cd@openoffice.org>2010-03-03 11:09:45 +0100
committerCarsten Driesner <cd@openoffice.org>2010-03-03 11:09:45 +0100
commit79199b42d311089db2709db8fb84e236ab419c0a (patch)
tree78eb749b5543000c66ac421fa03fd2018bc2b19e /desktop/source/app/langselect.cxx
parent67f5b4e2af040ae81ca633b8fc07d9269990678f (diff)
native0: #161679# Additional parameter and ini file entry to define startup language
Diffstat (limited to 'desktop/source/app/langselect.cxx')
-rw-r--r--desktop/source/app/langselect.cxx140
1 files changed, 125 insertions, 15 deletions
diff --git a/desktop/source/app/langselect.cxx b/desktop/source/app/langselect.cxx
index 2ad0b382e4..42e0f925ea 100644
--- a/desktop/source/app/langselect.cxx
+++ b/desktop/source/app/langselect.cxx
@@ -33,15 +33,14 @@
#include "app.hxx"
#include "langselect.hxx"
+#include "cmdlineargs.hxx"
#include <stdio.h>
-#ifndef _RTL_STRING_HXX
#include <rtl/string.hxx>
-#endif
-#ifndef _SVTOOLS_PATHOPTIONS_HXX
+#include <rtl/bootstrap.hxx>
#include <svtools/pathoptions.hxx>
-#endif
#include <tools/resid.hxx>
+#include <tools/config.hxx>
#include <i18npool/mslangid.hxx>
#include <comphelper/processfactory.hxx>
#include <com/sun/star/container/XNameAccess.hpp>
@@ -55,6 +54,7 @@
#include <rtl/locale.hxx>
#include <rtl/instance.hxx>
#include <osl/process.h>
+#include <osl/file.hxx>
using namespace rtl;
using namespace com::sun::star::uno;
@@ -65,10 +65,54 @@ using namespace com::sun::star::util;
namespace desktop {
+static char const SOFFICE_BOOTSTRAP[] = "Bootstrap";
+static char const SOFFICE_STARTLANG[] = "STARTLANG";
sal_Bool LanguageSelection::bFoundLanguage = sal_False;
OUString LanguageSelection::aFoundLanguage;
const OUString LanguageSelection::usFallbackLanguage = OUString::createFromAscii("en-US");
+
+static sal_Bool existsURL( OUString const& sURL )
+{
+ using namespace osl;
+ DirectoryItem aDirItem;
+
+ if (sURL.getLength() != 0)
+ return ( DirectoryItem::get( sURL, aDirItem ) == DirectoryItem::E_None );
+
+ return sal_False;
+}
+
+// locate soffice.ini/.rc file
+static OUString locateSofficeIniFile()
+{
+ OUString aUserDataPath;
+ OUString aSofficeIniFileURL;
+
+ // Retrieve the default file URL for the soffice.ini/rc
+ rtl::Bootstrap().getIniName( aSofficeIniFileURL );
+
+ if ( utl::Bootstrap::locateUserData( aUserDataPath ) == utl::Bootstrap::PATH_EXISTS )
+ {
+ const char CONFIG_DIR[] = "/config";
+
+ sal_Int32 nIndex = aSofficeIniFileURL.lastIndexOf( '/');
+ if ( nIndex > 0 )
+ {
+ OUString aUserSofficeIniFileURL;
+ OUStringBuffer aBuffer( aUserDataPath );
+ aBuffer.appendAscii( CONFIG_DIR );
+ aBuffer.append( aSofficeIniFileURL.copy( nIndex ));
+ aUserSofficeIniFileURL = aBuffer.makeStringAndClear();
+
+ if ( existsURL( aUserSofficeIniFileURL ))
+ return aUserSofficeIniFileURL;
+ }
+ }
+ // Fallback try to use the soffice.ini/rc from program folder
+ return aSofficeIniFileURL;
+}
+
Locale LanguageSelection::IsoStringToLocale(const OUString& str)
{
Locale l;
@@ -122,8 +166,51 @@ bool LanguageSelection::prepareLanguage()
catch (Exception&)
{
}
+
// get the selected UI language as string
- OUString aLocaleString = getLanguageString();
+ bool bCmdLanguage( false );
+ bool bIniLanguage( false );
+ OUString aEmpty;
+ OUString aLocaleString = getUserUILanguage();
+
+ if ( aLocaleString.getLength() == 0 )
+ {
+ CommandLineArgs* pCmdLineArgs = Desktop::GetCommandLineArgs();
+ if ( pCmdLineArgs )
+ {
+ pCmdLineArgs->GetLanguage(aLocaleString);
+ if (isInstalledLanguage(aLocaleString, sal_False))
+ {
+ bCmdLanguage = true;
+ bFoundLanguage = true;
+ aFoundLanguage = aLocaleString;
+ }
+ else
+ aLocaleString = aEmpty;
+ }
+
+ if ( !bCmdLanguage )
+ {
+ OUString aSOfficeIniURL = locateSofficeIniFile();
+ Config aConfig(aSOfficeIniURL);
+ aConfig.SetGroup( SOFFICE_BOOTSTRAP );
+ OString sLang = aConfig.ReadKey( SOFFICE_STARTLANG );
+ aLocaleString = OUString( sLang.getStr(), sLang.getLength(), RTL_TEXTENCODING_ASCII_US );
+ if (isInstalledLanguage(aLocaleString, sal_False))
+ {
+ bIniLanguage = true;
+ bFoundLanguage = true;
+ aFoundLanguage = aLocaleString;
+ }
+ else
+ aLocaleString = aEmpty;
+ }
+ }
+
+ // user further fallbacks for the UI language
+ if ( aLocaleString.getLength() == 0 )
+ aLocaleString = getLanguageString();
+
if ( aLocaleString.getLength() > 0 )
{
try
@@ -135,13 +222,24 @@ bool LanguageSelection::prepareLanguage()
// flush any data already written to the configuration (which
// currently uses independent caches for different locales and thus
// would ignore data written to another cache):
- Reference< XFlushable >(theConfigProvider, UNO_QUERY_THROW)->
- flush();
+ Reference< XFlushable >(theConfigProvider, UNO_QUERY_THROW)->flush();
theConfigProvider->setLocale(loc);
- Reference< XPropertySet > xProp(getConfigAccess("org.openoffice.Setup/L10N/", sal_True), UNO_QUERY_THROW);
- xProp->setPropertyValue(OUString::createFromAscii("ooLocale"), makeAny(aLocaleString));
- Reference< XChangesBatch >(xProp, UNO_QUERY_THROW)->commitChanges();
+ if ( !bCmdLanguage )
+ {
+ // Store language only
+ Reference< XPropertySet > xProp(getConfigAccess("org.openoffice.Setup/L10N/", sal_True), UNO_QUERY_THROW);
+ xProp->setPropertyValue(OUString::createFromAscii("ooLocale"), makeAny(aLocaleString));
+ Reference< XChangesBatch >(xProp, UNO_QUERY_THROW)->commitChanges();
+ }
+
+ if ( bIniLanguage )
+ {
+ // Store language only
+ Reference< XPropertySet > xProp(getConfigAccess("org.openoffice.Office.Linguistic/General/", sal_True), UNO_QUERY_THROW);
+ xProp->setPropertyValue(OUString::createFromAscii("UILocale"), makeAny(aLocaleString));
+ Reference< XChangesBatch >(xProp, UNO_QUERY_THROW)->commitChanges();
+ }
bSuccess = sal_True;
}
@@ -156,7 +254,7 @@ bool LanguageSelection::prepareLanguage()
}
}
-
+
// #i32939# setting of default document locale
// #i32939# this should not be based on the UI language
setDefaultLanguage(aLocaleString);
@@ -188,11 +286,8 @@ void LanguageSelection::setDefaultLanguage(const OUString& sLocale)
}
}
-OUString LanguageSelection::getLanguageString()
+OUString LanguageSelection::getUserUILanguage()
{
- // did we already find a language?
- if (bFoundLanguage)
- return aFoundLanguage;
// check whether the user has selected a specific language
OUString aUserLanguage = getUserLanguage();
if (aUserLanguage.getLength() > 0 )
@@ -210,6 +305,21 @@ OUString LanguageSelection::getLanguageString()
resetUserLanguage();
}
}
+
+ return aUserLanguage;
+}
+
+OUString LanguageSelection::getLanguageString()
+{
+ // did we already find a language?
+ if (bFoundLanguage)
+ return aFoundLanguage;
+
+ // check whether the user has selected a specific language
+ OUString aUserLanguage = getUserUILanguage();
+ if (aUserLanguage.getLength() > 0 )
+ return aUserLanguage ;
+
// try to use system default
aUserLanguage = getSystemLanguage();
if (aUserLanguage.getLength() > 0 )