From 1f9fbc29833885ae8cac439e4e1cec688bdd9dfd Mon Sep 17 00:00:00 2001 From: RĂ¼diger Timm Date: Fri, 20 Aug 2004 13:23:23 +0000 Subject: INTEGRATION: CWS syssettings01 (1.7.26); FILE MERGED 2004/08/04 11:39:16 lo 1.7.26.5: #i32207# select UI language from Language Options dialog 2004/08/03 15:39:32 lo 1.7.26.4: #i32207# select UI language from Language Options dialog 2004/08/03 08:25:29 lo 1.7.26.3: #i8452# language selections through tools/options 2004/08/02 08:36:04 obr 1.7.26.2: RESYNC: (1.7-1.9); FILE MERGED 2004/07/30 16:31:39 lo 1.7.26.1: #i32207# select UI language from Language Options dialog --- desktop/source/app/langselect.cxx | 349 ++++++++++++++++---------------------- 1 file changed, 142 insertions(+), 207 deletions(-) diff --git a/desktop/source/app/langselect.cxx b/desktop/source/app/langselect.cxx index 1688e609e8d3..7d995b363ee2 100644 --- a/desktop/source/app/langselect.cxx +++ b/desktop/source/app/langselect.cxx @@ -2,8 +2,8 @@ * * $RCSfile: langselect.cxx,v $ * - * $Revision: 1.10 $ - * last change: $Author: rt $ $Date: 2004-08-20 13:00:26 $ + * $Revision: 1.11 $ + * last change: $Author: rt $ $Date: 2004-08-20 14:23:23 $ * * The Contents of this file are made available subject to the terms of * either of the following licenses @@ -60,7 +60,6 @@ #include "app.hxx" #include "langselect.hxx" -#include "langselect.hrc" #include #ifndef _RTL_STRING_HXX @@ -83,6 +82,7 @@ #endif #include #include +#include #include #include #include @@ -97,26 +97,13 @@ using namespace com::sun::star::uno; using namespace com::sun::star::lang; using namespace com::sun::star::container; using namespace com::sun::star::beans; +using namespace com::sun::star::util; namespace desktop { -LanguageSelectionDialog::LanguageSelectionDialog(ResMgr *pResMgr) : - ModalDialog(NULL,ResId(DLG_LANGSELECT, pResMgr)), - m_aText(this, ResId(TXT_DLG_LANGSELECT, pResMgr)), - m_aListBox(this, ResId(LST_DLG_LANGSELECT, pResMgr)), - m_aButton(this, ResId(BTN_DLG_LANGSELECT_OK, pResMgr)) -{ - FreeResource(); -} - -namespace { struct lLanguages : public rtl::Static {}; } - -// execute the language selection -// display a dialog if more than one language is installed -// XXX this is a temporary solution -static sal_Bool bFoundLanguage = sal_False; -//static LanguageType aFoundLanguageType = LANGUAGE_DONTKNOW; -static OUString aFoundLanguage; +sal_Bool LanguageSelection::bFoundLanguage = sal_False; +OUString LanguageSelection::aFoundLanguage; +const OUString LanguageSelection::usFallbackLanguage = OUString::createFromAscii("en-US"); Locale LanguageSelection::IsoStringToLocale(const OUString& str) { @@ -130,245 +117,193 @@ Locale LanguageSelection::IsoStringToLocale(const OUString& str) void LanguageSelection::prepareLanguage() { - // XXX make everything works without assertions in first run - // in multi-language installations, some things might fail in first run - if (getUserLanguage().getLength() > 0) return; - IsoList l = getInstalledIsoLanguages(); - if (l.size() >= 1) + OUString aLocaleString = getLanguageString(); + OUString sConfigSrvc = OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider"); + Reference< XMultiServiceFactory > theMSF = comphelper::getProcessServiceFactory(); + try { - // throw any away existing default config - OUString sConfigSrvc = OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider"); - Reference< XMultiServiceFactory > theMSF = comphelper::getProcessServiceFactory(); + Reference< XLocalizable > theConfigProvider( - theMSF->createInstance( sConfigSrvc ),UNO_QUERY ); - OSL_ENSURE(theConfigProvider.is(), "cannot localize config manager."); - if (theConfigProvider.is()) - { - OUString aLocaleString = *l.begin(); - Locale loc = LanguageSelection::IsoStringToLocale(aLocaleString); - theConfigProvider->setLocale(loc); - } + theMSF->createInstance( sConfigSrvc ),UNO_QUERY_THROW ); + Locale loc = LanguageSelection::IsoStringToLocale(aLocaleString); + 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(); + } + catch (Exception& e) + { + OString aMsg = OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US); + OSL_ENSURE(sal_False, aMsg.getStr()); + } } + OUString LanguageSelection::getLanguageString() { - + // did we already find a language? if (bFoundLanguage) return aFoundLanguage; - - // check whether there was aleady a language selected by the user + // check whether the user has selected a specific language OUString aUserLanguage = getUserLanguage(); if (aUserLanguage.getLength() > 0 ) { - bFoundLanguage = sal_True; - aFoundLanguage = aUserLanguage; - // return aFoundLanguageType; - // we can not return yet, we need to check whether this instance supports - // the language that was previously chosen by the user... - } - - // fill list - IsoList &rLanguages = lLanguages::get(); - if (rLanguages.size() < 1) - rLanguages = getInstalledIsoLanguages(); - // check whether found language is available - if (bFoundLanguage) - { - IsoList::const_iterator iLang = rLanguages.begin(); - while (iLang != rLanguages.end()) + if (isInstalledLanguage(aUserLanguage)) { - if (iLang->equals(aFoundLanguage)) - return aFoundLanguage; - else - iLang++; + // all is well + bFoundLanguage = sal_True; + aFoundLanguage = aUserLanguage; + return aFoundLanguage; } - } - if (rLanguages.size() > 1) { - // are there multiple languages installed? - // get resource - rtl::OString aMgrName = OString("langselect") + OString::valueOf((sal_Int32)SUPD, 10); - ::com::sun::star::lang::Locale aLocale; - ResMgr* pResMgr = ResMgr::SearchCreateResMgr( aMgrName, aLocale ); - LanguageSelectionDialog lsd(pResMgr); - StrList languages(getLanguageStrings(rLanguages)); - for (StrList::iterator str_iter = languages.begin(); str_iter != languages.end(); str_iter++) + else { - lsd.m_aListBox.InsertEntry(*str_iter); + // selected language is not/no longer installed + resetUserLanguage(); } - - lsd.Execute(); - short nSelected = lsd.m_aListBox.GetSelectEntryPos(); - IsoList::const_iterator i = rLanguages.begin(); - for (sal_Int32 n=0; n(*lang_iter); - ::com::sun::star::lang::Locale aLocale = LanguageSelection::IsoStringToLocale(lang); - ResMgr* pResMgr = ResMgr::SearchCreateResMgr( aMgrName, aLocale ); - if (pResMgr != NULL) { - String aString(ResId(STR_LANGSELECT, pResMgr)); - aList.push_back(aString); - delete pResMgr; - } + bFoundLanguage = sal_True; + aFoundLanguage = usFallbackLanguage; + return aFoundLanguage; } - return aList; + // falback didn't work use first installed language + aUserLanguage = getFirstInstalledLanguage(); + bFoundLanguage = sal_True; + aFoundLanguage = aUserLanguage; + return aFoundLanguage; } -// get a language choosen by the user -OUString LanguageSelection::getUserLanguage() +Reference< XNameAccess > LanguageSelection::getConfigAccess(const sal_Char* pPath, sal_Bool bUpdate) { - OUString aLanguage; + Reference< XNameAccess > xNameAccess; try{ - OUString sConfigSrvc = OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider"); - OUString sAccessSrvc = OUString::createFromAscii("com.sun.star.configuration.ConfigurationAccess"); - OUString sConfigURL = OUString::createFromAscii("org.openoffice.Setup/L10N/"); - OUString sLocales = OUString::createFromAscii("ooLocale"); + OUString sAccessSrvc; + if (bUpdate) + sAccessSrvc = OUString::createFromAscii("com.sun.star.configuration.ConfigurationUpdateAccess"); + else + sAccessSrvc = OUString::createFromAscii("com.sun.star.configuration.ConfigurationAccess"); + + OUString sConfigURL = OUString::createFromAscii(pPath); // get configuration provider Reference< XMultiServiceFactory > theMSF = comphelper::getProcessServiceFactory(); Reference< XMultiServiceFactory > theConfigProvider = Reference< XMultiServiceFactory > ( - theMSF->createInstance( sConfigSrvc ),UNO_QUERY ); - // check provider - if (!theConfigProvider.is()) return aLanguage; + theMSF->createInstance( sConfigSrvc ),UNO_QUERY_THROW ); // access the provider Sequence< Any > theArgs(1); theArgs[ 0 ] <<= sConfigURL; - Reference< XNameAccess > theNameAccess = Reference< XNameAccess > ( + xNameAccess = Reference< XNameAccess > ( theConfigProvider->createInstanceWithArguments( - sAccessSrvc, theArgs ), UNO_QUERY ); - // check access - if (!theNameAccess.is()) return aLanguage; - // run query - Any aResult = theNameAccess->getByName( sLocales ); - OUString aLangString; - if (aResult >>= aLangString) - { - aLanguage = aLangString; - } - } catch (com::sun::star::uno::Exception) + sAccessSrvc, theArgs ), UNO_QUERY_THROW ); + } catch (com::sun::star::uno::Exception& e) { - // didn't work - return dontknow - return aLanguage; + OString aMsg = OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US); + OSL_ENSURE(sal_False, aMsg.getStr()); } - return aLanguage; + return xNameAccess; } -// get a list with the languages that are installed -IsoList LanguageSelection::getInstalledIsoLanguages() +Sequence< OUString > LanguageSelection::getInstalledLanguages() { - IsoList aList; - // read language list from org.openoffice.Setup/Office/ooSetupLocales - try{ - OUString sConfigSrvc = OUString::createFromAscii("com.sun.star.configuration.ConfigurationProvider"); - OUString sAccessSrvc = OUString::createFromAscii("com.sun.star.configuration.ConfigurationAccess"); - OUString sConfigURL = OUString::createFromAscii("org.openoffice.Setup/Office/InstalledLocales"); - - // get configuration provider - Reference< XMultiServiceFactory > theMSF = comphelper::getProcessServiceFactory(); - Reference< XMultiServiceFactory > theConfigProvider = Reference< XMultiServiceFactory > ( - theMSF->createInstance( sConfigSrvc ),UNO_QUERY ); - // check provider - if (!theConfigProvider.is()) return aList; - - // access the provider - Sequence< Any > theArgs(1); - theArgs[ 0 ] <<= sConfigURL; - Reference< XNameAccess > theNameAccess = Reference< XNameAccess > ( - theConfigProvider->createInstanceWithArguments( - sAccessSrvc, theArgs ), UNO_QUERY ); - //check access - if (!theNameAccess.is()) return aList; + Sequence< OUString > seqLanguages; + Reference< XNameAccess > xAccess = getConfigAccess("org.openoffice.Setup/Office/InstalledLocales", sal_False); + if (!xAccess.is()) return seqLanguages; + seqLanguages = xAccess->getElementNames(); + return seqLanguages; +} - Sequence< OUString > aLangSeq = theNameAccess->getElementNames(); +sal_Bool LanguageSelection::isInstalledLanguage(OUString& usLocale, sal_Bool bExact) +{ + sal_Bool bInstalled = sal_False; + Sequence< OUString > seqLanguages = getInstalledLanguages(); + for (sal_Int32 i=0; i theMSF = comphelper::getProcessServiceFactory(); - Reference< XMultiServiceFactory > theConfigProvider = Reference< XMultiServiceFactory > ( - theMSF->createInstance( sConfigSrvc ),UNO_QUERY ); - // check provider - if (!theConfigProvider.is()) return aList; + OUString aLanguage; + Sequence< OUString > seqLanguages = getInstalledLanguages(); + if (seqLanguages.getLength() > 0) + aLanguage = seqLanguages[0]; + return aLanguage; +} - // access the provider - Sequence< Any > theArgs(1); - theArgs[ 0 ] <<= sConfigURL; - Reference< XNameAccess > theNameAccess = Reference< XNameAccess > ( - theConfigProvider->createInstanceWithArguments( - sAccessSrvc, theArgs ), UNO_QUERY ); - //check access - if (!theNameAccess.is()) return aList; +OUString LanguageSelection::getUserLanguage() +{ + OUString aUserLanguage; + Reference< XNameAccess > xAccess(getConfigAccess("org.openoffice.Office.Linguistic/General", sal_False)); + if (xAccess.is()) + { + xAccess->getByName(OUString::createFromAscii("UILocale")) >>= aUserLanguage; + } + return aUserLanguage; +} - Sequence< OUString > aLangSeq = theNameAccess->getElementNames(); +OUString LanguageSelection::getSystemLanguage() +{ + OUString aUserLanguage; + Reference< XNameAccess > xAccess(getConfigAccess("org.openoffice.System/L10N", sal_False)); + if (xAccess.is()) + { + xAccess->getByName(OUString::createFromAscii("UILocale")) >>= aUserLanguage; + } + return aUserLanguage; +} - for (int i=0; i xProp(getConfigAccess("org.openoffice.Office.Linguistic/General", sal_True), UNO_QUERY_THROW); + xProp->setPropertyValue(OUString::createFromAscii("UILocale"), makeAny(OUString::createFromAscii(""))); + Reference< XChangesBatch >(xProp, UNO_QUERY_THROW)->commitChanges(); + } catch (com::sun::star::uno::RuntimeException& e) { - // didn't work - return empty list + OString aMsg = OUStringToOString(e.Message, RTL_TEXTENCODING_ASCII_US); + OSL_ENSURE(sal_False, aMsg.getStr()); } - return aList; + } -*/ + + } // namespace desktop -- cgit