diff options
author | Carsten Driesner <cd@openoffice.org> | 2010-03-03 11:09:45 +0100 |
---|---|---|
committer | Carsten Driesner <cd@openoffice.org> | 2010-03-03 11:09:45 +0100 |
commit | 79199b42d311089db2709db8fb84e236ab419c0a (patch) | |
tree | 78eb749b5543000c66ac421fa03fd2018bc2b19e /desktop | |
parent | 67f5b4e2af040ae81ca633b8fc07d9269990678f (diff) |
native0: #161679# Additional parameter and ini file entry to define startup language
Diffstat (limited to 'desktop')
-rw-r--r-- | desktop/source/app/cmdlineargs.cxx | 84 | ||||
-rw-r--r-- | desktop/source/app/cmdlineargs.hxx | 2 | ||||
-rw-r--r-- | desktop/source/app/langselect.cxx | 140 | ||||
-rw-r--r-- | desktop/source/app/langselect.hxx | 1 |
4 files changed, 182 insertions, 45 deletions
diff --git a/desktop/source/app/cmdlineargs.cxx b/desktop/source/app/cmdlineargs.cxx index 84bb6cd7b2..57e1a85a8c 100644 --- a/desktop/source/app/cmdlineargs.cxx +++ b/desktop/source/app/cmdlineargs.cxx @@ -230,7 +230,7 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier ) bViewEvent = sal_False; bStartEvent = sal_False; bDisplaySpec = sal_False; - } + } else if ( aArgStr.EqualsIgnoreCaseAscii( "-view" )) { // open in viewmode @@ -242,31 +242,43 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier ) bViewEvent = sal_True; bStartEvent = sal_False; bDisplaySpec = sal_False; - } + } else if ( aArgStr.EqualsIgnoreCaseAscii( "-show" )) { - // open in viewmode - bOpenEvent = sal_False; - bViewEvent = sal_False; - bStartEvent = sal_True; - bPrintEvent = sal_False; - bPrintToEvent = sal_False; - bForceNewEvent = sal_False; - bForceOpenEvent = sal_False; - bDisplaySpec = sal_False; + // open in viewmode + bOpenEvent = sal_False; + bViewEvent = sal_False; + bStartEvent = sal_True; + bPrintEvent = sal_False; + bPrintToEvent = sal_False; + bForceNewEvent = sal_False; + bForceOpenEvent = sal_False; + bDisplaySpec = sal_False; } else if ( aArgStr.EqualsIgnoreCaseAscii( "-display" )) { - // open in viewmode - bOpenEvent = sal_False; - bPrintEvent = sal_False; - bForceOpenEvent = sal_False; - bPrintToEvent = sal_False; - bForceNewEvent = sal_False; - bViewEvent = sal_False; - bStartEvent = sal_False; - bDisplaySpec = sal_True; + // set display + bOpenEvent = sal_False; + bPrintEvent = sal_False; + bForceOpenEvent = sal_False; + bPrintToEvent = sal_False; + bForceNewEvent = sal_False; + bViewEvent = sal_False; + bStartEvent = sal_False; + bDisplaySpec = sal_True; + } + else if ( aArgStr.EqualsIgnoreCaseAscii( "-language" )) + { + bOpenEvent = sal_False; + bPrintEvent = sal_False; + bForceOpenEvent = sal_False; + bPrintToEvent = sal_False; + bForceNewEvent = sal_False; + bViewEvent = sal_False; + bStartEvent = sal_False; + bDisplaySpec = sal_False; } + #ifdef MACOSX /* #i84053# ignore -psn on Mac Platform dependent #ifdef here is ugly, however this is currently @@ -275,15 +287,15 @@ void CommandLineArgs::ParseCommandLine_Impl( Supplier& supplier ) */ else if ( aArgStr.CompareToAscii( "-psn", 4 ) == COMPARE_EQUAL ) { - // finder argument from MacOSX - bOpenEvent = sal_False; - bPrintEvent = sal_False; - bForceOpenEvent = sal_False; - bPrintToEvent = sal_False; - bForceNewEvent = sal_False; - bViewEvent = sal_False; - bStartEvent = sal_False; - bDisplaySpec = sal_False; + // finder argument from MacOSX + bOpenEvent = sal_False; + bPrintEvent = sal_False; + bForceOpenEvent = sal_False; + bPrintToEvent = sal_False; + bForceNewEvent = sal_False; + bViewEvent = sal_False; + bStartEvent = sal_False; + bDisplaySpec = sal_False; } #endif } @@ -505,7 +517,12 @@ sal_Bool CommandLineArgs::InterpretCommandLineParameter( const ::rtl::OUString& } else if ( aArgStr.Copy(0, 9).EqualsIgnoreCaseAscii( "-version=" )) { - AddStringListParam_Impl( CMD_STRINGPARAM_VERSION, aArgStr.Copy( 15 ) ); + AddStringListParam_Impl( CMD_STRINGPARAM_VERSION, aArgStr.Copy( 9 ) ); + return sal_True; + } + else if ( aArgStr.Copy(0, 10).EqualsIgnoreCaseAscii( "-language=" )) + { + AddStringListParam_Impl( CMD_STRINGPARAM_LANGUAGE, aArgStr.Copy( 10 ) ); return sal_True; } else if ( aArg.equalsAsciiL( RTL_CONSTASCII_STRINGPARAM( "-writer" )) == sal_True ) @@ -848,6 +865,13 @@ sal_Bool CommandLineArgs::GetPrinterName( ::rtl::OUString& rPara ) const return m_aStrSetParams[ CMD_STRINGPARAM_PRINTERNAME ]; } +sal_Bool CommandLineArgs::GetLanguage( ::rtl::OUString& rPara ) const +{ + osl::MutexGuard aMutexGuard( m_aMutex ); + rPara = m_aStrParams[ CMD_STRINGPARAM_LANGUAGE ]; + return m_aStrSetParams[ CMD_STRINGPARAM_LANGUAGE ]; +} + sal_Bool CommandLineArgs::IsEmpty() const { osl::MutexGuard aMutexGuard( m_aMutex ); diff --git a/desktop/source/app/cmdlineargs.hxx b/desktop/source/app/cmdlineargs.hxx index db4619151f..e2c3e112ab 100644 --- a/desktop/source/app/cmdlineargs.hxx +++ b/desktop/source/app/cmdlineargs.hxx @@ -93,6 +93,7 @@ class CommandLineArgs CMD_STRINGPARAM_PRINTTOLIST, CMD_STRINGPARAM_PRINTERNAME, CMD_STRINGPARAM_DISPLAY, + CMD_STRINGPARAM_LANGUAGE, CMD_STRINGPARAM_COUNT // must be last element! }; @@ -168,6 +169,7 @@ class CommandLineArgs sal_Bool GetPrintList( ::rtl::OUString& rPara) const; sal_Bool GetPrintToList( ::rtl::OUString& rPara ) const; sal_Bool GetPrinterName( ::rtl::OUString& rPara ) const; + sal_Bool GetLanguage( ::rtl::OUString& rPara ) const; // Special analyzed states (does not match directly to a command line parameter!) sal_Bool IsPrinting() const; 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 ) diff --git a/desktop/source/app/langselect.hxx b/desktop/source/app/langselect.hxx index 3418b80caf..3220557aa8 100644 --- a/desktop/source/app/langselect.hxx +++ b/desktop/source/app/langselect.hxx @@ -57,6 +57,7 @@ private: static com::sun::star::uno::Sequence< rtl::OUString > getInstalledLanguages(); static sal_Bool isInstalledLanguage(rtl::OUString& usLocale, sal_Bool bExact=sal_False); static rtl::OUString getFirstInstalledLanguage(); + static rtl::OUString getUserUILanguage(); static rtl::OUString getUserLanguage(); static rtl::OUString getSystemLanguage(); static void resetUserLanguage(); |