Chromium Code Reviews| OLD | NEW |
|---|---|
| 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. | 1 // Copyright (c) 2010 The Chromium Authors. All rights reserved. |
| 2 // Use of this source code is governed by a BSD-style license that can be | 2 // Use of this source code is governed by a BSD-style license that can be |
| 3 // found in the LICENSE file. | 3 // found in the LICENSE file. |
| 4 | 4 |
| 5 #include "chrome/browser/chromeos/login/language_switch_menu.h" | 5 #include "chrome/browser/chromeos/login/language_switch_menu.h" |
| 6 | 6 |
| 7 #include "app/resource_bundle.h" | 7 #include "app/resource_bundle.h" |
| 8 #include "base/i18n/rtl.h" | 8 #include "base/i18n/rtl.h" |
| 9 #include "base/utf_string_conversions.h" | 9 #include "base/utf_string_conversions.h" |
| 10 #include "chrome/browser/browser_process.h" | 10 #include "chrome/browser/browser_process.h" |
| (...skipping 49 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 60 line, WideToUTF16(language_list_->GetLanguageNameAt(line))); | 60 line, WideToUTF16(language_list_->GetLanguageNameAt(line))); |
| 61 } | 61 } |
| 62 | 62 |
| 63 // Initialize menu here so it appears fast when called. | 63 // Initialize menu here so it appears fast when called. |
| 64 menu_.reset(new views::Menu2(&menu_model_)); | 64 menu_.reset(new views::Menu2(&menu_model_)); |
| 65 } | 65 } |
| 66 | 66 |
| 67 std::wstring LanguageSwitchMenu::GetCurrentLocaleName() const { | 67 std::wstring LanguageSwitchMenu::GetCurrentLocaleName() const { |
| 68 DCHECK(g_browser_process); | 68 DCHECK(g_browser_process); |
| 69 const std::string locale = g_browser_process->GetApplicationLocale(); | 69 const std::string locale = g_browser_process->GetApplicationLocale(); |
| 70 return language_list_->GetLanguageNameAt( | 70 int index = language_list_->GetIndexFromLocale(locale); |
| 71 language_list_->GetIndexFromLocale(locale)); | 71 if (index == -1) { |
|
Peter Kasting
2010/12/20 17:18:48
I don't think we should "handle" this error. IMO
glotov
2010/12/21 13:19:08
Agree. That was my second option but I wanted some
| |
| 72 // If locale cannot be found (probably resources bundle failed to | |
| 73 // load or user edited prefs file manually) - use the default. | |
| 74 LOG(DFATAL) << "Unknown locale: " << locale << ". Defaulting to the first."; | |
| 75 index = 0; | |
| 76 } | |
| 77 return language_list_->GetLanguageNameAt(index); | |
| 72 }; | 78 }; |
| 73 | 79 |
| 74 void LanguageSwitchMenu::SetFirstLevelMenuWidth(int width) { | 80 void LanguageSwitchMenu::SetFirstLevelMenuWidth(int width) { |
| 75 DCHECK(menu_ != NULL); | 81 DCHECK(menu_ != NULL); |
| 76 menu_->SetMinimumWidth(width); | 82 menu_->SetMinimumWidth(width); |
| 77 } | 83 } |
| 78 | 84 |
| 79 // static | 85 // static |
| 80 void LanguageSwitchMenu::SwitchLanguage(const std::string& locale) { | 86 void LanguageSwitchMenu::SwitchLanguage(const std::string& locale) { |
| 81 DCHECK(g_browser_process); | 87 DCHECK(g_browser_process); |
| 82 if (g_browser_process->GetApplicationLocale() == locale) { | 88 if (g_browser_process->GetApplicationLocale() == locale) { |
| 83 return; | 89 return; |
| 84 } | 90 } |
| 85 // Save new locale. | 91 // Save new locale. |
| 86 PrefService* prefs = g_browser_process->local_state(); | 92 PrefService* prefs = g_browser_process->local_state(); |
| 87 // TODO(markusheintz): If the preference is managed and can not be changed by | 93 // TODO(markusheintz): If the preference is managed and can not be changed by |
| 88 // the user, changing the language should be disabled in the UI. | 94 // the user, changing the language should be disabled in the UI. |
| 89 // TODO(markusheintz): Change the if condition to prefs->IsUserModifiable() | 95 // TODO(markusheintz): Change the if condition to prefs->IsUserModifiable() |
| 90 // once Mattias landed his pending patch. | 96 // once Mattias landed his pending patch. |
| 91 if (!prefs->IsManagedPreference(prefs::kApplicationLocale)) { | 97 if (!prefs->IsManagedPreference(prefs::kApplicationLocale)) { |
| 92 prefs->SetString(prefs::kApplicationLocale, locale); | 98 prefs->SetString(prefs::kApplicationLocale, locale); |
| 93 prefs->SavePersistentPrefs(); | 99 prefs->SavePersistentPrefs(); |
| 94 | 100 |
| 95 // Switch the locale. | 101 // Switch the locale. |
| 96 ResourceBundle::ReloadSharedInstance(locale); | 102 CHECK(ResourceBundle::ReloadSharedInstance(locale) == locale) |
|
Peter Kasting
2010/12/20 17:18:48
Never do real work inside a CHECK or DCHECK.
glotov
2010/12/21 13:19:08
Done.
| |
| 103 << "Locale could not be found for " << locale; | |
| 97 | 104 |
| 98 // Enable the keyboard layouts that are necessary for the new locale. | 105 // Enable the keyboard layouts that are necessary for the new locale. |
| 99 input_method::EnableInputMethods( | 106 input_method::EnableInputMethods( |
| 100 locale, input_method::kKeyboardLayoutsOnly, | 107 locale, input_method::kKeyboardLayoutsOnly, |
| 101 CrosLibrary::Get()->GetKeyboardLibrary()-> | 108 CrosLibrary::Get()->GetKeyboardLibrary()-> |
| 102 GetHardwareKeyboardLayoutName()); | 109 GetHardwareKeyboardLayoutName()); |
| 103 | 110 |
| 104 // The following line does not seem to affect locale anyhow. Maybe in | 111 // The following line does not seem to affect locale anyhow. Maybe in |
| 105 // future.. | 112 // future.. |
| 106 g_browser_process->SetApplicationLocale(locale); | 113 g_browser_process->SetApplicationLocale(locale); |
| (...skipping 38 matching lines...) Expand 10 before | Expand all | Expand 10 after Loading... | |
| 145 void LanguageSwitchMenu::ExecuteCommand(int command_id) { | 152 void LanguageSwitchMenu::ExecuteCommand(int command_id) { |
| 146 const std::string locale = language_list_->GetLocaleFromIndex(command_id); | 153 const std::string locale = language_list_->GetLocaleFromIndex(command_id); |
| 147 SwitchLanguage(locale); | 154 SwitchLanguage(locale); |
| 148 InitLanguageMenu(); | 155 InitLanguageMenu(); |
| 149 | 156 |
| 150 // Update all view hierarchies that the locale has changed. | 157 // Update all view hierarchies that the locale has changed. |
| 151 views::Widget::NotifyLocaleChanged(); | 158 views::Widget::NotifyLocaleChanged(); |
| 152 } | 159 } |
| 153 | 160 |
| 154 } // namespace chromeos | 161 } // namespace chromeos |
| OLD | NEW |