summaryrefslogtreecommitdiffstats
path: root/chrome/browser/chromeos/options/language_config_model.cc
diff options
context:
space:
mode:
authorsatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-20 10:15:41 +0000
committersatorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98>2010-07-20 10:15:41 +0000
commit74b42fc17ac6a967bb9159b8270169dc63545ec0 (patch)
tree83e604062b7fdc81eee9d41ce4210ca15ab11b64 /chrome/browser/chromeos/options/language_config_model.cc
parent0dbe9f329821edc0150896ca05f40a9402b259de (diff)
downloadchromium_src-74b42fc17ac6a967bb9159b8270169dc63545ec0.zip
chromium_src-74b42fc17ac6a967bb9159b8270169dc63545ec0.tar.gz
chromium_src-74b42fc17ac6a967bb9159b8270169dc63545ec0.tar.bz2
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
Diffstat (limited to 'chrome/browser/chromeos/options/language_config_model.cc')
-rw-r--r--chrome/browser/chromeos/options/language_config_model.cc41
1 files changed, 21 insertions, 20 deletions
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<std::string>* 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<std::string>* 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<std::string>* input_method_ids) const {
@@ -206,20 +220,7 @@ void LanguageConfigModel::GetInputMethodIdsFromLanguageCode(
}
void LanguageConfigModel::NotifyPrefChanged() {
- std::vector<std::string> input_method_ids;
- GetActiveInputMethodIds(&input_method_ids);
-
- std::set<std::string> 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,