diff options
author | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-20 10:15:41 +0000 |
---|---|---|
committer | satorux@chromium.org <satorux@chromium.org@0039d316-1c4b-4281-b951-d872f2087c98> | 2010-07-20 10:15:41 +0000 |
commit | 74b42fc17ac6a967bb9159b8270169dc63545ec0 (patch) | |
tree | 83e604062b7fdc81eee9d41ce4210ca15ab11b64 | |
parent | 0dbe9f329821edc0150896ca05f40a9402b259de (diff) | |
download | chromium_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
-rw-r--r-- | chrome/browser/chromeos/options/language_config_model.cc | 41 | ||||
-rw-r--r-- | chrome/browser/chromeos/options/language_config_model.h | 19 | ||||
-rw-r--r-- | chrome/browser/chromeos/preferences.cc | 15 | ||||
-rw-r--r-- | chrome/browser/chromeos/preferences.h | 1 | ||||
-rw-r--r-- | chrome/browser/sync/glue/synchronized_preferences.h | 1 | ||||
-rw-r--r-- | chrome/common/pref_names.cc | 7 | ||||
-rw-r--r-- | chrome/common/pref_names.h | 1 |
7 files changed, 59 insertions, 26 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, diff --git a/chrome/browser/chromeos/options/language_config_model.h b/chrome/browser/chromeos/options/language_config_model.h index 014ea14..ec79bc6 100644 --- a/chrome/browser/chromeos/options/language_config_model.h +++ b/chrome/browser/chromeos/options/language_config_model.h @@ -48,7 +48,7 @@ class AddLanguageComboboxModel : public LanguageComboboxModel { // The model of LanguageConfigView. class LanguageConfigModel : public NotificationObserver { public: - LanguageConfigModel(PrefService* pref_service); + explicit LanguageConfigModel(PrefService* pref_service); // Counts the number of active input methods for the given language code. size_t CountNumActiveInputMethods(const std::string& language_code); @@ -77,18 +77,26 @@ class LanguageConfigModel : public NotificationObserver { // Returns true if an IME of |input_method_id| is activated. bool InputMethodIsActivated(const std::string& input_method_id); - // Gets the list of active IME IDs like "pinyin" and "m17n:ar:kbd". + // Gets the list of active IME IDs like "pinyin" and "m17n:ar:kbd" from + // the underlying preference object. The original contents of + // |out_input_method_ids| are lost. void GetActiveInputMethodIds( std::vector<std::string>* out_input_method_ids); + // Gets the list of preferred language codes like "en-US" and "fr" from + // the underlying preference object. The original contents of + // |out_language_codes| are lost. + void GetPreferredLanguageCodes( + std::vector<std::string>* out_language_codes); + // Gets the list of input method ids associated with the given language // code. The original contents of |input_method_ids| will be lost. void GetInputMethodIdsFromLanguageCode( const std::string& language_code, std::vector<std::string>* input_method_ids) const; - // Callback for |preload_engines_| pref updates. Initializes the preferred - // language codes based on the updated pref value. + // Callback for |preferred_language_codes_| pref updates. Initializes + // the preferred language codes based on the updated pref value. void NotifyPrefChanged(); // NotificationObserver overrides. @@ -124,7 +132,8 @@ class LanguageConfigModel : public NotificationObserver { PrefService* pref_service_; // The codes of the preferred languages. std::vector<std::string> preferred_language_codes_; - StringPrefMember preload_engines_; + StringPrefMember preferred_languages_pref_; + StringPrefMember preload_engines_pref_; // List of supported language codes like "en" and "ja". std::vector<std::string> supported_language_codes_; // List of supported IME IDs like "pinyin" and "m17n:ar:kbd". diff --git a/chrome/browser/chromeos/preferences.cc b/chrome/browser/chromeos/preferences.cc index 0fe3b48..7a993d9 100644 --- a/chrome/browser/chromeos/preferences.cc +++ b/chrome/browser/chromeos/preferences.cc @@ -36,6 +36,7 @@ void Preferences::RegisterUserPrefs(PrefService* prefs) { kHotkeyNextEngineInMenu); prefs->RegisterStringPref(prefs::kLanguageHotkeyPreviousEngine, kHotkeyPreviousEngine); + prefs->RegisterStringPref(prefs::kLanguagePreferredLanguages, ""); prefs->RegisterStringPref(prefs::kLanguagePreloadEngines, kFallbackInputMethodId); // EN layout for (size_t i = 0; i < kNumChewingBooleanPrefs; ++i) { @@ -94,6 +95,8 @@ void Preferences::Init(PrefService* prefs) { prefs::kLanguageHotkeyNextEngineInMenu, prefs, this); language_hotkey_previous_engine_.Init( prefs::kLanguageHotkeyPreviousEngine, prefs, this); + language_preferred_languages_.Init(prefs::kLanguagePreferredLanguages, + prefs, this); language_preload_engines_.Init(prefs::kLanguagePreloadEngines, prefs, this); for (size_t i = 0; i < kNumChewingBooleanPrefs; ++i) { language_chewing_boolean_prefs_[i].Init( @@ -136,6 +139,10 @@ void Preferences::Init(PrefService* prefs) { } std::string locale(g_browser_process->GetApplicationLocale()); + // Add input methods based on the application locale when the user first + // logs in. For instance, if the user chooses Japanese as the UI + // language at the first login, we'll add input methods associated with + // Japanese, such as mozc. if (locale != kFallbackInputMethodLocale && !prefs->HasPrefPath(prefs::kLanguagePreloadEngines)) { std::string preload_engines(language_preload_engines_.GetValue()); @@ -149,6 +156,10 @@ void Preferences::Init(PrefService* prefs) { } language_preload_engines_.SetValue(preload_engines); } + // Add the UI language to the preferred languages the user first logs in. + if (!prefs->HasPrefPath(prefs::kLanguagePreferredLanguages)) { + language_preferred_languages_.SetValue(locale); + } // Initialize touchpad settings to what's saved in user preferences. NotifyPrefChanged(NULL); @@ -198,6 +209,10 @@ void Preferences::NotifyPrefChanged(const std::wstring* pref_name) { kPreviousEngineConfigName, language_hotkey_previous_engine_.GetValue()); } + if (!pref_name || *pref_name == prefs::kLanguagePreferredLanguages) { + // Unlike kLanguagePreloadEngines and some other input method + // preferencs, we don't need to send this to ibus-daemon. + } if (!pref_name || *pref_name == prefs::kLanguagePreloadEngines) { SetLanguageConfigStringListAsCSV(kGeneralSectionName, kPreloadEnginesConfigName, diff --git a/chrome/browser/chromeos/preferences.h b/chrome/browser/chromeos/preferences.h index e0b93fc..a9a2250 100644 --- a/chrome/browser/chromeos/preferences.h +++ b/chrome/browser/chromeos/preferences.h @@ -83,6 +83,7 @@ class Preferences : public NotificationObserver { // Input method preferences. StringPrefMember language_hotkey_next_engine_in_menu_; StringPrefMember language_hotkey_previous_engine_; + StringPrefMember language_preferred_languages_; StringPrefMember language_preload_engines_; BooleanPrefMember language_chewing_boolean_prefs_[kNumChewingBooleanPrefs]; StringPrefMember language_chewing_multiple_choice_prefs_[ diff --git a/chrome/browser/sync/glue/synchronized_preferences.h b/chrome/browser/sync/glue/synchronized_preferences.h index 027ff24..3d25956 100644 --- a/chrome/browser/sync/glue/synchronized_preferences.h +++ b/chrome/browser/sync/glue/synchronized_preferences.h @@ -125,6 +125,7 @@ static const wchar_t* kSynchronizedPreferences[] = { prefs::kLanguagePinyinMinusEqualPage, prefs::kLanguagePinyinShiftSelectCandidate, prefs::kLanguagePinyinTradCandidate, + prefs::kLanguagePreferredLanguages, prefs::kLanguagePreloadEngines, // TODO(yusukes): Add prefs for ibus-mozc (Japanese input method). // prefs::kLanguageMozcPreeditMethod, diff --git a/chrome/common/pref_names.cc b/chrome/common/pref_names.cc index ad60dec..e04994f 100644 --- a/chrome/common/pref_names.cc +++ b/chrome/common/pref_names.cc @@ -218,8 +218,13 @@ const wchar_t kLanguageHotkeyNextEngineInMenu[] = const wchar_t kLanguageHotkeyPreviousEngine[] = L"settings.language.hotkey_previous_engine"; +// A string pref (comma-separated list) set to the preferred language IDs +// (ex. "en-US,fr,ko"). +const wchar_t kLanguagePreferredLanguages[] = + L"settings.language.preferred_languages"; + // A string pref (comma-separated list) set to the preloaded (active) input -// method IDs. +// method IDs (ex. "pinyin,mozc"). const wchar_t kLanguagePreloadEngines[] = L"settings.language.preload_engines"; // Boolean prefs for ibus-chewing Chinese input method. diff --git a/chrome/common/pref_names.h b/chrome/common/pref_names.h index 27b0451..9897ec0 100644 --- a/chrome/common/pref_names.h +++ b/chrome/common/pref_names.h @@ -78,6 +78,7 @@ extern const wchar_t kLanguageCurrentInputMethod[]; extern const wchar_t kLanguagePreviousInputMethod[]; extern const wchar_t kLanguageHotkeyNextEngineInMenu[]; extern const wchar_t kLanguageHotkeyPreviousEngine[]; +extern const wchar_t kLanguagePreferredLanguages[]; extern const wchar_t kLanguagePreloadEngines[]; extern const wchar_t kLanguageChewingAutoShiftCur[]; extern const wchar_t kLanguageChewingAddPhraseDirection[]; |