From 74b42fc17ac6a967bb9159b8270169dc63545ec0 Mon Sep 17 00:00:00 2001 From: "satorux@chromium.org" Date: Tue, 20 Jul 2010 10:15:41 +0000 Subject: Add "settings.language.preferred_languages" for Chromium OS's Languages and Input dialog. Before this change, we used to get the list of preferred languages based on the active input methods. This is tricky. Having a preference for the value is simpler, and makes it easier for us to implement the DOM UI version. BUG=none TEST=manually Review URL: http://codereview.chromium.org/3012012 git-svn-id: svn://svn.chromium.org/chrome/trunk/src@53035 0039d316-1c4b-4281-b951-d872f2087c98 --- .../chromeos/options/language_config_model.cc | 41 +++++++++++----------- 1 file changed, 21 insertions(+), 20 deletions(-) (limited to 'chrome/browser/chromeos/options/language_config_model.cc') diff --git a/chrome/browser/chromeos/options/language_config_model.cc b/chrome/browser/chromeos/options/language_config_model.cc index 93818aec..fafa2f6 100644 --- a/chrome/browser/chromeos/options/language_config_model.cc +++ b/chrome/browser/chromeos/options/language_config_model.cc @@ -76,12 +76,14 @@ LanguageConfigModel::LanguageConfigModel(PrefService* pref_service) // Initialize the maps and vectors. InitInputMethodIdVectors(); - preload_engines_.Init( + preferred_languages_pref_.Init( + prefs::kLanguagePreferredLanguages, pref_service_, this); + preload_engines_pref_.Init( prefs::kLanguagePreloadEngines, pref_service_, this); // TODO(yusukes): It might be safer to call GetActiveLanguages() cros API - // here and compare the result and preload_engines_.GetValue(). If there's - // a discrepancy between IBus setting and Chrome prefs, we can resolve it - // by calling preload_engines_SetValue() here. + // here and compare the result and preload_engines_pref_.GetValue(). + // If there's a discrepancy between IBus setting and Chrome prefs, we + // can resolve it by calling preload_engines_pref_SetValue() here. // Initialize the language codes currently activated. NotifyPrefChanged(); @@ -122,11 +124,15 @@ size_t LanguageConfigModel::AddLanguageCode( std::find(preferred_language_codes_.begin(), preferred_language_codes_.end(), language_code)); + preferred_languages_pref_.SetValue( + JoinString(preferred_language_codes_, ',')); return added_at; } void LanguageConfigModel::RemoveLanguageAt(size_t row) { preferred_language_codes_.erase(preferred_language_codes_.begin() + row); + preferred_languages_pref_.SetValue( + JoinString(preferred_language_codes_, ',')); } void LanguageConfigModel::UpdateInputMethodPreferences( @@ -136,7 +142,7 @@ void LanguageConfigModel::UpdateInputMethodPreferences( // function below uses stable sort, the relateve order of input methods that // belong to the same language (e.g. "mozc" and "xkb:jp::jpn") is maintained. input_method::SortInputMethodIdsByNames(&new_input_method_ids); - preload_engines_.SetValue(JoinString(new_input_method_ids, ',')); + preload_engines_pref_.SetValue(JoinString(new_input_method_ids, ',')); } void LanguageConfigModel::DeactivateInputMethodsFor( @@ -186,12 +192,20 @@ bool LanguageConfigModel::InputMethodIsActivated( void LanguageConfigModel::GetActiveInputMethodIds( std::vector* out_input_method_ids) { - const std::string value = preload_engines_.GetValue(); + const std::string value = preload_engines_pref_.GetValue(); out_input_method_ids->clear(); if (!value.empty()) SplitString(value, ',', out_input_method_ids); } +void LanguageConfigModel::GetPreferredLanguageCodes( + std::vector* out_language_codes) { + const std::string value = preferred_languages_pref_.GetValue(); + out_language_codes->clear(); + if (!value.empty()) + SplitString(value, ',', out_language_codes); +} + void LanguageConfigModel::GetInputMethodIdsFromLanguageCode( const std::string& language_code, std::vector* input_method_ids) const { @@ -206,20 +220,7 @@ void LanguageConfigModel::GetInputMethodIdsFromLanguageCode( } void LanguageConfigModel::NotifyPrefChanged() { - std::vector input_method_ids; - GetActiveInputMethodIds(&input_method_ids); - - std::set language_code_set; - for (size_t i = 0; i < input_method_ids.size(); ++i) { - const std::string language_code = - input_method::GetLanguageCodeFromInputMethodId(input_method_ids[i]); - language_code_set.insert(language_code); - } - - preferred_language_codes_.clear(); - preferred_language_codes_.assign( - language_code_set.begin(), language_code_set.end()); - input_method::SortLanguageCodesByNames(&preferred_language_codes_); + GetPreferredLanguageCodes(&preferred_language_codes_); } void LanguageConfigModel::Observe(NotificationType type, -- cgit v1.1